Cannot Check Custom Villager Profession

Started by Warper_0ff on

Topic category: Help with Minecraft modding (Java Edition)

Joined May 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Cannot Check Custom Villager Profession

Hi,

I was making a custom villager called the Crafter, I'd like him to build things based of his profession level ;

  • Novice : Build a little campfire
  • Apprentice : Build a well
  • Journeyman : Build a house
  • Expert : Build an Iron Golem
  • Master : Build walls around his base (he spawns alone in forests and not villages)

But I was stuck when I needed to detect if the villager has this specific profession in an entity tick update,

with a custom code snippet, I was able to detect a VANILLA profession like Farmer, Butcher...etc

but this doesn't seems to work with custom professions, here is the code of the procedure :

 

package net.mcreator.infinityblades.procedures;

/* imports omitted */

@Mod.EventBusSubscriber

public class CrafterVillagerTickProcedure {

    @SubscribeEvent

    public static void onEntityTick(LivingEvent.LivingTickEvent event) {

        execute(event, event.getEntity());

    }



    public static void execute(Entity entity) {

        execute(null, entity);

    }



    private static void execute(@Nullable Event event, Entity entity) {

        if (entity == null)

            return;

        boolean found = false;

        double sx = 0;

        double sy = 0;

        double sz = 0;

        if (entity instanceof Villager) {

            if (((Villager) entity).getVillagerData().getProfession() == VillagerProfession.CRAFTER) {

                {

                    Entity _ent = entity;

                    if (!_ent.level().isClientSide() && _ent.getServer() != null) {

                        _ent.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, _ent.position(), _ent.getRotationVector(), _ent.level() instanceof ServerLevel ? (ServerLevel) _ent.level() : null, 4,

                                _ent.getName().getString(), _ent.getDisplayName(), _ent.level().getServer(), _ent), "say Im a Crafter !");

                    }

                }

            }

        }

    }

}
Joined May 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I think I will just do the…
Fri, 05/03/2024 - 12:21

I think I will just do the procedure if the villager isn't any of the vanilla ones. But if I need to make another villager, it will be a problem. So if anyone knows a solution, tell me please