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

Trying reflection for the first time, and something which seemed very simple eludes me.

 

if (rider != null && rider.ridingEntity != null) {
			if (rider.getHeldItem() != null && rider.getHeldItem().isItemEqual(new ItemStack(Items.carrot_on_a_stick))) {
				System.out.println("Rider is holding carrot on a stick.");
				Class clazz = EntityPig.class;
				Method method = null;
				try {
					method = clazz.getMethod("updateAITasks", (Class) null);
				} catch (NoSuchMethodException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (SecurityException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				if (method != null) {
					try {
						method.invoke(pig, (Class) null);
					} catch (IllegalAccessException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (IllegalArgumentException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (InvocationTargetException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}

					System.out.println("Success!");
				}
			}
			System.out.println("CheckRiderThread: ridingEntity set.");
		}
	}

 

Here is the corresponding method I am trying to access from EntityPig:

protected void updateAITasks()
    {
        super.updateAITasks();
    }

 

So, why is it throwing a NoSuchMethodException when I try to access the method?

Your class.getMethod() call has too many parameters. Remove "(Class) null"

Maker of the Craft++ mod.

  • Author

Still doesn't work.

 

if (rider != null && rider.ridingEntity != null) {
			if (rider.getHeldItem() != null && rider.getHeldItem().isItemEqual(new ItemStack(Items.carrot_on_a_stick))) {
				System.out.println("Rider is holding carrot on a stick.");
				Class clazz = EntityPig.class;
				Method method = null;
				try {
					method = clazz.getMethod("updateAITasks");
				} catch (NoSuchMethodException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (SecurityException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				if (method != null) {
					try {
						method.invoke(pig);
					} catch (IllegalAccessException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (IllegalArgumentException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (InvocationTargetException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}

					System.out.println("Success!");
				}
			}
			System.out.println("CheckRiderThread: ridingEntity set.");
		}
	}

 

@diesieben: If you join the game on a mounted pig and are holding a carrot on a stick, you have to wait a significant amount of time before it registers and the pig starts walking. I'm attempting to eliminate the wait time.

  • Author

How do I set it to accessible if I can't access it in the first place?

 

Edit: Nevermind, figured it out. I got the method to fire but unfortunately it didn't do anything. Thanks anyway, though.

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.