Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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

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.

  • Author

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.

  • Author

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?

  • Author

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

 

  • Author

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

 

  • Author

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

  • Author

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.

  • Author

Oh, so Minecraft#objectMouseOver is a server side method, so I just need to write a similar method for the client?

  • Author

So I need to perform the calculation on the server, I think I got it. Thanks

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.