Class PartHelpers

java.lang.Object
org.cyclops.integrateddynamics.core.helper.PartHelpers

public class PartHelpers extends Object
Helpers related to parts.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    A callback for setting part state holders.
    static class 
    A part and state holder.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    addPart(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction side, IPartType partType, net.minecraft.world.item.ItemStack itemStack)
    Add a part to the given side with the part state in the given item.
    static boolean
    addPart(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction side, IPartType partType, IPartState partState)
    Add a part to the given side with the part state.
    static boolean
    canInteractWith(PartTarget target, net.minecraft.world.entity.player.Player player, IPartContainer expectedPartContainer)
    If the given player can currently interact with the part gui at the given position.
    static org.apache.commons.lang3.tuple.Pair<net.minecraft.core.Direction,? extends PartHelpers.PartStateHolder<?,?>>
    deserializePart(net.minecraft.world.level.storage.ValueInput valueInput, INetwork network, net.minecraft.core.BlockPos pos)
    Read part data from nbt.
    static void
    deserializeParts(net.minecraft.world.level.storage.ValueInput valueInput, INetwork network, net.minecraft.core.BlockPos pos, Map<net.minecraft.core.Direction,PartHelpers.PartStateHolder<?,?>> partData, net.minecraft.world.level.Level world)
    Read parts data from nbt.
    static org.apache.commons.lang3.tuple.Pair<net.minecraft.core.Direction,IPartType>
    deserializePartType(net.minecraft.world.level.storage.ValueInput valueInput, INetwork network, net.minecraft.core.BlockPos pos)
    Read a part from nbt.
    static org.apache.commons.lang3.tuple.Triple<IPartContainer,PartTypeBase,PartTarget>
    Construct a data holder for constructing a part-related container.
    getPart(PartPos partPos)
    Get a part at the given position.
    getPartContainer(net.neoforged.neoforge.common.extensions.ILevelExtension world, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction side)
    Deprecated.
    getPartContainer(net.neoforged.neoforge.common.extensions.ILevelExtension world, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction side, net.minecraft.world.level.block.state.BlockState blockState)
    Get the part container capability at the given position.
    getPartContainer(org.cyclops.cyclopscore.datastructure.DimPos dimPos, net.minecraft.core.Direction side)
    Deprecated.
    getPartContainer(org.cyclops.cyclopscore.datastructure.DimPos dimPos, net.minecraft.core.Direction side, net.minecraft.world.level.block.state.BlockState blockState, net.minecraft.world.level.block.entity.BlockEntity blockEntity)
    Get the part container capability at the given position.
    getPartContainerChecked(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction side)
    Get the part container capability at the given position.
    getPartContainerChecked(org.cyclops.cyclopscore.datastructure.DimPos dimPos, net.minecraft.core.Direction side)
    Get the part container capability at the given position.
    getPartContainerChecked(org.cyclops.cyclopscore.datastructure.DimPos dimPos, net.minecraft.core.Direction side, net.minecraft.world.level.block.state.BlockState blockState, net.minecraft.world.level.block.entity.BlockEntity blockEntity)
    Get the part container capability at the given position.
    Get the part container capability at the given position.
    static void
    openContainerAspectSettings(net.minecraft.server.level.ServerPlayer player, PartPos pos, IAspect<?,?> aspect)
    Open an aspect settings gui container from the server.
    static net.minecraft.world.InteractionResult
    openContainerPart(net.minecraft.server.level.ServerPlayer player, PartPos pos, IPartType<?,?> partType)
    Open a part gui container from the server.
    static boolean
    openContainerPartOffsets(net.minecraft.server.level.ServerPlayer player, PartPos pos, IPartType<?,?> partType)
    Open a part offset gui container from the server.
    static boolean
    openContainerPartSettings(net.minecraft.server.level.ServerPlayer player, PartPos pos, IPartType<?,?> partType)
    Open a part settings gui container from the server.
    static <P extends IPartType<P, S>, S extends IPartState<P>>
    P
    readPart(net.minecraft.network.FriendlyByteBuf packetBuffer)
    Read a part from a packet buffer.
    static PartTarget
    readPartTarget(net.minecraft.network.RegistryFriendlyByteBuf packetBuffer)
    Read a part target from a packet buffer.
    static boolean
    removePart(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction side, net.minecraft.world.entity.player.Player player, boolean destroyIfEmpty, boolean dropMainElement, boolean saveState)
    Remove a part from the given side of the given part container.
    static boolean
    serializePart(net.minecraft.world.level.storage.ValueOutput valueOutput, net.minecraft.core.BlockPos pos, org.apache.commons.lang3.tuple.Pair<net.minecraft.core.Direction,PartHelpers.PartStateHolder<?,?>> partData)
    Write the given part data to nbt.
    static void
    serializeParts(net.minecraft.world.level.storage.ValueOutput valueOutput, net.minecraft.core.BlockPos pos, Map<net.minecraft.core.Direction,PartHelpers.PartStateHolder<?,?>> partData)
    Write the given parts to nbt.
    static void
    serializePartType(net.minecraft.world.level.storage.ValueOutput valueOutput, net.minecraft.core.Direction side, IPartType partType)
    Write the given part type to nbt.
    static boolean
    setPart(INetwork network, net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction side, IPartType part, IPartState partState, PartHelpers.IPartStateHolderCallback callback)
    Forcefully set a part at the given side.
    static IPartType
    validatePartType(INetwork network, String partTypeName, IPartType partType)
    Check if the given part type is null and run it through the network even bus in an UnknownPartEvent to get another type.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PartHelpers

      public PartHelpers()
  • Method Details

    • getPartContainer

      @Deprecated public static Optional<IPartContainer> getPartContainer(net.neoforged.neoforge.common.extensions.ILevelExtension world, net.minecraft.core.BlockPos pos, @Nullable net.minecraft.core.Direction side)
      Deprecated.
      Get the part container capability at the given position. If possible, prefer using the variant with block state.
      Parameters:
      world - The world.
      pos - The position.
      side - The side.
      Returns:
      The optional part container capability.
    • getPartContainer

      public static Optional<IPartContainer> getPartContainer(net.neoforged.neoforge.common.extensions.ILevelExtension world, net.minecraft.core.BlockPos pos, @Nullable net.minecraft.core.Direction side, net.minecraft.world.level.block.state.BlockState blockState)
      Get the part container capability at the given position.
      Parameters:
      world - The world.
      pos - The position.
      side - The side.
      blockState - The block state.
      Returns:
      The optional part container capability.
    • getPartContainer

      @Deprecated public static Optional<IPartContainer> getPartContainer(org.cyclops.cyclopscore.datastructure.DimPos dimPos, @Nullable net.minecraft.core.Direction side)
      Deprecated.
      Get the part container capability at the given position. If possible, prefer using the variant with block state.
      Parameters:
      dimPos - The dimensional position.
      side - The side.
      Returns:
      The optional part container capability.
    • getPartContainer

      public static Optional<IPartContainer> getPartContainer(org.cyclops.cyclopscore.datastructure.DimPos dimPos, @Nullable net.minecraft.core.Direction side, @Nullable net.minecraft.world.level.block.state.BlockState blockState, @Nullable net.minecraft.world.level.block.entity.BlockEntity blockEntity)
      Get the part container capability at the given position.
      Parameters:
      dimPos - The dimensional position.
      side - The side.
      blockState - The block state.
      blockEntity - The block entity.
      Returns:
      The optional part container capability.
    • getPartContainerChecked

      public static IPartContainer getPartContainerChecked(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, @Nullable net.minecraft.core.Direction side)
      Get the part container capability at the given position. If it is not present, then an illegal state exception will be thrown. This should only be called if you know for certain that there will be a part container present.
      Parameters:
      world - The world.
      pos - The position.
      side - The side.
      Returns:
      The part container capability.
    • getPartContainerChecked

      public static IPartContainer getPartContainerChecked(org.cyclops.cyclopscore.datastructure.DimPos dimPos, @Nullable net.minecraft.core.Direction side)
      Get the part container capability at the given position. If it is not present, then an illegal state exception will be thrown. This should only be called if you know for certain that there will be a part container present.
      Parameters:
      dimPos - The dimensional position.
      side - The side.
      Returns:
      The part container capability.
    • getPartContainerChecked

      public static IPartContainer getPartContainerChecked(org.cyclops.cyclopscore.datastructure.DimPos dimPos, @Nullable net.minecraft.core.Direction side, @Nullable net.minecraft.world.level.block.state.BlockState blockState, @Nullable net.minecraft.world.level.block.entity.BlockEntity blockEntity)
      Get the part container capability at the given position. If it is not present, then an illegal state exception will be thrown.

      This should only be called if you know for certain that there will be a part container present.

      Parameters:
      dimPos - The dimensional position.
      side - The side.
      blockState - The block state.
      blockEntity - The block entity.
      Returns:
      The part container capability.
    • getPartContainerChecked

      public static IPartContainer getPartContainerChecked(PartPos pos)
      Get the part container capability at the given position. If it is not present, then an illegal state exception will be thrown. This should only be called if you know for certain that there will be a part container present.
      Parameters:
      pos - The part position.
      Returns:
      The part container capability.
    • validatePartType

      public static IPartType validatePartType(INetwork network, String partTypeName, @Nullable IPartType partType)
      Check if the given part type is null and run it through the network even bus in an UnknownPartEvent to get another type.
      Parameters:
      network - The network.
      partTypeName - The part name.
      partType - The part type.
      Returns:
      A possibly non-null part type.
    • serializePartType

      public static void serializePartType(net.minecraft.world.level.storage.ValueOutput valueOutput, net.minecraft.core.Direction side, IPartType partType)
      Write the given part type to nbt.
      Parameters:
      valueOutput - The output to write to.
      side - The side to write.
      partType - The part type to write.
    • serializePart

      public static boolean serializePart(net.minecraft.world.level.storage.ValueOutput valueOutput, net.minecraft.core.BlockPos pos, org.apache.commons.lang3.tuple.Pair<net.minecraft.core.Direction,PartHelpers.PartStateHolder<?,?>> partData)
      Write the given part data to nbt.
      Parameters:
      valueOutput - The output to write to.
      pos - The position of the part, used for error reporting.
      partData - The part data.
      Returns:
      If the writing succeeded.
    • serializeParts

      public static void serializeParts(net.minecraft.world.level.storage.ValueOutput valueOutput, net.minecraft.core.BlockPos pos, Map<net.minecraft.core.Direction,PartHelpers.PartStateHolder<?,?>> partData)
      Write the given parts to nbt.
      Parameters:
      valueOutput - The output to write to.
      pos - The position of the part, used for error reporting.
      partData - The part data.
    • deserializePartType

      public static org.apache.commons.lang3.tuple.Pair<net.minecraft.core.Direction,IPartType> deserializePartType(net.minecraft.world.level.storage.ValueInput valueInput, @Nullable INetwork network, net.minecraft.core.BlockPos pos)
      Read a part from nbt.
      Parameters:
      valueInput - The value to read from.
      network - The network the part will be part of.
      pos - The position of the part, used for error reporting.
      Returns:
      The part data.
    • deserializePart

      public static org.apache.commons.lang3.tuple.Pair<net.minecraft.core.Direction,? extends PartHelpers.PartStateHolder<?,?>> deserializePart(net.minecraft.world.level.storage.ValueInput valueInput, @Nullable INetwork network, net.minecraft.core.BlockPos pos)
      Read part data from nbt.
      Parameters:
      valueInput - The value to read from.
      network - The network the part will be part of.
      pos - The position of the part, used for error reporting.
      Returns:
      The part data.
    • deserializeParts

      public static void deserializeParts(net.minecraft.world.level.storage.ValueInput valueInput, @Nullable INetwork network, net.minecraft.core.BlockPos pos, Map<net.minecraft.core.Direction,PartHelpers.PartStateHolder<?,?>> partData, net.minecraft.world.level.Level world)
      Read parts data from nbt. If the world is not null and we are running client-side, a block render update will automatically be triggered if needed.
      Parameters:
      valueInput - The value to read from.
      network - The network the part will be part of.
      pos - The position of the part, used for error reporting.
      partData - The map of part data to write to.
      world - The world.
    • removePart

      public static boolean removePart(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction side, @Nullable net.minecraft.world.entity.player.Player player, boolean destroyIfEmpty, boolean dropMainElement, boolean saveState)
      Remove a part from the given side of the given part container.
      Parameters:
      world - The world.
      pos - The position of the container.
      side - The side.
      player - The player that is removing the part or null.
      destroyIfEmpty - If the cable block must be removed if no other parts are present after this removal.
      dropMainElement - If the main part element should be dropped.
      saveState - If the element state should be saved in the item.
      Returns:
      If the block was set to air (removed).
    • addPart

      public static boolean addPart(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction side, IPartType partType, net.minecraft.world.item.ItemStack itemStack)
      Add a part to the given side with the part state in the given item.
      Parameters:
      level - The world.
      pos - The position of the container.
      side - The side.
      partType - The part type.
      itemStack - The item holding the part state.
      Returns:
      If the part was added.
    • addPart

      public static boolean addPart(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction side, IPartType partType, IPartState partState)
      Add a part to the given side with the part state.
      Parameters:
      world - The world.
      pos - The position of the container.
      side - The side.
      partType - The part type.
      partState - The part state.
      Returns:
      If the part was added.
    • setPart

      public static boolean setPart(@Nullable INetwork network, net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction side, IPartType part, IPartState partState, PartHelpers.IPartStateHolderCallback callback)
      Forcefully set a part at the given side.
      Parameters:
      network - The network.
      world - The world.
      pos - The position of the container.
      side - The side.
      part - The part to set.
      partState - The part state to set.
      callback - The callback for the part state holder.
      Returns:
      If the part could be placed.
    • canInteractWith

      public static boolean canInteractWith(PartTarget target, net.minecraft.world.entity.player.Player player, IPartContainer expectedPartContainer)
      If the given player can currently interact with the part gui at the given position.
      Parameters:
      target - The part target.
      player - The player.
      expectedPartContainer - The expected part container.
      Returns:
      If the player can interact with it.
    • getPart

      @Nullable public static PartHelpers.PartStateHolder<?,?> getPart(PartPos partPos)
      Get a part at the given position.
      Parameters:
      partPos - The part position.
      Returns:
      The part.
    • openContainerPart

      public static net.minecraft.world.InteractionResult openContainerPart(net.minecraft.server.level.ServerPlayer player, PartPos pos, IPartType<?,?> partType)
      Open a part gui container from the server.
      Parameters:
      player - The player opening the gui.
      pos - The part position.
      partType - The part type.
      Returns:
      The action result.
    • openContainerPartSettings

      public static boolean openContainerPartSettings(net.minecraft.server.level.ServerPlayer player, PartPos pos, IPartType<?,?> partType)
      Open a part settings gui container from the server.
      Parameters:
      player - The player opening the gui.
      pos - The part position.
      partType - The part type.
      Returns:
      If the part has a container provider for settings.
    • openContainerAspectSettings

      public static void openContainerAspectSettings(net.minecraft.server.level.ServerPlayer player, PartPos pos, IAspect<?,?> aspect)
      Open an aspect settings gui container from the server.
      Parameters:
      player - The player opening the gui.
      pos - The part position.
      aspect - The aspect for which to show the settings.
    • openContainerPartOffsets

      public static boolean openContainerPartOffsets(net.minecraft.server.level.ServerPlayer player, PartPos pos, IPartType<?,?> partType)
      Open a part offset gui container from the server.
      Parameters:
      player - The player opening the gui.
      pos - The part position.
      partType - The part type.
      Returns:
      If the part has a container provider for offsets.
    • getContainerPartConstructionData

      public static org.apache.commons.lang3.tuple.Triple<IPartContainer,PartTypeBase,PartTarget> getContainerPartConstructionData(PartPos pos)
      Construct a data holder for constructing a part-related container.
      Parameters:
      pos - A part position.
      Returns:
      A data holder.
    • readPartTarget

      public static PartTarget readPartTarget(net.minecraft.network.RegistryFriendlyByteBuf packetBuffer)
      Read a part target from a packet buffer.
      Parameters:
      packetBuffer - A packet buffer.
      Returns:
      A part target.
    • readPart

      public static <P extends IPartType<P, S>, S extends IPartState<P>> P readPart(net.minecraft.network.FriendlyByteBuf packetBuffer)
      Read a part from a packet buffer.
      Type Parameters:
      P - The part type type.
      S - The part state type.
      Parameters:
      packetBuffer - A packet buffer.
      Returns:
      A part.