Class AbstractPart
- Direct Known Subclasses:
MissingPart
Generally implementations will want to override (in addition to the abstract methods):
getPickStack(BlockHitResult)(and optionallyaddDrops(DefaultedList)}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA target for retrieving item drops fromaddDrops(ItemDropTarget, LootContext). -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal MultipartContainerfinal PartDefinitionfinal MultipartHolderstatic final ParentNetIdSingle<AbstractPart>static final NetIdDataK<AbstractPart>static final NetIdSignalK<AbstractPart>static final NetIdDataK<AbstractPart> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAllAttributes(AttributeList<?> list) Offers every contained attribute to the given attribute list.voidaddDrops(AbstractPart.ItemDropTarget target, LootContext context) voidDeprecated.protected final voidaddRequiredPart(AbstractPart required) voidafterBreak(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(PlayerEntity player, BlockState state, float hardness) CalculatescalculateBreakingDelta(PlayerEntity)as if this part was the given block state instead, but using a custom hardness value.floatcalculateBreakingDelta(PlayerEntity player) final floatcalculateBreakingDelta(PlayerEntity player, Block block) CalculatescalculateBreakingDelta(PlayerEntity)as if this part was the given block instead.final floatcalculateBreakingDelta(PlayerEntity player, 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 BlockStategetDynamicShape(float partialTicks) Deprecated.Use (and implement)getDynamicShape(float, Vec3d)instead.getDynamicShape(float partialTicks, Vec3d hitVec) abstract PartModelKeyCalled on the client for both rendering, and checking if this needs to re-render inMultipartContainer.redrawIfChanged().Deprecated.Use (and implement)getPickStack(BlockHitResult)instead.getPickStack(BlockHitResult hitResult) Called whenever this part is picked by the player (similar toBlock.getPickStack(BlockView, BlockPos, BlockState)but with aBlockHitResultfor picking pieces of parts).abstract VoxelShapegetShape()booleanisBlocking(Direction searchDirection) voidmirror(BlockMirror mirror) Deprecated.Please use thePartTransformEvent.Mirrorevent instead.voidonAdded(MultipartEventBus bus) Called whenever this part was added to theMultipartContainer, either inBlockEntity.cancelRemoval()or when it is manually added by an item.booleanonBreak(PlayerEntity player) Called instead ofBlock.onBreak(World, BlockPos, BlockState, PlayerEntity), to play the broken sound, and spawn break particles.voidonPlacedBy(PlayerEntity player, Hand hand) Open method, that's designed to be called from theItemthat places this part into the world.voidbooleanonSpawnFallParticles(LivingEntity fallenEntity, Random entityRandom) Called on the server when an entity has fallen on this part and is attempting to spawn particles for it.onUse(PlayerEntity player, Hand hand, BlockHitResult hit) Called whenever this part is used viaAbstractBlock.onUse(BlockState, World, BlockPos, PlayerEntity, Hand, BlockHitResult).protected voidCalled by default inonBreak(PlayerEntity)to play the breaking sound.protected final voidplayBreakSound(BlockState blockState) protected final voidplayHitSound(BlockState blockState) voidplayHitSound(PlayerEntity player) Called instead ofBlock.onBreak(World, BlockPos, BlockState, PlayerEntity), to play the broken sound, and spawn break particles.protected static final doublepos(World world, Direction side, Direction.Axis axis, double size) voidreadRenderData(NetByteBuf buffer, IMsgReadCtx ctx) protected final voidremoveRequiredPart(AbstractPart required) voidrotate(BlockRotation rotation) Deprecated.Please use thePartTransformEvent.Rotateevent instead.final <T> voidsendNetworkUpdate(T obj, NetIdDataK<T> netId, NetIdDataK.IMsgDataWriterK<T> writer) Sends the givenNetIdDataKto every player currently watching this multipart, with a customNetIdDataK.IMsgDataWriterK.final <T> voidsendNetworkUpdate(T obj, NetIdTyped<T> netId) Sends the givenNetIdDataKorNetIdSignalKto every player currently watching this multipart.final <T> voidsendNetworkUpdateExcept(PlayerEntity except, T obj, NetIdDataK<T> netId, NetIdDataK.IMsgDataWriterK<T> writer) Sends the givenNetIdDataKto every player currently watching this multipart, with a customNetIdDataK.IMsgDataWriterK, except for the given player.final <T> voidsendNetworkUpdateExcept(PlayerEntity except, T obj, NetIdTyped<T> netId) Sends the givenNetIdDataKorNetIdSignalKto every player currently watching this multipart, except for the given player.protected final voidsendSpawnFallParticles(Vec3d pos, int count) Actually Sends the packet from the server to the clients that spawns the fall particles.booleanDeprecated.This was renamed tospawnHitParticle(Direction)protected voidCalled on the client to spawn break particles.protected final voidspawnBreakParticles(BlockState state) protected final voidspawnBreakParticles(BlockState state, Sprite sprite) protected final voidspawnBreakParticles(BlockState state, Identifier spriteId) protected voidspawnFallParticles(Vec3d pos, int count) Called on the client to spawn fall particles.protected final voidspawnFallParticles(Vec3d pos, int count, BlockState state) protected final voidspawnFallParticles(Vec3d pos, int count, BlockState state, Sprite sprite) protected final voidspawnFallParticles(Vec3d pos, int count, BlockState state, Identifier spriteId) booleanspawnHitParticle(Direction side) Spawns a single partial-break (hit) particle.protected final voidspawnHitParticle(Direction side, BlockState state) protected final voidspawnHitParticle(Direction side, BlockState state, Sprite sprite) protected final voidspawnHitParticle(Direction side, BlockState state, Identifier spriteId) protected final voidspawnHitParticle(Direction side, Box box, BlockState state, Sprite sprite) booleanspawnIronGolemParticle(IronGolemEntity ironGolem, Random entityRandom) Spawns a single particle for when an iron golem walks on this part.protected final voidspawnIronGolemParticle(IronGolemEntity ironGolem, Random entityRandom, BlockState state) protected final voidspawnIronGolemParticle(IronGolemEntity ironGolem, Random entityRandom, BlockState state, Sprite sprite) protected final voidspawnIronGolemParticle(IronGolemEntity ironGolem, Random entityRandom, BlockState state, Identifier spriteId) booleanspawnSprintParticle(Entity sprintingEntity, Random entityRandom) Spawns a single sprint particle.protected final voidspawnSprintParticle(Entity sprintingEntity, Random entityRandom, BlockState state) protected final voidspawnSprintParticle(Entity sprintingEntity, Random entityRandom, BlockState state, Sprite sprite) protected final voidspawnSprintParticle(Entity sprintingEntity, Random entityRandom, BlockState state, Identifier spriteId) toTag()voidwriteCreationData(NetByteBuf buffer, IMsgWriteCtx ctx) Writes the payload that will be passed intoPartDefinition.loadFromBuffer(MultipartHolder, NetByteBuf, IMsgReadCtx)on the client.voidwriteRenderData(NetByteBuf buffer, IMsgWriteCtx ctx)
-
Field Details
-
NET_ID
-
NET_RENDER_DATA
-
NET_SPAWN_BREAK_PARTICLES
-
NET_SPAWN_FALL_PARTICLES
-
definition
-
holder
-
container
-
-
Constructor Details
-
AbstractPart
-
-
Method Details
-
toTag
-
writeCreationData
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
-
readRenderData
- Throws:
InvalidInputDataException
-
sendNetworkUpdate
Sends the givenNetIdDataKorNetIdSignalKto every player currently watching this multipart. -
sendNetworkUpdate
public final <T> void sendNetworkUpdate(T obj, NetIdDataK<T> netId, NetIdDataK.IMsgDataWriterK<T> writer) Sends the givenNetIdDataKto every player currently watching this multipart, with a customNetIdDataK.IMsgDataWriterK. -
sendNetworkUpdateExcept
public final <T> void sendNetworkUpdateExcept(@Nullable PlayerEntity except, T obj, NetIdTyped<T> netId) Sends the givenNetIdDataKorNetIdSignalKto every player currently watching this multipart, except for the given player. -
sendNetworkUpdateExcept
public final <T> void sendNetworkUpdateExcept(@Nullable PlayerEntity except, T obj, NetIdDataK<T> netId, 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
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
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
- Returns:
- The
BlockStateto use forplayBreakSound(),playHitSound(PlayerEntity),spawnBreakParticles(),spawnHitParticle(Direction), andcalculateBreakingDelta(PlayerEntity).
-
playHitSound
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
-
playHitSound
-
spawnBreakingParticles
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
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
-
spawnHitParticle
@Environment(CLIENT) protected final void spawnHitParticle(Direction side, BlockState state, @Nullable Identifier spriteId) -
spawnHitParticle
@Environment(CLIENT) protected final void spawnHitParticle(Direction side, BlockState state, @Nullable Sprite sprite) -
spawnHitParticle
@Environment(CLIENT) protected final void spawnHitParticle(Direction side, Box box, BlockState state, @Nullable Sprite sprite) -
pos
-
spawnBreakParticles
@Environment(CLIENT) protected void spawnBreakParticles()Called on the client to spawn break particles. This callsspawnBreakParticles(BlockState)withgetClosestBlockState()by default. -
spawnBreakParticles
-
spawnBreakParticles
@Environment(CLIENT) protected final void spawnBreakParticles(BlockState state, @Nullable Identifier spriteId) -
spawnBreakParticles
@Environment(CLIENT) protected final void spawnBreakParticles(BlockState state, @Nullable Sprite sprite) -
spawnSprintParticle
@Environment(CLIENT) public boolean spawnSprintParticle(Entity sprintingEntity, Random entityRandom) Spawns a single sprint particle.- Parameters:
sprintingEntity- The entity doing the sprinting.entityRandom- The entity's random for use in particle position & velocity calculations.- Returns:
- True to cancel the default sprinting particle from spawning, false otherwise.
-
spawnSprintParticle
@Environment(CLIENT) protected final void spawnSprintParticle(Entity sprintingEntity, Random entityRandom, BlockState state) -
spawnSprintParticle
@Environment(CLIENT) protected final void spawnSprintParticle(Entity sprintingEntity, Random entityRandom, BlockState state, @Nullable Identifier spriteId) -
spawnSprintParticle
@Environment(CLIENT) protected final void spawnSprintParticle(Entity sprintingEntity, Random entityRandom, BlockState state, @Nullable Sprite sprite) -
spawnIronGolemParticle
@Environment(CLIENT) public boolean spawnIronGolemParticle(IronGolemEntity ironGolem, Random entityRandom) Spawns a single particle for when an iron golem walks on this part.- Parameters:
ironGolem- The iron golem doing the walking.entityRandom- The iron golem's random for use in particle position & velocity calculations.- Returns:
- True to cancel the default iron golem walking particle from spawning, false otherwise.
-
spawnIronGolemParticle
@Environment(CLIENT) protected final void spawnIronGolemParticle(IronGolemEntity ironGolem, Random entityRandom, BlockState state) -
spawnIronGolemParticle
@Environment(CLIENT) protected final void spawnIronGolemParticle(IronGolemEntity ironGolem, Random entityRandom, BlockState state, @Nullable Identifier spriteId) -
spawnIronGolemParticle
@Environment(CLIENT) protected final void spawnIronGolemParticle(IronGolemEntity ironGolem, Random entityRandom, BlockState state, @Nullable Sprite sprite) -
onSpawnFallParticles
Called on the server when an entity has fallen on this part and is attempting to spawn particles for it. This is to send packets to clients to actually spawn the particles.- Parameters:
fallenEntity- The entity that has just landed on this part.entityRandom- The entity's random for use in particle position & velocity calculations.- Returns:
- True to cancel the default fall particle from spawning, false otherwise.
-
sendSpawnFallParticles
Actually Sends the packet from the server to the clients that spawns the fall particles.- Parameters:
pos- The position of the particles to spawn.count- The number of particles to spawn.
-
spawnFallParticles
Called on the client to spawn fall particles. By default, this callsspawnFallParticles(Vec3d, int, BlockState)withgetClosestBlockState()as itsBlockStateparameter.- Parameters:
pos- The position of the particles to spawn.count- The number of particles to spawn.
-
spawnFallParticles
@Environment(CLIENT) protected final void spawnFallParticles(Vec3d pos, int count, BlockState state) -
spawnFallParticles
@Environment(CLIENT) protected final void spawnFallParticles(Vec3d pos, int count, BlockState state, @Nullable Identifier spriteId) -
spawnFallParticles
@Environment(CLIENT) protected final void spawnFallParticles(Vec3d pos, int count, BlockState state, @Nullable Sprite sprite) -
addRequiredPart
-
removeRequiredPart
-
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
- Returns:
- The shape to use when solidity logic, collisions with entities, ray tracing, etc. This should always
encompass
getShape().
-
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
- Returns:
- The shape for rendering bounding boxes and ray tracing.
-
getDynamicShape
Deprecated.Use (and implement)getDynamicShape(float, Vec3d)instead.- 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.
-
getDynamicShape
- Parameters:
hitVec- The exact position of the main block where... oh.- 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
- Returns:
- True if this pluggable should be an
obstaclefor attributes with it'sgetShape()when searching in this particular direction.
-
addAllAttributes
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
Deprecated.Use (and implement)getPickStack(BlockHitResult)instead.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.
-
getPickStack
Called whenever this part is picked by the player (similar toBlock.getPickStack(BlockView, BlockPos, BlockState)but with aBlockHitResultfor picking pieces of parts).- Parameters:
hitResult- The hit result on the part being picked ornullif being called formaddDrops(DefaultedList).- Returns:
- The stack that should be picked, or ItemStack.EMPTY if no stack can be picked from this part.
-
addDrops
-
addDrops
Deprecated.Replaced byaddDrops(ItemDropTarget, LootContext) -
afterBreak
Called instead ofBlock.afterBreak(World, PlayerEntity, BlockPos, BlockState, BlockEntity, ItemStack), except that this shouldn't drop any items, as that's handled separately. -
calculateBreakingDelta
Part version ofAbstractBlock.calcBlockBreakingDelta(BlockState, PlayerEntity, BlockView, BlockPos).The default implementation treats parts as equal to
getClosestBlockState(). -
calculateBreakingDelta
CalculatescalculateBreakingDelta(PlayerEntity)as if this part was the given block instead. -
calculateBreakingDelta
CalculatescalculateBreakingDelta(PlayerEntity)as if this part was the given block state instead. -
calcBreakingDelta
CalculatescalculateBreakingDelta(PlayerEntity)as if this part was the given block state instead, but using a custom hardness value. -
onUse
Called whenever this part is used viaAbstractBlock.onUse(BlockState, World, BlockPos, PlayerEntity, Hand, BlockHitResult). -
rotate
Deprecated.Please use thePartTransformEvent.Rotateevent instead.Called wheneverBlockEntity#applyRotation(BlockRotation)orAbstractBlock.AbstractBlockState.rotate(BlockRotation)is called on the containing block.Note: This is only called when an applied transformation consists solely of a rotate transformation.
- Parameters:
rotation- A rotation. LMP never calls this withBlockRotation.NONE
-
mirror
Deprecated.Please use thePartTransformEvent.Mirrorevent instead.Called wheneverBlockEntity#applyMirror(BlockMirror)orAbstractBlock.AbstractBlockState.mirror(BlockMirror)is called on the containing block.Note: This is only called when an applied transformation consists solely of a mirror transformation.
- 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.
-
addDrops(ItemDropTarget, LootContext)