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 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 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.Replaced byaddDrops(ItemDropTarget, LootContext)
protected void
addRequiredPart(AbstractPart required)
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.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.float
calculateBreakingDelta(net.minecraft.entity.player.PlayerEntity player)
Part version ofAbstractBlock.calcBlockBreakingDelta(BlockState, PlayerEntity, BlockView, BlockPos)
.float
calculateBreakingDelta(net.minecraft.entity.player.PlayerEntity player, net.minecraft.block.Block block)
CalculatescalculateBreakingDelta(PlayerEntity)
as if this part was the given block instead.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.boolean
canOverlapWith(AbstractPart other)
Checks to see if thisAbstractPart
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 inMultipartContainer.redrawIfChanged()
.net.minecraft.util.shape.VoxelShape
getOutlineShape()
net.minecraft.item.ItemStack
getPickStack()
Called whenever this part is picked by the player (similar toBlock.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 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(net.minecraft.entity.player.PlayerEntity player)
Called instead ofBlock.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 theItem
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 viaAbstractBlock.onUse(BlockState, World, BlockPos, PlayerEntity, Hand, BlockHitResult)
.protected void
playBreakSound()
Called by default inonBreak(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 ofBlock.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 wheneverBlockEntity.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 givenNetIdDataK
to every player currently watching this multipart, with a customNetIdDataK.IMsgDataWriterK
.<T> void
sendNetworkUpdate(T obj, alexiil.mc.lib.net.NetIdTyped<T> netId)
Sends the givenNetIdDataK
orNetIdSignalK
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 givenNetIdDataK
to every player currently watching this multipart, with a customNetIdDataK.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 givenNetIdDataK
orNetIdSignalK
to every player currently watching this multipart, except for the given player.boolean
spawnBreakingParticles(net.minecraft.util.math.Direction side)
Deprecated.This was renamed tospawnHitParticle(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 intoPartDefinition.loadFromBuffer(MultipartHolder, NetByteBuf, IMsgReadCtx)
on the client.void
writeRenderData(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 givenNetIdDataK
orNetIdSignalK
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 givenNetIdDataK
to 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 givenNetIdDataK
orNetIdSignalK
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 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
public void onPlacedBy(net.minecraft.entity.player.PlayerEntity player, net.minecraft.util.Hand hand)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
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
BlockState
to 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
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
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
obstacle
for 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 theVoxelShape
argument!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
PartModelKey
for thePartModelBaker
to use to emit a static model. Returning null will bake nothing.
-