net.minecraftforge.event.AttachCapabilitiesEvent Java Examples

The following examples show how to use net.minecraftforge.event.AttachCapabilitiesEvent. 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 IUpgradableBlock && event.getObject() instanceof TileEntityBase) {
		TileEntityBase chest = (TileEntityBase) event.getObject();
		chest.addElement(new IC2EnergyElement(chest));
	}
}
 
Example #4
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 #5
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 #6
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 #7
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 #8
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 #9
Source File: CyberwareDataHandler.java    From Cyberware with MIT License 5 votes vote down vote up
@SubscribeEvent
public void attachCyberwareData(AttachCapabilitiesEvent.Entity event)
{
	if (event.getEntity() instanceof EntityPlayer)
	{
		event.addCapability(CyberwareUserDataImpl.Provider.NAME, new CyberwareUserDataImpl.Provider());
	}
}
 
Example #10
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 #11
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 #12
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 #13
Source File: BaseCapabilityProvider.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void gatherCapabilities(@Nullable ICapabilityProvider parent) {
	AttachCapabilitiesEvent<T> event = new AttachCapabilitiesEvent<>(baseClass, provider);
	MinecraftForge.EVENT_BUS.post(event);

	if (!event.getCapabilities().isEmpty() || parent != null) {
		capabilities = new CapabilityDispatcher(event.getCapabilities(), event.getListeners(), parent);
	} else {
		capabilities = null;
	}
}
 
Example #14
Source File: CapabilityProvider.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void gatherCapabilities(@Nullable ICapabilityProvider parent) {
	AttachCapabilitiesEvent<B> event = new AttachCapabilitiesEvent<>(baseClass, (B) this);
	MinecraftForge.EVENT_BUS.post(event);

	if (!event.getCapabilities().isEmpty() || parent != null) {
		capabilities = new CapabilityDispatcher(event.getCapabilities(), event.getListeners(), parent);
	} else {
		capabilities = null;
	}
}
 
Example #15
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 #16
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 #17
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 #18
Source File: EventHandler.java    From Signals with GNU General Public License v3.0 4 votes vote down vote up
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onCapabilityAttachmentTile(AttachCapabilitiesEvent<TileEntity> event){
    RailManager.getInstance().onTileEntityCapabilityAttachEvent(event);
}
 
Example #19
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 #20
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 #21
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 #22
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 #23
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 #24
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());
}