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.

[SOLVED]@ForgeSubscribe not recognized and how to set player walking speed?

Featured Replies

Posted

I am using eclipse with Forge and it sees the @ForgeSubscribe annotation as an error. How can I fix this and also how can I set my players walking speed. I am unable to find a way to get a reference to my EntityPlayer.

Do I compare it with the EntityPlayer class or something else?

 

learn to java.

If I helped please press the Thank You button.

  • Author

I know java I just don't know which specific class I should use. I am new to Minecraft modding.

A simple rundown of how I would explain it (this is how I think of it) is events are called on pretty much everything and every action by anything. So larsgerrits suggested 'instanceof' which is very helpful for finding the right type of entity to deal with, lets say you want to do a check or update for every living thing

@SubscribeEvent
public void onLivingUpdateEvent(LivingUpdateEvent event)
{

This is how you will hook into any EntityLivingBase's update event, so if you wanted all players, wolves, iron golems, and villagers to "slowly heal" you would need:

@SubscribeEvent
public void onLivingUpdateEvent(LivingUpdateEvent event)
{
	if (event.entity instanceof EntityPlayer)
	{
		EntityPlayer player = (EntityPlayer) event.entity;
		player.heal(0.025f);			
	}
	else if (event.entity instanceof EntityIronGolem)
	{
		EntityIronGolem golem = (EntityIronGolem) event.entity;
		golem.heal(0.05f);
	}
	else if (event.entity instanceof EntityVillager)
	{
		EntityVillager villager = (EntityVillager) event.entity;
		villager.heal(0.075f);
	}
	else if (event.entity instanceof EntityWolf)
	{
		EntityWolf wolf = (EntityWolf) event.entity;
		wolf.heal(0.05f);
	}		
}

 

I'd really suggest going through a few tutorials on this (like I have) either jabelar's that he posted above or CoolAlias's [1.7.2][1.6.4] EventHandler and IExtendedEntityProperties.

  • Author

I finally got it working. All that needs to be done now is to increase the players damage. How can I check if the player is the source of damage in the LivingHurtEvent?

I finally got it working. All that needs to be done now is to increase the players damage. How can I check if the player is the source of damage in the LivingHurtEvent?

 

The event parameter has a source field which is type DamageSource.  DamageSource is a bit funny because of course there are all sorts of different things that can cause damage besides the player -- like lava, falling, explosions, hunger, and so on.  But there is a getEntity() method as well (it will return null if it wasn't an entity).  Now if you just inspect the code of DamageSource you might think it will always return null (because that is what the method does in that class), however there is an EntityDamageSource class that extends DamageSource that may be passed as the source (and of course EntityDamageSource will return an entity).

 

I think that if you check if event.source.getEntity() instanceof EntityPlayer then you'll know it is player.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Be aware, however, that DamageSource#getEntity will return, for example, the player responsible for shooting the arrow entity that damaged the target - this may be what you want, it may not (usually it is).

 

DamageSource#getSourceOfDamage() returns the actual entity directly responsible for the damage, which in our example above would be the EntityArrow that hit the target.

 

As jabelar mentioned, there is EntityDamageSource, for which both of the above methods return the same thing, and there is EntityDamageSourceIndirect (for things such as projectiles), for which the two methods return different entities as explained above.

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.