Example usage for net.minecraftforge.event AttachCapabilitiesEvent addCapability

List of usage examples for net.minecraftforge.event AttachCapabilitiesEvent addCapability

Introduction

In this page you can find the example usage for net.minecraftforge.event AttachCapabilitiesEvent addCapability.

Prototype

public void addCapability(ResourceLocation key, ICapabilityProvider cap) 

Source Link

Document

Adds a capability to be attached to this object.

Usage

From source file:blusunrize.immersiveengineering.common.util.compat.BaublesHelper.java

@SubscribeEvent
public void onCapabilitiesAttach(AttachCapabilitiesEvent<ItemStack> event) {
    if (event.getObject().getItem() == IEContent.itemPowerpack) {
        event.addCapability(new ResourceLocation("baubles", "bauble_cap"), new ICapabilityProvider() {
            @Override//from   w w w. ja  va 2  s.co  m
            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
                        ? BaublesCapabilities.CAPABILITY_ITEM_BAUBLE.cast(BAUBLE_POWERPACK)
                        : null;
            }
        });
    }
}

From source file:com.elytradev.thermionics.Thermionics.java

License:Open Source License

@SubscribeEvent
public void onAttachCapabilities(AttachCapabilitiesEvent<Entity> e) {
    if (e.getObject() instanceof EntityPlayer) {
        e.addCapability(new ResourceLocation("thermionics", "weaponskill"), new ICapabilityProvider() {
            private WeaponSkillInfo info = new WeaponSkillInfo();

            @Override/*from w w  w  .j a va 2s  . c om*/
            public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
                return (capability == CAPABILITY_WEAPONSKILL);
            }

            @SuppressWarnings("unchecked")
            @Override
            public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
                if (capability == CAPABILITY_WEAPONSKILL) {
                    return (T) info;
                } else {
                    return null;
                }
            }
        });
    }
}

From source file:com.fireball1725.firelib.guimaker.capability.GuiMakerHandler.java

License:Open Source License

@SubscribeEvent
public void attachCapabilitiesEvent(AttachCapabilitiesEvent<TileEntity> event) {
    if (event.getObject() instanceof IGuiMaker) {
        event.addCapability(GUI_MAKER, new GuiMakerProvider(event.getObject()));
    }//from   w w  w  . j a v  a 2s  .com
}

From source file:com.lothrazar.cyclicmagic.event.EventPlayerData.java

License:Open Source License

/**
 * /* w  ww  . j  av  a 2s.c  o m*/
 * TODO
 * 
 * SHOULD BE AttachCapabilitiesEvent<EntityPlayer> ..BUT that NEVER EVER fires, so data never gets attached to player soo NPEs all over crash the game SO IM forced to do it this way, fire it on
 * GLOBAL object and check instanceof at runtime NO IDEA if its a bug in forge or if there is a right way / wrong way. but of course forge has no docs and nobody to ask
 * 
 * @param event
 */
@SuppressWarnings("rawtypes")
@SubscribeEvent
public void onEntityConstruct(AttachCapabilitiesEvent event) {//was AttachCapabilitiesEvent.Entity in 1.11 and previous
    if (event.getObject() instanceof EntityPlayer) {
        event.addCapability(new ResourceLocation(Const.MODID, "IModdedSleeping"), new PlayerCapInstance());
    }
}

From source file:jayavery.geomastery.main.PlayerEvents.java

License:Open Source License

/** Attaches ICapPlayer to the Player. */
@SubscribeEvent//from  w w  w  .j a va2 s .  co  m
public void playerCapabilities(AttachCapabilitiesEvent<Entity> event) {

    if (!(event.getObject() instanceof EntityPlayer)) {

        return;
    }

    EntityPlayer player = (EntityPlayer) event.getObject();

    if (!(player.hasCapability(GeoCaps.CAP_PLAYER, null))) {

        event.addCapability(GeoCaps.CAP_PLAYER_ID, new ProviderCapPlayer(new DefaultCapPlayer(player)));
    }
}

From source file:nightkosh.gravestone_extended.core.CapabilityHandler.java

License:LGPL

@SubscribeEvent
public void attachCapability(AttachCapabilitiesEvent<Entity> event) {
    if (event.getObject() instanceof EntityPlayer) {
        event.addCapability(AIR_CAP, new ChokeProvider());
    }/*w w  w  .  j a  v  a2 s  .c  o  m*/
}

From source file:valkyrienwarfare.addon.control.ControlEventsCommon.java

License:Open Source License

@SubscribeEvent
public void onAttachCapabilityEventItem(AttachCapabilitiesEvent event) {
    if (event.getObject() instanceof ItemStack) {
        ItemStack stack = (ItemStack) event.getObject();
        if (stack.getItem() instanceof ItemRelayWire) {
            event.addCapability(new ResourceLocation(ValkyrienWarfareControl.INSTANCE.getModID(), "LastRelay"),
                    new LastNodeCapabilityProvider());
        }/*from  w ww  . j  a  va 2s  . c o  m*/
    }
}

From source file:valkyrienwarfare.mod.event.EventsCommon.java

License:Open Source License

@SubscribeEvent
public void onEntityConstruct(AttachCapabilitiesEvent evt) {
    if (evt.getObject() instanceof EntityPlayer) {
        evt.addCapability(new ResourceLocation(ValkyrienWarfareMod.MODID, "AirshipCounter"),
                new ICapabilitySerializable<NBTTagIntArray>() {
                    IAirshipCounterCapability inst = ValkyrienWarfareMod.airshipCounter.getDefaultInstance();

                    @Override//from ww w . j a  v  a  2s. co m
                    public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
                        return capability == ValkyrienWarfareMod.airshipCounter;
                    }

                    @Override
                    public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
                        return capability == ValkyrienWarfareMod.airshipCounter
                                ? ValkyrienWarfareMod.airshipCounter.<T>cast(inst)
                                : null;
                    }

                    @Override
                    public NBTTagIntArray serializeNBT() {
                        return (NBTTagIntArray) ValkyrienWarfareMod.airshipCounter.getStorage()
                                .writeNBT(ValkyrienWarfareMod.airshipCounter, inst, null);
                    }

                    @Override
                    public void deserializeNBT(NBTTagIntArray nbt) {
                        //Otherwise its old, then ignore it
                        if (nbt instanceof NBTTagIntArray) {
                            ValkyrienWarfareMod.airshipCounter.getStorage()
                                    .readNBT(ValkyrienWarfareMod.airshipCounter, inst, null, nbt);
                        }
                    }
                });
    }
}