Class PartStateBase<P extends IPartType>
java.lang.Object
org.cyclops.integrateddynamics.core.part.PartStateBase<P>
- All Implemented Interfaces:
org.cyclops.cyclopscore.persist.IDirtyMarkListener
,IPartState<P>
- Direct Known Subclasses:
PartStateActiveVariableBase
,PartStateEmpty
,PartStateReaderBase
,PartTypeConnector.State
public abstract class PartStateBase<P extends IPartType>
extends Object
implements IPartState<P>, org.cyclops.cyclopscore.persist.IDirtyMarkListener
A default implementation of the
IPartState
.-
Field Summary
Fields inherited from interface org.cyclops.integrateddynamics.api.part.IPartState
GLOBALCOUNTER_KEY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<T> void
addVolatileCapability
(PartCapability<T> capability, Optional<T> value) Add a capability to this state that will not be automatically persisted to NBT.void
Clear all named inventories.void
Set a flag indicating that the next time thatIPartType.shouldTriggerBlockRenderUpdate(IPartState, IPartState)
is queried, it should return true.void
gatherCapabilities
(P partType) Gathers the capabilities of this part state.void
Generate a server-wide unique ID for this part state.getAspectProperties
(IAspect aspect) Get the properties for the given aspect.<T> Optional
<T> getCapability
(P partType, PartCapability<T> capability, INetwork network, IPartNetwork partNetwork, PartTarget target) Get the given capability.int
protected int
int
getId()
A server-wide unique ID for this part that is persisted when the part is broken and moved.net.minecraft.core.NonNullList
<net.minecraft.world.item.ItemStack> getInventoryNamed
(String name) int
net.minecraft.network.chat.MutableComponent
getOffsetVariableError
(int slot) int
net.minecraft.core.Vec3i
net.minecraft.core.Direction
int
void
initializeOffsets
(PartTarget target) Run the initialization logic for offset handling.boolean
Check if dirty and reset the dirty state.boolean
boolean
boolean
Check if this part state should update and reset the flag.void
Indicate that this state has changes that must be saved to the world.void
Indicate that the contents of the offset variables inventory have changed.void
onDirty()
void
readAspectProperties
(ValueDeseralizationContext valueDeseralizationContext, String name, net.minecraft.nbt.CompoundTag tag) void
readFromNBT
(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.nbt.CompoundTag tag) Read a state from NBT.void
removeVolatileCapability
(PartCapability<?> capability) Remove a non-persisted capability.boolean
void
Enables a flag that tells the part container to send an NBT update to the client(s).void
setAspectProperties
(IAspect aspect, IAspectProperties properties) Set the properties for the given aspect.void
setChannel
(int channel) Set the channel for this state.void
setEnabled
(boolean enabled) Enable the part from working.void
setInventoryNamed
(String name, net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack> inventory) Set the inventory of the given name.void
setMaxOffset
(int maxOffset) Update the max offset for this part.void
setPriority
(int priority) Set the priority of this part in the network.void
setTargetOffset
(net.minecraft.core.Vec3i targetOffset) void
setTargetSideOverride
(net.minecraft.core.Direction targetSide) Indicate that the given part should interact with the given side of the target.void
setUpdateInterval
(int updateInterval) Set the update interval for this state.void
updateOffsetVariables
(P partType, INetwork network, IPartNetwork partNetwork, PartTarget target) Tick any internal offset variables.protected void
writeAspectProperties
(ValueDeseralizationContext valueDeseralizationContext, String name, net.minecraft.nbt.CompoundTag tag) void
writeToNBT
(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.nbt.CompoundTag tag) Write a state to NBT.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.cyclops.integrateddynamics.api.part.IPartState
loadInventoryNamed, saveInventoryNamed
-
Constructor Details
-
PartStateBase
public PartStateBase()
-
-
Method Details
-
writeToNBT
public void writeToNBT(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.nbt.CompoundTag tag) Description copied from interface:IPartState
Write a state to NBT.- Specified by:
writeToNBT
in interfaceIPartState<P extends IPartType>
- Parameters:
valueDeseralizationContext
-tag
- The tag to write to.
-
readFromNBT
public void readFromNBT(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.nbt.CompoundTag tag) Description copied from interface:IPartState
Read a state from NBT.- Specified by:
readFromNBT
in interfaceIPartState<P extends IPartType>
- Parameters:
valueDeseralizationContext
- Getter for blocks.tag
- The tag to read from.
-
writeAspectProperties
protected void writeAspectProperties(ValueDeseralizationContext valueDeseralizationContext, String name, net.minecraft.nbt.CompoundTag tag) -
readAspectProperties
public void readAspectProperties(ValueDeseralizationContext valueDeseralizationContext, String name, net.minecraft.nbt.CompoundTag tag) -
generateId
public void generateId()Description copied from interface:IPartState
Generate a server-wide unique ID for this part state.- Specified by:
generateId
in interfaceIPartState<P extends IPartType>
-
getId
public int getId()Description copied from interface:IPartState
A server-wide unique ID for this part that is persisted when the part is broken and moved.- Specified by:
getId
in interfaceIPartState<P extends IPartType>
- Returns:
- The unique ID
-
setUpdateInterval
public void setUpdateInterval(int updateInterval) Description copied from interface:IPartState
Set the update interval for this state.- Specified by:
setUpdateInterval
in interfaceIPartState<P extends IPartType>
- Parameters:
updateInterval
- The tick interval to update this element.
-
getUpdateInterval
public int getUpdateInterval()- Specified by:
getUpdateInterval
in interfaceIPartState<P extends IPartType>
- Returns:
- The tick interval to update this element.
-
setPriority
public void setPriority(int priority) Description copied from interface:IPartState
Set the priority of this part in the network.- Specified by:
setPriority
in interfaceIPartState<P extends IPartType>
- Parameters:
priority
- The new priority
-
getPriority
public int getPriority()- Specified by:
getPriority
in interfaceIPartState<P extends IPartType>
- Returns:
- The priority of this part in the network.
-
setChannel
public void setChannel(int channel) Description copied from interface:IPartState
Set the channel for this state.- Specified by:
setChannel
in interfaceIPartState<P extends IPartType>
- Parameters:
channel
- The new channel
-
getChannel
public int getChannel()- Specified by:
getChannel
in interfaceIPartState<P extends IPartType>
- Returns:
- This part's channel.
-
getTargetOffset
public net.minecraft.core.Vec3i getTargetOffset()- Specified by:
getTargetOffset
in interfaceIPartState<P extends IPartType>
- Returns:
- The target position offset.
-
setTargetOffset
public void setTargetOffset(net.minecraft.core.Vec3i targetOffset) - Specified by:
setTargetOffset
in interfaceIPartState<P extends IPartType>
- Parameters:
targetOffset
- The target position offset.
-
setTargetSideOverride
public void setTargetSideOverride(net.minecraft.core.Direction targetSide) Description copied from interface:IPartState
Indicate that the given part should interact with the given side of the target.- Specified by:
setTargetSideOverride
in interfaceIPartState<P extends IPartType>
- Parameters:
targetSide
- The side of the target block to interact with. Null removes the side override.
-
getTargetSideOverride
@Nullable public net.minecraft.core.Direction getTargetSideOverride()- Specified by:
getTargetSideOverride
in interfaceIPartState<P extends IPartType>
- Returns:
- The side of the target block to interact with. Can be null.
-
markDirty
public void markDirty()Description copied from interface:IPartState
Indicate that this state has changes that must be saved to the world.- Specified by:
markDirty
in interfaceIPartState<P extends IPartType>
-
isDirtyAndReset
public boolean isDirtyAndReset()Description copied from interface:IPartState
Check if dirty and reset the dirty state.- Specified by:
isDirtyAndReset
in interfaceIPartState<P extends IPartType>
- Returns:
- If this state has changed since the last time and needs to be persisted to NBT eventually.
-
isUpdateAndReset
public boolean isUpdateAndReset()Description copied from interface:IPartState
Check if this part state should update and reset the flag.- Specified by:
isUpdateAndReset
in interfaceIPartState<P extends IPartType>
- Returns:
- If this state has changed since the last time and needs to be updated to the client.
-
forceBlockRenderUpdate
public void forceBlockRenderUpdate()Description copied from interface:IPartState
Set a flag indicating that the next time thatIPartType.shouldTriggerBlockRenderUpdate(IPartState, IPartState)
is queried, it should return true. This is useful in cases where the player makes changes inside a part, the state difference checking can not be relied upon, and a state update should be forced in any case. This should only be called client-side.- Specified by:
forceBlockRenderUpdate
in interfaceIPartState<P extends IPartType>
-
isForceBlockRenderUpdateAndReset
public boolean isForceBlockRenderUpdateAndReset()- Specified by:
isForceBlockRenderUpdateAndReset
in interfaceIPartState<P extends IPartType>
- Returns:
- If a block render update is forced. This flagged will be set to false after this method is called. This should only be called client-side.
-
onDirty
public void onDirty()- Specified by:
onDirty
in interfaceorg.cyclops.cyclopscore.persist.IDirtyMarkListener
-
sendUpdate
public void sendUpdate()Enables a flag that tells the part container to send an NBT update to the client(s). -
getAspectProperties
Description copied from interface:IPartState
Get the properties for the given aspect. This will only retrieve the already saved properties, so this could be null if not set before. It is better to call theIAspect.getProperties(IPartType, PartTarget, IPartState)
method instead.- Specified by:
getAspectProperties
in interfaceIPartState<P extends IPartType>
- Parameters:
aspect
- The aspect to get the properties from.- Returns:
- The properties, this can be null if still the default.
-
setAspectProperties
Description copied from interface:IPartState
Set the properties for the given aspect.- Specified by:
setAspectProperties
in interfaceIPartState<P extends IPartType>
- Parameters:
aspect
- The aspect to get the properties from.properties
- The properties, this can be null if still the default.
-
setEnabled
public void setEnabled(boolean enabled) Description copied from interface:IPartState
Enable the part from working.- Specified by:
setEnabled
in interfaceIPartState<P extends IPartType>
- Parameters:
enabled
- If it should work.
-
isEnabled
public boolean isEnabled()- Specified by:
isEnabled
in interfaceIPartState<P extends IPartType>
- Returns:
- If the part should work.
-
getInventoryNamed
public net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack> getInventoryNamed(String name) - Specified by:
getInventoryNamed
in interfaceIPartState<P extends IPartType>
- Parameters:
name
- The inventory name.- Returns:
- Get the inventory contents of the given name.
-
setInventoryNamed
public void setInventoryNamed(String name, net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack> inventory) Description copied from interface:IPartState
Set the inventory of the given name.- Specified by:
setInventoryNamed
in interfaceIPartState<P extends IPartType>
- Parameters:
name
- The inventory name.inventory
- Inventory contents.
-
getInventoriesNamed
public Map<String,net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack>> getInventoriesNamed()- Specified by:
getInventoriesNamed
in interfaceIPartState<P extends IPartType>
- Returns:
- All named inventories.
-
clearInventoriesNamed
public void clearInventoriesNamed()Description copied from interface:IPartState
Clear all named inventories.- Specified by:
clearInventoriesNamed
in interfaceIPartState<P extends IPartType>
-
gatherCapabilities
Gathers the capabilities of this part state. Don't call this unless you know what you're doing!- Specified by:
gatherCapabilities
in interfaceIPartState<P extends IPartType>
- Parameters:
partType
- The part type this state is associated with.
-
getCapability
public <T> Optional<T> getCapability(P partType, PartCapability<T> capability, INetwork network, IPartNetwork partNetwork, PartTarget target) Description copied from interface:IPartState
Get the given capability.- Specified by:
getCapability
in interfaceIPartState<P extends IPartType>
- Type Parameters:
T
- The capability type.- Parameters:
partType
- The part type.capability
- The capability to get.network
- The network the part belongs to.partNetwork
- The part network the part belongs to.target
- The target.- Returns:
- The optional capability instance.
-
addVolatileCapability
Description copied from interface:IPartState
Add a capability to this state that will not be automatically persisted to NBT.- Specified by:
addVolatileCapability
in interfaceIPartState<P extends IPartType>
- Type Parameters:
T
- The capability type.- Parameters:
capability
- The optional capability.value
- The capability instance.
-
removeVolatileCapability
Description copied from interface:IPartState
Remove a non-persisted capability.- Specified by:
removeVolatileCapability
in interfaceIPartState<P extends IPartType>
- Parameters:
capability
- The capability.
-
getDefaultUpdateInterval
protected int getDefaultUpdateInterval() -
initializeOffsets
Description copied from interface:IPartState
Run the initialization logic for offset handling.- Specified by:
initializeOffsets
in interfaceIPartState<P extends IPartType>
-
updateOffsetVariables
public void updateOffsetVariables(P partType, INetwork network, IPartNetwork partNetwork, PartTarget target) Description copied from interface:IPartState
Tick any internal offset variables.- Specified by:
updateOffsetVariables
in interfaceIPartState<P extends IPartType>
- Parameters:
partType
- The part type.network
- The network.partNetwork
- The part network.target
- The part target.
-
getOffsetVariableError
@Nullable public net.minecraft.network.chat.MutableComponent getOffsetVariableError(int slot) - Specified by:
getOffsetVariableError
in interfaceIPartState<P extends IPartType>
- Parameters:
slot
- The offset variable slot.- Returns:
- The current error, or null if no error.
-
requiresOffsetUpdates
public boolean requiresOffsetUpdates()- Specified by:
requiresOffsetUpdates
in interfaceIPartState<P extends IPartType>
- Returns:
- If the part contains variable-driven offsets that require updating.
-
markOffsetVariablesChanged
public void markOffsetVariablesChanged()Description copied from interface:IPartState
Indicate that the contents of the offset variables inventory have changed.- Specified by:
markOffsetVariablesChanged
in interfaceIPartState<P extends IPartType>
-
getMaxOffset
public int getMaxOffset()- Specified by:
getMaxOffset
in interfaceIPartState<P extends IPartType>
- Returns:
- The max offset allowed in this part.
-
setMaxOffset
public void setMaxOffset(int maxOffset) Description copied from interface:IPartState
Update the max offset for this part.- Specified by:
setMaxOffset
in interfaceIPartState<P extends IPartType>
- Parameters:
maxOffset
- The new offset.
-