Package alexiil.mc.lib.multipart.api
Class AbstractPart
java.lang.Object
alexiil.mc.lib.multipart.api.AbstractPart
public abstract class AbstractPart extends 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 interface
AbstractPart.ItemDropTarget
A target for retrieving item drops fromaddDrops(ItemDropTarget, LootContext)
. -
Field Summary
Fields Modifier and Type Field Description PartDefinition
definition
MultipartHolder
holder
static ParentNetIdSingle<AbstractPart>
NET_ID
static NetIdDataK<AbstractPart>
NET_RENDER_DATA
static 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(AttributeList<?> list)
Offers every contained attribute to the given attribute list.void
addDrops(AbstractPart.ItemDropTarget target, LootContext context)
void
addDrops(DefaultedList<ItemStack> to)
Deprecated.Replaced byaddDrops(ItemDropTarget, LootContext)
protected 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)
float
calculateBreakingDelta(PlayerEntity player, Block block)
CalculatescalculateBreakingDelta(PlayerEntity)
as if this part was the given block instead.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
getClosestBlockState()
VoxelShape
getCollisionShape()
VoxelShape
getCullingShape()
VoxelShape
getDynamicShape(float partialTicks)
abstract PartModelKey
getModelKey()
Called on the client for both rendering, and checking if this needs to re-render inMultipartContainer.redrawIfChanged()
.VoxelShape
getOutlineShape()
ItemStack
getPickStack()
Called whenever this part is picked by the player (similar toBlock.getPickStack(BlockView, BlockPos, BlockState)
)abstract VoxelShape
getShape()
boolean
isBlocking(Direction searchDirection)
void
mirror(BlockMirror mirror)
Called wheneverBlockEntity.applyMirror(BlockMirror)
is called on the containing block.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
onRemoved()
ActionResult
onUse(PlayerEntity player, Hand hand, BlockHitResult hit)
Called whenever this part is used viaAbstractBlock.onUse(BlockState, World, BlockPos, PlayerEntity, Hand, BlockHitResult)
.protected void
playBreakSound()
Called by default inonBreak(PlayerEntity)
to play the breaking sound.protected void
playBreakSound(BlockState blockState)
protected 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 double
pos(World world, Direction side, Direction.Axis axis, double size)
void
readRenderData(NetByteBuf buffer, IMsgReadCtx ctx)
protected void
removeRequiredPart(AbstractPart required)
void
rotate(BlockRotation rotation)
Called wheneverBlockEntity.applyRotation(BlockRotation)
is called on the containing block.<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
.<T> void
sendNetworkUpdate(T obj, NetIdTyped<T> netId)
Sends the givenNetIdDataK
orNetIdSignalK
to every player currently watching this multipart.<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.<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.boolean
spawnBreakingParticles(Direction side)
Deprecated.This was renamed tospawnHitParticle(Direction)
protected void
spawnBreakParticles()
Called on the client to spawn break particles.protected void
spawnBreakParticles(BlockState state)
protected void
spawnBreakParticles(BlockState state, Sprite sprite)
protected void
spawnBreakParticles(BlockState state, Identifier spriteId)
boolean
spawnHitParticle(Direction side)
Spawns a single partial-break (hit) particle.protected void
spawnHitParticle(Direction side, BlockState state)
protected void
spawnHitParticle(Direction side, BlockState state, Sprite sprite)
protected void
spawnHitParticle(Direction side, BlockState state, Identifier spriteId)
protected void
spawnHitParticle(Direction side, Box box, BlockState state, Sprite sprite)
CompoundTag
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
-
Constructor Details
-
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. -
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) -
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.
-
getDynamicShape
- 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
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
-
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
Called wheneverBlockEntity.applyRotation(BlockRotation)
is called on the containing block.- Parameters:
rotation
- A rotation. LMP never calls this withBlockRotation.NONE
-
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
PartModelKey
for thePartModelBaker
to use to emit a static model. Returning null will bake nothing.
-