Class AbstractPart

java.lang.Object
alexiil.mc.lib.multipart.api.AbstractPart

public abstract class AbstractPart
extends java.lang.Object
The base class for every part in a multipart block.

Generally implementations will want to override (in addition to the abstract methods):

  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static interface  AbstractPart.ItemDropTarget
    A target for retrieving item drops from addDrops(ItemDropTarget, LootContext).
  • Field Summary

    Fields 
    Modifier and Type Field Description
    PartDefinition definition  
    MultipartHolder holder  
    static alexiil.mc.lib.net.ParentNetIdSingle<AbstractPart> NET_ID  
    static alexiil.mc.lib.net.NetIdDataK<AbstractPart> NET_RENDER_DATA  
    static alexiil.mc.lib.net.NetIdSignalK<AbstractPart> NET_SPAWN_BREAK_PARTICLES  
  • Constructor Summary

    Constructors 
    Constructor Description
    AbstractPart​(PartDefinition definition, MultipartHolder holder)  
  • Method Summary

    Modifier and Type Method Description
    void addAllAttributes​(alexiil.mc.lib.attributes.AttributeList<?> list)
    Offers every contained attribute to the given attribute list.
    void addDrops​(AbstractPart.ItemDropTarget target, net.minecraft.loot.context.LootContext context)  
    void addDrops​(net.minecraft.util.collection.DefaultedList<net.minecraft.item.ItemStack> to)
    Deprecated.
    protected void addRequiredPart​(AbstractPart required)  
    void afterBreak​(net.minecraft.entity.player.PlayerEntity player)
    Called instead of Block.afterBreak(World, PlayerEntity, BlockPos, BlockState, BlockEntity, ItemStack), except that this shouldn't drop any items, as that's handled separately.
    static float calcBreakingDelta​(net.minecraft.entity.player.PlayerEntity player, net.minecraft.block.BlockState state, float hardness)
    Calculates calculateBreakingDelta(PlayerEntity) as if this part was the given block state instead, but using a custom hardness value.
    float calculateBreakingDelta​(net.minecraft.entity.player.PlayerEntity player)
    Part version of AbstractBlock.calcBlockBreakingDelta(BlockState, PlayerEntity, BlockView, BlockPos).
    float calculateBreakingDelta​(net.minecraft.entity.player.PlayerEntity player, net.minecraft.block.Block block)
    Calculates calculateBreakingDelta(PlayerEntity) as if this part was the given block instead.
    float calculateBreakingDelta​(net.minecraft.entity.player.PlayerEntity player, net.minecraft.block.BlockState state)
    Calculates calculateBreakingDelta(PlayerEntity) as if this part was the given block state instead.
    boolean canOverlapWith​(AbstractPart other)
    Checks to see if this AbstractPart can overlap with the other part.
    protected net.minecraft.block.BlockState getClosestBlockState()  
    net.minecraft.util.shape.VoxelShape getCollisionShape()  
    net.minecraft.util.shape.VoxelShape getCullingShape()  
    net.minecraft.util.shape.VoxelShape getDynamicShape​(float partialTicks)  
    abstract PartModelKey getModelKey()
    Called on the client for both rendering, and checking if this needs to re-render in MultipartContainer.redrawIfChanged().
    net.minecraft.util.shape.VoxelShape getOutlineShape()  
    net.minecraft.item.ItemStack getPickStack()
    Called whenever this part is picked by the player (similar to Block.getPickStack(BlockView, BlockPos, BlockState))
    abstract net.minecraft.util.shape.VoxelShape getShape()  
    boolean isBlocking​(net.minecraft.util.math.Direction searchDirection)  
    void mirror​(net.minecraft.util.BlockMirror mirror)
    Called whenever BlockEntity.applyMirror(BlockMirror) is called on the containing block.
    void onAdded​(MultipartEventBus bus)
    Called whenever this part was added to the MultipartContainer, either in BlockEntity.cancelRemoval() or when it is manually added by an item.
    boolean onBreak​(net.minecraft.entity.player.PlayerEntity player)
    Called instead of Block.onBreak(World, BlockPos, BlockState, PlayerEntity), to play the broken sound, and spawn break particles.
    void onPlacedBy​(net.minecraft.entity.player.PlayerEntity player, net.minecraft.util.Hand hand)
    Open method, that's designed to be called from the Item that places this part into the world.
    void onRemoved()  
    net.minecraft.util.ActionResult onUse​(net.minecraft.entity.player.PlayerEntity player, net.minecraft.util.Hand hand, net.minecraft.util.hit.BlockHitResult hit)
    Called whenever this part is used via AbstractBlock.onUse(BlockState, World, BlockPos, PlayerEntity, Hand, BlockHitResult).
    protected void playBreakSound()
    Called by default in onBreak(PlayerEntity) to play the breaking sound.
    protected void playBreakSound​(net.minecraft.block.BlockState blockState)  
    protected void playHitSound​(net.minecraft.block.BlockState blockState)  
    void playHitSound​(net.minecraft.entity.player.PlayerEntity player)
    Called instead of Block.onBreak(World, BlockPos, BlockState, PlayerEntity), to play the broken sound, and spawn break particles.
    protected static double pos​(net.minecraft.world.World world, net.minecraft.util.math.Direction side, net.minecraft.util.math.Direction.Axis axis, double size)  
    void readRenderData​(alexiil.mc.lib.net.NetByteBuf buffer, alexiil.mc.lib.net.IMsgReadCtx ctx)  
    protected void removeRequiredPart​(AbstractPart required)  
    void rotate​(net.minecraft.util.BlockRotation rotation)
    Called whenever BlockEntity.applyRotation(BlockRotation) is called on the containing block.
    <T> void sendNetworkUpdate​(T obj, alexiil.mc.lib.net.NetIdDataK<T> netId, alexiil.mc.lib.net.NetIdDataK.IMsgDataWriterK<T> writer)
    Sends the given NetIdDataK to every player currently watching this multipart, with a custom NetIdDataK.IMsgDataWriterK.
    <T> void sendNetworkUpdate​(T obj, alexiil.mc.lib.net.NetIdTyped<T> netId)
    Sends the given NetIdDataK or NetIdSignalK to every player currently watching this multipart.
    <T> void sendNetworkUpdateExcept​(net.minecraft.entity.player.PlayerEntity except, T obj, alexiil.mc.lib.net.NetIdDataK<T> netId, alexiil.mc.lib.net.NetIdDataK.IMsgDataWriterK<T> writer)
    Sends the given NetIdDataK to every player currently watching this multipart, with a custom NetIdDataK.IMsgDataWriterK, except for the given player.
    <T> void sendNetworkUpdateExcept​(net.minecraft.entity.player.PlayerEntity except, T obj, alexiil.mc.lib.net.NetIdTyped<T> netId)
    Sends the given NetIdDataK or NetIdSignalK to every player currently watching this multipart, except for the given player.
    boolean spawnBreakingParticles​(net.minecraft.util.math.Direction side)
    Deprecated.
    This was renamed to spawnHitParticle(Direction)
    protected void spawnBreakParticles()
    Called on the client to spawn break particles.
    protected void spawnBreakParticles​(net.minecraft.block.BlockState state)  
    protected void spawnBreakParticles​(net.minecraft.block.BlockState state, net.minecraft.client.texture.Sprite sprite)  
    protected void spawnBreakParticles​(net.minecraft.block.BlockState state, net.minecraft.util.Identifier spriteId)  
    boolean spawnHitParticle​(net.minecraft.util.math.Direction side)
    Spawns a single partial-break (hit) particle.
    protected void spawnHitParticle​(net.minecraft.util.math.Direction side, net.minecraft.block.BlockState state)  
    protected void spawnHitParticle​(net.minecraft.util.math.Direction side, net.minecraft.block.BlockState state, net.minecraft.client.texture.Sprite sprite)  
    protected void spawnHitParticle​(net.minecraft.util.math.Direction side, net.minecraft.block.BlockState state, net.minecraft.util.Identifier spriteId)  
    protected void spawnHitParticle​(net.minecraft.util.math.Direction side, net.minecraft.util.math.Box box, net.minecraft.block.BlockState state, net.minecraft.client.texture.Sprite sprite)  
    net.minecraft.nbt.CompoundTag toTag()  
    void writeCreationData​(alexiil.mc.lib.net.NetByteBuf buffer, alexiil.mc.lib.net.IMsgWriteCtx ctx)
    Writes the payload that will be passed into PartDefinition.loadFromBuffer(MultipartHolder, NetByteBuf, IMsgReadCtx) on the client.
    void writeRenderData​(alexiil.mc.lib.net.NetByteBuf buffer, alexiil.mc.lib.net.IMsgWriteCtx ctx)  

    Methods inherited from class java.lang.Object

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

  • Constructor Details

  • Method Details

    • toTag

      public net.minecraft.nbt.CompoundTag toTag()
    • writeCreationData

      public void writeCreationData​(alexiil.mc.lib.net.NetByteBuf buffer, alexiil.mc.lib.net.IMsgWriteCtx ctx)
      Writes the payload that will be passed into PartDefinition.loadFromBuffer(MultipartHolder, NetByteBuf, IMsgReadCtx) on the client. (This is called on the server and sent to the client). Note that this will be called *instead* of write and read payload.
    • writeRenderData

      public void writeRenderData​(alexiil.mc.lib.net.NetByteBuf buffer, alexiil.mc.lib.net.IMsgWriteCtx ctx)
    • readRenderData

      public void readRenderData​(alexiil.mc.lib.net.NetByteBuf buffer, alexiil.mc.lib.net.IMsgReadCtx ctx) throws alexiil.mc.lib.net.InvalidInputDataException
      Throws:
      alexiil.mc.lib.net.InvalidInputDataException
    • sendNetworkUpdate

      public final <T> void sendNetworkUpdate​(T obj, alexiil.mc.lib.net.NetIdTyped<T> netId)
      Sends the given NetIdDataK or NetIdSignalK to every player currently watching this multipart.
    • sendNetworkUpdate

      public final <T> void sendNetworkUpdate​(T obj, alexiil.mc.lib.net.NetIdDataK<T> netId, alexiil.mc.lib.net.NetIdDataK.IMsgDataWriterK<T> writer)
      Sends the given NetIdDataK to every player currently watching this multipart, with a custom NetIdDataK.IMsgDataWriterK.
    • sendNetworkUpdateExcept

      public final <T> void sendNetworkUpdateExcept​(@Nullable net.minecraft.entity.player.PlayerEntity except, T obj, alexiil.mc.lib.net.NetIdTyped<T> netId)
      Sends the given NetIdDataK or NetIdSignalK to every player currently watching this multipart, except for the given player.
    • sendNetworkUpdateExcept

      public final <T> void sendNetworkUpdateExcept​(@Nullable net.minecraft.entity.player.PlayerEntity except, T obj, alexiil.mc.lib.net.NetIdDataK<T> netId, alexiil.mc.lib.net.NetIdDataK.IMsgDataWriterK<T> writer)
      Sends the given NetIdDataK to every player currently watching this multipart, with a custom NetIdDataK.IMsgDataWriterK, except for the given player.
    • onAdded

      public void onAdded​(MultipartEventBus bus)
      Called whenever this part was added to the MultipartContainer, either in BlockEntity.cancelRemoval() or when it is manually added by an item.

      Register event handlers (as methods) with MultipartEventBus.addListener(Object, Class, EventListener).

      Parameters:
      bus - The event bus to register with. This is shorthand for holder.getContainer().getEventBus()
    • onRemoved

      public void onRemoved()
    • onPlacedBy

      public void onPlacedBy​(net.minecraft.entity.player.PlayerEntity player, net.minecraft.util.Hand hand)
      Open method, that's designed to be called from the Item that places this part into the world.

      (Nothing calls this by default, as all parts are placed from a custom item).

    • onBreak

      public boolean onBreak​(net.minecraft.entity.player.PlayerEntity player)
      Called instead of Block.onBreak(World, BlockPos, BlockState, PlayerEntity), to play the broken sound, and spawn break particles.
      Returns:
      True if this should prevent Block.onBreak(World, BlockPos, BlockState, PlayerEntity) from being called afterwards, false otherwise.
    • getClosestBlockState

      protected net.minecraft.block.BlockState getClosestBlockState()
      Returns:
      The BlockState to use for playBreakSound(), playHitSound(PlayerEntity), spawnBreakParticles(), spawnHitParticle(Direction), and calculateBreakingDelta(PlayerEntity).
    • playHitSound

      @Environment(CLIENT) public void playHitSound​(net.minecraft.entity.player.PlayerEntity player)
      Called instead of Block.onBreak(World, BlockPos, BlockState, PlayerEntity), to play the broken sound, and spawn break particles.
    • playBreakSound

      protected void playBreakSound()
      Called by default in onBreak(PlayerEntity) to play the breaking sound. The default implementation calls playBreakSound(BlockState) with getClosestBlockState().
    • playBreakSound

      protected final void playBreakSound​(net.minecraft.block.BlockState blockState)
    • playHitSound

      @Environment(CLIENT) protected final void playHitSound​(net.minecraft.block.BlockState blockState)
    • spawnBreakingParticles

      @Environment(CLIENT) @Deprecated public boolean spawnBreakingParticles​(net.minecraft.util.math.Direction side)
      Deprecated.
      This was renamed to spawnHitParticle(Direction)
      Spawns a single breaking particle.
      Parameters:
      side - The side that was hit
      Returns:
      True to cancel the default breaking particle from spawning, false otherwise.
    • spawnHitParticle

      @Environment(CLIENT) public boolean spawnHitParticle​(net.minecraft.util.math.Direction side)
      Spawns a single partial-break (hit) particle.
      Parameters:
      side - The side that was hit
      Returns:
      True to cancel the default breaking particle from spawning, false otherwise.
    • spawnHitParticle

      @Environment(CLIENT) protected final void spawnHitParticle​(net.minecraft.util.math.Direction side, net.minecraft.block.BlockState state)
    • spawnHitParticle

      @Environment(CLIENT) protected final void spawnHitParticle​(net.minecraft.util.math.Direction side, net.minecraft.block.BlockState state, @Nullable net.minecraft.util.Identifier spriteId)
    • spawnHitParticle

      @Environment(CLIENT) protected final void spawnHitParticle​(net.minecraft.util.math.Direction side, net.minecraft.block.BlockState state, @Nullable net.minecraft.client.texture.Sprite sprite)
    • spawnHitParticle

      @Environment(CLIENT) protected final void spawnHitParticle​(net.minecraft.util.math.Direction side, net.minecraft.util.math.Box box, net.minecraft.block.BlockState state, @Nullable net.minecraft.client.texture.Sprite sprite)
    • pos

      protected static final double pos​(net.minecraft.world.World world, net.minecraft.util.math.Direction side, net.minecraft.util.math.Direction.Axis axis, double size)
    • spawnBreakParticles

      @Environment(CLIENT) protected void spawnBreakParticles()
      Called on the client to spawn break particles. This calls spawnBreakParticles(BlockState) with getClosestBlockState() by default.
    • spawnBreakParticles

      @Environment(CLIENT) protected final void spawnBreakParticles​(net.minecraft.block.BlockState state)
    • spawnBreakParticles

      @Environment(CLIENT) protected final void spawnBreakParticles​(net.minecraft.block.BlockState state, @Nullable net.minecraft.util.Identifier spriteId)
    • spawnBreakParticles

      @Environment(CLIENT) protected final void spawnBreakParticles​(net.minecraft.block.BlockState state, @Nullable net.minecraft.client.texture.Sprite sprite)
    • addRequiredPart

      protected final void addRequiredPart​(AbstractPart required)
    • removeRequiredPart

      protected final void removeRequiredPart​(AbstractPart required)
    • getShape

      public abstract net.minecraft.util.shape.VoxelShape getShape()
      Returns:
      The VoxelShape to use for calculating if this pluggable overlaps with another pluggable.
    • canOverlapWith

      public boolean canOverlapWith​(AbstractPart other)
      Checks to see if this AbstractPart can overlap with the other part. Note that this is only called if the getShape() of this part intersects with the getShape() of the other part. However this is never called if the shape of one of the parts is completely contained by the shape of the other part.

      This is called once for each part currently contained in a MultipartContainer in MultipartContainer.offerNewPart(MultipartCreator, boolean).

    • getCollisionShape

      public net.minecraft.util.shape.VoxelShape getCollisionShape()
      Returns:
      The shape to use when solidity logic, collisions with entities, ray tracing, etc. This should always encompass getShape().
    • getCullingShape

      public net.minecraft.util.shape.VoxelShape getCullingShape()
      Returns:
      The shape to use when calculating lighting and checking for opacity. This may be empty, although it should always be contained by getCollisionShape(). Generally anything that's not opaque should override this and return VoxelShapes.empty().
    • getOutlineShape

      public net.minecraft.util.shape.VoxelShape getOutlineShape()
      Returns:
      The shape for rendering bounding boxes and ray tracing.
    • getDynamicShape

      public net.minecraft.util.shape.VoxelShape getDynamicShape​(float partialTicks)
      Returns:
      The (potentially dynamic) shape for rendering bounding boxes and ray tracing. Unlike getOutlineShape() this is only called when rendering the box for this specific part.
    • isBlocking

      public boolean isBlocking​(net.minecraft.util.math.Direction searchDirection)
      Returns:
      True if this pluggable should be an obstacle for attributes with it's getShape() when searching in this particular direction.
    • addAllAttributes

      public void addAllAttributes​(alexiil.mc.lib.attributes.AttributeList<?> list)
      Offers every contained attribute to the given attribute list. NOTE: This must always use AttributeList.offer(Object, VoxelShape) with getShape() as the VoxelShape argument!

      The default implementation will AttributeList.obstruct(VoxelShape) the getShape() if isBlocking(Direction) returns true, and the search direction is not null.

    • getPickStack

      public net.minecraft.item.ItemStack getPickStack()
      Called whenever this part is picked by the player (similar to Block.getPickStack(BlockView, BlockPos, BlockState))
      Returns:
      The stack that should be picked, or ItemStack.EMPTY if no stack can be picked from this part.
    • addDrops

      public void addDrops​(AbstractPart.ItemDropTarget target, net.minecraft.loot.context.LootContext context)
    • addDrops

      @Deprecated public void addDrops​(net.minecraft.util.collection.DefaultedList<net.minecraft.item.ItemStack> to)
      Deprecated.
    • afterBreak

      public void afterBreak​(net.minecraft.entity.player.PlayerEntity player)
      Called instead of Block.afterBreak(World, PlayerEntity, BlockPos, BlockState, BlockEntity, ItemStack), except that this shouldn't drop any items, as that's handled separately.
    • calculateBreakingDelta

      public float calculateBreakingDelta​(net.minecraft.entity.player.PlayerEntity player)
      Part version of AbstractBlock.calcBlockBreakingDelta(BlockState, PlayerEntity, BlockView, BlockPos).

      The default implementation treats parts as equal to getClosestBlockState().

    • calculateBreakingDelta

      public final float calculateBreakingDelta​(net.minecraft.entity.player.PlayerEntity player, net.minecraft.block.Block block)
      Calculates calculateBreakingDelta(PlayerEntity) as if this part was the given block instead.
    • calculateBreakingDelta

      public final float calculateBreakingDelta​(net.minecraft.entity.player.PlayerEntity player, net.minecraft.block.BlockState state)
      Calculates calculateBreakingDelta(PlayerEntity) as if this part was the given block state instead.
    • calcBreakingDelta

      public static float calcBreakingDelta​(net.minecraft.entity.player.PlayerEntity player, net.minecraft.block.BlockState state, float hardness)
      Calculates calculateBreakingDelta(PlayerEntity) as if this part was the given block state instead, but using a custom hardness value.
    • onUse

      public net.minecraft.util.ActionResult onUse​(net.minecraft.entity.player.PlayerEntity player, net.minecraft.util.Hand hand, net.minecraft.util.hit.BlockHitResult hit)
      Called whenever this part is used via AbstractBlock.onUse(BlockState, World, BlockPos, PlayerEntity, Hand, BlockHitResult).
    • rotate

      public void rotate​(net.minecraft.util.BlockRotation rotation)
      Called whenever BlockEntity.applyRotation(BlockRotation) is called on the containing block.
      Parameters:
      rotation - A rotation. LMP never calls this with BlockRotation.NONE
    • mirror

      public void mirror​(net.minecraft.util.BlockMirror mirror)
      Called whenever BlockEntity.applyMirror(BlockMirror) is called on the containing block.
      Parameters:
      mirror - A mirror. LMP never calls this with BlockMirror.NONE
    • getModelKey

      @Nullable public abstract PartModelKey getModelKey()
      Called on the client for both rendering, and checking if this needs to re-render in MultipartContainer.redrawIfChanged().

      This is no longer called on the server.

      Returns:
      The PartModelKey for the PartModelBaker to use to emit a static model. Returning null will bake nothing.