net.minecraftforge.common.capabilities.ICapabilityProvider Java Examples
The following examples show how to use
net.minecraftforge.common.capabilities.ICapabilityProvider.
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: RailManager.java From Signals with GNU General Public License v3.0 | 6 votes |
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 #2
Source File: GlassBottleFluidHandler.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
private IFluidHandlerItem getNextInChain() { if(rawCapabilityProviders != null) { boolean foundMyself = false; for(ICapabilityProvider provider : rawCapabilityProviders) { IFluidHandlerItem fluidHandlerItem = provider.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); if(fluidHandlerItem != null) { if(fluidHandlerItem == this) { foundMyself = true; } else if(foundMyself) { this.nextHandlerInChain = fluidHandlerItem; break; } } } this.rawCapabilityProviders = null; } return nextHandlerInChain; }
Example #3
Source File: BaseCapabilityProvider.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
@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 #4
Source File: CapabilityProtectiveArmor.java From AdvancedRocketry with MIT License | 5 votes |
@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 #5
Source File: ItemWithSubtypesMixin.java From customstuff4 with GNU General Public License v3.0 | 5 votes |
@Nullable @Override public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) { if (!getContent().modules.isEmpty()) { return new CapabilityProviderItem(stack, getContent()); } else { return null; } }
Example #6
Source File: WrapperEvent.java From NOVA-Core with GNU Lesser General Public License v3.0 | 5 votes |
public CapabilityToComponent(ICapabilityProvider capabilities, Class<NOVA> component, Set<NOVA> defaultInstances, Direction direction) { this.capabilities = capabilities; this.component = component; this.defaultInstances = Collections.unmodifiableSet(defaultInstances); this.instances = new HashSet<>(); this.direction = direction; }
Example #7
Source File: ItemBreakingTracker.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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: CombinedCapabilityProvider.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) { for (ICapabilityProvider provider : providers) { if (provider.hasCapability(capability, facing)) { return true; } } return false; }
Example #9
Source File: CombinedCapabilityProvider.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Nullable @Override public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) { for (ICapabilityProvider provider : providers) { T cap = provider.getCapability(capability, facing); if (cap != null) { return cap; } } return null; }
Example #10
Source File: FoamSprayerBehavior.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public ICapabilityProvider createProvider(ItemStack itemStack) { return new FluidHandlerItemStack(itemStack, 10000) { @Override public boolean canFillFluidType(FluidStack fluid) { return fluid != null && fluid.isFluidEqual(Materials.ConstructionFoam.getFluid(1)); } }; }
Example #11
Source File: MetaTileEntityTank.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public ICapabilityProvider initItemStackCapabilities(ItemStack itemStack) { return new FluidHandlerItemStack(itemStack, tankSize) { @Override public boolean canFillFluidType(FluidStack fluid) { return MetaTileEntityTank.this.canFillFluidType(fluid); } }; }
Example #12
Source File: ToolMetaItem.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) { ICapabilityProvider capabilityProvider = super.initCapabilities(stack, nbt); if (capabilityProvider != null && capabilityProvider.hasCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null)) { IElectricItem electricItem = capabilityProvider.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null); //noinspection ConstantConditions electricItem.addChargeListener((itemStack, newCharge) -> { int newDamage = (newCharge == 0 ? 16000 : 0) + itemStack.getItemDamage() % 16000; if (newDamage != itemStack.getItemDamage()) { itemStack.setItemDamage(newDamage); } }); } return capabilityProvider; }
Example #13
Source File: FluidStats.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public ICapabilityProvider createProvider(ItemStack itemStack) { if (allowPartlyFill) { return new ThermalFluidHandlerItemStack(itemStack, maxCapacity, minFluidTemperature, maxFluidTemperature); } return new SimpleThermalFluidHandlerItemStack(itemStack, maxCapacity, minFluidTemperature, maxFluidTemperature); }
Example #14
Source File: MetaItem.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) { T metaValueItem = getItem(stack); if (metaValueItem == null) { return null; } ArrayList<ICapabilityProvider> providers = new ArrayList<>(); for (IMetaItemStats metaItemStats : metaValueItem.getAllStats()) { if (metaItemStats instanceof IItemCapabilityProvider) { IItemCapabilityProvider provider = (IItemCapabilityProvider) metaItemStats; providers.add(provider.createProvider(stack)); } } return new CombinedCapabilityProvider(providers); }
Example #15
Source File: ItemBBagBase.java From BetterChests with GNU Lesser General Public License v3.0 | 4 votes |
@Override public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) { //Added indirection layer, so we can use a BagInventory where the entity is set. return new CapabilityHandlerBag(stack); }
Example #16
Source File: ItemEnderBucket.java From enderutilities with GNU Lesser General Public License v3.0 | 4 votes |
@Override public ICapabilityProvider initCapabilities(ItemStack stack, NBTTagCompound nbt) { return new FluidHandlerEnderBucket(this, stack); }
Example #17
Source File: ItemJar.java From Wizardry with GNU Lesser General Public License v3.0 | 4 votes |
@Nullable @Override public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) { return new ManaCapabilityProvider(new CustomManaCapability(1000, 1000, 0, 0)); }
Example #18
Source File: ItemPearlBelt.java From Wizardry with GNU Lesser General Public License v3.0 | 4 votes |
@Nullable @Override public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) { return new BeltItemHandler(stack); }
Example #19
Source File: NacrePearlSpell.java From Wizardry with GNU Lesser General Public License v3.0 | 4 votes |
@Nullable @Override public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) { return new ManaCapabilityProvider(new CustomManaCapability(300, 300, 0, 0)); }
Example #20
Source File: ItemOrb.java From Wizardry with GNU Lesser General Public License v3.0 | 4 votes |
@Nullable @Override public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) { return new ManaCapabilityProvider(new CustomManaCapability(100, 100, stack.getItemDamage() * 100, 0)); }
Example #21
Source File: CapabilityHandlerBag.java From BetterChests with GNU Lesser General Public License v3.0 | 4 votes |
protected ICapabilityProvider getActualProvider() { return ((ItemBBagBase<?>)stack.getItem()).getInventoryFor(stack, null); }
Example #22
Source File: ItemPressureTank.java From AdvancedRocketry with MIT License | 4 votes |
@Override public ICapabilityProvider initCapabilities(ItemStack stack, NBTTagCompound nbt) { return new TankCapabilityItemStack(stack, getCapacity(stack)); }
Example #23
Source File: CapabilityUtils.java From Levels with GNU General Public License v2.0 | 4 votes |
@Nullable public static <T> T getCapability(@Nullable ICapabilityProvider provider, Capability<T> capability, @Nullable EnumFacing facing) { return provider != null && provider.hasCapability(capability, facing) ? provider.getCapability(capability, facing) : null; }
Example #24
Source File: GTItemFluidTube.java From GT-Classic with GNU Lesser General Public License v3.0 | 4 votes |
@Override public ICapabilityProvider initCapabilities(ItemStack stack, NBTTagCompound nbt) { return new GTFluidItemStackHandler(stack, stack, size); }
Example #25
Source File: GlassBottleFluidHandler.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
public GlassBottleFluidHandler(ItemStack itemStack, Collection<ICapabilityProvider> rawCapabilityProviders) { this.itemStack = itemStack; this.rawCapabilityProviders = rawCapabilityProviders; }
Example #26
Source File: ElectricStats.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
@Override public ICapabilityProvider createProvider(ItemStack itemStack) { return new ElectricItem(itemStack, maxCharge, tier, chargeable, dischargeable); }
Example #27
Source File: SoftMalletItemStat.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
@Override public ICapabilityProvider createProvider(ItemStack itemStack) { return new CapabilityProvider(itemStack); }
Example #28
Source File: ScrewdriverItemStat.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
@Override public ICapabilityProvider createProvider(ItemStack itemStack) { return new CapabilityProvider(itemStack); }
Example #29
Source File: WrenchItemStat.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
@Override public ICapabilityProvider createProvider(ItemStack itemStack) { return new CapabilityProvider(itemStack); }
Example #30
Source File: CombinedCapabilityProvider.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
public CombinedCapabilityProvider(List<ICapabilityProvider> providers) { this.providers = providers.toArray(new ICapabilityProvider[0]); }