Fuck bukkit's stupid classloaders

This commit is contained in:
Daniel Mills 2020-01-31 13:43:28 -05:00
parent 7cc6dd03ff
commit 6373478d13
14 changed files with 174 additions and 71 deletions

View File

@ -1,12 +1,9 @@
package ninja.bytecode.iris; package ninja.bytecode.iris;
import java.io.File; import java.io.File;
import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Difficulty; import org.bukkit.World;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -15,13 +12,11 @@ import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import mortar.api.rift.Rift; import mortar.api.rift.Rift;
import mortar.api.sched.J; import mortar.api.sched.S;
import mortar.bukkit.command.Command; import mortar.bukkit.command.Command;
import mortar.bukkit.plugin.Control; import mortar.bukkit.plugin.Control;
import mortar.bukkit.plugin.Instance;
import mortar.bukkit.plugin.Mortar;
import mortar.bukkit.plugin.MortarPlugin; import mortar.bukkit.plugin.MortarPlugin;
import mortar.lib.control.RiftController; import mortar.util.reflection.V;
import mortar.util.text.C; import mortar.util.text.C;
import ninja.bytecode.iris.command.CommandIris; import ninja.bytecode.iris.command.CommandIris;
import ninja.bytecode.iris.controller.ExecutionController; import ninja.bytecode.iris.controller.ExecutionController;
@ -29,6 +24,7 @@ import ninja.bytecode.iris.controller.PackController;
import ninja.bytecode.iris.controller.WandController; import ninja.bytecode.iris.controller.WandController;
import ninja.bytecode.iris.generator.IrisGenerator; import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.util.Direction; import ninja.bytecode.iris.util.Direction;
import ninja.bytecode.iris.util.HotswapGenerator;
import ninja.bytecode.shuriken.logging.L; import ninja.bytecode.shuriken.logging.L;
public class Iris extends MortarPlugin public class Iris extends MortarPlugin
@ -38,7 +34,6 @@ public class Iris extends MortarPlugin
public static IrisMetrics metrics; public static IrisMetrics metrics;
private ExecutionController executionController; private ExecutionController executionController;
@Instance
public static Iris instance; public static Iris instance;
@Control @Control
@ -58,6 +53,11 @@ public class Iris extends MortarPlugin
instance = this; instance = this;
executionController = new ExecutionController(); executionController = new ExecutionController();
executionController.start(); executionController.start();
primaryThread = Thread.currentThread();
L.consoleConsumer = (s) -> Bukkit.getConsoleSender().sendMessage(s);
Direction.calculatePermutations();
settings = new Settings();
getServer().getPluginManager().registerEvents((Listener) this, this);
super.onEnable(); super.onEnable();
} }
@ -66,49 +66,56 @@ public class Iris extends MortarPlugin
return getDataFolder("cache", "object"); return getDataFolder("cache", "object");
} }
public static boolean isGen(World world)
{
IrisGenerator g = getGen(world);
return g != null && g instanceof IrisGenerator;
}
public static IrisGenerator getGen(World world)
{
try
{
return (IrisGenerator) ((HotswapGenerator) world.getGenerator()).getGenerator();
}
catch(Throwable e)
{
}
return null;
}
@Override @Override
public void start() public void start()
{ {
primaryThread = Thread.currentThread();
instance = this; instance = this;
L.consoleConsumer = (s) -> Bukkit.getConsoleSender().sendMessage(s);
Direction.calculatePermutations();
settings = new Settings();
getServer().getPluginManager().registerEvents((Listener) this, this);
packController.compile(); packController.compile();
J.s(() -> new S(0)
{ {
if(settings.performance.debugMode) @Override
public void run()
{ {
try instance = Iris.this;
for(World i : Bukkit.getWorlds())
{ {
r = Mortar.getController(RiftController.class).createRift("iris/" + UUID.randomUUID().toString()); try
r.setGenerator(IrisGenerator.class);
r.setDifficulty(Difficulty.NORMAL);
r.setTemporary(true);
r.setSeed(0);
r.setViewDistance(10);
r.setTileTickLimit(0.1);
r.setEntityTickLimit(0.1);
r.setPhysicsThrottle(5);
r.setMonsterActivationRange(5);
r.setArrowDespawnRate(1);
r.load();
for(Player i : Bukkit.getOnlinePlayers())
{ {
i.teleport(r.getSpawn()); new V(i.getGenerator()).invoke("setGenerator", new IrisGenerator());
i.setGameMode(GameMode.CREATIVE); L.i("Hotloading Generator for World " + i.getName());
}
catch(Throwable e)
{
} }
} }
catch(Throwable e)
{
e.printStackTrace();
}
} }
}, 10); };
instance = this;
} }
@Override @Override
@ -122,6 +129,7 @@ public class Iris extends MortarPlugin
HandlerList.unregisterAll((Plugin) this); HandlerList.unregisterAll((Plugin) this);
Bukkit.getScheduler().cancelTasks(this); Bukkit.getScheduler().cancelTasks(this);
executionController.stop(); executionController.stop();
packController.dispose();
} }
@EventHandler @EventHandler
@ -145,7 +153,7 @@ public class Iris extends MortarPlugin
@Override @Override
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) public ChunkGenerator getDefaultWorldGenerator(String worldName, String id)
{ {
return new IrisGenerator(); return new HotswapGenerator(new IrisGenerator());
} }
@Override @Override
@ -166,6 +174,17 @@ public class Iris extends MortarPlugin
public static ExecutionController exec() public static ExecutionController exec()
{ {
if(instance == null)
{
instance = (Iris) Bukkit.getPluginManager().getPlugin("Iris");
}
if(instance.executionController == null)
{
instance.executionController = new ExecutionController();
instance.executionController.start();
}
return instance.executionController; return instance.executionController;
} }

View File

@ -16,10 +16,10 @@ public class Settings
public ObjectMode objectMode = ObjectMode.PARALLAX; public ObjectMode objectMode = ObjectMode.PARALLAX;
public int threadPriority = Thread.MAX_PRIORITY; public int threadPriority = Thread.MAX_PRIORITY;
public int threadCount = 16; public int threadCount = 16;
public boolean debugMode = true; public boolean debugMode = false;
public int decorationAccuracy = 1; public int decorationAccuracy = 1;
public boolean noObjectFail = false; public boolean noObjectFail = false;
public boolean verbose = true; public boolean verbose = false;
public int placeHistoryLimit = 8192; public int placeHistoryLimit = 8192;
} }

View File

@ -5,6 +5,7 @@ import org.bukkit.entity.Player;
import mortar.bukkit.command.MortarCommand; import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender; import mortar.bukkit.command.MortarSender;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.generator.IrisGenerator; import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.pack.IrisBiome; import ninja.bytecode.iris.pack.IrisBiome;
@ -21,7 +22,7 @@ public class CommandFindBiome extends MortarCommand
{ {
World w = null; World w = null;
if(sender.isPlayer() && sender.player().getWorld().getGenerator() instanceof IrisGenerator) if(sender.isPlayer() && Iris.isGen(sender.player().getWorld()))
{ {
w = sender.player().getWorld(); w = sender.player().getWorld();
} }
@ -38,7 +39,7 @@ public class CommandFindBiome extends MortarCommand
} }
Player p = sender.player(); Player p = sender.player();
IrisGenerator g = (IrisGenerator) w.getGenerator(); IrisGenerator g = Iris.getGen(p.getWorld());
if(args.length > 0) if(args.length > 0)
{ {
IrisBiome b = null; IrisBiome b = null;

View File

@ -7,7 +7,7 @@ import org.bukkit.entity.Player;
import mortar.bukkit.command.MortarCommand; import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender; import mortar.bukkit.command.MortarSender;
import mortar.util.text.C; import mortar.util.text.C;
import ninja.bytecode.iris.generator.IrisGenerator; import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.generator.genobject.PlacedObject; import ninja.bytecode.iris.generator.genobject.PlacedObject;
public class CommandFindObject extends MortarCommand public class CommandFindObject extends MortarCommand
@ -23,7 +23,7 @@ public class CommandFindObject extends MortarCommand
{ {
World w = null; World w = null;
if(sender.isPlayer() && sender.player().getWorld().getGenerator() instanceof IrisGenerator) if(sender.isPlayer() && Iris.isGen(sender.player().getWorld()))
{ {
w = sender.player().getWorld(); w = sender.player().getWorld();
} }
@ -38,7 +38,7 @@ public class CommandFindObject extends MortarCommand
if(args.length > 0) if(args.length > 0)
{ {
PlacedObject o = ((IrisGenerator) w.getGenerator()).randomObject(args[0]); PlacedObject o = Iris.getGen(w).randomObject(args[0]);
if(o != null) if(o != null)
{ {

View File

@ -29,7 +29,7 @@ public class CommandReloadChunks extends MortarCommand
for(Chunk i : p.getWorld().getLoadedChunks()) for(Chunk i : p.getWorld().getLoadedChunks())
{ {
NMP.CHUNK.refresh(p, i); NMP.CHUNK.refreshIgnorePosition(p, i);
} }
return true; return true;

View File

@ -6,6 +6,7 @@ import org.bukkit.World;
import mortar.bukkit.command.MortarCommand; import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender; import mortar.bukkit.command.MortarSender;
import mortar.util.text.C; import mortar.util.text.C;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.generator.IrisGenerator; import ninja.bytecode.iris.generator.IrisGenerator;
public class CommandTimings extends MortarCommand public class CommandTimings extends MortarCommand
@ -21,7 +22,7 @@ public class CommandTimings extends MortarCommand
{ {
World world = null; World world = null;
if(sender.isPlayer() && sender.player().getWorld().getGenerator() instanceof IrisGenerator) if(sender.isPlayer() && Iris.isGen(sender.player().getWorld()))
{ {
world = sender.player().getWorld(); world = sender.player().getWorld();
} }
@ -48,7 +49,7 @@ public class CommandTimings extends MortarCommand
return true; return true;
} }
((IrisGenerator) world.getGenerator()).getMetrics().send(sender, (m) -> sender.sendMessage(m)); Iris.getGen(world).getMetrics().send(sender, (m) -> sender.sendMessage(m));
return true; return true;
} }

View File

@ -6,6 +6,7 @@ import org.bukkit.entity.Player;
import mortar.bukkit.command.MortarCommand; import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender; import mortar.bukkit.command.MortarSender;
import mortar.util.text.C; import mortar.util.text.C;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.generator.IrisGenerator; import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.pack.IrisBiome; import ninja.bytecode.iris.pack.IrisBiome;
import ninja.bytecode.iris.util.BiomeLayer; import ninja.bytecode.iris.util.BiomeLayer;
@ -24,7 +25,7 @@ public class CommandWhatBiome extends MortarCommand
{ {
World world = null; World world = null;
if(sender.isPlayer() && sender.player().getWorld().getGenerator() instanceof IrisGenerator) if(sender.isPlayer() && Iris.isGen(sender.player().getWorld()))
{ {
world = sender.player().getWorld(); world = sender.player().getWorld();
} }
@ -36,7 +37,7 @@ public class CommandWhatBiome extends MortarCommand
} }
Player p = sender.player(); Player p = sender.player();
IrisGenerator g = (IrisGenerator) world.getGenerator(); IrisGenerator g = Iris.getGen(world);
IrisBiome biome = g.getBiome((int) g.getOffsetX(p.getLocation().getX(), p.getLocation().getZ()), (int) g.getOffsetZ(p.getLocation().getX(), p.getLocation().getZ())); IrisBiome biome = g.getBiome((int) g.getOffsetX(p.getLocation().getX(), p.getLocation().getZ()), (int) g.getOffsetZ(p.getLocation().getX(), p.getLocation().getZ()));
BiomeLayer l = new BiomeLayer(g, biome); BiomeLayer l = new BiomeLayer(g, biome);
sender.sendMessage("Biome: " + C.BOLD + C.WHITE + biome.getName() + C.RESET + C.GRAY + " (" + C.GOLD + l.getBiome().getRarityString() + C.GRAY + ")"); sender.sendMessage("Biome: " + C.BOLD + C.WHITE + biome.getName() + C.RESET + C.GRAY + " (" + C.GOLD + l.getBiome().getRarityString() + C.GRAY + ")");

View File

@ -36,7 +36,7 @@ public class CommandWhatObject extends MortarCommand
{ {
World world = null; World world = null;
if(sender.isPlayer() && sender.player().getWorld().getGenerator() instanceof IrisGenerator) if(sender.isPlayer() && Iris.isGen(sender.player().getWorld()))
{ {
world = sender.player().getWorld(); world = sender.player().getWorld();
} }
@ -48,7 +48,7 @@ public class CommandWhatObject extends MortarCommand
} }
Player p = sender.player(); Player p = sender.player();
IrisGenerator generator = (IrisGenerator) world.getGenerator(); IrisGenerator generator = Iris.getGen(world);
Location l = p.getTargetBlock(null, 32).getLocation(); Location l = p.getTargetBlock(null, 32).getLocation();
PlacedObject po = generator.nearest(l, 12); PlacedObject po = generator.nearest(l, 12);

View File

@ -123,6 +123,7 @@ public class IrisGenerator extends ParallaxWorldGenerator
{ {
return; return;
} }
random = new Random(world.getSeed()); random = new Random(world.getSeed());
rTerrain = new RNG(world.getSeed()); rTerrain = new RNG(world.getSeed());
swirl = new CNG(rTerrain.nextParallelRNG(0), 40, 1).scale(0.007); swirl = new CNG(rTerrain.nextParallelRNG(0), 40, 1).scale(0.007);
@ -390,12 +391,23 @@ public class IrisGenerator extends ParallaxWorldGenerator
hl = hl == 0 && !t.equals(Material.AIR) ? i : hl; hl = hl == 0 && !t.equals(Material.AIR) ? i : hl;
} }
plan.setRealHeight(x, z, hl);
plan.setRealWaterHeight(x, z, hw == 0 ? seaLevel : hw);
plan.setBiome(x, z, biome);
if(!surfaceOnly) if(!surfaceOnly)
{ {
glCaves.genCaves(wxxf, wzxf, x, z, data, plan); glCaves.genCaves(wxxf, wzxf, x, z, data, plan);
glOres.genOres(wxxf, wzxf, x, z, hl, data, plan); glOres.genOres(wxxf, wzxf, x, z, hl, data, plan);
} }
for(int i = highest; i > 0; i--)
{
Material t = data.getType(x, i, z);
hw = i > seaLevel && hw == 0 && (t.equals(Material.WATER) || t.equals(Material.STATIONARY_WATER)) ? i : hw;
hl = hl == 0 && !t.equals(Material.AIR) ? i : hl;
}
plan.setRealHeight(x, z, hl); plan.setRealHeight(x, z, hl);
plan.setRealWaterHeight(x, z, hw == 0 ? seaLevel : hw); plan.setRealWaterHeight(x, z, hw == 0 ? seaLevel : hw);
plan.setBiome(x, z, biome); plan.setBiome(x, z, biome);

View File

@ -109,6 +109,11 @@ public class GenLayerBiome extends GenLayer
return true; return true;
} }
if(Borders.isBorderWithin(x, z, 7, 24D, (x + z) / 100D, (xx, zz) -> ocean.getIndex(xx, zz)))
{
return true;
}
if(ocean.getClosestNeighbor(x, z) > 0.2) if(ocean.getClosestNeighbor(x, z) > 0.2)
{ {
return true; return true;
@ -119,11 +124,6 @@ public class GenLayerBiome extends GenLayer
return true; return true;
} }
if(ocean.hasBorder(3, 7, x, z) || ocean.hasBorder(3, 3, x, z))
{
return true;
}
if(channel.hasBorder(3, 7, xf, zf) || channel.hasBorder(3, 3, xf, zf)) if(channel.hasBorder(3, 7, xf, zf) || channel.hasBorder(3, 3, xf, zf))
{ {
return true; return true;

View File

@ -19,15 +19,13 @@ public class GenLayerCaves extends GenLayer
{ {
private PolygonGenerator g; private PolygonGenerator g;
private CNG gincline; private CNG gincline;
private CNG gfract;
public GenLayerCaves(IrisGenerator iris, World world, Random random, RNG rng) public GenLayerCaves(IrisGenerator iris, World world, Random random, RNG rng)
{ {
//@builder //@builder
super(iris, world, random, rng); super(iris, world, random, rng);
g = new PolygonGenerator(rng.nextParallelRNG(1111), 3, 0.014, 1, (c) -> c); g = new PolygonGenerator(rng.nextParallelRNG(1111), 3, 0.024, 8, (c) -> c);
gincline = new CNG(rng.nextParallelRNG(1112), 1D, 3).scale(0.00652); gincline = new CNG(rng.nextParallelRNG(1112), 1D, 3).scale(0.00652);
gfract = new CNG(rng.nextParallelRNG(1113), 24D, 1).scale(0.0152);
//@done //@done
} }
@ -37,22 +35,20 @@ public class GenLayerCaves extends GenLayer
return gnoise; return gnoise;
} }
public void genCaves(double xxf, double zzf, int x, int z, AtomicChunkData data, ChunkPlan plan) public void genCaves(double wxxf, double wzxf, int x, int z, AtomicChunkData data, ChunkPlan plan)
{ {
PrecisionStopwatch s = PrecisionStopwatch.start(); PrecisionStopwatch s = PrecisionStopwatch.start();
int wxxf = (int) (xxf + gfract.noise(xxf, zzf));
int wzxf = (int) (zzf - gfract.noise(zzf, xxf));
double itr = 2; double itr = 2;
double level = 8; double level = 8;
double incline = 157; double incline = 157;
double baseWidth = 11; double baseWidth = 11;
double drop = 35; double drop = 46;
for(double m = 1; m <= itr; m += 0.65) for(double m = 1; m <= itr; m += 0.45)
{ {
double w = baseWidth / m; double w = baseWidth / m;
if(w < 3.5) if(w < 5)
{ {
break; break;
} }

View File

@ -51,10 +51,10 @@ public class GenLayerCliffs extends GenLayer
continue; continue;
} }
double var = 6.2 * block; double var = 12.2 * block;
double varCombined = 15.45 * block; double varCombined = 15.45 * block;
double sep = (shift / 1.8D) * block; double sep = (shift / 1.8D) * block;
double height = (47 + (i * shift)) * block; double height = (67 + (i * shift)) * block;
double sh = ((gen.noise(dx + dz, dz - dx) - 0.5D) * 2D) * varCombined; double sh = ((gen.noise(dx + dz, dz - dx) - 0.5D) * 2D) * varCombined;
double shv = ((gen.noise(dz + dx, dx - dz) - 0.5D) * 2D) * varCombined; double shv = ((gen.noise(dz + dx, dx - dz) - 0.5D) * 2D) * varCombined;
double lo = (gen.noise(dx + (i * -1000), dz + (i * 1000)) * var) + height + sh; double lo = (gen.noise(dx + (i * -1000), dz + (i * 1000)) * var) + height + sh;

View File

@ -1,7 +1,6 @@
package ninja.bytecode.iris.generator.placer; package ninja.bytecode.iris.generator.placer;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block;
import ninja.bytecode.iris.generator.IrisGenerator; import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.generator.parallax.ParallaxCache; import ninja.bytecode.iris.generator.parallax.ParallaxCache;

View File

@ -0,0 +1,74 @@
package ninja.bytecode.iris.util;
import java.util.List;
import java.util.Random;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
import ninja.bytecode.iris.generator.IrisGenerator;
@SuppressWarnings("deprecation")
public class HotswapGenerator extends ChunkGenerator
{
private IrisGenerator gen;
public HotswapGenerator(IrisGenerator gen)
{
setGenerator(gen);
}
public void setGenerator(IrisGenerator gen)
{
this.gen = gen;
}
public IrisGenerator getGenerator()
{
return gen;
}
@Override
public byte[] generate(World world, Random random, int x, int z)
{
return gen.generate(world, random, x, z);
}
@Override
public short[][] generateExtBlockSections(World world, Random random, int x, int z, BiomeGrid biomes)
{
return gen.generateExtBlockSections(world, random, x, z, biomes);
}
@Override
public byte[][] generateBlockSections(World world, Random random, int x, int z, BiomeGrid biomes)
{
return gen.generateBlockSections(world, random, x, z, biomes);
}
@Override
public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome)
{
return gen.generateChunkData(world, random, x, z, biome);
}
@Override
public boolean canSpawn(World world, int x, int z)
{
return gen.canSpawn(world, x, z);
}
@Override
public List<BlockPopulator> getDefaultPopulators(World world)
{
return gen.getDefaultPopulators(world);
}
@Override
public Location getFixedSpawnLocation(World world, Random random)
{
return gen.getFixedSpawnLocation(world, random);
}
}