Posted May 28, 20232 yr Hello! I'm following a tutorial at moddingtutorials.org where they suggest I make an item that turns blocks into dirt on use. It works perfectly until I try to use the item on the block that is too far or out of my mining range or is too far. The block of dirt replaces the block I pointed to for just a fraction of a second and then goes back to its original state. I have no idea, how to fix this, other than setting the range of the item to match the mining range. Any suggestions? Here's my code for this: public class DirtStaff extends Item { public DirtStaff(Properties properties) { super(properties); } protected static BlockHitResult rayTrace(Level world, Player player, ClipContext.Fluid fluidMode) { float f = player.getXRot(); float f1 = player.getYRot(); Vec3 vec3 = player.getEyePosition(); float f2 = Mth.cos(-f1 * ((float)Math.PI / 180F) - (float)Math.PI); float f3 = Mth.sin(-f1 * ((float)Math.PI / 180F) - (float)Math.PI); float f4 = -Mth.cos(-f * ((float)Math.PI / 180F)); float f5 = Mth.sin(-f * ((float)Math.PI / 180F)); float f6 = f3 * f4; float f7 = f2 * f4; double d0 = 15; // range Vec3 vec31 = vec3.add((double)f6 * d0, (double)f5 * d0, (double)f7 * d0); return world.clip(new ClipContext(vec3, vec31, ClipContext.Block.OUTLINE, fluidMode, player)); } @Override public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) { BlockHitResult ray = rayTrace(world, player, ClipContext.Fluid.NONE); BlockPos lookPos = ray.getBlockPos(); world.setBlock(lookPos, Blocks.DIRT.defaultBlockState(), 1024); return super.use(world, player, hand); } }
May 28, 20232 yr You are not changing any real blocks regardless of range. https://forums.minecraftforge.net/search/?q=sidedSuccess&quick=1&type=forums_topic&nodes=70 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.
May 28, 20232 yr And you should override useOn() which will tell you which block you are interacting with. What you are doing sounds very similar to the ShovelItem when creating paths. 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.
May 29, 20232 yr Author On 5/28/2023 at 11:19 AM, warjort said: And you should override useOn() which will tell you which block you are interacting with. What you are doing sounds very similar to the ShovelItem when creating paths. I'm sorry, I didn't quite catch that. What do I do with it? What should I put in that function?
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.