Jump to content

Recommended Posts

Posted (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 by t_h0e
added crash log
Posted (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 by Animefan8888
  • Like 1

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.

Posted

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?

Posted

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;
	}

 

Posted

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;
		}
	}

 

Posted

GameRenderer.GetMouseOver() returns void. Is there something else I should be using, or do I have to create my own raytracing method?

Posted

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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • So am trying to make a custom 1.19.2 modpack and everything works until I add Oculus. I have tried Oculus+Embedium and Oculus+Rubdium and by themselves they work but as soon as I add anything it crashes no matter what it is. The modpack works fine with just Embedium and Rubdium. Can you help me to see if this is something i can fix or do i just have to deal with not having shaders. Here is the crash log. Thank you for your time. https://paste.ee/p/WXfNZ24K
    • What do I do now when it says "1 error"?
    • Hello everyone new here how are you all?
    • I haven't tested it but under https://minecraft.wiki/w/Items_model_definition it says now:   So I guess the resource location must have changed with 1.24.4, which means you need to move your models/item/ to the new source. But as I said I haven't tested this so it also may be that this wont work. Nevertheless give it a try      EDIT (important) So now I tested it and found out how it works   Let the model files (e.g. the .json from blockbench) within "assets/<your_mod_id>/models/item" In addition to that do the following: Every model you added will need a new file under "assets/<your_mod_id>/items" That file is also a JSON and looks like this: { "model": { "type": "minecraft:model", "model": "your_mod_id:item/custom_item" } } - "type" can be minecraft:model, minecraft:composite, minecraft:condition, minecraft:select, minecraft:range_dispatch, minecraft:empty, minecraft:bundle/selected_item or minecraft:special. (In most cases you would need minecraft:model) - "model" is the path to your actual model for this item. For example the value above would point to "assets/your_mod_id/models/item/custom_item"
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.