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 Details

    • getUniqueName

      net.minecraft.resources.Identifier getUniqueName()
      Returns:
      The unique name for this part type.
    • getTranslationKey

      String getTranslationKey()
      Returns:
      The unlocalized name of this part.
    • getBlockModelPath

      net.minecraft.resources.Identifier getBlockModelPath()
      Returns:
      JSON facadeModel path for the block representation of this part.
    • getItem

      net.minecraft.world.item.Item getItem()
      Returns:
      The item associated with this part type.
    • isSolid

      boolean isSolid(S state)
      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.
    • serializeState

      void serializeState(net.minecraft.world.level.storage.ValueOutput valueOutput, S partState)
      Write the properties of this part to NBT. An identificator for this part is not required, this is written somewhere else.
      Parameters:
      valueOutput - The value to write to.
      partState - The state of this part.
    • deserializeState

      S deserializeState(net.minecraft.world.level.storage.ValueInput valueInput)
      Read the properties of this part from nbt. This tag is guaranteed to only contain data for this part.
      Parameters:
      valueInput - The input to read from.
      Returns:
      The state of this part.
    • defaultBlockState

      S defaultBlockState()
      Returns:
      The default state of this part.
    • setUpdateInterval

      void setUpdateInterval(S state, int updateInterval)
      Set the update interval for this part.
      Parameters:
      state - The state
      updateInterval - The tick interval to update this element.
    • getUpdateInterval

      int getUpdateInterval(S state)
      Parameters:
      state - The state
      Returns:
      The tick interval to update this element.
    • getMinimumUpdateInterval

      int getMinimumUpdateInterval(S state)
      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.
      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 state
      priority - The new priority
      channel - The new channel
    • getPriority

      int getPriority(S state)
      Parameters:
      state - The state
      Returns:
      The priority of this part in the network.
    • getChannel

      int getChannel(S state)
      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

      net.minecraft.core.Vec3i getTargetOffset(S state)
      Parameters:
      state - The state
      Returns:
      The target position offset.
    • setTargetOffset

      boolean setTargetOffset(S state, PartPos center, net.minecraft.core.Vec3i offset)
      Parameters:
      state - The state
      center - The center position.
      offset - The target position offset.
      Returns:
      True if the offset was valid
    • setTargetSideOverride

      void setTargetSideOverride(S state, @Nullable net.minecraft.core.Direction side)
      Indicate that the given part should interact with the given side of the target.
      Parameters:
      state - The state
      side - The side of the target block to interact with. Null removes the side override.
    • getTargetSideOverride

      @Nullable net.minecraft.core.Direction getTargetSideOverride(S state)
      Parameters:
      state - The state
      Returns:
      The overridden side of the target block to interact with. Can be null.
    • getTarget

      PartTarget getTarget(PartPos pos, S state)
      Get the part target for this part.
      Parameters:
      pos - The center position of this part.
      state - The state.
      Returns:
      The part target.
    • onOffsetVariablesChanged

      void onOffsetVariablesChanged(PartTarget target, S state)
      Called when an offset variable was inserted or removed from a slot.
      Parameters:
      target - The target block.
      state - The state.
    • onAspectVariablesChanged

      void onAspectVariablesChanged(PartTarget target, S state)
      Called when an aspect setting variable was inserted or removed from a slot.
      Parameters:
      target - The target block.
      state - The state.
    • snapshotConfig

      PartConfigSnapshot snapshotConfig(ValueDeseralizationContext valueDeseralizationContext, S state, Set<PartConfigSection> sections)
      Take a snapshot of the configuration of this part, so that it can be pasted onto another part.
      Parameters:
      valueDeseralizationContext - A value deserialization context.
      state - The state.
      sections - The configuration sections to include.
      Returns:
      The snapshot.
    • applyConfig

      PartConfigApplyResult applyConfig(ValueDeseralizationContext valueDeseralizationContext, @Nullable INetwork network, @Nullable IPartNetwork partNetwork, PartTarget target, S state, PartConfigSnapshot snapshot, Set<PartConfigSection> sections, net.minecraft.world.entity.player.Player player)
      Paste a configuration snapshot onto this part. This is only called server-side.
      Parameters:
      valueDeseralizationContext - A value deserialization context.
      network - The network of this part, or null if it is not in a network.
      partNetwork - The part network of this part, or null if it is not in a network.
      target - The target block.
      state - The state.
      snapshot - The snapshot to paste.
      sections - The configuration sections to paste.
      player - The player that is pasting, whose inventory is used for the variable cards.
      Returns:
      The outcome.
    • snapshotConfigExtra

      default net.minecraft.nbt.CompoundTag snapshotConfigExtra(ValueDeseralizationContext valueDeseralizationContext, S state, PartConfigSection section)
      Take a snapshot of the state that PartConfigSnapshot does not know about itself. This is the extension point for part types that hold their own state, such as the part types that addons add. Implementations should only store what the player configured, so that pasting does not overwrite anything that was left at its default, and should keep the format stable, as a snapshot can outlive a world reload. This is only called server-side.
      Parameters:
      valueDeseralizationContext - A value deserialization context.
      state - The state.
      section - The configuration section that is being copied.
      Returns:
      What to store for that section, or an empty tag to store nothing.
    • applyConfigExtra

      default void applyConfigExtra(ValueDeseralizationContext valueDeseralizationContext, PartTarget target, S state, PartConfigSection section, PartConfigSnapshot snapshot, net.minecraft.world.entity.player.Player player, PartConfigApplyResult result)
      Paste back what snapshotConfigExtra(ValueDeseralizationContext, IPartState, PartConfigSection) stored. This is only called for the sections that are being pasted, and only when the snapshot holds something for them. Since the subset modes of the Wrench can paste onto another part type, implementations should check PartConfigSnapshot.sourcePartType() before reading anything that only makes sense for their own part types. Anything that had to be consumed from the player can be reported through the given result, so that the player is told about it. This is only called server-side.
      Parameters:
      valueDeseralizationContext - A value deserialization context.
      target - The target block.
      state - The state.
      section - The configuration section that is being pasted.
      snapshot - The snapshot that is being pasted, holding the stored state in PartConfigSnapshot.getExtraData(PartConfigSection).
      player - The player that is pasting.
      result - The outcome to report into.
    • getConfigExtraRequirements

      default List<net.minecraft.network.chat.Component> getConfigExtraRequirements(PartConfigSnapshot snapshot, PartConfigSection section)
      What a player needs in their inventory before applyConfigExtra(ValueDeseralizationContext, PartTarget, IPartState, PartConfigSection, PartConfigSnapshot, Player, PartConfigApplyResult) can paste everything, to be shown in the tooltip of the Wrench. This is called on the part type that the snapshot was taken from, on both sides.
      Parameters:
      snapshot - The snapshot that is being pasted.
      section - The configuration section that would be pasted.
      Returns:
      One line per requirement, or nothing if pasting needs nothing from the player.
    • getConfigExtraEntries

      default List<PartConfigEntry> getConfigExtraEntries(ValueDeseralizationContext valueDeseralizationContext, PartConfigSnapshot snapshot, PartConfigSection section)
      The separate things that snapshotConfigExtra(ValueDeseralizationContext, IPartState, PartConfigSection) stored, so that the player can switch them off one by one in the gui of the Wrench. Build the identifiers with PartConfigEntry.idExtra(PartConfigSection, String), and check PartConfigSnapshot.isEnabled(String) for each of them when pasting. A part type that lists no entries has everything it stored switched on and off as a whole instead. This is called on the part type that the snapshot was taken from, on both sides.
      Parameters:
      valueDeseralizationContext - A value deserialization context.
      snapshot - The snapshot that is being pasted.
      section - The configuration section to list the entries of.
      Returns:
      The entries that the given section holds.
    • isUpdate

      boolean isUpdate(S state)
      Parameters:
      state - The state
      Returns:
      If this element should be updated. This method is only called once during network initialization.
    • update

      void update(INetwork network, IPartNetwork partNetwork, PartTarget target, S state)
      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

      void beforeNetworkKill(INetwork network, IPartNetwork partNetwork, PartTarget target, S state)
      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

      void afterNetworkAlive(INetwork network, IPartNetwork partNetwork, PartTarget target, S state)
      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

      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.
      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, net.minecraft.util.ProblemReporter.PathElement problemPath, S state, boolean saveState)
      Get the itemstack from the given state.
      Parameters:
      valueDeseralizationContext -
      problemPath -
      state - The state
      saveState - 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.util.ProblemReporter.PathElement problemPath, net.minecraft.world.item.ItemStack itemStack)
      Get the part state from the given itemstack.
      Parameters:
      valueDeseralizationContext -
      problemPath -
      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 state
      itemStacks - 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

      void onNetworkAddition(INetwork network, IPartNetwork partNetwork, PartTarget target, S state)
      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

      void onNetworkRemoval(INetwork network, IPartNetwork partNetwork, PartTarget target, S state)
      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 appropriate IgnoredBlock.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

      void onPreRemoved(INetwork network, IPartNetwork partNetwork, PartTarget target, S state)
      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

      void onPostRemoved(INetwork network, IPartNetwork partNetwork, PartTarget target, S state)
      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, @Nullable net.minecraft.core.Direction side)
      Called when a neighbouring block is updated, more specifically when BlockBehaviour.neighborChanged(BlockState, Level, BlockPos, Block, Orientation, boolean), IBlockExtension.onNeighborChange(BlockState, LevelReader, BlockPos, BlockPos) or BlockBehaviour.updateShape(BlockState, LevelReader, ScheduledTickAccess, BlockPos, Direction, BlockPos, BlockState, RandomSource) is called.
      Parameters:
      network - The network to update in.
      partNetwork - The part network to update in.
      target - The target block.
      state - The state
      world - The world in which the neighbour was updated.
      side - The side at the center block.
    • getConsumptionRate

      int getConsumptionRate(S state)
      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 state
      updated - If the INetworkElement.update(INetwork) was called.
    • isEnabled

      boolean isEnabled(S state)
      Parameters:
      state - The state
      Returns:
      If this part is enabled.
    • setEnabled

      void setEnabled(S state, boolean enabled)
      Set if this part should work.
      Parameters:
      state - The state
      enabled - If it should work.
    • loadTooltip

      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.
      Parameters:
      state - The state.
      lines - The list to add lines to.
    • loadTooltip

      void loadTooltip(net.minecraft.world.item.ItemStack itemStack, Consumer<net.minecraft.network.chat.Component> tooltipAdder)
      Add tooltip lines for this aspect when this part's item is being hovered.
      Parameters:
      itemStack - The itemstack.
      tooltipAdder - The list to add lines to.
    • shouldTriggerBlockRenderUpdate

      boolean shouldTriggerBlockRenderUpdate(@Nullable S oldPartState, @Nullable S newPartState)
      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

      boolean forceLightTransparency(S state)
      Parameters:
      state - The state.
      Returns:
      If this part should force the block to be transparent to light.
    • getContainerProvider

      default Optional<net.minecraft.world.MenuProvider> getContainerProvider(PartPos pos)
      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

      default Optional<net.minecraft.world.MenuProvider> getContainerProviderSettings(PartPos pos)
      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

      default Optional<net.minecraft.world.MenuProvider> getContainerProviderOffsets(PartPos pos)
      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.