类 ComponentEnergyStorage
java.lang.Object
net.neoforged.neoforge.energy.ComponentEnergyStorage
- 所有已实现的接口:
IEnergyStorage
Variant of
EnergyStorage
for use with data components.
The actual data storage is managed by a data component, and all changes will write back to that component.
To use this class, register a new DataComponentType
which holds an Integer
for your item.
Then reference that component from your ICapabilityProvider
passed to RegisterCapabilitiesEvent.registerItem(net.neoforged.neoforge.capabilities.ItemCapability<T, C>, net.neoforged.neoforge.capabilities.ICapabilityProvider<net.minecraft.world.item.ItemStack, C, T>, net.minecraft.world.level.ItemLike...)
to create an instance of this class.
-
字段概要
字段修饰符和类型字段说明protected final int
protected final DataComponentType
<Integer> protected final int
protected final int
protected final MutableDataComponentHolder
-
构造器概要
构造器构造器说明ComponentEnergyStorage
(MutableDataComponentHolder parent, DataComponentType<Integer> energyComponent, int capacity) Creates a new ItemEnergyStorage with a transfer rate equivalent to the capacity.ComponentEnergyStorage
(MutableDataComponentHolder parent, DataComponentType<Integer> energyComponent, int capacity, int maxTransfer) Creates a new ItemEnergyStorage with a unified receive / extract rate.ComponentEnergyStorage
(MutableDataComponentHolder parent, DataComponentType<Integer> energyComponent, int capacity, int maxReceive, int maxExtract) Creates a new ComponentEnergyStorage with a data component as the backing store for the energy value. -
方法概要
修饰符和类型方法说明boolean
Returns if this storage can have energy extracted.boolean
Used to determine if this storage can receive energy.int
extractEnergy
(int toExtract, boolean simulate) Removes energy from the storage.int
Returns the amount of energy currently stored.int
Returns the maximum amount of energy that can be stored.int
receiveEnergy
(int toReceive, boolean simulate) Adds energy to the storage.protected void
setEnergy
(int energy) Writes a new energy value to the data component.
-
字段详细资料
-
parent
-
energyComponent
-
capacity
protected final int capacity -
maxReceive
protected final int maxReceive -
maxExtract
protected final int maxExtract
-
-
构造器详细资料
-
ComponentEnergyStorage
public ComponentEnergyStorage(MutableDataComponentHolder parent, DataComponentType<Integer> energyComponent, int capacity, int maxReceive, int maxExtract) Creates a new ComponentEnergyStorage with a data component as the backing store for the energy value.- 参数:
parent
- The parent component holder, such as anItemStack
energyComponent
- The data component referencing the stored energy of the item stackcapacity
- The max capacity of the energy being storedmaxReceive
- The max per-transfer power input ratemaxExtract
- The max per-transfer power output rate
-
ComponentEnergyStorage
public ComponentEnergyStorage(MutableDataComponentHolder parent, DataComponentType<Integer> energyComponent, int capacity, int maxTransfer) Creates a new ItemEnergyStorage with a unified receive / extract rate.- 另请参阅:
-
ComponentEnergyStorage
public ComponentEnergyStorage(MutableDataComponentHolder parent, DataComponentType<Integer> energyComponent, int capacity) Creates a new ItemEnergyStorage with a transfer rate equivalent to the capacity.- 另请参阅:
-
-
方法详细资料
-
receiveEnergy
public int receiveEnergy(int toReceive, boolean simulate) 从接口复制的说明:IEnergyStorage
Adds energy to the storage. Returns the amount of energy that was accepted.- 指定者:
receiveEnergy
在接口中IEnergyStorage
- 参数:
toReceive
- The amount of energy being received.simulate
- If true, the insertion will only be simulated, meaningIEnergyStorage.getEnergyStored()
will not change.- 返回:
- Amount of energy that was (or would have been, if simulated) accepted by the storage.
-
extractEnergy
public int extractEnergy(int toExtract, boolean simulate) 从接口复制的说明:IEnergyStorage
Removes energy from the storage. Returns the amount of energy that was removed.- 指定者:
extractEnergy
在接口中IEnergyStorage
- 参数:
toExtract
- The amount of energy being extracted.simulate
- If true, the extraction will only be simulated, meaningIEnergyStorage.getEnergyStored()
will not change.- 返回:
- Amount of energy that was (or would have been, if simulated) extracted from the storage.
-
getEnergyStored
public int getEnergyStored()从接口复制的说明:IEnergyStorage
Returns the amount of energy currently stored.- 指定者:
getEnergyStored
在接口中IEnergyStorage
-
getMaxEnergyStored
public int getMaxEnergyStored()从接口复制的说明:IEnergyStorage
Returns the maximum amount of energy that can be stored.- 指定者:
getMaxEnergyStored
在接口中IEnergyStorage
-
canExtract
public boolean canExtract()从接口复制的说明:IEnergyStorage
Returns if this storage can have energy extracted. If this is false, then any calls to extractEnergy will return 0.- 指定者:
canExtract
在接口中IEnergyStorage
-
canReceive
public boolean canReceive()从接口复制的说明:IEnergyStorage
Used to determine if this storage can receive energy. If this is false, then any calls to receiveEnergy will return 0.- 指定者:
canReceive
在接口中IEnergyStorage
-
setEnergy
protected void setEnergy(int energy) Writes a new energy value to the data component. Clamps to [0, capacity]- 参数:
energy
- The new energy value
-