Jump to content

Recommended Posts

Posted

Hi all,

 

I was wondering if anyone is aware of a method for setting vanilla entities to be aggro vs. another entity?

 

For example my mod introduces new NPCs.  I would like zombies/skeletons/etc to attack these entities as they would a player.

 

I've tried a couple solutions with out (much) luck.

 

First --

Using entity join world event to add targeting tasks (more for the zombie than others) -- I can get the zombie to 'look at' my NPCs, but their speed is not being set properly for the task (and moveSpeed field is protected/not accessible from the event).  I could manually set the speed for the mob, but would still need to be able to access the moveSpeed field. (or manually map class -> speed for a lookup table)  Also, this method will only work for 'new AI enabled' mobs as far as I can tell (zombie, skeleton).

 

//@ForgeSubscribe
//public void onEntitySpawn(EntityJoinWorldEvent evt)
//  {
//  if(evt.entity instanceof EntityMob)
//    {
//    EntityMob zomb = (EntityMob)evt.entity;
//    Config.logDebug("setting entity attack tasks for: "+zomb);
//    zomb.tasks.addTask(3, new EntityAIAttackOnCollide(zomb, NpcBase.class, zomb.getAIMoveSpeed(), true));  //<--yes I know getAIMoveSpeed() is incorrect......
//    zomb.targetTasks.addTask(2, new EntityAINearestAttackableTarget(zomb, NpcBase.class, 16.0F, 0, true));
//    }
//  }

 

Second--

Tried having my NPCs 'broadcast' attack/revenge targets to nearby EntityMob entities.  Works good for skeletons, but not on zombie pig-men (didn't really check past that).

 

protected void broadcastAggro()  
  {
  List<EntityMob> mobs = worldObj.getEntitiesWithinAABB(EntityMob.class, AxisAlignedBB.getAABBPool().getAABB(posX-16, posY-8, posZ-16, posX+16, posY+8, posZ+16));
  for(EntityMob mob : mobs)
    {
    if(mob.getAttackTarget()==null)
      {
      Config.logDebug("setting mob attack target");
      mob.setRevengeTarget(this);
      }
    }
  }

 

 

So, I've got a  couple of 'hacks' that 'work' for specific mobs, but are not something I really want to implement, and I'm really looking for something a bit more abstract that will work for _all_ vanilla mobs (and hopefully at least some mod-entities/mobs).

 

Is anyone aware of a 'proper' method to handle this?

 

Thanks in advance,

Posted

I guess you can just take a look at EntityWolf. In this base class of minecraft you can probably find a method that makes the wolf attack sheep. I think it can't be too hard.

 

That's the wrong way around though. The method there is in the wolf, not the sheep; he wants to make the vanilla thing (wolf as example) attack his mod mobs

I don't know how to do it but I am curious, it's something I want too :P

(Off-topic; will the NPCs be scriptable at all? (like Citizens for bukkit))

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Posted

Thanks for the reply,

 

Yes, I'm looking for a method to set vanilla entities to be hostile towards mine. 

 

I'm thinking I could probably use the two methods I pointed out above, but they would be specialized per-vanilla mob, and not really what I'm looking for (e.g. I would have to set zombie AI one way, skeleton another, witches yet another, etc...).  I was hoping someone had come across and solved this one before (or at least that I had missed something obvious in the MC source).

 

 

Off topic:

The NPCs are more like assorted RTS units -- peons/workers, melee units, archers, siege-engine drivers.  Not custom-scriptable or storyline oriented -- more production/resource/combat oriented.

Posted
That's the wrong way around though. The method there is in the wolf, not the sheep; he wants to make the vanilla thing (wolf as example) attack his mod mobs

I don't know how to do it but I am curious, it's something I want too

 

Well you say, the wrong way around. But all that i say is that the method found in EntityWolf can be used to make it so that whatever entity you want to attack your own mob or a vanilla mob. I'm not sure how to do this without altering base classes because i am not really going to do something similar but i think the method is not that complicated or is it?

Posted

I tried to do the same thing with my turrets. Works quite well, except of the entities move faster than usual when targeted, so you have to ajust the speed (so do I :P).

Everytime the projectile hits a target, the target will 'target' the shooting entity (the turret).

Have some code:

https://github.com/SanAndreasP/TurretModv3/blob/master/sanandreasp/mods/TurretMod3/entity/projectile/TurretProjectile.java#L381

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

Thanks SanAndreasP,

 

I think the move-speed thing can be solved 'fairly' easily (more reflection to pull the default moveSpeed out of the mob).

 

Your solution might be the way to go.  Trying to insert AI tasks will be problematic with some mobs, but it looks like most mobs use the revenge-target/attack target methods to at least some effect. 

 

I was really hoping to find a method to set during mob spawning/creation, and not have to have my npcs 'broadcast' for aggro at all, but its looking like it won't really be feasible with the current state of things.

 

 

One final question  -- I've mostly stayed away from reflection for various reasons (specifically reflecting on obfuscated code) -- I see that you are pulling the private field by field name --  If I go this route, all I should really have to worry about is renaming the field in my code if the name changes in an MC update ?  (e.g. how stable is it generally between forge/MCP versions for the same MC version?)

Posted

Thanks SanAndreasP,

 

I think the move-speed thing can be solved 'fairly' easily (more reflection to pull the default moveSpeed out of the mob).

 

Your solution might be the way to go.  Trying to insert AI tasks will be problematic with some mobs, but it looks like most mobs use the revenge-target/attack target methods to at least some effect. 

 

I was really hoping to find a method to set during mob spawning/creation, and not have to have my npcs 'broadcast' for aggro at all, but its looking like it won't really be feasible with the current state of things.

 

 

One final question  -- I've mostly stayed away from reflection for various reasons (specifically reflecting on obfuscated code) -- I see that you are pulling the private field by field name --  If I go this route, all I should really have to worry about is renaming the field in my code if the name changes in an MC update ?  (e.g. how stable is it generally between forge/MCP versions for the same MC version?)

 

You see the 2 string parameters. The first one is the name given by MCP, so you can test it. The second one is the SRG name of that field. It's like an index given by MCP before the real naming occurs. (path of deobfuscation goes like >> Notch (obfuscated) names -> SRG (index) names -> deobfuscated (community-driven) names <<

The Notch names and the deobf-names are changing through MC updates, where SRG names are unlikely to change (except the fields / methods have changed or been removed or something like that).

Forge comes with "runtime-deobfuscation", meaning it converts the Notch names to SRG names and thus mods don't need to update unless a part in MC changed which the mod uses.

To get those SRG names, open the '/forge/mcp/conf/fields.csv' and look up the name. The SRG name is the very first (starts with 'field_'). For methods it's in the 'method.csv' in the same directory.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

Awesome, thanks for the crash course in obfuscation.  Your explanation straightens out a couple things I had wondered about (SRG naming and consistency).

 

I'll let you know if I run across any other solutions to this problem, but will probably be using similar to what you have proposed.

 

 

Thanks again :)

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • accidental duplicate mesage cuz lag
    • https://gnomebot.dev/paste/231527759279685634/1372324909073563730/1372324908629102716 https://gnomebot.dev/paste/231527759279685634/1372320454861262908/1372320454299090996 seems like theres a registry sync error, not sure what that means though, however in an old pack i played on, i actually had a registry sync error happen whenever the world tried too save and it would suddenly stop loading chunks, is there a mod fix for this or some way too bypass registry syncing? is this a server problem? i have no issues with the pack on pc, only on my server.
    • i think the problem is the player animator library but i need it for one of my main mods is there any way i can fix this? The game crashed: rendering overlay Error: java.lang.IllegalArgumentException: Failed to create player model for default heres the crash report: https://pastebin.com/U5Wp8ysb
    • I have been an enthusiastic investor in crypt0currencies for several years, and my digital assets have been integral to my financial strategy. A few months ago, I encountered a distressing predicament when I lost access to my primary cryptocurrency walleet after clicking on an airdrop link that inadvertently connected to my walleet. The dread of potentially losing all my hard-earned funds was overwhelming, leaving me uncertain about where to seek assistance. In my pursuit of solutions, I stumbled upon ChainDigger Retrievers. From our initial consultation to the triumphant recovery of my assets, the team exhibited exceptional expertise. They provided comprehensive explanations of the recovery process, ensuring I was informed at every stage and offering reassurance during this tumultuous time. Their approach was not only meticulous but also compassionate, which significantly alleviated my anxiety. ChainDigger Retrievers unwavering commitment to resolving my issue was evident throughout the process. Leveraging their profound understanding of crypt0currency technology and digital forensics, they initiated an exhaustive investigation to trace the transactions linked to my compromised wallet. Their meticulous analysis and relentless determination were apparent as they left no stone unturned in their quest to recover my funds. After several days of diligent investigation, the team successfully recovered everything I had lost. They uncovered that the link I had clicked contained malware, which scammeers had used to infiltrate my walleet. This revelation was both alarming and enlightening, underscoring the inherent risks associated with crypt0currency transactions when proper precautions are not taken.Thanks to ChainDigger Retrievers, I not only regained everything but also acquired invaluable knowledge about safeguarding my investments. Their expertise and steadfast support transformed a daunting situation into a manageable one, and I am profoundly grateful for their assistance. I can now continue my investment journey with renewed confidence, knowing that I have a trustworthy ally in ChainDigger Retrievers. Their client satisfaction is truly commendable, and I wholeheartedly recommend their services to anyone facing similar challenges in the crypt0currency realm. With their help, I was able to turn a distressing time into a positive outcome, and I will forever be grateful for their support.  
    • I didn’t even notice that side of the report, as I expected it was a bunch of client mods, thanks for the advice
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.