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
Modifier and TypeClassDescriptionstatic interface
A target for retrieving item drops fromaddDrops(ItemDropTarget, LootContext)
. -
Field Summary
Modifier and TypeFieldDescriptionfinal MultipartContainer
final PartDefinition
final MultipartHolder
static final ParentNetIdSingle<AbstractPart>
static final NetIdDataK<AbstractPart>
static final NetIdSignalK<AbstractPart>
static final NetIdDataK<AbstractPart>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addAllAttributes
(AttributeList<?> list) Offers every contained attribute to the given attribute list.void
addDrops
(AbstractPart.ItemDropTarget target, LootContext context) void
Deprecated.protected final void
addRequiredPart
(AbstractPart required) void
afterBreak
(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 float
calcBreakingDelta
(PlayerEntity player, BlockState state, float hardness) CalculatescalculateBreakingDelta(PlayerEntity)
as if this part was the given block state instead, but using a custom hardness value.float
calculateBreakingDelta
(PlayerEntity player) final float
calculateBreakingDelta
(PlayerEntity player, Block block) CalculatescalculateBreakingDelta(PlayerEntity)
as if this part was the given block instead.final float
calculateBreakingDelta
(PlayerEntity player, BlockState state) CalculatescalculateBreakingDelta(PlayerEntity)
as if this part was the given block state instead.boolean
canOverlapWith
(AbstractPart other) Checks to see if thisAbstractPart
can overlap with the other part.protected BlockState
getDynamicShape
(float partialTicks) Deprecated.Use (and implement)getDynamicShape(float, Vec3d)
instead.getDynamicShape
(float partialTicks, Vec3d hitVec) abstract PartModelKey
Called 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 aBlockHitResult
for picking pieces of parts).abstract VoxelShape
getShape()
boolean
isBlocking
(Direction searchDirection) void
mirror
(BlockMirror mirror) Deprecated.Please use thePartTransformEvent.Mirror
event instead.void
onAdded
(MultipartEventBus bus) Called whenever this part was added to theMultipartContainer
, either inBlockEntity.cancelRemoval()
or when it is manually added by an item.boolean
onBreak
(PlayerEntity player) Called instead ofBlock.onBreak(World, BlockPos, BlockState, PlayerEntity)
, to play the broken sound, and spawn break particles.void
onPlacedBy
(PlayerEntity player, Hand hand) Open method, that's designed to be called from theItem
that places this part into the world.void
boolean
onSpawnFallParticles
(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 void
Called by default inonBreak(PlayerEntity)
to play the breaking sound.protected final void
playBreakSound
(BlockState blockState) protected final void
playHitSound
(BlockState blockState) void
playHitSound
(PlayerEntity player) Called instead ofBlock.onBreak(World, BlockPos, BlockState, PlayerEntity)
, to play the broken sound, and spawn break particles.protected static final double
pos
(World world, Direction side, Direction.Axis axis, double size) void
readRenderData
(NetByteBuf buffer, IMsgReadCtx ctx) final void
Clears this part's block's shape caches.final void
Should be called on the server to ensure this part's block's shape caches are cleared on both the client and the server.final void
Redraws this part's block if need be.protected final void
removeRequiredPart
(AbstractPart required) void
rotate
(BlockRotation rotation) Deprecated.Please use thePartTransformEvent.Rotate
event instead.final <T> void
sendNetworkUpdate
(T obj, NetIdDataK<T> netId, NetIdDataK.IMsgDataWriterK<T> writer) Sends the givenNetIdDataK
to every player currently watching this multipart, with a customNetIdDataK.IMsgDataWriterK
.final <T> void
sendNetworkUpdate
(T obj, NetIdTyped<T> netId) Sends the givenNetIdDataK
orNetIdSignalK
to every player currently watching this multipart.final <T> void
sendNetworkUpdateExcept
(PlayerEntity except, T obj, NetIdDataK<T> netId, NetIdDataK.IMsgDataWriterK<T> writer) Sends the givenNetIdDataK
to every player currently watching this multipart, with a customNetIdDataK.IMsgDataWriterK
, except for the given player.final <T> void
sendNetworkUpdateExcept
(PlayerEntity except, T obj, NetIdTyped<T> netId) Sends the givenNetIdDataK
orNetIdSignalK
to every player currently watching this multipart, except for the given player.protected final void
sendSpawnFallParticles
(Vec3d pos, int count) Actually Sends the packet from the server to the clients that spawns the fall particles.boolean
Deprecated.This was renamed tospawnHitParticle(Direction)
protected void
Called on the client to spawn break particles.protected final void
spawnBreakParticles
(BlockState state) protected final void
spawnBreakParticles
(BlockState state, Sprite sprite) protected final void
spawnBreakParticles
(BlockState state, Identifier spriteId) protected void
spawnFallParticles
(Vec3d pos, int count) Called on the client to spawn fall particles.protected final void
spawnFallParticles
(Vec3d pos, int count, BlockState state) protected final void
spawnFallParticles
(Vec3d pos, int count, BlockState state, Sprite sprite) protected final void
spawnFallParticles
(Vec3d pos, int count, BlockState state, Identifier spriteId) boolean
spawnHitParticle
(Direction side) Spawns a single partial-break (hit) particle.protected final void
spawnHitParticle
(Direction side, BlockState state) protected final void
spawnHitParticle
(Direction side, BlockState state, Sprite sprite) protected final void
spawnHitParticle
(Direction side, BlockState state, Identifier spriteId) protected final void
spawnHitParticle
(Direction side, Box box, BlockState state, Sprite sprite) boolean
spawnIronGolemParticle
(IronGolemEntity ironGolem, Random entityRandom) Spawns a single particle for when an iron golem walks on this part.protected final void
spawnIronGolemParticle
(IronGolemEntity ironGolem, Random entityRandom, BlockState state) protected final void
spawnIronGolemParticle
(IronGolemEntity ironGolem, Random entityRandom, BlockState state, Sprite sprite) protected final void
spawnIronGolemParticle
(IronGolemEntity ironGolem, Random entityRandom, BlockState state, Identifier spriteId) boolean
spawnSprintParticle
(Entity sprintingEntity, Random entityRandom) Spawns a single sprint particle.protected final void
spawnSprintParticle
(Entity sprintingEntity, Random entityRandom, BlockState state) protected final void
spawnSprintParticle
(Entity sprintingEntity, Random entityRandom, BlockState state, Sprite sprite) protected final void
spawnSprintParticle
(Entity sprintingEntity, Random entityRandom, BlockState state, Identifier spriteId) toTag()
void
writeCreationData
(NetByteBuf buffer, IMsgWriteCtx ctx) Writes the payload that will be passed intoPartDefinition.loadFromBuffer(MultipartHolder, NetByteBuf, IMsgReadCtx)
on the client.void
writeRenderData
(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 givenNetIdDataK
orNetIdSignalK
to every player currently watching this multipart. -
sendNetworkUpdate
public final <T> void sendNetworkUpdate(T obj, NetIdDataK<T> netId, NetIdDataK.IMsgDataWriterK<T> writer) Sends the givenNetIdDataK
to 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 givenNetIdDataK
orNetIdSignalK
to 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 givenNetIdDataK
to every player currently watching this multipart, with a customNetIdDataK.IMsgDataWriterK
, except for the given player. -
redrawIfChanged
public final void redrawIfChanged()Redraws this part's block if need be.This can be invoked on the server to send a message to the client to redraw if needed.
This is a convenience method for invoking
MultipartContainer.redrawIfChanged()
. -
recalculateShape
public final void recalculateShape()Clears this part's block's shape caches.This is a convenience method for invoking
MultipartContainer.recalculateShape()
. -
recalculateShapeSynced
public final void recalculateShapeSynced()Should be called on the server to ensure this part's block's shape caches are cleared on both the client and the server.This is a convenience method for invoking
MultipartContainer.recalculateShapeSynced()
. -
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 theItem
that 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
BlockState
to 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 itsBlockState
parameter.- 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
VoxelShape
to use for calculating if this pluggable overlaps with another pluggable.
-
canOverlapWith
Checks to see if thisAbstractPart
can 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
MultipartContainer
inMultipartContainer.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.
-
getSidesShape
- Returns:
- The shape that side solidness tests are performed against.
-
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
obstacle
for 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 theVoxelShape
argument!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 aBlockHitResult
for picking pieces of parts).- Parameters:
hitResult
- The hit result on the part being picked ornull
if 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.Rotate
event 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.Mirror
event 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
PartModelKey
for thePartModelBaker
to use to emit a static model. Returning null will bake nothing.
-
addDrops(ItemDropTarget, LootContext)