Interface IPartState<P extends IPartType>
- All Known Subinterfaces:
IPartStateReader<P>
,IPartStateWriter<P>
- All Known Implementing Classes:
PartStateActiveVariableBase
,PartStateBase
,PartStateEmpty
,PartStateReaderBase
,PartStateWriterBase
,PartTypeConnector.State
,PartTypeConnectorMonoDirectional.State
,PartTypeConnectorOmniDirectional.State
,PartTypePanelDisplay.State
,PartTypePanelLightDynamic.State
,PartTypePanelVariableDriven.State
public interface IPartState<P extends IPartType>
A value holder for an
IPartType
.
This is what will be serialized from and to NBT.
This object is mutable and should not be recreated.
Note that you should be careful when passing around this state, because when the server sends an update to the
client, this state could be overwritten with a new version, so always try to use the part container to get the state.-
Field 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
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.default void
loadInventoryNamed
(String name, net.minecraft.world.Container inventory) Load the inventory of the given name from the part state.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
readFromNBT
(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.nbt.CompoundTag tag) Read a state from NBT.void
removeVolatileCapability
(PartCapability<?> capability) Remove a non-persisted capability.boolean
default void
saveInventoryNamed
(String name, net.minecraft.world.Container inventory) Save the inventory of the given name into the part state.void
setAspectProperties
(IAspect aspect, IAspectProperties properties) Set the properties for the given aspect.void
setChannel
(int channel) Deprecated.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 offset) Update the max offset for this part.void
setPriority
(int priority) Deprecated.Should only be called fromINetwork.setPriorityAndChannel(INetworkElement, int, int)
}!void
setTargetOffset
(net.minecraft.core.Vec3i offset) void
setTargetSideOverride
(net.minecraft.core.Direction side) 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.void
writeToNBT
(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.nbt.CompoundTag tag) Write a state to NBT.
-
Field Details
-
GLOBALCOUNTER_KEY
- See Also:
-
-
Method Details
-
writeToNBT
void writeToNBT(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.nbt.CompoundTag tag) Write a state to NBT.- Parameters:
valueDeseralizationContext
-tag
- The tag to write to.
-
readFromNBT
void readFromNBT(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.nbt.CompoundTag tag) Read a state from NBT.- Parameters:
valueDeseralizationContext
- Getter for blocks.tag
- The tag to read from.
-
generateId
void generateId()Generate a server-wide unique ID for this part state. -
getId
int getId()A server-wide unique ID for this part that is persisted when the part is broken and moved.- Returns:
- The unique ID
-
setUpdateInterval
void setUpdateInterval(int updateInterval) Set the update interval for this state.- Parameters:
updateInterval
- The tick interval to update this element.
-
getUpdateInterval
int getUpdateInterval()- Returns:
- The tick interval to update this element.
-
setPriority
Deprecated.Should only be called fromINetwork.setPriorityAndChannel(INetworkElement, int, int)
}!Set the priority of this part in the network.- Parameters:
priority
- The new priority
-
getPriority
int getPriority()- Returns:
- The priority of this part in the network.
-
setChannel
Deprecated.Should only be called fromINetwork.setPriorityAndChannel(INetworkElement, int, int)
}!Set the channel for this state.- Parameters:
channel
- The new channel
-
getChannel
int getChannel()- Returns:
- This part's channel.
-
getTargetOffset
net.minecraft.core.Vec3i getTargetOffset()- Returns:
- The target position offset.
-
setTargetOffset
void setTargetOffset(net.minecraft.core.Vec3i offset) - Parameters:
offset
- The target position offset.
-
setTargetSideOverride
void setTargetSideOverride(@Nullable net.minecraft.core.Direction side) Indicate that the given part should interact with the given side of the target.- Parameters:
side
- The side of the target block to interact with. Null removes the side override.
-
getTargetSideOverride
@Nullable net.minecraft.core.Direction getTargetSideOverride()- Returns:
- The side of the target block to interact with. Can be null.
-
markDirty
void markDirty()Indicate that this state has changes that must be saved to the world. -
isDirtyAndReset
boolean isDirtyAndReset()Check if dirty and reset the dirty state.- Returns:
- If this state has changed since the last time and needs to be persisted to NBT eventually.
-
isUpdateAndReset
boolean isUpdateAndReset()Check if this part state should update and reset the flag.- Returns:
- If this state has changed since the last time and needs to be updated to the client.
-
forceBlockRenderUpdate
void forceBlockRenderUpdate()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. -
isForceBlockRenderUpdateAndReset
boolean isForceBlockRenderUpdateAndReset()- 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.
-
getAspectProperties
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.- Parameters:
aspect
- The aspect to get the properties from.- Returns:
- The properties, this can be null if still the default.
-
setAspectProperties
Set the properties for the given aspect.- Parameters:
aspect
- The aspect to get the properties from.properties
- The properties, this can be null if still the default.
-
setEnabled
void setEnabled(boolean enabled) Enable the part from working.- Parameters:
enabled
- If it should work.
-
isEnabled
boolean isEnabled()- Returns:
- If the part should work.
-
gatherCapabilities
Gathers the capabilities of this part state. Don't call this unless you know what you're doing!- Parameters:
partType
- The part type this state is associated with.
-
getCapability
<T> Optional<T> getCapability(P partType, PartCapability<T> capability, INetwork network, IPartNetwork partNetwork, PartTarget target) Get the given capability.- 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
Add a capability to this state that will not be automatically persisted to NBT.- Type Parameters:
T
- The capability type.- Parameters:
capability
- The optional capability.value
- The capability instance.
-
removeVolatileCapability
Remove a non-persisted capability.- Parameters:
capability
- The capability.
-
loadInventoryNamed
Load the inventory of the given name from the part state.- Parameters:
name
- The inventory name.inventory
- The inventory object to load into.
-
saveInventoryNamed
Save the inventory of the given name into the part state.- Parameters:
name
- The inventory name.inventory
- The inventory object to save.
-
getInventoryNamed
@Nullable net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack> getInventoryNamed(String name) - Parameters:
name
- The inventory name.- Returns:
- Get the inventory contents of the given name.
-
setInventoryNamed
void setInventoryNamed(String name, net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack> inventory) Set the inventory of the given name.- Parameters:
name
- The inventory name.inventory
- Inventory contents.
-
getInventoriesNamed
Map<String,net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack>> getInventoriesNamed()- Returns:
- All named inventories.
-
clearInventoriesNamed
void clearInventoriesNamed()Clear all named inventories. -
initializeOffsets
Run the initialization logic for offset handling. -
updateOffsetVariables
void updateOffsetVariables(P partType, INetwork network, IPartNetwork partNetwork, PartTarget target) Tick any internal offset variables.- Parameters:
partType
- The part type.network
- The network.partNetwork
- The part network.target
- The part target.
-
markOffsetVariablesChanged
void markOffsetVariablesChanged()Indicate that the contents of the offset variables inventory have changed. -
getOffsetVariableError
@Nullable net.minecraft.network.chat.MutableComponent getOffsetVariableError(int slot) - Parameters:
slot
- The offset variable slot.- Returns:
- The current error, or null if no error.
-
requiresOffsetUpdates
boolean requiresOffsetUpdates()- Returns:
- If the part contains variable-driven offsets that require updating.
-
getMaxOffset
int getMaxOffset()- Returns:
- The max offset allowed in this part.
-
setMaxOffset
void setMaxOffset(int offset) Update the max offset for this part.- Parameters:
offset
- The new offset.
-
INetwork.setPriorityAndChannel(INetworkElement, int, int)
}!