2018-10-19 14:35:25 +02:00
|
|
|
package de.ellpeck.naturesaura.compat;
|
|
|
|
|
|
|
|
import baubles.api.BaubleType;
|
|
|
|
import baubles.api.IBauble;
|
|
|
|
import baubles.api.cap.BaublesCapabilities;
|
|
|
|
import de.ellpeck.naturesaura.NaturesAura;
|
|
|
|
import de.ellpeck.naturesaura.items.ModItems;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
import net.minecraftforge.common.capabilities.Capability;
|
|
|
|
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
|
|
|
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
|
|
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
|
|
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
|
|
|
public class BaublesCompat {
|
|
|
|
|
|
|
|
private final IBauble eye = stack -> BaubleType.CHARM;
|
2018-10-20 21:19:08 +02:00
|
|
|
private final IBauble cache = stack -> BaubleType.BELT;
|
2018-10-19 14:35:25 +02:00
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onCapabilitiesAttach(AttachCapabilitiesEvent<ItemStack> event) {
|
|
|
|
Item item = event.getObject().getItem();
|
|
|
|
if (item == ModItems.EYE) {
|
2018-10-20 21:19:08 +02:00
|
|
|
this.addCap(event, this.eye);
|
|
|
|
} else if (item == ModItems.AURA_CACHE) {
|
|
|
|
this.addCap(event, this.cache);
|
2018-10-19 14:35:25 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-20 21:19:08 +02:00
|
|
|
|
|
|
|
private void addCap(AttachCapabilitiesEvent<ItemStack> event, IBauble type) {
|
|
|
|
event.addCapability(new ResourceLocation(NaturesAura.MOD_ID, "bauble"), new ICapabilityProvider() {
|
|
|
|
@Override
|
|
|
|
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
|
|
|
return capability == BaublesCapabilities.CAPABILITY_ITEM_BAUBLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
|
|
|
return capability == BaublesCapabilities.CAPABILITY_ITEM_BAUBLE ? (T) type : null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-10-19 14:35:25 +02:00
|
|
|
}
|