mirror of
https://github.com/FalsePattern/FalsePatternLib.git
synced 2026-11-16 22:15:11 +00:00
code cleanup
This commit is contained in:
76 files changed
+691
-622
No files matched your search
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* Copyright (C) 2022 FalsePattern
|
||||
* All Rights Reserved
|
||||
*
|
||||
@@ -23,20 +23,22 @@ package com.falsepattern.lib.compat;
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
import com.falsepattern.lib.util.MathUtil;
|
||||
import com.google.common.collect.AbstractIterator;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
import lombok.val;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.Vec3;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static net.minecraft.util.EnumFacing.DOWN;
|
||||
import static net.minecraft.util.EnumFacing.EAST;
|
||||
@@ -105,12 +107,9 @@ public class BlockPos extends Vec3i {
|
||||
* @see #getAllInBoxMutable(BlockPos, BlockPos)
|
||||
*/
|
||||
public static Iterable<BlockPos> getAllInBox(@NonNull BlockPos from, @NonNull BlockPos to) {
|
||||
return getAllInBox(Math.min(from.getX(), to.getX()),
|
||||
Math.min(from.getY(), to.getY()),
|
||||
Math.min(from.getZ(), to.getZ()),
|
||||
Math.max(from.getX(), to.getX()),
|
||||
Math.max(from.getY(), to.getY()),
|
||||
Math.max(from.getZ(), to.getZ()));
|
||||
return getAllInBox(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()),
|
||||
Math.min(from.getZ(), to.getZ()), Math.max(from.getX(), to.getX()),
|
||||
Math.max(from.getY(), to.getY()), Math.max(from.getZ(), to.getZ()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,12 +129,7 @@ public class BlockPos extends Vec3i {
|
||||
* @see #getAllInBox(BlockPos, BlockPos)
|
||||
* @see #getAllInBoxMutable(BlockPos, BlockPos)
|
||||
*/
|
||||
public static Iterable<BlockPos> getAllInBox(final int x0,
|
||||
final int y0,
|
||||
final int z0,
|
||||
final int x1,
|
||||
final int y1,
|
||||
final int z1) {
|
||||
public static Iterable<BlockPos> getAllInBox(final int x0, final int y0, final int z0, final int x1, final int y1, final int z1) {
|
||||
return () -> new AbstractIterator<BlockPos>() {
|
||||
private boolean first = true;
|
||||
private int lastX;
|
||||
@@ -186,12 +180,9 @@ public class BlockPos extends Vec3i {
|
||||
* @see #getAllInBoxMutable(BlockPos, BlockPos)
|
||||
*/
|
||||
public static Iterable<BlockPos.MutableBlockPos> getAllInBoxMutable(@NonNull BlockPos from, @NonNull BlockPos to) {
|
||||
return getAllInBoxMutable(Math.min(from.getX(), to.getX()),
|
||||
Math.min(from.getY(), to.getY()),
|
||||
Math.min(from.getZ(), to.getZ()),
|
||||
Math.max(from.getX(), to.getX()),
|
||||
Math.max(from.getY(), to.getY()),
|
||||
Math.max(from.getZ(), to.getZ()));
|
||||
return getAllInBoxMutable(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()),
|
||||
Math.min(from.getZ(), to.getZ()), Math.max(from.getX(), to.getX()),
|
||||
Math.max(from.getY(), to.getY()), Math.max(from.getZ(), to.getZ()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -214,12 +205,7 @@ public class BlockPos extends Vec3i {
|
||||
* @see #getAllInBox(int, int, int, int, int, int)
|
||||
* @see #getAllInBoxMutable(BlockPos, BlockPos)
|
||||
*/
|
||||
public static Iterable<BlockPos.MutableBlockPos> getAllInBoxMutable(final int x0,
|
||||
final int y0,
|
||||
final int z0,
|
||||
final int x1,
|
||||
final int y1,
|
||||
final int z1) {
|
||||
public static Iterable<BlockPos.MutableBlockPos> getAllInBoxMutable(final int x0, final int y0, final int z0, final int x1, final int y1, final int z1) {
|
||||
return () -> new AbstractIterator<MutableBlockPos>() {
|
||||
private MutableBlockPos pos;
|
||||
|
||||
@@ -297,8 +283,7 @@ public class BlockPos extends Vec3i {
|
||||
if (blocks == 0) {
|
||||
return this;
|
||||
}
|
||||
return new BlockPos(x + facing.getFrontOffsetX() * blocks,
|
||||
y + facing.getFrontOffsetY() * blocks,
|
||||
return new BlockPos(x + facing.getFrontOffsetX() * blocks, y + facing.getFrontOffsetY() * blocks,
|
||||
z + facing.getFrontOffsetZ() * blocks);
|
||||
}
|
||||
|
||||
@@ -362,8 +347,7 @@ public class BlockPos extends Vec3i {
|
||||
|
||||
@Override
|
||||
public BlockPos crossProduct(@NonNull Vec3i vec) {
|
||||
return new BlockPos(y * vec.getZ() - z * vec.getY(),
|
||||
z * vec.getX() - x * vec.getZ(),
|
||||
return new BlockPos(y * vec.getZ() - z * vec.getY(), z * vec.getX() - x * vec.getZ(),
|
||||
x * vec.getY() - y * vec.getX());
|
||||
}
|
||||
|
||||
@@ -451,8 +435,7 @@ public class BlockPos extends Vec3i {
|
||||
}
|
||||
|
||||
public BlockPos.MutableBlockPos move(@NonNull EnumFacing facing, int blocks) {
|
||||
return this.setPos(x + facing.getFrontOffsetX() * blocks,
|
||||
y + facing.getFrontOffsetY() * blocks,
|
||||
return this.setPos(x + facing.getFrontOffsetX() * blocks, y + facing.getFrontOffsetY() * blocks,
|
||||
z + facing.getFrontOffsetZ() * blocks);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* Copyright (C) 2022 FalsePattern
|
||||
* All Rights Reserved
|
||||
*
|
||||
@@ -21,13 +21,15 @@
|
||||
package com.falsepattern.lib.compat;
|
||||
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NonNull;
|
||||
import lombok.val;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
* A functional equivalent to ChunkPos present in Minecraft 1.12.
|
||||
*/
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* Copyright (C) 2022 FalsePattern
|
||||
* All Rights Reserved
|
||||
*
|
||||
@@ -21,19 +21,21 @@
|
||||
package com.falsepattern.lib.compat;
|
||||
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.NonNull;
|
||||
import lombok.val;
|
||||
import lombok.var;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A functional equivalent to GuiLabel present in Minecraft 1.12.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* Copyright (C) 2022 FalsePattern
|
||||
* All Rights Reserved
|
||||
*
|
||||
@@ -169,7 +169,7 @@ public class MathHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Buckets an integer with specifed bucket sizes. Args: i, bucketSize
|
||||
* Buckets an integer with specified bucket sizes. Args: i, bucketSize
|
||||
*/
|
||||
public static int bucketInt(int i, int bucketSize) {
|
||||
return i < 0 ? -((-i - 1) / bucketSize) - 1 : i / bucketSize;
|
||||
@@ -196,11 +196,8 @@ public class MathHelper {
|
||||
|
||||
public static double average(long[] values) {
|
||||
long i = 0L;
|
||||
long[] along1 = values;
|
||||
int j = values.length;
|
||||
|
||||
for (int k = 0; k < j; ++k) {
|
||||
long l = along1[k];
|
||||
for (long l : values) {
|
||||
i += l;
|
||||
}
|
||||
|
||||
@@ -245,25 +242,23 @@ public class MathHelper {
|
||||
* parses the string as integer or returns the second parameter if it fails
|
||||
*/
|
||||
public static int parseIntWithDefault(String str, int def) {
|
||||
int j = def;
|
||||
|
||||
try {
|
||||
j = Integer.parseInt(str);
|
||||
return Integer.parseInt(str);
|
||||
} catch (Throwable throwable) {
|
||||
return def;
|
||||
}
|
||||
|
||||
return j;
|
||||
}
|
||||
|
||||
/**
|
||||
* parses the string as integer or returns the second parameter if it fails. this value is capped to par2
|
||||
*/
|
||||
public static int parseIntWithDefaultAndMax(String str, int def, int min) {
|
||||
int k = def;
|
||||
int k;
|
||||
|
||||
try {
|
||||
k = Integer.parseInt(str);
|
||||
} catch (Throwable throwable) {
|
||||
k = def;
|
||||
}
|
||||
|
||||
if (k < min) {
|
||||
@@ -288,11 +283,12 @@ public class MathHelper {
|
||||
}
|
||||
|
||||
public static double parseDoubleWithDefaultAndMin(String str, double def, double min) {
|
||||
double d2 = def;
|
||||
double d2;
|
||||
|
||||
try {
|
||||
d2 = Double.parseDouble(str);
|
||||
} catch (Throwable throwable) {
|
||||
d2 = def;
|
||||
}
|
||||
|
||||
if (d2 < min) {
|
||||
@@ -337,7 +333,7 @@ public class MathHelper {
|
||||
* highest bit that is set. For example, if the number in binary is 0...100101, this will return 5.
|
||||
*/
|
||||
public static int calculateLogBaseTwo(int a) {
|
||||
/**
|
||||
/*
|
||||
* Uses a B(2, 5) De Bruijn sequence and a lookup table to efficiently calculate the log-base-two of the given
|
||||
* value. Optimized for cases where the input value is a power-of-two. If the input value is not a power-of-
|
||||
* two, then subtract 1 from the return value.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* Copyright (C) 2022 FalsePattern
|
||||
* All Rights Reserved
|
||||
*
|
||||
@@ -22,6 +22,8 @@ package com.falsepattern.lib.compat;
|
||||
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
import lombok.NonNull;
|
||||
import lombok.val;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
@StableAPI(since = "0.6.0")
|
||||
@@ -32,43 +34,8 @@ public enum Rotation {
|
||||
COUNTERCLOCKWISE_90;
|
||||
|
||||
public Rotation add(@NonNull Rotation rotation) {
|
||||
switch (rotation) {
|
||||
case CLOCKWISE_180:
|
||||
switch (this) {
|
||||
case NONE:
|
||||
return CLOCKWISE_180;
|
||||
case CLOCKWISE_90:
|
||||
return COUNTERCLOCKWISE_90;
|
||||
case CLOCKWISE_180:
|
||||
return NONE;
|
||||
case COUNTERCLOCKWISE_90:
|
||||
return CLOCKWISE_90;
|
||||
}
|
||||
case COUNTERCLOCKWISE_90:
|
||||
switch (this) {
|
||||
case NONE:
|
||||
return COUNTERCLOCKWISE_90;
|
||||
case CLOCKWISE_90:
|
||||
return NONE;
|
||||
case CLOCKWISE_180:
|
||||
return CLOCKWISE_90;
|
||||
case COUNTERCLOCKWISE_90:
|
||||
return CLOCKWISE_180;
|
||||
}
|
||||
case CLOCKWISE_90:
|
||||
switch (this) {
|
||||
case NONE:
|
||||
return CLOCKWISE_90;
|
||||
case CLOCKWISE_90:
|
||||
return CLOCKWISE_180;
|
||||
case CLOCKWISE_180:
|
||||
return COUNTERCLOCKWISE_90;
|
||||
case COUNTERCLOCKWISE_90:
|
||||
return NONE;
|
||||
}
|
||||
default:
|
||||
return this;
|
||||
}
|
||||
val values = Rotation.values();
|
||||
return values[(ordinal() + rotation.ordinal()) % values.length];
|
||||
}
|
||||
|
||||
public EnumFacing rotate(@NonNull EnumFacing facing) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* Copyright (C) 2022 FalsePattern
|
||||
* All Rights Reserved
|
||||
*
|
||||
@@ -21,8 +21,6 @@
|
||||
package com.falsepattern.lib.compat;
|
||||
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import com.falsepattern.lib.util.MathUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -30,6 +28,8 @@ import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.val;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
* A functional equivalent to Vec3i present in Minecraft 1.12.
|
||||
*/
|
||||
@@ -71,8 +71,7 @@ public class Vec3i implements Comparable<Vec3i> {
|
||||
* @return the new resulting vector
|
||||
*/
|
||||
public Vec3i crossProduct(@NonNull Vec3i vec) {
|
||||
return new Vec3i(y * vec.getZ() - z * vec.getY(),
|
||||
z * vec.getX() - x * vec.getZ(),
|
||||
return new Vec3i(y * vec.getZ() - z * vec.getY(), z * vec.getX() - x * vec.getZ(),
|
||||
x * vec.getY() - y * vec.getX());
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user