Class PartHelpers

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

public class PartHelpers extends Object
Helpers related to parts.
  • Constructor Details

    • PartHelpers

      public PartHelpers()
  • Method Details

    • getPartContainer

      public static Optional<IPartContainer> getPartContainer(net.neoforged.neoforge.common.extensions.ILevelExtension world, net.minecraft.core.BlockPos pos, @Nullable net.minecraft.core.Direction side)
      Get the part container capability at the given position.
      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

      public static Optional<IPartContainer> getPartContainer(org.cyclops.cyclopscore.datastructure.DimPos dimPos, @Nullable net.minecraft.core.Direction side)
      Get the part container capability at the given position.
      Parameters:
      dimPos - The dimensional position.
      side - The side.
      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(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.
    • writePartTypeToNBT

      public static void writePartTypeToNBT(net.minecraft.nbt.CompoundTag partTag, net.minecraft.core.Direction side, IPartType partType)
      Write the given part type to nbt.
      Parameters:
      partTag - The tag to write to.
      side - The side to write.
      partType - The part type to write.
    • writePartToNBT

      public static boolean writePartToNBT(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.core.BlockPos pos, net.minecraft.nbt.CompoundTag partTag, org.apache.commons.lang3.tuple.Pair<net.minecraft.core.Direction,PartHelpers.PartStateHolder<?,?>> partData)
      Write the given part data to nbt.
      Parameters:
      pos - The position of the part, used for error reporting.
      partTag - The tag to write to.
      partData - The part data.
      Returns:
      If the writing succeeded.
    • writePartsToNBT

      public static void writePartsToNBT(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.core.BlockPos pos, net.minecraft.nbt.CompoundTag tag, Map<net.minecraft.core.Direction,PartHelpers.PartStateHolder<?,?>> partData)
      Write the given parts to nbt.
      Parameters:
      pos - The position of the part, used for error reporting.
      tag - The tag to write to.
      partData - The part data.
    • readPartTypeFromNBT

      public static org.apache.commons.lang3.tuple.Pair<net.minecraft.core.Direction,IPartType> readPartTypeFromNBT(@Nullable INetwork network, net.minecraft.core.BlockPos pos, net.minecraft.nbt.CompoundTag partTag)
      Read a part from nbt.
      Parameters:
      network - The network the part will be part of.
      pos - The position of the part, used for error reporting.
      partTag - The tag to read from.
      Returns:
      The part data.
    • readPartFromNBT

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

      public static void readPartsFromNBT(@Nullable INetwork network, net.minecraft.core.BlockPos pos, net.minecraft.nbt.CompoundTag tag, 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:
      network - The network the part will be part of.
      pos - The position of the part, used for error reporting.
      tag - The tag to read from.
      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.