Skip to content

Commit

Permalink
Use Mth.degreesDifference
Browse files Browse the repository at this point in the history
  • Loading branch information
Edivad99 committed Sep 27, 2023
1 parent 674abe4 commit 9b25f2d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/main/java/mods/railcraft/charge/ChargeNetworkImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ public void startUsageRecording(int ticksToRecord, Consumer<Double> usageConsume

public boolean checkUsageRecordingCompletion() {
usageRecorder = usageRecorder.filter(UsageRecorder::run);
return !usageRecorder.isPresent();
return usageRecorder.isEmpty();
}

@Override
Expand Down
16 changes: 1 addition & 15 deletions src/main/java/mods/railcraft/util/MathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@

public final class MathUtil {

public static float getDistanceBetweenAngles(float angle1, float angle2) {
angle1 = normalizeAngle(angle1);
angle2 = normalizeAngle(angle2);
return normalizeAngle(angle1 - angle2);
}

public static float normalizeAngle(float angle) {
while (angle < -180F)
angle += 360F;
while (angle > 180F)
angle -= 360F;
return angle;
}

public static boolean nearZero(double f) {
return Math.abs(f) < 0.001;
}
Expand All @@ -28,7 +14,7 @@ public static BlockPos centroid(Collection<? extends Vec3i> points) {
double x = 0;
double y = 0;
double z = 0;
for (Vec3i pos : points) {
for (var pos : points) {
x += pos.getX();
y += pos.getY();
z += pos.getZ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import mods.railcraft.api.carts.Train;
import mods.railcraft.api.core.RailcraftConstants;
import mods.railcraft.api.event.CartLinkEvent;
import mods.railcraft.util.MathUtil;
import mods.railcraft.world.entity.vehicle.locomotive.Locomotive;
import mods.railcraft.world.level.block.track.ElevatorTrackBlock;
import mods.railcraft.world.level.block.track.behaivor.HighSpeedTrackUtil;
Expand All @@ -24,6 +23,7 @@
import net.minecraft.nbt.Tag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.level.block.BaseRailBlock;
Expand Down Expand Up @@ -506,8 +506,7 @@ public void tick() {
}

// Fix flip
var distance =
MathUtil.getDistanceBetweenAngles(this.minecart.getYRot(), this.minecart.yRotO);
var distance = Mth.degreesDifference(this.minecart.getYRot(), this.minecart.yRotO);
var cutoff = 120F;
if (distance < -cutoff || distance >= cutoff) {
this.minecart.setYRot(this.minecart.getYRot() + 180.0F);
Expand Down

0 comments on commit 9b25f2d

Please sign in to comment.