Tikaji Posted May 6, 2020 Posted May 6, 2020 (edited) 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 May 6, 2020 by Tikaji Some more info on issue. Quote
Draco18s Posted May 6, 2020 Posted May 6, 2020 Return something other than PASS? Pass means "I didn't do anything." Check the other values and return the obviously correct one. Quote 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.
Tikaji Posted May 6, 2020 Author Posted May 6, 2020 I do return something other than PASS. PASS is the default return if none of the cases are met. Quote
Recommended Posts
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.