t_h0e Posted August 4, 2019 Share Posted August 4, 2019 (edited) I'm currently working on a method for a custom item that will print information in the chat about what is being looked at by the player. I am using the onItemRightClick method, but my game crashes when this code is ran: @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) { RayTraceResult rtr = this.rayTrace(worldIn, playerIn, RayTraceContext.FluidMode.NONE); playerIn.sendMessage(ITextComponent.Serializer.fromJson(rtr.hitInfo.toString())); return onItemRightClick(worldIn, playerIn, handIn); } There are multiple parts of this snippet that I am very uncertain about, so it wouldn't surprise me if I am doing more than one thing wrong ?. Any advice would be much appreciated. EDIT: Updated my code as well as added crash log crash-2019-08-04_12.45.37-client.txt Edited August 4, 2019 by t_h0e added crash log Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 4, 2019 Share Posted August 4, 2019 (edited) 1 hour ago, t_h0e said: return super.onItemRightClick(worldIn, playerIn, handIn); Change this to return your own ActionResult. 1 hour ago, t_h0e said: but my game crashes when this code is ran: Unsure of the crash, but perhaps a NullPointerException? Post your crash. Edited August 4, 2019 by Animefan8888 1 Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
t_h0e Posted August 4, 2019 Author Share Posted August 4, 2019 I added my crash log to the original post. You were spot on about the NullPointerException but I'm not sure what is causing it. Quote Link to comment Share on other sites More sharing options...
t_h0e Posted August 4, 2019 Author Share Posted August 4, 2019 Hmm, Ok. What field tell me which object (if any) was hit from a RayTraceResult? Also I believe I am serializing my string into an ITextComponent wrong. Is my best option to just implement ITextComponent in my own method? Quote Link to comment Share on other sites More sharing options...
t_h0e Posted August 4, 2019 Author Share Posted August 4, 2019 Thanks for the help! I got it working by changing the method to itemInteractionForEntity after a bit of tweaking. I believe onItemRightClick is called too many times for how I am applying it. @Override public boolean itemInteractionForEntity(ItemStack stackIn, PlayerEntity playerIn, LivingEntity livingIn, Hand handIn) { if (m.objectMouseOver.getType() == RayTraceResult.Type.ENTITY) { EntityRayTraceResult ertr = (EntityRayTraceResult) m.objectMouseOver; playerIn.sendMessage(ertr.getEntity().getName()); return true; } else return false; } Quote Link to comment Share on other sites More sharing options...
t_h0e Posted August 4, 2019 Author Share Posted August 4, 2019 When I use this code, I receive no message at all. I read another post that said RayTraceResult does not return entities because it is the same as World::RayTraceBlocks, however I'm not sure if that's why I'm receiving nothing at all. @Override public boolean itemInteractionForEntity(ItemStack stackIn, PlayerEntity playerIn, LivingEntity livingIn, Hand handIn) { RayTraceResult rtr = this.rayTrace(playerIn.world, playerIn, RayTraceContext.FluidMode.NONE); if (rtr.getType() == RayTraceResult.Type.ENTITY) { EntityRayTraceResult ertr = (EntityRayTraceResult) m.objectMouseOver; playerIn.sendMessage(ertr.getEntity().getName()); return true; } } Quote Link to comment Share on other sites More sharing options...
t_h0e Posted August 4, 2019 Author Share Posted August 4, 2019 GameRenderer.GetMouseOver() returns void. Is there something else I should be using, or do I have to create my own raytracing method? Quote Link to comment Share on other sites More sharing options...
t_h0e Posted August 5, 2019 Author Share Posted August 5, 2019 Well, I believe I need to learn more about how to send network packets between the logical sides, because that is something I am not familiar with at all. It's unfortunate that a solely single player mod needs to be that complicated due to minecraft's design. Quote Link to comment Share on other sites More sharing options...
t_h0e Posted August 5, 2019 Author Share Posted August 5, 2019 Oh, so Minecraft#objectMouseOver is a server side method, so I just need to write a similar method for the client? Quote Link to comment Share on other sites More sharing options...
t_h0e Posted August 5, 2019 Author Share Posted August 5, 2019 So I need to perform the calculation on the server, I think I got it. Thanks Quote Link to comment Share on other sites More sharing options...
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.