DimStorage

DimStorage

9M Downloads

Conflict with Just Dire Things

Direwolf20-MC opened this issue ยท 4 comments

commented

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In DimBlockBase, the following code is causing a dupe bug in Just Dire things:

public boolean onDestroyedByPlayer(BlockState state, Level level, BlockPos pos, Player player, boolean willHarvest, FluidState fluid) {
        BlockEntity blockentity = level.getBlockEntity(pos);
        if (blockentity instanceof BlockEntityFrequencyOwner block) {
            if (block.canAccess(player) || player.isCreative()) {
                return willHarvest || super.onDestroyedByPlayer(state, level, pos, player, false, fluid);
            }
        }

        return false;
    }

Specifically its returning 'true' if willHarvest is 'true'. I'm not sure if what i'm doing is wrong, but what I'm doing is calling state.onDestroyedByPlayer(level, pos, player, true, level.getFluidState(pos)) (See here: https://github.com/Direwolf20-MC/JustDireThings/blob/main/src/main/java/com/direwolf20/justdirethings/common/items/interfaces/Helpers.java#L66) when breaking the block with my tools.

For most other blocks, when they get to this method, they return 'false' because i've already broken it. But since you're returning willHarvest before calling the super method, its skipping that check, and doubling the drop.

If I'm doing things wrong please let me know :). But I'm curious if the 'return willHarvest ||' piece is needed on your side?

How can I reproduce this bug or crash?

Break your blocks using a tool from Just Dire Things

Configuration

- Mod version:9.0.0
- Forge version: Latest
- Minecraft version: 1.21

Relevant log output

No response

Anything else?

No response

commented

I put that willHarvest || to fix a bug I had in 2020. #26
Apparently it is no longer necessary, probably I changed some logic during the versions.
The fact remains that calling the super method returns true. So I don't know how much it changes, however I remove the or.

commented

Maybe it changes because the method calls these methods:

default boolean onDestroyedByPlayer(BlockState state, Level level, BlockPos pos, Player player, boolean willHarvest, FluidState fluid) {
    return level.isClientSide() ? level.setBlock(pos, fluid.createLegacyBlock(), 11) : level.removeBlock(pos, false);
}
commented

Cool thanks, this should fix it for me :). I think what was happening was my tool was breaking the block and dropping the items, and when the super call happens, it would have returned false because the block was already broken, but since you returned true, it assumed the block needed to be dropped still and doubled the drops.

commented

Confirmed this fixed it :) thanks!