ToxeNRald351 Posted May 28, 2023 Posted May 28, 2023 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); } } Quote
warjort Posted May 28, 2023 Posted May 28, 2023 You are not changing any real blocks regardless of range. https://forums.minecraftforge.net/search/?q=sidedSuccess&quick=1&type=forums_topic&nodes=70 Quote 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.
warjort Posted May 28, 2023 Posted May 28, 2023 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. Quote 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.
ToxeNRald351 Posted May 29, 2023 Author Posted May 29, 2023 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? 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.