Solved [1.8] custom Entity is Invisible

Discussion in 'Spigot Plugin Development' started by nyannetwork, Aug 24, 2015.

  1. Code (Text):
    import net.minecraft.server.v1_8_R3.*;

    import org.bukkit.Location;
    import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
    import org.bukkit.craftbukkit.v1_8_R3.entity.CraftBlaze;
    import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity;
    import org.bukkit.entity.Blaze;
    import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
    import org.bukkit.util.Vector;

    import java.lang.reflect.Field;
    import java.util.List;

    public class Trader extends EntityBlaze {

        public Trader(World world) {
            super(world);

        }
        public void makeSound(String s, float f, float f1)
        {
            return;
        }




        @Override
    public void move(double d0, double d1, double d2) {
         super.move(0, 0, 0);
    }

        @Override
    public void g(double x, double y, double z) {
         Vector vector = this.getBukkitEntity().getVelocity();
         super.g(vector.getX(), vector.getY(), vector.getZ());

            List goalB = (List)getPrivateField("b", PathfinderGoalSelector.class, goalSelector); goalB.clear();
            List goalC = (List)getPrivateField("c", PathfinderGoalSelector.class, goalSelector); goalC.clear();
            List targetB = (List)getPrivateField("b", PathfinderGoalSelector.class, targetSelector); targetB.clear();
            List targetC = (List)getPrivateField("c", PathfinderGoalSelector.class, targetSelector); targetC.clear();

            this.goalSelector.a(2, new PathfinderGoalMeleeAttack(this, EntityHuman.class, 1.0D, false));
            this.goalSelector.a(2, new PathfinderGoalMeleeAttack(this, Entity.class, 1.0D, false));
            this.goalSelector.a(8, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 8.0F));

        }

        public static Object getPrivateField(String fieldName, Class clazz, Object object)
        {
            Field field;
            Object o = null;

            try
            {
                field = clazz.getDeclaredField(fieldName);

                field.setAccessible(true);

                o = field.get(object);
            }
            catch(NoSuchFieldException e)
            {
                e.printStackTrace();
            }
            catch(IllegalAccessException e)
            {
                e.printStackTrace();
            }

            return o;
    }



        public static Blaze spawn(Location location) {
            World mcWorld = (World) ((CraftWorld) location.getWorld()).getHandle();
            final Trader customEntity = new Trader(
                    mcWorld);
            customEntity.setLocation(location.getX(), location.getY(),
                    location.getZ(), location.getYaw(), location.getPitch());
            ((CraftLivingEntity) customEntity.getBukkitEntity())
                    .setRemoveWhenFarAway(false);
            mcWorld.addEntity(customEntity, SpawnReason.CUSTOM);
            return (CraftBlaze) customEntity.getBukkitEntity();
        }
    }