Hello everyone. I need help, I hope you can help me ... I want to make a mob, a pet with the same features of a pet wolf. I know there are plugins for pets, but do not want something around my plugin (only if I can work with the plugin API). You say what you think best, please. Thank you for your attention.
TheIronKill What "I think best" is to use an API. They exist to make life easier. Unless you want to take the time to code custom NMS entities that support multiple versions and pathfinders and whatnot to mimic a wolf and run safely across versions.
You could even use this if you wanted to: Code:java package resources.codechimps.co.uk; import java.lang.reflect.Field;import java.util.UUID; import net.minecraft.server.v1_7_R3.EntityInsentient;import net.minecraft.server.v1_7_R3.PathEntity;import net.minecraft.server.v1_7_R3.PathfinderGoal;import net.minecraft.server.v1_7_R3.PathfinderGoalFloat;import net.minecraft.server.v1_7_R3.PathfinderGoalSelector; import org.bukkit.Bukkit;import org.bukkit.Location;import org.bukkit.craftbukkit.v1_7_R3.entity.CraftLivingEntity;import org.bukkit.craftbukkit.v1_7_R3.util.UnsafeList;import org.bukkit.entity.LivingEntity; public class PetControl { /* * @author Alex Harris * * PetControl is a class to create and control pets for each player. * */ /* * Example Usage: * final Player p = (Player) sender; * Creeper creeper = p.getWorld().spawn(p.getLocation(), Creeper.class); * creeper.setCustomName(ChatColor.GOLD + p.getDisplayName() + "'s Pet"); * creeper.setCustomNameVisible(true); * PetControl.createPet(creeper, p.getUUID()); * */ private static Field gsa; private static Field goalSelector; private static Field targetSelector; static { try { gsa = PathfinderGoalSelector.class.getDeclaredField("b"); gsa.setAccessible(true); goalSelector = EntityInsentient.class.getDeclaredField("goalSelector"); goalSelector.setAccessible(true); targetSelector = EntityInsentient.class.getDeclaredField("targetSelector"); targetSelector.setAccessible(true); } catch (Exception e) { e.printStackTrace(); } } @SuppressWarnings("deprecation") public static void createPet(LivingEntity e, UUID toFollow) { try { Object nms_entity = ((CraftLivingEntity) e).getHandle(); if (nms_entity instanceof EntityInsentient) { PathfinderGoalSelector goal = (PathfinderGoalSelector) goalSelector.get(nms_entity); PathfinderGoalSelector target = (PathfinderGoalSelector) targetSelector.get(nms_entity); gsa.set(goal, new UnsafeList<Object>()); gsa.set(target, new UnsafeList<Object>()); goal.a(0, new PathfinderGoalFloat((EntityInsentient) nms_entity)); goal.a(1, new PathfinderGoalWalktoTile((EntityInsentient) nms_entity, toFollow)); } else { throw new IllegalArgumentException(e.getType().getName() + " is not an instance of an EntityInsentient."); } } catch (Exception ex) { ex.printStackTrace(); } } public static class PathfinderGoalWalktoTile extends PathfinderGoal { private EntityInsentient entity; private PathEntity path; private UUID p; public PathfinderGoalWalktoTile(EntityInsentient entitycreature, UUID p) { this.entity = entitycreature; this.p = p; } @Override public boolean a() { if (Bukkit.getPlayer(p) == null) { return path != null; } Location targetLocation = Bukkit.getPlayer(p).getLocation(); boolean flag = this.entity.getNavigation().c(); this.entity.getNavigation().b(false); this.path = this.entity.getNavigation().a(targetLocation.getX() + 1, targetLocation.getY(), targetLocation.getZ() + 1); this.entity.getNavigation().b(flag); if (this.path != null) { this.c(); } return this.path != null; } @Override public void c() { this.entity.getNavigation().a(this.path, 1D); } }}