Mob doesn't despawn with the procedure "Despawn provided entity"

Started by TheSwitzVirgin on

Topic category: Help with Minecraft modding (Java Edition)

Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Mob doesn't despawn with the procedure "Despawn provided entity"
Sun, 03/29/2020 - 06:55 (edited)

So I want to swap a mob to another when offered gold ingot and this is the event I have until now:

https://imgur.com/a/5fVVbof

But instead of despawning the mob, it despawn the Player.

Edited by TheSwitzVirgin on Sun, 03/29/2020 - 06:55
Joined May 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Perhaps you could use the …
Mon, 03/30/2020 - 15:31

Perhaps you could use the "Entity (sub)type of" block to only check for your entity and despawn that? I'm guessing it's targeting the player because the GUI test you have at the top checks the player, so in that instance, the provided entity is the player.

Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
And how do I do that? I…
Tue, 03/31/2020 - 08:22

And how do I do that? I already tried with "if current entity is (the custom mob) = true" and it doesn't despawn. 

Joined May 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Well then maybe you could…
Thu, 04/02/2020 - 02:29

Well then maybe you could use a custom code snippet. Try using one in place of "despawn provided entity" and type entity.remove(); into it (with the semicolon)

Joined Jun 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
how do you add the entity…
Fri, 04/03/2020 - 18:24

how do you add the entity.remove(); where is the custom code snippet

Joined May 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It's located in the …
Sat, 04/04/2020 - 18:30

It's located in the "Advanced" tab when making a procedure. It's purple and has a text box as its only input

Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The procedure "despawn…
Mon, 04/06/2020 - 17:19

The procedure "despawn provided entity" already add that code like ilustrated on the image:

https://imgur.com/QOAAgS2

And it despawns the player.

Joined May 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I see. Could you paste the…
Mon, 04/06/2020 - 23:08

I see. Could you paste the full code? Does it mention any other entities than the one on that line?

Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Sure, this is the full code…
Wed, 04/08/2020 - 12:43

Sure, this is the full code so far:

 

package net.mcreator.empire_war;

import net.minecraft.world.World;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.item.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.inventory.IInventory;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.Entity;

import java.util.HashMap;

@Elementsempire_war.ModElement.Tag
public class MCreatorHire extends Elementsempire_war.ModElement {
    public MCreatorHire(Elementsempire_war instance) {
        super(instance, 6);
    }

    public static void executeProcedure(java.util.HashMap<String, Object> dependencies) {
        if (dependencies.get("entity") == null) {
            System.err.println("Failed to load dependency entity for procedure MCreatorHire!");
            return;
        }
        if (dependencies.get("x") == null) {
            System.err.println("Failed to load dependency x for procedure MCreatorHire!");
            return;
        }
        if (dependencies.get("y") == null) {
            System.err.println("Failed to load dependency y for procedure MCreatorHire!");
            return;
        }
        if (dependencies.get("z") == null) {
            System.err.println("Failed to load dependency z for procedure MCreatorHire!");
            return;
        }
        if (dependencies.get("guiinventory") == null) {
            System.err.println("Failed to load dependency guiinventory for procedure MCreatorHire!");
            return;
        }
        if (dependencies.get("world") == null) {
            System.err.println("Failed to load dependency world for procedure MCreatorHire!");
            return;
        }
        Entity entity = (Entity) dependencies.get("entity");
        int x = (int) dependencies.get("x");
        int y = (int) dependencies.get("y");
        int z = (int) dependencies.get("z");
        HashMap guiinventory = (HashMap) dependencies.get("guiinventory");
        World world = (World) dependencies.get("world");
        if (((new Object() {
            public ItemStack getItemStack(int sltid) {
                IInventory inv = (IInventory) guiinventory.get("Trading");
                if (inv != null)
                    return inv.getStackInSlot(sltid);
                return ItemStack.EMPTY;
            }
        }.getItemStack((int) (0))).getItem() == new ItemStack(Items.GOLD_INGOT, (int) (1)).getItem())) {
            if (!world.isRemote) {
                Entity entityToSpawn = new MCreatorWarrior.CustomEntity(MCreatorWarrior.entity, world);
                entityToSpawn.setLocationAndAngles(x, y, z, world.rand.nextFloat() * 360F, 0);
                world.addEntity(entityToSpawn);
            }
            entity.remove();
        } else {
            if (entity instanceof PlayerEntity && !world.isRemote) {
                ((PlayerEntity) entity).sendStatusMessage(new StringTextComponent("Give me some Gold first and then we talk."), (true));
            }
            if (entity instanceof PlayerEntity)
                ((PlayerEntity) entity).closeScreen();
        }
    }
}

 

I'm not sure if it mentions another entity or not.

Joined May 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It doesn't. I think the only…
Fri, 04/10/2020 - 22:00

It doesn't. I think the only way to make this work is to put this code into the entity directly instead of using a procedure. I'm not sure how comfortable you are with coding, but if you can find in you custom entity where this procedure is triggered, you could basically copy-paste this code with a few tweaks. If you do that, then you'd be able to differentiate the player from the entity.