Tree changes
This commit is contained in:
parent
683235ebe9
commit
c9346da1ee
4 changed files with 324 additions and 165 deletions
|
@ -1,119 +1,123 @@
|
|||
package ru.betterend.util;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class MHelper {
|
||||
public static final float PI2 = (float) (Math.PI * 2);
|
||||
private static final int ALPHA = 255 << 24;
|
||||
public static final Random RANDOM = new Random();
|
||||
|
||||
public static int color(int r, int g, int b) {
|
||||
return ALPHA | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
public static int randRange(int min, int max, Random random) {
|
||||
return min + random.nextInt(max - min + 1);
|
||||
}
|
||||
|
||||
public static double randRange(double min, double max, Random random) {
|
||||
return min + random.nextDouble() * (max - min);
|
||||
}
|
||||
|
||||
public static float randRange(float min, float max, Random random) {
|
||||
return min + random.nextFloat() * (max - min);
|
||||
}
|
||||
|
||||
public static byte setBit(byte source, int pos, boolean value) {
|
||||
return value ? setBitTrue(source, pos) : setBitFalse(source, pos);
|
||||
}
|
||||
|
||||
public static byte setBitTrue(byte source, int pos) {
|
||||
source |= 1 << pos;
|
||||
return source;
|
||||
}
|
||||
|
||||
public static byte setBitFalse(byte source, int pos) {
|
||||
source &= ~(1 << pos);
|
||||
return source;
|
||||
}
|
||||
|
||||
public static boolean getBit(byte source, int pos) {
|
||||
return ((source >> pos) & 1) == 1;
|
||||
}
|
||||
|
||||
public static int floor(float x) {
|
||||
return x < 0 ? (int) (x - 1) : (int) x;
|
||||
}
|
||||
|
||||
public static float wrap(float x, float side) {
|
||||
return x - floor(x / side) * side;
|
||||
}
|
||||
|
||||
public static int floor(double x) {
|
||||
return x < 0 ? (int) (x - 1) : (int) x;
|
||||
}
|
||||
|
||||
public static int min(int a, int b) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
public static int max(int a, int b) {
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
public static float min(float a, float b) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
public static float max(float a, float b) {
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
public static float lengthSqr(float x, float y, float z) {
|
||||
return x * x + y * y + z * z;
|
||||
}
|
||||
|
||||
public static double lengthSqr(double x, double y, double z) {
|
||||
return x * x + y * y + z * z;
|
||||
}
|
||||
|
||||
public static float length(float x, float y, float z) {
|
||||
return (float) Math.sqrt(lengthSqr(x, y, z));
|
||||
}
|
||||
|
||||
public static float lengthSqr(float x, float y) {
|
||||
return x * x + y * y;
|
||||
}
|
||||
|
||||
public static double lengthSqr(double x, double y) {
|
||||
return x * x + y * y;
|
||||
}
|
||||
|
||||
public static float length(float x, float y) {
|
||||
return (float) Math.sqrt(lengthSqr(x, y));
|
||||
}
|
||||
|
||||
public static double length(double x, double y) {
|
||||
return Math.sqrt(lengthSqr(x, y));
|
||||
}
|
||||
|
||||
public static float dot(float x1, float y1, float z1, float x2, float y2, float z2) {
|
||||
return x1 * x2 + y1 * y2 + z1 * z2;
|
||||
}
|
||||
|
||||
public static float dot(float x1, float y1, float x2, float y2) {
|
||||
return x1 * x2 + y1 * y2;
|
||||
}
|
||||
|
||||
public static int getSeed(int seed, int x, int y) {
|
||||
int h = seed + x * 374761393 + y * 668265263;
|
||||
h = (h ^ (h >> 13)) * 1274126177;
|
||||
return h ^ (h >> 16);
|
||||
}
|
||||
|
||||
public static int getSeed(int seed, int x, int y, int z) {
|
||||
int h = seed + x * 374761393 + y * 668265263 + z;
|
||||
h = (h ^ (h >> 13)) * 1274126177;
|
||||
return h ^ (h >> 16);
|
||||
}
|
||||
}
|
||||
package ru.betterend.util;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class MHelper {
|
||||
public static final float PI2 = (float) (Math.PI * 2);
|
||||
private static final int ALPHA = 255 << 24;
|
||||
public static final Random RANDOM = new Random();
|
||||
|
||||
public static int color(int r, int g, int b) {
|
||||
return ALPHA | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
public static int randRange(int min, int max, Random random) {
|
||||
return min + random.nextInt(max - min + 1);
|
||||
}
|
||||
|
||||
public static double randRange(double min, double max, Random random) {
|
||||
return min + random.nextDouble() * (max - min);
|
||||
}
|
||||
|
||||
public static float randRange(float min, float max, Random random) {
|
||||
return min + random.nextFloat() * (max - min);
|
||||
}
|
||||
|
||||
public static byte setBit(byte source, int pos, boolean value) {
|
||||
return value ? setBitTrue(source, pos) : setBitFalse(source, pos);
|
||||
}
|
||||
|
||||
public static byte setBitTrue(byte source, int pos) {
|
||||
source |= 1 << pos;
|
||||
return source;
|
||||
}
|
||||
|
||||
public static byte setBitFalse(byte source, int pos) {
|
||||
source &= ~(1 << pos);
|
||||
return source;
|
||||
}
|
||||
|
||||
public static boolean getBit(byte source, int pos) {
|
||||
return ((source >> pos) & 1) == 1;
|
||||
}
|
||||
|
||||
public static int floor(float x) {
|
||||
return x < 0 ? (int) (x - 1) : (int) x;
|
||||
}
|
||||
|
||||
public static float wrap(float x, float side) {
|
||||
return x - floor(x / side) * side;
|
||||
}
|
||||
|
||||
public static int floor(double x) {
|
||||
return x < 0 ? (int) (x - 1) : (int) x;
|
||||
}
|
||||
|
||||
public static int min(int a, int b) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
public static int max(int a, int b) {
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
public static float min(float a, float b) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
public static float max(float a, float b) {
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
public static float max(float a, float b, float c) {
|
||||
return max(a, max(b, c));
|
||||
}
|
||||
|
||||
public static float lengthSqr(float x, float y, float z) {
|
||||
return x * x + y * y + z * z;
|
||||
}
|
||||
|
||||
public static double lengthSqr(double x, double y, double z) {
|
||||
return x * x + y * y + z * z;
|
||||
}
|
||||
|
||||
public static float length(float x, float y, float z) {
|
||||
return (float) Math.sqrt(lengthSqr(x, y, z));
|
||||
}
|
||||
|
||||
public static float lengthSqr(float x, float y) {
|
||||
return x * x + y * y;
|
||||
}
|
||||
|
||||
public static double lengthSqr(double x, double y) {
|
||||
return x * x + y * y;
|
||||
}
|
||||
|
||||
public static float length(float x, float y) {
|
||||
return (float) Math.sqrt(lengthSqr(x, y));
|
||||
}
|
||||
|
||||
public static double length(double x, double y) {
|
||||
return Math.sqrt(lengthSqr(x, y));
|
||||
}
|
||||
|
||||
public static float dot(float x1, float y1, float z1, float x2, float y2, float z2) {
|
||||
return x1 * x2 + y1 * y2 + z1 * z2;
|
||||
}
|
||||
|
||||
public static float dot(float x1, float y1, float x2, float y2) {
|
||||
return x1 * x2 + y1 * y2;
|
||||
}
|
||||
|
||||
public static int getSeed(int seed, int x, int y) {
|
||||
int h = seed + x * 374761393 + y * 668265263;
|
||||
h = (h ^ (h >> 13)) * 1274126177;
|
||||
return h ^ (h >> 16);
|
||||
}
|
||||
|
||||
public static int getSeed(int seed, int x, int y, int z) {
|
||||
int h = seed + x * 374761393 + y * 668265263 + z;
|
||||
h = (h ^ (h >> 13)) * 1274126177;
|
||||
return h ^ (h >> 16);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,9 @@ import com.google.common.collect.Lists;
|
|||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos.Mutable;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import ru.betterend.util.sdf.SDF;
|
||||
import ru.betterend.util.sdf.operator.SDFUnion;
|
||||
import ru.betterend.util.sdf.primitive.SDFLine;
|
||||
|
@ -41,12 +43,13 @@ public class SplineHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public static void parableOffset(List<Vector3f> spline, float distance) {
|
||||
public static void powerOffset(List<Vector3f> spline, float distance, float power) {
|
||||
int count = spline.size();
|
||||
float max = count + 1;
|
||||
for (int i = 1; i < count; i++) {
|
||||
Vector3f pos = spline.get(i);
|
||||
float x = (float) i / (float) (count + 1);
|
||||
float y = pos.getY() + x * x * distance;
|
||||
float x = (float) i / max;
|
||||
float y = pos.getY() + (float) Math.pow(x, power) * distance;
|
||||
pos.set(pos.getX(), y, pos.getZ());
|
||||
}
|
||||
}
|
||||
|
@ -69,4 +72,67 @@ public class SplineHelper {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean fillSpline(List<Vector3f> spline, StructureWorldAccess world, BlockState state, BlockPos pos, Function<BlockState, Boolean> replace) {
|
||||
Vector3f startPos = spline.get(0);
|
||||
for (int i = 1; i < spline.size(); i++) {
|
||||
Vector3f endPos = spline.get(i);
|
||||
if (!(fillLine(startPos, endPos, world, state, pos, replace))) {
|
||||
return false;
|
||||
}
|
||||
startPos = endPos;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean fillLine(Vector3f start, Vector3f end, StructureWorldAccess world, BlockState state, BlockPos pos, Function<BlockState, Boolean> replace) {
|
||||
float dx = end.getX() - start.getX();
|
||||
float dy = end.getY() - start.getY();
|
||||
float dz = end.getZ() - start.getZ();
|
||||
float max = MHelper.max(Math.abs(dx), Math.abs(dy), Math.abs(dz));
|
||||
int count = MHelper.floor(max + 1);
|
||||
dx /= max;
|
||||
dy /= max;
|
||||
dz /= max;
|
||||
float x = start.getX();
|
||||
float y = start.getY();
|
||||
float z = start.getZ();
|
||||
boolean down = Math.abs(dy) > 0.2;
|
||||
|
||||
BlockState bState;
|
||||
Mutable bPos = new Mutable();
|
||||
for (int i = 0; i < count; i++) {
|
||||
bPos.set(x + pos.getX(), y + pos.getY(), z + pos.getZ());
|
||||
bState = world.getBlockState(bPos);
|
||||
if (bState.equals(state) || replace.apply(bState)) {
|
||||
BlocksHelper.setWithoutUpdate(world, bPos, state);
|
||||
bPos.setY(bPos.getY() - 1);
|
||||
bState = world.getBlockState(bPos);
|
||||
if (down && bState.equals(state) || replace.apply(bState)) {
|
||||
BlocksHelper.setWithoutUpdate(world, bPos, state);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
x += dx;
|
||||
y += dy;
|
||||
z += dz;
|
||||
}
|
||||
bPos.set(end.getX() + pos.getX(), end.getY() + pos.getY(), end.getZ() + pos.getZ());
|
||||
bState = world.getBlockState(bPos);
|
||||
if (bState.equals(state) || replace.apply(bState)) {
|
||||
BlocksHelper.setWithoutUpdate(world, bPos, state);
|
||||
bPos.setY(bPos.getY() - 1);
|
||||
bState = world.getBlockState(bPos);
|
||||
if (down && bState.equals(state) || replace.apply(bState)) {
|
||||
BlocksHelper.setWithoutUpdate(world, bPos, state);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue