Skip to content

[Crash] Block placed automatically via Block Placer #19

@JDDev0

Description

@JDDev0

Minecraft: 1.20.1 (Fabric) and 1.20.4 (Fabric)
Reframed: 1.6.6


The game crashes if a block is placed automatically via a block placer.

The Player Entity in the

BlockItem.writeNbtToBlockEntity(World world, @Nullable PlayerEntity player, BlockPos pos, ItemStack stack)

method might be null and is null if a block is placed with a block placer from Energized Power.

The fix is relatively easy.

You just need to check for null in this method

private static void placeBlockWithOffHandCamo(World world, PlayerEntity player, BlockPos pos, ItemStack stack, CallbackInfoReturnable<Boolean> cir, @Local LocalRef<NbtCompound> compound) {

A simple solution would be to add the check as the first statement in the if check:

if (player == null || compound.get() != null
            || player.getOffHandStack().isEmpty()
            || player.getMainHandStack().isEmpty()
            || !(player.getMainHandStack().getItem() instanceof BlockItem frame)
            || !(frame.getBlock() instanceof ReFramedBlock)
            || !(player.getOffHandStack().getItem() instanceof BlockItem block)
            || block.getBlock() instanceof BlockEntityProvider
            || (world.getBlockState(pos).contains(Properties.LAYERS) && world.getBlockState(pos).get(Properties.LAYERS) > 1)
            || !Block.isShapeFullCube(block.getBlock().getDefaultState().getCollisionShape(world, pos))
        ) return;

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixa fix is either in progress or already implemented for future versions

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions