Avaritia:Reforged

Avaritia:Reforged

45.5k Downloads

[Change the destroy() metod]

Reaviik opened this issue · 0 comments

commented

Checks/检查

  • I confirm that I have searched for existing issues / pull requests before reporting to avoid duplicate reporting./我确认在报告之前我已经搜索了现有的问题或者拉取请求,以避免重复报告。
  • I confirm that I noted that if I don't follow the instructions, the issue may be closed directly./我确认我已经检查,如果我不按照说明进行操作,该问题可能会被直接关闭。

Description/描述

I tried to make this modification myself but I was not successful using the method

        serverPlayer.gameMode.destroyBlock(pos);

to break the blocks with the tools, perhaps with your expertise it will be possible.

Why change?
Basically, the way it is done, it is not possible to make these tools available to players on a server because this type of destroying blocks bypasses all land protection systems.

I have been using this method that I mentioned in my mod to create a hammer, here is the example if you are interested in modifying it, I would be grateful <3

`
private static final Set HARVESTED_BLOCKS = new HashSet<>();

@SubscribeEvent
public static void onHammerUsage(final BlockEvent.BreakEvent event) {
    final Player player = event.getPlayer();
    final ItemStack mainHandItem = player.getMainHandItem();

    if (!(mainHandItem.getItem() instanceof HammerItem hammer) || !(player instanceof ServerPlayer serverPlayer)) {
        return;
    }

    final BlockPos initialBlockPos = event.getPos();
    if (HARVESTED_BLOCKS.contains(initialBlockPos)) {
        return;
    }

    processHammerBreak(mainHandItem, hammer, initialBlockPos, serverPlayer);
}

private static void processHammerBreak(ItemStack mainHandItem, HammerItem hammer, BlockPos initialBlockPos, ServerPlayer serverPlayer) {
    final int baseRange = mainHandItem.getOrCreateTag().getInt("range");
    final int effectiveRange = mainHandItem.getItem() == ModItemsAdditions.IMPERIAL_INFINITY_HAMMER.get() ? baseRange + 2 : baseRange + 1;

    for (BlockPos pos : HammerItem.getBlocksToBeDestroyed(effectiveRange, initialBlockPos, serverPlayer)) {
        if (pos == initialBlockPos || !hammer.isCorrectToolForDrops(mainHandItem, serverPlayer.level().getBlockState(pos))) {
            continue;
        }

        HARVESTED_BLOCKS.add(pos);
        serverPlayer.gameMode.destroyBlock(pos);
        double x = pos.getX()+0.5D;
        double y = pos.getY()+0.5D;
        double z = pos.getZ()+0.5D;
        serverPlayer.serverLevel().sendParticles(ParticleTypes.SCULK_SOUL, x, y, z, 4, 0, 0, 0, 0);
        HARVESTED_BLOCKS.remove(pos);
    }
}

`