Class PartHelper

java.lang.Object
appeng.api.parts.PartHelper

public final class PartHelper extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    canPlacePartHost(@Nullable net.minecraft.world.entity.player.Player player, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos)
     
     
    static @Nullable IPartHost
    getOrPlacePartHost(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, boolean force, @Nullable net.minecraft.world.entity.player.Player player)
    Gets or places a part host at the given position.
    static <T extends IPart>
    T
    getPart(IPartItem<T> partItem, net.minecraft.world.level.BlockGetter level, net.minecraft.core.BlockPos pos, @Nullable net.minecraft.core.Direction side)
    Tries to retrieve a part placed from a given part item from the world, and returns it.
    static @Nullable IPart
    getPart(net.minecraft.world.level.BlockGetter level, net.minecraft.core.BlockPos pos, @Nullable net.minecraft.core.Direction side)
    Tries to retrieve a part from the world, and returns it.
    static @Nullable IPartHost
    getPartHost(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos)
    Gets a part host at the given position.
    static @Nullable IPartHost
    placePartHost(@Nullable net.minecraft.world.entity.player.Player player, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos)
    Tries placing a new part host at the given location as a player.
    static <T extends IPart>
    T
    setPart(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, @Nullable net.minecraft.core.Direction side, @Nullable net.minecraft.world.entity.player.Player player, IPartItem<T> partItem)
    Place or replace a part at the given position and side.
    static net.minecraft.world.InteractionResult
    usePartItem(net.minecraft.world.item.context.UseOnContext context)
    When implementing a custom part in an addon, you can use this method in Item.useOn(net.minecraft.world.item.context.UseOnContext) of your parts item (if you're not using AE2s internal PartItem class) to implement part placement.

    Methods inherited from class java.lang.Object

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

    • usePartItem

      public static net.minecraft.world.InteractionResult usePartItem(net.minecraft.world.item.context.UseOnContext context)
      When implementing a custom part in an addon, you can use this method in Item.useOn(net.minecraft.world.item.context.UseOnContext) of your parts item (if you're not using AE2s internal PartItem class) to implement part placement.
      Returns:
      The result of placement suitable for returning from Item.useOn(UseOnContext).
    • getPart

      @Nullable public static <T extends IPart> T getPart(IPartItem<T> partItem, net.minecraft.world.level.BlockGetter level, net.minecraft.core.BlockPos pos, @Nullable @Nullable net.minecraft.core.Direction side)
      Tries to retrieve a part placed from a given part item from the world, and returns it.
      Parameters:
      side - Null will retrieve the part at the center (the cable).
    • getPart

      @Nullable public static @Nullable IPart getPart(net.minecraft.world.level.BlockGetter level, net.minecraft.core.BlockPos pos, @Nullable @Nullable net.minecraft.core.Direction side)
      Tries to retrieve a part from the world, and returns it.
      Parameters:
      side - Null will retrieve the part at the center (the cable).
    • setPart

      @Nullable public static <T extends IPart> T setPart(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, @Nullable @Nullable net.minecraft.core.Direction side, @Nullable @Nullable net.minecraft.world.entity.player.Player player, IPartItem<T> partItem)
      Place or replace a part at the given position and side. Use `null` as the side to place a cable in the center of the bus. An existing cable bus at the location will be reused, otherwise the existing block will be replaced with a cable bus if its material is replaceable.
      Parameters:
      player - The player is only used to set the ownership of the created grid node.
    • getOrPlacePartHost

      @Nullable public static @Nullable IPartHost getOrPlacePartHost(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos, boolean force, @Nullable @Nullable net.minecraft.world.entity.player.Player player)
      Gets or places a part host at the given position. The caller needs to handle empty part hosts. They should be cleaned up if they contain no parts, otherwise they may impact gameplay.

      Use IPartHost.isEmpty() and IPartHost.cleanup().

      Parameters:
      force - If true, an existing non-cable-bus block will be unconditionally replaced.
      player - The player trying to place the cable bus. Will be used to check if the player can actually place it if force is not true.
    • placePartHost

      @Nullable public static @Nullable IPartHost placePartHost(@Nullable @Nullable net.minecraft.world.entity.player.Player player, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos)
      Tries placing a new part host at the given location as a player.
      Returns:
      null if placing a new bus fails (even if a bus already is at that location)
    • canPlacePartHost

      public static boolean canPlacePartHost(@Nullable @Nullable net.minecraft.world.entity.player.Player player, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos)
    • getPartHost

      @Nullable public static @Nullable IPartHost getPartHost(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos)
      Gets a part host at the given position.
    • getCableRenderMode

      public static CableRenderMode getCableRenderMode()
      Returns:
      the render mode