NaturesAura/src/main/java/de/ellpeck/naturesaura/compat/BaublesCompat.java
2018-10-19 14:35:25 +02:00

42 lines
1.6 KiB
Java

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;
@SubscribeEvent
public void onCapabilitiesAttach(AttachCapabilitiesEvent<ItemStack> event) {
Item item = event.getObject().getItem();
if (item == ModItems.EYE) {
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) BaublesCompat.this.eye : null;
}
});
}
}
}