Jump to content

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


Gadersd

Recommended Posts

You should make separate posts if you have multiple questions.

 

Anyway, for the @ForgeSubscribe problem, in 1.7.2 and later it changed to just @Subscribe.  If you're working with events you might want to check out my tutorial: http://jabelarminecraft.blogspot.com/p/minecraft-forge-172-event-handling.html

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

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.