Security Craft

Security Craft

63M Downloads

Reinforced blocks break when using spells

Walnuss1 opened this issue · 2 comments

commented

Issue description

Some spells from the mods "Ars Nouveau" and "Iron's Spells 'n Spellbooks" can break reinforced blocks from other players.

Steps to reproduce

  1. Start 2 minecraft instances with SecurityCraft and those 2 mods
  2. Make a singleplayer world and open to lan
  3. Place reinforced blocks with account 1
  4. Join with account 2 and use the Touch Dig (Legendary) spell scroll or the novice spellbook from ars nouveau with an projectile - break spell
  5. the block breaks..

Minecraft version

1.21.1

Forge/NeoForge version

21.1.196

SecurityCraft version

v1.10

Other relevant versions

ars-nouveau-1.21.1-5.10.3
irons_spellbooks-1.21.1-3.14.2

If a (crash)log is relevant for this issue, link it here: (It's almost always relevant)

No response

commented

Im not sure whether this issue is just specific to these versions.
Here’s some NeoForge mod code to prevent players from breaking reinforced blocks they don’t own. If the issue isn't specific to these versions then you might need to adjust it to use your platform-independent code.

    @SubscribeEvent(priority = EventPriority.HIGHEST)
    public static void onBlockBreak(BlockEvent.BreakEvent event) {
        BlockState state = event.getState();
        BlockPos pos = event.getPos();
        var level = event.getLevel();

        ResourceLocation id = BuiltInRegistries.BLOCK.getKey(state.getBlock());

        // Check if the block is from SecurityCraft and starts with reinforced_
        if (!id.getNamespace().equals("securitycraft") || !id.getPath().startsWith("reinforced_")) {
            return;
        }

        // Ignore if it wasn't issued by a player
        if (!(event.getPlayer() instanceof ServerPlayer player)) {
            return;
        }

        BlockEntity tileEntity = level.getBlockEntity(pos);
        if (tileEntity == null) {
            // No tile entity, cancel to be safe
            event.setCanceled(true);
            return;
        }

        var registries = level.registryAccess();
        CompoundTag tag = tileEntity.saveWithoutMetadata(registries);
        if (!tag.contains("ownerUUID")) {
            // No owner data, cancel breaking
            event.setCanceled(true);
            return;
        }

        String ownerUUID = tag.getString("ownerUUID");
        if (!ownerUUID.equals(player.getUUID().toString())) {
            // Player breaking is not owner, cancel
            event.setCanceled(true);
        }
    }
commented

#573 is the same issue