How to make mobs be a 'pet' to another mob

Started by tntapplecraft YT on

Topic category: Advanced modding

Joined Feb 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to make mobs be a 'pet' to another mob

So basically I want to make a necromancer mob that can control undead and make them attack. If they get attacked by the player all the undead around it should attack the player afterwards. I also want the necromancer to drop it's robes, which let the player control the undead. Is there anyway to do this?

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
So basically I want to make…
Sun, 06/14/2020 - 18:12

So basically I want to make a necromancer mob that can control undead and make them attack. If they get attacked by the player all the undead around it should attack the player afterwards.

Wrote this up just for you😘 lol;

    @SubscribeEvent
    public void necromancerDamage(LivingDamageEvent event) {
        if (event.getEntity() instanceof NecromancerEntity && event.getSource().getTrueSource() instanceof LivingEntity)
        {
            List<MobEntity> mobEntities = event.getEntity().world.getEntitiesWithinAABB(MobEntity.class, event.getEntity().getBoundingBox().grow(10));
            Iterator iterator = mobEntities.iterator();
            while (iterator.hasNext()) {
                MobEntity mobEntity = (MobEntity) event.getEntity();
                if (mobEntity.isEntityUndead())
                {
                    mobEntity.setAttackTarget((LivingEntity) event.getSource().getTrueSource());
                }
            }
        }
    }

 

 

 also want the necromancer to drop it's robes, which let the player control the undead.

Explain more, like how control them. Control movement, etc.

Joined Feb 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
just the same thing with the…
Sun, 06/21/2020 - 02:38

just the same thing with the necromancers

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ok, something similar to…
Sun, 06/21/2020 - 02:48

Ok, something similar to this should work, I am on my phone right now so some of the methods may be incorrect.

public void livingAttackTarget(LivingSetAttackTargetEvent event) {
if (event.getTarget().inventory.getItemStackInSlot(EquipmentSlot.CHEST) == new ItemStack(YOURNECROMANCERROBES) && event.getEntity() instanceof MobEntity) {
((MobEntity)event.getEntity()).setAttackTarget(null);
((MobEntity)event.getEntity()).setAggroed(false);
}
}

 

Joined Feb 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
so where do I put this code?
Sun, 06/21/2020 - 05:04

so where do I put this code?

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Since these are events, they…
Sun, 06/21/2020 - 10:39

Since these are events, they can be in any registered class using,

MinecraftForge.EVENT_BUS.register(TheClass);

 

Joined Feb 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ok I did the first code for…
Tue, 06/30/2020 - 08:36

Ok I did the first code for calling all undead to attack the player, but when I put the code into the necromancer damage event and edit it a little and then run client an error message pops up. I think I need to put the code into tick update, but I'm not sure. can you clarify this for me?

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Post what you have
Tue, 06/30/2020 - 13:22

Post what you have

Joined Feb 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
package net.mcreator…
Wed, 07/01/2020 - 05:45

package net.mcreator.thestonesofpower.procedures;

import net.mcreator.thestonesofpower.ThestonesofpowerModElements;

@ThestonesofpowerModElements.ModElement.Tag
public class NecromancerEntityIsHurtProcedure extends ThestonesofpowerModElements.ModElement {
    public NecromancerEntityIsHurtProcedure(ThestonesofpowerModElements instance) {
        super(instance, 133);
    }

    public static void executeProcedure(java.util.HashMap<String, Object> dependencies) {
        if (event.getEntity() instanceof NecromancerEntity && event.getSource().getTrueSource() instanceof LivingEntity) { List<MobEntity> mobEntities = event.getEntity().world.getEntitiesWithinAABB(MobEntity.class, event.getEntity().getBoundingBox().grow(20
        0)); Iterator iterator = mobEntities.iterator(); while (iterator.hasNext()) { MobEntity mobEntity = (MobEntity) event.getEntity(); if (mobEntity.isEntityUndead()) { mobEntity.setAttackTarget((LivingEntity) event.getSource().getTrueSource()); } } } }
    }
}
 

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Don't use the code I…
Wed, 07/01/2020 - 06:19

Don't use the code I provided with the procedure wrapper. It provides dependencies, not the event.

 

Instead you should create a custom element, register it, and then use the code in its entirety.

Joined Feb 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I still get the error…
Wed, 07/01/2020 - 06:52

I still get the error message that the code doesn't compile properly when i try to run client

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Can you post the error?
Wed, 07/01/2020 - 13:24

Can you post the error?