Jump to content

[1.17]Identification of inappropriate tools


ocome

Recommended Posts

Identification of inappropriate tools

    public boolean mineBlock(ItemStack stack, Level level, BlockState state, BlockPos pos, LivingEntity entityLiving) {
        baseBlock(stack, level, state, pos, entityLiving);
        return true;
    }

    public void baseBlock(ItemStack stack, Level level, BlockState state, BlockPos pos, LivingEntity entityLiving) {

        int a [] = {-1, 0, 1};
        for (int ax = 0; ax < 3; ax++) {
            for (int ay = 0; ay < 3; ay++) {
                for (int az = 0; az < 3; az++) {
                    BlockPos aPos = new BlockPos(pos.getX() + a[ax], pos.getY() + a[ay],pos.getZ() + a[az]);

                    BlockState aState = level.getBlockState(aPos);
                    if (aState.getBlock() == state.getBlock()
                            && modeInt(stack) == 1
                            && aState.requiresCorrectToolForDrops()
                    ){
                        level.destroyBlock(aPos, true);
                        baseBlock(stack, level, state, aPos, entityLiving);
                        stack.hurtAndBreak(1, entityLiving, (entity) -> {
                            entity.broadcastBreakEvent(EquipmentSlot.MAINHAND);
                        });
                    }
                }
            }
        }

    }

But it crashes when you break a block without the proper tools.

&& aState.requiresCorrectToolForDrops()

I know this is wrong, but I don't know what statement I can use for the condition when it's not the right tool

In 1.16, I think you could use ToolType, but is there an equivalent?

 

Is the block being dug with the corresponding tool?
I want to add a condition to check

Edited by ocome
Link to comment
Share on other sites

16 hours ago, ocome said:
int a [] = {-1, 0, 1};
//...
pos.getX() + a[ax]

 

What. Gross.

First off, you could just loop ax = -1; ax <= 1 (same for y and z) and then use BlockPos.add(ax, ay, az)

Or you could use the static method in the BlockPos class to get all blocks in range and iterate over the resulting collection (the MCP name was getAllInBox).

 

Older code, but example of the latter:
https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/java/com/draco18s/harderores/EventHandlers.java#L121

  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.