Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

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.

  • Author

I do return something other than PASS. PASS is the default return if none of the cases are met.

  • 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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.