Removed logger, Splines and Json Factory
This commit is contained in:
parent
055baeaae0
commit
df890a0167
22 changed files with 21 additions and 533 deletions
|
@ -5,6 +5,7 @@ import net.fabricmc.api.ModInitializer;
|
|||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import ru.bclib.util.Logger;
|
||||
import ru.betterend.api.BetterEndPlugin;
|
||||
import ru.betterend.config.Configs;
|
||||
import ru.betterend.effects.EndEnchantments;
|
||||
|
@ -30,7 +31,6 @@ import ru.betterend.registry.EndStructures;
|
|||
import ru.betterend.registry.EndTags;
|
||||
import ru.betterend.util.BonemealUtil;
|
||||
import ru.betterend.util.DataFixerUtil;
|
||||
import ru.betterend.util.Logger;
|
||||
import ru.betterend.util.LootTableUtil;
|
||||
import ru.betterend.world.generator.BetterEndBiomeSource;
|
||||
import ru.betterend.world.generator.GeneratorOptions;
|
||||
|
@ -38,7 +38,7 @@ import ru.betterend.world.surface.SurfaceBuilders;
|
|||
|
||||
public class BetterEnd implements ModInitializer {
|
||||
public static final String MOD_ID = "betterend";
|
||||
public static final Logger LOGGER = Logger.get();
|
||||
public static final Logger LOGGER = new Logger(MOD_ID);
|
||||
private static boolean hasHydrogen;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,21 +14,19 @@ import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConf
|
|||
import net.minecraft.world.level.material.Material;
|
||||
import ru.bclib.sdf.SDF;
|
||||
import ru.bclib.util.MHelper;
|
||||
import ru.bclib.util.SplineHelper;
|
||||
import ru.betterend.integration.Integrations;
|
||||
import ru.betterend.registry.EndTags;
|
||||
import ru.betterend.util.SplineHelper;
|
||||
import ru.betterend.world.features.DefaultFeature;
|
||||
|
||||
public class BigEtherTreeFeature extends DefaultFeature {
|
||||
@Override
|
||||
public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos,
|
||||
NoneFeatureConfiguration config) {
|
||||
public boolean place(WorldGenLevel world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, NoneFeatureConfiguration config) {
|
||||
if (!world.getBlockState(pos.below()).getBlock().is(EndTags.END_GROUND))
|
||||
return false;
|
||||
|
||||
BlockState log = Integrations.BYG.getDefaultState("ether_log");
|
||||
BlockState wood = Integrations.BYG.getDefaultState("ether_wood");
|
||||
// BlockState leaves = Integrations.BYG.getDefaultState("ether_leaves");
|
||||
Function<BlockPos, BlockState> splinePlacer = (bpos) -> {
|
||||
return log;
|
||||
};
|
||||
|
@ -51,7 +49,6 @@ public class BigEtherTreeFeature extends DefaultFeature {
|
|||
List<Vector3f> branch = SplineHelper.makeSpline(0, 0, 0, length, 0, 0, points < 2 ? 2 : points);
|
||||
SplineHelper.powerOffset(branch, length, 2F);
|
||||
int rotCount = MHelper.randRange(5, 7, random);
|
||||
// float startRad = MathHelper.lerp(splinePos, 2.3F, 0.8F) * 0.8F;
|
||||
Vector3f start = SplineHelper.getPos(trunk, splinePos * (trunk.size() - 1));
|
||||
for (int j = 0; j < rotCount; j++) {
|
||||
float angle = startAngle + (float) j / rotCount * MHelper.PI2;
|
||||
|
@ -76,9 +73,4 @@ public class BigEtherTreeFeature extends DefaultFeature {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
// private void makeLeavesSphere(StructureWorldAccess world, BlockPos pos,
|
||||
// BlockState leaves, Function<BlockState, Boolean> ignore) {
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -25,10 +25,10 @@ import ru.bclib.sdf.operator.SDFSmoothUnion;
|
|||
import ru.bclib.sdf.primitive.SDFCappedCone;
|
||||
import ru.bclib.sdf.primitive.SDFSphere;
|
||||
import ru.bclib.util.MHelper;
|
||||
import ru.bclib.util.SplineHelper;
|
||||
import ru.betterend.integration.Integrations;
|
||||
import ru.betterend.registry.EndTags;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.SplineHelper;
|
||||
import ru.betterend.world.features.DefaultFeature;
|
||||
|
||||
public class GreatNightshadeTreeFeature extends DefaultFeature {
|
||||
|
|
|
@ -25,10 +25,10 @@ import ru.bclib.sdf.operator.SDFSmoothUnion;
|
|||
import ru.bclib.sdf.primitive.SDFCappedCone;
|
||||
import ru.bclib.sdf.primitive.SDFSphere;
|
||||
import ru.bclib.util.MHelper;
|
||||
import ru.bclib.util.SplineHelper;
|
||||
import ru.betterend.integration.Integrations;
|
||||
import ru.betterend.registry.EndTags;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.SplineHelper;
|
||||
import ru.betterend.world.features.DefaultFeature;
|
||||
|
||||
public class NightshadeRedwoodTreeFeature extends DefaultFeature {
|
||||
|
|
|
@ -23,10 +23,10 @@ import ru.bclib.sdf.operator.SDFTranslate;
|
|||
import ru.bclib.sdf.operator.SDFUnion;
|
||||
import ru.bclib.sdf.primitive.SDFSphere;
|
||||
import ru.bclib.util.MHelper;
|
||||
import ru.bclib.util.SplineHelper;
|
||||
import ru.betterend.integration.Integrations;
|
||||
import ru.betterend.noise.OpenSimplexNoise;
|
||||
import ru.betterend.registry.EndTags;
|
||||
import ru.betterend.util.SplineHelper;
|
||||
import ru.betterend.world.features.DefaultFeature;
|
||||
|
||||
public class OldBulbisTreeFeature extends DefaultFeature {
|
||||
|
|
|
@ -26,11 +26,11 @@ import net.minecraft.server.MinecraftServer;
|
|||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.Biome.BiomeCategory;
|
||||
import net.minecraft.world.level.biome.Biomes;
|
||||
import ru.bclib.util.JsonFactory;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.config.Configs;
|
||||
import ru.betterend.integration.Integrations;
|
||||
import ru.betterend.interfaces.IBiomeList;
|
||||
import ru.betterend.util.JsonFactory;
|
||||
import ru.betterend.world.biome.EndBiome;
|
||||
import ru.betterend.world.biome.air.BiomeIceStarfield;
|
||||
import ru.betterend.world.biome.cave.EmptyAuroraCaveBiome;
|
||||
|
|
|
@ -11,9 +11,9 @@ import net.minecraft.server.MinecraftServer;
|
|||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.Level;
|
||||
import ru.bclib.util.ColorUtil;
|
||||
import ru.bclib.util.JsonFactory;
|
||||
import ru.bclib.util.MHelper;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.util.JsonFactory;
|
||||
|
||||
public class EndPortals {
|
||||
|
||||
|
|
|
@ -1,91 +0,0 @@
|
|||
package ru.betterend.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import ru.betterend.BetterEnd;
|
||||
|
||||
public class JsonFactory {
|
||||
|
||||
public final static Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
public static JsonObject getJsonObject(InputStream stream) {
|
||||
try {
|
||||
Reader reader = new InputStreamReader(stream);
|
||||
JsonElement json = loadJson(reader);
|
||||
if (json != null && json.isJsonObject()) {
|
||||
JsonObject jsonObject = json.getAsJsonObject();
|
||||
return jsonObject != null ? jsonObject : new JsonObject();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
BetterEnd.LOGGER.catching(ex);
|
||||
}
|
||||
return new JsonObject();
|
||||
}
|
||||
|
||||
public static JsonObject getJsonObject(File jsonFile) {
|
||||
if (jsonFile.exists()) {
|
||||
JsonElement json = loadJson(jsonFile);
|
||||
if (json != null && json.isJsonObject()) {
|
||||
JsonObject jsonObject = json.getAsJsonObject();
|
||||
return jsonObject != null ? jsonObject : new JsonObject();
|
||||
}
|
||||
}
|
||||
return new JsonObject();
|
||||
}
|
||||
|
||||
public static JsonElement loadJson(File jsonFile) {
|
||||
if (jsonFile.exists()) {
|
||||
try (Reader reader = new FileReader(jsonFile)) {
|
||||
return loadJson(reader);
|
||||
} catch (Exception ex) {
|
||||
BetterEnd.LOGGER.catching(ex);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static JsonElement loadJson(Reader reader) {
|
||||
return GSON.fromJson(reader, JsonElement.class);
|
||||
}
|
||||
|
||||
public static void storeJson(File jsonFile, JsonElement jsonObject) {
|
||||
try(FileWriter writer = new FileWriter(jsonFile)) {
|
||||
String json = GSON.toJson(jsonObject);
|
||||
writer.write(json);
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
BetterEnd.LOGGER.catching(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getInt(JsonObject object, String member, int def) {
|
||||
JsonElement elem = object.get(member);
|
||||
return elem == null ? def : elem.getAsInt();
|
||||
}
|
||||
|
||||
public static float getFloat(JsonObject object, String member, float def) {
|
||||
JsonElement elem = object.get(member);
|
||||
return elem == null ? def : elem.getAsFloat();
|
||||
}
|
||||
|
||||
public static boolean getBoolean(JsonObject object, String member, boolean def) {
|
||||
JsonElement elem = object.get(member);
|
||||
return elem == null ? def : elem.getAsBoolean();
|
||||
}
|
||||
|
||||
public static String getString(JsonObject object, String member, String def) {
|
||||
JsonElement elem = object.get(member);
|
||||
return elem == null ? def : elem.getAsString();
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
package ru.betterend.util;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import ru.betterend.BetterEnd;
|
||||
|
||||
public final class Logger {
|
||||
|
||||
private static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
private String modPref = "[" + BetterEnd.MOD_ID + "] ";
|
||||
|
||||
private Logger() {}
|
||||
|
||||
public static Logger get() {
|
||||
return new Logger();
|
||||
}
|
||||
|
||||
public void log(Level level, String message) {
|
||||
LOGGER.log(level, modPref + message);
|
||||
}
|
||||
|
||||
public void log(Level level, String message, Object... params) {
|
||||
LOGGER.log(level, modPref + message, params);
|
||||
}
|
||||
|
||||
public void debug(Object message) {
|
||||
this.log(Level.DEBUG, message.toString());
|
||||
}
|
||||
|
||||
public void debug(Object message, Object... params) {
|
||||
this.log(Level.DEBUG, message.toString(), params);
|
||||
}
|
||||
|
||||
public void catching(Throwable ex) {
|
||||
this.error(ex.getLocalizedMessage());
|
||||
LOGGER.catching(ex);
|
||||
}
|
||||
|
||||
public void info(String message) {
|
||||
this.log(Level.INFO, message);
|
||||
}
|
||||
|
||||
public void info(String message, Object... params) {
|
||||
this.log(Level.INFO, message, params);
|
||||
}
|
||||
|
||||
public void warning(String message, Object... params) {
|
||||
this.log(Level.WARN, message, params);
|
||||
}
|
||||
|
||||
public void warning(String message, Object obj, Exception ex) {
|
||||
LOGGER.warn(modPref + message, obj, ex);
|
||||
}
|
||||
|
||||
public void error(String message) {
|
||||
this.log(Level.ERROR, message);
|
||||
}
|
||||
|
||||
public void error(String message, Object obj, Exception ex) {
|
||||
LOGGER.error(modPref + message, obj, ex);
|
||||
}
|
||||
|
||||
public void error(String message, Exception ex) {
|
||||
LOGGER.error(modPref + message, ex);
|
||||
}
|
||||
}
|
|
@ -1,345 +0,0 @@
|
|||
package ru.betterend.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.math.Vector3f;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.level.WorldGenLevel;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import ru.bclib.sdf.SDF;
|
||||
import ru.bclib.sdf.operator.SDFUnion;
|
||||
import ru.bclib.sdf.primitive.SDFLine;
|
||||
import ru.bclib.util.MHelper;
|
||||
|
||||
public class SplineHelper {
|
||||
public static List<Vector3f> makeSpline(float x1, float y1, float z1, float x2, float y2, float z2, int points) {
|
||||
List<Vector3f> spline = Lists.newArrayList();
|
||||
spline.add(new Vector3f(x1, y1, z1));
|
||||
int count = points - 1;
|
||||
for (int i = 1; i < count; i++) {
|
||||
float delta = (float) i / (float) count;
|
||||
float x = Mth.lerp(delta, x1, x2);
|
||||
float y = Mth.lerp(delta, y1, y2);
|
||||
float z = Mth.lerp(delta, z1, z2);
|
||||
spline.add(new Vector3f(x, y, z));
|
||||
}
|
||||
spline.add(new Vector3f(x2, y2, z2));
|
||||
return spline;
|
||||
}
|
||||
|
||||
public static List<Vector3f> smoothSpline(List<Vector3f> spline, int segmentPoints) {
|
||||
List<Vector3f> result = Lists.newArrayList();
|
||||
Vector3f start = spline.get(0);
|
||||
for (int i = 1; i < spline.size(); i++) {
|
||||
Vector3f end = spline.get(i);
|
||||
for (int j = 0; j < segmentPoints; j++) {
|
||||
float delta = (float) j / segmentPoints;
|
||||
delta = 0.5F - 0.5F * Mth.cos(delta * 3.14159F);
|
||||
result.add(lerp(start, end, delta));
|
||||
}
|
||||
start = end;
|
||||
}
|
||||
result.add(start);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Vector3f lerp(Vector3f start, Vector3f end, float delta) {
|
||||
float x = Mth.lerp(delta, start.x(), end.x());
|
||||
float y = Mth.lerp(delta, start.y(), end.y());
|
||||
float z = Mth.lerp(delta, start.z(), end.z());
|
||||
return new Vector3f(x, y, z);
|
||||
}
|
||||
|
||||
public static void offsetParts(List<Vector3f> spline, Random random, float dx, float dy, float dz) {
|
||||
int count = spline.size();
|
||||
for (int i = 1; i < count; i++) {
|
||||
Vector3f pos = spline.get(i);
|
||||
float x = pos.x() + (float) random.nextGaussian() * dx;
|
||||
float y = pos.y() + (float) random.nextGaussian() * dy;
|
||||
float z = pos.z() + (float) random.nextGaussian() * dz;
|
||||
pos.set(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
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 / max;
|
||||
float y = pos.y() + (float) Math.pow(x, power) * distance;
|
||||
pos.set(pos.x(), y, pos.z());
|
||||
}
|
||||
}
|
||||
|
||||
public static SDF buildSDF(List<Vector3f> spline, float radius1, float radius2, Function<BlockPos, BlockState> placerFunction) {
|
||||
int count = spline.size();
|
||||
float max = count - 2;
|
||||
SDF result = null;
|
||||
Vector3f start = spline.get(0);
|
||||
for (int i = 1; i < count; i++) {
|
||||
Vector3f pos = spline.get(i);
|
||||
float delta = (float) (i - 1) / max;
|
||||
SDF line = new SDFLine()
|
||||
.setRadius(Mth.lerp(delta, radius1, radius2))
|
||||
.setStart(start.x(), start.y(), start.z())
|
||||
.setEnd(pos.x(), pos.y(), pos.z())
|
||||
.setBlock(placerFunction);
|
||||
result = result == null ? line : new SDFUnion().setSourceA(result).setSourceB(line);
|
||||
start = pos;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static SDF buildSDF(List<Vector3f> spline, Function<Float, Float> radiusFunction, Function<BlockPos, BlockState> placerFunction) {
|
||||
int count = spline.size();
|
||||
float max = count - 2;
|
||||
SDF result = null;
|
||||
Vector3f start = spline.get(0);
|
||||
for (int i = 1; i < count; i++) {
|
||||
Vector3f pos = spline.get(i);
|
||||
float delta = (float) (i - 1) / max;
|
||||
SDF line = new SDFLine()
|
||||
.setRadius(radiusFunction.apply(delta))
|
||||
.setStart(start.x(), start.y(), start.z())
|
||||
.setEnd(pos.x(), pos.y(), pos.z())
|
||||
.setBlock(placerFunction);
|
||||
result = result == null ? line : new SDFUnion().setSourceA(result).setSourceB(line);
|
||||
start = pos;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean fillSpline(List<Vector3f> spline, WorldGenLevel 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;
|
||||
}
|
||||
|
||||
public static void fillSplineForce(List<Vector3f> spline, WorldGenLevel 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);
|
||||
fillLineForce(startPos, endPos, world, state, pos, replace);
|
||||
startPos = endPos;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean fillLine(Vector3f start, Vector3f end, WorldGenLevel world, BlockState state, BlockPos pos, Function<BlockState, Boolean> replace) {
|
||||
float dx = end.x() - start.x();
|
||||
float dy = end.y() - start.y();
|
||||
float dz = end.z() - start.z();
|
||||
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.x();
|
||||
float y = start.y();
|
||||
float z = start.z();
|
||||
boolean down = Math.abs(dy) > 0.2;
|
||||
|
||||
BlockState bState;
|
||||
MutableBlockPos bPos = new MutableBlockPos();
|
||||
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.x() + pos.getX(), end.y() + pos.getY(), end.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);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void fillLineForce(Vector3f start, Vector3f end, WorldGenLevel world, BlockState state, BlockPos pos, Function<BlockState, Boolean> replace) {
|
||||
float dx = end.x() - start.x();
|
||||
float dy = end.y() - start.y();
|
||||
float dz = end.z() - start.z();
|
||||
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.x();
|
||||
float y = start.y();
|
||||
float z = start.z();
|
||||
boolean down = Math.abs(dy) > 0.2;
|
||||
|
||||
BlockState bState;
|
||||
MutableBlockPos bPos = new MutableBlockPos();
|
||||
for (int i = 0; i < count; i++) {
|
||||
bPos.set(x + pos.getX(), y + pos.getY(), z + pos.getZ());
|
||||
bState = world.getBlockState(bPos);
|
||||
if (replace.apply(bState)) {
|
||||
BlocksHelper.setWithoutUpdate(world, bPos, state);
|
||||
bPos.setY(bPos.getY() - 1);
|
||||
bState = world.getBlockState(bPos);
|
||||
if (down && replace.apply(bState)) {
|
||||
BlocksHelper.setWithoutUpdate(world, bPos, state);
|
||||
}
|
||||
}
|
||||
x += dx;
|
||||
y += dy;
|
||||
z += dz;
|
||||
}
|
||||
bPos.set(end.x() + pos.getX(), end.y() + pos.getY(), end.z() + pos.getZ());
|
||||
bState = world.getBlockState(bPos);
|
||||
if (replace.apply(bState)) {
|
||||
BlocksHelper.setWithoutUpdate(world, bPos, state);
|
||||
bPos.setY(bPos.getY() - 1);
|
||||
bState = world.getBlockState(bPos);
|
||||
if (down && replace.apply(bState)) {
|
||||
BlocksHelper.setWithoutUpdate(world, bPos, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean canGenerate(List<Vector3f> spline, float scale, BlockPos start, WorldGenLevel world, Function<BlockState, Boolean> canReplace) {
|
||||
int count = spline.size();
|
||||
Vector3f vec = spline.get(0);
|
||||
MutableBlockPos mut = new MutableBlockPos();
|
||||
float x1 = start.getX() + vec.x() * scale;
|
||||
float y1 = start.getY() + vec.y() * scale;
|
||||
float z1 = start.getZ() + vec.z() * scale;
|
||||
for (int i = 1; i < count; i++) {
|
||||
vec = spline.get(i);
|
||||
float x2 = start.getX() + vec.x() * scale;
|
||||
float y2 = start.getY() + vec.y() * scale;
|
||||
float z2 = start.getZ() + vec.z() * scale;
|
||||
|
||||
for (float py = y1; py < y2; py += 3) {
|
||||
if (py - start.getY() < 10) continue;
|
||||
float lerp = (py - y1) / (y2 - y1);
|
||||
float x = Mth.lerp(lerp, x1, x2);
|
||||
float z = Mth.lerp(lerp, z1, z2);
|
||||
mut.set(x, py, z);
|
||||
if (!canReplace.apply(world.getBlockState(mut))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
z1 = z2;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean canGenerate(List<Vector3f> spline, BlockPos start, WorldGenLevel world, Function<BlockState, Boolean> canReplace) {
|
||||
int count = spline.size();
|
||||
Vector3f vec = spline.get(0);
|
||||
MutableBlockPos mut = new MutableBlockPos();
|
||||
float x1 = start.getX() + vec.x();
|
||||
float y1 = start.getY() + vec.y();
|
||||
float z1 = start.getZ() + vec.z();
|
||||
for (int i = 1; i < count; i++) {
|
||||
vec = spline.get(i);
|
||||
float x2 = start.getX() + vec.x();
|
||||
float y2 = start.getY() + vec.y();
|
||||
float z2 = start.getZ() + vec.z();
|
||||
|
||||
for (float py = y1; py < y2; py += 3) {
|
||||
if (py - start.getY() < 10) continue;
|
||||
float lerp = (py - y1) / (y2 - y1);
|
||||
float x = Mth.lerp(lerp, x1, x2);
|
||||
float z = Mth.lerp(lerp, z1, z2);
|
||||
mut.set(x, py, z);
|
||||
if (!canReplace.apply(world.getBlockState(mut))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
z1 = z2;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Vector3f getPos(List<Vector3f> spline, float index) {
|
||||
int i = (int) index;
|
||||
int last = spline.size() - 1;
|
||||
if (i >= last) {
|
||||
return spline.get(last);
|
||||
}
|
||||
float delta = index - i;
|
||||
Vector3f p1 = spline.get(i);
|
||||
Vector3f p2 = spline.get(i + 1);
|
||||
float x = Mth.lerp(delta, p1.x(), p2.x());
|
||||
float y = Mth.lerp(delta, p1.y(), p2.y());
|
||||
float z = Mth.lerp(delta, p1.z(), p2.z());
|
||||
return new Vector3f(x, y, z);
|
||||
}
|
||||
|
||||
public static void rotateSpline(List<Vector3f> spline, float angle) {
|
||||
for (Vector3f v: spline) {
|
||||
float sin = (float) Math.sin(angle);
|
||||
float cos = (float) Math.cos(angle);
|
||||
float x = v.x() * cos + v.z() * sin;
|
||||
float z = v.x() * sin + v.z() * cos;
|
||||
v.set(x, v.y(), z);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Vector3f> copySpline(List<Vector3f> spline) {
|
||||
List<Vector3f> result = new ArrayList<Vector3f>(spline.size());
|
||||
for (Vector3f v: spline) {
|
||||
result.add(new Vector3f(v.x(), v.y(), v.z()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void scale(List<Vector3f> spline, float scale) {
|
||||
scale(spline, scale, scale, scale);
|
||||
}
|
||||
|
||||
public static void scale(List<Vector3f> spline, float x, float y, float z) {
|
||||
for (Vector3f v: spline) {
|
||||
v.set(v.x() * x, v.y() * y, v.z() * z);
|
||||
}
|
||||
}
|
||||
|
||||
public static void offset(List<Vector3f> spline, Vector3f offset) {
|
||||
for (Vector3f v: spline) {
|
||||
v.set(offset.x() + v.x(), offset.y() + v.y(), offset.z() + v.z());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,8 +11,8 @@ import com.google.gson.JsonObject;
|
|||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import ru.bclib.util.JsonFactory;
|
||||
import ru.betterend.config.Configs;
|
||||
import ru.betterend.util.JsonFactory;
|
||||
import ru.betterend.util.StructureHelper;
|
||||
import ru.betterend.world.features.EndFeature;
|
||||
import ru.betterend.world.features.ListFeature;
|
||||
|
|
|
@ -25,11 +25,11 @@ import ru.bclib.sdf.operator.SDFSubtraction;
|
|||
import ru.bclib.sdf.operator.SDFTranslate;
|
||||
import ru.bclib.sdf.primitive.SDFSphere;
|
||||
import ru.bclib.util.MHelper;
|
||||
import ru.bclib.util.SplineHelper;
|
||||
import ru.betterend.noise.OpenSimplexNoise;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.registry.EndTags;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.SplineHelper;
|
||||
import ru.betterend.world.features.DefaultFeature;
|
||||
|
||||
public class DragonTreeFeature extends DefaultFeature {
|
||||
|
|
|
@ -20,11 +20,11 @@ import net.minecraft.world.level.material.Material;
|
|||
import ru.bclib.sdf.PosInfo;
|
||||
import ru.bclib.sdf.SDF;
|
||||
import ru.bclib.util.MHelper;
|
||||
import ru.bclib.util.SplineHelper;
|
||||
import ru.betterend.blocks.basis.AttachedBlock;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.registry.EndTags;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.SplineHelper;
|
||||
import ru.betterend.world.features.DefaultFeature;
|
||||
|
||||
public class GiganticAmaranitaFeature extends DefaultFeature {
|
||||
|
|
|
@ -23,11 +23,11 @@ import ru.bclib.sdf.operator.SDFSmoothUnion;
|
|||
import ru.bclib.sdf.operator.SDFTranslate;
|
||||
import ru.bclib.sdf.operator.SDFUnion;
|
||||
import ru.bclib.util.MHelper;
|
||||
import ru.bclib.util.SplineHelper;
|
||||
import ru.betterend.blocks.HelixTreeLeavesBlock;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.registry.EndTags;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.SplineHelper;
|
||||
import ru.betterend.world.features.DefaultFeature;
|
||||
|
||||
public class HelixTreeFeature extends DefaultFeature {
|
||||
|
|
|
@ -22,10 +22,10 @@ import ru.bclib.sdf.operator.SDFSubtraction;
|
|||
import ru.bclib.sdf.operator.SDFTranslate;
|
||||
import ru.bclib.sdf.primitive.SDFSphere;
|
||||
import ru.bclib.util.MHelper;
|
||||
import ru.bclib.util.SplineHelper;
|
||||
import ru.betterend.blocks.JellyshroomCapBlock;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.registry.EndTags;
|
||||
import ru.betterend.util.SplineHelper;
|
||||
import ru.betterend.world.features.DefaultFeature;
|
||||
|
||||
public class JellyshroomFeature extends DefaultFeature {
|
||||
|
|
|
@ -22,11 +22,11 @@ import ru.bclib.sdf.operator.SDFSubtraction;
|
|||
import ru.bclib.sdf.operator.SDFTranslate;
|
||||
import ru.bclib.sdf.primitive.SDFSphere;
|
||||
import ru.bclib.util.MHelper;
|
||||
import ru.bclib.util.SplineHelper;
|
||||
import ru.betterend.noise.OpenSimplexNoise;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.registry.EndTags;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.SplineHelper;
|
||||
import ru.betterend.world.features.DefaultFeature;
|
||||
|
||||
public class LacugroveFeature extends DefaultFeature {
|
||||
|
|
|
@ -24,6 +24,7 @@ import ru.bclib.sdf.operator.SDFSubtraction;
|
|||
import ru.bclib.sdf.operator.SDFTranslate;
|
||||
import ru.bclib.sdf.primitive.SDFSphere;
|
||||
import ru.bclib.util.MHelper;
|
||||
import ru.bclib.util.SplineHelper;
|
||||
import ru.betterend.blocks.BlockProperties;
|
||||
import ru.betterend.blocks.BlockProperties.TripleShape;
|
||||
import ru.betterend.blocks.basis.FurBlock;
|
||||
|
@ -31,7 +32,6 @@ import ru.betterend.noise.OpenSimplexNoise;
|
|||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.registry.EndTags;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.SplineHelper;
|
||||
import ru.betterend.world.features.DefaultFeature;
|
||||
|
||||
public class LucerniaFeature extends DefaultFeature {
|
||||
|
|
|
@ -27,13 +27,13 @@ import ru.bclib.sdf.primitive.SDFCappedCone;
|
|||
import ru.bclib.sdf.primitive.SDFPrimitive;
|
||||
import ru.bclib.sdf.primitive.SDFSphere;
|
||||
import ru.bclib.util.MHelper;
|
||||
import ru.bclib.util.SplineHelper;
|
||||
import ru.betterend.blocks.MossyGlowshroomCapBlock;
|
||||
import ru.betterend.blocks.basis.FurBlock;
|
||||
import ru.betterend.noise.OpenSimplexNoise;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.registry.EndTags;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.SplineHelper;
|
||||
import ru.betterend.world.features.DefaultFeature;
|
||||
|
||||
public class MossyGlowshroomFeature extends DefaultFeature {
|
||||
|
|
|
@ -23,11 +23,11 @@ import ru.bclib.sdf.operator.SDFSubtraction;
|
|||
import ru.bclib.sdf.operator.SDFTranslate;
|
||||
import ru.bclib.sdf.primitive.SDFSphere;
|
||||
import ru.bclib.util.MHelper;
|
||||
import ru.bclib.util.SplineHelper;
|
||||
import ru.betterend.noise.OpenSimplexNoise;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.registry.EndTags;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.SplineHelper;
|
||||
import ru.betterend.world.features.DefaultFeature;
|
||||
|
||||
public class PythadendronTreeFeature extends DefaultFeature {
|
||||
|
|
|
@ -24,6 +24,7 @@ import ru.bclib.sdf.operator.SDFSubtraction;
|
|||
import ru.bclib.sdf.operator.SDFTranslate;
|
||||
import ru.bclib.sdf.primitive.SDFSphere;
|
||||
import ru.bclib.util.MHelper;
|
||||
import ru.bclib.util.SplineHelper;
|
||||
import ru.betterend.blocks.BlockProperties;
|
||||
import ru.betterend.blocks.BlockProperties.TripleShape;
|
||||
import ru.betterend.blocks.basis.FurBlock;
|
||||
|
@ -31,7 +32,6 @@ import ru.betterend.noise.OpenSimplexNoise;
|
|||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.registry.EndTags;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.SplineHelper;
|
||||
import ru.betterend.world.features.DefaultFeature;
|
||||
|
||||
public class TenaneaFeature extends DefaultFeature {
|
||||
|
|
|
@ -26,12 +26,12 @@ import ru.bclib.sdf.operator.SDFTranslate;
|
|||
import ru.bclib.sdf.operator.SDFUnion;
|
||||
import ru.bclib.sdf.primitive.SDFSphere;
|
||||
import ru.bclib.util.MHelper;
|
||||
import ru.bclib.util.SplineHelper;
|
||||
import ru.betterend.blocks.UmbrellaTreeClusterBlock;
|
||||
import ru.betterend.blocks.UmbrellaTreeMembraneBlock;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.registry.EndTags;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.SplineHelper;
|
||||
import ru.betterend.world.features.DefaultFeature;
|
||||
|
||||
public class UmbrellaTreeFeature extends DefaultFeature {
|
||||
|
|
|
@ -22,12 +22,12 @@ import ru.bclib.sdf.primitive.SDFCappedCone;
|
|||
import ru.bclib.sdf.primitive.SDFPrimitive;
|
||||
import ru.bclib.sdf.primitive.SDFSphere;
|
||||
import ru.bclib.util.MHelper;
|
||||
import ru.bclib.util.SplineHelper;
|
||||
import ru.betterend.blocks.MossyGlowshroomCapBlock;
|
||||
import ru.betterend.blocks.basis.FurBlock;
|
||||
import ru.betterend.noise.OpenSimplexNoise;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
import ru.betterend.util.SplineHelper;
|
||||
|
||||
public class GiantMossyGlowshroomStructure extends SDFStructureFeature {
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue