Java Code Examples for net.minecraftforge.event.AttachCapabilitiesEvent#addCapability()

The following examples show how to use net.minecraftforge.event.AttachCapabilitiesEvent#addCapability() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WorldEventsCommon.java    From Valkyrien-Skies with Apache License 2.0 7 votes vote down vote up
@SubscribeEvent
public void onAttachCapabilityEventItem(AttachCapabilitiesEvent event) {
    if (event.getObject() instanceof ItemStack) {
        ItemStack stack = (ItemStack) event.getObject();
        Item item = stack.getItem();

        if (item instanceof ItemValkyriumCrystal) {
            event.addCapability(
                new ResourceLocation(ValkyrienSkiesWorld.MOD_ID, "AntiGravityValue"),
                new AntiGravityCapabilityProvider(VSConfig.valkyriumCrystalForce));
        }
        if (stack.getItem() instanceof ItemBlock) {
            ItemBlock blockItem = (ItemBlock) stack.getItem();
            if (blockItem.getBlock() instanceof BlockValkyriumOre) {
                event.addCapability(
                    new ResourceLocation(ValkyrienSkiesWorld.MOD_ID, "AntiGravityValue"),
                    new AntiGravityCapabilityProvider(VSConfig.valkyriumOreForce));
            }
        }
    }
}
 
Example 2
Source File: RailManager.java    From Signals with GNU General Public License v3.0 6 votes vote down vote up
public void onTileEntityCapabilityAttachEvent(AttachCapabilitiesEvent<TileEntity> event){
    ICapabilityProvider provider = new CapabilityDestinationProvider.Provider();
    boolean requiresCap = false;

    CapabilityDestinationProvider cap = provider.getCapability(CapabilityDestinationProvider.INSTANCE, null);
    for(IDestinationProvider destinationProvider : destinationProviders) {
        if(destinationProvider.isTileEntityApplicable(event.getObject())) {
            try {
                cap.addDestinationProvider(destinationProvider.getClass().newInstance());
                if(!requiresCap) {
                    requiresCap = true;
                    event.addCapability(new ResourceLocation(Constants.MOD_ID, "destinationProviderCapability"), provider);
                }
            } catch(Exception e) {
                e.printStackTrace();
            }
        }
    }
}
 
Example 3
Source File: BlockHandler.java    From BetterChests with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void initTe(AttachCapabilitiesEvent<TileEntity> event) {
	if (event.getObject() instanceof TileEntityBBarrel) {
		TileEntityBBarrel chest = (TileEntityBBarrel) event.getObject();
		event.addCapability(rl, new CapabilityHandler(chest));
	}
}
 
Example 4
Source File: ProxyCommon.java    From WearableBackpacks with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onAttachCapabilitiesEntity(AttachCapabilitiesEvent<Entity> event) {
	if (!BackpackRegistry.canEntityWearBackpacks(event.getObject())) return;
	// Give entities that can wear backpacks the backpack capability.
	event.addCapability(BackpackCapability.IDENTIFIER,
		new BackpackCapability.Provider((EntityLivingBase)event.getObject()));
}
 
Example 5
Source File: CapabilityProtectiveArmor.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@SubscribeEvent
public void attachCapabilities(AttachCapabilitiesEvent<ItemStack> evt)
{
	if (evt.getCapabilities().containsKey(KEY)) {
		return;
	}
	Item item = evt.getObject().getItem();
	if (item instanceof ItemSpaceArmor) {
		evt.addCapability(KEY, (ICapabilityProvider) item);
	}
}
 
Example 6
Source File: ItemBreakingTracker.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SubscribeEvent
public void attachCapabilities(AttachCapabilitiesEvent<Entity> e)
{
    if (!ConfigManager.SERVER.enableScraping.get())
        return;
    final Entity entity = e.getObject();

    if (!(entity instanceof ServerPlayerEntity))
        return;

    if (entity.world == null || entity.world.isRemote)
        return;

    e.addCapability(PROP_KEY, new ICapabilityProvider()
    {
        ItemBreakingTracker cap = new ItemBreakingTracker();
        LazyOptional<ItemBreakingTracker> cap_provider = LazyOptional.of(() -> cap);

        {
            cap.init(entity, entity.world);
        }

        @SuppressWarnings("unchecked")
        @Override
        public <T> LazyOptional<T> getCapability(Capability<T> capability, @Nullable Direction facing)
        {
            if (capability == TRACKER)
                return cap_provider.cast();
            return LazyOptional.empty();
        }
    });
}
 
Example 7
Source File: ControlEventsCommon.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@SubscribeEvent
public void onAttachCapabilityEventItem(AttachCapabilitiesEvent<ItemStack> event) {
    if (event.getObject().getItem() instanceof ItemRelayWire) {
        event.addCapability(new ResourceLocation(ValkyrienSkiesControl.MOD_ID, "LastRelay"),
            new LastNodeCapabilityProvider());
    }
}
 
Example 8
Source File: CivilizationHandlers.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onEntityLoad(AttachCapabilitiesEvent<Entity> event) {
	if (!(event.getObject() instanceof EntityPlayer)) {
		return;
	}
	EntityPlayer player = (EntityPlayer) event.getObject();
	event.addCapability(new ResourceLocation(ToroQuest.MODID, "playerCivilization"), new PlayerCivilizationCapabilityProvider(player));
	syncClientCapability(player);
}
 
Example 9
Source File: ModCapabilities.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public static void attachEntity(AttachCapabilitiesEvent<Entity> e) {
	if (e.getObject() instanceof EntityPlayer) {
		ManaCapabilityProvider manaCap = new ManaCapabilityProvider(new DefaultManaCapability());
		e.addCapability(new ResourceLocation(Wizardry.MODID, "capability_mana"), manaCap);

		MiscCapabilityProvider miscCap = new MiscCapabilityProvider(new DefaultMiscCapability());
		e.addCapability(new ResourceLocation(Wizardry.MODID, "capability_misc"), miscCap);
	}
}
 
Example 10
Source File: PlayerPropertyEvents.java    From YouTubeModdingTutorial with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onEntityConstructing(AttachCapabilitiesEvent<Entity> event){
    if (event.getObject() instanceof EntityPlayer) {
        if (!event.getObject().hasCapability(PlayerProperties.PLAYER_MANA, null)) {
            event.addCapability(new ResourceLocation(MyMod.MODID, "Mana"), new PropertiesDispatcher());
        }
    }
}
 
Example 11
Source File: WizardryChunkCapability.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public static void onAttachCapabilities(AttachCapabilitiesEvent<Chunk> event)
{
	event.addCapability(WIZARDRY_CHUNK_ID, StandardWizardryChunk.create());
}
 
Example 12
Source File: WizardryWorldCapability.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public static void onAttachCapabilities(AttachCapabilitiesEvent<World> event) {
	event.addCapability(WIZARDRY_WORLD_ID, StandardWizardryWorld.create(event.getObject()));
}
 
Example 13
Source File: EventHandler.java    From Signals with GNU General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void onCapabilityAttachmentEntity(AttachCapabilitiesEvent<Entity> event){
    if(event.getObject() instanceof EntityMinecart) {
        event.addCapability(new ResourceLocation(Constants.MOD_ID, "minecartDestinationCapability"), new CapabilityMinecartDestination.Provider());
    }
}
 
Example 14
Source File: EventHandler.java    From Signals with GNU General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void onCapabilityAttachmentStack(AttachCapabilitiesEvent<ItemStack> event){
    if(event.getObject().getItem() == ModItems.TICKET) {
        event.addCapability(new ResourceLocation(Constants.MOD_ID, "ticketDestinationCapability"), new CapabilityMinecartDestination.Provider());
    }
}
 
Example 15
Source File: EntityXpHandler.java    From TinkersToolLeveling with MIT License 4 votes vote down vote up
@SubscribeEvent
public void onCapabilityAttach(AttachCapabilitiesEvent<Entity> event) {
  if(event.getObject() instanceof EntityLivingBase && event.getObject().isEntityAlive()) {
    event.addCapability(CAPABILITY_KEY, new DamageXpHandler());
  }
}
 
Example 16
Source File: StatCapabilityHandler.java    From GokiStats with MIT License 4 votes vote down vote up
@SubscribeEvent
public void attachCapability(AttachCapabilitiesEvent<Entity> event) {
    if (!(event.getObject() instanceof EntityPlayer)) return;
    event.addCapability(new ResourceLocation(Reference.MODID, "stat_container"), new CapabilityStat.Provider());
}
 
Example 17
Source File: EntityEventHandler.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void onAttachCapabilitiesEntity(AttachCapabilitiesEvent<Entity> event)
{
    event.addCapability(EnderUtilitiesCapabilities.PORTAL_COOLDOWN_CAP_NAME, new PortalCooldownCapabilityProvider());
}
 
Example 18
Source File: GTWorldGenCapability.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public static void attachChunkCapabilities(AttachCapabilitiesEvent<Chunk> event) {
    event.addCapability(CAPABILITY_ID, new WorldGenCapabilityProvider());
}
 
Example 19
Source File: SquashableMod.java    From CommunityMod with GNU Lesser General Public License v2.1 4 votes vote down vote up
@SubscribeEvent
public static void onAttachEntityCapabilities(AttachCapabilitiesEvent<Entity> event) {
    event.addCapability(new ResourceLocation(CommunityGlobals.MOD_ID, "squashable"), new Squashable());
}