Posted August 13, 201411 yr 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.
August 13, 201411 yr 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/
August 13, 201411 yr Author Thanks the error is now gone. How do check if the event.entity is my player?
August 13, 201411 yr instanceof Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
August 13, 201411 yr Do I compare it with the EntityPlayer class or something else? learn to java. If I helped please press the Thank You button.
August 13, 201411 yr Author I know java I just don't know which specific class I should use. I am new to Minecraft modding.
August 13, 201411 yr 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. Currently updating my Mod to 1.10.2 https://bitbucket.org/hugo_the_dwarf/riseoftristram2016/src?at=master
August 13, 201411 yr 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?
August 14, 201411 yr 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/
August 14, 201411 yr 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. http://i.imgur.com/NdrFdld.png[/img]
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.