Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.srinjoy.saddlemod;
- import net.minecraft.entity.*;
- import net.minecraft.entity.ai.attributes.IAttribute;
- import net.minecraft.entity.ai.attributes.RangedAttribute;
- import net.minecraft.entity.player.PlayerEntity;
- import net.minecraft.network.datasync.DataParameter;
- import net.minecraft.network.datasync.DataSerializers;
- import net.minecraft.network.datasync.EntityDataManager;
- import net.minecraft.potion.Effects;
- import net.minecraft.util.math.MathHelper;
- import net.minecraft.util.math.Vec3d;
- import net.minecraft.world.World;
- import javax.annotation.Nonnull;
- import java.util.Objects;
- public class CustomEntity extends CreatureEntity {
- private float jumpPower;
- private boolean allowStandSliding;
- private static final DataParameter<Byte> STATUS = EntityDataManager.createKey(CustomEntity.class, DataSerializers.BYTE);
- protected static final IAttribute JUMP_STRENGTH = (new RangedAttribute((IAttribute)null, "horse.jumpStrength", 0.7D, 0.0D, 2.0D)).setDescription("Jump Strength").setShouldWatch(true);
- private boolean horseJumping;
- private float prevRearingAmount;
- protected CustomEntity(EntityType<? extends CreatureEntity> type, World worldIn) {
- super(type, worldIn);
- }
- @Override
- public boolean canBeSteered() {
- return true;
- }
- @Override
- public void travel(@Nonnull Vec3d p_213352_1_) {
- if (this.isAlive()){
- if (this.isBeingRidden() && this.canBeSteered()){
- LivingEntity entity = (LivingEntity) this.getControllingPassenger();
- this.rotationYaw = entity.rotationYaw;
- this.prevRotationYaw = this.rotationYaw;
- this.rotationPitch = entity.rotationPitch * 0.5F;
- this.setRotation(this.rotationYaw, this.rotationPitch);
- this.renderYawOffset = this.rotationYaw;
- this.rotationYawHead = this.renderYawOffset;
- float f = entity.moveStrafing * 0.5F;
- float f1 = entity.moveForward;
- if (f1 <= 0.0F) f1 *= 0.25F;
- if (this.onGround && this.jumpPower == 0.0F && this.isRearing() && !this.allowStandSliding) {
- f = 0.0F;
- f1 = 0.0F;
- }
- if (this.jumpPower > 0.0F && !this.isHorseJumping() && this.onGround) {
- double d0 = this.getHorseJumpStrength() * (double)this.jumpPower * (double)this.getJumpFactor();
- double d1;
- if (this.isPotionActive(Effects.JUMP_BOOST)) {
- d1 = d0 + (double)((float)(Objects.requireNonNull(this.getActivePotionEffect(Effects.JUMP_BOOST)).getAmplifier() + 1) * 0.1F);
- } else {
- d1 = d0;
- }
- Vec3d vec3d = this.getMotion();
- this.setMotion(vec3d.x, d1, vec3d.z);
- this.setHorseJumping(true);
- this.isAirBorne = true;
- if (f1 > 0.0F) {
- float f2 = MathHelper.sin(this.rotationYaw * ((float)Math.PI / 180F));
- float f3 = MathHelper.cos(this.rotationYaw * ((float)Math.PI / 180F));
- this.setMotion(this.getMotion().add((double)(-0.4F * f2 * this.jumpPower), 0.0D, (double)(0.4F * f3 * this.jumpPower)));
- }
- this.jumpPower = 0.0F;
- }
- this.jumpMovementFactor = this.getAIMoveSpeed() * 0.1F;
- if (this.canPassengerSteer()) {
- this.setAIMoveSpeed((float)this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getValue());
- super.travel(new Vec3d((double)f, p_213352_1_.y, (double)f1));
- } else if (entity instanceof PlayerEntity) {
- this.setMotion(Vec3d.ZERO);
- }
- if (this.onGround) {
- this.jumpPower = 0.0F;
- this.setHorseJumping(false);
- }
- this.prevLimbSwingAmount = this.limbSwingAmount;
- double d2 = this.getPosX() - this.prevPosX;
- double d3 = this.getPosZ() - this.prevPosZ;
- float f4 = MathHelper.sqrt(d2 * d2 + d3 * d3) * 4.0F;
- if (f4 > 1.0F) {
- f4 = 1.0F;
- }
- this.limbSwingAmount += (f4 - this.limbSwingAmount) * 0.4F;
- this.limbSwing += this.limbSwingAmount;
- } else {
- this.jumpMovementFactor = 0.02F;
- super.travel(p_213352_1_);
- }
- }
- }
- @Override
- public void updatePassenger(@Nonnull Entity passenger) {
- super.updatePassenger(passenger);
- if (passenger instanceof MobEntity) {
- MobEntity mobentity = (MobEntity)passenger;
- this.renderYawOffset = mobentity.renderYawOffset;
- }
- if (this.prevRearingAmount > 0.0F) {
- float f3 = MathHelper.sin(this.renderYawOffset * ((float)Math.PI / 180F));
- float f = MathHelper.cos(this.renderYawOffset * ((float)Math.PI / 180F));
- float f1 = 0.7F * this.prevRearingAmount;
- float f2 = 0.15F * this.prevRearingAmount;
- passenger.setPosition(this.getPosX() + (double)(f1 * f3), this.getPosY() + this.getMountedYOffset() + passenger.getYOffset() + (double)f2, this.getPosZ() - (double)(f1 * f));
- if (passenger instanceof LivingEntity) {
- ((LivingEntity)passenger).renderYawOffset = this.renderYawOffset;
- }
- }
- }
- private void setHorseJumping(boolean jumping) {
- this.horseJumping = jumping;
- }
- private double getHorseJumpStrength() {
- return this.getAttribute(JUMP_STRENGTH).getValue();
- }
- private boolean isHorseJumping() {
- return this.horseJumping;
- }
- private boolean isRearing() {
- return this.getHorseWatchableBoolean(32);
- }
- private boolean getHorseWatchableBoolean(int p_110233_1_) {
- return (this.dataManager.get(STATUS) & p_110233_1_) != 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement