Jump to content

Editing current mobs update method.


Gnomorian

Recommended Posts

is there a way to "inject?" my own update method into existing mobs like skeletons or creepers, while still being loaded by forge, i have a piece of armor that i want them to recognise, and not attack the person with it, and even protect them, i know i could use entityupate event to check if its currently targeting a player with the helm and cancel it, but this will happen allot, im guessing it will be more efficent to either replace all skeletons for example that spawn in with a custom skeleton that has the changed ai, or inject a custom method into the skeleton before the game starts.

 

is there a way to do the method replacement as, or another  way of doing thing, thanks for the help.

<iframe src="http://widget.mcf.li/mc-mods/minecraft/225523-gnomgnoms-utils" width="100%" style="border: none;"></iframe>

Link to comment
Share on other sites

You really don't need to use reflection... Simply register with LivingUpdateEvent, which is triggered each time the entity is updated.

 

There are lots of other events, here is a list http://www.minecraftforge.net/wiki/Event_Reference

 

A little tip: When it comes down to reflection, stop, think and change the way you are coding. Reflection might be nice and powerful but also slow down the JVM drastically.

I require Java, both the coffee and the code :)

Link to comment
Share on other sites

What you are talking about is NOT Reflection, it's ASM (manipulating bytecode), and NO - you don't need it.

 

Use Forge Events:

LivingSetAttackTargetEvent

Get event.target, if target instaceof EntityPlayer then checks his helmet, if helmet == yours set target to null.

 

Note: I've never used it, and I am not quite sure if it will work - setting terget to null might only null event reference not the actual target (I am not in IDE). Just try and see if it ll work.

 

As to "protecting them" - it's quite harder part, you will need to add new AI stuff and save player to be protected in IExtendedEntityProperties. I don't event know if you can add AI to vanilla mob (never done that). If not - you are better of extending mob and removeing normal one spawning from all biomes or cancel their spawn event.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

yea, i was aware of the events, but setting the attackee to null will be happening constantly if its the only player aound, was hoping to not add to the performance issues minecraft has when many mods are doing things like this all the time. well, ill use the event then.

<iframe src="http://widget.mcf.li/mc-mods/minecraft/225523-gnomgnoms-utils" width="100%" style="border: none;"></iframe>

Link to comment
Share on other sites

yea, i was aware of the events, but setting the attackee to null will be happening constantly if its the only player aound, was hoping to not add to the performance issues minecraft has when many mods are doing things like this all the time. well, ill use the event then.

 

I work in this kind of stuff and from experience on working with big projects manipulating byte code or using reflection will slow down performance much much more then executing a few extra lines of code here and there. ;)

 

Use the events, that's what they are made for. :)

 

Comparison

Setting something to null is maybe 3 instructions to the CPU, when reflection is more likely to be in the hundreds :)

I require Java, both the coffee and the code :)

Link to comment
Share on other sites

I generally try to avoid reflection or code manipulation altogether when I have access to available fields or events.

 

Comparison

Setting something to null is maybe 3 instructions to the CPU, when reflection is more likely to be in the hundreds :)

Not true, see above. The JVM people are smart people, much smarter than any of us here. They know how to make this shit fast.

 

Yeah I pulled those values out of my posterior, and though the code will likely execute at a similar speed once compiled it's not a recommend practice.

 

as Ernio said, you could simply stop the normal zombie from spawning and create your own zombie based on the vanilla class file by extending it, I'd still recommend the events.

I require Java, both the coffee and the code :)

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.