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

Started by tntapplecraft YT on

Topic category: Advanced modding

Active 3 years ago
Joined Feb 2018
Points:
819

User statistics:

  • Modifications: 2
  • Forum topics: 10
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 136
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?

Active 4 years ago
Joined Sep 2019
Points:
973

User statistics:

  • Modifications: 1
  • Forum topics: 14
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 507
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.

Active 3 years ago
Joined Feb 2018
Points:
819

User statistics:

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

just the same thing with the necromancers

Active 4 years ago
Joined Sep 2019
Points:
973

User statistics:

  • Modifications: 1
  • Forum topics: 14
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 507
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);
}
}

 

Active 3 years ago
Joined Feb 2018
Points:
819

User statistics:

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

so where do I put this code?

Active 4 years ago
Joined Sep 2019
Points:
973

User statistics:

  • Modifications: 1
  • Forum topics: 14
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 507
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);

 

Active 3 years ago
Joined Feb 2018
Points:
819

User statistics:

  • Modifications: 2
  • Forum topics: 10
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 136
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?

Active 4 years ago
Joined Sep 2019
Points:
973

User statistics:

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

Post what you have

Active 3 years ago
Joined Feb 2018
Points:
819

User statistics:

  • Modifications: 2
  • Forum topics: 10
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 136
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()); } } } }
    }
}
 

Active 4 years ago
Joined Sep 2019
Points:
973

User statistics:

  • Modifications: 1
  • Forum topics: 14
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 507
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.

Active 3 years ago
Joined Feb 2018
Points:
819

User statistics:

  • Modifications: 2
  • Forum topics: 10
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 136
oh ok  
Wed, 07/01/2020 - 06:38

oh ok

 

Active 3 years ago
Joined Feb 2018
Points:
819

User statistics:

  • Modifications: 2
  • Forum topics: 10
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 136
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

Active 4 years ago
Joined Sep 2019
Points:
973

User statistics:

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

Can you post the error?