Flywheel/src/main/java/com/jozufozu/flywheel/util/AngleHelper.java

55 lines
1.4 KiB
Java
Raw Normal View History

2021-06-16 20:19:33 +02:00
package com.jozufozu.flywheel.util;
import net.minecraft.util.Direction;
import net.minecraft.util.Direction.Axis;
public class AngleHelper {
/**
* Legacy method. See {@link #horizontalAngleNew(Direction)} for new method.
*/
public static float horizontalAngle(Direction facing) {
2021-07-15 20:36:24 +02:00
float angle = facing.toYRot();
if (facing.getAxis() == Axis.X) angle = -angle;
return angle;
}
/**
* Same as {@link #horizontalAngle(Direction)}, but returns 0 instead of -90 for vertical directions.
*/
public static float horizontalAngleNew(Direction facing) {
if (facing.getAxis()
.isVertical()) {
return 0;
}
2021-07-15 20:36:24 +02:00
float angle = facing.toYRot();
if (facing.getAxis() == Axis.X) angle = -angle;
return angle;
}
public static float verticalAngle(Direction facing) {
return facing == Direction.UP ? -90 : facing == Direction.DOWN ? 90 : 0;
}
public static float rad(double angle) {
if (angle == 0) return 0;
return (float) (angle / 180 * Math.PI);
}
public static float deg(double angle) {
if (angle == 0) return 0;
return (float) (angle * 180 / Math.PI);
}
Fundamentals of Fluid Transfer - Fixed some inconsistencies with a tanks' fluidhandler invalidation when resized - Patched crashes in present fluid handling of the basin - Tanks now slightly shade horizontal faces of the contained liquid - Tanks no longer resend data every tick when filled gradually - Introduced a new lerped value type with better design decisions - Refactored Smart tileentity serialization to better support custom overrides in contained behaviours - Pumps propagate flows in the pipe networks in front and behind itself. - Pumps collect all possible in and outputs across the reachable pipe graph as endpoints - Flows move across multiple branches of a pipe network when both are equally viable - Open-ended pipes are treated as endpoints and leak fluid into and out of a block space - Open endpoints serialize stateful information about fluid units gathered and held at the interface - Open endpoints turn a fluid block into 1000 fluid units and back - Open endpoints undo their transaction when their flow changes from pull to push - Open endpoints cannot pull fluids back when a full liquid block was not placed yet - Open endpoints waterlog blocks when the provided fluid is water - A collision response is triggered when different types of fluids meet at open endpoints - Fluids are transferred instantly by the throughput of a completed flow per tick - Pumps cut flows when vital pipes are removed - Pumps do not lose progress of finished flows when an unrelated part of the pipe network changes - Pumps do not lose progress of finished flows when reversed - Pumps distribute their throughput across available input flows evenly - Pumps distribute gathered input fluid across outputs evenly - Pumps expose furthest reachable pipefaces to other pumps for chained transfer - Chained pumps with fully overlapping flow sections provide their endpoints at the entrance of the other pump - Chained pumps with overlapping flow sections participate in two shared endpoints, one for each pump dominating the contested region - Chained pumps with overlapping flow only transfer via the optimal of the two possible endpoints based on their speeds - Chained pumps of equal speed pick one of the two available endpoints deterministically - Pumps transfer without flows when no pipe is between the pump and the endpoint - Pumps serialize and recover stateful information about held fluid units at open endpoints - Chained pumps do not actively transfer when both are partaking with push flows (or both pulling) - A pull flow originating from an inter-pump endpoint only commences when the corresponding push flow is completed - Chained pumps re-determine the optimal flow when the speed of one is changed at runtime - Throughput of chained pumps is determined by their weakest link in terms of speed - Endpoints created for chained pumps is treated equally to other available endpoints when fluid is distributed - Pipes do not contain a physical amount of fluid. - Pipes never hold serialized vital stateful information about fluid transfer. - Pipes synchronize local flow progress and fluid type to clients - Flows in a pipe progress with the speed of the network flow - A networks flow speed depends on the speed of the aggregated pump - Pipe flows of different flow graphs of different pumps interact with each other - A collision response is triggered when two different types of fluid meet within a pipe - Pipes spawn particles to illustrate contained flows/liquids of flows - The fluid transfer role is exposed through a TE behaviour with some callbacks and properties - Open endpoints show particles when interacting with in-world fluids
2020-08-24 21:02:03 +02:00
public static float angleLerp(double pct, double current, double target) {
return (float) (current + getShortestAngleDiff(current, target) * pct);
}
public static float getShortestAngleDiff(double current, double target) {
current = current % 360;
target = target % 360;
return (float) (((((target - current) % 360) + 540) % 360) - 180);
}
}