Interface IPartType<P extends IPartType<P,S>,S extends IPartState<P>>
- Type Parameters:
P
- The part type.S
- The part state type.
- All Superinterfaces:
INetworkEventListener<IPartNetworkElement<P,
S>>
- All Known Subinterfaces:
IPartTypeActiveVariable<P,
,S> IPartTypeReader<P,
,S> IPartTypeWriter<P,
S>
- All Known Implementing Classes:
PartTypeAdapter
,PartTypeAspects
,PartTypeAudioReader
,PartTypeAudioWriter
,PartTypeBase
,PartTypeBlockReader
,PartTypeConfigurable
,PartTypeConnector
,PartTypeConnectorMonoDirectional
,PartTypeConnectorOmniDirectional
,PartTypeEffectWriter
,PartTypeEntityReader
,PartTypeEntityWriter
,PartTypeExtraDimensionalReader
,PartTypeFluidReader
,PartTypeInventoryReader
,PartTypeInventoryWriter
,PartTypeMachineReader
,PartTypeMachineWriter
,PartTypeNetworkReader
,PartTypePanel
,PartTypePanelDisplay
,PartTypePanelLightDynamic
,PartTypePanelLightStatic
,PartTypePanelVariableDriven
,PartTypeReadBase
,PartTypeRedstoneReader
,PartTypeRedstoneWriter
,PartTypeWorldReader
,PartTypeWriteBase
public interface IPartType<P extends IPartType<P,S>,S extends IPartState<P>>
extends INetworkEventListener<IPartNetworkElement<P,S>>
A type of part that can be inserted into a
IPartContainer
.
Only one unique instance for each part should exist, the values are stored inside an
IPartState
.-
Method Summary
Modifier and TypeMethodDescriptionvoid
addDrops
(PartTarget target, S state, List<net.minecraft.world.item.ItemStack> itemStacks, boolean dropMainElement, boolean saveState) Add the itemstacks to drop when this element is removed.void
afterNetworkAlive
(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) Called right after this network is initialized.void
afterNetworkReAlive
(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) Called right after this network has come alive again, for example after a network restart.void
beforeNetworkKill
(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) Called right before the network is terminated or will be reset.createNetworkElement
(IPartContainer partContainer, org.cyclops.cyclopscore.datastructure.DimPos pos, net.minecraft.core.Direction side) Create a network element for this part type.boolean
forceLightTransparency
(S state) fromNBT
(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.nbt.CompoundTag tag) Read the properties of this part from nbt.net.minecraft.world.level.block.state.BlockState
net.minecraft.resources.ResourceLocation
net.minecraft.world.level.block.state.BlockState
getBlockState
(IPartContainer partContainer, net.minecraft.core.Direction side) Get the base block state that will be rendered for this part.int
getChannel
(S state) net.minecraft.world.item.ItemStack
getCloneItemStack
(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, S state) Get the itemstack from the given state.int
getConsumptionRate
(S state) default Optional
<net.minecraft.world.MenuProvider> default Optional
<net.minecraft.world.MenuProvider> default Optional
<net.minecraft.world.MenuProvider> net.minecraft.world.item.Item
getItem()
net.minecraft.world.item.ItemStack
getItemStack
(ValueDeseralizationContext valueDeseralizationContext, S state, boolean saveState) Get the itemstack from the given state.int
getMinimumUpdateInterval
(S state) int
getPriority
(S state) getState
(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.world.item.ItemStack itemStack) Get the part state from the given itemstack.Get the part target for this part.net.minecraft.core.Vec3i
getTargetOffset
(S state) net.minecraft.core.Direction
getTargetSideOverride
(S state) net.minecraft.resources.ResourceLocation
int
getUpdateInterval
(S state) boolean
boolean
boolean
void
loadTooltip
(net.minecraft.world.item.ItemStack itemStack, List<net.minecraft.network.chat.Component> lines) Add tooltip lines for this aspect when this part's item is being hovered.void
loadTooltip
(S state, List<net.minecraft.network.chat.Component> lines) Add tooltip lines for this aspect when this part is being hovered by a mod like WAILA.void
onBlockNeighborChange
(INetwork network, IPartNetwork partNetwork, PartTarget target, S state, net.minecraft.world.level.BlockGetter world, net.minecraft.world.level.block.Block neighbourBlock, net.minecraft.core.BlockPos neighbourBlockPos) Called when a neighbouring block is updated, more specifically whenBlockBehaviour.neighborChanged(BlockState, Level, BlockPos, Block, BlockPos, boolean)
,IBlockExtension.onNeighborChange(BlockState, LevelReader, BlockPos, BlockPos)
orBlockBehaviour.updateShape(BlockState, Direction, BlockState, LevelAccessor, BlockPos, BlockPos)
is called.void
onNetworkAddition
(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) Called when this element is added to the network.void
onNetworkRemoval
(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) Called when this element is removed from the network.void
onOffsetVariablesChanged
(PartTarget target, S state) Called when an offset variable was inserted or removed from a slot.net.minecraft.world.InteractionResult
onPartActivated
(S partState, net.minecraft.core.BlockPos pos, net.minecraft.world.level.Level world, net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand, net.minecraft.world.item.ItemStack heldItem, net.minecraft.world.phys.BlockHitResult hit) Called when a part is right-clicked.void
onPostRemoved
(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) Called after this element has been removed.void
onPreRemoved
(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) Called when this element is about to be removed.void
postUpdate
(INetwork network, IPartNetwork partNetwork, PartTarget target, S state, boolean updated) Called after the element was updated or not.void
setEnabled
(S state, boolean enabled) Set if this part should work.void
setPriorityAndChannel
(INetwork network, IPartNetwork partNetwork, PartTarget target, S state, int priority, int channel) Deprecated.boolean
setTargetOffset
(S state, PartPos center, net.minecraft.core.Vec3i offset) void
setTargetSideOverride
(S state, net.minecraft.core.Direction side) Indicate that the given part should interact with the given side of the target.void
setUpdateInterval
(S state, int updateInterval) Set the update interval for this part.boolean
shouldTriggerBlockRenderUpdate
(S oldPartState, S newPartState) Check if the given state change should trigger a block render update.default boolean
void
toNBT
(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.nbt.CompoundTag tag, S partState) Write the properties of this part to NBT.void
update
(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) Update at the tick interval specified.void
updateTick
(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, S partState, net.minecraft.util.RandomSource random) Called when a block update occursdefault void
writeExtraGuiData
(net.minecraft.network.RegistryFriendlyByteBuf packetBuffer, PartPos pos, net.minecraft.server.level.ServerPlayer player) This method can be overridden for cases when additional data needs to be sent to clients when opening containers.default void
writeExtraGuiDataOffsets
(net.minecraft.network.RegistryFriendlyByteBuf packetBuffer, PartPos pos, net.minecraft.server.level.ServerPlayer player) This method can be overridden for cases when additional data needs to be sent to clients when opening offsets containers.default void
writeExtraGuiDataSettings
(net.minecraft.network.RegistryFriendlyByteBuf packetBuffer, PartPos pos, net.minecraft.server.level.ServerPlayer player) This method can be overridden for cases when additional data needs to be sent to clients when opening settings containers.Methods inherited from interface org.cyclops.integrateddynamics.api.network.INetworkEventListener
getSubscribedEvents, hasEventSubscriptions, onEvent
-
Method Details
-
getUniqueName
net.minecraft.resources.ResourceLocation getUniqueName()- Returns:
- The unique name for this part type.
-
getTranslationKey
String getTranslationKey()- Returns:
- The unlocalized name of this part.
-
getBlockModelPath
net.minecraft.resources.ResourceLocation getBlockModelPath()- Returns:
- JSON model path for the block representation of this part.
-
getItem
net.minecraft.world.item.Item getItem()- Returns:
- The item associated with this part type.
-
isSolid
- Parameters:
state
- The state- Returns:
- If this element is solid.
-
getPartRenderPosition
PartRenderPosition getPartRenderPosition()- Returns:
- The position part occupies, used to calculate the required render lengths. This part is assumed to be aligned at the edge of the block for the depth, while centered on width and height.
-
toNBT
void toNBT(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.nbt.CompoundTag tag, S partState) Write the properties of this part to NBT. An identificator for this part is not required, this is written somewhere else.- Parameters:
valueDeseralizationContext
-tag
- The tag to write to. This tag is guaranteed to be empty.partState
- The state of this part.
-
fromNBT
Read the properties of this part from nbt. This tag is guaranteed to only contain data for this part.- Parameters:
valueDeseralizationContext
-tag
- The tag to read from.- Returns:
- The state of this part.
-
defaultBlockState
S defaultBlockState()- Returns:
- The default state of this part.
-
setUpdateInterval
Set the update interval for this part.- Parameters:
state
- The stateupdateInterval
- The tick interval to update this element.
-
getUpdateInterval
- Parameters:
state
- The state- Returns:
- The tick interval to update this element.
-
getMinimumUpdateInterval
- Parameters:
state
- The state- Returns:
- The minimum allowed tick interval to update this element.
-
setPriorityAndChannel
@Deprecated void setPriorityAndChannel(INetwork network, IPartNetwork partNetwork, PartTarget target, S state, int priority, int channel) Deprecated.Should only be called fromINetwork.setPriorityAndChannel(INetworkElement, int, int)
!Set the priority and channel of this part in the network.- Parameters:
network
- The network to update in.partNetwork
- The part network to update in.target
- The target block.state
- The statepriority
- The new prioritychannel
- The new channel
-
getPriority
- Parameters:
state
- The state- Returns:
- The priority of this part in the network.
-
getChannel
- Parameters:
state
- The state- Returns:
- The channel of this part in the network.
-
supportsOffsets
default boolean supportsOffsets()- Returns:
- If this part can handle custom offsets.
-
getTargetOffset
- Parameters:
state
- The state- Returns:
- The target position offset.
-
setTargetOffset
- Parameters:
state
- The statecenter
- The center position.offset
- The target position offset.- Returns:
- True if the offset was valid
-
setTargetSideOverride
Indicate that the given part should interact with the given side of the target.- Parameters:
state
- The stateside
- The side of the target block to interact with. Null removes the side override.
-
getTargetSideOverride
- Parameters:
state
- The state- Returns:
- The overridden side of the target block to interact with. Can be null.
-
getTarget
Get the part target for this part.- Parameters:
pos
- The center position of this part.state
- The state.- Returns:
- The part target.
-
onOffsetVariablesChanged
Called when an offset variable was inserted or removed from a slot.- Parameters:
target
- The target block.state
- The state.
-
isUpdate
- Parameters:
state
- The state- Returns:
- If this element should be updated. This method is only called once during network initialization.
-
update
Update at the tick interval specified.- Parameters:
network
- The network to update in.partNetwork
- The part network to update in.target
- The target block.state
- The state
-
beforeNetworkKill
Called right before the network is terminated or will be reset.- Parameters:
network
- The network to update in.partNetwork
- The part network to update in.target
- The target block.state
- The state
-
afterNetworkAlive
Called right after this network is initialized.- Parameters:
network
- The network to update in.partNetwork
- The part network to update in.target
- The target block.state
- The state
-
afterNetworkReAlive
Called right after this network has come alive again, for example after a network restart.- Parameters:
network
- The network to update in.partNetwork
- The part network to update in.target
- The target block.state
- The state
-
getItemStack
net.minecraft.world.item.ItemStack getItemStack(ValueDeseralizationContext valueDeseralizationContext, S state, boolean saveState) Get the itemstack from the given state.- Parameters:
valueDeseralizationContext
-state
- The statesaveState
- If the part state should be saved in the item.- Returns:
- The itemstack possibly containing the state information.
-
getCloneItemStack
net.minecraft.world.item.ItemStack getCloneItemStack(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, S state) Get the itemstack from the given state.- Parameters:
world
- The world.pos
- The position.state
- The state.- Returns:
- The itemstack possibly containing the state information.
-
getState
S getState(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.world.item.ItemStack itemStack) Get the part state from the given itemstack.- Parameters:
valueDeseralizationContext
-itemStack
- The itemstack possibly containing state information.- Returns:
- The state contained in the itemstack or the default part state.
-
addDrops
void addDrops(PartTarget target, S state, List<net.minecraft.world.item.ItemStack> itemStacks, boolean dropMainElement, boolean saveState) Add the itemstacks to drop when this element is removed.- Parameters:
target
- The target.state
- The stateitemStacks
- The itemstack list to add to.dropMainElement
- If the part itself should also be dropped.saveState
- If the part state should be saved in the item.
-
onNetworkAddition
Called when this element is added to the network.- Parameters:
network
- The network to update in.partNetwork
- The part network to update in.target
- The target block.state
- The state
-
onNetworkRemoval
Called when this element is removed from the network.- Parameters:
network
- The network to update in.partNetwork
- The part network to update in.target
- The target block.state
- The state
-
createNetworkElement
INetworkElement createNetworkElement(IPartContainer partContainer, org.cyclops.cyclopscore.datastructure.DimPos pos, net.minecraft.core.Direction side) Create a network element for this part type.- Parameters:
partContainer
- The container this part is/will be part of.pos
- The position this network element is/will be placed at.side
- The side this network element is/will be placed at.- Returns:
- A new network element instance.
-
onPartActivated
net.minecraft.world.InteractionResult onPartActivated(S partState, net.minecraft.core.BlockPos pos, net.minecraft.world.level.Level world, net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand, net.minecraft.world.item.ItemStack heldItem, net.minecraft.world.phys.BlockHitResult hit) Called when a part is right-clicked.- Parameters:
partState
- The state of this part.pos
- The position of the block this part is part of.world
- The world.player
- The player activating the part.hand
- The hand in use by the player.heldItem
- The held item.hit
- The ray trace hit result.- Returns:
- The action result.
-
getBlockState
net.minecraft.world.level.block.state.BlockState getBlockState(IPartContainer partContainer, net.minecraft.core.Direction side) Get the base block state that will be rendered for this part. An appropriateIgnoredBlock.FACING
property will be set.- Parameters:
partContainer
- The part entity.side
- The position of the part.- Returns:
- The block state to render with.
-
getBaseBlockState
net.minecraft.world.level.block.state.BlockState getBaseBlockState()- Returns:
- The default block state representation of this part.
-
updateTick
void updateTick(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, S partState, net.minecraft.util.RandomSource random) Called when a block update occurs- Parameters:
world
- The world.pos
- The position.partState
- The part state.random
- A random instance.
-
onPreRemoved
Called when this element is about to be removed.- Parameters:
network
- The network.partNetwork
- The part network to update in.target
- The target block.state
- The state
-
onPostRemoved
Called after this element has been removed.- Parameters:
network
- The network.partNetwork
- The part network to update in.target
- The target block.state
- The state
-
onBlockNeighborChange
void onBlockNeighborChange(@Nullable INetwork network, @Nullable IPartNetwork partNetwork, PartTarget target, S state, net.minecraft.world.level.BlockGetter world, net.minecraft.world.level.block.Block neighbourBlock, net.minecraft.core.BlockPos neighbourBlockPos) Called when a neighbouring block is updated, more specifically whenBlockBehaviour.neighborChanged(BlockState, Level, BlockPos, Block, BlockPos, boolean)
,IBlockExtension.onNeighborChange(BlockState, LevelReader, BlockPos, BlockPos)
orBlockBehaviour.updateShape(BlockState, Direction, BlockState, LevelAccessor, BlockPos, BlockPos)
is called.- Parameters:
network
- The network to update in.partNetwork
- The part network to update in.target
- The target block.state
- The stateworld
- The world in which the neighbour was updated.neighbourBlock
- The block type of the neighbour that was updated.neighbourBlockPos
- The position of the neighbour that was updated.
-
getConsumptionRate
- Parameters:
state
- The state- Returns:
- The consumption rate of this part for the given state.
-
postUpdate
void postUpdate(INetwork network, IPartNetwork partNetwork, PartTarget target, S state, boolean updated) Called after the element was updated or not. If the update was not called, this can be because the network did not contain enough energy to let this element work.- Parameters:
network
- The network to update in.partNetwork
- The part network to update in.target
- The target block.state
- The stateupdated
- If theINetworkElement.update(INetwork)
was called.
-
isEnabled
- Parameters:
state
- The state- Returns:
- If this part is enabled.
-
setEnabled
Set if this part should work.- Parameters:
state
- The stateenabled
- If it should work.
-
loadTooltip
Add tooltip lines for this aspect when this part is being hovered by a mod like WAILA.- Parameters:
state
- The state.lines
- The list to add lines to.
-
loadTooltip
void loadTooltip(net.minecraft.world.item.ItemStack itemStack, List<net.minecraft.network.chat.Component> lines) Add tooltip lines for this aspect when this part's item is being hovered.- Parameters:
itemStack
- The itemstack.lines
- The list to add lines to.
-
shouldTriggerBlockRenderUpdate
Check if the given state change should trigger a block render update. This is only called client-side. The new and old partstates are never both null, at most one will be null.- Parameters:
oldPartState
- The old part state.newPartState
- The new part state.- Returns:
- If it should trigger a block render update.
-
forceLightTransparency
- Parameters:
state
- The state.- Returns:
- If this part should force the block to be transparent to light.
-
getContainerProvider
- Parameters:
pos
- The part position. May be null when called client-side, for checking presence.- Returns:
- The optional container provider for the part type gui.
-
writeExtraGuiData
default void writeExtraGuiData(net.minecraft.network.RegistryFriendlyByteBuf packetBuffer, PartPos pos, net.minecraft.server.level.ServerPlayer player) This method can be overridden for cases when additional data needs to be sent to clients when opening containers.- Parameters:
packetBuffer
- A packet buffer that can be written to.pos
- A part position.player
- The player opening the gui.
-
getContainerProviderSettings
- Parameters:
pos
- The part position. May be null when called client-side, for checking presence.- Returns:
- The optional container provider for the part settings gui.
-
getContainerProviderOffsets
- Parameters:
pos
- The part position. May be null when called client-side, for checking presence.- Returns:
- The optional container provider for the part offsets gui.
-
writeExtraGuiDataSettings
default void writeExtraGuiDataSettings(net.minecraft.network.RegistryFriendlyByteBuf packetBuffer, PartPos pos, net.minecraft.server.level.ServerPlayer player) This method can be overridden for cases when additional data needs to be sent to clients when opening settings containers.- Parameters:
packetBuffer
- A packet buffer that can be written to.pos
- A part position.player
- The player opening the settings gui.
-
writeExtraGuiDataOffsets
default void writeExtraGuiDataOffsets(net.minecraft.network.RegistryFriendlyByteBuf packetBuffer, PartPos pos, net.minecraft.server.level.ServerPlayer player) This method can be overridden for cases when additional data needs to be sent to clients when opening offsets containers.- Parameters:
packetBuffer
- A packet buffer that can be written to.pos
- A part position.player
- The player opening the offsets gui.
-
INetwork.setPriorityAndChannel(INetworkElement, int, int)
!