NMS Chicken Doesn't Move/Glide

Discussion in 'Spigot Plugin Development' started by Bladian, May 6, 2015.

Thread Status:
Not open for further replies.
  1. Title says it all.

    I have this custom chicken that doesn't move at all.

    This has something to do with the g override, since when I test it, the chicken moves perfectly.

    Here is the custom chicken class.

    Code (Text):
    package me.mounts.mounts;

    import net.minecraft.server.v1_8_R2.*;
    import org.bukkit.craftbukkit.v1_8_R2.CraftWorld;

    import java.lang.reflect.Field;

    public class CustomChicken1 extends EntityChicken {

        public void g(float f, float f1) {
            if (this.passenger != null && this.passenger instanceof EntityHuman) {
                this.lastYaw = this.yaw = this.passenger.yaw;
                this.pitch = this.passenger.pitch * 0.5F;
                this.setYawPitch(this.yaw, this.pitch);
                this.aK = this.aI = this.yaw;
                f = ((EntityLiving) this.passenger).aZ * 0.5F;
                f1 = ((EntityLiving) this.passenger).ba;
                if (f1 <= 0.0F) {
                    f1 *= 0.25F;
                Field jump = null;
                try {
                    jump = EntityLiving.class.getDeclaredField("aY");
                } catch (NoSuchFieldException e1) {
                    if (jump != null) {
                        try {
                            if (!jump.getBoolean(this.passenger)) {
                            } else {
                                double jumpHeight = 0.5D;
                                this.motY = jumpHeight;
                        } catch (IllegalAccessException e) {
                        this.S = 1.0F;
                        this.aM = this.bI() * 0.1F;
                        if (!this.world.isClientSide) {
                            this.k((float) this.getAttributeInstance(GenericAttributes.d).getValue());
                            super.g(f, f1);

                        this.aA = this.aB;
                        double d0 = this.locX - this.lastX;
                        double d1 = this.locZ - this.lastZ;
                        float f4 = MathHelper.sqrt(d0 * d0 + d1 * d1) * 4.0F;
                        if (f4 > 1.0F) {
                            f4 = 1.0F;

                        this.aB += (f4 - this.aB) * 0.4F;
                        this.aC += this.aB;
                    } else {
                        this.S = 0.5F;
                        this.aM = 0.02F;
                        super.g(f, f1);


        public CustomChicken1(org.bukkit.World world) {

            super(((CraftWorld) world).getHandle());


    Everything is registered and the chicken spawns, it also follows my yaw and pitch, but it doesn't move at all.

    Any help?

    This is taken from the horse class from spigot, I double checked everything just incase.
  2. Not sure what you mean sorry.

    I had this code, tested yesterday, had no problem, but as soon as I came back, it all stopped working.
  3. You probably shouldn't do the stuff in your catch-block.
    • Winner Winner x 1
  4. Why not?
  5. at is a protected field, you should be able to access it directly.
    it will never execute. Move that code to the try block.
    • Winner Winner x 1
  6. ...No comment.

    My idiocy had passed all meanings.

    I'll test it out now thanks!
  7. HOURS AND HOURS OR DOUBLE-CHECKING just because I mixed up the blocks.


    Thank you both!
  8. Just one more problem, when I jump it basically allows me to fly. Is there any way to limit the duration of the jump.
  9. @BurnerDiamond set it false several ticks later? You have a method that is called every tick, that functions just like run() in a timer task. Just make an int field which stores how many ticks they are jumping, and set it to false when you reach a threshold (how much is up to you).
  10. Thanks for the answer but I found a better solution.

    There's an onGround() method which returns whether or not he's on the ground.

    Thanks for your help though.
Thread Status:
Not open for further replies.