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

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!

  • Author
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
  • Author
@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!

  • Author
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!

  • Author

Ok, thanks for your help :D

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

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.