help with custom mob behavior(solved)

Started by potatomancer on

Topic category: Help with Minecraft modding (Java Edition)

Joined Oct 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
help with custom mob behavior(solved)
Thu, 10/16/2025 - 00:08 (edited)

i am trying to make a mob that, upon noticing the player or a mob it is hostile to:

  1. saves its targets position
  2. waits for 1 second
  3. moves towards saved position with increased speed and dies when reaching it (mob explodes on death, i already have that part made)

i have no idea on how to change mob behavior beyond the provided task/goals editor, so general information on the tools to do this for the future will be greatly appreciated

Edited by potatomancer on Thu, 10/16/2025 - 00:08
Joined Dec 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It'd probably be easiest to…
Thu, 10/09/2025 - 08:29

It'd probably be easiest to just use the tick trigger for the entity and then the path find procedure block

Joined Oct 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
i set up the base for the…
Sat, 10/11/2025 - 01:47

i set up the base for the mob behavior (thanks for the tick trigger tip, didnt know that existed) but, despite saving the target position as a local variable, it navigates towards 0, 0, 0 instead of the target coordinates. heres the generated code from my current procedure, please let me know if i am doing something wrong

package net.mcreator.bluedwarf.procedures;

/* imports omitted */

@EventBusSubscriber
public class GlitchBehaviorProcedure {
@SubscribeEvent
public static void onEntityTick(EntityTickEvent.Pre event) {
execute(event, event.getEntity().level(), event.getEntity().getX(), event.getEntity().getY(), event.getEntity().getZ(), event.getEntity());
}

public static void execute(LevelAccessor world, double x, double y, double z, Entity entity) {
execute(null, world, x, y, z, entity);
}

private static void execute(@Nullable Event event, LevelAccessor world, double x, double y, double z, Entity entity) {
if (entity == null)
return;
double PlayerX = 0;
double PlayerY = 0;
double PlayerZ = 0;
if ((entity instanceof LivingEntity _livingEntity0 && _livingEntity0.getAttributes().hasAttribute(BlueDwarfModAttributes.IS_GLITCH) ? _livingEntity0.getAttribute(BlueDwarfModAttributes.IS_GLITCH).getBaseValue() : 0) == 1) {
if (entity.getPersistentData().getDouble("timer") == 0) {
if (!world.getEntitiesOfClass(Player.class, new AABB(Vec3.ZERO, Vec3.ZERO).move(new Vec3(x, y, z)).inflate(16 / 2d), e -> true).isEmpty()) {
PlayerX = (findEntityInWorldRange(world, Player.class, x, y, z, 16)).getX();
PlayerY = (findEntityInWorldRange(world, Player.class, x, y, z, 16)).getY();
PlayerZ = (findEntityInWorldRange(world, Player.class, x, y, z, 16)).getZ();
if (entity instanceof LivingEntity _livingEntity9 && _livingEntity9.getAttributes().hasAttribute(Attributes.MOVEMENT_SPEED))
_livingEntity9.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(0);
entity.getPersistentData().putDouble("timer", (entity.getPersistentData().getDouble("timer") + 1));
}
}
if (entity.getPersistentData().getDouble("timer") > 0) {
entity.getPersistentData().putDouble("timer", (entity.getPersistentData().getDouble("timer") + 1));
if (entity.getPersistentData().getDouble("timer") >= 20) {
if (entity instanceof LivingEntity _livingEntity16 && _livingEntity16.getAttributes().hasAttribute(Attributes.MOVEMENT_SPEED))
_livingEntity16.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(1);
if (entity instanceof Mob _entity)
_entity.getNavigation().moveTo(PlayerX, PlayerY, PlayerZ, 1);
if (entity.getPersistentData().getDouble("timer") >= 120) {
entity.hurt(new DamageSource(world.holderOrThrow(DamageTypes.GENERIC_KILL)), 1);
}
if (entity.getX() == PlayerX) {
if (entity.getY() == PlayerY) {
if (entity.getZ() == PlayerZ) {
entity.hurt(new DamageSource(world.holderOrThrow(DamageTypes.GENERIC_KILL)), 1);
}
}
}
}
}
}
}

private static Entity findEntityInWorldRange(LevelAccessor world, Class<? extends Entity> clazz, double x, double y, double z, double range) {
return (Entity) world.getEntitiesOfClass(clazz, AABB.ofSize(new Vec3(x, y, z), range, range, range), e -> true).stream().sorted(Comparator.comparingDouble(e -> e.distanceToSqr(x, y, z))).findFirst().orElse(null);
}
}
Joined Dec 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
can you send the procedure…
Sat, 10/11/2025 - 08:42

can you send the procedure as an image instead?

Joined Oct 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
yes, but i dont know what…
Sun, 10/12/2025 - 23:58

yes, but i dont know what null means. is that why the coordinates arent working? if so, what do i do about it?

Joined Dec 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
it means it couldn't find…
Mon, 10/13/2025 - 06:54

it means it couldn't find any entity, and yeah that'd be why

Joined Oct 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
it doesnt make sense why the…
Mon, 10/13/2025 - 23:18

it doesnt make sense why the values will return as 0, there is an if statement assuring that the data is valid and i also tried making the get radius larger than the if radius, and it still doesnt work. please tell me how to stop it from being null

Joined Dec 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
oh have you tested if it…
Tue, 10/14/2025 - 12:35

oh have you tested if it even passes that condition?

in mcreator local number variables are set to 0 at the start of the procedure

Joined Oct 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
i know it passes the…
Tue, 10/14/2025 - 23:04

i know it passes the procedure because if it didnt the entity wouldnt navigate at all, but it does, just not to where i want it to.

Joined Dec 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
oh wait. Local variables are…
Wed, 10/15/2025 - 08:24

oh wait. Local variables are "cleared"/"forgotten" when the execution of the procedure reaches the end of it.

Joined Oct 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
switched the variables to an…
Thu, 10/16/2025 - 00:08

switched the variables to an nbt value and it worked! thanks for your help