Lots of crap

This commit is contained in:
cyberpwn 2022-04-14 20:40:37 -04:00
parent a40e533068
commit 185b366d8d
7 changed files with 141 additions and 1 deletions

View File

@ -27,6 +27,7 @@ import com.volmit.iris.core.link.OraxenLink;
import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.core.nms.INMS;
import com.volmit.iris.core.service.StudioSVC;
import com.volmit.iris.core.tools.IrisToolbelt;
import com.volmit.iris.engine.EnginePanic;
import com.volmit.iris.engine.object.IrisBiome;
import com.volmit.iris.engine.object.IrisCompat;

View File

@ -32,15 +32,21 @@ import com.volmit.iris.engine.platform.PlatformChunkGenerator;
import com.volmit.iris.util.plugin.VolmitSender;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
import java.io.File;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
/**
* Something you really want to wear if working on Iris. Shit gets pretty hectic down there.
* Hope you packed snacks & road sodas.
*/
public class IrisToolbelt {
public static Map<String, Boolean> toolbeltConfiguration = new HashMap<>();
/**
* Will find / download / search for the dimension or return null
* <p>
@ -210,4 +216,54 @@ public class IrisToolbelt {
public static boolean isStudio(World i) {
return isIrisWorld(i) && access(i).isStudio();
}
public static void retainMantleDataForSlice(String className)
{
toolbeltConfiguration.put("retain.mantle." + className, true);
}
public static <T> T getMantleData(World world, int x, int y, int z, Class<T> of)
{
PlatformChunkGenerator e = access(world);
if(e == null) {return null;}
return e.getEngine().getMantle().getMantle().get(x, y - world.getMinHeight(), z, of);
}
/////////////////// REFLECTIVE METHODS //////////////////////////
// Copy this stuff to your project, it's safe to use with a
// bukkit api only.
/////////////////////////////////////////////////////////////////
public static void setup() throws Throwable {
Method m = Class.forName("com.volmit.iris.core.tools.IrisToolbelt").getDeclaredMethod("retainMantleDataForSlice", String.class);
m.invoke(null, String.class.getCanonicalName());
m.invoke(null, BlockData.class.getCanonicalName());
}
public static boolean hasMantleObject(World world, int x, int y, int z) {
try {
Method m = Class.forName("com.volmit.iris.core.tools.IrisToolbelt").getDeclaredMethod("getMantleData", World.class, int.class, int.class, int.class, Class.class);
String s = (String) m.invoke(null, world, x, y, z, String.class);
if(s != null) {return true;}
} catch(Throwable ignored) {}
return false;
}
public static BlockData getMantleBlock(World world, int x, int y, int z) {
try {
Method m = Class.forName("com.volmit.iris.core.tools.IrisToolbelt").getDeclaredMethod("getMantleData", World.class, int.class, int.class, int.class, Class.class);
BlockData s = (BlockData) m.invoke(null, world, x, y, z, BlockData.class);
if(s != null) {return s;}
} catch(Throwable ignored) {}
return null;
}
public static int getMantleIdentity(World world, int x, int y, int z) {
try {
Method m = Class.forName("com.volmit.iris.core.tools.IrisToolbelt").getDeclaredMethod("getMantleData", World.class, int.class, int.class, int.class, Class.class);
String s = (String) m.invoke(null, world, x, y, z, String.class);
if(s != null) {return Integer.parseInt(s.split("\\Q@\\E")[1]);}
} catch(Throwable ignored) {}
return -1;
}
}

View File

@ -24,6 +24,7 @@ import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.object.IObjectPlacer;
import com.volmit.iris.engine.object.IrisGeneratorStyle;
import com.volmit.iris.engine.object.IrisPosition;
import com.volmit.iris.engine.object.TileData;
import com.volmit.iris.util.collection.KMap;
@ -31,6 +32,7 @@ import com.volmit.iris.util.collection.KSet;
import com.volmit.iris.util.function.Function3;
import com.volmit.iris.util.mantle.Mantle;
import com.volmit.iris.util.mantle.MantleChunk;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.matter.Matter;
import lombok.Data;
import org.bukkit.block.TileState;
@ -121,6 +123,13 @@ public class MantleWriter implements IObjectPlacer {
return (x * x) + (z * z);
}
public <T> void setDataWarped(int x, int y, int z, T t, RNG rng, IrisData data, IrisGeneratorStyle style)
{
setData((int)Math.round(style.warp(rng, data, x, x, y, -z)),
(int)Math.round(style.warp(rng, data, y, z, -x, y)),
(int)Math.round(style.warp(rng, data, z, -y, z, x)), t);
}
public <T> void setData(int x, int y, int z, T t) {
if(t == null) {
return;
@ -233,6 +242,10 @@ public class MantleWriter implements IObjectPlacer {
setElipsoidFunction(cx, cy, cz, rx, ry, rz, fill, (a, b, c) -> data);
}
public <T> void setElipsoidWarped(int cx, int cy, int cz, double rx, double ry, double rz, boolean fill, T data, RNG rng, IrisData idata, IrisGeneratorStyle style) {
setElipsoidFunctionWarped(cx, cy, cz, rx, ry, rz, fill, (a, b, c) -> data, rng, idata, style);
}
/**
* Set an elipsoid into the mantle
*
@ -312,6 +325,63 @@ public class MantleWriter implements IObjectPlacer {
}
}
public <T> void setElipsoidFunctionWarped(int cx, int cy, int cz, double rx, double ry, double rz, boolean fill, Function3<Integer, Integer, Integer, T> data, RNG rng, IrisData idata, IrisGeneratorStyle style) {
rx += 0.5;
ry += 0.5;
rz += 0.5;
final double invRadiusX = 1 / rx;
final double invRadiusY = 1 / ry;
final double invRadiusZ = 1 / rz;
final int ceilRadiusX = (int) Math.ceil(rx);
final int ceilRadiusY = (int) Math.ceil(ry);
final int ceilRadiusZ = (int) Math.ceil(rz);
double nextXn = 0;
forX:
for(int x = 0; x <= ceilRadiusX; ++x) {
final double xn = nextXn;
nextXn = (x + 1) * invRadiusX;
double nextYn = 0;
forY:
for(int y = 0; y <= ceilRadiusY; ++y) {
final double yn = nextYn;
nextYn = (y + 1) * invRadiusY;
double nextZn = 0;
for(int z = 0; z <= ceilRadiusZ; ++z) {
final double zn = nextZn;
nextZn = (z + 1) * invRadiusZ;
double distanceSq = lengthSq(xn, yn, zn);
if(distanceSq > 1) {
if(z == 0) {
if(y == 0) {
break forX;
}
break forY;
}
break;
}
if(!fill) {
if(lengthSq(nextXn, yn, zn) <= 1 && lengthSq(xn, nextYn, zn) <= 1 && lengthSq(xn, yn, nextZn) <= 1) {
continue;
}
}
setDataWarped(x + cx, y + cy, z + cz, data.apply(x + cx, y + cy, z + cz), rng, idata, style);
setDataWarped(-x + cx, y + cy, z + cz, data.apply(-x + cx, y + cy, z + cz), rng, idata, style);
setDataWarped(x + cx, -y + cy, z + cz, data.apply(x + cx, -y + cy, z + cz), rng, idata, style);
setDataWarped(x + cx, y + cy, -z + cz, data.apply(x + cx, y + cy, -z + cz), rng, idata, style);
setDataWarped(-x + cx, y + cy, -z + cz, data.apply(-x + cx, y + cy, -z + cz), rng, idata, style);
setDataWarped(-x + cx, -y + cy, z + cz, data.apply(-x + cx, -y + cy, z + cz), rng, idata, style);
setDataWarped(x + cx, -y + cy, -z + cz, data.apply(x + cx, -y + cy, -z + cz), rng, idata, style);
setDataWarped(-x + cx, y + cy, -z + cz, data.apply(-x + cx, y + cy, -z + cz), rng, idata, style);
setDataWarped(-x + cx, -y + cy, -z + cz, data.apply(-x + cx, -y + cy, -z + cz), rng, idata, style);
}
}
}
}
/**
* Set a cuboid of data in the mantle
*

View File

@ -128,6 +128,11 @@ public class IrisGeneratorStyle {
return cng;
}
public double warp(RNG rng, IrisData data, double value, double... coords)
{
return create(rng, data).noise(coords) + value;
}
public CNG create(RNG rng, IrisData data) {
return cng.aquire(() -> createNoCache(rng, data));
}

View File

@ -20,6 +20,7 @@ package com.volmit.iris.util.mantle;
import com.volmit.iris.Iris;
import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.core.tools.IrisToolbelt;
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.mantle.EngineMantle;
@ -570,6 +571,11 @@ public class Mantle {
}
public void deleteChunkSlice(int x, int z, Class<?> c) {
if(!IrisToolbelt.toolbeltConfiguration.isEmpty() && IrisToolbelt.toolbeltConfiguration.getOrDefault("retain.mantle." + c.getCanonicalName(), false))
{
return;
}
getChunk(x, z).deleteSlices(c);
}

View File

@ -31,7 +31,8 @@ public enum MantleFlag {
FLUID_BODIES,
INITIAL_SPAWNED_MARKER,
CLEANED,
PLANNED;
PLANNED,
ETCHED;
static StateList getStateList() {
return new StateList(MantleFlag.values());

View File

@ -29,6 +29,7 @@ import java.io.IOException;
@Sliced
public class CavernMatter extends RawMatter<MatterCavern> {
public static final MatterCavern EMPTY = new MatterCavern(false, "", (byte) 0);
public static final MatterCavern BASIC = new MatterCavern(true, "", (byte) 0);
public CavernMatter() {
this(1, 1, 1);