Jump to content

Recommended Posts

Posted (edited)

Hi!

I want to make a debug mod. One feature of it is to show the active goals over all living entities. So I made some code in my EventHandler:

@SubscribeEvent
public void showGoal(RenderNameplateEvent event) {
   	if (event.getEntity instanceof ItemEntity || event.getEntity instanceof Player) return;
	if (((Mob) event.getEntity())goalSelector.getRunningGoals().toArray().length <= 0) return;
	
	((Mob) event.getEntity()).goalSelector.getRunningGoals().forEach(goal -> {
		//Set the name to the goal that I want
	});
}

The problem is, that event.getEntity() returns an Entity, but for getting the goals of the entity I need a Mob (no, there isn't an event.getEntityLiving()). How would I get the entity as a Mob?

Ps: I can get the world of the entity with

event.getEntity().getCommandSenderWorld();

 

Edited by OutCraft

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

Posted
42 minutes ago, diesieben07 said:

Learn basic Java, such as the instanceof operator and casting.

The problem is that it gives me the living entity as Entity. I can cast it to Mob (I know Java, I know how to cast), but then I also can't get the goals because the Entity that I get doesn't have goals. Goals are only registered on Mobs and Entities that extend Mob

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

  • OutCraft changed the title to Convert Entity to Mob
Posted
@SubscribeEvent
public void showGoal(RenderNameplateEvent event) {
	Entity entity = event.getEntity();
	System.out.println(entity + ": " + "Hi!"); <- This triggers for all entities
	((Mob) entity).goalSelector.getRunningGoals().forEach(goal -> {
		System.out.println(entity + ": " + "Hi!");  <- This never triggers
		event.setContent(new TextComponent(goal.getGoal().getClass().getName()));
	});
	System.out.println(((Mob) entity).goalSelector.getRunningGoals().toArray().length); <- This gives length 0
}

 

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

Posted
3 minutes ago, diesieben07 said:

Goals are a server side thing and not present on the client.

Ahh, this makes sense!

Can I get the goals with a clientside mod or do I need the mod on the Server and transfer packets?

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

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.