terrarium-earth / Cadmus

A land claiming mod that allows users to claim land to protect your home from thieves, bandits and monsters, and admins to claim land with region flags and advanced protection!
MIT License
21 stars 8 forks source link

[Bug]: the player loses the block when placing it if the protected area is not his #28

Open Misaass opened 9 months ago

Misaass commented 9 months ago

Bug Description

modify the mod in the blockPlace mixin to prevent that from happening, it would be a good feature since it should not remove the block from the player

private void place(BlockPlaceContext blockPlaceContext, CallbackInfoReturnable<InteractionResult> cir) {

        if (!ClaimApi.API.canPlaceBlock(blockPlaceContext.getLevel(), blockPlaceContext.getClickedPos(), blockPlaceContext.getPlayer())) {

            Player playerPlaced = null;

            if(blockPlaceContext.getPlayer() != null) {
                playerPlaced = blockPlaceContext.getPlayer();

                int slot = playerPlaced.getInventory().selected;

                ItemStack stack = playerPlaced.getInventory().getItem(slot);

                cir.setReturnValue(InteractionResult.FAIL);

                blockPlaceContext.getPlayer().getInventory().setItem(slot, stack.copy());
            }
            else {
                cir.setReturnValue(InteractionResult.FAIL);
            }
        }
    }

How to Reproduce?

No response

Expected Behavior

No response

Version

1.0.0

Mod Loader Version

1.20.x

Mod Loader

Fabric

Logs or additional context

No response

Code of Conduct