Class PartTypeAdapter<P extends IPartType<P,S>,S extends IPartState<P>>
java.lang.Object
org.cyclops.integrateddynamics.api.part.PartTypeAdapter<P,S>
- All Implemented Interfaces:
INetworkEventListener<IPartNetworkElement<P,
,S>> IPartType<P,
S>
- Direct Known Subclasses:
PartTypeBase
public abstract class PartTypeAdapter<P extends IPartType<P,S>,S extends IPartState<P>>
extends Object
implements IPartType<P,S>
Default implementation of
IPartType
.-
Constructor Summary
-
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.protected abstract S
protected abstract String
fromNBT
(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.nbt.CompoundTag tag) Read the properties of this part from nbt.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) net.minecraft.world.item.ItemStack
getItemStack
(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.Set<Class<? extends INetworkEvent>>
Get the part target for this part.net.minecraft.core.Vec3i
getTargetOffset
(S state) net.minecraft.core.Direction
getTargetSideOverride
(S state) final String
int
getUpdateInterval
(S state) boolean
protected boolean
hasOffsetVariables
(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)
,IForgeBlock.onNeighborChange(BlockState, LevelReader, BlockPos, BlockPos)
orBlockBehaviour.updateShape(BlockState, Direction, BlockState, LevelAccessor, BlockPos, BlockPos)
is called.void
onEvent
(INetworkEvent event, IPartNetworkElement<P, S> networkElement) Can be called at any time by theINetworkEventBus
.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) Set the priority and channel of this part in the network.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.void
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 occursMethods 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.IPartType
createNetworkElement, forceLightTransparency, getBaseBlockState, getBlockModelPath, getBlockState, getContainerProvider, getContainerProviderOffsets, getContainerProviderSettings, getItem, getPartRenderPosition, getUniqueName, supportsOffsets, writeExtraGuiData, writeExtraGuiDataOffsets, writeExtraGuiDataSettings
-
Constructor Details
-
PartTypeAdapter
public PartTypeAdapter()
-
-
Method Details
-
getTranslationKey
- Specified by:
getTranslationKey
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Returns:
- The unlocalized name of this part.
-
createTranslationKey
-
isSolid
-
toNBT
Description copied from interface:IPartType
Write the properties of this part to NBT. An identificator for this part is not required, this is written somewhere else. -
fromNBT
public S fromNBT(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.nbt.CompoundTag tag) Description copied from interface:IPartType
Read the properties of this part from nbt. This tag is guaranteed to only contain data for this part. -
setUpdateInterval
Description copied from interface:IPartType
Set the update interval for this part.- Specified by:
setUpdateInterval
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
state
- The stateupdateInterval
- The tick interval to update this element.
-
getUpdateInterval
- Specified by:
getUpdateInterval
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
state
- The state- Returns:
- The tick interval to update this element.
-
getMinimumUpdateInterval
- Specified by:
getMinimumUpdateInterval
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
state
- The state- Returns:
- The minimum allowed tick interval to update this element.
-
setPriorityAndChannel
public void setPriorityAndChannel(INetwork network, IPartNetwork partNetwork, PartTarget target, S state, int priority, int channel) Description copied from interface:IPartType
Set the priority and channel of this part in the network.- Specified by:
setPriorityAndChannel
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - 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
- Specified by:
getPriority
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
state
- The state- Returns:
- The priority of this part in the network.
-
getChannel
- Specified by:
getChannel
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
state
- The state- Returns:
- The channel of this part in the network.
-
getTargetOffset
- Specified by:
getTargetOffset
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
state
- The state- Returns:
- The target position offset.
-
setTargetOffset
- Specified by:
setTargetOffset
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
state
- The statecenter
- The center position.offset
- The target position offset.- Returns:
- True if the offset was valid
-
setTargetSideOverride
Description copied from interface:IPartType
Indicate that the given part should interact with the given side of the target.- Specified by:
setTargetSideOverride
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
state
- The stateside
- The side of the target block to interact with. Null removes the side override.
-
getTargetSideOverride
- Specified by:
getTargetSideOverride
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
state
- The state- Returns:
- The overridden side of the target block to interact with. Can be null.
-
getTarget
Description copied from interface:IPartType
Get the part target for this part. -
hasOffsetVariables
-
onOffsetVariablesChanged
Description copied from interface:IPartType
Called when an offset variable was inserted or removed from a slot.- Specified by:
onOffsetVariablesChanged
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
target
- The target block.state
- The state.
-
isUpdate
-
update
Description copied from interface:IPartType
Update at the tick interval specified. -
beforeNetworkKill
public void beforeNetworkKill(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) Description copied from interface:IPartType
Called right before the network is terminated or will be reset.- Specified by:
beforeNetworkKill
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
network
- The network to update in.partNetwork
- The part network to update in.target
- The target block.state
- The state
-
afterNetworkAlive
public void afterNetworkAlive(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) Description copied from interface:IPartType
Called right after this network is initialized.- Specified by:
afterNetworkAlive
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
network
- The network to update in.partNetwork
- The part network to update in.target
- The target block.state
- The state
-
afterNetworkReAlive
public void afterNetworkReAlive(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) Description copied from interface:IPartType
Called right after this network has come alive again, for example after a network restart.- Specified by:
afterNetworkReAlive
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
network
- The network to update in.partNetwork
- The part network to update in.target
- The target block.state
- The state
-
getItemStack
Description copied from interface:IPartType
Get the itemstack from the given state.- Specified by:
getItemStack
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
state
- The statesaveState
- If the part state should be saved in the item.- Returns:
- The itemstack possibly containing the state information.
-
getCloneItemStack
public net.minecraft.world.item.ItemStack getCloneItemStack(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, S state) Description copied from interface:IPartType
Get the itemstack from the given state.- Specified by:
getCloneItemStack
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
world
- The world.pos
- The position.state
- The state.- Returns:
- The itemstack possibly containing the state information.
-
getState
public S getState(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.world.item.ItemStack itemStack) Description copied from interface:IPartType
Get the part state from the given itemstack. -
constructDefaultState
- Returns:
- Constructor call for a new default state for this part type.
-
defaultBlockState
- Specified by:
defaultBlockState
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Returns:
- The default state of this part.
-
addDrops
public void addDrops(PartTarget target, S state, List<net.minecraft.world.item.ItemStack> itemStacks, boolean dropMainElement, boolean saveState) Description copied from interface:IPartType
Add the itemstacks to drop when this element is removed.- Specified by:
addDrops
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - 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
public void onNetworkAddition(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) Description copied from interface:IPartType
Called when this element is added to the network.- Specified by:
onNetworkAddition
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
network
- The network to update in.partNetwork
- The part network to update in.target
- The target block.state
- The state
-
onNetworkRemoval
public void onNetworkRemoval(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) Description copied from interface:IPartType
Called when this element is removed from the network.- Specified by:
onNetworkRemoval
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
network
- The network to update in.partNetwork
- The part network to update in.target
- The target block.state
- The state
-
onPartActivated
public 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) Description copied from interface:IPartType
Called when a part is right-clicked.- Specified by:
onPartActivated
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - 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.
-
updateTick
public void updateTick(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, S partState, net.minecraft.util.RandomSource random) Description copied from interface:IPartType
Called when a block update occurs- Specified by:
updateTick
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
world
- The world.pos
- The position.partState
- The part state.random
- A random instance.
-
onPreRemoved
Description copied from interface:IPartType
Called when this element is about to be removed.- Specified by:
onPreRemoved
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
network
- The network.partNetwork
- The part network to update in.target
- The target block.state
- The state
-
onPostRemoved
Description copied from interface:IPartType
Called after this element has been removed.- Specified by:
onPostRemoved
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
network
- The network.partNetwork
- The part network to update in.target
- The target block.state
- The state
-
onBlockNeighborChange
public 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) Description copied from interface:IPartType
Called when a neighbouring block is updated, more specifically whenBlockBehaviour.neighborChanged(BlockState, Level, BlockPos, Block, BlockPos, boolean)
,IForgeBlock.onNeighborChange(BlockState, LevelReader, BlockPos, BlockPos)
orBlockBehaviour.updateShape(BlockState, Direction, BlockState, LevelAccessor, BlockPos, BlockPos)
is called.- Specified by:
onBlockNeighborChange
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - 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
- Specified by:
getConsumptionRate
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
state
- The state- Returns:
- The consumption rate of this part for the given state.
-
postUpdate
public void postUpdate(INetwork network, IPartNetwork partNetwork, PartTarget target, S state, boolean updated) Description copied from interface:IPartType
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.- Specified by:
postUpdate
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - 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
-
setEnabled
Description copied from interface:IPartType
Set if this part should work.- Specified by:
setEnabled
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
state
- The stateenabled
- If it should work.
-
loadTooltip
Description copied from interface:IPartType
Add tooltip lines for this aspect when this part is being hovered by a mod like WAILA.- Specified by:
loadTooltip
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
state
- The state.lines
- The list to add lines to.
-
loadTooltip
public void loadTooltip(net.minecraft.world.item.ItemStack itemStack, List<net.minecraft.network.chat.Component> lines) Description copied from interface:IPartType
Add tooltip lines for this aspect when this part's item is being hovered.- Specified by:
loadTooltip
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
itemStack
- The itemstack.lines
- The list to add lines to.
-
shouldTriggerBlockRenderUpdate
Description copied from interface:IPartType
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.- Specified by:
shouldTriggerBlockRenderUpdate
in interfaceIPartType<P extends IPartType<P,
S>, S extends IPartState<P>> - Parameters:
oldPartState
- The old part state.newPartState
- The new part state.- Returns:
- If it should trigger a block render update.
-
hasEventSubscriptions
public boolean hasEventSubscriptions()- Specified by:
hasEventSubscriptions
in interfaceINetworkEventListener<P extends IPartType<P,
S>> - Returns:
- If this should be registered to the network event bus for listening to network events.
-
getSubscribedEvents
- Specified by:
getSubscribedEvents
in interfaceINetworkEventListener<P extends IPartType<P,
S>> - Returns:
- The static set of events this listener should be subscribed to.
-
onEvent
Description copied from interface:INetworkEventListener
Can be called at any time by theINetworkEventBus
. Only events in the set fromINetworkEventListener.getSubscribedEvents()
will be received.
-