Jump to content

[1.15.2] Prevent Block Placement [SOLVED]


Tikaji

Recommended Posts

How do I go about preventing a block placement from happening on block activation? I currently have a block that has overridden onBlockActivated and it works as expected, however the block that is in the players hand is placed for a split second and then is removed, which then causes my itemstack to be decreased (I'm making the assumption that this is the default behavior of placing a block). I also looked at the EntityPlaceEvent and tried cancelling it, but I still got the same behavior. I would like to prevent that split second block placement and stack decrease.

Here is the onBlockActivated if it helps.

Spoiler

@Override
    public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos,
        PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
        if (!worldIn.isRemote()) {
            ItemStack stack = player.getHeldItem(handIn);

            if (stack.isEmpty() && player.isSneaking()) {
                TileEntity tileEntity = worldIn.getTileEntity(pos);
                if (tileEntity instanceof SieveTile) {
                    SieveTile sieveTile = (SieveTile) tileEntity;
                    sieveTile.removeMesh(true);
                    return ActionResultType.SUCCESS;
                }
            }

            if (stack.getItem() instanceof MeshItem) {
                TileEntity tileEntity = worldIn.getTileEntity(pos);
                if (tileEntity instanceof SieveTile) {
                    SieveTile sieveTile = (SieveTile) tileEntity;
                    sieveTile.insertMesh(stack);
                    return ActionResultType.SUCCESS;
                }
            }

            if(stack.getItem() instanceof BlockItem) {
                BlockItem blockItem = (BlockItem)stack.getItem();
                if(SieveDrops.isBlockSiftable(blockItem.getBlock())) {
                    TileEntity tileEntity = worldIn.getTileEntity(pos);
                    if(tileEntity instanceof SieveTile) {
                        SieveTile sieveTile = (SieveTile)tileEntity;
                        sieveTile.insertSiftableBlock(stack);
                        return ActionResultType.SUCCESS;
                    }
                }
            }
        }
        return ActionResultType.PASS;
    }

 

 

In addition, I know that there are four ActionResultTypes, when exactly should each of those types be returned? I notice that I get a slightly different behavior based on which type I return.

Edited by Tikaji
Some more info on issue.
Link to comment
Share on other sites

Return something other than PASS? Pass means "I didn't do anything."

Check the other values and return the obviously correct one.

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

  • Tikaji changed the title to [1.15.2] Prevent Block Placement [SOLVED]

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.