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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDrops(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.voidafterNetworkAlive(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) Called right after this network is initialized.voidafterNetworkReAlive(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) Called right after this network has come alive again, for example after a network restart.voidbeforeNetworkKill(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) Called right before the network is terminated or will be reset.protected abstract Sprotected abstract StringfromNBT(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.nbt.CompoundTag tag) Read the properties of this part from nbt.intgetChannel(S state) net.minecraft.world.item.ItemStackgetCloneItemStack(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, S state) Get the itemstack from the given state.intgetConsumptionRate(S state) net.minecraft.world.item.ItemStackgetItemStack(ValueDeseralizationContext valueDeseralizationContext, S state, boolean saveState) Get the itemstack from the given state.intgetMinimumUpdateInterval(S state) intgetPriority(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.Vec3igetTargetOffset(S state) net.minecraft.core.DirectiongetTargetSideOverride(S state) final StringintgetUpdateInterval(S state) booleanprotected booleanhasOffsetVariables(S state) booleanbooleanbooleanvoidloadTooltip(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.voidloadTooltip(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.voidonBlockNeighborChange(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.voidonEvent(INetworkEvent event, IPartNetworkElement<P, S> networkElement) Can be called at any time by theINetworkEventBus.voidonNetworkAddition(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) Called when this element is added to the network.voidonNetworkRemoval(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) Called when this element is removed from the network.voidonOffsetVariablesChanged(PartTarget target, S state) Called when an offset variable was inserted or removed from a slot.net.minecraft.world.InteractionResultonPartActivated(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.voidonPostRemoved(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) Called after this element has been removed.voidonPreRemoved(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) Called when this element is about to be removed.voidpostUpdate(INetwork network, IPartNetwork partNetwork, PartTarget target, S state, boolean updated) Called after the element was updated or not.voidsetEnabled(S state, boolean enabled) Set if this part should work.voidsetPriorityAndChannel(INetwork network, IPartNetwork partNetwork, PartTarget target, S state, int priority, int channel) Set the priority and channel of this part in the network.booleansetTargetOffset(S state, PartPos center, net.minecraft.core.Vec3i offset) voidsetTargetSideOverride(S state, net.minecraft.core.Direction side) Indicate that the given part should interact with the given side of the target.voidsetUpdateInterval(S state, int updateInterval) Set the update interval for this part.booleanshouldTriggerBlockRenderUpdate(S oldPartState, S newPartState) Check if the given state change should trigger a block render update.voidtoNBT(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.nbt.CompoundTag tag, S partState) Write the properties of this part to NBT.voidupdate(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) Update at the tick interval specified.voidupdateTick(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, waitMethods 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:
getTranslationKeyin interfaceIPartType<P extends IPartType<P,S>, S extends IPartState<P>> - Returns:
- The unlocalized name of this part.
-
createTranslationKey
-
isSolid
-
toNBT
public void toNBT(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.nbt.CompoundTag tag, S partState) Description copied from interface:IPartTypeWrite 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:IPartTypeRead the properties of this part from nbt. This tag is guaranteed to only contain data for this part. -
setUpdateInterval
Description copied from interface:IPartTypeSet the update interval for this part.- Specified by:
setUpdateIntervalin interfaceIPartType<P extends IPartType<P,S>, S extends IPartState<P>> - Parameters:
state- The stateupdateInterval- The tick interval to update this element.
-
getUpdateInterval
- Specified by:
getUpdateIntervalin 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:
getMinimumUpdateIntervalin 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:IPartTypeSet the priority and channel of this part in the network.- Specified by:
setPriorityAndChannelin 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:
getPriorityin 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:
getChannelin 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:
getTargetOffsetin interfaceIPartType<P extends IPartType<P,S>, S extends IPartState<P>> - Parameters:
state- The state- Returns:
- The target position offset.
-
setTargetOffset
- Specified by:
setTargetOffsetin 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:IPartTypeIndicate that the given part should interact with the given side of the target.- Specified by:
setTargetSideOverridein 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:
getTargetSideOverridein 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:IPartTypeGet the part target for this part. -
hasOffsetVariables
-
onOffsetVariablesChanged
Description copied from interface:IPartTypeCalled when an offset variable was inserted or removed from a slot.- Specified by:
onOffsetVariablesChangedin interfaceIPartType<P extends IPartType<P,S>, S extends IPartState<P>> - Parameters:
target- The target block.state- The state.
-
isUpdate
-
update
Description copied from interface:IPartTypeUpdate at the tick interval specified. -
beforeNetworkKill
public void beforeNetworkKill(INetwork network, IPartNetwork partNetwork, PartTarget target, S state) Description copied from interface:IPartTypeCalled right before the network is terminated or will be reset.- Specified by:
beforeNetworkKillin 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:IPartTypeCalled right after this network is initialized.- Specified by:
afterNetworkAlivein 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:IPartTypeCalled right after this network has come alive again, for example after a network restart.- Specified by:
afterNetworkReAlivein 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
public net.minecraft.world.item.ItemStack getItemStack(ValueDeseralizationContext valueDeseralizationContext, S state, boolean saveState) Description copied from interface:IPartTypeGet the itemstack from the given state.- Specified by:
getItemStackin interfaceIPartType<P extends IPartType<P,S>, S extends IPartState<P>> - Parameters:
valueDeseralizationContext-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:IPartTypeGet the itemstack from the given state.- Specified by:
getCloneItemStackin 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:IPartTypeGet the part state from the given itemstack. -
constructDefaultState
- Returns:
- Constructor call for a new default state for this part type.
-
defaultBlockState
- Specified by:
defaultBlockStatein 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:IPartTypeAdd the itemstacks to drop when this element is removed.- Specified by:
addDropsin 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:IPartTypeCalled when this element is added to the network.- Specified by:
onNetworkAdditionin 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:IPartTypeCalled when this element is removed from the network.- Specified by:
onNetworkRemovalin 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:IPartTypeCalled when a part is right-clicked.- Specified by:
onPartActivatedin 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:IPartTypeCalled when a block update occurs- Specified by:
updateTickin 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:IPartTypeCalled when this element is about to be removed.- Specified by:
onPreRemovedin 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:IPartTypeCalled after this element has been removed.- Specified by:
onPostRemovedin 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:IPartTypeCalled 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.- Specified by:
onBlockNeighborChangein 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:
getConsumptionRatein 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:IPartTypeCalled 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:
postUpdatein 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:IPartTypeSet if this part should work.- Specified by:
setEnabledin interfaceIPartType<P extends IPartType<P,S>, S extends IPartState<P>> - Parameters:
state- The stateenabled- If it should work.
-
loadTooltip
Description copied from interface:IPartTypeAdd tooltip lines for this aspect when this part is being hovered by a mod like WAILA.- Specified by:
loadTooltipin 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:IPartTypeAdd tooltip lines for this aspect when this part's item is being hovered.- Specified by:
loadTooltipin 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:IPartTypeCheck 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:
shouldTriggerBlockRenderUpdatein 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:
hasEventSubscriptionsin 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:
getSubscribedEventsin interfaceINetworkEventListener<P extends IPartType<P,S>> - Returns:
- The static set of events this listener should be subscribed to.
-
onEvent
Description copied from interface:INetworkEventListenerCan be called at any time by theINetworkEventBus. Only events in the set fromINetworkEventListener.getSubscribedEvents()will be received.
-