diff --git a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityAmphithere.java b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityAmphithere.java index a6d2d55413..dfcd160eb9 100644 --- a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityAmphithere.java +++ b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityAmphithere.java @@ -34,6 +34,7 @@ import net.minecraft.world.entity.*; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.ai.control.FlyingMoveControl; import net.minecraft.world.entity.ai.control.MoveControl; import net.minecraft.world.entity.ai.goal.*; import net.minecraft.world.entity.ai.goal.target.OwnerHurtByTargetGoal; @@ -47,6 +48,7 @@ import net.minecraft.world.level.block.LeavesBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.HitResult; +import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.NotNull; @@ -235,7 +237,6 @@ public float getWalkTargetValue(@NotNull BlockPos pos) { @Override protected void registerGoals() { - this.goalSelector.addGoal(0, new DragonAIRide<>(this)); this.goalSelector.addGoal(0, new SitWhenOrderedToGoal(this)); this.goalSelector.addGoal(1, new FloatGoal(this)); this.goalSelector.addGoal(1, new AmphithereAIAttackMelee(this, 1.0D, true)); @@ -266,7 +267,7 @@ protected void switchNavigator(int navigatorType) { this.navigation = new PathNavigateFlyingCreature(this, level()); this.navigatorType = 1; } else { - this.moveControl = new IafDragonFlightManager.PlayerFlightMoveHelper<>(this); + this.moveControl = new FlyingMoveControl(this, 20, false); this.navigation = new PathNavigateFlyingCreature(this, level()); this.navigatorType = 2; } @@ -422,9 +423,7 @@ public void aiStep() { } else if (!diving && diveProgress > 0.0F) { diveProgress -= 1F; } - if (this.isFlying()) { - this.setDeltaMovement(this.getDeltaMovement().x, this.getDeltaMovement().y + 0.08D, this.getDeltaMovement().z); - } + if (this.isFallen && this.flightBehavior != FlightBehavior.NONE) { this.flightBehavior = FlightBehavior.NONE; } @@ -580,6 +579,7 @@ public static AttributeSupplier.Builder bakeAttributes() { .add(Attributes.MOVEMENT_SPEED, 0.4D) //ATTACK .add(Attributes.ATTACK_DAMAGE, IafConfig.amphithereAttackStrength) + .add(Attributes.FLYING_SPEED, IafConfig.amphithereFlightSpeed) //FOLLOW RANGE .add(Attributes.FOLLOW_RANGE, 32.0D); } @@ -588,6 +588,7 @@ public static AttributeSupplier.Builder bakeAttributes() { public void setConfigurableAttributes() { this.getAttribute(Attributes.MAX_HEALTH).setBaseValue(IafConfig.amphithereMaxHealth); this.getAttribute(Attributes.ATTACK_DAMAGE).setBaseValue(IafConfig.amphithereAttackStrength); + this.getAttribute(Attributes.FLYING_SPEED).setBaseValue(IafConfig.amphithereFlightSpeed); } @Override @@ -746,11 +747,6 @@ public boolean doHurtTarget(@NotNull Entity entityIn) { return false; } - // FIXME :: Unused - public boolean isRidingPlayer(Player player) { - return getRidingPlayer() != null && player != null && getRidingPlayer().getUUID().equals(player.getUUID()); - } - @Override public @Nullable Player getRidingPlayer() { if (this.getControllingPassenger() instanceof Player player) { @@ -934,13 +930,63 @@ public boolean canPhaseThroughBlock(LevelAccessor world, BlockPos pos) { return world.getBlockState(pos).getBlock() instanceof LeavesBlock; } + // FIXME: I don't know what's is overriding the flight speed (I assume it's on the server side) + @Override + protected float getRiddenSpeed(@NotNull Player pPlayer) { + return (this.isFlying() || this.isHovering()) ? (float) this.getAttributeValue(Attributes.FLYING_SPEED) * 2F : (float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 0.5F; + } + @Override public void travel(@NotNull Vec3 travelVector) { - if (!this.canMove() && !this.isVehicle()) { - super.travel(travelVector.multiply(0, 1, 0)); - return; + if (this.isControlledByLocalInstance()) { + if (this.isInWater()) { + this.moveRelative(0.02F, travelVector); + this.move(MoverType.SELF, this.getDeltaMovement()); + this.setDeltaMovement(this.getDeltaMovement().scale(0.8F)); + } else if (this.isInLava()) { + this.moveRelative(0.02F, travelVector); + this.move(MoverType.SELF, this.getDeltaMovement()); + this.setDeltaMovement(this.getDeltaMovement().scale(0.5D)); + } else if (this.isFlying() || this.isHovering()) { + this.moveRelative(0.1F, travelVector); + this.move(MoverType.SELF, this.getDeltaMovement()); + this.setDeltaMovement(this.getDeltaMovement().scale(0.9D)); + } else { + super.travel(travelVector); + } + } else { + super.travel(travelVector); } - super.travel(travelVector); + } + + @Override + protected void tickRidden(@NotNull Player player, @NotNull Vec3 travelVector) { + super.tickRidden(player, travelVector); + Vec2 vec2 = this.getRiddenRotation(player); + this.setRot(vec2.y, vec2.x); + this.yRotO = this.yBodyRot = this.yHeadRot = this.getYRot(); + if (this.isControlledByLocalInstance()) { + Vec3 vec3 = this.getDeltaMovement(); + float vertical = this.isGoingUp() ? 0.2F : this.isGoingDown() ? -0.2F : 0F; + if (!this.isFlying() && !this.isHovering()) { + vertical = (float) travelVector.y; + } + this.setDeltaMovement(vec3.add(0, vertical, 0)); + } + } + + @Override + protected @NotNull Vec3 getRiddenInput(Player player, @NotNull Vec3 travelVector) { + float f = player.xxa * 0.5F; + float f1 = player.zza; + if (f1 <= 0.0F) { + f1 *= 0.25F; + } + + return new Vec3(f, 0.0D, f1); + } + protected Vec2 getRiddenRotation(LivingEntity entity) { + return new Vec2(entity.getXRot() * 0.5F, entity.getYRot()); } public boolean canMove() { diff --git a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityHippogryph.java b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityHippogryph.java index f3f39f431c..11de117295 100644 --- a/src/main/java/com/github/alexthe666/iceandfire/entity/EntityHippogryph.java +++ b/src/main/java/com/github/alexthe666/iceandfire/entity/EntityHippogryph.java @@ -763,6 +763,7 @@ protected void tickRidden(@NotNull Player player, @NotNull Vec3 travelVector) { } } + @Override protected @NotNull Vec3 getRiddenInput(Player player, @NotNull Vec3 travelVector) { float f = player.xxa * 0.5F; float f1 = player.zza; diff --git a/src/main/java/com/github/alexthe666/iceandfire/entity/ai/DragonAIRide.java b/src/main/java/com/github/alexthe666/iceandfire/entity/ai/DragonAIRide.java deleted file mode 100644 index 8600465967..0000000000 --- a/src/main/java/com/github/alexthe666/iceandfire/entity/ai/DragonAIRide.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.github.alexthe666.iceandfire.entity.ai; - -import com.github.alexthe666.iceandfire.entity.EntityDragonBase; -import com.github.alexthe666.iceandfire.entity.util.IFlyingMount; -import net.minecraft.world.entity.Mob; -import net.minecraft.world.entity.ai.goal.Goal; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.phys.Vec3; - -import java.util.EnumSet; - -public class DragonAIRide extends Goal { - - private final T dragon; - private Player player; - - public DragonAIRide(T dragon) { - this.dragon = dragon; - this.setFlags(EnumSet.of(Flag.MOVE)); - } - - @Override - public boolean canUse() { - player = dragon.getRidingPlayer(); - - return player != null; - } - - @Override - public void start() { - dragon.getNavigation().stop(); - } - - @Override - public void tick() { - dragon.getNavigation().stop(); - dragon.setTarget(null); - double x = dragon.getX(); - double y = dragon.getY(); - double z = dragon.getZ(); - double speed = 1.8F * dragon.getFlightSpeedModifier(); - Vec3 lookVec = player.getLookAngle(); - if (player.zza < 0) { - lookVec = lookVec.yRot((float) Math.PI); - } else if (player.xxa > 0) { - lookVec = lookVec.yRot((float) Math.PI * 0.5f); - } else if (player.xxa < 0) { - lookVec = lookVec.yRot((float) Math.PI * -0.5f); - } - if (Math.abs(player.xxa) > 0.0) { - speed *= 0.25D; - } - if (player.zza < 0.0) { - speed *= 0.15D; - } - if (dragon.isGoingUp()) { - lookVec = lookVec.add(0, 1, 0); - } else if (dragon.isGoingDown()) { - lookVec = lookVec.add(0, -1, 0); - } - if (player.xxa != 0 || player.zza != 0 || (dragon.fliesLikeElytra())) { - x += lookVec.x * 10; - z += lookVec.z * 10; - } - if ((dragon.isFlying() || hovering()) && (dragon.fliesLikeElytra() || dragon.isGoingUp() || dragon.isGoingDown())) { - y += lookVec.y * dragon.getYSpeedMod(); - } - if (dragon.fliesLikeElytra() && lookVec.y == -1 || !(dragon.isFlying() || hovering()) && !dragon.onGround()) { - y -= 1; - } - dragon.getMoveControl().setWantedPosition(x, y, z, speed); - } - - @Override - public boolean requiresUpdateEveryTick() { - return true; - } - - private boolean hovering() { - return dragon.isHovering() || dragon instanceof EntityDragonBase && ((EntityDragonBase) dragon).useFlyingPathFinder(); - } -} diff --git a/src/main/java/com/github/alexthe666/iceandfire/mixin/SuppressVehicleMovedWronglyMixin.java b/src/main/java/com/github/alexthe666/iceandfire/mixin/SuppressVehicleMovedWronglyMixin.java index 0695ec6172..41c1a65aaa 100644 --- a/src/main/java/com/github/alexthe666/iceandfire/mixin/SuppressVehicleMovedWronglyMixin.java +++ b/src/main/java/com/github/alexthe666/iceandfire/mixin/SuppressVehicleMovedWronglyMixin.java @@ -1,5 +1,6 @@ package com.github.alexthe666.iceandfire.mixin; +import com.github.alexthe666.iceandfire.entity.EntityAmphithere; import com.github.alexthe666.iceandfire.entity.EntityHippocampus; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; @@ -14,13 +15,17 @@ @Mixin(ServerGamePacketListenerImpl.class) public class SuppressVehicleMovedWronglyMixin { - @Shadow public ServerPlayer player; - @WrapOperation(method = "handleMoveVehicle(Lnet/minecraft/network/protocol/game/ServerboundMoveVehiclePacket;)V", at = @At( value = "INVOKE", target = "Lorg/slf4j/Logger;warn(Ljava/lang/String;[Ljava/lang/Object;)V", ordinal = 1, remap = false)) + @Shadow + public ServerPlayer player; + + @WrapOperation(method = "handleMoveVehicle(Lnet/minecraft/network/protocol/game/ServerboundMoveVehiclePacket;)V", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;warn(Ljava/lang/String;[Ljava/lang/Object;)V", ordinal = 1, remap = false)) private void iaf_lowerVehicleMovedWronglyLoggingLevel(Logger instance, String s, Object[] o, Operation original) { if (this.player.getRootVehicle() instanceof EntityHippocampus) { - instance.debug(s,o); + instance.debug(s, o); + } else if (this.player.getRootVehicle() instanceof EntityAmphithere) { + instance.debug(s, o); } else { - instance.warn(s,o); + instance.warn(s, o); } }