Search in sources :

Example 1 with ItemCapabilityWrapper

use of mekanism.common.capabilities.ItemCapabilityWrapper in project Mekanism by mekanism.

the class ItemMekaSuitArmor method initCapabilities.

@Override
public ICapabilityProvider initCapabilities(ItemStack stack, CompoundNBT nbt) {
    stack.hideTooltipPart(TooltipDisplayFlags.MODIFIERS);
    // Note: We interact with this capability using "manual" as the automation type, to ensure we can properly bypass the energy limit for extracting
    // Internal is used by the "null" side, which is what will get used for most items
    ItemCapabilityWrapper wrapper = new ItemCapabilityWrapper(stack, RateLimitEnergyHandler.create(() -> getChargeRate(stack), () -> getMaxEnergy(stack), BasicEnergyContainer.manualOnly, BasicEnergyContainer.alwaysTrue), RadiationShieldingHandler.create(item -> isModuleEnabled(item, MekanismModules.RADIATION_SHIELDING_UNIT) ? ItemHazmatSuitArmor.getShieldingByArmor(slot) : 0), LaserDissipationHandler.create(item -> isModuleEnabled(item, MekanismModules.LASER_DISSIPATION_UNIT) ? laserDissipation : 0, item -> isModuleEnabled(item, MekanismModules.LASER_DISSIPATION_UNIT) ? laserRefraction : 0));
    if (!gasTankSpecs.isEmpty()) {
        wrapper.add(RateLimitMultiTankGasHandler.create(gasTankSpecs));
    }
    return wrapper;
}
Also used : Gas(mekanism.api.chemical.gas.Gas) Arrays(java.util.Arrays) AutomationType(mekanism.api.inventory.AutomationType) ICustomModule(mekanism.api.gear.ICustomModule) CompoundNBT(net.minecraft.nbt.CompoundNBT) Dist(net.minecraftforge.api.distmarker.Dist) ItemCapabilityWrapper(mekanism.common.capabilities.ItemCapabilityWrapper) Capabilities(mekanism.common.capabilities.Capabilities) MekaSuitArmor(mekanism.client.render.armor.MekaSuitArmor) GasStack(mekanism.api.chemical.gas.GasStack) Module(mekanism.common.content.gear.Module) NonNullList(net.minecraft.util.NonNullList) ArmorMaterial(net.minecraft.item.ArmorMaterial) RadiationShieldingHandler(mekanism.common.capabilities.radiation.item.RadiationShieldingHandler) LaserDissipationHandler(mekanism.common.capabilities.laser.item.LaserDissipationHandler) IModule(mekanism.api.gear.IModule) PlayerEntity(net.minecraft.entity.player.PlayerEntity) BasicEnergyContainer(mekanism.common.capabilities.energy.BasicEnergyContainer) LivingEntity(net.minecraft.entity.LivingEntity) CustomArmor(mekanism.client.render.armor.CustomArmor) Set(java.util.Set) StorageUtils(mekanism.common.util.StorageUtils) FloatSupplier(mekanism.api.functions.FloatSupplier) RateLimitEnergyHandler(mekanism.common.capabilities.energy.item.RateLimitEnergyHandler) List(java.util.List) MekKeyHandler(mekanism.client.key.MekKeyHandler) MekanismGases(mekanism.common.registries.MekanismGases) IModuleContainerItem(mekanism.common.content.gear.IModuleContainerItem) ItemGroup(net.minecraft.item.ItemGroup) Optional(java.util.Optional) MekanismLang(mekanism.common.MekanismLang) ModuleEnergyUnit(mekanism.common.content.gear.shared.ModuleEnergyUnit) ModuleJetpackUnit(mekanism.common.content.gear.mekasuit.ModuleJetpackUnit) IGasHandler(mekanism.api.chemical.gas.IGasHandler) EnumColor(mekanism.api.text.EnumColor) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) ICapabilityProvider(net.minecraftforge.common.capabilities.ICapabilityProvider) ITooltipFlag(net.minecraft.client.util.ITooltipFlag) ModuleDamageAbsorbInfo(mekanism.api.gear.ICustomModule.ModuleDamageAbsorbInfo) ArrayList(java.util.ArrayList) EndermanEntity(net.minecraft.entity.monster.EndermanEntity) ITextComponent(net.minecraft.util.text.ITextComponent) HashSet(java.util.HashSet) JetpackMode(mekanism.common.item.gear.ItemJetpack.JetpackMode) ItemStack(net.minecraft.item.ItemStack) GasTankSpec(mekanism.common.capabilities.chemical.item.RateLimitMultiTankGasHandler.GasTankSpec) FloatingLong(mekanism.api.math.FloatingLong) Rarity(net.minecraft.item.Rarity) IEnergyContainer(mekanism.api.energy.IEnergyContainer) MekanismModules(mekanism.common.registries.MekanismModules) Nonnull(javax.annotation.Nonnull) LinkedHashSet(java.util.LinkedHashSet) Nullable(javax.annotation.Nullable) Mekanism(mekanism.common.Mekanism) IModeItem(mekanism.common.item.interfaces.IModeItem) TooltipDisplayFlags(net.minecraft.item.ItemStack.TooltipDisplayFlags) World(net.minecraft.world.World) MekanismKeyHandler(mekanism.client.key.MekanismKeyHandler) DamageSource(net.minecraft.util.DamageSource) Consumer(java.util.function.Consumer) EquipmentSlotType(net.minecraft.inventory.EquipmentSlotType) Collections(java.util.Collections) Action(mekanism.api.Action) MekanismConfig(mekanism.common.config.MekanismConfig) FloatingLongSupplier(mekanism.api.math.FloatingLongSupplier) RateLimitMultiTankGasHandler(mekanism.common.capabilities.chemical.item.RateLimitMultiTankGasHandler) ItemCapabilityWrapper(mekanism.common.capabilities.ItemCapabilityWrapper)

Example 2 with ItemCapabilityWrapper

use of mekanism.common.capabilities.ItemCapabilityWrapper in project Mekanism by mekanism.

the class ItemBlockMachine method initCapabilities.

@Override
public ICapabilityProvider initCapabilities(ItemStack stack, CompoundNBT nbt) {
    if (Attribute.has(getBlock(), AttributeEnergy.class)) {
        AttributeEnergy attributeEnergy = Attribute.get(getBlock(), AttributeEnergy.class);
        FloatingLongSupplier maxEnergy;
        if (Attribute.has(getBlock(), AttributeUpgradeSupport.class)) {
            // If our block supports upgrades, make a more dynamically updating cache for our item's max energy
            maxEnergy = new UpgradeBasedFloatingLongCache(stack, attributeEnergy::getStorage);
        } else {
            // Otherwise, just return that the max is what the base max is
            maxEnergy = attributeEnergy::getStorage;
        }
        return new ItemCapabilityWrapper(stack, RateLimitEnergyHandler.create(maxEnergy, BasicEnergyContainer.manualOnly, BasicEnergyContainer.alwaysTrue));
    }
    return super.initCapabilities(stack, nbt);
}
Also used : FloatingLongSupplier(mekanism.api.math.FloatingLongSupplier) ItemCapabilityWrapper(mekanism.common.capabilities.ItemCapabilityWrapper) AttributeEnergy(mekanism.common.block.attribute.AttributeEnergy)

Aggregations

FloatingLongSupplier (mekanism.api.math.FloatingLongSupplier)2 ItemCapabilityWrapper (mekanism.common.capabilities.ItemCapabilityWrapper)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Consumer (java.util.function.Consumer)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 Action (mekanism.api.Action)1 Gas (mekanism.api.chemical.gas.Gas)1 GasStack (mekanism.api.chemical.gas.GasStack)1 IGasHandler (mekanism.api.chemical.gas.IGasHandler)1 IEnergyContainer (mekanism.api.energy.IEnergyContainer)1 FloatSupplier (mekanism.api.functions.FloatSupplier)1 ICustomModule (mekanism.api.gear.ICustomModule)1