Whenever there's a valid position a cardboard box could be placed on the ground, it'll flicker on that position (as if it was placed there for a split second) before the packing ends.
VID_20231004_100113.mp4
I belive this might be some issue with the ActionResult
s returned on the packing logic, albeit I'm not certain.
public ActionResult useOnBlock (ItemUsageContext context ) {
if (!context .getWorld ().isClient ()) {
World world = context .getWorld ();
BlockPos pos = context .getBlockPos ();
Optional <BlockEntity > blockEntity = Optional .ofNullable (world .getBlockEntity (pos ));
if (context .getPlayer ().isSneaking ()) {
BlockState blockState = world .getBlockState (pos );
if (blockState .getBlock ().getHardness () >= 0.01F && isNbtBlockAir (context .getStack ()) && !blockState .isIn (TagRegistry .UNBOXABLE ) && !isOnCarrierBlackList (blockState )) {
if (blockEntity .isPresent () && hasLootTable (blockEntity .get ())) return super .useOnBlock (context );
NbtList nbtList = new NbtList ();
if (blockEntity .isPresent ()) {
NbtCompound nbtCopy = blockEntity .get ().createNbtWithId ();
nbtCopy .remove ("id" );
nbtCopy .remove ("x" );
nbtCopy .remove ("y" );
nbtCopy .remove ("z" );
nbtList .add (nbtCopy );
// Desperate attempt to cover every edge case :)
Clearable .clear (blockEntity );
world .removeBlockEntity (pos );
}
world .setBlockState (pos , BlockRegistry .CARDBOARD_BOX .getPlacementState (new ItemPlacementContext (context )), 32 );
world .playSound (null , pos , SoundEvents .ITEM_ARMOR_EQUIP_LEATHER , SoundCategory .BLOCKS , 1F , 1F );
blockEntity = Optional .ofNullable (world .getBlockEntity (pos )); // refresh block entity
if (blockEntity .isPresent () && blockEntity .get () instanceof CardboardBoxBlockEntity cardboardBoxBE ) {
cardboardBoxBE .blockState = blockState ;
cardboardBoxBE .nbtCopy = nbtList ;
blockEntity .get ().markDirty ();
}
context .getStack ().decrement (1 );
return ActionResult .PASS ;
}
}
}
return super .useOnBlock (context );
}