Package alexiil.mc.lib.multipart.api
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):
getPickStack()(and optionallyaddDrops(DefaultedList)}
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAbstractPart.ItemDropTargetA target for retrieving item drops fromaddDrops(ItemDropTarget, LootContext). -
Field Summary
Fields Modifier and Type Field Description PartDefinitiondefinitionMultipartHolderholderstatic alexiil.mc.lib.net.ParentNetIdSingle<AbstractPart>NET_IDstatic alexiil.mc.lib.net.NetIdDataK<AbstractPart>NET_RENDER_DATAstatic 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 voidaddAllAttributes(alexiil.mc.lib.attributes.AttributeList<?> list)Offers every contained attribute to the given attribute list.voidaddDrops(AbstractPart.ItemDropTarget target, net.minecraft.loot.context.LootContext context)voidaddDrops(net.minecraft.util.collection.DefaultedList<net.minecraft.item.ItemStack> to)Deprecated.Replaced byaddDrops(ItemDropTarget, LootContext)protected voidaddRequiredPart(AbstractPart required)voidafterBreak(net.minecraft.entity.player.PlayerEntity player)Called instead ofBlock.afterBreak(World, PlayerEntity, BlockPos, BlockState, BlockEntity, ItemStack), except that this shouldn't drop any items, as that's handled separately.static floatcalcBreakingDelta(net.minecraft.entity.player.PlayerEntity player, net.minecraft.block.BlockState state, float hardness)CalculatescalculateBreakingDelta(PlayerEntity)as if this part was the given block state instead, but using a custom hardness value.floatcalculateBreakingDelta(net.minecraft.entity.player.PlayerEntity player)Part version ofAbstractBlock.calcBlockBreakingDelta(BlockState, PlayerEntity, BlockView, BlockPos).floatcalculateBreakingDelta(net.minecraft.entity.player.PlayerEntity player, net.minecraft.block.Block block)CalculatescalculateBreakingDelta(PlayerEntity)as if this part was the given block instead.floatcalculateBreakingDelta(net.minecraft.entity.player.PlayerEntity player, net.minecraft.block.BlockState state)CalculatescalculateBreakingDelta(PlayerEntity)as if this part was the given block state instead.booleancanOverlapWith(AbstractPart other)Checks to see if thisAbstractPartcan overlap with the other part.protected net.minecraft.block.BlockStategetClosestBlockState()net.minecraft.util.shape.VoxelShapegetCollisionShape()net.minecraft.util.shape.VoxelShapegetCullingShape()net.minecraft.util.shape.VoxelShapegetDynamicShape(float partialTicks)abstract PartModelKeygetModelKey()Called on the client for both rendering, and checking if this needs to re-render inMultipartContainer.redrawIfChanged().net.minecraft.util.shape.VoxelShapegetOutlineShape()net.minecraft.item.ItemStackgetPickStack()Called whenever this part is picked by the player (similar toBlock.getPickStack(BlockView, BlockPos, BlockState))abstract net.minecraft.util.shape.VoxelShapegetShape()booleanisBlocking(net.minecraft.util.math.Direction searchDirection)voidmirror(net.minecraft.util.BlockMirror mirror)Called wheneverBlockEntity.applyMirror(BlockMirror)is called on the containing block.voidonAdded(MultipartEventBus bus)Called whenever this part was added to theMultipartContainer, either inBlockEntity.cancelRemoval()or when it is manually added by an item.booleanonBreak(net.minecraft.entity.player.PlayerEntity player)Called instead ofBlock.onBreak(World, BlockPos, BlockState, PlayerEntity), to play the broken sound, and spawn break particles.voidonPlacedBy(net.minecraft.entity.player.PlayerEntity player, net.minecraft.util.Hand hand)Open method, that's designed to be called from theItemthat places this part into the world.voidonRemoved()net.minecraft.util.ActionResultonUse(net.minecraft.entity.player.PlayerEntity player, net.minecraft.util.Hand hand, net.minecraft.util.hit.BlockHitResult hit)Called whenever this part is used viaAbstractBlock.onUse(BlockState, World, BlockPos, PlayerEntity, Hand, BlockHitResult).protected voidplayBreakSound()Called by default inonBreak(PlayerEntity)to play the breaking sound.protected voidplayBreakSound(net.minecraft.block.BlockState blockState)protected voidplayHitSound(net.minecraft.block.BlockState blockState)voidplayHitSound(net.minecraft.entity.player.PlayerEntity player)Called instead ofBlock.onBreak(World, BlockPos, BlockState, PlayerEntity), to play the broken sound, and spawn break particles.protected static doublepos(net.minecraft.world.World world, net.minecraft.util.math.Direction side, net.minecraft.util.math.Direction.Axis axis, double size)voidreadRenderData(alexiil.mc.lib.net.NetByteBuf buffer, alexiil.mc.lib.net.IMsgReadCtx ctx)protected voidremoveRequiredPart(AbstractPart required)voidrotate(net.minecraft.util.BlockRotation rotation)Called wheneverBlockEntity.applyRotation(BlockRotation)is called on the containing block.<T> voidsendNetworkUpdate(T obj, alexiil.mc.lib.net.NetIdDataK<T> netId, alexiil.mc.lib.net.NetIdDataK.IMsgDataWriterK<T> writer)Sends the givenNetIdDataKto every player currently watching this multipart, with a customNetIdDataK.IMsgDataWriterK.<T> voidsendNetworkUpdate(T obj, alexiil.mc.lib.net.NetIdTyped<T> netId)Sends the givenNetIdDataKorNetIdSignalKto every player currently watching this multipart.<T> voidsendNetworkUpdateExcept(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 givenNetIdDataKto every player currently watching this multipart, with a customNetIdDataK.IMsgDataWriterK, except for the given player.<T> voidsendNetworkUpdateExcept(net.minecraft.entity.player.PlayerEntity except, T obj, alexiil.mc.lib.net.NetIdTyped<T> netId)Sends the givenNetIdDataKorNetIdSignalKto every player currently watching this multipart, except for the given player.booleanspawnBreakingParticles(net.minecraft.util.math.Direction side)Deprecated.This was renamed tospawnHitParticle(Direction)protected voidspawnBreakParticles()Called on the client to spawn break particles.protected voidspawnBreakParticles(net.minecraft.block.BlockState state)protected voidspawnBreakParticles(net.minecraft.block.BlockState state, net.minecraft.client.texture.Sprite sprite)protected voidspawnBreakParticles(net.minecraft.block.BlockState state, net.minecraft.util.Identifier spriteId)booleanspawnHitParticle(net.minecraft.util.math.Direction side)Spawns a single partial-break (hit) particle.protected voidspawnHitParticle(net.minecraft.util.math.Direction side, net.minecraft.block.BlockState state)protected voidspawnHitParticle(net.minecraft.util.math.Direction side, net.minecraft.block.BlockState state, net.minecraft.client.texture.Sprite sprite)protected voidspawnHitParticle(net.minecraft.util.math.Direction side, net.minecraft.block.BlockState state, net.minecraft.util.Identifier spriteId)protected voidspawnHitParticle(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.CompoundTagtoTag()voidwriteCreationData(alexiil.mc.lib.net.NetByteBuf buffer, alexiil.mc.lib.net.IMsgWriteCtx ctx)Writes the payload that will be passed intoPartDefinition.loadFromBuffer(MultipartHolder, NetByteBuf, IMsgReadCtx)on the client.voidwriteRenderData(alexiil.mc.lib.net.NetByteBuf buffer, alexiil.mc.lib.net.IMsgWriteCtx ctx)
-
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 intoPartDefinition.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 givenNetIdDataKorNetIdSignalKto 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 givenNetIdDataKto every player currently watching this multipart, with a customNetIdDataK.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 givenNetIdDataKorNetIdSignalKto 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 givenNetIdDataKto every player currently watching this multipart, with a customNetIdDataK.IMsgDataWriterK, except for the given player. -
onAdded
Called whenever this part was added to theMultipartContainer, either inBlockEntity.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 forholder.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 theItemthat 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 ofBlock.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
BlockStateto use forplayBreakSound(),playHitSound(PlayerEntity),spawnBreakParticles(),spawnHitParticle(Direction), andcalculateBreakingDelta(PlayerEntity).
-
playHitSound
@Environment(CLIENT) public void playHitSound(net.minecraft.entity.player.PlayerEntity player)Called instead ofBlock.onBreak(World, BlockPos, BlockState, PlayerEntity), to play the broken sound, and spawn break particles. -
playBreakSound
protected void playBreakSound()Called by default inonBreak(PlayerEntity)to play the breaking sound. The default implementation callsplayBreakSound(BlockState)withgetClosestBlockState(). -
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 tospawnHitParticle(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 callsspawnBreakParticles(BlockState)withgetClosestBlockState()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
-
removeRequiredPart
-
getShape
public abstract net.minecraft.util.shape.VoxelShape getShape()- Returns:
- The
VoxelShapeto use for calculating if this pluggable overlaps with another pluggable.
-
canOverlapWith
Checks to see if thisAbstractPartcan overlap with the other part. Note that this is only called if thegetShape()of this part intersects with thegetShape()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
MultipartContainerinMultipartContainer.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 returnVoxelShapes.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
obstaclefor attributes with it'sgetShape()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 useAttributeList.offer(Object, VoxelShape)withgetShape()as theVoxelShapeargument!The default implementation will
AttributeList.obstruct(VoxelShape)thegetShape()ifisBlocking(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 toBlock.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.Replaced byaddDrops(ItemDropTarget, LootContext) -
afterBreak
public void afterBreak(net.minecraft.entity.player.PlayerEntity player)Called instead ofBlock.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 ofAbstractBlock.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)CalculatescalculateBreakingDelta(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)CalculatescalculateBreakingDelta(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)CalculatescalculateBreakingDelta(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 viaAbstractBlock.onUse(BlockState, World, BlockPos, PlayerEntity, Hand, BlockHitResult). -
rotate
public void rotate(net.minecraft.util.BlockRotation rotation)Called wheneverBlockEntity.applyRotation(BlockRotation)is called on the containing block.- Parameters:
rotation- A rotation. LMP never calls this withBlockRotation.NONE
-
mirror
public void mirror(net.minecraft.util.BlockMirror mirror)Called wheneverBlockEntity.applyMirror(BlockMirror)is called on the containing block.- Parameters:
mirror- A mirror. LMP never calls this withBlockMirror.NONE
-
getModelKey
Called on the client for both rendering, and checking if this needs to re-render inMultipartContainer.redrawIfChanged().This is no longer called on the server.
- Returns:
- The
PartModelKeyfor thePartModelBakerto use to emit a static model. Returning null will bake nothing.
-