This commit is contained in:
Daniel Mills 2020-03-16 11:55:17 -04:00
parent ba9cb41d47
commit 59f29eb6b4
144 changed files with 1335 additions and 19970 deletions

18
pom.xml
View File

@ -144,26 +144,16 @@
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>ninja.bytecode</groupId>
<artifactId>Shuriken</artifactId>
<version>1.1.14</version>
</dependency>
<dependency>
<groupId>com.volmit</groupId>
<artifactId>Mortar</artifactId>
<version>1.0.76</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<version>1.15.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bukkit.craftbukkit</groupId>
<artifactId>cb-1.12.2</artifactId>
<version>1.12.2</version>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.15.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

View File

@ -1,200 +1,61 @@
package ninja.bytecode.iris;
import java.io.File;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Difficulty;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.WorldCreator;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import mortar.api.rift.PhantomRift;
import mortar.api.rift.Rift;
import mortar.api.rift.RiftException;
import mortar.bukkit.command.Command;
import mortar.bukkit.plugin.Control;
import mortar.bukkit.plugin.MortarPlugin;
import mortar.util.text.C;
import ninja.bytecode.iris.command.CommandIris;
import ninja.bytecode.iris.controller.ExecutionController;
import ninja.bytecode.iris.controller.PackController;
import ninja.bytecode.iris.controller.WandController;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.util.Direction;
import ninja.bytecode.iris.util.HotswapGenerator;
import ninja.bytecode.iris.util.IrisMetrics;
import ninja.bytecode.shuriken.logging.L;
public class Iris extends MortarPlugin
public class Iris extends JavaPlugin
{
public static Thread primaryThread;
public static Settings settings;
public static IrisMetrics metrics;
private static ExecutionController executionController;
public static Iris instance;
@Control
private PackController packController;
@Control
private WandController wandController;
@Command
private CommandIris commandIris;
private Rift r;
@Override
public void onEnable()
{
instance = this;
executionController = new ExecutionController();
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();
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () ->
{
for(World i : Bukkit.getWorlds())
{
if(i.getName().startsWith("iris/"))
{
Bukkit.unloadWorld(i, false);
}
}
public File getObjectCacheFolder()
{
return getDataFolder("cache", "object");
}
public static boolean isGen(World world)
{
IrisGenerator g = getGen(world);
return g != null;
}
public static IrisGenerator getGen(World world)
{
try
{
return (IrisGenerator) ((HotswapGenerator) world.getGenerator()).getGenerator();
}
catch(Throwable e)
{
}
return null;
}
@Override
public void start()
{
instance = this;
packController.compile();
if(Iris.settings.performance.debugMode)
{
try
{
//@builder
r = new PhantomRift("Iris-Debug/" + UUID.randomUUID().toString())
.setTileTickLimit(0.1)
.setEntityTickLimit(0.1)
.setAllowBosses(false)
.setEnvironment(Environment.NORMAL)
.setDifficulty(Difficulty.PEACEFUL)
.setRandomLightUpdates(false)
.setViewDistance(32)
.setHangingTickRate(2000)
.setGenerator(IrisGenerator.class)
.load();
World world = Bukkit.createWorld(new WorldCreator("iris/" + UUID.randomUUID()).generator(new IrisGenerator()));
for(Player i : Bukkit.getOnlinePlayers())
{
r.send(i);
i.teleport(new Location(world, 0, 100, 0));
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () ->
{
i.setGameMode(GameMode.SPECTATOR);
}, 5);
}
//@done
});
}
catch(RiftException e)
public void onDisable()
{
e.printStackTrace();
}
}
}
@Override
public void stop()
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if(settings.performance.debugMode && r != null)
{
r.colapse();
}
HandlerList.unregisterAll((Plugin) this);
Bukkit.getScheduler().cancelTasks(this);
executionController.stop();
}
@EventHandler
public void on(PlayerJoinEvent e)
{
if(settings.performance.debugMode && r != null)
{
e.getPlayer().teleport(r.getSpawn());
}
}
public void reload()
{
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () ->
{
onDisable();
onEnable();
});
return false;
}
@Override
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id)
{
return new HotswapGenerator(new IrisGenerator());
}
@Override
public String getTag(String arg0)
{
return makeTag(C.GREEN, C.DARK_GRAY, C.GRAY, C.BOLD + "Iris" + C.RESET);
}
public static String makeTag(C brace, C tag, C text, String tagName)
{
return brace + "\u3008" + tag + tagName + brace + "\u3009" + " " + text;
}
public static PackController pack()
{
return instance.packController;
}
public static ExecutionController exec()
{
if(executionController == null)
{
executionController = new ExecutionController();
executionController.start();
}
return executionController;
}
public static WandController wand()
{
return instance.wandController;
return new IrisGenerator();
}
}

View File

@ -0,0 +1,84 @@
package ninja.bytecode.iris;
import java.util.List;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
import ninja.bytecode.iris.util.ING;
import ninja.bytecode.iris.util.RNG;
public class IrisGenerator extends ChunkGenerator
{
private boolean initialized = false;
private ING sng;
public void onInit()
{
if(initialized)
{
return;
}
initialized = true;
sng = new ING(new RNG(), 2);
}
@Override
public boolean canSpawn(World world, int x, int z)
{
return super.canSpawn(world, x, z);
}
@Override
public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome)
{
onInit();
ChunkData data = Bukkit.createChunkData(world);
for(int i = 0; i < 16; i++)
{
for(int j = 0; j < 16; j++)
{
double wx = (x * 16) + i;
double wz = (z * 16) + j;
int y = (int) Math.round(sng.noise(wx / 30D, wz / 30D) * 20);
for(int k = 0; k < 4; k++)
{
if(k < 0)
{
continue;
}
data.setBlock(i, k + y, j, Material.STONE.createBlockData());
}
}
}
return data;
}
@Override
public List<BlockPopulator> getDefaultPopulators(World world)
{
return super.getDefaultPopulators(world);
}
@Override
public Location getFixedSpawnLocation(World world, Random random)
{
return super.getFixedSpawnLocation(world, random);
}
@Override
public boolean isParallelCapable()
{
return true;
}
}

View File

@ -1,87 +0,0 @@
package ninja.bytecode.iris;
import ninja.bytecode.iris.util.InterpolationMode;
import ninja.bytecode.iris.util.ObjectMode;
import ninja.bytecode.iris.util.PerformanceMode;
public class Settings
{
public PerformanceSettings performance = new PerformanceSettings();
public GeneratorSettings gen = new GeneratorSettings();
public OreSettings ore = new OreSettings();
public static class PerformanceSettings
{
public PerformanceMode performanceMode = PerformanceMode.EXPLICIT;
public ObjectMode objectMode = ObjectMode.PARALLAX;
public int threadPriority = Thread.MAX_PRIORITY;
public int threadCount = 32;
public boolean debugMode = true;
public int decorationAccuracy = 1;
public boolean noObjectFail = false;
public boolean verbose = false;
public int placeHistoryLimit = 8192;
}
public static class GeneratorSettings
{
public InterpolationMode interpolationMode = InterpolationMode.BILINEAR;
public int interpolationRadius = 53;
public int blockSmoothing = 1;
public double objectDensity = 1D;
public double horizontalZoom = 2;
public double heightFracture = 155;
public double landScale = 0.44;
public double landChance = 0.56;
public double roughness = 1.25;
public double biomeEdgeFuzzScale = 1.75;
public double biomeEdgeScrambleScale = 0.2;
public double biomeEdgeScrambleRange = 2.5;
public double heightMultiplier = 0.806;
public double heightExponentBase = 1;
public double heightExponentMultiplier = 1.41;
public double heightScale = 0.56;
public double baseHeight = 0.065;
public int seaLevel = 63;
public double biomeScale = 0.8;
public boolean flatBedrock = false;
}
public static class OreSettings
{
public int ironMinHeight = 5;
public int ironMaxHeight = 65;
public double ironMaxDispersion = 0.02;
public double ironMinDispersion = 0.26;
public int coalMinHeight = 5;
public int coalMaxHeight = 100;
public double coalMaxDispersion = 0.02;
public double coalMinDispersion = 0.29;
public int goldMinHeight = 5;
public int goldMaxHeight = 34;
public double goldMaxDispersion = 0.01;
public double goldMinDispersion = 0.13;
public int redstoneMinHeight = 5;
public int redstoneMaxHeight = 15;
public double redstoneMaxDispersion = 0.05;
public double redstoneMinDispersion = 0.17;
public int lapisMinHeight = 13;
public int lapisMaxHeight = 33;
public double lapisMaxDispersion = 0.05;
public double lapisMinDispersion = 0.12;
public int diamondMinHeight = 5;
public int diamondMaxHeight = 16;
public double diamondMaxDispersion = 0.05;
public double diamondMinDispersion = 0.1;
public int emeraldMinHeight = 5;
public int emeraldMaxHeight = 16;
public double emeraldMaxDispersion = 0.005;
public double emeraldMinDispersion = 0.07;
}
}

View File

@ -1,33 +0,0 @@
package ninja.bytecode.iris.command;
import mortar.bukkit.command.Command;
import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender;
import mortar.util.text.C;
public class CommandFind extends MortarCommand
{
@Command
private CommandFindBiome fBiome;
@Command
private CommandFindObject fObject;
public CommandFind()
{
super("find", "f");
setDescription("Teleport to a specific biome / object");
}
@Override
public boolean handle(MortarSender sender, String[] args)
{
for(MortarCommand i : getChildren())
{
sender.sendMessage("/iris find " + C.WHITE + i.getNode() + C.GRAY + (!i.getNodes().isEmpty() ? "," : "") + i.getNodes().toString(",") + " - " + C.DARK_GREEN + i.getDescription());
}
return true;
}
}

View File

@ -1,93 +0,0 @@
package ninja.bytecode.iris.command;
import org.bukkit.World;
import org.bukkit.entity.Player;
import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.pack.IrisBiome;
public class CommandFindBiome extends MortarCommand
{
public CommandFindBiome()
{
super("biome", "b");
setDescription("Teleport to a biome by name");
}
@Override
public boolean handle(MortarSender sender, String[] args)
{
World w = null;
if(sender.isPlayer() && Iris.isGen(sender.player().getWorld()))
{
w = sender.player().getWorld();
}
else
{
if(sender.isPlayer())
{
sender.sendMessage(sender.player().getWorld().getGenerator().getClass().getCanonicalName());
}
sender.sendMessage("Console / Non-Iris World.");
return true;
}
Player p = sender.player();
IrisGenerator g = Iris.getGen(p.getWorld());
if(args.length > 0)
{
IrisBiome b = null;
for(IrisBiome i : g.getDimension().getBiomes())
{
if(args[0].toLowerCase().equals(i.getName().toLowerCase().replaceAll("\\Q \\E", "_")))
{
b = i;
break;
}
}
if(b == null)
{
sender.sendMessage("Couldn't find any biomes containing '" + args[0] + "'.");
}
else
{
sender.sendMessage("Looking for Biome " + b.getName() + "...");
boolean f = false;
for(int i = 0; i < 10000; i++)
{
int x = (int) ((int) (29999983 / 1.2) * Math.random());
int z = (int) ((int) (29999983 / 1.2) * Math.random());
if(g.getBiome((int) g.getOffsetX(x, z), (int) g.getOffsetZ(x, z)).equals(b))
{
f = true;
p.teleport(w.getHighestBlockAt(x, z).getLocation());
break;
}
}
if(!f)
{
sender.sendMessage("Couldn't for " + b.getName() + " in 10,000 different locations and could not find it. Try again!");
}
}
}
else
{
sender.sendMessage("/iris find biome <query>");
}
return true;
}
}

View File

@ -1,64 +0,0 @@
package ninja.bytecode.iris.command;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender;
import mortar.util.text.C;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.generator.genobject.PlacedObject;
public class CommandFindObject extends MortarCommand
{
public CommandFindObject()
{
super("object", "o");
setDescription("Teleport to an object by name");
}
@Override
public boolean handle(MortarSender sender, String[] args)
{
World w = null;
if(sender.isPlayer() && Iris.isGen(sender.player().getWorld()))
{
w = sender.player().getWorld();
}
else
{
sender.sendMessage("Console / Non-Iris World.");
return true;
}
Player p = sender.player();
if(args.length > 0)
{
PlacedObject o = Iris.getGen(w).randomObject(args[0]);
if(o != null)
{
Location l = new Location(w, o.getX(), o.getY(), o.getZ());
p.teleport(l);
sender.sendMessage("Found Object " + C.DARK_GREEN + o.getF().replace(":", "/" + C.WHITE));
}
else
{
sender.sendMessage("Couldn't find any objects containing '" + args[0] + "' Either");
}
}
else
{
sender.sendMessage("/iris find object <query>");
}
return true;
}
}

View File

@ -1,44 +0,0 @@
package ninja.bytecode.iris.command;
import mortar.bukkit.command.Command;
import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender;
import mortar.util.text.C;
public class CommandIris extends MortarCommand
{
@Command
private CommandTimings timings;
@Command
private CommandWhat what;
@Command
private CommandFind find;
@Command
private CommandObject object;
@Command
private CommandSelection selection;
@Command
private CommandReload reload;
public CommandIris()
{
super("iris", "irs", "ir");
}
@Override
public boolean handle(MortarSender sender, String[] args)
{
for(MortarCommand i : getChildren())
{
sender.sendMessage("/iris " + C.WHITE + i.getNode() + C.GRAY + (!i.getNodes().isEmpty() ? "," : "") + i.getNodes().toString(",") + " - " + C.DARK_GREEN + i.getDescription());
}
return true;
}
}

View File

@ -1,36 +0,0 @@
package ninja.bytecode.iris.command;
import mortar.bukkit.command.Command;
import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender;
import mortar.util.text.C;
public class CommandObject extends MortarCommand
{
@Command
private CommandObjectWand oWand;
@Command
private CommandObjectLoad oLoad;
@Command
private CommandObjectSave oSave;
public CommandObject()
{
super("object", "o");
setDescription("Object Subcommands");
}
@Override
public boolean handle(MortarSender sender, String[] args)
{
for(MortarCommand i : getChildren())
{
sender.sendMessage("/iris object " + C.WHITE + i.getNode() + C.GRAY + (!i.getNodes().isEmpty() ? "," : "") + i.getNodes().toString(",") + " - " + C.DARK_GREEN + i.getDescription());
}
return true;
}
}

View File

@ -1,166 +0,0 @@
package ninja.bytecode.iris.command;
import java.io.File;
import java.io.FileInputStream;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender;
import mortar.util.text.C;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.controller.WandController;
import ninja.bytecode.iris.generator.genobject.GenObject;
import ninja.bytecode.iris.util.Direction;
import ninja.bytecode.shuriken.format.Form;
public class CommandObjectLoad extends MortarCommand
{
public CommandObjectLoad()
{
super("load", "l");
setDescription("Load & Paste an object");
}
@Override
public boolean handle(MortarSender sender, String[] args)
{
if(!sender.isPlayer())
{
sender.sendMessage("Players Only");
return true;
}
if(args.length < 1)
{
sender.sendMessage("/iris object load <name>");
sender.sendMessage("Use -c to place at cursor");
sender.sendMessage("Use -g to place with gravity");
sender.sendMessage("Use -w to set hydrophilic");
sender.sendMessage("Use -u to set submerged");
sender.sendMessage("Use -h:<int> to shift vertically");
sender.sendMessage("Use -m:<int> to set max slope");
sender.sendMessage("Use -b:<int> to set base slope");
sender.sendMessage("Use -f:N -t:S to rotate north to south (180 deg)");
return true;
}
Player p = sender.player();
GenObject s = new GenObject(1, 1, 1);
File f = new File(Iris.instance.getDataFolder(), "schematics/" + args[0] + ".ish");
if(!f.exists())
{
sender.sendMessage("Can't find " + args[0]);
return true;
}
try
{
FileInputStream fin = new FileInputStream(f);
s.read(fin, true);
boolean cursor = false;
boolean gravity = false;
Direction df = null;
Direction dt = null;
int shift = 0;
for(String i : args)
{
if(i.equalsIgnoreCase("-c"))
{
sender.sendMessage("Placing @ Cursor");
cursor = true;
continue;
}
if(i.equalsIgnoreCase("-u"))
{
sender.sendMessage("Placing Submerged");
s.setSubmerged(true);
continue;
}
if(i.equalsIgnoreCase("-w"))
{
sender.sendMessage("Placing with Hydrophilia");
s.setHydrophilic(true);
continue;
}
if(i.equalsIgnoreCase("-g"))
{
sender.sendMessage("Placing with Gravity");
gravity = true;
continue;
}
if(i.startsWith("-m:"))
{
shift = Integer.valueOf(i.split("\\Q:\\E")[1]);
sender.sendMessage("Max Slope set to " + shift);
s.setMaxslope(shift);
continue;
}
if(i.startsWith("-b:"))
{
shift = Integer.valueOf(i.split("\\Q:\\E")[1]);
sender.sendMessage("Base Slope set to " + shift);
s.setBaseslope(shift);
continue;
}
if(i.startsWith("-h:"))
{
shift = Integer.valueOf(i.split("\\Q:\\E")[1]);
sender.sendMessage("Shifting Placement by 0," + shift + ",0");
continue;
}
if(i.startsWith("-f:"))
{
df = Direction.valueOf(i.split("\\Q:\\E")[1].toUpperCase().substring(0, 1));
continue;
}
if(i.startsWith("-t:"))
{
dt = Direction.valueOf(i.split("\\Q:\\E")[1].toUpperCase().substring(0, 1));
continue;
}
}
if(dt != null && df != null)
{
sender.sendMessage("Rotating " + C.WHITE + df + C.GRAY + " to " + C.WHITE + dt);
s.rotate(df, dt);
}
Location at = p.getLocation();
if(cursor)
{
at = p.getTargetBlock(null, 64).getLocation();
}
s.setShift(0, shift, 0);
s.setGravity(gravity);
WandController.pasteSchematic(s, at);
p.playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.25f);
sender.sendMessage("Pasted " + args[0] + " (" + Form.f(s.getSchematic().size()) + " Blocks Modified)");
}
catch(Throwable e1)
{
e1.printStackTrace();
}
return true;
}
}

View File

@ -1,67 +0,0 @@
package ninja.bytecode.iris.command;
import java.io.File;
import java.io.FileOutputStream;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.controller.WandController;
import ninja.bytecode.iris.generator.genobject.GenObject;
import ninja.bytecode.shuriken.format.Form;
public class CommandObjectSave extends MortarCommand
{
public CommandObjectSave()
{
super("save", "s");
setDescription("Save an object");
}
@Override
public boolean handle(MortarSender sender, String[] args)
{
if(!sender.isPlayer())
{
sender.sendMessage("Players Only");
return true;
}
if(args.length < 1)
{
sender.sendMessage("/iris object save <name>");
return true;
}
Player p = sender.player();
GenObject s = WandController.createSchematic(p.getInventory().getItemInMainHand(), p.getLocation());
if(s == null)
{
sender.sendMessage("Hold your wand while using this command.");
return true;
}
File f = new File(Iris.instance.getDataFolder(), "schematics/" + args[0] + ".ish");
f.getParentFile().mkdirs();
try
{
FileOutputStream fos = new FileOutputStream(f);
s.write(fos, true);
p.sendMessage("Saved " + args[0] + " (" + Form.f(s.getSchematic().size()) + " Entries)");
p.playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 0.45f);
}
catch(Throwable e1)
{
p.sendMessage("Failed. Check the console!");
e1.printStackTrace();
}
return true;
}
}

View File

@ -1,32 +0,0 @@
package ninja.bytecode.iris.command;
import org.bukkit.Sound;
import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender;
import ninja.bytecode.iris.controller.WandController;
public class CommandObjectWand extends MortarCommand
{
public CommandObjectWand()
{
super("wand", "w");
setDescription("Obtain Iris Wand");
}
@Override
public boolean handle(MortarSender sender, String[] args)
{
if(!sender.isPlayer())
{
sender.sendMessage("Players Only");
return true;
}
sender.player().getInventory().addItem(WandController.createWand());
sender.player().playSound(sender.player().getLocation(), Sound.ITEM_ARMOR_EQUIP_DIAMOND, 1f, 1.55f);
return true;
}
}

View File

@ -1,36 +0,0 @@
package ninja.bytecode.iris.command;
import mortar.bukkit.command.Command;
import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender;
import mortar.util.text.C;
public class CommandReload extends MortarCommand
{
@Command
private CommandReloadPack rThis;
@Command
private CommandReloadChunks rChunks;
@Command
private CommandReloadIris rIris;
public CommandReload()
{
super("reload", "r");
setDescription("Reload Chunks / Pack / Iris");
}
@Override
public boolean handle(MortarSender sender, String[] args)
{
for(MortarCommand i : getChildren())
{
sender.sendMessage("/iris reload " + C.WHITE + i.getNode() + C.GRAY + (!i.getNodes().isEmpty() ? "," : "") + i.getNodes().toString(",") + " - " + C.DARK_GREEN + i.getDescription());
}
return true;
}
}

View File

@ -1,38 +0,0 @@
package ninja.bytecode.iris.command;
import org.bukkit.Chunk;
import org.bukkit.entity.Player;
import mortar.api.nms.NMP;
import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender;
public class CommandReloadChunks extends MortarCommand
{
public CommandReloadChunks()
{
super("chunks", "c");
setDescription("Resends chunk packets.");
}
@Override
public boolean handle(MortarSender sender, String[] args)
{
if(!sender.isPlayer())
{
sender.sendMessage("Again, You don't have a position. Stop it.");
}
sender.sendMessage("Resending Chunks in your view distance.");
Player p = sender.player();
for(Chunk i : p.getWorld().getLoadedChunks())
{
NMP.CHUNK.refreshIgnorePosition(p, i);
}
return true;
}
}

View File

@ -1,23 +0,0 @@
package ninja.bytecode.iris.command;
import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender;
import ninja.bytecode.iris.Iris;
public class CommandReloadIris extends MortarCommand
{
public CommandReloadIris()
{
super("iris", "i");
setDescription("Reloads Iris");
}
@Override
public boolean handle(MortarSender sender, String[] args)
{
Iris.instance.reload();
return true;
}
}

View File

@ -1,142 +0,0 @@
package ninja.bytecode.iris.command;
import java.util.function.Consumer;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
import mortar.api.sched.J;
import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender;
import mortar.logic.queue.ChronoLatch;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.controller.PackController;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.generator.WorldReactor;
import ninja.bytecode.iris.pack.CompiledDimension;
import ninja.bytecode.shuriken.collections.KList;
import ninja.bytecode.shuriken.collections.KMap;
import ninja.bytecode.shuriken.format.Form;
import ninja.bytecode.shuriken.logging.L;
public class CommandReloadPack extends MortarCommand
{
public CommandReloadPack()
{
super("pack", "p");
setDescription("Reloads the pack + regen");
}
@Override
public boolean handle(MortarSender sender, String[] args)
{
sender.sendMessage("=== Hotloading Pack ===");
PackController c = Iris.pack();
KMap<String, String> f = new KMap<>();
for(World i : Bukkit.getWorlds())
{
if(i.getGenerator() instanceof IrisGenerator)
{
String n = ((IrisGenerator) i.getGenerator()).getDimension().getName();
sender.sendMessage("Preparing " + n);
f.put(i.getName(), n);
}
}
if(f.isEmpty())
{
sender.sendMessage("No Worlds to inject!");
return true;
}
J.a(() ->
{
try
{
Consumer<String> m = (msg) ->
{
J.s(() ->
{
String mm = msg;
if(msg.contains("|"))
{
KList<String> fx = new KList<>();
fx.add(msg.split("\\Q|\\E"));
fx.remove(0);
fx.remove(0);
mm = fx.toString("");
}
sender.sendMessage(mm.replaceAll("\\Q \\E", ""));
});
};
L.addLogConsumer(m);
c.compile();
L.logConsumers.remove(m);
J.s(() ->
{
if(sender.isPlayer())
{
ChronoLatch cl = new ChronoLatch(3000);
Player p = sender.player();
World ww = sender.player().getWorld();
sender.sendMessage("Regenerating View Distance");
WorldReactor r = new WorldReactor(ww);
r.generateRegionNormal(p, true, 200, (pct) ->
{
if(cl.flip())
{
sender.sendMessage("Regenerating " + Form.pc(pct));
}
}, () ->
{
sender.sendMessage("Done! Use F3 + A");
});
}
}, 5);
for(String fi : f.k())
{
J.s(() ->
{
World i = Bukkit.getWorld(fi);
CompiledDimension dim = c.getDimension(f.get(fi));
for(String k : c.getDimensions().k())
{
if(c.getDimension(k).getName().equals(f.get(fi)))
{
dim = c.getDimension(k);
break;
}
}
if(dim == null)
{
J.s(() -> sender.sendMessage("Cannot find dimnension: " + f.get(fi)));
return;
}
sender.sendMessage("Hotloaded " + i.getName());
IrisGenerator g = ((IrisGenerator) i.getGenerator());
g.inject(dim);
});
}
}
catch(Throwable e)
{
e.printStackTrace();
}
});
return true;
}
}

View File

@ -1,42 +0,0 @@
package ninja.bytecode.iris.command;
import mortar.bukkit.command.Command;
import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender;
import mortar.util.text.C;
public class CommandSelection extends MortarCommand
{
@Command
private CommandSelectionExpand expand;
@Command
private CommandSelectionShift shift;
@Command
private CommandSelectionShrink shr;
@Command
private CommandSelectionXUp xip;
@Command
private CommandSelectionXVert xvc;
public CommandSelection()
{
super("selection", "sel", "s");
setDescription("Wand Selection Subcommands");
}
@Override
public boolean handle(MortarSender sender, String[] args)
{
for(MortarCommand i : getChildren())
{
sender.sendMessage("/iris sel " + C.WHITE + i.getNode() + C.GRAY + (!i.getNodes().isEmpty() ? "," : "") + i.getNodes().toString(",") + " - " + C.DARK_GREEN + i.getDescription());
}
return true;
}
}

View File

@ -1,60 +0,0 @@
package ninja.bytecode.iris.command;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender;
import ninja.bytecode.iris.controller.WandController;
import ninja.bytecode.iris.util.Cuboid;
import ninja.bytecode.iris.util.Direction;
public class CommandSelectionExpand extends MortarCommand
{
public CommandSelectionExpand()
{
super("expand", "+");
setDescription("Expand in looking direction");
}
@Override
public boolean handle(MortarSender sender, String[] args)
{
if(!sender.isPlayer())
{
sender.sendMessage("Players Only");
return true;
}
Player p = sender.player();
if(!WandController.isWand(p))
{
sender.sendMessage("Ready your Wand.");
return true;
}
if(args.length == 0)
{
sender.sendMessage("/iris selection expand <amount>");
return true;
}
int amt = Integer.valueOf(args[0]);
Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand());
Location a1 = b[0].clone();
Location a2 = b[1].clone();
Cuboid cursor = new Cuboid(a1, a2);
Direction d = Direction.closest(p.getLocation().getDirection()).reverse();
cursor = cursor.expand(d, amt);
b[0] = cursor.getLowerNE();
b[1] = cursor.getUpperSW();
p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1]));
p.updateInventory();
p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f);
return true;
}
}

View File

@ -1,61 +0,0 @@
package ninja.bytecode.iris.command;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender;
import ninja.bytecode.iris.controller.WandController;
import ninja.bytecode.iris.util.Cuboid;
import ninja.bytecode.iris.util.Direction;
public class CommandSelectionShift extends MortarCommand
{
public CommandSelectionShift()
{
super("shift", ">");
setDescription("Shift looking direction");
}
@Override
public boolean handle(MortarSender sender, String[] args)
{
if(!sender.isPlayer())
{
sender.sendMessage("Players Only");
return true;
}
Player p = sender.player();
if(!WandController.isWand(p))
{
sender.sendMessage("Ready your Wand.");
return true;
}
if(args.length == 0)
{
sender.sendMessage("/iris selection shift <amount>");
return true;
}
int amt = Integer.valueOf(args[0]);
Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand());
Location a1 = b[0].clone();
Location a2 = b[1].clone();
Direction d = Direction.closest(p.getLocation().getDirection()).reverse();
a1.add(d.toVector().multiply(amt));
a2.add(d.toVector().multiply(amt));
Cuboid cursor = new Cuboid(a1, a2);
b[0] = cursor.getLowerNE();
b[1] = cursor.getUpperSW();
p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1]));
p.updateInventory();
p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f);
return true;
}
}

View File

@ -1,57 +0,0 @@
package ninja.bytecode.iris.command;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender;
import ninja.bytecode.iris.controller.WandController;
import ninja.bytecode.iris.util.Cuboid;
import ninja.bytecode.iris.util.Cuboid.CuboidDirection;
public class CommandSelectionShrink extends MortarCommand
{
public CommandSelectionShrink()
{
super("shrinkwrap", "shrink");
setDescription("Match blocks boundary");
}
@Override
public boolean handle(MortarSender sender, String[] args)
{
if(!sender.isPlayer())
{
sender.sendMessage("Players Only");
return true;
}
Player p = sender.player();
if(!WandController.isWand(p))
{
sender.sendMessage("Ready your Wand.");
return true;
}
Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand());
Location a1 = b[0].clone();
Location a2 = b[1].clone();
Cuboid cursor = new Cuboid(a1, a2);
cursor = cursor.contract(CuboidDirection.North);
cursor = cursor.contract(CuboidDirection.South);
cursor = cursor.contract(CuboidDirection.East);
cursor = cursor.contract(CuboidDirection.West);
cursor = cursor.contract(CuboidDirection.Up);
cursor = cursor.contract(CuboidDirection.Down);
b[0] = cursor.getLowerNE();
b[1] = cursor.getUpperSW();
p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1]));
p.updateInventory();
p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f);
return true;
}
}

View File

@ -1,72 +0,0 @@
package ninja.bytecode.iris.command;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender;
import ninja.bytecode.iris.controller.WandController;
import ninja.bytecode.iris.util.Cuboid;
import ninja.bytecode.iris.util.Cuboid.CuboidDirection;
public class CommandSelectionXUp extends MortarCommand
{
public CommandSelectionXUp()
{
super("expandup", "xup");
setDescription("Expand Up & Trim In");
}
@Override
public boolean handle(MortarSender sender, String[] args)
{
if(!sender.isPlayer())
{
sender.sendMessage("Players Only");
return true;
}
Player p = sender.player();
if(!WandController.isWand(p))
{
sender.sendMessage("Ready your Wand.");
return true;
}
Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand());
b[0].add(new Vector(0, 1, 0));
b[1].add(new Vector(0, 1, 0));
Location a1 = b[0].clone();
Location a2 = b[1].clone();
Cuboid cursor = new Cuboid(a1, a2);
while(!cursor.containsOnly(Material.AIR))
{
a1.add(new Vector(0, 1, 0));
a2.add(new Vector(0, 1, 0));
cursor = new Cuboid(a1, a2);
}
a1.add(new Vector(0, -1, 0));
a2.add(new Vector(0, -1, 0));
b[0] = a1;
a2 = b[1];
cursor = new Cuboid(a1, a2);
cursor = cursor.contract(CuboidDirection.North);
cursor = cursor.contract(CuboidDirection.South);
cursor = cursor.contract(CuboidDirection.East);
cursor = cursor.contract(CuboidDirection.West);
b[0] = cursor.getLowerNE();
b[1] = cursor.getUpperSW();
p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1]));
p.updateInventory();
p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f);
return true;
}
}

View File

@ -1,83 +0,0 @@
package ninja.bytecode.iris.command;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender;
import ninja.bytecode.iris.controller.WandController;
import ninja.bytecode.iris.util.Cuboid;
import ninja.bytecode.iris.util.Cuboid.CuboidDirection;
public class CommandSelectionXVert extends MortarCommand
{
public CommandSelectionXVert()
{
super("expandvertical", "xvert");
setDescription("Expand Up + Down & Trim In");
}
@Override
public boolean handle(MortarSender sender, String[] args)
{
if(!sender.isPlayer())
{
sender.sendMessage("Players Only");
return true;
}
Player p = sender.player();
if(!WandController.isWand(p))
{
sender.sendMessage("Ready your Wand.");
return true;
}
Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand());
Location a1 = b[0].clone();
Location a2 = b[1].clone();
Location a1x = b[0].clone();
Location a2x = b[1].clone();
Cuboid cursor = new Cuboid(a1, a2);
Cuboid cursorx = new Cuboid(a1, a2);
while(!cursor.containsOnly(Material.AIR))
{
a1.add(new Vector(0, 1, 0));
a2.add(new Vector(0, 1, 0));
cursor = new Cuboid(a1, a2);
}
a1.add(new Vector(0, -1, 0));
a2.add(new Vector(0, -1, 0));
while(!cursorx.containsOnly(Material.AIR))
{
a1x.add(new Vector(0, -1, 0));
a2x.add(new Vector(0, -1, 0));
cursorx = new Cuboid(a1x, a2x);
}
a1x.add(new Vector(0, 1, 0));
a2x.add(new Vector(0, 1, 0));
b[0] = a1;
b[1] = a2x;
cursor = new Cuboid(b[0], b[1]);
cursor = cursor.contract(CuboidDirection.North);
cursor = cursor.contract(CuboidDirection.South);
cursor = cursor.contract(CuboidDirection.East);
cursor = cursor.contract(CuboidDirection.West);
b[0] = cursor.getLowerNE();
b[1] = cursor.getUpperSW();
p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1]));
p.updateInventory();
p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f);
return true;
}
}

View File

@ -1,57 +0,0 @@
package ninja.bytecode.iris.command;
import org.bukkit.Bukkit;
import org.bukkit.World;
import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender;
import mortar.util.text.C;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.generator.IrisGenerator;
public class CommandTimings extends MortarCommand
{
public CommandTimings()
{
super("timings", "t");
setDescription("Tick use on a per chunk basis");
}
@Override
public boolean handle(MortarSender sender, String[] args)
{
World world = null;
if(sender.isPlayer() && Iris.isGen(sender.player().getWorld()))
{
world = sender.player().getWorld();
}
else if(args.length >= 1)
{
World t = Bukkit.getWorld(args[0]);
if(t == null)
{
sender.sendMessage("Unknown world " + args[0]);
return true;
}
else if(t.getGenerator() instanceof IrisGenerator)
{
world = t;
}
}
else
{
sender.sendMessage("Console / Non-Iris World. " + C.WHITE + "Use /iris timings <world>");
return true;
}
Iris.getGen(world).getMetrics().send(sender, (m) -> sender.sendMessage(m));
return true;
}
}

View File

@ -1,36 +0,0 @@
package ninja.bytecode.iris.command;
import mortar.bukkit.command.Command;
import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender;
import mortar.util.text.C;
public class CommandWhat extends MortarCommand
{
@Command
private CommandWhatBiome wBiome;
@Command
private CommandWhatObject wObject;
@Command
private CommandWhatBlock wBlock;
public CommandWhat()
{
super("what", "w");
setDescription("Identify what you are looking at.");
}
@Override
public boolean handle(MortarSender sender, String[] args)
{
for(MortarCommand i : getChildren())
{
sender.sendMessage("/iris what " + C.WHITE + i.getNode() + C.GRAY + (!i.getNodes().isEmpty() ? "," : "") + i.getNodes().toString(",") + " - " + C.DARK_GREEN + i.getDescription());
}
return true;
}
}

View File

@ -1,66 +0,0 @@
package ninja.bytecode.iris.command;
import org.bukkit.World;
import org.bukkit.entity.Player;
import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender;
import mortar.util.text.C;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.pack.IrisBiome;
import ninja.bytecode.iris.util.BiomeLayer;
import ninja.bytecode.shuriken.format.Form;
public class CommandWhatBiome extends MortarCommand
{
public CommandWhatBiome()
{
super("biome", "b");
setDescription("Identify Current Biome");
}
@Override
public boolean handle(MortarSender sender, String[] args)
{
World world = null;
if(sender.isPlayer() && Iris.isGen(sender.player().getWorld()))
{
world = sender.player().getWorld();
}
else
{
sender.sendMessage("Console / Non-Iris World.");
return true;
}
Player p = sender.player();
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()));
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 + ")");
for(String i : biome.getSchematicGroups().k())
{
String f = "";
double percent = biome.getSchematicGroups().get(i);
if(percent > 1D)
{
f = (int) percent + " + " + Form.pc(percent - (int) percent, percent - (int) percent >= 0.01 ? 0 : 3);
}
else
{
f = Form.pc(percent, percent >= 0.01 ? 0 : 3);
}
sender.sendMessage("* " + C.DARK_GREEN + i + ": " + C.BOLD + C.WHITE + f + C.RESET + C.GRAY + " (" + Form.f(g.getDimension().getObjectGroup(i).size()) + " variants)");
}
return true;
}
}

View File

@ -1,33 +0,0 @@
package ninja.bytecode.iris.command;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender;
public class CommandWhatBlock extends MortarCommand
{
public CommandWhatBlock()
{
super("block", "id", "i");
setDescription("Identify Current Block Looking at");
}
@SuppressWarnings("deprecation")
@Override
public boolean handle(MortarSender sender, String[] args)
{
if(!sender.isPlayer())
{
sender.sendMessage("Not sure where you are looking.");
}
Player p = sender.player();
Block b = p.getTargetBlock(null, 64);
sender.sendMessage(b.getType().getId() + ":" + b.getData() + " (" + b.getType().toString() + ":" + b.getData() + ")");
return true;
}
}

View File

@ -1,165 +0,0 @@
package ninja.bytecode.iris.command;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import mortar.api.sched.SR;
import mortar.bukkit.command.MortarCommand;
import mortar.bukkit.command.MortarSender;
import mortar.lang.collection.FinalInteger;
import mortar.util.text.C;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.generator.genobject.GenObject;
import ninja.bytecode.iris.generator.genobject.GenObjectGroup;
import ninja.bytecode.iris.generator.genobject.PlacedObject;
import ninja.bytecode.iris.pack.IrisBiome;
import ninja.bytecode.shuriken.collections.KMap;
import ninja.bytecode.shuriken.format.Form;
public class CommandWhatObject extends MortarCommand
{
private KMap<String, GenObject> goc;
private KMap<String, GenObjectGroup> gog;
public CommandWhatObject()
{
super("object", "o");
setDescription("WAYLA For Objects");
goc = new KMap<>();
gog = new KMap<>();
}
@Override
public boolean handle(MortarSender sender, String[] args)
{
World world = null;
if(sender.isPlayer() && Iris.isGen(sender.player().getWorld()))
{
world = sender.player().getWorld();
}
else
{
sender.sendMessage("Console / Non-Iris World.");
return true;
}
Player p = sender.player();
IrisGenerator generator = Iris.getGen(world);
Location l = p.getTargetBlock(null, 32).getLocation();
PlacedObject po = generator.nearest(l, 12);
if(po != null)
{
if(!goc.containsKey(po.getF()))
{
String root = po.getF().split("\\Q:\\E")[0];
String n = po.getF().split("\\Q:\\E")[1];
GenObjectGroup gg = generator.getDimension().getObjectGroup(root);
gog.put(root, gg);
for(GenObject i : gg.getSchematics())
{
if(i.getName().equals(n))
{
goc.put(po.getF(), i);
break;
}
}
if(!goc.containsKey(po.getF()))
{
goc.put(po.getF(), new GenObject(0, 0, 0));
}
}
GenObjectGroup ggg = gog.get(po.getF().split("\\Q:\\E")[0]);
GenObject g = goc.get(po.getF());
if(g != null)
{
Location point = new Location(l.getWorld(), po.getX(), po.getY(), po.getZ());
IrisBiome biome = generator.getBiome((int) generator.getOffsetX(po.getX(), po.getZ()), (int) generator.getOffsetZ(po.getX(), po.getZ()));
String gg = po.getF().split("\\Q:\\E")[0];
p.sendMessage(C.DARK_GREEN + C.BOLD.toString() + gg + C.GRAY + "/" + C.RESET + C.ITALIC + C.GRAY + g.getName() + C.RESET + C.WHITE + " (1 of " + Form.f(generator.getDimension().getObjectGroup(gg).size()) + " variants)");
if(biome.getSchematicGroups().containsKey(gg))
{
String f = "";
double percent = biome.getSchematicGroups().get(gg);
if(percent > 1D)
{
f = (int) percent + " + " + Form.pc(percent - (int) percent, percent - (int) percent >= 0.01 ? 0 : 3);
}
else
{
f = Form.pc(percent, percent >= 0.01 ? 0 : 3);
}
p.sendMessage(C.GOLD + "Spawn Chance in " + C.YELLOW + biome.getName() + C.RESET + ": " + C.BOLD + C.WHITE + f);
}
try
{
int a = 0;
int b = 0;
double c = 0;
for(GenObject i : ggg.getSchematics())
{
a += i.getSuccesses();
b += i.getPlaces();
}
c = ((double) a / (double) b);
p.sendMessage(C.GRAY + "Grp: " + C.DARK_AQUA + Form.f(a) + C.GRAY + " of " + C.AQUA + Form.f(b) + C.GRAY + " placements (" + C.DARK_AQUA + Form.pc(c, 0) + C.GRAY + ")");
}
catch(Throwable e)
{
e.printStackTrace();
}
p.sendMessage(C.GRAY + "Var: " + C.DARK_AQUA + Form.f(g.getSuccesses()) + C.GRAY + " of " + C.AQUA + Form.f(g.getPlaces()) + C.GRAY + " placements (" + C.DARK_AQUA + Form.pc(g.getSuccess(), 0) + C.GRAY + ")");
for(String i : ggg.getFlags())
{
p.sendMessage(C.GRAY + "- " + C.DARK_PURPLE + i);
}
FinalInteger fi = new FinalInteger(125);
new SR()
{
@Override
public void run()
{
if(point.distanceSquared(p.getLocation()) > 64 * 64)
{
cancel();
}
fi.sub(1);
Iris.wand().draw(new Location[] {point.clone().add(g.getW() / 2, g.getH() / 2, g.getD() / 2), point.clone().subtract(g.getW() / 2, g.getH() / 2, g.getD() / 2)
}, p);
if(fi.get() <= 0)
{
cancel();
}
}
};
}
}
return true;
}
}

View File

@ -1,64 +0,0 @@
package ninja.bytecode.iris.controller;
import org.bukkit.World;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.shuriken.collections.KMap;
import ninja.bytecode.shuriken.execution.TaskExecutor;
public class ExecutionController
{
KMap<String, TaskExecutor> executors;
public void start()
{
executors = new KMap<>();
}
public void stop()
{
for(TaskExecutor i : executors.v())
{
i.close();
}
executors.clear();
}
public TaskExecutor getExecutor(World world, String f)
{
String k = world.getWorldFolder().getAbsolutePath() + " (" + world + ") " + f;
if(executors.containsKey(k))
{
return executors.get(k);
}
TaskExecutor x = new TaskExecutor(getTC(), Iris.settings.performance.threadPriority, "Iris " + f);
executors.put(k, x);
return x;
}
public int getTC()
{
switch(Iris.settings.performance.performanceMode)
{
case HALF_CPU:
return Math.max(Runtime.getRuntime().availableProcessors() / 2, 1);
case MATCH_CPU:
return Runtime.getRuntime().availableProcessors();
case SINGLE_THREADED:
return 1;
case DOUBLE_CPU:
return Runtime.getRuntime().availableProcessors() * 2;
case UNLIMITED:
return -1;
case EXPLICIT:
return Iris.settings.performance.threadCount;
default:
break;
}
return Math.max(Runtime.getRuntime().availableProcessors() / 2, 1);
}
}

View File

@ -1,358 +0,0 @@
package ninja.bytecode.iris.controller;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import mortar.bukkit.plugin.Controller;
import net.md_5.bungee.api.ChatColor;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.generator.genobject.GenObject;
import ninja.bytecode.iris.generator.genobject.GenObjectGroup;
import ninja.bytecode.iris.pack.CompiledDimension;
import ninja.bytecode.iris.pack.IrisBiome;
import ninja.bytecode.iris.pack.IrisDimension;
import ninja.bytecode.iris.pack.IrisPack;
import ninja.bytecode.shuriken.bench.PrecisionStopwatch;
import ninja.bytecode.shuriken.collections.KList;
import ninja.bytecode.shuriken.collections.KMap;
import ninja.bytecode.shuriken.execution.J;
import ninja.bytecode.shuriken.format.Form;
import ninja.bytecode.shuriken.io.IO;
import ninja.bytecode.shuriken.json.JSONException;
import ninja.bytecode.shuriken.json.JSONObject;
import ninja.bytecode.shuriken.logging.L;
public class PackController extends Controller
{
private KMap<String, CompiledDimension> compiledDimensions;
private KMap<String, IrisDimension> dimensions;
private KMap<String, IrisBiome> biomes;
private KMap<String, GenObjectGroup> genObjectGroups;
private boolean ready;
@Override
public void start()
{
compiledDimensions = new KMap<>();
dimensions = new KMap<>();
biomes = new KMap<>();
genObjectGroups = new KMap<>();
ready = false;
}
@Override
public void stop()
{
}
@Override
public void tick()
{
}
public boolean isReady()
{
return ready;
}
public KList<File> getFiles(File folder)
{
KList<File> buf = new KList<File>();
if(!folder.exists())
{
return buf;
}
if(folder.isDirectory())
{
for(File i : folder.listFiles())
{
if(i.isFile())
{
buf.add(i);
}
else if(i.isDirectory())
{
buf.addAll(getFiles(folder));
}
}
}
return buf;
}
public void compile()
{
dimensions = new KMap<>();
biomes = new KMap<>();
genObjectGroups = new KMap<>();
ready = false;
PrecisionStopwatch p = PrecisionStopwatch.start();
File dims = new File(Iris.instance.getDataFolder(), "dimensions");
dims.mkdirs();
try
{
IrisPack master = new IrisPack(loadJSON("pack/manifest.json"));
master.load();
}
catch(Throwable e)
{
e.printStackTrace();
}
L.v(ChatColor.LIGHT_PURPLE + "Processing Content");
for(GenObjectGroup i : genObjectGroups.v())
{
i.processVariants();
}
for(String i : dimensions.k())
{
IrisDimension id = dimensions.get(i);
CompiledDimension d = new CompiledDimension(id);
for(IrisBiome j : id.getBiomes())
{
d.registerBiome(j);
KList<String> g = j.getSchematicGroups().k();
g.sort();
for(String k : g)
{
d.registerObject(genObjectGroups.get(k));
if(j.isLush())
{
try
{
GenObjectGroup ggx = genObjectGroups.get(k).copy("-lush-" + j.getLush());
ggx.applyLushFilter(j.getLush());
d.registerObject(ggx);
j.getSchematicGroups().put(ggx.getName(), j.getSchematicGroups().get(k));
j.getSchematicGroups().remove(k);
}
catch(Throwable e)
{
e.printStackTrace();
}
}
if(j.isSnowy())
{
try
{
GenObjectGroup ggx = genObjectGroups.get(k).copy("-snow-" + j.getSnow());
ggx.applySnowFilter((int) (j.getSnow() * 4));
d.registerObject(ggx);
j.getSchematicGroups().put(ggx.getName(), j.getSchematicGroups().get(k));
j.getSchematicGroups().remove(k);
}
catch(Throwable e)
{
e.printStackTrace();
}
}
}
}
d.sort();
compiledDimensions.put(i, d);
}
for(String i : compiledDimensions.k())
{
CompiledDimension d = compiledDimensions.get(i);
d.computeObjectSize();
L.i(ChatColor.GREEN + i + ChatColor.WHITE + " (" + d.getEnvironment().toString().toLowerCase() + ")");
L.i(ChatColor.DARK_GREEN + " Biomes: " + ChatColor.GRAY + Form.f(d.getBiomes().size()));
L.i(ChatColor.DARK_GREEN + " Objects: " + ChatColor.GRAY + Form.f(d.countObjects()));
L.flush();
}
L.i("");
L.i(ChatColor.LIGHT_PURPLE + "Compilation Time: " + ChatColor.WHITE + Form.duration(p.getMilliseconds(), 2));
L.i(ChatColor.GREEN + "Iris Dimensions Successfully Compiled!");
L.i("");
L.flush();
ready = true;
}
public KMap<String, CompiledDimension> getCompiledDimensions()
{
return compiledDimensions;
}
public KMap<String, IrisDimension> getDimensions()
{
return dimensions;
}
public KMap<String, IrisBiome> getBiomes()
{
return biomes;
}
public KMap<String, GenObjectGroup> getGenObjectGroups()
{
return genObjectGroups;
}
public CompiledDimension getDimension(String name)
{
return compiledDimensions.get(name);
}
public IrisDimension loadDimension(String s) throws JSONException, IOException
{
L.v(ChatColor.GOLD + "Loading Dimension: " + ChatColor.GRAY + "pack/dimensions/" + s + ".json");
return new IrisDimension(loadJSON("pack/dimensions/" + s + ".json"));
}
public IrisBiome loadBiome(String s) throws JSONException, IOException
{
L.v(ChatColor.DARK_GREEN + "Loading Biome: " + ChatColor.GRAY + "pack/biomes/" + s + ".json");
return new IrisBiome(loadJSON("pack/biomes/" + s + ".json"));
}
public GenObjectGroup loadSchematicGroup(String s)
{
GenObjectGroup g = GenObjectGroup.load("pack/objects/" + s);
L.v(ChatColor.DARK_AQUA + "Loading Objects: " + ChatColor.GRAY + "pack/objects/" + s + ".ish");
if(g != null)
{
genObjectGroups.put(s, g);
return g;
}
L.i("Cannot load Object Group: " + s);
return null;
}
public GenObject loadSchematic(String s) throws IOException
{
return GenObject.load(loadResource("pack/objects/" + s + ".ish"));
}
public JSONObject loadJSON(String s) throws JSONException, IOException
{
return new JSONObject(IO.readAll(loadResource(s)));
}
public File loadFolder(String string)
{
File internal = internalResource(string);
if(internal.exists())
{
return internal;
}
L.f(ChatColor.RED + "Cannot find folder: " + internal.getAbsolutePath());
return null;
}
public InputStream loadResource(String string) throws IOException
{
File internal = internalResource(string);
if(internal.exists())
{
L.flush();
return new FileInputStream(internal);
}
else
{
L.f(ChatColor.RED + "Cannot find Resource: " + ChatColor.YELLOW + internal.getAbsolutePath());
if(internal.getName().equals("manifest.json"))
{
L.f(ChatColor.RED + "Reloading Iris to fix manifest jar issues");
Iris.instance.reload();
}
return null;
}
}
private static File internalResource(String resource)
{
if(new File(Iris.instance.getDataFolder(), "pack").exists())
{
return new File(Iris.instance.getDataFolder(), resource);
}
return new File(System.getProperty("java.io.tmpdir") + "/Iris/" + resource);
}
public void registerBiome(String name, IrisBiome biome)
{
biomes.put(name, biome);
}
public void registerDimension(String i, IrisDimension d)
{
dimensions.put(i, d);
}
public void invalidate()
{
J.attempt(() -> new File(Iris.instance.getDataFolder(), "dimensions").delete());
compiledDimensions.clear();
}
public IrisBiome getBiomeById(String id)
{
if(!biomes.containsKey(id))
{
try
{
biomes.put(id, ((PackController) Iris.instance.getController(PackController.class)).loadBiome(id));
}
catch(JSONException | IOException e)
{
e.printStackTrace();
}
}
return biomes.get(id);
}
public void dispose()
{
for(GenObjectGroup i : genObjectGroups.values())
{
i.dispose();
}
for(IrisDimension i : dimensions.values())
{
i.dispose();
}
for(CompiledDimension i : compiledDimensions.values())
{
i.dispose();
}
compiledDimensions.clear();
dimensions.clear();
biomes.clear();
genObjectGroups.clear();
}
}

View File

@ -1,323 +0,0 @@
package ninja.bytecode.iris.controller;
import java.awt.Color;
import java.util.Iterator;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.util.BlockVector;
import org.bukkit.util.Vector;
import mortar.bukkit.plugin.Controller;
import mortar.compute.math.M;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.generator.genobject.GenObject;
import ninja.bytecode.iris.util.Cuboid;
import ninja.bytecode.iris.util.MB;
import ninja.bytecode.iris.util.ParticleEffect;
import ninja.bytecode.iris.util.ParticleRedstone;
import ninja.bytecode.shuriken.collections.KList;
public class WandController extends Controller
{
@Override
public void start()
{
// TODO: Optimize
Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, () ->
{
for(Player i : Bukkit.getOnlinePlayers())
{
tick(i);
}
}, 0, 0);
}
@Override
public void stop()
{
}
@Override
public void tick()
{
}
@EventHandler
public void tick(Player p)
{
try
{
if(isWand(p.getInventory().getItemInMainHand()))
{
Location[] d = getCuboid(p.getInventory().getItemInMainHand());
draw(d, p);
}
}
catch(Throwable e)
{
}
}
public void draw(Location[] d, Player p)
{
ParticleEffect.CRIT_MAGIC.display(0.1f, 1, d[0].clone().add(0.5, 0.5, 0.5).clone().add(Vector.getRandom().subtract(Vector.getRandom()).normalize().clone().multiply(0.65)), p);
ParticleEffect.CRIT.display(0.1f, 1, d[1].clone().add(0.5, 0.5, 0.5).clone().add(Vector.getRandom().subtract(Vector.getRandom()).normalize().clone().multiply(0.65)), p);
if(!d[0].getWorld().equals(d[1].getWorld()))
{
return;
}
if(d[0].distanceSquared(d[1]) > 64 * 64)
{
return;
}
int minx = Math.min(d[0].getBlockX(), d[1].getBlockX());
int miny = Math.min(d[0].getBlockY(), d[1].getBlockY());
int minz = Math.min(d[0].getBlockZ(), d[1].getBlockZ());
int maxx = Math.max(d[0].getBlockX(), d[1].getBlockX());
int maxy = Math.max(d[0].getBlockY(), d[1].getBlockY());
int maxz = Math.max(d[0].getBlockZ(), d[1].getBlockZ());
for(double j = minx - 1; j < maxx + 1; j += 0.25)
{
for(double k = miny - 1; k < maxy + 1; k += 0.25)
{
for(double l = minz - 1; l < maxz + 1; l += 0.25)
{
if(M.r(0.25))
{
boolean jj = j == minx || j == maxx;
boolean kk = k == miny || k == maxy;
boolean ll = l == minz || l == maxz;
double aa = j;
double bb = k;
double cc = l;
if((jj && kk) || (jj && ll) || (ll && kk))
{
Vector push = new Vector(0, 0, 0);
if(j == minx)
{
push.add(new Vector(-0.55, 0, 0));
}
if(k == miny)
{
push.add(new Vector(0, -0.55, 0));
}
if(l == minz)
{
push.add(new Vector(0, 0, -0.55));
}
if(j == maxx)
{
push.add(new Vector(0.55, 0, 0));
}
if(k == maxy)
{
push.add(new Vector(0, 0.55, 0));
}
if(l == maxz)
{
push.add(new Vector(0, 0, 0.55));
}
Location lv = new Location(d[0].getWorld(), aa, bb, cc).clone().add(0.5, 0.5, 0.5).clone().add(push);
int color = Color.getHSBColor((float) (0.5f + (Math.sin((aa + bb + cc + (p.getTicksLived() / 2)) / 20f) / 2)), 1, 1).getRGB();
new ParticleRedstone().setColor(new Color(color)).play(lv, p);
}
}
}
}
}
}
@EventHandler
public void on(PlayerInteractEvent e)
{
if(e.getHand().equals(EquipmentSlot.HAND) && isWand(e.getPlayer().getInventory().getItemInMainHand()))
{
if(e.getAction().equals(Action.LEFT_CLICK_BLOCK))
{
e.setCancelled(true);
e.getPlayer().getInventory().setItemInMainHand(update(true, e.getClickedBlock().getLocation(), e.getPlayer().getInventory().getItemInMainHand()));
e.getPlayer().playSound(e.getClickedBlock().getLocation(), Sound.BLOCK_END_PORTAL_FRAME_FILL, 1f, 0.67f);
e.getPlayer().updateInventory();
}
else if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK))
{
e.setCancelled(true);
e.getPlayer().getInventory().setItemInMainHand(update(false, e.getClickedBlock().getLocation(), e.getPlayer().getInventory().getItemInMainHand()));
e.getPlayer().playSound(e.getClickedBlock().getLocation(), Sound.BLOCK_END_PORTAL_FRAME_FILL, 1f, 1.17f);
e.getPlayer().updateInventory();
}
}
}
public static void pasteSchematic(GenObject s, Location at)
{
s.place(at);
}
@SuppressWarnings("deprecation")
public static GenObject createSchematic(ItemStack wand, Location at)
{
if(!isWand(wand))
{
return null;
}
try
{
Location[] f = getCuboid(wand);
Cuboid c = new Cuboid(f[0], f[1]);
GenObject s = new GenObject(c.getSizeX(), c.getSizeY(), c.getSizeZ());
Iterator<Block> bb = c.iterator();
while(bb.hasNext())
{
Block b = bb.next();
if(b.getType().equals(Material.AIR))
{
continue;
}
byte data = b.getData();
BlockVector bv = b.getLocation().subtract(c.getCenter()).toVector().toBlockVector();
s.put(bv.getBlockX(), bv.getBlockY(), bv.getBlockZ(),
new MB(b.getType(), data));
}
return s;
}
catch(Throwable e)
{
e.printStackTrace();
}
return null;
}
public static Location stringToLocation(String s)
{
try
{
String[] f = s.split("\\Q in \\E");
String[] g = f[0].split("\\Q,\\E");
return new Location(Bukkit.getWorld(f[1]), Integer.valueOf(g[0]), Integer.valueOf(g[1]), Integer.valueOf(g[2]));
}
catch(Throwable e)
{
return null;
}
}
public static String locationToString(Location s)
{
if(s == null)
{
return "<#>";
}
return s.getBlockX() + "," + s.getBlockY() + "," + s.getBlockZ() + " in " + s.getWorld().getName();
}
public static ItemStack createWand()
{
return createWand(null, null);
}
public static ItemStack update(boolean left, Location a, ItemStack item)
{
if(!isWand(item))
{
return item;
}
Location[] f = getCuboid(item);
Location other = left ? f[1] : f[0];
if(other != null && !other.getWorld().getName().equals(a.getWorld().getName()))
{
other = null;
}
return createWand(left ? a : other, left ? other : a);
}
public static ItemStack createWand(Location a, Location b)
{
ItemStack is = new ItemStack(Material.BLAZE_ROD);
is.addUnsafeEnchantment(Enchantment.ARROW_INFINITE, 1);
ItemMeta im = is.getItemMeta();
im.setDisplayName(ChatColor.BOLD + "" + ChatColor.GOLD + "Wand of Iris");
im.setUnbreakable(true);
im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_PLACED_ON, ItemFlag.HIDE_POTION_EFFECTS, ItemFlag.HIDE_DESTROYS, ItemFlag.HIDE_ENCHANTS);
im.setLore(new KList<String>().add(locationToString(a), locationToString(b)));
is.setItemMeta(im);
return is;
}
public static boolean isWand(Player p)
{
ItemStack is = p.getInventory().getItemInMainHand();
return !(is == null || !isWand(is));
}
public static Location[] getCuboid(ItemStack is)
{
ItemMeta im = is.getItemMeta();
return new Location[] {stringToLocation(im.getLore().get(0)), stringToLocation(im.getLore().get(1))};
}
public static boolean isWand(ItemStack item)
{
if(!item.getType().equals(createWand().getType()))
{
return false;
}
if(!item.getItemMeta().getEnchants().equals(createWand().getItemMeta().getEnchants()))
{
return false;
}
if(!item.getItemMeta().getDisplayName().equals(createWand().getItemMeta().getDisplayName()))
{
return false;
}
return true;
}
}

View File

@ -1,728 +0,0 @@
package ninja.bytecode.iris.generator;
import java.util.List;
import java.util.Random;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.TreeSpecies;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.material.Leaves;
import org.bukkit.util.NumberConversions;
import mortar.util.text.C;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.generator.atomics.AtomicChunkData;
import ninja.bytecode.iris.generator.genobject.GenObjectDecorator;
import ninja.bytecode.iris.generator.genobject.PlacedObject;
import ninja.bytecode.iris.generator.layer.GenLayerBiome;
import ninja.bytecode.iris.generator.layer.GenLayerCarving;
import ninja.bytecode.iris.generator.layer.GenLayerCaves;
import ninja.bytecode.iris.generator.layer.GenLayerCliffs;
import ninja.bytecode.iris.generator.layer.GenLayerLayeredNoise;
import ninja.bytecode.iris.generator.layer.GenLayerOres;
import ninja.bytecode.iris.generator.layer.GenLayerSnow;
import ninja.bytecode.iris.generator.parallax.ParallaxWorldGenerator;
import ninja.bytecode.iris.pack.BiomeType;
import ninja.bytecode.iris.pack.CompiledDimension;
import ninja.bytecode.iris.pack.IrisBiome;
import ninja.bytecode.iris.pack.IrisRegion;
import ninja.bytecode.iris.util.ChunkPlan;
import ninja.bytecode.iris.util.InterpolationMode;
import ninja.bytecode.iris.util.IrisInterpolation;
import ninja.bytecode.iris.util.IrisMetrics;
import ninja.bytecode.iris.util.MB;
import ninja.bytecode.iris.util.NoiseProvider;
import ninja.bytecode.iris.util.ObjectMode;
import ninja.bytecode.iris.util.SChunkVector;
import ninja.bytecode.shuriken.bench.PrecisionStopwatch;
import ninja.bytecode.shuriken.collections.KList;
import ninja.bytecode.shuriken.logging.L;
import ninja.bytecode.shuriken.math.CNG;
import ninja.bytecode.shuriken.math.M;
import ninja.bytecode.shuriken.math.RNG;
public class IrisGenerator extends ParallaxWorldGenerator
{
//@builder
public static final KList<MB> ROCK = new KList<MB>().add(new MB[] {
MB.of(Material.STONE),
MB.of(Material.STONE),
MB.of(Material.STONE),
MB.of(Material.STONE),
MB.of(Material.STONE),
MB.of(Material.STONE),
MB.of(Material.STONE),
MB.of(Material.STONE),
MB.of(Material.STONE),
MB.of(Material.STONE, 5),
MB.of(Material.STONE, 5),
MB.of(Material.STONE, 5),
MB.of(Material.STONE, 5),
MB.of(Material.STONE, 5),
MB.of(Material.STONE, 5)
});
//@done
private boolean disposed;
private CNG scatter;
private CNG beach;
private CNG swirl;
private MB BEDROCK = new MB(Material.BEDROCK);
private GenObjectDecorator god;
private GenLayerLayeredNoise glLNoise;
private GenLayerBiome glBiome;
private GenLayerSnow glSnow;
private GenLayerCliffs glCliffs;
private GenLayerCaves glCaves;
private GenLayerCarving glCarving;
private GenLayerOres glOres;
private RNG rTerrain;
private CompiledDimension dim;
private IrisMetrics metrics = new IrisMetrics(0, 512);
private int objectHits;
public IrisGenerator()
{
this(Iris.pack().getDimension("overworld"));
}
public void hitObject()
{
objectHits++;
}
public IrisGenerator(CompiledDimension dim)
{
objectHits = 0;
CNG.hits = 0;
CNG.creates = 0;
this.dim = dim;
disposed = false;
L.i("Preparing Dimension: " + dim.getName() + " With " + dim.getBiomes().size() + " Biomes...");
}
public int scatterInt(int x, int y, int z, int bound)
{
return (int) (scatter(x, y, z) * (double) (bound - 1));
}
public double scatter(int x, int y, int z)
{
return scatter.noise(x, y, z);
}
public boolean scatterChance(int x, int y, int z, double chance)
{
return scatter(x, y, z) > chance;
}
@Override
public void onInit(World world, Random random)
{
if(disposed)
{
return;
}
random = new Random(world.getSeed());
rTerrain = new RNG(world.getSeed());
swirl = new CNG(rTerrain.nextParallelRNG(0), 40, 1).scale(0.007);
beach = new CNG(rTerrain.nextParallelRNG(0), 3, 1).scale(0.15);
glLNoise = new GenLayerLayeredNoise(this, world, random, rTerrain.nextParallelRNG(2));
glBiome = new GenLayerBiome(this, world, random, rTerrain.nextParallelRNG(4), dim.getBiomes());
glSnow = new GenLayerSnow(this, world, random, rTerrain.nextParallelRNG(5));
glCliffs = new GenLayerCliffs(this, world, random, rTerrain.nextParallelRNG(9));
glCaves = new GenLayerCaves(this, world, random, rTerrain.nextParallelRNG(10));
glCarving = new GenLayerCarving(this, world, random, rTerrain.nextParallelRNG(11));
glOres = new GenLayerOres(this, world, random, rTerrain.nextParallelRNG(12));
scatter = new CNG(rTerrain.nextParallelRNG(52), 1, 1).scale(10);
if(Iris.settings.performance.objectMode.equals(ObjectMode.PARALLAX))
{
god = new GenObjectDecorator(this);
}
}
@Override
public ChunkPlan onInitChunk(World world, int x, int z, Random random)
{
return new ChunkPlan();
}
public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome)
{
random = new Random(world.getSeed());
PrecisionStopwatch s = getMetrics().start();
ChunkData d = super.generateChunkData(world, random, x, z, biome);
getMetrics().stop("chunk:ms", s);
getMetrics().put("noise-hits", CNG.hits);
metrics.setGenerators((int) CNG.creates);
CNG.hits = 0;
return d;
}
public IrisBiome biome(String name)
{
return getDimension().getBiomeByName(name);
}
public double getOffsetX(double x, double z)
{
return Math.round((double) x * (Iris.settings.gen.horizontalZoom / 1.90476190476)) + swirl.noise(x, z);
}
public double getOffsetZ(double x, double z)
{
return Math.round((double) z * (Iris.settings.gen.horizontalZoom / 1.90476190476)) - swirl.noise(z, x);
}
public IrisMetrics getMetrics()
{
return metrics;
}
public IrisBiome getBeach(IrisBiome biome)
{
IrisBiome beach = null;
IrisRegion region = glBiome.getRegion(biome.getRegionID());
if(region != null)
{
beach = region.getBeach();
}
if(beach == null)
{
beach = biome("Beach");
}
return beach;
}
public int computeHeight(int x, int z, ChunkPlan plan, IrisBiome biome)
{
return (int) Math.round(M.clip(getANoise((int) x, (int) z, plan, biome), 0D, 1D) * 253);
}
public double getInterpolation(int x, int z, double opacity, ChunkPlan plan)
{
PrecisionStopwatch s = getMetrics().start();
NoiseProvider n = (xf, zf) -> getBiomedHeight((int) Math.round(xf), (int) Math.round(zf), plan);
double d = 0;
double rad = Iris.settings.gen.interpolationRadius;
InterpolationMode m = Iris.settings.gen.interpolationMode;
if(m.equals(InterpolationMode.BILINEAR))
{
d = IrisInterpolation.getBilinearNoise(x, z, rad, n);
}
else if(m.equals(InterpolationMode.BICUBIC))
{
d = IrisInterpolation.getBicubicNoise(x, z, rad, n);
}
else if(m.equals(InterpolationMode.HERMITE_BICUBIC))
{
d = IrisInterpolation.getHermiteNoise(x, z, rad, n);
}
else
{
d = n.noise(x, z);
}
getMetrics().stop("interpolation:ms:x256:/biome:.", s);
return d;
}
public double getANoise(int x, int z, ChunkPlan plan, IrisBiome biome)
{
double hv = getInterpolation((int) x, (int) z, 1D, plan);
hv += glLNoise.generateLayer(hv * Iris.settings.gen.roughness * 215, (double) x * Iris.settings.gen.roughness * 0.82, (double) z * Iris.settings.gen.roughness * 0.82) * (1.6918 * (hv * 2.35));
if(biome.hasCliffs())
{
hv = glCliffs.generateLayer(hv, x, z, biome.getCliffScale(), biome.getCliffChance());
}
return hv;
}
public IrisRegion getRegion(IrisBiome biome)
{
return glBiome.getRegion(biome.getRegionID());
}
@Override
public List<BlockPopulator> getDefaultPopulators(World world)
{
KList<BlockPopulator> p = new KList<>();
if(Iris.settings.performance.objectMode.equals(ObjectMode.QUICK_N_DIRTY) || Iris.settings.performance.objectMode.equals(ObjectMode.LIGHTING))
{
p.add(god = new GenObjectDecorator(this));
}
return p;
}
@Override
public void onGenParallax(int x, int z, Random random)
{
try
{
PrecisionStopwatch s = getMetrics().start();
god.populateParallax(x, z, random);
String xx = "x" + getParallaxSize().getX() * getParallaxSize().getZ();
getMetrics().stop("object:" + xx + ":.:ms:/parallax", s);
}
catch(Throwable e)
{
e.printStackTrace();
}
}
private double getObjectHits()
{
int hits = objectHits;
objectHits = 0;
return hits;
}
public IrisBiome getBiome(int x, int z)
{
IrisBiome biome = glBiome.getBiome(x, z);
int height = computeHeight((int) x, (int) z, new ChunkPlan(), biome);
biome = getBiome((int) x, height, (int) z);
return biome;
}
private IrisBiome getBiome(int x, int y, int z)
{
int seaLevel = Iris.settings.gen.seaLevel;
boolean land = y >= seaLevel;
int beachHeight = land ? 1 + (int) Math.round(seaLevel + beach.noise(x, z) + 1) : seaLevel;
boolean beach = y <= beachHeight && land;
IrisBiome biome = glBiome.getBiome(x, z);
IrisBiome realBiome = glBiome.getBiome(x, z, true);
boolean nearAquatic = glBiome.isNearAquatic(x, z);
IrisRegion region = getRegion(realBiome);
// Remove Oceans from biomes above sea level
if(land && biome.getType().equals(BiomeType.FLUID))
{
biome = realBiome;
}
// Add Beaches & Shores
if(beach && biome.getType().equals(BiomeType.LAND))
{
biome = nearAquatic ? region.getBeach() : region.getShore();
}
// // Replace biomes under sea level with lakes
if(!land && biome.getType().equals(BiomeType.LAND))
{
biome = region.getLake();
}
return biome;
}
@Override
public Biome onGenColumn(int wxxf, int wzxf, int x, int z, ChunkPlan plan, AtomicChunkData data, boolean surfaceOnly)
{
PrecisionStopwatch s = getMetrics().start();
if(disposed)
{
data.setBlock(x, 0, z, Material.MAGENTA_GLAZED_TERRACOTTA);
return Biome.VOID;
}
double wx = getOffsetX(wxxf, wzxf);
double wz = getOffsetZ(wxxf, wzxf);
int wxx = (int) wx;
int wzx = (int) wz;
int highest = 0;
int seaLevel = Iris.settings.gen.seaLevel;
IrisBiome biome = glBiome.getBiome(wxx, wzx);
int height = computeHeight(wxx, wzx, plan, biome);
int max = Math.max(height, seaLevel);
biome = getBiome(wxx, height, wzx);
MB FLUID = biome.getFluid();
for(int i = surfaceOnly ? max > seaLevel ? max - 2 : height - 2 : 0; i < max; i++)
{
MB mb = ROCK.get(scatterInt(wzx, i, wxx, ROCK.size()));
boolean carved = surfaceOnly ? false : glCarving.isCarved(wzx, wxx, x, z, i, data, plan);
boolean underwater = i >= height && i < seaLevel;
boolean underground = i < height;
int dheight = biome.getDirtDepth();
int rheight = biome.getRockDepth();
boolean dirt = (height - 1) - i < (dheight > 0 ? scatterInt(x, i, z, 4) : 0) + dheight;
boolean rocky = i > height - rheight && !dirt;
boolean bedrock = i == 0 || !Iris.settings.gen.flatBedrock ? i <= 2 : i < scatterInt(x, i, z, 3);
if(!carved)
{
mb = underwater ? FLUID : mb;
mb = underground && dirt ? biome.getSubSurface(wxx, i, wzx, rTerrain) : mb;
mb = underground && rocky ? biome.getRock(wxx, i, wzx, rTerrain) : mb;
mb = bedrock ? BEDROCK : mb;
if(i == height - 1)
{
mb = biome.getSurface(wx, wz, rTerrain);
}
highest = i > highest ? i : highest;
}
else
{
mb = MB.of(Material.AIR);
}
data.setBlock(x, i, z, mb.material, mb.data);
}
getMetrics().stop("terrain:ms:x256:/chunk:..", s);
int hw = 0;
int hl = 0;
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.setRealWaterHeight(x, z, hw == 0 ? seaLevel : hw);
plan.setBiome(x, z, biome);
if(!surfaceOnly)
{
glCaves.genCaves(wxxf, wzxf, x, z, 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.setRealWaterHeight(x, z, hw == 0 ? seaLevel : hw);
plan.setBiome(x, z, biome);
double time = s.getMilliseconds() * 256D;
double atime = getMetrics().get("chunk:ms").getAverage();
getMetrics().setParScale(time / atime);
getMetrics().put("objects:,:/parallax", getObjectHits());
return biome.getRealBiome();
}
@Override
protected void onDecorateChunk(World world, int cx, int cz, AtomicChunkData data, ChunkPlan plan)
{
PrecisionStopwatch p = PrecisionStopwatch.start();
int x = 0;
int z = 0;
int hhx = 0;
int v = 0;
int borderh = 0;
int above = 0;
int below = 0;
for(int f = 0; f < Iris.settings.gen.blockSmoothing; f++)
{
for(x = 0; x < 16; x++)
{
for(z = 0; z < 16; z++)
{
hhx = plan.getRealHeight(x, z);
borderh = 0;
if(x == 0 || x == 15)
{
borderh++;
}
if(z == 0 || z == 15)
{
borderh++;
}
if(hhx > Iris.settings.gen.seaLevel - 2)
{
above = 0;
below = 0;
if(x + 1 <= 15)
{
v = plan.getRealHeight(x + 1, z);
if(v > hhx)
{
above++;
}
else if(v < hhx)
{
below++;
}
}
if(x - 1 >= 0)
{
v = plan.getRealHeight(x - 1, z);
if(v > hhx)
{
above++;
}
else if(v < hhx)
{
below++;
}
}
if(z + 1 <= 15)
{
v = plan.getRealHeight(x, z + 1);
if(v > hhx)
{
above++;
}
else if(v < hhx)
{
below++;
}
}
if(z - 1 >= 0)
{
v = plan.getRealHeight(x, z - 1);
if(v > hhx)
{
above++;
}
else if(v < hhx)
{
below++;
}
}
// Patch Hole
if(above >= 4 - borderh)
{
data.setBlock(x, hhx + 1, z, data.getMB(x, hhx, z));
plan.setRealHeight(x, z, hhx + 1);
}
// Remove Nipple
else if(below >= 4 - borderh)
{
data.setBlock(x, hhx - 1, z, data.getMB(x, hhx, z));
data.setBlock(x, hhx, z, Material.AIR);
plan.setRealHeight(x, z, hhx - 1);
}
}
}
}
}
getMetrics().stop("decoration:ms:/chunk:..", p);
}
@SuppressWarnings("deprecation")
@Override
protected void onDecorateColumn(World world, int x, int z, int wx, int wz, AtomicChunkData data, ChunkPlan plan)
{
PrecisionStopwatch p = PrecisionStopwatch.start();
int h = plan.getRealHeight(x, z);
if(h < 63)
{
return;
}
IrisBiome biome = plan.getBiome(x, z);
if(biome == null)
{
return;
}
if(biome.getSnow() > 0)
{
double level = glSnow.getHeight(wx, wz) * biome.getSnow();
int blocks = (int) level;
level -= blocks;
int layers = (int) (level * 7D);
int snowHeight = blocks + (layers > 0 ? 1 : 0);
for(int j = 0; j < snowHeight; j++)
{
data.setBlock(x, h + j + 1, z, j == snowHeight - 1 ? Material.SNOW : Material.SNOW_BLOCK, j == snowHeight - 1 ? (byte) layers : (byte) 0);
}
}
else
{
MB mbx = biome.getScatterChanceSingle(scatter(wx, h, wz), scatter(wz, h, wx));
if(!mbx.material.equals(Material.AIR))
{
data.setBlock(x, h + 1, z, mbx.material, mbx.data);
if(mbx.material.equals(Material.DOUBLE_PLANT))
{
data.setBlock(x, h + 2, z, mbx.material, (byte) 10);
}
}
}
if(biome.getLush() > 0.33)
{
double lx = (biome.getLush() > 1 ? 1 : biome.getLush()) - 0.33;
double g = glSnow.getHeight(wz, wx);
if(lx / 1.18D > g)
{
double gx = glSnow.getHeight(wx * 2.25, wz * 2.25);
double gf = glSnow.getHeight(wx * 6.25, wz * 6.25);
if(gf > gx)
{
Leaves l = new Leaves(TreeSpecies.values()[(int) (gx * (TreeSpecies.values().length - 1))]);
l.setDecaying(false);
l.setDecayable(false);
data.setBlock(x, h - 1, z, data.getMB(x, h, z));
data.setBlock(x, h, z, l.getItemType(), l.getData());
if(gf - gx > 0.2)
{
l = new Leaves(TreeSpecies.values()[(int) (gf * (TreeSpecies.values().length - 1))]);
l.setDecaying(false);
l.setDecayable(false);
data.setBlock(x, h + 1, z, l.getItemType(), l.getData());
}
}
}
}
getMetrics().stop("pardecoration:ms:x256:/chunk:..", p);
}
@Override
public void onPostChunk(World world, int cx, int cz, Random random, AtomicChunkData data, ChunkPlan plan)
{
}
private double getBiomedHeight(int x, int z, ChunkPlan plan)
{
double xh = plan.getHeight(x, z);
if(xh == -1)
{
IrisBiome biome = glBiome.getBiome(x, z);
double h = Iris.settings.gen.baseHeight + biome.getHeight();
h += biome.getGenerator().getHeight(x, z) / 2D;
plan.setHeight(x, z, h);
return h;
}
return xh;
}
public RNG getRTerrain()
{
return rTerrain;
}
public CompiledDimension getDimension()
{
return dim;
}
public void dispose()
{
if(disposed)
{
return;
}
L.w(C.YELLOW + "Disposed Iris World " + C.RED + getWorld().getName());
disposed = true;
dim = null;
glLNoise = null;
glSnow = null;
glCliffs = null;
god.dispose();
}
public boolean isDisposed()
{
return disposed;
}
public PlacedObject nearest(Location o, int i)
{
PlacedObject f = null;
double d = Integer.MAX_VALUE;
if(god != null)
{
for(PlacedObject j : god.getHistory())
{
double dx = Math.abs(NumberConversions.square(j.getX() - o.getX()) + NumberConversions.square(j.getY() - o.getY()) + NumberConversions.square(j.getZ() - o.getZ()));
if(dx < d)
{
d = dx;
f = j;
}
}
}
return f;
}
public PlacedObject randomObject(String string)
{
return god.randomObject(string);
}
@Override
protected SChunkVector getParallaxSize()
{
return dim.getMaxChunkSize();
}
@Override
protected void onUnload()
{
dispose();
}
public void inject(CompiledDimension dimension)
{
this.dim = dimension;
onInit(getWorld(), rTerrain);
}
}

View File

@ -1,81 +0,0 @@
package ninja.bytecode.iris.generator;
import ninja.bytecode.iris.pack.IrisBiome;
import ninja.bytecode.iris.util.MB;
public class IrisSample
{
public MB surface;
public int height;
public IrisBiome biome;
public MB getSurface()
{
return surface;
}
public void setSurface(MB surface)
{
this.surface = surface;
}
public int getHeight()
{
return height;
}
public void setHeight(int height)
{
this.height = height;
}
public IrisBiome getBiome()
{
return biome;
}
public void setBiome(IrisBiome biome)
{
this.biome = biome;
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((biome == null) ? 0 : biome.hashCode());
result = prime * result + height;
result = prime * result + ((surface == null) ? 0 : surface.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
if(this == obj)
return true;
if(obj == null)
return false;
if(getClass() != obj.getClass())
return false;
IrisSample other = (IrisSample) obj;
if(biome == null)
{
if(other.biome != null)
return false;
}
else if(!biome.equals(other.biome))
return false;
if(height != other.height)
return false;
if(surface == null)
{
if(other.surface != null)
return false;
}
else if(!surface.equals(other.surface))
return false;
return true;
}
}

View File

@ -1,105 +0,0 @@
package ninja.bytecode.iris.generator;
import java.util.Collections;
import java.util.function.Consumer;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.entity.Player;
import mortar.api.nms.NMP;
import mortar.api.sched.J;
import mortar.compute.math.M;
import mortar.lang.collection.FinalDouble;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.util.ChronoQueue;
import ninja.bytecode.iris.util.ObjectMode;
import ninja.bytecode.iris.util.SMCAVector;
import ninja.bytecode.shuriken.collections.KList;
import ninja.bytecode.shuriken.collections.KMap;
public class WorldReactor
{
private static KList<ChronoQueue> q = new KList<>();
private final World world;
public WorldReactor(World world)
{
this.world = world;
}
public void generateRegionNormal(Player p, boolean force, double mst, Consumer<Double> progress, Runnable done)
{
for(ChronoQueue i : WorldReactor.q)
{
i.close();
}
WorldReactor.q.clear();
ChronoQueue q = new ChronoQueue(mst, 10240);
WorldReactor.q.add(q);
FinalDouble of = new FinalDouble(0D);
FinalDouble max = new FinalDouble(0D);
KMap<SMCAVector, Double> d = new KMap<>();
int mx = p.getLocation().getChunk().getX();
int mz = p.getLocation().getChunk().getZ();
for(int xx = p.getLocation().getChunk().getX() - 32; xx < p.getLocation().getChunk().getX() + 32; xx++)
{
int x = xx;
for(int zz = p.getLocation().getChunk().getZ() - 32; zz < p.getLocation().getChunk().getZ() + 32; zz++)
{
int z = zz;
if(world.isChunkLoaded(x, z) || world.loadChunk(x, z, false))
{
d.put(new SMCAVector(x, z), Math.sqrt(Math.pow(x - mx, 2) + Math.pow(z - mz, 2)));
}
}
}
KList<SMCAVector> v = d.k();
Collections.sort(v, (a, b) -> (int) (10000 * (d.get(a) - d.get(b))));
for(SMCAVector i : v)
{
int x = i.getX();
int z = i.getZ();
if(Iris.settings.performance.objectMode.equals(ObjectMode.PARALLAX) && world.getGenerator() instanceof IrisGenerator)
{
IrisGenerator gg = ((IrisGenerator) world.getGenerator());
gg.getWorldData().deleteChunk(x, z);
}
max.add(1);
q.queue(() ->
{
world.regenerateChunk(x, z);
Chunk cc = world.getChunkAt(x, z);
NMP.host.relight(cc);
of.add(1);
if(of.get() == max.get())
{
progress.accept(1D);
q.dieSlowly();
done.run();
}
else
{
progress.accept(M.clip(of.get() / max.get(), 0D, 1D));
}
});
}
J.s(() ->
{
q.dieSlowly();
}, 20);
}
}

View File

@ -1,83 +0,0 @@
package ninja.bytecode.iris.generator.atomics;
import java.io.Serializable;
import java.lang.reflect.Field;
import sun.misc.Unsafe;
@SuppressWarnings("restriction")
public class AtomicCharArray implements Serializable
{
private static final long serialVersionUID = 2862133569453604235L;
private static final Unsafe unsafe;
private static final int base;
private static final int shift;
volatile char[] array;
public AtomicCharArray(int var1)
{
this.array = new char[var1];
}
private long checkedByteOffset(int var1)
{
if(var1 >= 0 && var1 < this.array.length)
{
return byteOffset(var1);
}
else
{
throw new IndexOutOfBoundsException("index " + var1);
}
}
public final char get(int var1)
{
return this.getRaw(this.checkedByteOffset(var1));
}
private char getRaw(long var1)
{
return unsafe.getCharVolatile(this.array, var1);
}
public final void set(int var1, char var2)
{
unsafe.putCharVolatile(this.array, this.checkedByteOffset(var1), var2);
}
private static long byteOffset(int var0)
{
return ((long) var0 << shift) + (long) base;
}
static
{
Field f;
Unsafe o = null;
try
{
f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
o = (Unsafe) f.get(null);
}
catch(Throwable e)
{
e.printStackTrace();
}
unsafe = o;
base = unsafe.arrayBaseOffset(int[].class);
int var0 = unsafe.arrayIndexScale(int[].class);
if((var0 & var0 - 1) != 0)
{
throw new Error("data type scale not a power of two");
}
else
{
shift = 31 - Integer.numberOfLeadingZeros(var0);
}
}
}

View File

@ -1,456 +0,0 @@
package ninja.bytecode.iris.generator.atomics;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.util.concurrent.locks.ReentrantLock;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_12_R1.generator.CraftChunkData;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.generator.ChunkGenerator.ChunkData;
import org.bukkit.material.MaterialData;
import mortar.compute.math.M;
import ninja.bytecode.iris.util.MB;
public final class AtomicChunkData implements ChunkGenerator.ChunkData
{
private static final Field t;
private static final Field[] sections;
private static final int h = 0x1000;
private final int maxHeight;
private static ReentrantLock[] locks;
private char[] s0;
private char[] s1;
private char[] s2;
private char[] s3;
private char[] s4;
private char[] s5;
private char[] s6;
private char[] s7;
private char[] s8;
private char[] s9;
private char[] s10;
private char[] s11;
private char[] s12;
private char[] s13;
private char[] s14;
private char[] s15;
private char[][] m;
private World w;
private long lastUse;
private int bits;
public AtomicChunkData(World world)
{
this.maxHeight = world.getMaxHeight();
this.w = world;
bits = 0;
lastUse = M.ms();
}
public long getTimeSinceLastUse()
{
return M.ms() - lastUse;
}
public void read(InputStream in) throws IOException
{
read(in, true);
}
public void read(InputStream in, boolean ignoreAir) throws IOException
{
DataInputStream din = new DataInputStream(in);
int bits = din.readInt();
for(int i = 0; i < 16; i++)
{
int bit = getBit(i);
if((bits & bit) == bit)
{
char[] section = getChunkSection(i << 4, true);
for(int j = 0; j < section.length; j++)
{
char c = din.readChar();
if(c == 0 && ignoreAir)
{
continue;
}
section[j] = c;
}
}
}
din.close();
}
public void write(OutputStream out) throws IOException
{
DataOutputStream dos = new DataOutputStream(out);
dos.writeInt(getDataBits());
for(int i = 0; i < 16; i++)
{
if(hasDataBit(i))
{
char[] section = getChunkSection(i << 4, false);
for(int j = 0; j < section.length; j++)
{
dos.writeChar(section[j]);
}
}
}
dos.close();
}
public boolean hasDataBit(int section)
{
int b = getBit(section);
return (bits & b) == b;
}
public void clearDataBits()
{
bits = 0;
}
public void addDataBit(int section)
{
bits |= getBit(section);
}
public void removeDataBit(int section)
{
bits ^= getBit(section);
}
public int getDataBits()
{
return bits;
}
public int getBit(int index)
{
return (int) (index < 0 ? -1 : Math.pow(2, index));
}
public int computeDataBits()
{
int bits = 0;
for(int i = 0; i < 16; i++)
{
try
{
bits |= sections[i].get(this) != null ? getBit(i) : 0;
}
catch(Throwable e)
{
}
}
return bits;
}
@Override
public int getMaxHeight()
{
return maxHeight;
}
@SuppressWarnings("deprecation")
@Override
public void setBlock(int x, int y, int z, Material material)
{
setBlock(x, y, z, material.getId());
}
@SuppressWarnings("deprecation")
@Override
public void setBlock(int x, int y, int z, MaterialData material)
{
setBlock(x, y, z, material.getItemTypeId(), material.getData());
}
@SuppressWarnings("deprecation")
@Override
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, Material material)
{
setRegion(xMin, yMin, zMin, xMax, yMax, zMax, material.getId());
}
@SuppressWarnings("deprecation")
@Override
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, MaterialData material)
{
setRegion(xMin, yMin, zMin, xMax, yMax, zMax, material.getItemTypeId(), material.getData());
}
@SuppressWarnings("deprecation")
@Override
public Material getType(int x, int y, int z)
{
lastUse = M.ms();
return Material.getMaterial(getTypeId(x, y, z));
}
@SuppressWarnings("deprecation")
@Override
public MaterialData getTypeAndData(int x, int y, int z)
{
lastUse = M.ms();
return getType(x, y, z).getNewData(getData(x, y, z));
}
@SuppressWarnings("deprecation")
public void setBlock(int x, int y, int z, Material blockId, byte data)
{
setBlock(x, y, z, blockId.getId(), data);
}
@Override
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, int blockId)
{
lastUse = M.ms();
setRegion(xMin, yMin, zMin, xMax, yMax, zMax, blockId, (byte) 0);
}
@Override
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, int blockId, int data)
{
lastUse = M.ms();
throw new UnsupportedOperationException("AtomicChunkData does not support setting regions");
}
@Override
public void setBlock(int x, int y, int z, int blockId)
{
setBlock(x, y, z, blockId, (byte) 0);
}
@Override
public void setBlock(int x, int y, int z, int blockId, byte data)
{
setBlock(x, y, z, (char) (blockId << 4 | data));
}
@SuppressWarnings("deprecation")
public MB getMB(int x, int y, int z)
{
if(x != (x & 0xf) || y < 0 || y >= maxHeight || z != (z & 0xf))
{
lastUse = M.ms();
return MB.of(Material.AIR);
}
char[] section = getChunkSection(y, false);
if(section == null)
{
lastUse = M.ms();
return MB.of(Material.AIR);
}
else
{
lastUse = M.ms();
char xf = section[(y & 0xf) << 8 | z << 4 | x];
return MB.of(Material.getMaterial(xf >> 4), xf & 0xf);
}
}
@Override
public int getTypeId(int x, int y, int z)
{
if(x != (x & 0xf) || y < 0 || y >= maxHeight || z != (z & 0xf))
{
return 0;
}
char[] section = getChunkSection(y, false);
if(section == null)
{
return 0;
}
else
{
lastUse = M.ms();
return section[(y & 0xf) << 8 | z << 4 | x] >> 4;
}
}
@Override
public byte getData(int x, int y, int z)
{
if(x != (x & 0xf) || y < 0 || y >= maxHeight || z != (z & 0xf))
{
lastUse = M.ms();
return (byte) 0;
}
char[] section = getChunkSection(y, false);
if(section == null)
{
lastUse = M.ms();
return (byte) 0;
}
else
{
lastUse = M.ms();
return (byte) (section[(y & 0xf) << 8 | z << 4 | x] & 0xf);
}
}
private void setBlock(int x, int y, int z, char type)
{
if(x != (x & 0xf) || y < 0 || y >= maxHeight || z != (z & 0xf))
{
return;
}
lastUse = M.ms();
ReentrantLock l = locks[y >> 4];
l.lock();
getChunkSection(y, true)[(y & 0xf) << 8 | z << 4 | x] = type;
l.unlock();
}
private char[] getChunkSection(int y, boolean c)
{
try
{
int s = y >> 4;
Field sf = sections[s];
char[] section = (char[]) sf.get(this);
if(section == null && c)
{
sf.set(this, new char[h]);
section = (char[]) sf.get(this);
addDataBit(s);
}
return section;
}
catch(Throwable e)
{
e.printStackTrace();
}
return null;
}
public ChunkData toChunkData()
{
ChunkData c = new CraftChunkData(w);
try
{
m = (char[][]) t.get(c);
m[0] = s0;
m[1] = s1;
m[2] = s2;
m[3] = s3;
m[4] = s4;
m[5] = s5;
m[6] = s6;
m[7] = s7;
m[8] = s8;
m[9] = s9;
m[10] = s10;
m[11] = s11;
m[12] = s12;
m[13] = s13;
m[14] = s14;
m[15] = s15;
}
catch(IllegalArgumentException | IllegalAccessException e)
{
e.printStackTrace();
}
return c;
}
static
{
locks = new ReentrantLock[16];
Field[] s = new Field[16];
for(int i = 0; i < 16; i++)
{
try
{
s[i] = AtomicChunkData.class.getDeclaredField("s" + i);
locks[i] = new ReentrantLock();
}
catch(Throwable e)
{
e.printStackTrace();
}
}
sections = s;
Field x = null;
try
{
x = CraftChunkData.class.getDeclaredField("sections");
x.setAccessible(true);
}
catch(Throwable e)
{
e.printStackTrace();
}
t = x;
}
public void inject(AtomicChunkData data)
{
for(int i = 0; i < 16; i++)
{
if(hasDataBit(i))
{
char[] fromSection = getChunkSection(i << 4, false);
char[] toSection = data.getChunkSection(i << 4, true);
for(int j = 0; j < fromSection.length; j++)
{
char x = fromSection[j];
if(x != 0)
{
toSection[j] = x;
}
}
}
}
}
public void setBlock(int x, int y, int z, MB mb)
{
setBlock(x, y, z, mb.material, mb.data);
}
}

View File

@ -1,80 +0,0 @@
package ninja.bytecode.iris.generator.atomics;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.bukkit.World;
import org.jnbt.ByteArrayTag;
import org.jnbt.CompoundTag;
import org.jnbt.NBTInputStream;
import org.jnbt.NBTOutputStream;
import org.jnbt.Tag;
import ninja.bytecode.shuriken.collections.KMap;
public class AtomicRegionData
{
private final World world;
private KMap<String, Tag> tag;
public AtomicRegionData(World world)
{
this.world = world;
tag = new KMap<>();
}
public void read(InputStream in) throws IOException
{
NBTInputStream nin = new NBTInputStream(in);
tag = new KMap<>();
tag.putAll(((CompoundTag) nin.readTag()).getValue());
nin.close();
}
public void write(OutputStream out) throws IOException
{
NBTOutputStream nos = new NBTOutputStream(out);
nos.writeTag(new CompoundTag("imca", tag));
nos.close();
}
public boolean contains(int rx, int rz)
{
return tag.containsKey(rx + "." + rz);
}
public void delete(int rx, int rz)
{
tag.remove(rx + "." + rz);
}
public void set(int rx, int rz, AtomicChunkData data) throws IOException
{
ByteArrayOutputStream boas = new ByteArrayOutputStream();
data.write(boas);
tag.put(rx + "." + rz, new ByteArrayTag(rx + "." + rz, boas.toByteArray()));
}
public AtomicChunkData get(int rx, int rz) throws IOException
{
if(!contains(rx, rz))
{
return null;
}
AtomicChunkData data = new AtomicChunkData(world);
ByteArrayTag btag = (ByteArrayTag) tag.get(rx + "." + rz);
ByteArrayInputStream in = new ByteArrayInputStream(btag.getValue());
data.read(in);
return data;
}
public World getWorld()
{
return world;
}
}

View File

@ -1,158 +0,0 @@
package ninja.bytecode.iris.generator.atomics;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.bukkit.World;
import ninja.bytecode.iris.util.SMCAVector;
import ninja.bytecode.shuriken.collections.KList;
import ninja.bytecode.shuriken.collections.KMap;
public class AtomicWorldData
{
private World world;
private KMap<SMCAVector, AtomicRegionData> loadedSections;
public AtomicWorldData(World world)
{
this.world = world;
loadedSections = new KMap<>();
getSubregionFolder().mkdirs();
}
public KList<SMCAVector> getLoadedRegions()
{
return loadedSections.k();
}
public AtomicRegionData getSubregion(int x, int z) throws IOException
{
if(!isSectionLoaded(x, z))
{
loadedSections.put(new SMCAVector(x, z), loadSection(x, z));
}
AtomicRegionData f = loadedSections.get(new SMCAVector(x, z));
return f;
}
public void saveAll() throws IOException
{
for(SMCAVector i : loadedSections.keySet())
{
saveSection(i);
}
}
public void unloadAll(boolean save) throws IOException
{
for(SMCAVector i : loadedSections.keySet())
{
unloadSection(i, save);
}
}
public void deleteSection(int x, int z) throws IOException
{
unloadSection(x, z, false);
getSubregionFile(x, z).delete();
}
public boolean isSectionLoaded(int x, int z)
{
return isSectionLoaded(new SMCAVector(x, z));
}
public boolean isSectionLoaded(SMCAVector s)
{
return loadedSections.containsKey(s);
}
public boolean unloadSection(int x, int z, boolean save) throws IOException
{
return unloadSection(new SMCAVector(x, z), save);
}
public boolean unloadSection(SMCAVector s, boolean save) throws IOException
{
if(!isSectionLoaded(s))
{
return false;
}
if(save)
{
saveSection(s);
}
loadedSections.remove(s);
return true;
}
public boolean saveSection(int x, int z) throws IOException
{
return saveSection(new SMCAVector(x, z));
}
public boolean saveSection(SMCAVector s) throws IOException
{
if(!isSectionLoaded(s.getX(), s.getZ()))
{
return false;
}
AtomicRegionData data = loadedSections.get(s);
FileOutputStream fos = new FileOutputStream(getSubregionFile(s.getX(), s.getZ()));
data.write(fos);
fos.close();
return true;
}
public AtomicRegionData loadSection(int x, int z) throws IOException
{
if(isSectionLoaded(x, z))
{
return loadedSections.get(new SMCAVector(x, z));
}
File file = getSubregionFile(x, z);
if(!file.exists())
{
return createSection(x, z);
}
FileInputStream fin = new FileInputStream(file);
AtomicRegionData data = new AtomicRegionData(world);
data.read(fin);
fin.close();
return data;
}
public AtomicRegionData createSection(int x, int z)
{
if(isSectionLoaded(x, z))
{
return loadedSections.get(new SMCAVector(x, z));
}
AtomicRegionData data = new AtomicRegionData(world);
loadedSections.put(new SMCAVector(x, z), data);
return data;
}
public File getSubregionFile(int x, int z)
{
return new File(getSubregionFolder(), "sr." + x + "." + z + ".smca");
}
public File getSubregionFolder()
{
return new File(world.getWorldFolder(), "subregion");
}
}

View File

@ -1,463 +0,0 @@
package ninja.bytecode.iris.generator.genobject;
import java.util.Collections;
import java.util.Random;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.generator.BlockPopulator;
import mortar.api.sched.S;
import mortar.logic.format.F;
import mortar.util.text.C;
import net.md_5.bungee.api.ChatColor;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.generator.parallax.ParallaxCache;
import ninja.bytecode.iris.generator.placer.AtomicParallaxPlacer;
import ninja.bytecode.iris.generator.placer.BukkitPlacer;
import ninja.bytecode.iris.generator.placer.NMSPlacer;
import ninja.bytecode.iris.pack.IrisBiome;
import ninja.bytecode.iris.util.IPlacer;
import ninja.bytecode.iris.util.MB;
import ninja.bytecode.iris.util.ObjectMode;
import ninja.bytecode.iris.util.SMCAVector;
import ninja.bytecode.shuriken.collections.KList;
import ninja.bytecode.shuriken.collections.KMap;
import ninja.bytecode.shuriken.collections.KSet;
import ninja.bytecode.shuriken.execution.ChronoLatch;
import ninja.bytecode.shuriken.execution.J;
import ninja.bytecode.shuriken.logging.L;
import ninja.bytecode.shuriken.math.M;
import ninja.bytecode.shuriken.math.RNG;
public class GenObjectDecorator extends BlockPopulator
{
private KList<PlacedObject> placeHistory;
private KMap<IrisBiome, KList<GenObjectGroup>> orderCache;
private KMap<IrisBiome, KMap<GenObjectGroup, Double>> populationCache;
private IPlacer placer;
private IrisGenerator g;
private ChronoLatch cl = new ChronoLatch(250);
public GenObjectDecorator(IrisGenerator generator)
{
this.g = generator;
placeHistory = new KList<>();
populationCache = new KMap<>();
orderCache = new KMap<>();
for(IrisBiome i : generator.getDimension().getBiomes())
{
KMap<GenObjectGroup, Double> gc = new KMap<>();
KMap<Integer, KList<GenObjectGroup>> or = new KMap<>();
int ff = 0;
for(String j : i.getSchematicGroups().k())
{
double c = i.getSchematicGroups().get(j);
try
{
GenObjectGroup g = generator.getDimension().getObjectGroup(j);
ff += g.size();
gc.put(g, c);
if(!or.containsKey(g.getPiority()))
{
or.put(g.getPiority(), new KList<>());
}
or.get(g.getPiority()).add(g);
}
catch(Throwable e)
{
L.f(ChatColor.RED + "Failed to inject " + j + " into GenObjectDecorator");
L.ex(e);
}
}
if(!gc.isEmpty())
{
KList<GenObjectGroup> g = new KList<>();
for(KList<GenObjectGroup> j : or.v())
{
g.addAll(j);
}
Collections.sort(g, (a, b) -> a.getPiority() - b.getPiority());
orderCache.put(i, g);
populationCache.put(i, gc);
if(Iris.settings.performance.verbose)
{
L.v(C.DARK_GREEN + i.getName() + ": " + C.DARK_AQUA + F.f(ff) + " Objects");
}
}
}
L.i("Population Cache is " + populationCache.size());
}
@Override
public void populate(World world, Random random, Chunk source)
{
Runnable m = () ->
{
try
{
if(g.isDisposed())
{
placeHistory.clear();
return;
}
KSet<IrisBiome> hits = new KSet<>();
int cx = source.getX();
int cz = source.getZ();
for(int i = 0; i < Iris.settings.performance.decorationAccuracy; i++)
{
int x = (cx << 4) + random.nextInt(16);
int z = (cz << 4) + random.nextInt(16);
IrisBiome biome = g.getBiome((int) g.getOffsetX(x, z), (int) g.getOffsetZ(x, z));
if(hits.contains(biome))
{
continue;
}
KMap<GenObjectGroup, Double> objects = populationCache.get(biome);
if(objects == null)
{
continue;
}
hits.add(biome);
populate(world, cx, cz, random, biome);
}
}
catch(Throwable e)
{
e.printStackTrace();
}
};
if(Iris.settings.performance.objectMode.equals(ObjectMode.QUICK_N_DIRTY))
{
J.a(m);
}
else
{
m.run();
}
}
@SuppressWarnings("deprecation")
private void populate(World world, int cx, int cz, Random random, IrisBiome biome)
{
for(GenObjectGroup i : orderCache.get(biome))
{
if(biome.getSchematicGroups().get(i.getName()) == null)
{
L.w(C.YELLOW + "Cannot find chance for " + C.RED + i.getName() + C.YELLOW + " in Biome " + C.RED + biome.getName());
continue;
}
for(int j = 0; j < getTries(biome.getSchematicGroups().get(i.getName())); j++)
{
if(M.r(Iris.settings.gen.objectDensity))
{
GenObject go = i.getSchematics().get(random.nextInt(i.getSchematics().size()));
int x = (cx << 4) + random.nextInt(16);
int z = (cz << 4) + random.nextInt(16);
if(i.getWorldChance() >= 0D)
{
int rngx = (int) Math.floor(x / (double) (i.getWorldRadius() == 0 ? 32 : i.getWorldRadius()));
int rngz = (int) Math.floor(z / (double) (i.getWorldRadius() == 0 ? 32 : i.getWorldRadius()));
if(new RNG(new SMCAVector(rngx, rngz).hashCode()).nextDouble() < i.getWorldChance())
{
if(Iris.settings.performance.verbose)
{
L.w(C.WHITE + "Object " + C.YELLOW + i.getName() + "/*" + C.WHITE + " failed to place due to a world chance.");
}
break;
}
}
int by = world.getHighestBlockYAt(x, z);
Block b = world.getBlockAt(x, by - 1, z);
MB mb = MB.of(b.getType(), b.getData());
if(!Iris.settings.performance.noObjectFail)
{
if(!mb.material.isSolid() || !biome.isSurface(mb.material))
{
if(Iris.settings.performance.verbose)
{
L.w(C.WHITE + "Object " + C.YELLOW + i.getName() + "/*" + C.WHITE + " failed to place in " + C.YELLOW + mb.material.toString().toLowerCase() + C.WHITE + " at " + C.YELLOW + F.f(x) + " " + F.f(by) + " " + F.f(z));
}
return;
}
}
if(Iris.settings.performance.objectMode.equals(ObjectMode.QUICK_N_DIRTY))
{
placer = new NMSPlacer(world);
}
else if(Iris.settings.performance.objectMode.equals(ObjectMode.LIGHTING_PHYSICS))
{
placer = new BukkitPlacer(world, true);
}
else if(Iris.settings.performance.objectMode.equals(ObjectMode.LIGHTING))
{
placer = new BukkitPlacer(world, false);
}
Runnable rx = () ->
{
Location start = go.place(x, by, z, placer);
if(start != null)
{
g.hitObject();
if(Iris.settings.performance.verbose)
{
L.v(C.GRAY + "Placed " + C.DARK_GREEN + i.getName() + C.WHITE + "/" + C.DARK_GREEN + go.getName() + C.GRAY + " at " + C.DARK_GREEN + F.f(start.getBlockX()) + " " + F.f(start.getBlockY()) + " " + F.f(start.getBlockZ()));
}
if(Iris.settings.performance.debugMode)
{
placeHistory.add(new PlacedObject(start.getBlockX(), start.getBlockY(), start.getBlockZ(), i.getName() + ":" + go.getName()));
if(placeHistory.size() > Iris.settings.performance.placeHistoryLimit)
{
while(placeHistory.size() > Iris.settings.performance.placeHistoryLimit)
{
placeHistory.remove(0);
}
}
}
}
};
if(Iris.settings.performance.objectMode.equals(ObjectMode.QUICK_N_DIRTY))
{
new S(20)
{
@Override
public void run()
{
rx.run();
}
};
}
else
{
rx.run();
}
}
}
}
if(placer != null && cl.flip())
{
placer.flush();
}
}
public void populateParallax(int cx, int cz, Random random)
{
try
{
if(g.isDisposed())
{
placeHistory.clear();
return;
}
ParallaxCache cache = new ParallaxCache(g);
KSet<IrisBiome> hits = new KSet<>();
for(int i = 0; i < Iris.settings.performance.decorationAccuracy; i++)
{
int x = (cx << 4) + random.nextInt(16);
int z = (cz << 4) + random.nextInt(16);
IrisBiome biome = cache.getBiome(x, z);
if(hits.contains(biome))
{
continue;
}
KMap<GenObjectGroup, Double> objects = populationCache.get(biome);
if(objects == null)
{
continue;
}
hits.add(biome);
populateParallax(cx, cz, random, biome, cache);
}
}
catch(Throwable e)
{
e.printStackTrace();
}
}
private void populateParallax(int cx, int cz, Random random, IrisBiome biome, ParallaxCache cache)
{
for(GenObjectGroup i : orderCache.get(biome))
{
if(biome.getSchematicGroups().get(i.getName()) == null)
{
L.w(C.YELLOW + "Cannot find chance for " + C.RED + i.getName() + C.YELLOW + " in Biome " + C.RED + biome.getName());
continue;
}
for(int j = 0; j < getTries(biome.getSchematicGroups().get(i.getName())); j++)
{
if(M.r(Iris.settings.gen.objectDensity))
{
if(i.getSchematics().isEmpty())
{
continue;
}
GenObject go = i.getSchematics().get(random.nextInt(i.getSchematics().size()));
int x = (cx << 4) + random.nextInt(16);
int z = (cz << 4) + random.nextInt(16);
if(i.getWorldChance() >= 0D)
{
int rngx = (int) Math.floor(x / (double) (i.getWorldRadius() == 0 ? 32 : i.getWorldRadius()));
int rngz = (int) Math.floor(z / (double) (i.getWorldRadius() == 0 ? 32 : i.getWorldRadius()));
if(new RNG(new SMCAVector(rngx, rngz).hashCode()).nextDouble() < i.getWorldChance())
{
if(Iris.settings.performance.verbose)
{
L.w(C.WHITE + "Object " + C.YELLOW + i.getName() + "/*" + C.WHITE + " failed to place due to a world chance.");
}
break;
}
}
int by = cache.getHeight(x, z);
MB mb = cache.get(x, by, z);
if(!Iris.settings.performance.noObjectFail)
{
if(!mb.material.isSolid() || !biome.isSurface(mb.material))
{
if(Iris.settings.performance.verbose)
{
L.w(C.WHITE + "Object " + C.YELLOW + i.getName() + "/*" + C.WHITE + " failed to place in " + C.YELLOW + mb.material.toString().toLowerCase() + C.WHITE + " at " + C.YELLOW + F.f(x) + " " + F.f(by) + " " + F.f(z));
}
return;
}
}
placer = new AtomicParallaxPlacer(g, cache);
Location start = go.place(x, by, z, placer);
if(start != null)
{
g.hitObject();
if(Iris.settings.performance.verbose)
{
L.v(C.GRAY + "Placed " + C.DARK_GREEN + i.getName() + C.WHITE + "/" + C.DARK_GREEN + go.getName() + C.GRAY + " at " + C.DARK_GREEN + F.f(start.getBlockX()) + " " + F.f(start.getBlockY()) + " " + F.f(start.getBlockZ()));
}
if(Iris.settings.performance.debugMode)
{
placeHistory.add(new PlacedObject(start.getBlockX(), start.getBlockY(), start.getBlockZ(), i.getName() + ":" + go.getName()));
if(placeHistory.size() > Iris.settings.performance.placeHistoryLimit)
{
while(placeHistory.size() > Iris.settings.performance.placeHistoryLimit)
{
placeHistory.remove(0);
}
}
}
}
}
}
}
if(placer != null && cl.flip())
{
placer.flush();
}
}
public int getTries(double chance)
{
if(chance <= 0)
{
return 0;
}
if(Math.floor(chance) == chance)
{
return (int) chance;
}
int floor = (int) Math.floor(chance);
if(chance - floor > 0 && M.r(chance - floor))
{
floor++;
}
return floor;
}
public KList<PlacedObject> getHistory()
{
return placeHistory;
}
public void dispose()
{
}
public PlacedObject randomObject(String string)
{
KList<PlacedObject> v = new KList<>();
for(PlacedObject i : placeHistory)
{
if(i.getF().toLowerCase().replaceAll("\\Q:\\E", "/").startsWith(string.toLowerCase()))
{
v.add(i);
}
}
if(v.isEmpty())
{
return null;
}
return v.getRandom();
}
}

View File

@ -1,387 +0,0 @@
package ninja.bytecode.iris.generator.genobject;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.function.Consumer;
import net.md_5.bungee.api.ChatColor;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.util.Direction;
import ninja.bytecode.shuriken.collections.KList;
import ninja.bytecode.shuriken.format.Form;
import ninja.bytecode.shuriken.io.IO;
import ninja.bytecode.shuriken.logging.L;
public class GenObjectGroup
{
private KList<GenObject> schematics;
private KList<GenObject> osSchematics;
private KList<GenObject> pxSchematics;
private KList<String> flags;
private String name;
private int priority;
private double worldChance;
private int worldRad;
public GenObjectGroup(String name)
{
this.schematics = new KList<>();
this.flags = new KList<>();
this.name = name;
priority = Integer.MIN_VALUE;
worldChance = Integer.MIN_VALUE;
worldRad = 32;
}
public void read(DataInputStream din) throws IOException
{
flags.clear();
schematics.clear();
name = din.readUTF();
int fl = din.readInt();
int sc = din.readInt();
for(int i = 0; i < fl; i++)
{
flags.add(din.readUTF());
}
for(int i = 0; i < sc; i++)
{
GenObject g = new GenObject(0, 0, 0);
g.readDirect(din);
schematics.add(g);
}
}
public void write(DataOutputStream dos, Consumer<Double> progress) throws IOException
{
dos.writeUTF(name);
dos.writeInt(flags.size());
dos.writeInt(schematics.size());
for(String i : flags)
{
dos.writeUTF(i);
}
int of = 0;
if(progress != null)
{
progress.accept((double) of / (double) schematics.size());
}
for(GenObject i : schematics)
{
i.writeDirect(dos);
of++;
if(progress != null)
{
progress.accept((double) of / (double) schematics.size());
}
}
}
public void applyLushFilter(double factor)
{
if(flags.contains("no lush"))
{
L.i(ChatColor.DARK_GREEN + "Skipping Lush Filter for " + ChatColor.GRAY + getName());
return;
}
L.i(ChatColor.GREEN + "Applying Lush Filter to " + ChatColor.WHITE + getName());
for(GenObject i : schematics)
{
i.applyLushFilter(factor);
}
}
public void applySnowFilter(int factor)
{
if(flags.contains("no snow"))
{
L.i(ChatColor.DARK_AQUA + "Skipping Snow Filter for " + ChatColor.GRAY + getName());
return;
}
L.i(ChatColor.AQUA + "Applying Snow Filter to " + ChatColor.WHITE + getName());
for(GenObject i : schematics)
{
i.applySnowFilter(factor);
}
}
public GenObjectGroup copy(String suffix)
{
GenObjectGroup gog = new GenObjectGroup(name + suffix);
gog.schematics = new KList<>();
gog.flags = flags.copy();
for(GenObject i : schematics)
{
GenObject g = i.copy();
g.setName(i.getName() + suffix);
gog.schematics.add(g);
}
return gog;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public KList<GenObject> getSchematics()
{
return schematics;
}
public KList<GenObject> getPXSchematics()
{
if(pxSchematics == null)
{
pxSchematics = new KList<>();
for(GenObject i : schematics)
{
if(!i.isOversized())
{
pxSchematics.add(i);
}
}
}
return pxSchematics;
}
public KList<GenObject> getOSSchematics()
{
if(osSchematics == null)
{
osSchematics = new KList<>();
for(GenObject i : schematics)
{
if(i.isOversized())
{
osSchematics.add(i);
}
}
}
return pxSchematics;
}
public void setSchematics(KList<GenObject> schematics)
{
this.schematics = schematics;
}
public KList<String> getFlags()
{
return flags;
}
public void setFlags(KList<String> flags)
{
this.flags = flags;
}
public int size()
{
return getSchematics().size();
}
public int getPiority()
{
if(priority == Integer.MIN_VALUE)
{
for(String i : flags)
{
if(i.startsWith("priority "))
{
priority = Integer.valueOf(i.split("\\Q \\E")[1]);
break;
}
}
}
return priority;
}
public static GenObjectGroup load(String string)
{
File folder = Iris.pack().loadFolder(string);
if(folder != null)
{
GenObjectGroup g = new GenObjectGroup(string);
for(File i : folder.listFiles())
{
if(i.getName().endsWith(".ifl"))
{
try
{
g.flags.add(IO.readAll(i).split("\\Q\n\\E"));
}
catch(IOException e)
{
L.ex(e);
}
}
if(i.getName().endsWith(".ish"))
{
try
{
GenObject s = GenObject.load(i);
g.getSchematics().add(s);
}
catch(IOException e)
{
L.f("Cannot load Schematic: " + string + "/" + i.getName());
L.ex(e);
}
}
}
return g;
}
return null;
}
public void processVariants()
{
for(GenObject i : getSchematics())
{
i.recalculateMountShift();
for(String j : flags)
{
i.computeFlag(j);
}
}
if(!flags.contains("no rotation"))
{
KList<GenObject> inject = new KList<>();
for(GenObject i : getSchematics())
{
for(Direction j : new Direction[] {Direction.S, Direction.E, Direction.W})
{
GenObject cp = i.copy();
GenObject f = cp;
f.rotate(Direction.N, j);
f.recalculateMountShift();
inject.add(f);
}
}
getSchematics().add(inject);
}
L.i(ChatColor.LIGHT_PURPLE + "Processed " + ChatColor.WHITE + Form.f(schematics.size()) + ChatColor.LIGHT_PURPLE + " Schematics in " + ChatColor.WHITE + name);
}
public void dispose()
{
for(GenObject i : schematics)
{
i.dispose();
}
schematics.clear();
flags.clear();
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((flags == null) ? 0 : flags.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + priority;
return result;
}
@Override
public boolean equals(Object obj)
{
if(this == obj)
return true;
if(obj == null)
return false;
if(getClass() != obj.getClass())
return false;
GenObjectGroup other = (GenObjectGroup) obj;
if(flags == null)
{
if(other.flags != null)
return false;
}
else if(!flags.equals(other.flags))
return false;
if(name == null)
{
if(other.name != null)
return false;
}
else if(!name.equals(other.name))
return false;
if(priority != other.priority)
return false;
return true;
}
public double getWorldChance()
{
if(worldChance == Integer.MIN_VALUE)
{
for(String i : flags)
{
if(i.startsWith("world chance "))
{
worldChance = Double.valueOf(i.split("\\Q \\E")[2]);
}
}
}
return worldChance;
}
public double getWorldRadius()
{
if(worldRad == Integer.MIN_VALUE)
{
for(String i : flags)
{
if(i.startsWith("world radius "))
{
worldRad = Integer.valueOf(i.split("\\Q \\E")[2]);
}
}
}
return worldRad;
}
}

View File

@ -1,95 +0,0 @@
package ninja.bytecode.iris.generator.genobject;
public class PlacedObject
{
private int x;
private int y;
private int z;
private String f;
public PlacedObject(int x, int y, int z, String f)
{
this.x = x;
this.y = y;
this.z = z;
this.f = f;
}
public int getX()
{
return x;
}
public void setX(int x)
{
this.x = x;
}
public int getY()
{
return y;
}
public void setY(int y)
{
this.y = y;
}
public int getZ()
{
return z;
}
public void setZ(int z)
{
this.z = z;
}
public String getF()
{
return f;
}
public void setF(String f)
{
this.f = f;
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((f == null) ? 0 : f.hashCode());
result = prime * result + x;
result = prime * result + y;
result = prime * result + z;
return result;
}
@Override
public boolean equals(Object obj)
{
if(this == obj)
return true;
if(obj == null)
return false;
if(getClass() != obj.getClass())
return false;
PlacedObject other = (PlacedObject) obj;
if(f == null)
{
if(other.f != null)
return false;
}
else if(!f.equals(other.f))
return false;
if(x != other.x)
return false;
if(y != other.y)
return false;
if(z != other.z)
return false;
return true;
}
}

View File

@ -1,34 +0,0 @@
package ninja.bytecode.iris.generator.layer;
import ninja.bytecode.iris.pack.IrisBiome;
import ninja.bytecode.shuriken.math.CNG;
import ninja.bytecode.shuriken.math.RNG;
public class BiomeNoiseGenerator
{
protected IrisBiome biome;
protected CNG gen;
private double block = 1D / 255D;
public BiomeNoiseGenerator(RNG rng, IrisBiome biome)
{
this.biome = biome;
//@builder
gen = new CNG(rng.nextParallelRNG(31289 - biome.getName().length() * biome.getRealBiome().ordinal()), 1D, 1)
.scale(0.0025 * biome.getGenScale())
.fractureWith(new CNG(rng.nextParallelRNG(2922 * biome.getName().length() - biome.getRealBiome().ordinal()), 1D, 1)
.scale(0.0075 * biome.getGenSwirlScale()), 20D * biome.getGenSwirl());
//@done
}
public double getHeight(double x, double z)
{
if(biome.getGenAmplifier() == 0)
{
return 0;
}
double r = block * 52;
return (gen.noise(x, z) * biome.getGenAmplifier() * r);
}
}

View File

@ -1,217 +0,0 @@
package ninja.bytecode.iris.generator.layer;
import java.util.Random;
import java.util.function.Function;
import org.bukkit.World;
import mortar.util.text.C;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.pack.IrisBiome;
import ninja.bytecode.iris.pack.IrisRegion;
import ninja.bytecode.iris.util.BiomeLayer;
import ninja.bytecode.iris.util.Borders;
import ninja.bytecode.iris.util.GenLayer;
import ninja.bytecode.iris.util.PolygonGenerator;
import ninja.bytecode.shuriken.collections.KList;
import ninja.bytecode.shuriken.collections.KMap;
import ninja.bytecode.shuriken.logging.L;
import ninja.bytecode.shuriken.math.CNG;
import ninja.bytecode.shuriken.math.RNG;
public class GenLayerBiome extends GenLayer
{
private KMap<String, IrisRegion> regions;
private Function<CNG, CNG> factory;
private CNG fracture;
private CNG fuzz;
private PolygonGenerator channel;
private PolygonGenerator ocean;
private BiomeLayer master;
public GenLayerBiome(IrisGenerator iris, World world, Random random, RNG rng, KList<IrisBiome> biomes)
{
super(iris, world, random, rng);
//@builder
channel = new PolygonGenerator(rng.nextParallelRNG(-12), 2, 0.0005, 1, (g)->g.fractureWith(new CNG(rng.nextParallelRNG(34), 1D, 2)
.scale(0.01), 30));
ocean = new PolygonGenerator(rng.nextParallelRNG(-11), 6, 0.005, 1, (g)->g.fractureWith(new CNG(rng.nextParallelRNG(34), 1D, 2)
.scale(0.01), 150));
fuzz = new CNG(rng.nextParallelRNG(9112), 1D * 12 * Iris.settings.gen.biomeEdgeFuzzScale, 1).scale(6.5);
fracture = new CNG(rng.nextParallelRNG(28), 1D, 4).scale(0.0021 * Iris.settings.gen.biomeEdgeScrambleScale)
.fractureWith(new CNG(rng.nextParallelRNG(34), 1D, 2)
.scale(0.01), 12250);
factory = (g) -> g.fractureWith(new CNG(rng.nextParallelRNG(29), 1D, 3)
.scale(0.005 * Iris.settings.gen.biomeScale), 1024D / Iris.settings.gen.biomeScale)
.fractureWith(new CNG(rng.nextParallelRNG(1212), 1D, 2)
.scale(0.04)
.fractureWith(new CNG(rng.nextParallelRNG(1216), 1D, 3).scale(0.0004), 266), 66);
//@done
regions = new KMap<>();
for(IrisBiome i : biomes)
{
if(i.getRegionID().equals("default"))
{
continue;
}
if(!regions.containsKey(i.getRegionID()))
{
regions.put(i.getRegionID(), new IrisRegion(i.getRegionID()));
}
regions.get(i.getRegionID()).getBiomes().add(i);
}
for(IrisRegion i : regions.values())
{
i.load();
}
int m = 0;
for(IrisBiome i : iris.getDimension().getBiomes())
{
i.seal(iris.getRTerrain().nextParallelRNG(3922 - m++));
}
master = BiomeLayer.compile(iris, 0.082 * Iris.settings.gen.biomeScale * 0.189, 1, factory);
if(Iris.settings.performance.verbose)
{
master.print(2);
}
}
public IrisBiome getBiome(double wxx, double wzx)
{
return getBiome(wxx, wzx, false);
}
public boolean isNearAquatic(int wxx, int wzx)
{
double wx = Math.round((double) wxx * (Iris.settings.gen.horizontalZoom / 1.90476190476)) * Iris.settings.gen.biomeScale;
double wz = Math.round((double) wzx * (Iris.settings.gen.horizontalZoom / 1.90476190476)) * Iris.settings.gen.biomeScale;
double xf = wx + ((fracture.noise(wx, wz) / 2D) * 200D * Iris.settings.gen.biomeEdgeScrambleRange);
double zf = wz - ((fracture.noise(wz, wx) / 2D) * 200D * Iris.settings.gen.biomeEdgeScrambleRange);
double x = xf - fuzz.noise(wx, wz);
double z = zf + fuzz.noise(wz, wx);
if(ocean.getIndex(x, z) == 0)
{
return true;
}
if(channel.hasBorder(3, 44, xf, zf))
{
return true;
}
if(Borders.isBorderWithin(x, z, 3, 24D, (x + z) / 100D, (xx, zz) -> ocean.getIndex(xx, zz)))
{
return true;
}
if(ocean.getClosestNeighbor(x, z) > 0.2)
{
return true;
}
if(channel.getClosestNeighbor(x, z) > 0.2)
{
return true;
}
if(channel.hasBorder(3, 7, xf, zf) || channel.hasBorder(3, 3, xf, zf))
{
return true;
}
return false;
}
public IrisBiome getBiome(double wxx, double wzx, boolean real)
{
double wx = Math.round((double) wxx * (Iris.settings.gen.horizontalZoom / 1.90476190476)) * Iris.settings.gen.biomeScale;
double wz = Math.round((double) wzx * (Iris.settings.gen.horizontalZoom / 1.90476190476)) * Iris.settings.gen.biomeScale;
double xf = wx + ((fracture.noise(wx, wz) / 2D) * 200D * Iris.settings.gen.biomeEdgeScrambleRange);
double zf = wz - ((fracture.noise(wz, wx) / 2D) * 200D * Iris.settings.gen.biomeEdgeScrambleRange);
double x = xf - fuzz.noise(wx, wz);
double z = zf + fuzz.noise(wz, wx);
IrisBiome biome = master.computeBiome(x, z);
if(real)
{
return biome;
}
if(ocean.getIndex(x, z) == 0)
{
IrisRegion region = getRegion(biome.getRegionID());
if(region == null)
{
L.f(C.YELLOW + "Cannot find Region " + C.RED + biome.getRegionID());
return biome;
}
if(!Borders.isBorderWithin(x, z, 7, 45, (x / 10D) + (z / 10D), (a, b) -> ocean.getIndex(a, b)))
{
if(region.getDeepOcean() == null)
{
L.f(C.YELLOW + "Cannot find Deep Ocean in Region" + C.RED + biome.getRegionID());
return biome;
}
return getRegion(biome.getRegionID()).getDeepOcean();
}
if(region.getOcean() == null)
{
L.f(C.YELLOW + "Cannot find Ocean in Region" + C.RED + biome.getRegionID());
return biome;
}
return getRegion(biome.getRegionID()).getOcean();
}
if(channel.hasBorder(3, 44, xf, zf))
{
IrisRegion region = getRegion(biome.getRegionID());
if(region == null)
{
L.f(C.YELLOW + "Cannot find Region " + C.RED + biome.getRegionID());
return biome;
}
if(region.getChannel() == null)
{
L.f(C.YELLOW + "Cannot find Channel in Region" + C.RED + biome.getRegionID());
return biome;
}
return getRegion(biome.getRegionID()).getChannel();
}
return biome;
}
@Override
public double generateLayer(double noise, double dx, double dz)
{
return noise;
}
public IrisRegion getRegion(String name)
{
return regions.get(name);
}
public void compileInfo(BiomeLayer l)
{
l.compileChildren(0.082 * Iris.settings.gen.biomeScale * 0.189, 1, factory, true);
}
}

View File

@ -1,64 +0,0 @@
package ninja.bytecode.iris.generator.layer;
import java.util.Random;
import org.bukkit.World;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.generator.atomics.AtomicChunkData;
import ninja.bytecode.iris.util.ChunkPlan;
import ninja.bytecode.iris.util.GenLayer;
import ninja.bytecode.iris.util.IrisInterpolation;
import ninja.bytecode.shuriken.math.CNG;
import ninja.bytecode.shuriken.math.M;
import ninja.bytecode.shuriken.math.RNG;
public class GenLayerCarving extends GenLayer
{
private CNG scram;
private CNG cng;
private CNG cngh;
private CNG cngo;
public GenLayerCarving(IrisGenerator iris, World world, Random random, RNG rng)
{
//@builder
super(iris, world, random, rng);
cng = new CNG(rng.nextParallelRNG(2339234), 1D, 1).scale(0.02);
cngh = new CNG(rng.nextParallelRNG(1939234), 1D, 1).scale(0.027);
cngo = new CNG(rng.nextParallelRNG(8939234), 1D, 1).scale(0.002);
scram = new CNG(rng.nextParallelRNG(2639634), 1D, 1).scale(0.15);
//@done
}
@Override
public double generateLayer(double gnoise, double dx, double dz)
{
return gnoise;
}
public boolean isCarved(double vwxxf, double vwzxf, int x, int z, double hl, AtomicChunkData data, ChunkPlan plan)
{
double a = cngh.noise(vwxxf, vwzxf);
double hmax = 99 + (a * 30);
double hmin = 68 + (a * 30);
if(hl > hmax || hl < hmin)
{
return false;
}
double wxxf = (scram.noise(vwxxf, vwzxf) * 12) - vwzxf;
double wzxf = (scram.noise(vwzxf, vwxxf) * 12) + vwxxf;
double downrange = M.lerpInverse(hmin, hmax, hl);
double opacity = IrisInterpolation.sinCenter(downrange);
if(cng.noise(wxxf, wzxf, hl / 3) < (opacity / 1.4D) * cngo.noise(wxxf, wzxf))
{
return true;
}
return false;
}
}

View File

@ -1,120 +0,0 @@
package ninja.bytecode.iris.generator.layer;
import java.util.Random;
import org.bukkit.Material;
import org.bukkit.World;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.generator.atomics.AtomicChunkData;
import ninja.bytecode.iris.util.Borders;
import ninja.bytecode.iris.util.ChunkPlan;
import ninja.bytecode.iris.util.GenLayer;
import ninja.bytecode.iris.util.PolygonGenerator;
import ninja.bytecode.shuriken.bench.PrecisionStopwatch;
import ninja.bytecode.shuriken.math.CNG;
import ninja.bytecode.shuriken.math.RNG;
public class GenLayerCaves extends GenLayer
{
private PolygonGenerator g;
private CNG gincline;
private CNG scram;
public GenLayerCaves(IrisGenerator iris, World world, Random random, RNG rng)
{
//@builder
super(iris, world, random, rng);
g = new PolygonGenerator(rng.nextParallelRNG(1111), 3, 0.024, 8, (c) -> c);
gincline = new CNG(rng.nextParallelRNG(1112), 1D, 3).scale(0.00652);
scram = new CNG(rng.nextParallelRNG(2639634), 1D, 1).scale(0.15);
//@done
}
@Override
public double generateLayer(double gnoise, double dx, double dz)
{
return gnoise;
}
public void genCaves(double vwxxf, double vwzxf, int x, int z, AtomicChunkData data, ChunkPlan plan)
{
PrecisionStopwatch s = PrecisionStopwatch.start();
double itr = 2;
double level = 8;
double incline = 187;
double baseWidth = 11;
double drop = 41;
double wxxf = (scram.noise(vwxxf, vwzxf) * 6) - vwzxf;
double wzxf = (scram.noise(vwzxf, vwxxf) * 6) + vwxxf;
for(double m = 1; m <= itr; m += 0.45)
{
double w = baseWidth / m;
if(w < 5)
{
break;
}
int lowest = 325;
double n = incline * gincline.noise((wxxf + (m * 10000)), (wzxf - (m * 10000)));
for(double i = 1; i <= w / 3D; i++)
{
if(Borders.isBorderWithin((wxxf + (m * 10000)), (wzxf - (m * 10000)), 5, w / 2D / i, (wxxf / 3D) + (wzxf / 3D), (xx, zz) -> g.getIndex(xx, zz)))
{
int h = (int) ((level + n) - drop);
if(dig(x, (int) (h + i), z, data) && h + i < lowest)
{
lowest = (int) (h + i);
}
if(dig(x, (int) (h - i), z, data) && h - i < lowest)
{
lowest = (int) (h - i);
}
if(i == 1)
{
if(dig(x, (int) (h), z, data) && h < lowest)
{
lowest = (int) (h);
}
}
}
}
}
iris.getMetrics().stop("caves:ms:x256:/chunk:..", s);
}
public boolean dig(int x, int y, int z, AtomicChunkData data)
{
Material a = data.getType(x, y, z);
Material b = data.getType(x, y, z + 1);
Material c = data.getType(x, y + 1, z);
Material d = data.getType(x + 1, y, z);
Material e = data.getType(x, y, z - 1);
Material f = data.getType(x, y - 1, z);
Material g = data.getType(x - 1, y, z);
if(can(a) && cann(b) && cann(c) && cann(d) && cann(e) && cann(f) && cann(g))
{
data.setBlock(x, y, z, Material.AIR);
return true;
}
return false;
}
public boolean cann(Material m)
{
return m.isSolid() || m.equals(Material.AIR) && !m.equals(Material.BEDROCK);
}
public boolean can(Material m)
{
return m.isSolid() && !m.equals(Material.BEDROCK);
}
}

View File

@ -1,67 +0,0 @@
package ninja.bytecode.iris.generator.layer;
import java.util.Random;
import org.bukkit.World;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.util.GenLayer;
import ninja.bytecode.shuriken.math.CNG;
import ninja.bytecode.shuriken.math.RNG;
public class GenLayerCliffs extends GenLayer
{
private double block;
private CNG gen;
private CNG sh;
private CNG ch;
public GenLayerCliffs(IrisGenerator iris, World world, Random random, RNG rng)
{
//@builder
super(iris, world, random, rng);
block = 1D / 255D;
gen = new CNG(rng.nextParallelRNG(128), 1D, 4).scale(0.02);
sh = new CNG(rng.nextParallelRNG(127), 1D, 1).scale(0.00367);
ch = new CNG(rng.nextParallelRNG(127), 1D, 1).scale(0.00413);
//@done
}
@Override
public double generateLayer(double gnoise, double dx, double dz)
{
return generateLayer(gnoise, dx, dz, 1D, 0.37D);
}
public double generateLayer(double gnoise, double dx, double dz, double cliffs, double chance)
{
if(gnoise < block * 66)
{
return gnoise;
}
double shift = 10.25 + (sh.noise(dx, dz) * 2.25) * cliffs;
double hits = 183D / shift;
double n = gnoise;
for(int i = (int) hits; i > 0; i--)
{
if(ch.noise(dx + (i * -1000), dz + (i * 1000)) >= chance)
{
continue;
}
double var = 12.2 * block;
double varCombined = 15.45 * block;
double sep = (shift / 1.8D) * block;
double height = (67 + (i * shift)) * block;
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 lo = (gen.noise(dx + (i * -1000), dz + (i * 1000)) * var) + height + sh;
double hi = (gen.noise(dz + (i * 1000), dx + (i * -1000)) * var) + height + sep + shv;
n = n > lo && n < hi ? lo : n;
}
return n;
}
}

View File

@ -1,44 +0,0 @@
package ninja.bytecode.iris.generator.layer;
import java.util.Random;
import org.bukkit.World;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.util.GenLayer;
import ninja.bytecode.shuriken.math.CNG;
import ninja.bytecode.shuriken.math.RNG;
public class GenLayerLayeredNoise extends GenLayer
{
private CNG gen;
private CNG fract;
public GenLayerLayeredNoise(IrisGenerator iris, World world, Random random, RNG rng)
{
//@builder
super(iris, world, random, rng);
fract = new CNG(rng.nextParallelRNG(16), 1D, 9).scale(0.0181);
gen = new CNG(rng.nextParallelRNG(17), 0.19D, 8)
.scale(0.012)
.amp(0.5)
.freq(1.1)
.fractureWith(new CNG(rng.nextParallelRNG(18), 1, 5)
.scale(0.018)
.child(new CNG(rng.nextParallelRNG(19), 0.745, 2)
.scale(0.1))
.fractureWith(new CNG(rng.nextParallelRNG(20), 1, 3)
.scale(0.15), 24), 44);
}
public double getHeight(double x, double z)
{
return 0.65* gen.noise(x, z);
}
@Override
public double generateLayer(double gnoise, double dx, double dz)
{
return 0.65 * gen.noise(gnoise, dx + (fract.noise(gnoise, dx, dz) * 333), dz - (fract.noise(dz, dx, gnoise) * 333));
}
}

View File

@ -1,145 +0,0 @@
package ninja.bytecode.iris.generator.layer;
import java.util.Random;
import org.bukkit.Material;
import org.bukkit.World;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.Settings.OreSettings;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.generator.atomics.AtomicChunkData;
import ninja.bytecode.iris.util.ChunkPlan;
import ninja.bytecode.iris.util.GenLayer;
import ninja.bytecode.iris.util.IrisInterpolation;
import ninja.bytecode.shuriken.bench.PrecisionStopwatch;
import ninja.bytecode.shuriken.math.CNG;
import ninja.bytecode.shuriken.math.M;
import ninja.bytecode.shuriken.math.RNG;
public class GenLayerOres extends GenLayer
{
private CNG ore;
public GenLayerOres(IrisGenerator iris, World world, Random random, RNG rng)
{
//@builder
super(iris, world, random, rng);
ore = new CNG(rng.nextParallelRNG(12944), 1D, 1).scale(0.1);
//@done
}
@Override
public double generateLayer(double gnoise, double dx, double dz)
{
return gnoise;
}
public void genOres(double xxf, double zzf, int x, int z, int h, AtomicChunkData data, ChunkPlan plan)
{
PrecisionStopwatch s = PrecisionStopwatch.start();
OreSettings o = Iris.settings.ore;
for(int i = 0; i < h; i++)
{
if(i >= o.ironMinHeight && i <= o.ironMaxHeight &&
ore.noise(xxf + 64, i, zzf - 64) < IrisInterpolation.lerpCenterSinBezier(
o.ironMinDispersion,
Iris.settings.ore.ironMaxDispersion,
M.lerpInverse(o.ironMinHeight, o.ironMaxHeight, i)))
{
if(!can(data.getType(x, i, z)))
{
continue;
}
data.setBlock(x, i, z, Material.IRON_ORE);
}
if(i >= o.coalMinHeight && i <= o.coalMaxHeight &&
ore.noise(xxf + 128, i, zzf - 128) < IrisInterpolation.lerpCenterSinBezier(
o.coalMinDispersion,
Iris.settings.ore.coalMaxDispersion,
M.lerpInverse(o.coalMinHeight, o.coalMaxHeight, i)))
{
if(!can(data.getType(x, i, z)))
{
continue;
}
data.setBlock(x, i, z, Material.COAL_ORE);
}
if(i >= o.goldMinHeight && i <= o.goldMaxHeight &&
ore.noise(xxf + 64, i, zzf - 128) < IrisInterpolation.lerpCenterSinBezier(
o.goldMinDispersion,
Iris.settings.ore.goldMaxDispersion,
M.lerpInverse(o.goldMinHeight, o.goldMaxHeight, i)))
{
if(!can(data.getType(x, i, z)))
{
continue;
}
data.setBlock(x, i, z, Material.GOLD_ORE);
}
if(i >= o.redstoneMinHeight && i <= o.redstoneMaxHeight &&
ore.noise(xxf + 128, i, zzf - 64) < IrisInterpolation.lerpCenterSinBezier(
o.redstoneMinDispersion,
Iris.settings.ore.redstoneMaxDispersion,
M.lerpInverse(o.redstoneMinHeight, o.redstoneMaxHeight, i)))
{
if(!can(data.getType(x, i, z)))
{
continue;
}
data.setBlock(x, i, z, Material.REDSTONE_ORE);
}
if(i >= o.lapisMinHeight && i <= o.lapisMaxHeight &&
ore.noise(xxf + 256, i, zzf - 64) < IrisInterpolation.lerpCenterSinBezier(
o.lapisMinDispersion,
Iris.settings.ore.lapisMaxDispersion,
M.lerpInverse(o.lapisMinHeight, o.lapisMaxHeight, i)))
{
if(!can(data.getType(x, i, z)))
{
continue;
}
data.setBlock(x, i, z, Material.LAPIS_ORE);
}
if(i >= o.diamondMinHeight && i <= o.diamondMaxHeight &&
ore.noise(xxf + 64, i, zzf - 256) < IrisInterpolation.lerpCenterSinBezier(
o.diamondMinDispersion,
Iris.settings.ore.diamondMaxDispersion,
M.lerpInverse(o.diamondMinHeight, o.diamondMaxHeight, i)))
{
if(!can(data.getType(x, i, z)))
{
continue;
}
data.setBlock(x, i, z, Material.DIAMOND_ORE);
}
if(i >= o.emeraldMinHeight && i <= o.emeraldMaxHeight &&
ore.noise(xxf + 128, i, zzf - 256) < IrisInterpolation.lerpCenterSinBezier(
o.emeraldMinDispersion,
Iris.settings.ore.emeraldMaxDispersion,
M.lerpInverse(o.emeraldMinHeight, o.emeraldMaxHeight, i)))
{
if(!can(data.getType(x, i, z)))
{
continue;
}
data.setBlock(x, i, z, Material.EMERALD_ORE);
}
}
iris.getMetrics().stop("ores:ms:x256:/chunk:..", s);
}
public boolean can(Material m)
{
return m.equals(Material.STONE) || m.name().endsWith("_ORE");
}
}

View File

@ -1,42 +0,0 @@
package ninja.bytecode.iris.generator.layer;
import java.util.Random;
import org.bukkit.World;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.util.GenLayer;
import ninja.bytecode.shuriken.math.CNG;
import ninja.bytecode.shuriken.math.RNG;
public class GenLayerSnow extends GenLayer
{
private CNG gen;
public GenLayerSnow(IrisGenerator iris, World world, Random random, RNG rng)
{
//@builder
super(iris, world, random, rng);
gen = new CNG(rng.nextParallelRNG(117), 1D, 1)
.scale(0.059)
.amp(0.5)
.freq(1.1)
.fractureWith(new CNG(rng.nextParallelRNG(18), 1, 6)
.scale(0.018)
.child(new CNG(rng.nextParallelRNG(19), 0.745, 2)
.scale(0.1))
.fractureWith(new CNG(rng.nextParallelRNG(20), 1, 3)
.scale(0.15), 24), 44);
}
public double getHeight(double x, double z)
{
return gen.noise(x, z);
}
@Override
public double generateLayer(double gnoise, double dx, double dz)
{
return getHeight(dx, dz);
}
}

View File

@ -1,45 +0,0 @@
package ninja.bytecode.iris.generator.parallax;
import ninja.bytecode.iris.generator.atomics.AtomicChunkData;
import ninja.bytecode.iris.pack.IrisBiome;
public class ParallaxAnchor
{
private final int height;
private final int water;
private final IrisBiome biome;
private final AtomicChunkData data;
public ParallaxAnchor(int height, int water, IrisBiome biome, AtomicChunkData data)
{
this.height = height;
this.water = water;
this.biome = biome;
this.data = data;
}
public AtomicChunkData getData()
{
return data;
}
public int getWater()
{
return water;
}
public int getHeight()
{
return height;
}
public int getWaterHeight()
{
return water;
}
public IrisBiome getBiome()
{
return biome;
}
}

View File

@ -1,102 +0,0 @@
package ninja.bytecode.iris.generator.parallax;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.generator.atomics.AtomicChunkData;
import ninja.bytecode.iris.pack.IrisBiome;
import ninja.bytecode.iris.util.ChunkPlan;
import ninja.bytecode.iris.util.MB;
import ninja.bytecode.iris.util.SMCAVector;
import ninja.bytecode.shuriken.collections.KMap;
import ninja.bytecode.shuriken.collections.KSet;
public class ParallaxCache
{
private KMap<SMCAVector, ChunkPlan> cachePlan;
private KMap<SMCAVector, AtomicChunkData> cacheData;
private KSet<SMCAVector> contains;
private IrisGenerator gen;
public ParallaxCache(IrisGenerator gen)
{
this.gen = gen;
cacheData = new KMap<>();
cachePlan = new KMap<>();
contains = new KSet<>();
}
public MB get(int x, int y, int z)
{
SMCAVector s = new SMCAVector(x, z);
SMCAVector c = new SMCAVector(x >> 4, z >> 4);
if(contains.contains(s) && cacheData.containsKey(c) && cachePlan.containsKey(c) )
{
return cacheData.get(c).getMB(x & 15, y, z & 15);
}
createData(x, z, s, c);
return cacheData.get(c).getMB(x & 15, y, z & 15);
}
public IrisBiome getBiome(int x, int z)
{
SMCAVector s = new SMCAVector(x, z);
SMCAVector c = new SMCAVector(x >> 4, z >> 4);
if(contains.contains(s) && cacheData.containsKey(c) && cachePlan.containsKey(c) )
{
return cachePlan.get(c).getBiome(x & 15, z & 15);
}
createData(x, z, s, c);
return cachePlan.get(c).getBiome(x & 15, z & 15);
}
public int getWaterHeight(int x, int z)
{
SMCAVector s = new SMCAVector(x, z);
SMCAVector c = new SMCAVector(x >> 4, z >> 4);
if(contains.contains(s) && cacheData.containsKey(c) && cachePlan.containsKey(c) )
{
return cachePlan.get(c).getRealWaterHeight(x & 15, z & 15);
}
createData(x, z, s, c);
return cachePlan.get(c).getRealWaterHeight(x & 15, z & 15);
}
public int getHeight(int x, int z)
{
SMCAVector s = new SMCAVector(x, z);
SMCAVector c = new SMCAVector(x >> 4, z >> 4);
if(contains.contains(s) && cacheData.containsKey(c) && cachePlan.containsKey(c) )
{
return cachePlan.get(c).getRealHeight(x & 15, z & 15);
}
createData(x, z, s, c);
return cachePlan.get(c).getRealHeight(x & 15, z & 15);
}
private void createData(int x, int z, SMCAVector s, SMCAVector c)
{
if(!cacheData.containsKey(c))
{
cacheData.put(c, new AtomicChunkData(gen.getWorld()));
}
if(!cachePlan.containsKey(c))
{
cachePlan.put(c, new ChunkPlan());
}
gen.computeAnchor(x, z, cachePlan.get(c), cacheData.get(c));
contains.add(s);
}
}

View File

@ -1,194 +0,0 @@
package ninja.bytecode.iris.generator.parallax;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.WorldSaveEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import mortar.api.nms.NMP;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.generator.atomics.AtomicChunkData;
import ninja.bytecode.iris.util.ChunkPlan;
import ninja.bytecode.iris.util.IrisWorldData;
import ninja.bytecode.iris.util.ObjectMode;
import ninja.bytecode.iris.util.SChunkVector;
import ninja.bytecode.shuriken.bench.PrecisionStopwatch;
import ninja.bytecode.shuriken.execution.TaskExecutor.TaskGroup;
import ninja.bytecode.shuriken.math.RNG;
public abstract class ParallaxWorldGenerator extends ParallelChunkGenerator implements Listener
{
private World world;
private IrisWorldData data;
private RNG rMaster;
private AtomicChunkData buffer;
protected boolean saving;
@Override
public final void init(World world, Random random)
{
this.world = world;
saving = true;
buffer = new AtomicChunkData(world);
this.data = new IrisWorldData(world);
this.rMaster = new RNG(world.getSeed() + 1);
onInit(world, rMaster.nextParallelRNG(1));
Bukkit.getPluginManager().registerEvents(this, Iris.instance);
}
public void disableSaving()
{
saving = false;
data.disableSaving();
}
public void enableSaving()
{
saving = true;
data.enableSaving();
}
@EventHandler
public void on(ChunkLoadEvent e)
{
if(Iris.settings.performance.objectMode.equals(ObjectMode.PARALLAX) && e.getWorld().equals(world))
{
NMP.host.relight(e.getChunk());
}
}
@EventHandler
public void on(WorldUnloadEvent e)
{
if(e.getWorld().equals(world))
{
getWorldData().dispose();
onUnload();
}
}
@EventHandler
public void on(WorldSaveEvent e)
{
if(!saving)
{
return;
}
if(e.getWorld().equals(world))
{
getWorldData().saveAll();
}
}
public ParallaxAnchor computeAnchor(int wx, int wz, ChunkPlan heightBuffer, AtomicChunkData data)
{
onGenColumn(wx, wz, wx & 15, wz & 15, heightBuffer, data, false);
return new ParallaxAnchor(heightBuffer.getRealHeight(wx & 15, wz & 15), heightBuffer.getRealWaterHeight(wx & 15, wz & 15), heightBuffer.getBiome(wx & 15, wz & 15), data);
}
public ParallaxAnchor computeAnchor(int wx, int wz)
{
ChunkPlan heightBuffer = new ChunkPlan();
onGenColumn(wx, wz, wx & 15, wz & 15, heightBuffer, buffer, false);
return new ParallaxAnchor(heightBuffer.getRealHeight(wx & 15, wz & 15), heightBuffer.getRealWaterHeight(wx & 15, wz & 15), heightBuffer.getBiome(wx & 15, wz & 15), buffer);
}
public void doGenParallax(int x, int z)
{
onGenParallax(x, z, getRMaster(x, z, -59328));
getWorldData().getChunk(x, z);
}
@Override
public final ChunkPlan initChunk(World world, int x, int z, Random random)
{
PrecisionStopwatch ps = PrecisionStopwatch.start();
TaskGroup g = startWork();
if(Iris.settings.performance.objectMode.equals(ObjectMode.PARALLAX))
{
for(int ii = -(getParallaxSize().getX() / 2) - 1; ii < (((getParallaxSize().getX() / 2) + 1)); ii++)
{
int i = ii;
for(int jj = -(getParallaxSize().getZ() / 2) - 1; jj < (((getParallaxSize().getZ() / 2) + 1)); jj++)
{
int j = jj;
int cx = x + i;
int cz = z + j;
if(!getWorldData().exists(cx, cz))
{
g.queue(() ->
{
onGenParallax(cx, cz, getRMaster(cx, cz, -59328));
getWorldData().getChunk(cx, cz);
});
}
}
}
g.execute();
}
((IrisGenerator) this).getMetrics().put("parallax:ms:/chunk", ps.getMillis());
return onInitChunk(world, x, z, random);
}
@Override
public final void postChunk(World world, int x, int z, Random random, AtomicChunkData data, ChunkPlan plan)
{
onPostChunk(world, x, z, random, data, plan);
getWorldData().inject(x, z, data);
}
@Override
public final Biome genColumn(int wx, int wz, int x, int z, ChunkPlan plan, AtomicChunkData data, boolean surface)
{
return onGenColumn(wx, wz, x, z, plan, data, surface);
}
public World getWorld()
{
return world;
}
public IrisWorldData getWorldData()
{
return data;
}
public RNG getRMaster()
{
return rMaster;
}
public RNG getRMaster(int x, int z, int signature)
{
return rMaster.nextParallelRNG((int) (signature + x * z + z + x * 2.12));
}
protected abstract void onUnload();
protected abstract SChunkVector getParallaxSize();
public abstract void onGenParallax(int x, int z, Random random);
public abstract void onInit(World world, Random random);
public abstract ChunkPlan onInitChunk(World world, int x, int z, Random random);
public abstract Biome onGenColumn(int wx, int wz, int x, int z, ChunkPlan plan, AtomicChunkData data, boolean surfaceOnly);
public abstract void onPostChunk(World world, int x, int z, Random random, AtomicChunkData data, ChunkPlan plan);
}

View File

@ -1,191 +0,0 @@
package ninja.bytecode.iris.generator.parallax;
import java.util.Random;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.generator.ChunkGenerator;
import mortar.util.text.C;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.generator.atomics.AtomicChunkData;
import ninja.bytecode.iris.util.ChunkPlan;
import ninja.bytecode.iris.util.ChunkSpliceListener;
import ninja.bytecode.shuriken.execution.TaskExecutor;
import ninja.bytecode.shuriken.execution.TaskExecutor.TaskGroup;
import ninja.bytecode.shuriken.execution.TaskExecutor.TaskResult;
import ninja.bytecode.shuriken.logging.L;
import ninja.bytecode.shuriken.math.RollingSequence;
import ninja.bytecode.shuriken.reaction.O;
public abstract class ParallelChunkGenerator extends ChunkGenerator
{
private int i;
private int j;
private int wx;
private int wz;
private TaskExecutor backupService;
private TaskGroup tg;
private boolean ready = false;
int cg = 0;
private RollingSequence rs = new RollingSequence(512);
private World world;
private ChunkSpliceListener splicer;
public void setSplicer(ChunkSpliceListener splicer)
{
this.splicer = splicer;
}
public World getWorld()
{
return world;
}
public Biome generateFullColumn(int a, int b, int c, int d, ChunkPlan p, AtomicChunkData data)
{
return genColumn(a, b, c, d, p, data, false);
}
private TaskGroup work(String n)
{
if(Iris.instance == null || Iris.exec() == null)
{
if(backupService == null)
{
L.f(C.RED + "Cannot contact ExecutionController!" + C.YELLOW + " Did you reload iris?");
L.w(C.YELLOW + "Spinning up a temporary backup service until the issue resolves...");
backupService = new TaskExecutor(4, Thread.MAX_PRIORITY, "Iris Backup Handover");
Iris.instance.reload();
}
return backupService.startWork();
}
else if(backupService != null)
{
L.i(C.GREEN + "Reconnected to the execution service. Closing backup service now...");
backupService.close();
}
return Iris.exec().getExecutor(world, n).startWork();
}
public TaskGroup startParallaxWork()
{
return work("Parallax");
}
public TaskGroup startWork()
{
return work("Generator");
}
public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome)
{
random = new Random(world.getSeed());
if(splicer != null)
{
AtomicChunkData d = splicer.onSpliceAvailable(world, random, x, z, biome);
if(d != null)
{
return d.toChunkData();
}
}
AtomicChunkData data = new AtomicChunkData(world);
try
{
this.world = world;
if(!ready)
{
init(world, random);
ready = true;
}
tg = startWork();
O<ChunkPlan> plan = new O<ChunkPlan>();
for(i = 0; i < 16; i++)
{
wx = (x << 4) + i;
for(j = 0; j < 16; j++)
{
wz = (z << 4) + j;
int a = wx;
int b = wz;
int c = i;
int d = j;
tg.queue(() ->
{
Biome f = generateFullColumn(a, b, c, d, plan.get(), data);
biome.setBiome(c, d, f);
});
}
}
plan.set(initChunk(world, x, z, random));
TaskResult r = tg.execute();
onDecorateChunk(world, x, z, data, plan.get());
TaskGroup gd = startWork();
for(i = 0; i < 16; i++)
{
wx = (x << 4) + i;
for(j = 0; j < 16; j++)
{
wz = (z << 4) + j;
int a = wx;
int b = wz;
int c = i;
int d = j;
gd.queue(() -> onDecorateColumn(world, c, d, a, b, data, plan.get()));
}
}
gd.execute();
postChunk(world, x, z, random, data, plan.get());
rs.put(r.timeElapsed);
cg++;
}
catch(Throwable e)
{
try
{
for(int i = 0; i < 16; i++)
{
for(int j = 0; j < 16; j++)
{
data.setBlock(i, 0, j, Material.RED_GLAZED_TERRACOTTA);
}
}
}
catch(Throwable ex)
{
}
e.printStackTrace();
}
return data.toChunkData();
}
protected abstract void onDecorateColumn(World world2, int i2, int j2, int wx2, int wz2, AtomicChunkData data, ChunkPlan chunkPlan);
protected abstract void onDecorateChunk(World world2, int x, int z, AtomicChunkData data, ChunkPlan chunkPlan);
public abstract void init(World world, Random random);
public abstract ChunkPlan initChunk(World world, int x, int z, Random random);
public abstract void postChunk(World world, int x, int z, Random random, AtomicChunkData data, ChunkPlan plan);
public abstract Biome genColumn(int wx, int wz, int x, int z, ChunkPlan plan, AtomicChunkData data, boolean surfaceOnly);
}

View File

@ -1,47 +0,0 @@
package ninja.bytecode.iris.generator.placer;
import org.bukkit.Location;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.generator.parallax.ParallaxCache;
import ninja.bytecode.iris.util.IrisWorldData;
import ninja.bytecode.iris.util.MB;
import ninja.bytecode.iris.util.Placer;
public class AtomicParallaxPlacer extends Placer
{
private IrisWorldData data;
private ParallaxCache cache;
public AtomicParallaxPlacer(IrisGenerator g, ParallaxCache cache)
{
super(g.getWorld());
this.data = g.getWorldData();
this.cache = cache;
}
@Override
public MB get(Location l)
{
return cache.get(l.getBlockX(), l.getBlockY(), l.getBlockZ());
}
@SuppressWarnings("deprecation")
@Override
public void set(Location l, MB mb)
{
data.setBlock(l.getBlockX(), l.getBlockY(), l.getBlockZ(), mb.material.getId(), mb.data);
}
@Override
public int getHighestY(Location l)
{
return cache.getHeight(l.getBlockX(), l.getBlockZ());
}
@Override
public int getHighestYUnderwater(Location l)
{
return cache.getWaterHeight(l.getBlockX(), l.getBlockZ());
}
}

View File

@ -1,63 +0,0 @@
package ninja.bytecode.iris.generator.placer;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import ninja.bytecode.iris.util.MB;
import ninja.bytecode.iris.util.Placer;
public class BukkitPlacer extends Placer
{
private final boolean applyPhysics;
public BukkitPlacer(World world, boolean applyPhysics)
{
super(world);
this.applyPhysics = applyPhysics;
}
@SuppressWarnings("deprecation")
@Override
public MB get(Location l)
{
Block b = world.getBlockAt(l);
return MB.of(b.getType(), b.getData());
}
@SuppressWarnings("deprecation")
@Override
public void set(Location l, MB mb)
{
l.getBlock().setTypeIdAndData(mb.material.getId(), mb.data, applyPhysics);
}
@Override
public int getHighestYUnderwater(Location l)
{
int y = getHighestY(l);
while(y > 0)
{
y--;
Block b = l.getWorld().getBlockAt(l.getBlockX(), y, l.getBlockZ());
if(!b.isEmpty())
{
if(b.isLiquid())
{
continue;
}
return y + 1;
}
}
return y;
}
@Override
public int getHighestY(Location l)
{
return world.getHighestBlockYAt(l);
}
}

View File

@ -1,92 +0,0 @@
package ninja.bytecode.iris.generator.placer;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import mortar.api.nms.Catalyst;
import mortar.api.nms.NMP;
import mortar.api.world.MaterialBlock;
import ninja.bytecode.iris.util.MB;
import ninja.bytecode.iris.util.Placer;
import ninja.bytecode.shuriken.collections.KSet;
import ninja.bytecode.shuriken.execution.J;
public class NMSPlacer extends Placer
{
private KSet<Chunk> c;
public NMSPlacer(World world)
{
super(world);
c = new KSet<>();
}
@SuppressWarnings("deprecation")
@Override
public MB get(Location l)
{
Block b = world.getBlockAt(l);
return MB.of(b.getType(), b.getData());
}
@SuppressWarnings("deprecation")
@Override
public void set(Location l, MB mb)
{
Catalyst.host.setBlock(l, new MaterialBlock(mb.material.getId(), mb.data));
c.add(l.getChunk());
}
@Override
public int getHighestY(Location l)
{
return world.getHighestBlockYAt(l);
}
@Override
public int getHighestYUnderwater(Location l)
{
int y = getHighestY(l);
while(y > 0)
{
y--;
Block b = l.getWorld().getBlockAt(l.getBlockX(), y, l.getBlockZ());
if(!b.isEmpty())
{
if(b.isLiquid())
{
continue;
}
return y + 1;
}
}
return y;
}
public void flush()
{
J.attempt(() ->
{
for(Chunk i : c)
{
NMP.host.relight(i);
J.a(() ->
{
for(Player j : i.getWorld().getPlayers())
{
NMP.CHUNK.refreshIgnorePosition(j, i);
}
});
}
c.clear();
});
}
}

View File

@ -1,8 +0,0 @@
package ninja.bytecode.iris.pack;
public enum BiomeType
{
LAND,
FLUID,
FRONT;
}

View File

@ -1,244 +0,0 @@
package ninja.bytecode.iris.pack;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.function.Consumer;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import org.bukkit.World.Environment;
import org.bukkit.block.Biome;
import net.md_5.bungee.api.ChatColor;
import ninja.bytecode.iris.generator.genobject.GenObject;
import ninja.bytecode.iris.generator.genobject.GenObjectGroup;
import ninja.bytecode.iris.util.SChunkVector;
import ninja.bytecode.iris.util.SBlockVector;
import ninja.bytecode.shuriken.collections.KList;
import ninja.bytecode.shuriken.collections.KMap;
import ninja.bytecode.shuriken.io.CustomOutputStream;
import ninja.bytecode.shuriken.json.JSONObject;
import ninja.bytecode.shuriken.logging.L;
import ninja.bytecode.shuriken.math.RNG;
import ninja.bytecode.shuriken.reaction.O;
public class CompiledDimension
{
public static IrisBiome theVoid = new IrisBiome("Void", Biome.VOID).height(0).seal(RNG.r);
private IrisDimension dimension;
private KList<IrisBiome> biomes;
private KMap<String, IrisBiome> biomeCache;
private KMap<String, GenObjectGroup> objects;
private SBlockVector maxSize;
private SChunkVector maxChunkSize;
public CompiledDimension(IrisDimension dimension)
{
this.dimension = dimension;
biomes = new KList<>();
biomeCache = new KMap<>();
objects = new KMap<>();
maxSize = new SBlockVector(0, 0, 0);
maxChunkSize = new SChunkVector(0, 0);
}
public void read(InputStream in) throws IOException
{
GZIPInputStream gin = new GZIPInputStream(in);
DataInputStream din = new DataInputStream(gin);
dimension = new IrisDimension();
dimension.fromJSON(new JSONObject(din.readUTF()), false);
int bi = din.readInt();
int ob = din.readInt();
for(int i = 0; i < bi; i++)
{
IrisBiome b = new IrisBiome("Loading", Biome.VOID);
b.fromJSON(new JSONObject(din.readUTF()), false);
}
for(int i = 0; i < ob; i++)
{
GenObjectGroup g = new GenObjectGroup("Loading");
g.read(din);
}
}
public void write(OutputStream out, Consumer<Double> progress) throws IOException
{
GZIPOutputStream gzo = new CustomOutputStream(out, 1);
DataOutputStream dos = new DataOutputStream(gzo);
dos.writeUTF(dimension.toJSON().toString(0));
dos.writeInt(biomes.size());
dos.writeInt(objects.size());
for(IrisBiome i : biomes)
{
dos.writeUTF(i.toJSON().toString(0));
}
O<Integer> tc = new O<>();
O<Integer> oc = new O<>();
O<Integer> cc = new O<>();
tc.set(0);
oc.set(0);
cc.set(0);
for(GenObjectGroup i : objects.v())
{
tc.set(tc.get() + i.size());
}
for(GenObjectGroup i : objects.v().shuffle())
{
i.write(dos, (o) ->
{
cc.set((int) (o * i.size()));
if(progress != null)
{
progress.accept((double) (oc.get() + cc.get()) / (double) tc.get());
}
});
oc.set(oc.get() + cc.get());
cc.set(0);
}
dos.close();
}
public void registerBiome(IrisBiome j)
{
biomes.add(j);
biomeCache.put(j.getName(), j);
}
public void registerObject(GenObjectGroup g)
{
if(g.getName().startsWith("pack/objects/"))
{
g.setName(g.getName().replaceFirst("\\Qpack/objects/\\E", ""));
}
objects.put(g.getName(), g);
}
public String getName()
{
return dimension.getName();
}
public KList<IrisBiome> getBiomes()
{
return biomes;
}
public Environment getEnvironment()
{
return dimension.getEnvironment();
}
public GenObjectGroup getObjectGroup(String j)
{
return objects.get(j);
}
public int countObjects()
{
int m = 0;
for(GenObjectGroup i : objects.v())
{
m += i.size();
}
return m;
}
public void sort()
{
biomes.sort();
}
public IrisBiome getBiomeByName(String name)
{
IrisBiome b = biomeCache.get(name);
if(b == null)
{
L.f(ChatColor.RED + "Cannot Find Biome: " + ChatColor.GOLD + name);
return theVoid;
}
return b;
}
public void dispose()
{
biomes.clear();
biomeCache.clear();
for(GenObjectGroup i : objects.values())
{
i.dispose();
}
objects.clear();
}
public void computeObjectSize()
{
int maxWidth = 0;
int maxHeight = 0;
int maxDepth = 0;
for(GenObjectGroup i : objects.values())
{
for(GenObject j : i.getSchematics().copy())
{
maxWidth = j.getW() > maxWidth ? j.getW() : maxWidth;
maxHeight = j.getH() > maxHeight ? j.getH() : maxHeight;
maxDepth = j.getD() > maxDepth ? j.getD() : maxDepth;
}
}
maxSize = new SBlockVector(maxWidth, maxHeight, maxDepth);
maxChunkSize = new SChunkVector(Math.ceil((double) (maxWidth) / 16D), Math.ceil((double) (maxDepth) / 16D));
L.i("Max Object Bound is " + maxWidth + ", " + maxHeight + ", " + maxDepth);
L.i("Max Object Region is " + maxChunkSize.getX() + " by " + maxChunkSize.getZ() + " Chunks");
}
public static IrisBiome getTheVoid()
{
return theVoid;
}
public IrisDimension getDimension()
{
return dimension;
}
public KMap<String, IrisBiome> getBiomeCache()
{
return biomeCache;
}
public KMap<String, GenObjectGroup> getObjects()
{
return objects;
}
public SBlockVector getMaxSize()
{
return maxSize;
}
public SChunkVector getMaxChunkSize()
{
return maxChunkSize;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,109 +0,0 @@
package ninja.bytecode.iris.pack;
import java.io.IOException;
import org.bukkit.World.Environment;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.shuriken.collections.KList;
import ninja.bytecode.shuriken.execution.J;
import ninja.bytecode.shuriken.json.JSONArray;
import ninja.bytecode.shuriken.json.JSONException;
import ninja.bytecode.shuriken.json.JSONObject;
public class IrisDimension
{
private String name;
private Environment environment;
KList<IrisBiome> biomes;
public IrisDimension(JSONObject o) throws JSONException, IOException
{
this();
fromJSON(o);
}
public IrisDimension()
{
biomes = new KList<IrisBiome>();
environment = Environment.NORMAL;
}
public void fromJSON(JSONObject o) throws JSONException, IOException
{
fromJSON(o, true);
}
public void fromJSON(JSONObject o, boolean chain) throws JSONException, IOException
{
name = o.getString("name");
J.attempt(() -> environment = Environment.valueOf(o.getString("environment").toUpperCase().replaceAll(" ", "_")));
try
{
biomes = chain ? biomesFromArray(o.getJSONArray("biomes")) : new KList<>();
}
catch(Throwable e)
{
e.printStackTrace();
}
}
public JSONObject toJSON()
{
JSONObject o = new JSONObject();
o.put("name", name);
o.put("environment", environment.name().toLowerCase().replaceAll("_", " "));
o.put("biomes", biomesToArray(biomes));
return o;
}
private KList<IrisBiome> biomesFromArray(JSONArray a) throws JSONException, IOException
{
KList<IrisBiome> b = new KList<>();
for(int i = 0; i < a.length(); i++)
{
int ii = i;
IrisBiome bb = Iris.pack().loadBiome(a.getString(ii));
Iris.pack().registerBiome(a.getString(ii), bb);
b.add(bb);
}
return b;
}
private JSONArray biomesToArray(KList<IrisBiome> b)
{
JSONArray a = new JSONArray();
for(IrisBiome i : b)
{
a.put(i.getName().toLowerCase().replaceAll(" ", "_"));
}
return a;
}
public KList<IrisBiome> getBiomes()
{
return biomes;
}
public String getName()
{
return name;
}
public Environment getEnvironment()
{
return environment;
}
public void dispose()
{
biomes.clear();
}
}

View File

@ -1,86 +0,0 @@
package ninja.bytecode.iris.pack;
import java.io.IOException;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.shuriken.collections.KList;
import ninja.bytecode.shuriken.execution.J;
import ninja.bytecode.shuriken.json.JSONArray;
import ninja.bytecode.shuriken.json.JSONException;
import ninja.bytecode.shuriken.json.JSONObject;
public class IrisPack
{
private KList<String> dimensions;
private KList<String> biomes;
private KList<String> objects;
public IrisPack()
{
this.dimensions = new KList<>();
this.biomes = new KList<>();
this.objects = new KList<>();
}
public IrisPack(JSONObject o)
{
this();
fromJSON(o);
}
public void fromJSON(JSONObject o)
{
J.attempt(() -> dimensions = fromArray(o.getJSONArray("dimensions")));
J.attempt(() -> biomes = fromArray(o.getJSONArray("biomes")));
J.attempt(() -> objects = fromArray(o.getJSONArray("objects")));
}
public JSONObject toJSON()
{
JSONObject o = new JSONObject();
o.put("dimensions", toArray(dimensions));
o.put("biomes", toArray(biomes));
o.put("objects", toArray(objects));
return o;
}
public KList<String> fromArray(JSONArray ja)
{
KList<String> g = new KList<>();
for(int i = 0; i < ja.length(); i++)
{
g.add(ja.getString(i));
}
return g;
}
public JSONArray toArray(KList<String> s)
{
JSONArray ja = new JSONArray();
for(String i : s)
{
ja.put(i);
}
return ja;
}
public void load() throws JSONException, IOException
{
for(String i : dimensions)
{
IrisDimension d = Iris.pack().loadDimension(i);
Iris.pack().registerDimension(i, d);
}
}
public void loadBiome(String s) throws JSONException, IOException
{
IrisBiome b = Iris.pack().loadBiome(s);
Iris.pack().registerBiome(s, b);
}
}

View File

@ -1,123 +0,0 @@
package ninja.bytecode.iris.pack;
import java.util.Objects;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.shuriken.collections.KList;
import ninja.bytecode.shuriken.execution.J;
import ninja.bytecode.shuriken.json.JSONObject;
public class IrisRegion
{
private String name;
private KList<IrisBiome> biomes;
private IrisBiome ocean;
private IrisBiome deepOcean;
private IrisBiome lake;
private IrisBiome lakeBeach;
private IrisBiome channel;
private IrisBiome beach;
public IrisRegion(String name)
{
this.name = name;
this.biomes = new KList<>();
beach = null;
ocean = null;
deepOcean = null;
lake = null;
lakeBeach = null;
channel = null;
}
public void load()
{
J.attempt(() ->
{
JSONObject o = Iris.pack().loadJSON("pack/regions/" + name + ".json");
J.attempt(() -> name = o.getString("name"));
J.attempt(() -> ocean = Iris.pack().getBiomeById(o.getString("ocean")));
J.attempt(() -> deepOcean = Iris.pack().getBiomeById(o.getString("deepOcean")));
J.attempt(() -> beach = Iris.pack().getBiomeById(o.getString("beach")));
J.attempt(() -> lake = Iris.pack().getBiomeById(o.getString("lake")));
J.attempt(() -> lakeBeach = Iris.pack().getBiomeById(o.getString("shore")));
J.attempt(() -> channel = Iris.pack().getBiomeById(o.getString("channel")));
});
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public KList<IrisBiome> getBiomes()
{
return biomes;
}
public void setBiomes(KList<IrisBiome> biomes)
{
this.biomes = biomes;
}
public IrisBiome getBeach()
{
return beach;
}
public void setBeach(IrisBiome beach)
{
this.beach = beach;
}
public IrisBiome getOcean()
{
return ocean;
}
public IrisBiome getDeepOcean()
{
return deepOcean;
}
public IrisBiome getLake()
{
return lake;
}
public IrisBiome getShore()
{
return lakeBeach;
}
public IrisBiome getChannel()
{
return channel;
}
@Override
public int hashCode()
{
return Objects.hash(beach, biomes, channel, lake, lakeBeach, name, ocean);
}
@Override
public boolean equals(Object obj)
{
if(this == obj)
{
return true;
}
if(!(obj instanceof IrisRegion))
{
return false;
}
IrisRegion other = (IrisRegion) obj;
return Objects.equals(beach, other.beach) && Objects.equals(biomes, other.biomes) && Objects.equals(channel, other.channel) && Objects.equals(lake, other.lake) && Objects.equals(lakeBeach, other.lakeBeach) && Objects.equals(name, other.name) && Objects.equals(ocean, other.ocean);
}
}

View File

@ -1,31 +0,0 @@
package ninja.bytecode.iris.util;
import org.bukkit.util.Vector;
public enum Axis
{
X(1, 0, 0),
Y(0, 1, 0),
Z(0, 0, 1);
private int x;
private int y;
private int z;
private Axis(int x, int y, int z)
{
this.x = x;
this.y = y;
this.z = z;
}
public Vector positive()
{
return new Vector(x, y, z);
}
public Vector negative()
{
return VectorMath.reverse(positive());
}
}

View File

@ -0,0 +1,219 @@
package ninja.bytecode.iris.util;
import java.util.Random;
/**
* Generates noise using the "classic" perlin generator
*
* @see SimplexNoiseC "Improved" and faster version with slighly
* different results
*/
public class BasePerlinNoiseGenerator extends NoiseGenerator
{
protected static final int grad3[][] = {{1, 1, 0}, {-1, 1, 0}, {1, -1, 0}, {-1, -1, 0}, {1, 0, 1}, {-1, 0, 1}, {1, 0, -1}, {-1, 0, -1}, {0, 1, 1}, {0, -1, 1}, {0, 1, -1}, {0, -1, -1}};
private static final BasePerlinNoiseGenerator instance = new BasePerlinNoiseGenerator();
protected BasePerlinNoiseGenerator()
{
int p[] = {151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180};
for(int i = 0; i < 512; i++)
{
perm[i] = p[i & 255];
}
}
/**
* Creates a seeded perlin noise generator for the given seed
*
* @param seed
* Seed to construct this generator for
*/
public BasePerlinNoiseGenerator(long seed)
{
this(new Random(seed));
}
/**
* Creates a seeded perlin noise generator with the given Random
*
* @param rand
* Random to construct with
*/
public BasePerlinNoiseGenerator(Random rand)
{
offsetX = rand.nextDouble() * 256;
offsetY = rand.nextDouble() * 256;
offsetZ = rand.nextDouble() * 256;
for(int i = 0; i < 256; i++)
{
perm[i] = rand.nextInt(256);
}
for(int i = 0; i < 256; i++)
{
int pos = rand.nextInt(256 - i) + i;
int old = perm[i];
perm[i] = perm[pos];
perm[pos] = old;
perm[i + 256] = perm[i];
}
}
/**
* Computes and returns the 1D unseeded perlin noise for the given coordinates
* in 1D space
*
* @param x
* X coordinate
* @return Noise at given location, from range -1 to 1
*/
public static double getNoise(double x)
{
return instance.noise(x);
}
/**
* Computes and returns the 2D unseeded perlin noise for the given coordinates
* in 2D space
*
* @param x
* X coordinate
* @param y
* Y coordinate
* @return Noise at given location, from range -1 to 1
*/
public static double getNoise(double x, double y)
{
return instance.noise(x, y);
}
/**
* Computes and returns the 3D unseeded perlin noise for the given coordinates
* in 3D space
*
* @param x
* X coordinate
* @param y
* Y coordinate
* @param z
* Z coordinate
* @return Noise at given location, from range -1 to 1
*/
public static double getNoise(double x, double y, double z)
{
return instance.noise(x, y, z);
}
/**
* Gets the singleton unseeded instance of this generator
*
* @return Singleton
*/
public static BasePerlinNoiseGenerator getInstance()
{
return instance;
}
@Override
public double noise(double x, double y, double z)
{
x += offsetX;
y += offsetY;
z += offsetZ;
int floorX = floor(x);
int floorY = floor(y);
int floorZ = floor(z);
// Find unit cube containing the point
int X = floorX & 255;
int Y = floorY & 255;
int Z = floorZ & 255;
// Get relative xyz coordinates of the point within the cube
x -= floorX;
y -= floorY;
z -= floorZ;
// Compute fade curves for xyz
double fX = fade(x);
double fY = fade(y);
double fZ = fade(z);
// Hash coordinates of the cube corners
int A = perm[X] + Y;
int AA = perm[A] + Z;
int AB = perm[A + 1] + Z;
int B = perm[X + 1] + Y;
int BA = perm[B] + Z;
int BB = perm[B + 1] + Z;
return lerp(fZ, lerp(fY, lerp(fX, grad(perm[AA], x, y, z), grad(perm[BA], x - 1, y, z)), lerp(fX, grad(perm[AB], x, y - 1, z), grad(perm[BB], x - 1, y - 1, z))), lerp(fY, lerp(fX, grad(perm[AA + 1], x, y, z - 1), grad(perm[BA + 1], x - 1, y, z - 1)), lerp(fX, grad(perm[AB + 1], x, y - 1, z - 1), grad(perm[BB + 1], x - 1, y - 1, z - 1))));
}
/**
* Generates noise for the 1D coordinates using the specified number of octaves
* and parameters
*
* @param x
* X-coordinate
* @param octaves
* Number of octaves to use
* @param frequency
* How much to alter the frequency by each octave
* @param amplitude
* How much to alter the amplitude by each octave
* @return Resulting noise
*/
public static double getNoise(double x, int octaves, double frequency, double amplitude)
{
return instance.noise(x, octaves, frequency, amplitude);
}
/**
* Generates noise for the 2D coordinates using the specified number of octaves
* and parameters
*
* @param x
* X-coordinate
* @param y
* Y-coordinate
* @param octaves
* Number of octaves to use
* @param frequency
* How much to alter the frequency by each octave
* @param amplitude
* How much to alter the amplitude by each octave
* @return Resulting noise
*/
public static double getNoise(double x, double y, int octaves, double frequency, double amplitude)
{
return instance.noise(x, y, octaves, frequency, amplitude);
}
/**
* Generates noise for the 3D coordinates using the specified number of octaves
* and parameters
*
* @param x
* X-coordinate
* @param y
* Y-coordinate
* @param z
* Z-coordinate
* @param octaves
* Number of octaves to use
* @param frequency
* How much to alter the frequency by each octave
* @param amplitude
* How much to alter the amplitude by each octave
* @return Resulting noise
*/
public static double getNoise(double x, double y, double z, int octaves, double frequency, double amplitude)
{
return instance.noise(x, y, z, octaves, frequency, amplitude);
}
}

View File

@ -1,219 +0,0 @@
package ninja.bytecode.iris.util;
import java.util.function.Function;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import mortar.lang.collection.GList;
import mortar.lang.collection.GMap;
import mortar.logic.format.F;
import mortar.util.text.C;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.pack.BiomeType;
import ninja.bytecode.iris.pack.IrisBiome;
import ninja.bytecode.iris.util.PolygonGenerator.EnumPolygonGenerator;
import ninja.bytecode.shuriken.collections.KSet;
import ninja.bytecode.shuriken.logging.L;
import ninja.bytecode.shuriken.math.CNG;
import ninja.bytecode.shuriken.math.RNG;
public class BiomeLayer
{
public static final IrisBiome VOID = new IrisBiome("Master", Biome.VOID).height(-1).dirt(MB.of(Material.END_BRICKS)).seal(RNG.r);
private GList<BiomeLayer> children;
private EnumPolygonGenerator<BiomeLayer> gen;
private IrisBiome biome;
private IrisGenerator iris;
public BiomeLayer(IrisGenerator iris, IrisBiome biome)
{
this.biome = biome == null ? VOID : biome;
this.iris = iris;
this.children = new GList<>();
}
public void compileChildren(double scale, int octaves, Function<CNG, CNG> factory, boolean inf)
{
if(gen != null)
{
return;
}
if(children.isEmpty())
{
gen = null;
return;
}
GList<BiomeLayer> b = new GList<>();
GMap<BiomeLayer, Double> rarities = new GMap<>();
for(BiomeLayer i : getChildren())
{
b.add(i);
rarities.put(i, i.getBiome().getRarity());
}
if(!getBiome().equals(VOID))
{
b.add(this);
rarities.put(this, getBiome().getRarity());
}
gen = new EnumPolygonGenerator<>(iris.getRTerrain().nextParallelRNG(1022 + getBiome().getRealBiome().ordinal()), scale, octaves, b, rarities, factory).useRarity();
for(BiomeLayer i : getChildren())
{
i.compileChildren(scale, octaves, factory, inf);
}
}
private IrisBiome computeBiome(double x, double z, GList<String> f)
{
if(gen != null)
{
BiomeLayer b = gen.getChoice(x, z);
if(b.biome.equals(biome))
{
return biome;
}
if(f.contains(b.getBiome().getName()))
{
f.add("...");
f.add(b.getBiome().getName());
L.w(C.YELLOW + "Cyclic Biome Heiarchy Detected! " + C.RED + f.toString(C.GRAY + " -> " + C.RED));
return b.biome;
}
f.add(b.getBiome().getName());
return b.computeBiome(x, z, f);
}
return getBiome();
}
public IrisBiome computeBiome(double x, double z)
{
return computeBiome(x, z, new GList<String>());
}
public void addLayer(IrisBiome biome)
{
addLayer(new BiomeLayer(iris, biome));
}
public void addLayer(BiomeLayer layer)
{
getChildren().add(layer);
}
public IrisBiome getBiome()
{
return biome;
}
public GList<BiomeLayer> getChildren()
{
return children;
}
public void setChildren(GList<BiomeLayer> children)
{
this.children = children;
}
public void print(int indent)
{
print(0, F.repeat(" ", indent));
}
private void print(int index, String indent)
{
L.i(C.GRAY + F.repeat(indent, index) + "Layer " + C.DARK_GREEN + getBiome().getName() + C.GRAY + "(" + C.GOLD + getBiome().getRarityString() + C.GRAY + ")" + (getBiome().getGenAmplifier() != 0.35 ? C.DARK_AQUA + " A: " + getBiome().getGenAmplifier() : "") + (getBiome().getHeight() != 0.0 ? C.DARK_RED + " H: " + getBiome().getHeight() : "") + (getBiome().hasCliffs() ? C.DARK_PURPLE + " C: " + getBiome().getCliffChance() + " x " + getBiome().getCliffScale() : ""));
L.flush();
if(!getBiome().getSchematicGroups().isEmpty())
{
for(String i : getBiome().getSchematicGroups().k())
{
String f = "";
double percent = getBiome().getSchematicGroups().get(i);
if(percent > 1D)
{
f = (int) percent + " + " + F.pc(percent - (int) percent, percent - (int) percent >= 0.01 ? 0 : 3);
}
else
{
f = F.pc(percent, percent >= 0.01 ? 0 : 3);
}
L.i(C.GRAY + F.repeat(indent, index + 1) + "Object " + C.GOLD + i + C.GRAY + " at " + C.GOLD + f + C.GRAY + " (" + F.f(iris.getDimension().getObjectGroup(i).size()) + " variants)");
}
}
L.flush();
for(BiomeLayer i : children)
{
i.print(index + 1, indent);
}
}
public static BiomeLayer compile(IrisGenerator g, double scale, int octaves, Function<CNG, CNG> factory)
{
return compile(g, scale, octaves, factory, false);
}
public static BiomeLayer compile(IrisGenerator g, double scale, int octaves, Function<CNG, CNG> factory, boolean inf)
{
GMap<String, BiomeLayer> components = new GMap<>();
for(IrisBiome i : g.getDimension().getBiomes())
{
if(i.getType().equals(BiomeType.LAND))
{
components.put(i.getName(), new BiomeLayer(g, i));
}
}
KSet<String> deject = new KSet<>();
for(String i : components.keySet())
{
BiomeLayer b = components.get(i);
for(String j : b.getBiome().getParents())
{
try
{
components.get(j).addLayer(b);
deject.add(i);
}
catch(Throwable e)
{
L.w(C.YELLOW + "Cannot find Biome " + C.RED + j + C.YELLOW + " (" + C.WHITE + b.getBiome().getName() + C.YELLOW + "'s so-called 'parent'.)");
}
}
}
BiomeLayer master = new BiomeLayer(g, null);
for(String i : components.k())
{
if(deject.contains(i))
{
continue;
}
master.addLayer(components.get(i));
}
master.compileChildren(scale, octaves, factory, inf);
return master;
}
}

View File

@ -1,7 +0,0 @@
package ninja.bytecode.iris.util;
@FunctionalInterface
public interface BorderCheck<T>
{
public T get(double x, double z);
}

View File

@ -1,44 +0,0 @@
package ninja.bytecode.iris.util;
import ninja.bytecode.shuriken.math.M;
public class Borders
{
public static <T> double getDistanceToBorder(double x, double z, int samples, double minRadius, double maxRadius, double jump, BorderCheck<T> check)
{
double offset = 0;
double fract = 1;
for(double i = minRadius; i < maxRadius; i += jump * fract)
{
offset += jump / 3D;
fract += 0.333;
if(isBorderWithin(x, z, samples, maxRadius, offset, check))
{
return minRadius;
}
}
return maxRadius;
}
public static <T> boolean isBorderWithin(double x, double z, int samples, double radius, double offset, BorderCheck<T> check)
{
T center = check.get(x, z);
double ajump = Math.toRadians(360D / (double) samples) + offset;
for(int i = 0; i < samples; i++)
{
double dx = M.sin((float) ajump * i) * radius;
double dz = M.cos((float) ajump * i) * radius;
if(!center.equals(check.get(x + dx, z + dz)))
{
return true;
}
}
return false;
}
}

View File

@ -1,49 +0,0 @@
package ninja.bytecode.iris.util;
public class CDou
{
private double number;
private double max;
public CDou(double max)
{
number = 0;
this.max = max;
}
public CDou set(double n)
{
number = n;
circ();
return this;
}
public CDou add(double a)
{
number += a;
circ();
return this;
}
public CDou sub(double a)
{
number -= a;
circ();
return this;
}
public double get()
{
return number;
}
public void circ()
{
if(number < 0)
{
number = max - (Math.abs(number) > max ? max : Math.abs(number));
}
number = number % (max);
}
}

View File

@ -1,52 +0,0 @@
package ninja.bytecode.iris.util;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
import net.minecraft.server.v1_12_R1.IBlockData;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.shuriken.execution.J;
public class Catalyst12
{
public static void waitForChunk(World w, int x, int z)
{
if(!w.isChunkLoaded(x, z))
{
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> w.loadChunk(x, z, true));
}
int i = 0;
while(!w.isChunkLoaded(x, z) && i < 20)
{
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> w.loadChunk(x, z, true));
J.sleep(50);
i++;
}
}
@SuppressWarnings("deprecation")
public static void setBlock(World wo, int x, int y, int z, MB m)
{
if(y > wo.getMaxHeight())
{
return;
}
net.minecraft.server.v1_12_R1.World w = ((CraftWorld) wo).getHandle();
net.minecraft.server.v1_12_R1.Chunk chunk = w.getChunkAt(x >> 4, z >> 4);
int combined = m.material.getId() + (m.data << 12);
IBlockData ibd = net.minecraft.server.v1_12_R1.Block.getByCombinedId(combined);
if(chunk.getSections()[y >> 4] == null)
{
chunk.getSections()[y >> 4] = new net.minecraft.server.v1_12_R1.ChunkSection(y >> 4 << 4, chunk.world.worldProvider.m());
}
net.minecraft.server.v1_12_R1.ChunkSection sec = chunk.getSections()[y >> 4];
sec.setType(x & 15, y & 15, z & 15, ibd);
}
}

View File

@ -1,74 +0,0 @@
package ninja.bytecode.iris.util;
import java.util.Random;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.generator.BlockPopulator;
import ninja.bytecode.shuriken.math.M;
public abstract class ChancedPopulator extends BlockPopulator
{
private final double chance;
public ChancedPopulator(double chance)
{
this.chance = chance;
}
@Override
public void populate(World world, Random random, Chunk source)
{
if(chance == 0)
{
return;
}
if(chance > 0 && chance < 1 && M.r(chance))
{
doPopulate(world, random, source, (source.getX() << 4) + random.nextInt(16), (source.getZ() << 4) + random.nextInt(16));
}
if(chance > 1)
{
for(int i = 0; i < (int) chance; i++)
{
doPopulate(world, random, source, (source.getX() << 4) + random.nextInt(16), (source.getZ() << 4) + random.nextInt(16));
}
if(M.r(chance - ((int) chance)))
{
doPopulate(world, random, source, (source.getX() << 4) + random.nextInt(16), (source.getZ() << 4) + random.nextInt(16));
}
}
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(chance);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj)
{
if(this == obj)
return true;
if(obj == null)
return false;
if(getClass() != obj.getClass())
return false;
ChancedPopulator other = (ChancedPopulator) obj;
if(Double.doubleToLongBits(chance) != Double.doubleToLongBits(other.chance))
return false;
return true;
}
public abstract void doPopulate(World world, Random random, Chunk source, int x, int z);
}

View File

@ -1,71 +0,0 @@
package ninja.bytecode.iris.util;
import org.bukkit.Bukkit;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.shuriken.bench.PrecisionStopwatch;
import ninja.bytecode.shuriken.execution.J;
import ninja.bytecode.shuriken.execution.Queue;
import ninja.bytecode.shuriken.execution.ShurikenQueue;
import ninja.bytecode.shuriken.logging.L;
public class ChronoQueue
{
private PrecisionStopwatch s;
private Queue<Runnable> q;
private double limit;
private int jobLimit;
private boolean die;
private int j;
public ChronoQueue(double limit, int jobLimit)
{
die = false;
this.limit = limit;
this.jobLimit = jobLimit;
s = new PrecisionStopwatch();
j = Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, this::tick, 0, 0);
q = new ShurikenQueue<>();
}
public void close()
{
J.attempt(() -> Bukkit.getScheduler().cancelTask(j));
}
public void dieSlowly()
{
die = true;
}
public void queue(Runnable r)
{
q.queue(r);
}
private void tick()
{
s.reset();
s.begin();
while(q.hasNext() && (s.getMilliseconds() < limit || q.size() > jobLimit))
{
try
{
q.next().run();
}
catch(Throwable e)
{
L.ex(e);
}
}
s.end();
if(q.size() == 0 && die)
{
close();
}
}
}

View File

@ -1,138 +0,0 @@
package ninja.bytecode.iris.util;
import ninja.bytecode.iris.pack.IrisBiome;
import ninja.bytecode.shuriken.collections.KList;
import ninja.bytecode.shuriken.collections.KMap;
public class ChunkPlan
{
private final KMap<SChunkVector, Integer> realHeightCache;
private final KMap<SChunkVector, KList<Integer>> caveHeightCache;
private final KMap<SChunkVector, Integer> realWaterHeightCache;
private final KMap<SChunkVector, Double> heightCache;
private final KMap<SChunkVector, IrisBiome> biomeCache;
public ChunkPlan()
{
this.caveHeightCache = new KMap<>();
this.realHeightCache = new KMap<>();
this.realWaterHeightCache = new KMap<>();
this.heightCache = new KMap<>();
this.biomeCache = new KMap<>();
}
public IrisBiome getBiome(int x, int z)
{
return biomeCache.get(new SChunkVector(x, z));
}
public void setBiome(int x, int z, IrisBiome cng)
{
biomeCache.put(new SChunkVector(x, z), cng);
}
public double getHeight(int x, int z)
{
SChunkVector c = new SChunkVector(x, z);
if(hasHeight(c))
{
return heightCache.get(c);
}
return -1;
}
public int getRealHeight(int x, int z)
{
SChunkVector c = new SChunkVector(x, z);
if(realHeightCache.containsKey(c))
{
return realHeightCache.get(c);
}
return 0;
}
public KList<Integer> getCaveHeights(int x, int z)
{
SChunkVector c = new SChunkVector(x, z);
if(caveHeightCache.containsKey(c))
{
return caveHeightCache.get(c);
}
return null;
}
public int getRealWaterHeight(int x, int z)
{
SChunkVector c = new SChunkVector(x, z);
if(realWaterHeightCache.containsKey(c))
{
return realWaterHeightCache.get(c);
}
return 0;
}
public boolean hasHeight(SChunkVector c)
{
return heightCache.containsKey(c);
}
public boolean hasHeight(int x, int z)
{
return hasHeight(new SChunkVector(x, z));
}
public void setHeight(SChunkVector c, double h)
{
heightCache.put(c, h);
}
public void setCaveHeight(SChunkVector c, int h)
{
if(!caveHeightCache.containsKey(c))
{
caveHeightCache.put(c, new KList<>());
}
caveHeightCache.get(c).add(h);
}
public void setRealHeight(SChunkVector c, int h)
{
realHeightCache.put(c, h);
}
public void setRealHeight(int x, int z, int h)
{
setRealHeight(new SChunkVector(x, z), h);
}
public void setCaveHeight(int x, int z, int h)
{
setCaveHeight(new SChunkVector(x, z), h);
}
public void setRealWaterHeight(SChunkVector c, int h)
{
realWaterHeightCache.put(c, h);
}
public void setRealWaterHeight(int x, int z, int h)
{
setRealWaterHeight(new SChunkVector(x, z), h);
}
public void setHeight(int x, int z, double h)
{
setHeight(new SChunkVector(x, z), h);
}
public int biomeCacheSize()
{
return biomeCache.size();
}
}

View File

@ -1,14 +0,0 @@
package ninja.bytecode.iris.util;
import java.util.Random;
import org.bukkit.World;
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
import ninja.bytecode.iris.generator.atomics.AtomicChunkData;
@FunctionalInterface
public interface ChunkSpliceListener
{
public AtomicChunkData onSpliceAvailable(World world, Random random, int x, int z, BiomeGrid biome);
}

View File

@ -1,10 +0,0 @@
package ninja.bytecode.iris.util;
import java.awt.Color;
public interface ColoredEffect
{
public ColoredEffect setColor(Color color);
public Color getColor();
}

View File

@ -1,921 +0,0 @@
package ninja.bytecode.iris.util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.material.MaterialData;
import ninja.bytecode.shuriken.collections.KList;
/**
* Cuboids
*
* @author cyberpwn
*/
public class Cuboid implements Iterable<Block>, Cloneable, ConfigurationSerializable
{
protected final String worldName;
protected int x1, y1, z1;
protected int x2, y2, z2;
/**
* Construct a Cuboid given two Location objects which represent any two corners
* of the Cuboid.
*
* @param l1
* one of the corners
* @param l2
* the other corner
*/
public Cuboid(Location l1, Location l2)
{
if(!l1.getWorld().equals(l2.getWorld()))
{
throw new IllegalArgumentException("locations must be on the same world");
}
worldName = l1.getWorld().getName();
x1 = Math.min(l1.getBlockX(), l2.getBlockX());
y1 = Math.min(l1.getBlockY(), l2.getBlockY());
z1 = Math.min(l1.getBlockZ(), l2.getBlockZ());
x2 = Math.max(l1.getBlockX(), l2.getBlockX());
y2 = Math.max(l1.getBlockY(), l2.getBlockY());
z2 = Math.max(l1.getBlockZ(), l2.getBlockZ());
}
public KList<LivingEntity> getLivingEntities()
{
return new KList<LivingEntity>(new GListAdapter<Entity, LivingEntity>()
{
@Override
public LivingEntity onAdapt(Entity from)
{
if(from instanceof LivingEntity)
{
return (LivingEntity) from;
}
return null;
}
}.adapt(getEntities()));
}
public KList<Entity> getEntities()
{
KList<Entity> en = new KList<Entity>();
for(Chunk i : getChunks())
{
for(Entity j : i.getEntities())
{
if(contains(j.getLocation()))
{
en.add(j);
}
}
}
return en;
}
/**
* Set the locations
*
* @param l1
* a
* @param l2
* b
*/
public void set(Location l1, Location l2)
{
x1 = Math.min(l1.getBlockX(), l2.getBlockX());
y1 = Math.min(l1.getBlockY(), l2.getBlockY());
z1 = Math.min(l1.getBlockZ(), l2.getBlockZ());
x2 = Math.max(l1.getBlockX(), l2.getBlockX());
y2 = Math.max(l1.getBlockY(), l2.getBlockY());
z2 = Math.max(l1.getBlockZ(), l2.getBlockZ());
}
/**
* Construct a one-block Cuboid at the given Location of the Cuboid.
*
* @param l1
* location of the Cuboid
*/
public Cuboid(Location l1)
{
this(l1, l1);
}
/**
* Copy constructor.
*
* @param other
* the Cuboid to copy
*/
public Cuboid(Cuboid other)
{
this(other.getWorld().getName(), other.x1, other.y1, other.z1, other.x2, other.y2, other.z2);
}
/**
* Construct a Cuboid in the given World and xyz co-ordinates
*
* @param world
* the Cuboid's world
* @param x1
* X co-ordinate of corner 1
* @param y1
* Y co-ordinate of corner 1
* @param z1
* Z co-ordinate of corner 1
* @param x2
* X co-ordinate of corner 2
* @param y2
* Y co-ordinate of corner 2
* @param z2
* Z co-ordinate of corner 2
*/
public Cuboid(World world, int x1, int y1, int z1, int x2, int y2, int z2)
{
this.worldName = world.getName();
this.x1 = Math.min(x1, x2);
this.x2 = Math.max(x1, x2);
this.y1 = Math.min(y1, y2);
this.y2 = Math.max(y1, y2);
this.z1 = Math.min(z1, z2);
this.z2 = Math.max(z1, z2);
}
/**
* Construct a Cuboid in the given world name and xyz co-ordinates.
*
* @param worldName
* the Cuboid's world name
* @param x1
* X co-ordinate of corner 1
* @param y1
* Y co-ordinate of corner 1
* @param z1
* Z co-ordinate of corner 1
* @param x2
* X co-ordinate of corner 2
* @param y2
* Y co-ordinate of corner 2
* @param z2
* Z co-ordinate of corner 2
*/
private Cuboid(String worldName, int x1, int y1, int z1, int x2, int y2, int z2)
{
this.worldName = worldName;
this.x1 = Math.min(x1, x2);
this.x2 = Math.max(x1, x2);
this.y1 = Math.min(y1, y2);
this.y2 = Math.max(y1, y2);
this.z1 = Math.min(z1, z2);
this.z2 = Math.max(z1, z2);
}
public Cuboid(Map<String, Object> map)
{
worldName = (String) map.get("worldName");
x1 = (Integer) map.get("x1");
x2 = (Integer) map.get("x2");
y1 = (Integer) map.get("y1");
y2 = (Integer) map.get("y2");
z1 = (Integer) map.get("z1");
z2 = (Integer) map.get("z2");
}
@Override
public Map<String, Object> serialize()
{
Map<String, Object> map = new HashMap<String, Object>();
map.put("worldName", worldName);
map.put("x1", x1);
map.put("y1", y1);
map.put("z1", z1);
map.put("x2", x2);
map.put("y2", y2);
map.put("z2", z2);
return map;
}
public Cuboid flatten(int level)
{
return new Cuboid(getWorld(), x1, level, z1, x2, level, z2);
}
/**
* Get the Location of the lower northeast corner of the Cuboid (minimum XYZ
* co-ordinates).
*
* @return Location of the lower northeast corner
*/
public Location getLowerNE()
{
return new Location(getWorld(), x1, y1, z1);
}
/**
* Get the Location of the upper southwest corner of the Cuboid (maximum XYZ
* co-ordinates).
*
* @return Location of the upper southwest corner
*/
public Location getUpperSW()
{
return new Location(getWorld(), x2, y2, z2);
}
/**
* Get the the centre of the Cuboid
*
* @return Location at the centre of the Cuboid
*/
public Location getCenter()
{
int x1 = getUpperX() + 1;
int y1 = getUpperY() + 1;
int z1 = getUpperZ() + 1;
return new Location(getWorld(), getLowerX() + (x1 - getLowerX()) / 2.0, getLowerY() + (y1 - getLowerY()) / 2.0, getLowerZ() + (z1 - getLowerZ()) / 2.0);
}
/**
* Get the Cuboid's world.
*
* @return the World object representing this Cuboid's world
* @throws IllegalStateException
* if the world is not loaded
*/
public World getWorld()
{
World world = Bukkit.getWorld(worldName);
if(world == null)
{
throw new IllegalStateException("world '" + worldName + "' is not loaded");
}
return world;
}
/**
* Get the size of this Cuboid along the X axis
*
* @return Size of Cuboid along the X axis
*/
public int getSizeX()
{
return (x2 - x1) + 1;
}
/**
* Get the size of this Cuboid along the Y axis
*
* @return Size of Cuboid along the Y axis
*/
public int getSizeY()
{
return (y2 - y1) + 1;
}
/**
* Get the size of this Cuboid along the Z axis
*
* @return Size of Cuboid along the Z axis
*/
public int getSizeZ()
{
return (z2 - z1) + 1;
}
/**
* Get the cuboid dimensions
*
* @return the dimensions
*/
public Dimension getDimension()
{
return new Dimension(getSizeX(), getSizeY(), getSizeZ());
}
/**
* Get the minimum X co-ordinate of this Cuboid
*
* @return the minimum X co-ordinate
*/
public int getLowerX()
{
return x1;
}
/**
* Get the minimum Y co-ordinate of this Cuboid
*
* @return the minimum Y co-ordinate
*/
public int getLowerY()
{
return y1;
}
/**
* Get the minimum Z co-ordinate of this Cuboid
*
* @return the minimum Z co-ordinate
*/
public int getLowerZ()
{
return z1;
}
/**
* Get the maximum X co-ordinate of this Cuboid
*
* @return the maximum X co-ordinate
*/
public int getUpperX()
{
return x2;
}
/**
* Get the maximum Y co-ordinate of this Cuboid
*
* @return the maximum Y co-ordinate
*/
public int getUpperY()
{
return y2;
}
/**
* Get the maximum Z co-ordinate of this Cuboid
*
* @return the maximum Z co-ordinate
*/
public int getUpperZ()
{
return z2;
}
/**
* Get the Blocks at the eight corners of the Cuboid.
*
* @return array of Block objects representing the Cuboid corners
*/
public Block[] corners()
{
Block[] res = new Block[8];
World w = getWorld();
res[0] = w.getBlockAt(x1, y1, z1);
res[1] = w.getBlockAt(x1, y1, z2);
res[2] = w.getBlockAt(x1, y2, z1);
res[3] = w.getBlockAt(x1, y2, z2);
res[4] = w.getBlockAt(x2, y1, z1);
res[5] = w.getBlockAt(x2, y1, z2);
res[6] = w.getBlockAt(x2, y2, z1);
res[7] = w.getBlockAt(x2, y2, z2);
return res;
}
/**
* Expand the Cuboid in the given direction by the given amount. Negative
* amounts will shrink the Cuboid in the given direction. Shrinking a cuboid's
* face past the opposite face is not an error and will return a valid Cuboid.
*
* @param dir
* the direction in which to expand
* @param amount
* the number of blocks by which to expand
* @return a new Cuboid expanded by the given direction and amount
*/
public Cuboid expand(CuboidDirection dir, int amount)
{
switch(dir)
{
case North:
return new Cuboid(worldName, x1 - amount, y1, z1, x2, y2, z2);
case South:
return new Cuboid(worldName, x1, y1, z1, x2 + amount, y2, z2);
case East:
return new Cuboid(worldName, x1, y1, z1 - amount, x2, y2, z2);
case West:
return new Cuboid(worldName, x1, y1, z1, x2, y2, z2 + amount);
case Down:
return new Cuboid(worldName, x1, y1 - amount, z1, x2, y2, z2);
case Up:
return new Cuboid(worldName, x1, y1, z1, x2, y2 + amount, z2);
default:
throw new IllegalArgumentException("invalid direction " + dir);
}
}
public Cuboid expand(Direction dir, int amount)
{
int ax = dir.toVector().getBlockX() == 1 ? amount : 0;
int sx = dir.toVector().getBlockX() == -1 ? -amount : 0;
int ay = dir.toVector().getBlockY() == 1 ? amount : 0;
int sy = dir.toVector().getBlockY() == -1 ? -amount : 0;
int az = dir.toVector().getBlockZ() == 1 ? amount : 0;
int sz = dir.toVector().getBlockZ() == -1 ? -amount : 0;
return new Cuboid(worldName, x1 + sx, y1 + sy, z1 + sz, x2 + ax, y2 + ay, z2 + az);
}
/**
* Shift the Cuboid in the given direction by the given amount.
*
* @param dir
* the direction in which to shift
* @param amount
* the number of blocks by which to shift
* @return a new Cuboid shifted by the given direction and amount
*/
public Cuboid shift(CuboidDirection dir, int amount)
{
return expand(dir, amount).expand(dir.opposite(), -amount);
}
/**
* Outset (grow) the Cuboid in the given direction by the given amount.
*
* @param dir
* the direction in which to outset (must be Horizontal, Vertical, or
* Both)
* @param amount
* the number of blocks by which to outset
* @return a new Cuboid outset by the given direction and amount
*/
public Cuboid outset(CuboidDirection dir, int amount)
{
Cuboid c;
switch(dir)
{
case Horizontal:
c = expand(CuboidDirection.North, amount).expand(CuboidDirection.South, amount).expand(CuboidDirection.East, amount).expand(CuboidDirection.West, amount);
break;
case Vertical:
c = expand(CuboidDirection.Down, amount).expand(CuboidDirection.Up, amount);
break;
case Both:
c = outset(CuboidDirection.Horizontal, amount).outset(CuboidDirection.Vertical, amount);
break;
default:
throw new IllegalArgumentException("invalid direction " + dir);
}
return c;
}
/**
* Inset (shrink) the Cuboid in the given direction by the given amount.
* Equivalent to calling outset() with a negative amount.
*
* @param dir
* the direction in which to inset (must be Horizontal, Vertical, or
* Both)
* @param amount
* the number of blocks by which to inset
* @return a new Cuboid inset by the given direction and amount
*/
public Cuboid inset(CuboidDirection dir, int amount)
{
return outset(dir, -amount);
}
/**
* Return true if the point at (x,y,z) is contained within this Cuboid.
*
* @param x
* the X co-ordinate
* @param y
* the Y co-ordinate
* @param z
* the Z co-ordinate
* @return true if the given point is within this Cuboid, false otherwise
*/
public boolean contains(int x, int y, int z)
{
return x >= x1 && x <= x2 && y >= y1 && y <= y2 && z >= z1 && z <= z2;
}
/**
* Check if the given Block is contained within this Cuboid.
*
* @param b
* the Block to check for
* @return true if the Block is within this Cuboid, false otherwise
*/
public boolean contains(Block b)
{
return contains(b.getLocation());
}
/**
* Check if the given Location is contained within this Cuboid.
*
* @param l
* the Location to check for
* @return true if the Location is within this Cuboid, false otherwise
*/
public boolean contains(Location l)
{
return worldName.equals(l.getWorld().getName()) && contains(l.getBlockX(), l.getBlockY(), l.getBlockZ());
}
/**
* Get the volume of this Cuboid.
*
* @return the Cuboid volume, in blocks
*/
public int volume()
{
return getSizeX() * getSizeY() * getSizeZ();
}
/**
* Get the average light level of all empty (air) blocks in the Cuboid. Returns
* 0 if there are no empty blocks.
*
* @return the average light level of this Cuboid
*/
public byte averageLightLevel()
{
long total = 0;
int n = 0;
for(Block b : this)
{
if(b.isEmpty())
{
total += b.getLightLevel();
++n;
}
}
return n > 0 ? (byte) (total / n) : 0;
}
/**
* Contract the Cuboid, returning a Cuboid with any air around the edges
* removed, just large enough to include all non-air blocks.
*
* @return a new Cuboid with no external air blocks
*/
public Cuboid contract()
{
return this.contract(CuboidDirection.Down).contract(CuboidDirection.South).contract(CuboidDirection.East).contract(CuboidDirection.Up).contract(CuboidDirection.North).contract(CuboidDirection.West);
}
/**
* Contract the Cuboid in the given direction, returning a new Cuboid which has
* no exterior empty space. E.g. a direction of Down will push the top face
* downwards as much as possible.
*
* @param dir
* the direction in which to contract
* @return a new Cuboid contracted in the given direction
*/
public Cuboid contract(CuboidDirection dir)
{
Cuboid face = getFace(dir.opposite());
switch(dir)
{
case Down:
while(face.containsOnly(Material.AIR) && face.getLowerY() > this.getLowerY())
{
face = face.shift(CuboidDirection.Down, 1);
}
return new Cuboid(worldName, x1, y1, z1, x2, face.getUpperY(), z2);
case Up:
while(face.containsOnly(Material.AIR) && face.getUpperY() < this.getUpperY())
{
face = face.shift(CuboidDirection.Up, 1);
}
return new Cuboid(worldName, x1, face.getLowerY(), z1, x2, y2, z2);
case North:
while(face.containsOnly(Material.AIR) && face.getLowerX() > this.getLowerX())
{
face = face.shift(CuboidDirection.North, 1);
}
return new Cuboid(worldName, x1, y1, z1, face.getUpperX(), y2, z2);
case South:
while(face.containsOnly(Material.AIR) && face.getUpperX() < this.getUpperX())
{
face = face.shift(CuboidDirection.South, 1);
}
return new Cuboid(worldName, face.getLowerX(), y1, z1, x2, y2, z2);
case East:
while(face.containsOnly(Material.AIR) && face.getLowerZ() > this.getLowerZ())
{
face = face.shift(CuboidDirection.East, 1);
}
return new Cuboid(worldName, x1, y1, z1, x2, y2, face.getUpperZ());
case West:
while(face.containsOnly(Material.AIR) && face.getUpperZ() < this.getUpperZ())
{
face = face.shift(CuboidDirection.West, 1);
}
return new Cuboid(worldName, x1, y1, face.getLowerZ(), x2, y2, z2);
default:
throw new IllegalArgumentException("Invalid direction " + dir);
}
}
/**
* Get the Cuboid representing the face of this Cuboid. The resulting Cuboid
* will be one block thick in the axis perpendicular to the requested face.
*
* @param dir
* which face of the Cuboid to get
* @return the Cuboid representing this Cuboid's requested face
*/
public Cuboid getFace(CuboidDirection dir)
{
switch(dir)
{
case Down:
return new Cuboid(worldName, x1, y1, z1, x2, y1, z2);
case Up:
return new Cuboid(worldName, x1, y2, z1, x2, y2, z2);
case North:
return new Cuboid(worldName, x1, y1, z1, x1, y2, z2);
case South:
return new Cuboid(worldName, x2, y1, z1, x2, y2, z2);
case East:
return new Cuboid(worldName, x1, y1, z1, x2, y2, z1);
case West:
return new Cuboid(worldName, x1, y1, z2, x2, y2, z2);
default:
throw new IllegalArgumentException("Invalid direction " + dir);
}
}
/**
* Check if the Cuboid contains only blocks of the given type
*
* @param material
* the material to check for
* @return true if this Cuboid contains only blocks of the given type
*/
public boolean containsOnly(Material material)
{
for(Block b : this)
{
if(b.getType() != material)
{
return false;
}
}
return true;
}
/**
* Get the Cuboid big enough to hold both this Cuboid and the given one.
*
* @param other
* the other Cuboid to include
* @return a new Cuboid large enough to hold this Cuboid and the given Cuboid
*/
public Cuboid getBoundingCuboid(Cuboid other)
{
if(other == null)
{
return this;
}
int xMin = Math.min(getLowerX(), other.getLowerX());
int yMin = Math.min(getLowerY(), other.getLowerY());
int zMin = Math.min(getLowerZ(), other.getLowerZ());
int xMax = Math.max(getUpperX(), other.getUpperX());
int yMax = Math.max(getUpperY(), other.getUpperY());
int zMax = Math.max(getUpperZ(), other.getUpperZ());
return new Cuboid(worldName, xMin, yMin, zMin, xMax, yMax, zMax);
}
/**
* Get a block relative to the lower NE point of the Cuboid.
*
* @param x
* the X co-ordinate
* @param y
* the Y co-ordinate
* @param z
* the Z co-ordinate
* @return the block at the given position
*/
public Block getRelativeBlock(int x, int y, int z)
{
return getWorld().getBlockAt(x1 + x, y1 + y, z1 + z);
}
/**
* Get a block relative to the lower NE point of the Cuboid in the given World.
* This version of getRelativeBlock() should be used if being called many times,
* to avoid excessive calls to getWorld().
*
* @param w
* the World
* @param x
* the X co-ordinate
* @param y
* the Y co-ordinate
* @param z
* the Z co-ordinate
* @return the block at the given position
*/
public Block getRelativeBlock(World w, int x, int y, int z)
{
return w.getBlockAt(x1 + x, y1 + y, z1 + z);
}
/**
* Get a list of the chunks which are fully or partially contained in this
* cuboid.
*
* @return a list of Chunk objects
*/
public List<Chunk> getChunks()
{
List<Chunk> res = new ArrayList<Chunk>();
World w = getWorld();
int x1 = getLowerX() & ~0xf;
int x2 = getUpperX() & ~0xf;
int z1 = getLowerZ() & ~0xf;
int z2 = getUpperZ() & ~0xf;
for(int x = x1; x <= x2; x += 16)
{
for(int z = z1; z <= z2; z += 16)
{
res.add(w.getChunkAt(x >> 4, z >> 4));
}
}
return res;
}
/**
* Set all the blocks within the Cuboid to the given block ID and data byte.
*
* @param blockId
* the block ID
* @param data
* the block data
* @deprecated use {@link #fill(MaterialData, MassBlockUpdate)}
*/
@Deprecated
public void fill(int blockId, byte data)
{
for(Block b : this)
{
b.setTypeIdAndData(blockId, data, false);
}
}
/**
* Set all the blocks within the Cuboid to the given MaterialData, using a
* MassBlockUpdate object for fast updates.
*
* @param mat
* the MaterialData to set
* @param mbu
* the MassBlockUpdate object
*/
/**
* Reset the light level of all blocks within this Cuboid.
*/
/*
* (non-Javadoc)
*
* @see java.lang.Iterable#iterator()
*/
@Override
public Iterator<Block> iterator()
{
return new CuboidIterator(getWorld(), x1, y1, z1, x2, y2, z2);
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#clone()
*/
@Override
public Cuboid clone() throws CloneNotSupportedException
{
return new Cuboid(this);
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return "Cuboid: " + worldName + "," + x1 + "," + y1 + "," + z1 + "=>" + x2 + "," + y2 + "," + z2;
}
public class CuboidIterator implements Iterator<Block>
{
private World w;
private int baseX, baseY, baseZ;
private int x, y, z;
private int sizeX, sizeY, sizeZ;
public CuboidIterator(World w, int x1, int y1, int z1, int x2, int y2, int z2)
{
this.w = w;
baseX = x1;
baseY = y1;
baseZ = z1;
sizeX = Math.abs(x2 - x1) + 1;
sizeY = Math.abs(y2 - y1) + 1;
sizeZ = Math.abs(z2 - z1) + 1;
x = y = z = 0;
}
@Override
public boolean hasNext()
{
return x < sizeX && y < sizeY && z < sizeZ;
}
@Override
public Block next()
{
Block b = w.getBlockAt(baseX + x, baseY + y, baseZ + z);
if(++x >= sizeX)
{
x = 0;
if(++y >= sizeY)
{
y = 0;
++z;
}
}
return b;
}
@Override
public void remove()
{
// nop
}
}
public enum CuboidDirection
{
North,
East,
South,
West,
Up,
Down,
Horizontal,
Vertical,
Both,
Unknown;
public CuboidDirection opposite()
{
switch(this)
{
case North:
return South;
case East:
return West;
case South:
return North;
case West:
return East;
case Horizontal:
return Vertical;
case Vertical:
return Horizontal;
case Up:
return Down;
case Down:
return Up;
case Both:
return Both;
default:
return Unknown;
}
}
}
}

View File

@ -1,16 +0,0 @@
package ninja.bytecode.iris.util;
/**
* Represents a cuboid exception
*
* @author cyberpwn
*/
public class CuboidException extends Exception
{
public CuboidException(String string)
{
super(string);
}
private static final long serialVersionUID = 1L;
}

View File

@ -1,20 +0,0 @@
package ninja.bytecode.iris.util;
import org.bukkit.util.Vector;
public abstract class DOP
{
private String type;
public DOP(String type)
{
this.type = type;
}
public abstract Vector op(Vector v);
public String getType()
{
return type;
}
}

View File

@ -1,86 +0,0 @@
package ninja.bytecode.iris.util;
/**
* Dimensions
*
* @author cyberpwn
*/
public class Dimension
{
private final int width;
private final int height;
private final int depth;
/**
* Make a dimension
*
* @param width
* width of this (X)
* @param height
* the height (Y)
* @param depth
* the depth (Z)
*/
public Dimension(int width, int height, int depth)
{
this.width = width;
this.height = height;
this.depth = depth;
}
/**
* Make a dimension
*
* @param width
* width of this (X)
* @param height
* the height (Y)
*/
public Dimension(int width, int height)
{
this.width = width;
this.height = height;
this.depth = 0;
}
/**
* Get the direction of the flat part of this dimension (null if no thin
* face)
*
* @return the direction of the flat pane or null
*/
public DimensionFace getPane()
{
if(width == 1)
{
return DimensionFace.X;
}
if(height == 1)
{
return DimensionFace.Y;
}
if(depth == 1)
{
return DimensionFace.Z;
}
return null;
}
public int getWidth()
{
return width;
}
public int getHeight()
{
return height;
}
public int getDepth()
{
return depth;
}
}

View File

@ -1,24 +0,0 @@
package ninja.bytecode.iris.util;
/**
* Represents a dimension (coordinates not worlds)
*
* @author cyberpwn
*/
public enum DimensionFace
{
/**
* The X dimension (width)
*/
X,
/**
* The Y dimension (height)
*/
Y,
/**
* The Z dimension (depth)
*/
Z
}

View File

@ -1,534 +0,0 @@
package ninja.bytecode.iris.util;
import org.bukkit.block.BlockFace;
import org.bukkit.util.Vector;
import ninja.bytecode.iris.util.Cuboid.CuboidDirection;
import ninja.bytecode.shuriken.collections.KList;
import ninja.bytecode.shuriken.collections.KMap;
/**
* Directions
*
* @author cyberpwn
*/
public enum Direction
{
U(0, 1, 0, CuboidDirection.Up),
D(0, -1, 0, CuboidDirection.Down),
N(0, 0, -1, CuboidDirection.North),
S(0, 0, 1, CuboidDirection.South),
E(1, 0, 0, CuboidDirection.East),
W(-1, 0, 0, CuboidDirection.West);
private static KMap<GBiset<Direction, Direction>, DOP> permute = null;
private int x;
private int y;
private int z;
private CuboidDirection f;
public static Direction getDirection(BlockFace f)
{
switch(f)
{
case DOWN:
return D;
case EAST:
return E;
case EAST_NORTH_EAST:
return E;
case EAST_SOUTH_EAST:
return E;
case NORTH:
return N;
case NORTH_EAST:
return N;
case NORTH_NORTH_EAST:
return N;
case NORTH_NORTH_WEST:
return N;
case NORTH_WEST:
return N;
case SELF:
return U;
case SOUTH:
return S;
case SOUTH_EAST:
return S;
case SOUTH_SOUTH_EAST:
return S;
case SOUTH_SOUTH_WEST:
return S;
case SOUTH_WEST:
return S;
case UP:
return U;
case WEST:
return W;
case WEST_NORTH_WEST:
return W;
case WEST_SOUTH_WEST:
return W;
}
return D;
}
@Override
public String toString()
{
switch(this)
{
case D:
return "Down";
case E:
return "East";
case N:
return "North";
case S:
return "South";
case U:
return "Up";
case W:
return "West";
}
return "?";
}
public boolean isVertical()
{
return equals(D) || equals(U);
}
public static Direction closest(Vector v)
{
double m = Double.MAX_VALUE;
Direction s = null;
for(Direction i : values())
{
Vector x = i.toVector();
double g = x.dot(v);
if(g < m)
{
m = g;
s = i;
}
}
return s;
}
public static Direction closest(Vector v, Direction... d)
{
double m = Double.MAX_VALUE;
Direction s = null;
for(Direction i : d)
{
Vector x = i.toVector();
double g = x.distance(v);
if(g < m)
{
m = g;
s = i;
}
}
return s;
}
public static Direction closest(Vector v, KList<Direction> d)
{
double m = Double.MAX_VALUE;
Direction s = null;
for(Direction i : d)
{
Vector x = i.toVector();
double g = x.distance(v);
if(g < m)
{
m = g;
s = i;
}
}
return s;
}
public Vector toVector()
{
return new Vector(x, y, z);
}
public boolean isCrooked(Direction to)
{
if(equals(to.reverse()))
{
return false;
}
if(equals(to))
{
return false;
}
return true;
}
private Direction(int x, int y, int z, CuboidDirection f)
{
this.x = x;
this.y = y;
this.z = z;
this.f = f;
}
public Vector angle(Vector initial, Direction d)
{
calculatePermutations();
for(GBiset<Direction, Direction> i : permute.keySet())
{
if(i.getA().equals(this) && i.getB().equals(d))
{
return permute.get(i).op(initial);
}
}
return initial;
}
public Direction reverse()
{
switch(this)
{
case D:
return U;
case E:
return W;
case N:
return S;
case S:
return N;
case U:
return D;
case W:
return E;
default:
break;
}
return null;
}
public int x()
{
return x;
}
public int y()
{
return y;
}
public int z()
{
return z;
}
public CuboidDirection f()
{
return f;
}
public static KList<Direction> news()
{
return new KList<Direction>().add(N, E, W, S);
}
public static Direction getDirection(Vector v)
{
Vector k = VectorMath.triNormalize(v.clone().normalize());
for(Direction i : udnews())
{
if(i.x == k.getBlockX() && i.y == k.getBlockY() && i.z == k.getBlockZ())
{
return i;
}
}
return Direction.N;
}
public static KList<Direction> udnews()
{
return new KList<Direction>().add(U, D, N, E, W, S);
}
/**
* Get the directional value from the given byte from common directional blocks
* (MUST BE BETWEEN 0 and 5 INCLUSIVE)
*
* @param b
* the byte
* @return the direction or null if the byte is outside of the inclusive range
* 0-5
*/
public static Direction fromByte(byte b)
{
if(b > 5 || b < 0)
{
return null;
}
if(b == 0)
{
return D;
}
else if(b == 1)
{
return U;
}
else if(b == 2)
{
return N;
}
else if(b == 3)
{
return S;
}
else if(b == 4)
{
return W;
}
else
{
return E;
}
}
/**
* Get the byte value represented in some directional blocks
*
* @return the byte value
*/
public byte byteValue()
{
switch(this)
{
case D:
return 0;
case E:
return 5;
case N:
return 2;
case S:
return 3;
case U:
return 1;
case W:
return 4;
default:
break;
}
return -1;
}
public static void calculatePermutations()
{
if(permute != null)
{
return;
}
permute = new KMap<GBiset<Direction, Direction>, DOP>();
for(Direction i : udnews())
{
for(Direction j : udnews())
{
GBiset<Direction, Direction> b = new GBiset<Direction, Direction>(i, j);
if(i.equals(j))
{
permute.put(b, new DOP("DIRECT")
{
@Override
public Vector op(Vector v)
{
return v;
}
});
}
else if(i.reverse().equals(j))
{
if(i.isVertical())
{
permute.put(b, new DOP("R180CCZ")
{
@Override
public Vector op(Vector v)
{
return VectorMath.rotate90CCZ(VectorMath.rotate90CCZ(v));
}
});
}
else
{
permute.put(b, new DOP("R180CCY")
{
@Override
public Vector op(Vector v)
{
return VectorMath.rotate90CCY(VectorMath.rotate90CCY(v));
}
});
}
}
else if(getDirection(VectorMath.rotate90CX(i.toVector())).equals(j))
{
permute.put(b, new DOP("R90CX")
{
@Override
public Vector op(Vector v)
{
return VectorMath.rotate90CX(v);
}
});
}
else if(getDirection(VectorMath.rotate90CCX(i.toVector())).equals(j))
{
permute.put(b, new DOP("R90CCX")
{
@Override
public Vector op(Vector v)
{
return VectorMath.rotate90CCX(v);
}
});
}
else if(getDirection(VectorMath.rotate90CY(i.toVector())).equals(j))
{
permute.put(b, new DOP("R90CY")
{
@Override
public Vector op(Vector v)
{
return VectorMath.rotate90CY(v);
}
});
}
else if(getDirection(VectorMath.rotate90CCY(i.toVector())).equals(j))
{
permute.put(b, new DOP("R90CCY")
{
@Override
public Vector op(Vector v)
{
return VectorMath.rotate90CCY(v);
}
});
}
else if(getDirection(VectorMath.rotate90CZ(i.toVector())).equals(j))
{
permute.put(b, new DOP("R90CZ")
{
@Override
public Vector op(Vector v)
{
return VectorMath.rotate90CZ(v);
}
});
}
else if(getDirection(VectorMath.rotate90CCZ(i.toVector())).equals(j))
{
permute.put(b, new DOP("R90CCZ")
{
@Override
public Vector op(Vector v)
{
return VectorMath.rotate90CCZ(v);
}
});
}
else
{
permute.put(b, new DOP("FAIL")
{
@Override
public Vector op(Vector v)
{
return v;
}
});
}
}
}
}
public BlockFace getFace()
{
switch(this)
{
case D:
return BlockFace.DOWN;
case E:
return BlockFace.EAST;
case N:
return BlockFace.NORTH;
case S:
return BlockFace.SOUTH;
case U:
return BlockFace.UP;
case W:
return BlockFace.WEST;
}
return null;
}
public Axis getAxis()
{
switch(this)
{
case D:
return Axis.Y;
case E:
return Axis.X;
case N:
return Axis.Z;
case S:
return Axis.Z;
case U:
return Axis.Y;
case W:
return Axis.X;
}
return null;
}
}

View File

@ -1,77 +0,0 @@
package ninja.bytecode.iris.util;
import java.io.Serializable;
/**
* A Biset
*
* @author cyberpwn
*
* @param <A>
* the first object type
* @param <B>
* the second object type
*/
@SuppressWarnings("hiding")
public class GBiset<A, B> implements Serializable
{
private static final long serialVersionUID = 1L;
private A a;
private B b;
/**
* Create a new Biset
*
* @param a
* the first object
* @param b
* the second object
*/
public GBiset(A a, B b)
{
this.a = a;
this.b = b;
}
/**
* Get the object of the type A
*
* @return the first object
*/
public A getA()
{
return a;
}
/**
* Set the first object
*
* @param a
* the first object A
*/
public void setA(A a)
{
this.a = a;
}
/**
* Get the second object
*
* @return the second object
*/
public B getB()
{
return b;
}
/**
* Set the second object
*
* @param b
*/
public void setB(B b)
{
this.b = b;
}
}

View File

@ -1,51 +0,0 @@
package ninja.bytecode.iris.util;
import java.util.List;
import ninja.bytecode.shuriken.collections.KList;
/**
* Adapts a list of objects into a list of other objects
*
* @author cyberpwn
* @param <FROM>
* the from object in lists (the item INSIDE the list)
* @param <TO>
* the to object in lists (the item INSIDE the list)
*/
public abstract class GListAdapter<FROM, TO>
{
/**
* Adapts a list of FROM to a list of TO
*
* @param from
* the from list
* @return the to list
*/
public List<TO> adapt(List<FROM> from)
{
List<TO> adapted = new KList<TO>();
for(FROM i : from)
{
TO t = onAdapt(i);
if(t != null)
{
adapted.add(onAdapt(i));
}
}
return adapted;
}
/**
* Adapts a list object FROM to TO for use with the adapt method
*
* @param from
* the from object
* @return the to object
*/
public abstract TO onAdapt(FROM from);
}

View File

@ -1,10 +0,0 @@
package ninja.bytecode.iris.util;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@FunctionalInterface
public interface GRT
{
public Glower getGlower(Entity entity, Player observer);
}

View File

@ -1,32 +0,0 @@
package ninja.bytecode.iris.util;
import java.util.Random;
import org.bukkit.World;
import org.bukkit.block.Biome;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.shuriken.math.RNG;
public class GenLayer implements IGenLayer
{
protected RNG rng;
protected World world;
protected Random random;
protected IrisGenerator iris;
protected Biome biome = Biome.OCEAN;
public GenLayer(IrisGenerator iris, World world, Random random, RNG rng)
{
this.world = world;
this.random = random;
this.rng = rng;
this.iris = iris;
}
@Override
public double generateLayer(double noise, double dx, double dz)
{
return 0;
}
}

View File

@ -1,106 +0,0 @@
package ninja.bytecode.iris.util;
import org.bukkit.ChatColor;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import mortar.api.nms.NMP;
import mortar.util.text.C;
public class GlossGlower implements Glower
{
private final Player observer;
private final Entity entity;
private ChatColor color;
private boolean sentTeam;
public GlossGlower(Entity entity, Player observer)
{
sentTeam = false;
this.entity = entity;
this.observer = observer;
this.color = ChatColor.WHITE;
}
@Override
public Entity getEntity()
{
return entity;
}
@Override
public ChatColor getColor()
{
return color;
}
@Override
public void setColor(ChatColor color)
{
if(color.isFormat())
{
throw new UnsupportedOperationException("You cannot use format codes for glow colors");
}
this.color = color;
if(observer == null)
{
for(Player i : entity.getWorld().getPlayers())
{
NMP.host.sendGlowingColorMeta(i, getEntity(), C.values()[color.ordinal()]);
}
}
else
{
NMP.host.sendGlowingColorMeta(getObserver(), getEntity(), C.values()[color.ordinal()]);
}
}
@Override
public void setGlowing(boolean glowing)
{
if(observer == null)
{
for(Player i : entity.getWorld().getPlayers())
{
NMP.host.sendEntityMetadata(i, getEntity().getEntityId(), NMP.host.getMetaEntityProperties(false, false, false, false, false, glowing, false));
}
}
else
{
NMP.host.sendEntityMetadata(observer, getEntity().getEntityId(), NMP.host.getMetaEntityProperties(false, false, false, false, false, glowing, false));
}
}
@Override
public void destroy()
{
setGlowing(false);
if(sentTeam)
{
if(observer == null)
{
for(Player i : entity.getWorld().getPlayers())
{
NMP.host.sendRemoveGlowingColorMeta(i, getEntity());
}
}
else
{
NMP.host.sendRemoveGlowingColorMeta(getObserver(), getEntity());
}
}
}
@Override
public Player getObserver()
{
return observer;
}
}

View File

@ -1,14 +0,0 @@
package ninja.bytecode.iris.util;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
public class GlowManager
{
public static GRT f = null;
public static Glower create(Entity e, Player observer)
{
return f.getGlower(e, observer);
}
}

View File

@ -1,20 +0,0 @@
package ninja.bytecode.iris.util;
import org.bukkit.ChatColor;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
public interface Glower
{
public Player getObserver();
public Entity getEntity();
public ChatColor getColor();
public void setColor(ChatColor color);
public void setGlowing(boolean glowing);
public void destroy();
}

View File

@ -1,178 +0,0 @@
package ninja.bytecode.iris.util;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import mortar.api.nms.NMP;
import mortar.api.world.MaterialBlock;
import mortar.compute.math.M;
public class GlowingBlock
{
private static int idd = 123456789;
private int id;
private UUID uid;
private Location location;
private Location current;
private Player player;
private double factor;
private Vector velocity;
private boolean active;
private long mv = M.ms();
private MaterialBlock mb;
private ChatColor c;
public GlowingBlock(Player player, Location init, MaterialBlock mb, ChatColor c)
{
this.mb = mb;
this.uid = UUID.randomUUID();
this.id = idd--;
location = init;
current = init.clone();
this.player = player;
factor = Math.PI;
active = false;
velocity = new Vector();
this.c = c;
}
public int getId()
{
return id;
}
public void sendMetadata(boolean glowing)
{
PacketGate.mark(PacketCategory.EFFECT);
NMP.host.sendEntityMetadata(player, id, NMP.host.getMetaEntityProperties(false, false, false, false, false, glowing, false));
}
public void sendMetadata(ChatColor c)
{
PacketGate.mark(PacketCategory.EFFECT);
//NMP.host.sendGlowingColorMetaEntity(getPlayer(), uid, C.values()[c.ordinal()]);
}
public void update()
{
if(M.ms() - mv < 50)
{
return;
}
if(location.getX() == current.getX() && location.getY() == current.getY() && location.getZ() == current.getZ())
{
return;
}
mv = M.ms();
if(location.distanceSquared(current) > 16)
{
if(PacketGate.can(PacketCategory.EFFECT))
{
sendTeleport(location);
current = location;
}
}
else
{
if(PacketGate.can(PacketCategory.EFFECT))
{
double dx = location.getX() - current.getX();
double dy = location.getY() - current.getY();
double dz = location.getZ() - current.getZ();
dx += velocity.getX();
dy += velocity.getY();
dz += velocity.getZ();
dx = M.clip(dx, -8, 8);
dy = M.clip(dy, -8, 8);
dz = M.clip(dz, -8, 8);
sendMove(dx / factor, dy / factor, dz / factor);
current.add(dx / factor, dy / factor, dz / factor);
current.setX(Math.abs(location.getX() - current.getX()) < 0.00001 ? location.getX() : current.getX());
current.setY(Math.abs(location.getY() - current.getY()) < 0.00001 ? location.getY() : current.getY());
current.setZ(Math.abs(location.getZ() - current.getZ()) < 0.00001 ? location.getZ() : current.getZ());
if(location.getX() == current.getX() && location.getY() == current.getY() && location.getZ() == current.getZ())
{
if(PacketGate.can(PacketCategory.EFFECT))
{
sendTeleport(location);
current = location;
}
}
}
}
}
public Location getPosition()
{
return location.clone();
}
public void setPosition(Location l)
{
location = l;
}
public Player getPlayer()
{
return player;
}
public void destroy()
{
sendDestroy();
}
public void create()
{
sendSpawn();
}
public boolean isActive()
{
return active;
}
public void setFactor(int i)
{
factor = i;
}
private void sendTeleport(Location l)
{
NMP.host.teleportEntity(id, player, l, false);
}
private void sendMove(double x, double y, double z)
{
NMP.host.moveEntityRelative(id, player, x, y, z, false);
}
public void sendDestroy()
{
active = false;
NMP.host.removeEntity(id, player);
NMP.host.sendRemoveGlowingColorMetaEntity(getPlayer(), uid);
sendMetadata(false);
PacketGate.mark(PacketCategory.EFFECT);
PacketGate.mark(PacketCategory.EFFECT);
}
public void sendSpawn()
{
NMP.host.spawnFallingBlock(id, uid, location, player, mb);
sendMetadata(c);
sendMetadata(true);
active = true;
PacketGate.mark(PacketCategory.EFFECT);
PacketGate.mark(PacketCategory.EFFECT);
}
}

View File

@ -1,74 +0,0 @@
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);
}
}

View File

@ -1,6 +0,0 @@
package ninja.bytecode.iris.util;
public interface IGenLayer
{
public double generateLayer(double noise, double dx, double dz);
}

View File

@ -0,0 +1,38 @@
package ninja.bytecode.iris.util;
public class ING
{
private SNG base;
private SNG[] children;
public ING(RNG rng, int detail)
{
assert (detail >= 1);
this.children = new SNG[detail];
for(int i = 0; i < detail; i++)
{
children[i] = new SNG(rng.nextParallelRNG((i * 368989) % 13345));
}
base = new SNG(rng.nextParallelRNG(13));
}
public double noise(double x, double z)
{
double cx = x;
double cz = z;
int i;
double j;
double k;
for(i = 0; i < children.length; i++)
{
j = (i + 1) * 2;
k = (i + 1) * 1;
cx = cx + (children[i].noise((cx / j) + i, (cz / j) - i) * k);
cz = cz - (children[i].noise((cz / j) - i, (cx / j) + i) * k);
}
return (base.noise(cx, cz) / 2D) + 0.5D;
}
}

View File

@ -1,19 +0,0 @@
package ninja.bytecode.iris.util;
import org.bukkit.Location;
import org.bukkit.World;
public interface IPlacer
{
public World getWorld();
public MB get(Location l);
public void set(Location l, MB mb);
public int getHighestY(Location l);
public int getHighestYUnderwater(Location l);
public void flush();
}

View File

@ -1,9 +0,0 @@
package ninja.bytecode.iris.util;
public enum InterpolationMode
{
NONE,
BILINEAR,
BICUBIC,
HERMITE_BICUBIC
}

View File

@ -1,10 +0,0 @@
package ninja.bytecode.iris.util;
public enum InterpolationType
{
LINEAR,
PARAMETRIC_2,
PARAMETRIC_4,
BEZIER,
NONE;
}

View File

@ -1,10 +0,0 @@
package ninja.bytecode.iris.util;
import org.bukkit.event.Listener;
public interface IrisController extends Listener
{
public void onStart();
public void onStop();
}

View File

@ -1,73 +0,0 @@
package ninja.bytecode.iris.util;
import java.io.File;
import java.io.IOException;
import org.bukkit.Bukkit;
import org.bukkit.event.HandlerList;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.shuriken.collections.KMap;
import ninja.bytecode.shuriken.logging.L;
import ninja.bytecode.shuriken.tools.JarScanner;
public class IrisControllerSet
{
private KMap<Class<?>, IrisController> controllers;
public IrisControllerSet()
{
controllers = new KMap<>();
}
public void startControllers(File jar) throws IOException
{
JarScanner ja = new JarScanner(jar, "ninja.bytecode.iris.controller");
ja.scan();
for(Class<?> i : ja.getClasses())
{
try
{
IrisController c = (IrisController) i.getConstructor().newInstance();
Bukkit.getPluginManager().registerEvents(c, Iris.instance);
c.onStart();
controllers.put(i, c);
}
catch(Throwable e)
{
L.ex(e);
}
}
}
public void stopControllers()
{
for(Class<?> i : controllers.k())
{
try
{
IrisController c = controllers.get(i);
HandlerList.unregisterAll();
c.onStop();
}
catch(Throwable e)
{
L.ex(e);
}
}
controllers.clear();
}
public IrisController get(Class<? extends IrisController> c)
{
return controllers.get(c);
}
public int size()
{
return controllers.size();
}
}

View File

@ -1,221 +0,0 @@
package ninja.bytecode.iris.util;
import ninja.bytecode.shuriken.math.M;
public class IrisInterpolation
{
public static double bezier(double t)
{
return t * t * (3.0d - 2.0d * t);
}
public static double parametric(double t, double alpha)
{
double sqt = Math.pow(t, alpha);
return sqt / (alpha * (sqt - Math.pow(t, alpha - 1)) + 1.0d);
}
public static double lerp(double a, double b, double f)
{
return a + (f * (b - a));
}
public static double lerpBezier(double a, double b, double f)
{
return a + (bezier(f) * (b - a));
}
public static double sinCenter(double f)
{
return Math.sin(f * Math.PI);
}
public static double lerpCenterSinBezier(double a, double b, double f)
{
return lerpBezier(a, b, sinCenter(f));
}
public static double lerpCenterSin(double a, double b, double f)
{
return lerpBezier(a, b, sinCenter(f));
}
public static double lerpParametric(double a, double b, double f, double v)
{
return a + (parametric(f, v) * (b - a));
}
public static double blerp(double a, double b, double c, double d, double tx, double ty)
{
return lerp(lerp(a, b, tx), lerp(c, d, tx), ty);
}
public static double blerp(double a, double b, double c, double d, double tx, double ty, InterpolationType type)
{
if(type.equals(InterpolationType.LINEAR))
{
return blerp(a, b, c, d, tx, ty);
}
if(type.equals(InterpolationType.BEZIER))
{
return blerpBezier(a, b, c, d, tx, ty);
}
if(type.equals(InterpolationType.PARAMETRIC_2))
{
return blerpParametric(a, b, c, d, tx, ty, 2);
}
if(type.equals(InterpolationType.PARAMETRIC_4))
{
return blerpParametric(a, b, c, d, tx, ty, 4);
}
return 0;
}
public static double blerpBezier(double a, double b, double c, double d, double tx, double ty)
{
return lerpBezier(lerpBezier(a, b, tx), lerpBezier(c, d, tx), ty);
}
public static double blerpParametric(double a, double b, double c, double d, double tx, double ty, double v)
{
return lerpParametric(lerpParametric(a, b, tx, v), lerpParametric(c, d, tx, v), ty, v);
}
public static double hermite(double p0, double p1, double p2, double p3, double mu, double tension, double bias)
{
double m0, m1, mu2, mu3;
double a0, a1, a2, a3;
mu2 = mu * mu;
mu3 = mu2 * mu;
m0 = (p1 - p0) * (1 + bias) * (1 - tension) / 2;
m0 += (p2 - p1) * (1 - bias) * (1 - tension) / 2;
m1 = (p2 - p1) * (1 + bias) * (1 - tension) / 2;
m1 += (p3 - p2) * (1 - bias) * (1 - tension) / 2;
a0 = 2 * mu3 - 3 * mu2 + 1;
a1 = mu3 - 2 * mu2 + mu;
a2 = mu3 - mu2;
a3 = -2 * mu3 + 3 * mu2;
return (a0 * p1 + a1 * m0 + a2 * m1 + a3 * p2);
}
public static double bihermite(double p00, double p01, double p02, double p03, double p10, double p11, double p12, double p13, double p20, double p21, double p22, double p23, double p30, double p31, double p32, double p33, double mux, double muy, double tension, double bias)
{
return hermite(hermite(p00, p01, p02, p03, muy, tension, bias), hermite(p10, p11, p12, p13, muy, tension, bias), hermite(p20, p21, p22, p23, muy, tension, bias), hermite(p30, p31, p32, p33, muy, tension, bias), mux, tension, bias);
}
public static double cubic(double p0, double p1, double p2, double p3, double mu)
{
double a0, a1, a2, a3, mu2;
mu2 = mu * mu;
a0 = p3 - p2 - p0 + p1;
a1 = p0 - p1 - a0;
a2 = p2 - p0;
a3 = p1;
return a0 * mu * mu2 + a1 * mu2 + a2 * mu + a3;
}
public static double bicubic(double p00, double p01, double p02, double p03, double p10, double p11, double p12, double p13, double p20, double p21, double p22, double p23, double p30, double p31, double p32, double p33, double mux, double muy)
{
return cubic(cubic(p00, p01, p02, p03, muy), cubic(p10, p11, p12, p13, muy), cubic(p20, p21, p22, p23, muy), cubic(p30, p31, p32, p33, muy), mux);
}
public static double getBilinearNoise(int x, int z, double rad, NoiseProvider n)
{
int fx = (int) Math.floor(x / rad);
int fz = (int) Math.floor(z / rad);
int x1 = (int) Math.round(fx * rad);
int z1 = (int) Math.round(fz * rad);
int x2 = (int) Math.round((fx + 1) * rad);
int z2 = (int) Math.round((fz + 1) * rad);
double px = M.rangeScale(0, 1, x1, x2, x);
double pz = M.rangeScale(0, 1, z1, z2, z);
//@builder
return blerpBezier(
n.noise(x1, z1),
n.noise(x2, z1),
n.noise(x1, z2),
n.noise(x2, z2),
px, pz);
//@done
}
public static double getBicubicNoise(int x, int z, double rad, NoiseProvider n)
{
int fx = (int) Math.floor(x / rad);
int fz = (int) Math.floor(z / rad);
int x0 = (int) Math.round((fx - 1) * rad);
int z0 = (int) Math.round((fz - 1) * rad);
int x1 = (int) Math.round(fx * rad);
int z1 = (int) Math.round(fz * rad);
int x2 = (int) Math.round((fx + 1) * rad);
int z2 = (int) Math.round((fz + 1) * rad);
int x3 = (int) Math.round((fx + 2) * rad);
int z3 = (int) Math.round((fz + 2) * rad);
double px = M.rangeScale(0, 1, x1, x2, x);
double pz = M.rangeScale(0, 1, z1, z2, z);
//@builder
return bicubic(
n.noise(x0, z0),
n.noise(x0, z1),
n.noise(x0, z2),
n.noise(x0, z3),
n.noise(x1, z0),
n.noise(x1, z1),
n.noise(x1, z2),
n.noise(x1, z3),
n.noise(x2, z0),
n.noise(x2, z1),
n.noise(x2, z2),
n.noise(x2, z3),
n.noise(x3, z0),
n.noise(x3, z1),
n.noise(x3, z2),
n.noise(x3, z3),
px, pz);
//@done
}
public static double getHermiteNoise(int x, int z, double rad, NoiseProvider n)
{
int fx = (int) Math.floor(x / rad);
int fz = (int) Math.floor(z / rad);
int x0 = (int) Math.round((fx - 1) * rad);
int z0 = (int) Math.round((fz - 1) * rad);
int x1 = (int) Math.round(fx * rad);
int z1 = (int) Math.round(fz * rad);
int x2 = (int) Math.round((fx + 1) * rad);
int z2 = (int) Math.round((fz + 1) * rad);
int x3 = (int) Math.round((fx + 2) * rad);
int z3 = (int) Math.round((fz + 2) * rad);
double px = M.rangeScale(0, 1, x1, x2, x);
double pz = M.rangeScale(0, 1, z1, z2, z);
//@builder
return bihermite(
n.noise(x0, z0),
n.noise(x0, z1),
n.noise(x0, z2),
n.noise(x0, z3),
n.noise(x1, z0),
n.noise(x1, z1),
n.noise(x1, z2),
n.noise(x1, z3),
n.noise(x2, z0),
n.noise(x2, z1),
n.noise(x2, z2),
n.noise(x2, z3),
n.noise(x3, z0),
n.noise(x3, z1),
n.noise(x3, z2),
n.noise(x3, z3),
px, pz, 0.00001, 0.5);
//@done
}
}

View File

@ -1,233 +0,0 @@
package ninja.bytecode.iris.util;
import java.util.function.Consumer;
import org.bukkit.command.CommandSender;
import mortar.compute.math.M;
import mortar.util.text.C;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.shuriken.bench.PrecisionStopwatch;
import ninja.bytecode.shuriken.collections.KList;
import ninja.bytecode.shuriken.collections.KMap;
import ninja.bytecode.shuriken.format.Form;
import ninja.bytecode.shuriken.math.RollingSequence;
public class IrisMetrics
{
private int size;
private int generators;
private double scale;
private KMap<String, RollingSequence> sequences;
public IrisMetrics(int generators, int size)
{
scale = 1;
this.size = size;
this.generators = generators;
sequences = new KMap<>();
}
public String avgMS(String s, int dec)
{
return Form.duration(get(s).getAverage(), dec);
}
public String avg(String s, int dec)
{
return Form.f(get(s).getAverage(), dec);
}
public String maxMS(String s, int dec)
{
return Form.duration(get(s).getMax(), dec);
}
public String max(String s, int dec)
{
return Form.f(get(s).getMax(), dec);
}
public String minMS(String s, int dec)
{
return Form.duration(get(s).getMin(), dec);
}
public String min(String s, int dec)
{
return Form.f(get(s).getMin(), dec);
}
public String medianMS(String s, int dec)
{
return Form.duration(get(s).getMedian(), dec);
}
public String median(String s, int dec)
{
return Form.f(get(s).getMedian(), dec);
}
public RollingSequence get(String s)
{
if(!sequences.containsKey(s))
{
return new RollingSequence(2);
}
return sequences.get(s);
}
public PrecisionStopwatch start()
{
return PrecisionStopwatch.start();
}
public void stop(String f, PrecisionStopwatch g)
{
put(f, g.getMilliseconds());
}
public void put(String f, double t)
{
if(!sequences.containsKey(f))
{
sequences.put(f, new RollingSequence(size));
}
sequences.get(f).put(t);
}
public int getGenerators()
{
return generators;
}
public void setGenerators(int generators)
{
this.generators = generators;
}
public KMap<String, RollingSequence> getSequences()
{
return sequences;
}
public void setSequences(KMap<String, RollingSequence> sequences)
{
this.sequences = sequences;
}
public void send(CommandSender p, Consumer<String> c)
{
send(p, c, null, 0);
}
public void setParScale(double sf)
{
scale = sf;
}
public void send(CommandSender p, Consumer<String> c, String parent, int ind)
{
KMap<String, String> out = new KMap<>();
looking: for(String i : getSequences().k())
{
KList<String> o = new KList<>();
if(i.contains(":"))
{
o.add(i.split("\\Q:\\E"));
}
else
{
o.add(i);
}
String pf = o.get(0);
o.remove(0);
getSequences().get(i).resetExtremes();
double vmin = Math.abs(getSequences().get(i).getMin());
double vmed = Math.abs(getSequences().get(i).getMedian());
double vavg = Math.abs(getSequences().get(i).getAverage());
double vmax = Math.abs(getSequences().get(i).getMax());
for(String k : o)
{
if(k.startsWith("x"))
{
Double mult = Double.valueOf(k.substring(1));
vmin *= mult / (scale * 2D);
vmed *= mult / (scale * 2D);
vavg *= mult / (scale * 2D);
vmax *= mult / (scale * 2D);
}
}
boolean ms = false;
boolean comma = false;
String myparent = null;
int dot = 0;
for(String k : o)
{
if(k.startsWith("/"))
{
myparent = k.substring(1);
}
if(k.startsWith(".") && k.endsWith("."))
{
dot = k.length();
}
else if(k.equals(","))
{
comma = true;
}
if(k.equals("ms"))
{
ms = true;
}
}
if((parent != null) != (myparent != null))
{
continue looking;
}
if(parent != null && !myparent.equals(parent))
{
continue looking;
}
if(dot == 0 && vavg >= 1000 && !comma)
{
comma = true;
}
String af = ms ? Form.duration(vmin, dot) : comma ? Form.f((int) vmin) : Form.f(vmin, dot);
String bf = ms ? Form.duration(vmed, dot) : comma ? Form.f((int) vmed) : Form.f(vmed, dot);
String cf = ms ? Form.duration(vavg, dot) : comma ? Form.f((int) vavg) : Form.f(vavg, dot);
String df = ms ? Form.duration(vmax, dot) : comma ? Form.f((int) vmax) : Form.f(vmax, dot);
out.put(pf, C.DARK_GREEN.toString() + C.ITALIC + cf + C.RESET + C.GRAY + " (" + C.DARK_AQUA + C.ITALIC + af + C.RESET + C.GRAY + " > " + C.GOLD + C.ITALIC + bf + C.RESET + C.GRAY + " < " + C.DARK_RED + C.ITALIC + df + C.RESET + C.GRAY + ")");
}
if(ind == 0)
{
c.accept(C.WHITE.toString() + C.BOLD + "Total Generators: " + C.RESET + C.DARK_AQUA + C.ITALIC + Form.f(generators));
c.accept(C.WHITE.toString() + C.BOLD + "Parallelism: " + C.RESET + C.DARK_PURPLE + C.ITALIC + Form.pc(scale) + C.WHITE + C.BOLD + " Threads: " + C.RESET + C.BLUE + C.ITALIC + Iris.exec().getTC());
}
for(String i : out.k())
{
String g = Form.capitalizeWords(i.replaceAll("\\Q-\\E", " ").toLowerCase());
c.accept(Form.repeat(" ", M.iclip(ind, 0, 4)) + C.WHITE + C.BOLD + g + C.RESET + ": " + out.get(i));
send(p, c, i, ind + 1);
}
}
}

View File

@ -1,274 +0,0 @@
package ninja.bytecode.iris.util;
import java.io.IOException;
import org.bukkit.Bukkit;
import org.bukkit.World;
import mortar.util.text.C;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.generator.atomics.AtomicChunkData;
import ninja.bytecode.iris.generator.atomics.AtomicRegionData;
import ninja.bytecode.iris.generator.atomics.AtomicWorldData;
import ninja.bytecode.shuriken.collections.KList;
import ninja.bytecode.shuriken.collections.KMap;
import ninja.bytecode.shuriken.logging.L;
public class IrisWorldData
{
private final World world;
private final AtomicWorldData data;
private boolean saving;
private final KMap<SMCAVector, AtomicChunkData> loadedChunks;
public IrisWorldData(World world)
{
this.world = world;
saving = true;
data = new AtomicWorldData(world);
loadedChunks = new KMap<>();
Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, this::softUnloadWorld, 200, 20);
}
public void disableSaving()
{
saving = false;
}
public void enableSaving()
{
saving = true;
}
private void softUnloadWorld()
{
if(!saving)
{
return;
}
for(SMCAVector i : getLoadedChunks())
{
try
{
AtomicChunkData d = getChunk(i.getX(), i.getZ());
if(d.getTimeSinceLastUse() > 15000)
{
unloadChunk(i.getX(), i.getZ(), true);
}
}
catch(Throwable e)
{
e.printStackTrace();
}
}
for(SMCAVector i : getLoadedRegions())
{
softUnloadRegion(i.getX(), i.getZ());
}
}
private boolean softUnloadRegion(int rx, int rz)
{
if(!saving)
{
return false;
}
for(SMCAVector i : loadedChunks.keySet())
{
if(i.getX() >> 5 == rx && i.getZ() >> 5 == rz)
{
return false;
}
}
try
{
data.unloadSection(rx, rz, true);
return true;
}
catch(IOException e)
{
e.printStackTrace();
L.f(C.RED + "Failed to save Iris Subregion " + C.YELLOW + rx + " " + rz);
}
return false;
}
public boolean deleteChunk(int x, int z)
{
if(isChunkLoaded(x, z))
{
unloadChunk(x, z, false);
}
try
{
AtomicRegionData region = data.getSubregion(x >> 5, z >> 5);
region.delete(x & 31, z & 31);
return true;
}
catch(IOException e)
{
L.f(C.RED + "Failed delete chunk " + C.YELLOW + x + " " + z + C.RED.toString() + " -> Failed to get Region " + C.YELLOW + (x >> 5) + " " + (z >> 5));
e.printStackTrace();
}
return false;
}
public boolean unloadChunk(int x, int z, boolean save)
{
if(!isChunkLoaded(x, z))
{
return false;
}
if(save)
{
saveChunk(x, z);
}
loadedChunks.remove(new SMCAVector(x, z));
return true;
}
public boolean saveChunk(int x, int z)
{
if(!isChunkLoaded(x, z))
{
return false;
}
try
{
AtomicRegionData region = data.getSubregion(x >> 5, z >> 5);
region.set(x & 31, z & 31, getChunk(x, z));
return true;
}
catch(IOException e)
{
L.f(C.RED + "Failed save chunk " + C.YELLOW + x + " " + z + C.RED.toString() + " -> Failed to get Region " + C.YELLOW + (x >> 5) + " " + (z >> 5));
e.printStackTrace();
}
return false;
}
public AtomicChunkData getOnly(int x, int z)
{
if(!isChunkLoaded(x, z))
{
return null;
}
return getChunk(x, z);
}
public AtomicChunkData getChunk(int x, int z)
{
if(!isChunkLoaded(x, z))
{
try
{
AtomicRegionData region = data.getSubregion(x >> 5, z >> 5);
if(region.contains(x & 31, z & 31))
{
AtomicChunkData chunk = region.get(x & 31, z & 31);
loadedChunks.put(new SMCAVector(x, z), chunk);
}
else
{
AtomicChunkData data = new AtomicChunkData(world);
loadedChunks.put(new SMCAVector(x, z), data);
}
}
catch(IOException e)
{
L.f(C.RED + "Failed load chunk " + C.YELLOW + x + " " + z + C.RED.toString() + " -> Failed to get Region " + C.YELLOW + (x >> 5) + " " + (z >> 5));
e.printStackTrace();
}
}
return loadedChunks.get(new SMCAVector(x, z));
}
public boolean isChunkLoaded(int x, int z)
{
return loadedChunks.containsKey(new SMCAVector(x, z));
}
public void inject(int x, int z, AtomicChunkData data)
{
getChunk(x, z).inject(data);
}
public boolean exists(int x, int z)
{
try
{
return isChunkLoaded(x, z) || data.getSubregion(x >> 5, z >> 5).contains(x & 31, z & 31);
}
catch(IOException e)
{
L.f(C.RED + "Failed check chunk " + C.YELLOW + x + " " + z + C.RED.toString() + " -> Failed to get Region " + C.YELLOW + (x >> 5) + " " + (z >> 5));
e.printStackTrace();
}
return false;
}
public KList<SMCAVector> getLoadedChunks()
{
return loadedChunks.k();
}
public KList<SMCAVector> getLoadedRegions()
{
return data.getLoadedRegions();
}
public void saveAll()
{
for(SMCAVector i : loadedChunks.k())
{
saveChunk(i.getX(), i.getZ());
}
try
{
data.saveAll();
}
catch(IOException e)
{
e.printStackTrace();
}
}
public void setBlock(int x, int y, int z, int id, byte data)
{
getChunk(x >> 4, z >> 4).setBlock(x & 15, y, z & 15, id, data);
}
public void dispose()
{
for(SMCAVector i : getLoadedChunks())
{
unloadChunk(i.getX(), i.getZ(), true);
}
softUnloadWorld();
}
}

View File

@ -1,102 +0,0 @@
package ninja.bytecode.iris.util;
import org.bukkit.Material;
public class MB
{
public final Material material;
public final byte data;
@SuppressWarnings("deprecation")
public static MB of(String dat)
{
String material = dat;
byte data = 0;
if(dat.contains(":"))
{
material = dat.split("\\Q:\\E")[0];
data = Integer.valueOf(dat.split("\\Q:\\E")[1]).byteValue();
}
try
{
return new MB(Material.getMaterial(Integer.valueOf(material)), data);
}
catch(Throwable e)
{
}
try
{
return new MB(Material.getMaterial(material), data);
}
catch(Throwable e)
{
}
return MB.of(Material.AIR);
}
public String toString()
{
if(data == 0)
{
return material.name();
}
return material.name() + ":" + data;
}
public MB(Material material, int data)
{
this.material = material;
this.data = (byte) data;
}
public MB(Material material)
{
this(material, 0);
}
public static MB of(Material f)
{
return new MB(f);
}
public static MB of(Material f, int a)
{
return new MB(f, a);
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + data;
result = prime * result + ((material == null) ? 0 : material.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
if(this == obj)
return true;
if(obj == null)
return false;
if(getClass() != obj.getClass())
return false;
MB other = (MB) obj;
if(data != other.data)
return false;
if(material != other.material)
return false;
return true;
}
}

Some files were not shown because too many files have changed in this diff Show More