diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java index a293c8ef8..4b5ba6ef1 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java @@ -443,16 +443,6 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity, this.setRot(this.getYRot(), this.getXRot()); } - public static double calculateAngle(Vec3 passenger, Vec3 barrel) { - double startLength = passenger.length(); - double endLength = barrel.length(); - if (startLength > 0.0D && endLength > 0.0D) { - return Math.toDegrees(Math.acos(Mth.clamp(passenger.dot(barrel) / (startLength * endLength), -1, 1))); - } else { - return 0.0D; - } - } - protected void clampRotation(Entity entity) { float f = Mth.wrapDegrees(entity.getXRot()); float f1 = Mth.clamp(f, -45.0F, 5f + this.entityData.get(OFFSET_ANGLE)); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java index f3fdb2e16..30a0116e8 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java @@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.init.ModParticleTypes; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.item.ContainerBlockItem; import com.atsuishio.superbwarfare.tools.ParticleTool; +import com.atsuishio.superbwarfare.tools.VectorTool; import com.google.common.collect.Lists; import com.mojang.math.Axis; import net.minecraft.core.BlockPos; @@ -379,13 +380,7 @@ public class VehicleEntity extends Entity { move = move.multiply(1, 0, 1).normalize(); view = view.multiply(1, 0, 1).normalize(); - double startLength = move.length(); - double endLength = view.length(); - if (startLength > 0.0D && endLength > 0.0D) { - return Math.toDegrees(Math.acos(Mth.clamp(move.dot(view) / (startLength * endLength), -1, 1))); - } else { - return 0.0D; - } + return VectorTool.calculateAngle(move, view); } protected Vec3 getDismountOffset(double vehicleWidth, double passengerWidth) { diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/SeekTool.java b/src/main/java/com/atsuishio/superbwarfare/tools/SeekTool.java index 854ccc868..a1eb5b66d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/SeekTool.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/SeekTool.java @@ -5,7 +5,6 @@ import com.atsuishio.superbwarfare.entity.ClaymoreEntity; import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; import com.atsuishio.superbwarfare.entity.vehicle.MobileVehicleEntity; import net.minecraft.core.BlockPos; -import net.minecraft.util.Mth; import net.minecraft.world.entity.AreaEffectCloud; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.ExperienceOrb; @@ -95,16 +94,7 @@ public class SeekTool { private static double calculateAngle(Entity entityA, Entity entityB) { Vec3 start = new Vec3(entityA.getX() - entityB.getX(), entityA.getY() - entityB.getY(), entityA.getZ() - entityB.getZ()); Vec3 end = entityB.getLookAngle(); - return calculateAngle(start, end); + return VectorTool.calculateAngle(start, end); } - private static double calculateAngle(Vec3 start, Vec3 end) { - double startLength = start.length(); - double endLength = end.length(); - if (startLength > 0.0D && endLength > 0.0D) { - return Math.toDegrees(Math.acos(Mth.clamp(start.dot(end) / (startLength * endLength), -1, 1))); - } else { - return 0.0D; - } - } } diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/VectorTool.java b/src/main/java/com/atsuishio/superbwarfare/tools/VectorTool.java new file mode 100644 index 000000000..594061856 --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/tools/VectorTool.java @@ -0,0 +1,16 @@ +package com.atsuishio.superbwarfare.tools; + +import net.minecraft.util.Mth; +import net.minecraft.world.phys.Vec3; + +public class VectorTool { + public static double calculateAngle(Vec3 start, Vec3 end) { + double startLength = start.length(); + double endLength = end.length(); + if (startLength > 0.0D && endLength > 0.0D) { + return Math.toDegrees(Math.acos(Mth.clamp(start.dot(end) / (startLength * endLength), -1, 1))); + } else { + return 0.0D; + } + } +}