Unstoppable Custom Entity

Discussion in 'Plugin Development' started by MightyOne, Oct 12, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    MightyOne

    Hey,
    I tried to create a custom entity class in 1.12 to make a ridable cow. So basically I can control the cow but it is still a bit buggy

    1. For the first minute on a new cow I can only control it forward
    2. After that minute it gets super sanic speed, even if I tried to prevent that by multiplying the motion (motX, motZ) with backToNormalSpeed

    here is the class so far:

    Code:
    public class DisabledCow extends EntityCow{
    
        private static final float backToNormalSpeed = 0.5f;
    
        public DisabledCow(World world) {
            super(world);
            //stepHeight
            this.P = 1f;
        }
    
        //movement       x      y      z
        @Override
        public void a(float f, float f1, float f2) {
       
            //if has passenger and its is alive
            if(isVehicle() && cV()) {
                EntityLiving entityliving = (EntityLiving)bE();
           
                this.lastYaw = this.yaw = entityliving.yaw;
                this.pitch = entityliving.pitch * 0.5F;
                this.setYawPitch(this.yaw, this.pitch);
                this.aQ = this.aO = this.yaw;
    
                //be, bg, bh - Player WASD+Space?
                f = entityliving.be * 0.5f;
                f2 = entityliving.bg;
    
                //slow down backwards
                if (f2 <= 0.0f)
                    f2 *= 0.25;
           
                //calculate in which direction cow should go
                if (f2 > 0f) {
                    float f3 = MathHelper.sin(this.yaw * 0.017453292F);
                    float f4 = MathHelper.cos(this.yaw * 0.017453292F);
               
                    this.motX += -0.4F * f3 * backToNormalSpeed;
                    this.motZ += 0.4F * f4 * backToNormalSpeed;
                }
           
            }
            super.a(f, f1, f2);
        }
    
    
        //is passenger a living entity
        @Override
        public boolean cV() {
            return bE() instanceof EntityLiving;
        }
    
        //get passenger
        @Override @Nullable
        public Entity bE() {
            return bF().isEmpty() ? null : (Entity)bF().get(0);
        }
    Well I copied the majority from EntityHorseAbstract as good as possible and did not change methode names. I hope the code is selfexplanatory with the comments.

    Any idea how to fix these bugs or where they come from?
    Any help would be appreciated.
     
    Last edited: Oct 12, 2017
Thread Status:
Not open for further replies.

Share This Page