Record Class WrappedBlockEnergyContainer
java.lang.Object
java.lang.Record
earth.terrarium.botarium.common.energy.impl.WrappedBlockEnergyContainer
- Record Components:
blockEntity- The block entity.container- The wrapped energy container. Botarium provides a default implementation for this withSimpleEnergyContainer.
- All Implemented Interfaces:
EnergyContainer,Serializable,Updatable,net.minecraft.world.Clearable
public record WrappedBlockEnergyContainer(net.minecraft.world.level.block.entity.BlockEntity blockEntity, EnergyContainer container)
extends Record
implements EnergyContainer, Updatable
Represents a wrapped energy container for a block entity.
This class implements the EnergyContainer interface and the Updatable interface.
It delegates energy-related operations to the wrapped energy container, and updates the block entity when the energy is changed.
-
Constructor Summary
ConstructorsConstructorDescriptionWrappedBlockEnergyContainer(net.minecraft.world.level.block.entity.BlockEntity blockEntity, EnergyContainer container) Creates an instance of aWrappedBlockEnergyContainerrecord class. -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleannet.minecraft.world.level.block.entity.BlockEntityReturns the value of theblockEntityrecord component.voidReturns the value of thecontainerrecord component.voiddeserialize(net.minecraft.nbt.CompoundTag nbt) Deserializes the information of an object from aCompoundTag.final booleanIndicates whether some other object is "equal to" this one.longextractEnergy(long energy, boolean simulate) Extracts a given amount of energy into the container.longlongfinal inthashCode()Returns a hash code value for this object.longinsertEnergy(long energy, boolean simulate) Inserts a given amount of energy into the container.longinternalExtract(long amount, boolean simulate) An internal version ofEnergyContainer.extractEnergy(long, boolean)that is used by mod authors looking to directly interact with their own containers.longinternalInsert(long amount, boolean simulate) An internal version ofEnergyContainer.insertEnergy(long, boolean)that is used by mod authors looking to directly interact with their own containers.longlongnet.minecraft.nbt.CompoundTagserialize(net.minecraft.nbt.CompoundTag nbt) Serializes the information of an object to aCompoundTag.voidsetEnergy(long energy) Sets a given amount of energy in the container.final StringtoString()Returns a string representation of this record class.voidupdate()Called when the operation has been completed and the data has been updated.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface earth.terrarium.botarium.common.energy.base.EnergyContainer
readSnapshot
-
Constructor Details
-
WrappedBlockEnergyContainer
public WrappedBlockEnergyContainer(net.minecraft.world.level.block.entity.BlockEntity blockEntity, EnergyContainer container) Creates an instance of aWrappedBlockEnergyContainerrecord class.- Parameters:
blockEntity- the value for theblockEntityrecord componentcontainer- the value for thecontainerrecord component
-
-
Method Details
-
insertEnergy
public long insertEnergy(long energy, boolean simulate) Description copied from interface:EnergyContainerInserts a given amount of energy into the container.- Specified by:
insertEnergyin interfaceEnergyContainer- Parameters:
energy- The amount to be inserted into the container.simulate- If true, the container will not be modified.- Returns:
- The amount of energy that was added to the container.
-
extractEnergy
public long extractEnergy(long energy, boolean simulate) Description copied from interface:EnergyContainerExtracts a given amount of energy into the container.- Specified by:
extractEnergyin interfaceEnergyContainer- Parameters:
energy- The amount to be extracted from the container.simulate- If true, the container will not be modified.- Returns:
- The amount of energy that was removed from the container.
-
internalInsert
public long internalInsert(long amount, boolean simulate) Description copied from interface:EnergyContainerAn internal version ofEnergyContainer.insertEnergy(long, boolean)that is used by mod authors looking to directly interact with their own containers.You should not call this method for other mod's containers, instead use
EnergyContainer.insertEnergy(long, boolean).- Specified by:
internalInsertin interfaceEnergyContainer
-
internalExtract
public long internalExtract(long amount, boolean simulate) Description copied from interface:EnergyContainerAn internal version ofEnergyContainer.extractEnergy(long, boolean)that is used by mod authors looking to directly interact with their own containers.You should not call this method for other mod's containers, instead use
EnergyContainer.extractEnergy(long, boolean).- Specified by:
internalExtractin interfaceEnergyContainer
-
setEnergy
public void setEnergy(long energy) Description copied from interface:EnergyContainerSets a given amount of energy in the container.- Specified by:
setEnergyin interfaceEnergyContainer- Parameters:
energy- The amount of energy to set in the container.
-
getStoredEnergy
public long getStoredEnergy()- Specified by:
getStoredEnergyin interfaceEnergyContainer- Returns:
- The amount of energy in the container.
-
getMaxCapacity
public long getMaxCapacity()- Specified by:
getMaxCapacityin interfaceEnergyContainer- Returns:
- The maximum amount of energy that can be stored in the container.
-
maxInsert
public long maxInsert()- Specified by:
maxInsertin interfaceEnergyContainer- Returns:
- The maximum amount of energy that can be inserted into the container at a time.
-
maxExtract
public long maxExtract()- Specified by:
maxExtractin interfaceEnergyContainer- Returns:
- The maximum amount of energy that can be extracted from the container at a time.
-
allowsInsertion
public boolean allowsInsertion()- Specified by:
allowsInsertionin interfaceEnergyContainer- Returns:
- Whether the container allows for energy to be inserted.
-
allowsExtraction
public boolean allowsExtraction()- Specified by:
allowsExtractionin interfaceEnergyContainer- Returns:
- Whether the container allows for energy to be extracted.
-
createSnapshot
- Specified by:
createSnapshotin interfaceEnergyContainer- Returns:
- A
EnergySnapshotof the given state of theEnergyContainer.
-
deserialize
public void deserialize(net.minecraft.nbt.CompoundTag nbt) Description copied from interface:SerializableDeserializes the information of an object from aCompoundTag.- Specified by:
deserializein interfaceSerializable- Parameters:
nbt- TheCompoundTagto deserialize from.
-
serialize
public net.minecraft.nbt.CompoundTag serialize(net.minecraft.nbt.CompoundTag nbt) Description copied from interface:SerializableSerializes the information of an object to aCompoundTag.- Specified by:
serializein interfaceSerializable- Parameters:
nbt- TheCompoundTagto serialize to.- Returns:
- The
CompoundTagthat was passed in but with the information of the object serialized added to it.
-
update
public void update()Description copied from interface:UpdatableCalled when the operation has been completed and the data has been updated. -
clearContent
public void clearContent()- Specified by:
clearContentin interfacenet.minecraft.world.Clearable
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
blockEntity
public net.minecraft.world.level.block.entity.BlockEntity blockEntity()Returns the value of theblockEntityrecord component.- Returns:
- the value of the
blockEntityrecord component
-
container
Returns the value of thecontainerrecord component.- Returns:
- the value of the
containerrecord component
-