Jump to content

[1.7.10] NoSuchMethodException


Rui

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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



×
×
  • Create New...

Important Information

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