Package appeng.api.parts
Class PartHelper
java.lang.Object
appeng.api.parts.PartHelper
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancanPlacePartHost(@Nullable net.minecraft.world.entity.player.Player player, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos) static CableRenderModestatic @Nullable IPartHostgetOrPlacePartHost(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>
TgetPart(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 IPartgetPart(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 IPartHostgetPartHost(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos) Gets a part host at the given position.static @Nullable IPartHostplacePartHost(@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>
TsetPart(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.InteractionResultusePartItem(net.minecraft.world.item.context.UseOnContext context) When implementing a custom part in an addon, you can use this method inItem.useOn(net.minecraft.world.item.context.UseOnContext)of your parts item (if you're not using AE2s internal PartItem class) to implement part placement.
-
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 inItem.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. UseIPartHost.isEmpty()andIPartHost.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
- Returns:
- the render mode
-