SrinjoySS01

Untitled

Oct 25th, 2020
93
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.srinjoy.saddlemod;
  2.  
  3. import net.minecraft.entity.*;
  4. import net.minecraft.entity.ai.attributes.IAttribute;
  5. import net.minecraft.entity.ai.attributes.RangedAttribute;
  6. import net.minecraft.entity.player.PlayerEntity;
  7. import net.minecraft.network.datasync.DataParameter;
  8. import net.minecraft.network.datasync.DataSerializers;
  9. import net.minecraft.network.datasync.EntityDataManager;
  10. import net.minecraft.potion.Effects;
  11. import net.minecraft.util.math.MathHelper;
  12. import net.minecraft.util.math.Vec3d;
  13. import net.minecraft.world.World;
  14.  
  15. import javax.annotation.Nonnull;
  16. import java.util.Objects;
  17.  
  18. public class CustomEntity extends CreatureEntity {
  19.     private float jumpPower;
  20.     private boolean allowStandSliding;
  21.     private static final DataParameter<Byte> STATUS = EntityDataManager.createKey(CustomEntity.class, DataSerializers.BYTE);
  22.     protected static final IAttribute JUMP_STRENGTH = (new RangedAttribute((IAttribute)null, "horse.jumpStrength", 0.7D, 0.0D, 2.0D)).setDescription("Jump Strength").setShouldWatch(true);
  23.     private boolean horseJumping;
  24.     private float prevRearingAmount;
  25.  
  26.  
  27.     protected CustomEntity(EntityType<? extends CreatureEntity> type, World worldIn) {
  28.         super(type, worldIn);
  29.     }
  30.  
  31.     @Override
  32.     public boolean canBeSteered() {
  33.         return true;
  34.     }
  35.  
  36.     @Override
  37.     public void travel(@Nonnull Vec3d p_213352_1_) {
  38.         if (this.isAlive()){
  39.             if (this.isBeingRidden() && this.canBeSteered()){
  40.                 LivingEntity entity = (LivingEntity) this.getControllingPassenger();
  41.                 this.rotationYaw = entity.rotationYaw;
  42.                 this.prevRotationYaw = this.rotationYaw;
  43.                 this.rotationPitch = entity.rotationPitch * 0.5F;
  44.                 this.setRotation(this.rotationYaw, this.rotationPitch);
  45.                 this.renderYawOffset = this.rotationYaw;
  46.                 this.rotationYawHead = this.renderYawOffset;
  47.                 float f = entity.moveStrafing * 0.5F;
  48.                 float f1 = entity.moveForward;
  49.                 if (f1 <= 0.0F) f1 *= 0.25F;
  50.                 if (this.onGround && this.jumpPower == 0.0F && this.isRearing() && !this.allowStandSliding) {
  51.                     f = 0.0F;
  52.                     f1 = 0.0F;
  53.                 }
  54.                 if (this.jumpPower > 0.0F && !this.isHorseJumping() && this.onGround) {
  55.                     double d0 = this.getHorseJumpStrength() * (double)this.jumpPower * (double)this.getJumpFactor();
  56.                     double d1;
  57.                     if (this.isPotionActive(Effects.JUMP_BOOST)) {
  58.                         d1 = d0 + (double)((float)(Objects.requireNonNull(this.getActivePotionEffect(Effects.JUMP_BOOST)).getAmplifier() + 1) * 0.1F);
  59.                     } else {
  60.                         d1 = d0;
  61.                     }
  62.  
  63.                     Vec3d vec3d = this.getMotion();
  64.                     this.setMotion(vec3d.x, d1, vec3d.z);
  65.                     this.setHorseJumping(true);
  66.                     this.isAirBorne = true;
  67.                     if (f1 > 0.0F) {
  68.                         float f2 = MathHelper.sin(this.rotationYaw * ((float)Math.PI / 180F));
  69.                         float f3 = MathHelper.cos(this.rotationYaw * ((float)Math.PI / 180F));
  70.                         this.setMotion(this.getMotion().add((double)(-0.4F * f2 * this.jumpPower), 0.0D, (double)(0.4F * f3 * this.jumpPower)));
  71.                     }
  72.  
  73.                     this.jumpPower = 0.0F;
  74.                 }
  75.                 this.jumpMovementFactor = this.getAIMoveSpeed() * 0.1F;
  76.                 if (this.canPassengerSteer()) {
  77.                     this.setAIMoveSpeed((float)this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getValue());
  78.                     super.travel(new Vec3d((double)f, p_213352_1_.y, (double)f1));
  79.                 } else if (entity instanceof PlayerEntity) {
  80.                     this.setMotion(Vec3d.ZERO);
  81.                 }
  82.  
  83.                 if (this.onGround) {
  84.                     this.jumpPower = 0.0F;
  85.                     this.setHorseJumping(false);
  86.                 }
  87.  
  88.                 this.prevLimbSwingAmount = this.limbSwingAmount;
  89.                 double d2 = this.getPosX() - this.prevPosX;
  90.                 double d3 = this.getPosZ() - this.prevPosZ;
  91.                 float f4 = MathHelper.sqrt(d2 * d2 + d3 * d3) * 4.0F;
  92.                 if (f4 > 1.0F) {
  93.                     f4 = 1.0F;
  94.                 }
  95.  
  96.                 this.limbSwingAmount += (f4 - this.limbSwingAmount) * 0.4F;
  97.                 this.limbSwing += this.limbSwingAmount;
  98.             } else {
  99.                 this.jumpMovementFactor = 0.02F;
  100.                 super.travel(p_213352_1_);
  101.             }
  102.         }
  103.     }
  104.  
  105.     @Override
  106.     public void updatePassenger(@Nonnull Entity passenger) {
  107.         super.updatePassenger(passenger);
  108.         if (passenger instanceof MobEntity) {
  109.             MobEntity mobentity = (MobEntity)passenger;
  110.             this.renderYawOffset = mobentity.renderYawOffset;
  111.         }
  112.  
  113.         if (this.prevRearingAmount > 0.0F) {
  114.             float f3 = MathHelper.sin(this.renderYawOffset * ((float)Math.PI / 180F));
  115.             float f = MathHelper.cos(this.renderYawOffset * ((float)Math.PI / 180F));
  116.             float f1 = 0.7F * this.prevRearingAmount;
  117.             float f2 = 0.15F * this.prevRearingAmount;
  118.             passenger.setPosition(this.getPosX() + (double)(f1 * f3), this.getPosY() + this.getMountedYOffset() + passenger.getYOffset() + (double)f2, this.getPosZ() - (double)(f1 * f));
  119.             if (passenger instanceof LivingEntity) {
  120.                 ((LivingEntity)passenger).renderYawOffset = this.renderYawOffset;
  121.             }
  122.         }
  123.     }
  124.  
  125.     private void setHorseJumping(boolean jumping) {
  126.         this.horseJumping = jumping;
  127.     }
  128.  
  129.     private double getHorseJumpStrength() {
  130.         return this.getAttribute(JUMP_STRENGTH).getValue();
  131.     }
  132.  
  133.     private boolean isHorseJumping() {
  134.         return this.horseJumping;
  135.     }
  136.  
  137.     private boolean isRearing() {
  138.         return this.getHorseWatchableBoolean(32);
  139.     }
  140.  
  141.     private boolean getHorseWatchableBoolean(int p_110233_1_) {
  142.         return (this.dataManager.get(STATUS) & p_110233_1_) != 0;
  143.     }
  144. }
  145.  
RAW Paste Data