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 Details

    • PartTypeAdapter

      public PartTypeAdapter()
  • Method Details

    • getTranslationKey

      public final String getTranslationKey()
      Specified by:
      getTranslationKey in interface IPartType<P extends IPartType<P,S>,S extends IPartState<P>>
      Returns:
      The unlocalized name of this part.
    • createTranslationKey

      protected abstract String createTranslationKey()
    • isSolid

      public boolean isSolid(S state)
      Specified by:
      isSolid in interface IPartType<P extends IPartType<P,S>,S extends IPartState<P>>
      Parameters:
      state - The state
      Returns:
      If this element is solid.
    • toNBT

      public void toNBT(net.minecraft.nbt.CompoundTag tag, S partState)
      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.
      Specified by:
      toNBT in interface IPartType<P extends IPartType<P,S>,S extends IPartState<P>>
      Parameters:
      tag - The tag to write to. This tag is guaranteed to be empty.
      partState - The state of this part.
    • 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.
      Specified by:
      fromNBT in interface IPartType<P extends IPartType<P,S>,S extends IPartState<P>>
      tag - The tag to read from.
      Returns:
      The state of this part.
    • setUpdateInterval

      public void setUpdateInterval(S state, int updateInterval)
      Description copied from interface: IPartType
      Set the update interval for this part.
      Specified by:
      setUpdateInterval in interface IPartType<P extends IPartType<P,S>,S extends IPartState<P>>
      Parameters:
      state - The state
      updateInterval - The tick interval to update this element.
    • getUpdateInterval

      public int getUpdateInterval(S state)
      Specified by:
      getUpdateInterval in interface IPartType<P extends IPartType<P,S>,S extends IPartState<P>>
      Parameters:
      state - The state
      Returns:
      The tick interval to update this element.
    • getMinimumUpdateInterval

      public int getMinimumUpdateInterval(S state)
      Specified by:
      getMinimumUpdateInterval in interface IPartType<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 interface IPartType<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
      priority - The new priority
      channel - The new channel
    • getPriority

      public int getPriority(S state)
      Specified by:
      getPriority in interface IPartType<P extends IPartType<P,S>,S extends IPartState<P>>
      Parameters:
      state - The state
      Returns:
      The priority of this part in the network.
    • getChannel

      public int getChannel(S state)
      Specified by:
      getChannel in interface IPartType<P extends IPartType<P,S>,S extends IPartState<P>>
      Parameters:
      state - The state
      Returns:
      The channel of this part in the network.
    • getTargetOffset

      public net.minecraft.core.Vec3i getTargetOffset(S state)
      Specified by:
      getTargetOffset in interface IPartType<P extends IPartType<P,S>,S extends IPartState<P>>
      Parameters:
      state - The state
      Returns:
      The target position offset.
    • setTargetOffset

      public boolean setTargetOffset(S state, PartPos center, net.minecraft.core.Vec3i offset)
      Specified by:
      setTargetOffset in interface IPartType<P extends IPartType<P,S>,S extends IPartState<P>>
      Parameters:
      state - The state
      center - The center position.
      offset - The target position offset.
      Returns:
      True if the offset was valid
    • setTargetSideOverride

      public void setTargetSideOverride(S state, @Nullable net.minecraft.core.Direction side)
      Description copied from interface: IPartType
      Indicate that the given part should interact with the given side of the target.
      Specified by:
      setTargetSideOverride in interface IPartType<P extends IPartType<P,S>,S extends IPartState<P>>
      Parameters:
      state - The state
      side - The side of the target block to interact with. Null removes the side override.
    • getTargetSideOverride

      @Nullable public net.minecraft.core.Direction getTargetSideOverride(S state)
      Specified by:
      getTargetSideOverride in interface IPartType<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

      public PartTarget getTarget(PartPos pos, S state)
      Description copied from interface: IPartType
      Get the part target for this part.
      Specified by:
      getTarget in interface IPartType<P extends IPartType<P,S>,S extends IPartState<P>>
      Parameters:
      pos - The center position of this part.
      state - The state.
      Returns:
      The part target.
    • hasOffsetVariables

      protected boolean hasOffsetVariables(S state)
    • onOffsetVariablesChanged

      public void onOffsetVariablesChanged(PartTarget target, S state)
      Description copied from interface: IPartType
      Called when an offset variable was inserted or removed from a slot.
      Specified by:
      onOffsetVariablesChanged in interface IPartType<P extends IPartType<P,S>,S extends IPartState<P>>
      Parameters:
      target - The target block.
      state - The state.
    • isUpdate

      public boolean isUpdate(S state)
      Specified by:
      isUpdate in interface IPartType<P extends IPartType<P,S>,S extends IPartState<P>>
      Parameters:
      state - The state
      Returns:
      If this element should be updated. This method is only called once during network initialization.
    • update

      public void update(INetwork network, IPartNetwork partNetwork, PartTarget target, S state)
      Description copied from interface: IPartType
      Update at the tick interval specified.
      Specified by:
      update in interface IPartType<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
    • 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 interface IPartType<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 interface IPartType<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 interface IPartType<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(S state, boolean saveState)
      Description copied from interface: IPartType
      Get the itemstack from the given state.
      Specified by:
      getItemStack in interface IPartType<P extends IPartType<P,S>,S extends IPartState<P>>
      Parameters:
      state - The state
      saveState - 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 interface IPartType<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.
      Specified by:
      getState in interface IPartType<P extends IPartType<P,S>,S extends IPartState<P>>
      itemStack - The itemstack possibly containing state information.
      Returns:
      The state contained in the itemstack or the default part state.
    • constructDefaultState

      protected abstract S constructDefaultState()
      Returns:
      Constructor call for a new default state for this part type.
    • defaultBlockState

      public S defaultBlockState()
      Specified by:
      defaultBlockState in interface IPartType<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 interface IPartType<P extends IPartType<P,S>,S extends IPartState<P>>
      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

      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 interface IPartType<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 interface IPartType<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 interface IPartType<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 interface IPartType<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

      public void onPreRemoved(INetwork network, IPartNetwork partNetwork, PartTarget target, S state)
      Description copied from interface: IPartType
      Called when this element is about to be removed.
      Specified by:
      onPreRemoved in interface IPartType<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

      public void onPostRemoved(INetwork network, IPartNetwork partNetwork, PartTarget target, S state)
      Description copied from interface: IPartType
      Called after this element has been removed.
      Specified by:
      onPostRemoved in interface IPartType<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 when BlockBehaviour.neighborChanged(BlockState, Level, BlockPos, Block, BlockPos, boolean), IForgeBlock.onNeighborChange(BlockState, LevelReader, BlockPos, BlockPos) or BlockBehaviour.updateShape(BlockState, Direction, BlockState, LevelAccessor, BlockPos, BlockPos) is called.
      Specified by:
      onBlockNeighborChange in interface IPartType<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
      world - 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

      public int getConsumptionRate(S state)
      Specified by:
      getConsumptionRate in interface IPartType<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 interface IPartType<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
      updated - If the INetworkElement.update(INetwork) was called.
    • isEnabled

      public boolean isEnabled(S state)
      Specified by:
      isEnabled in interface IPartType<P extends IPartType<P,S>,S extends IPartState<P>>
      Parameters:
      state - The state
      Returns:
      If this part is enabled.
    • setEnabled

      public void setEnabled(S state, boolean enabled)
      Description copied from interface: IPartType
      Set if this part should work.
      Specified by:
      setEnabled in interface IPartType<P extends IPartType<P,S>,S extends IPartState<P>>
      Parameters:
      state - The state
      enabled - If it should work.
    • loadTooltip

      public void loadTooltip(S state, List<net.minecraft.network.chat.Component> lines)
      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 interface IPartType<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 interface IPartType<P extends IPartType<P,S>,S extends IPartState<P>>
      Parameters:
      itemStack - The itemstack.
      lines - The list to add lines to.
    • shouldTriggerBlockRenderUpdate

      public boolean shouldTriggerBlockRenderUpdate(@Nullable S oldPartState, @Nullable S newPartState)
      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 interface IPartType<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 interface INetworkEventListener<P extends IPartType<P,S>>
      Returns:
      If this should be registered to the network event bus for listening to network events.
    • getSubscribedEvents

      public Set<Class<? extends INetworkEvent>> getSubscribedEvents()
      Specified by:
      getSubscribedEvents in interface INetworkEventListener<P extends IPartType<P,S>>
      Returns:
      The static set of events this listener should be subscribed to.
    • onEvent

      public void onEvent(INetworkEvent event, IPartNetworkElement<P,S> networkElement)
      Description copied from interface: INetworkEventListener
      Can be called at any time by the INetworkEventBus. Only events in the set from INetworkEventListener.getSubscribedEvents() will be received.
      Specified by:
      onEvent in interface INetworkEventListener<P extends IPartType<P,S>>
      Parameters:
      event - The received event.
      networkElement - The network element.