Posted April 24, 20232 yr Hey y'all, I've been working on a simple farming mod for a while, and I ran into some trouble trying to implement a scythe tool. When the player right-clicks on a crop using the tool, I want that crop and the two adjacent crops (in the direction perpendicular to the player's horizontal view direction) to break. Currently, when I right-click a crop with a scythe, the clicked crop breaks normally but the adjacent crops stay behind as ghost blocks. All three crops do drop their respective loot, however. Interacting with the ghost blocks makes them vanish. Here's my relevant code in the ScytheItem class: Spoiler @Override public InteractionResult useOn(UseOnContext context) { Level level = context.getLevel(); BlockPos pos = context.getClickedPos(); if (!level.isClientSide && level.getBlockState(pos).getBlock() instanceof CropBlock && !(level.getBlockState(pos).getBlock() instanceof PlantedTrellisBlock)) { Player player = context.getPlayer(); level.destroyBlock(pos, true, player); switch (context.getHorizontalDirection()) { case NORTH, SOUTH -> { if (level.getBlockState(pos.east()).getBlock() instanceof CropBlock && !(level.getBlockState(pos.east()).getBlock() instanceof PlantedTrellisBlock)) { level.destroyBlock(pos.east(), true, player); } if (level.getBlockState(pos.west()).getBlock() instanceof CropBlock && !(level.getBlockState(pos.west()).getBlock() instanceof PlantedTrellisBlock)) { level.destroyBlock(pos.west(), true, player); } } case EAST, WEST -> { if (level.getBlockState(pos.north()).getBlock() instanceof CropBlock && !(level.getBlockState(pos.north()).getBlock() instanceof PlantedTrellisBlock)) { level.destroyBlock(pos.north(), true, player); } if (level.getBlockState(pos.south()).getBlock() instanceof CropBlock && !(level.getBlockState(pos.south()).getBlock() instanceof PlantedTrellisBlock)) { level.destroyBlock(pos.south(), true, player); } } } context.getItemInHand().hurtAndBreak(1, player, (livingEntity) -> livingEntity.broadcastBreakEvent(context.getHand())); } return super.useOn(context); } My guess is that I should pass some (non-default) integer flag in all the calls to destroyBlock. I can't seem to find what each integer flag does though. Any help would be greatly appreciated!
April 24, 20232 yr Quote Here's my relevant code in the ScytheItem class: No it is not. This is why you shouldn't post code snippets in the forum. Put your full code (enough to reproduce the problem) on github. Quote return super.useOn(context); If you are just extending the default Item class (we don't know what you extend) the above line of code will return PASS on the client and the server side code will never run. So what code you are actually running is unknown. You should really be using InteractionResult.sidedSuccess(level.isClientSide) unless you really do want the code in the super class to run. As the to the integer, I assume you mean the flags found in the Block class? The destroyBlock() method you call uses 3 which is UPDATE_NEIGHBORS and UPDATE_CLIENTS. That is usually what you want unless you have special requirements. Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
April 24, 20232 yr Author Heya, thanks for the swift reply. Changing the method return value to InteractionResult.sidedSuccess(level.isClientSide) actually resolved the issue somehow. Thanks for pointing out the flags in the Block class too, I was looking for those exactly. Not that I need them anymore, but at least I know where to look now.
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.