Posted June 25, 20223 yr Hi, I'm new at forge development and I am making an item that when right clicking any block with it it replaces it with another custom block. I tried using the method useOn and searched but I couldn't figure it out. Please help, Thank you.
June 25, 20223 yr Author but i can show you the bear outline @Override public InteractionResult useOn(UseOnContext pContext) { if(pContext.getLevel().isClientSide()) { BlockPos positionClicked = pContext.getClickedPos(); Player player = pContext.getPlayer(); here is supposed to be where i put the placement code after i grab all needed coords but i cant find the right command pContext.getItemInHand().hurtAndBreak(1, pContext.getPlayer(), (player) -> player.broadcastBreakEvent(player.getUsedItemHand())); return super.useOn(pContext); }
June 25, 20223 yr Author but i can show you the bear outline @Override public InteractionResult useOn(UseOnContext pContext) { if(pContext.getLevel().isClientSide()) { BlockPos positionClicked = pContext.getClickedPos(); Player player = pContext.getPlayer(); here is supposed to be where i put the placement code after i grab all needed coords but i cant find the right command pContext.getItemInHand().hurtAndBreak(1, pContext.getPlayer(), (Player) -> player.broadcastBreakEvent(player.getUsedItemHand())); return super.useOn(pContext); } Player needed a capital P
June 26, 20223 yr Author level : not a statement setBlock: cannot resolve symbol setblock i am running on vesrion 1.18.1 Extra Info
June 26, 20223 yr Author public class fluorite_dropper extends Item { public fluorite_dropper(Properties pProperties) { super(pProperties); } @Override public InteractionResult useOn(UseOnContext pContext) { if(pContext.getLevel().isClientSide()) { BlockPos positionClicked = pContext.getClickedPos(); Player player = pContext.getPlayer(); Level#setBlock pContext.getItemInHand().hurtAndBreak(1, pContext.getPlayer(), (Player) -> player.broadcastBreakEvent(player.getUsedItemHand())); return super.useOn(pContext); } return null; } } Exactly what i tried i never works this is everything i could collect of my attempts i just need the command that replaces blocks
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.