提取calculateAngle

This commit is contained in:
Light_Quanta 2025-01-26 10:17:39 +08:00
parent cd483aa9a9
commit 2e8852caf2
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
4 changed files with 19 additions and 28 deletions

View file

@ -443,16 +443,6 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity,
this.setRot(this.getYRot(), this.getXRot()); 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) { protected void clampRotation(Entity entity) {
float f = Mth.wrapDegrees(entity.getXRot()); float f = Mth.wrapDegrees(entity.getXRot());
float f1 = Mth.clamp(f, -45.0F, 5f + this.entityData.get(OFFSET_ANGLE)); float f1 = Mth.clamp(f, -45.0F, 5f + this.entityData.get(OFFSET_ANGLE));

View file

@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.init.ModParticleTypes;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.item.ContainerBlockItem; import com.atsuishio.superbwarfare.item.ContainerBlockItem;
import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.ParticleTool;
import com.atsuishio.superbwarfare.tools.VectorTool;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.mojang.math.Axis; import com.mojang.math.Axis;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -379,13 +380,7 @@ public class VehicleEntity extends Entity {
move = move.multiply(1, 0, 1).normalize(); move = move.multiply(1, 0, 1).normalize();
view = view.multiply(1, 0, 1).normalize(); view = view.multiply(1, 0, 1).normalize();
double startLength = move.length(); return VectorTool.calculateAngle(move, view);
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;
}
} }
protected Vec3 getDismountOffset(double vehicleWidth, double passengerWidth) { protected Vec3 getDismountOffset(double vehicleWidth, double passengerWidth) {

View file

@ -5,7 +5,6 @@ import com.atsuishio.superbwarfare.entity.ClaymoreEntity;
import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
import com.atsuishio.superbwarfare.entity.vehicle.MobileVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.MobileVehicleEntity;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.AreaEffectCloud; import net.minecraft.world.entity.AreaEffectCloud;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.ExperienceOrb; import net.minecraft.world.entity.ExperienceOrb;
@ -95,16 +94,7 @@ public class SeekTool {
private static double calculateAngle(Entity entityA, Entity entityB) { 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 start = new Vec3(entityA.getX() - entityB.getX(), entityA.getY() - entityB.getY(), entityA.getZ() - entityB.getZ());
Vec3 end = entityB.getLookAngle(); 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;
}
}
} }

View file

@ -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;
}
}
}