mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Massive enhancements
This commit is contained in:
parent
2a7b2343b2
commit
6179dbda8a
@ -10,8 +10,10 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import ninja.bytecode.iris.controller.TimingsController;
|
||||
import ninja.bytecode.iris.controller.WorldController;
|
||||
import ninja.bytecode.iris.generator.IrisGenerator;
|
||||
import ninja.bytecode.iris.spec.IrisBiome;
|
||||
import ninja.bytecode.iris.pack.IrisBiome;
|
||||
import ninja.bytecode.shuriken.format.F;
|
||||
|
||||
public class CommandIris implements CommandExecutor
|
||||
@ -28,7 +30,7 @@ public class CommandIris implements CommandExecutor
|
||||
{
|
||||
msg(sender, "/iris timings - Iris Timings");
|
||||
msg(sender, "/iris rtp [biome] - RTP to a biome");
|
||||
msg(sender, "/iris gen - Gen a new Iris World");
|
||||
msg(sender, "/iris reload - Reload & Recompile");
|
||||
msg(sender, "/ish - Iris Schematic Commands");
|
||||
}
|
||||
|
||||
@ -36,8 +38,8 @@ public class CommandIris implements CommandExecutor
|
||||
{
|
||||
if(args[0].equalsIgnoreCase("timings"))
|
||||
{
|
||||
double t = Iris.profiler.getResult("terrain").getAverage();
|
||||
double d = Iris.profiler.getResult("decor").getAverage();
|
||||
double t = Iris.getController(TimingsController.class).getResult("terrain");
|
||||
double d = Iris.getController(TimingsController.class).getResult("decor");
|
||||
msg(sender, "Generation: " + ChatColor.BOLD + ChatColor.WHITE + F.duration(t + d, 2));
|
||||
msg(sender, " \\Terrain: " + ChatColor.BOLD + ChatColor.WHITE + F.duration(t, 2));
|
||||
msg(sender, " \\Decor: " + ChatColor.BOLD + ChatColor.WHITE + F.duration(d, 2));
|
||||
@ -104,23 +106,10 @@ public class CommandIris implements CommandExecutor
|
||||
}
|
||||
}
|
||||
|
||||
if(args[0].equalsIgnoreCase("gen"))
|
||||
if(args[0].equalsIgnoreCase("reload"))
|
||||
{
|
||||
if(sender instanceof Player)
|
||||
{
|
||||
World wold = ((Player) sender).getWorld();
|
||||
World w = Iris.instance.createIrisWorld();
|
||||
((Player) sender).teleport(new Location(w, 0, 256, 0));
|
||||
((Player) sender).setFlying(true);
|
||||
((Player) sender).setGameMode(GameMode.CREATIVE);
|
||||
wold.setAutoSave(false);
|
||||
Bukkit.unloadWorld(wold, false);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Iris.instance.createIrisWorld();
|
||||
}
|
||||
msg(sender, "Reloading Iris...");
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> Iris.instance.reload());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,11 +15,11 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import ninja.bytecode.iris.schematic.Schematic;
|
||||
import ninja.bytecode.iris.controller.WandController;
|
||||
import ninja.bytecode.iris.generator.genobject.GenObject;
|
||||
import ninja.bytecode.iris.util.Cuboid;
|
||||
import ninja.bytecode.iris.util.Cuboid.CuboidDirection;
|
||||
import ninja.bytecode.iris.util.Direction;
|
||||
import ninja.bytecode.iris.util.WandUtil;
|
||||
import ninja.bytecode.shuriken.format.F;
|
||||
|
||||
public class CommandIsh implements CommandExecutor
|
||||
@ -53,7 +53,7 @@ public class CommandIsh implements CommandExecutor
|
||||
Player p = (Player) sender;
|
||||
if(args[0].equalsIgnoreCase("wand"))
|
||||
{
|
||||
p.getInventory().addItem(WandUtil.createWand());
|
||||
p.getInventory().addItem(WandController.createWand());
|
||||
p.playSound(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_DIAMOND, 1f, 1.55f);
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ public class CommandIsh implements CommandExecutor
|
||||
|
||||
if(args[0].equalsIgnoreCase("save"))
|
||||
{
|
||||
Schematic s = WandUtil.createSchematic(p.getInventory().getItemInMainHand(), p.getLocation());
|
||||
GenObject s = WandController.createSchematic(p.getInventory().getItemInMainHand(), p.getLocation());
|
||||
File f = new File(Iris.instance.getDataFolder(), "schematics/" + args[1] + ".ish");
|
||||
f.getParentFile().mkdirs();
|
||||
try
|
||||
@ -85,7 +85,7 @@ public class CommandIsh implements CommandExecutor
|
||||
|
||||
if(args[0].equalsIgnoreCase("load"))
|
||||
{
|
||||
Schematic s = new Schematic(1, 1, 1);
|
||||
GenObject s = new GenObject(1, 1, 1);
|
||||
File f = new File(Iris.instance.getDataFolder(), "schematics/" + args[1] + ".ish");
|
||||
if(!f.exists())
|
||||
{
|
||||
@ -115,7 +115,7 @@ public class CommandIsh implements CommandExecutor
|
||||
at = p.getTargetBlock(null, 64).getLocation();
|
||||
}
|
||||
|
||||
WandUtil.pasteSchematic(s, at);
|
||||
WandController.pasteSchematic(s, at);
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.25f);
|
||||
msg(p, "Pasted " + args[1] + " (" + F.f(s.getSchematic().size()) + " Blocks Modified)");
|
||||
}
|
||||
@ -128,7 +128,7 @@ public class CommandIsh implements CommandExecutor
|
||||
|
||||
if(args[0].equalsIgnoreCase("xup"))
|
||||
{
|
||||
Location[] b = WandUtil.getCuboid(p.getInventory().getItemInMainHand());
|
||||
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();
|
||||
@ -153,14 +153,14 @@ public class CommandIsh implements CommandExecutor
|
||||
cursor = cursor.contract(CuboidDirection.West);
|
||||
b[0] = cursor.getLowerNE();
|
||||
b[1] = cursor.getUpperSW();
|
||||
p.getInventory().setItemInMainHand(WandUtil.createWand(b[0], b[1]));
|
||||
p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1]));
|
||||
p.updateInventory();
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f);
|
||||
}
|
||||
|
||||
if(args[0].equalsIgnoreCase("shrinkwrap") || args[0].equalsIgnoreCase("shrink"))
|
||||
{
|
||||
Location[] b = WandUtil.getCuboid(p.getInventory().getItemInMainHand());
|
||||
Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand());
|
||||
Location a1 = b[0].clone();
|
||||
Location a2 = b[1].clone();
|
||||
Cuboid cursor = new Cuboid(a1, a2);
|
||||
@ -172,7 +172,7 @@ public class CommandIsh implements CommandExecutor
|
||||
cursor = cursor.contract(CuboidDirection.Down);
|
||||
b[0] = cursor.getLowerNE();
|
||||
b[1] = cursor.getUpperSW();
|
||||
p.getInventory().setItemInMainHand(WandUtil.createWand(b[0], b[1]));
|
||||
p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1]));
|
||||
p.updateInventory();
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f);
|
||||
}
|
||||
@ -180,7 +180,7 @@ public class CommandIsh implements CommandExecutor
|
||||
if(args[0].equalsIgnoreCase("expand"))
|
||||
{
|
||||
int amt = Integer.valueOf(args[1]);
|
||||
Location[] b = WandUtil.getCuboid(p.getInventory().getItemInMainHand());
|
||||
Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand());
|
||||
Location a1 = b[0].clone();
|
||||
Location a2 = b[1].clone();
|
||||
Cuboid cursor = new Cuboid(a1, a2);
|
||||
@ -188,7 +188,7 @@ public class CommandIsh implements CommandExecutor
|
||||
cursor = cursor.expand(d, amt);
|
||||
b[0] = cursor.getLowerNE();
|
||||
b[1] = cursor.getUpperSW();
|
||||
p.getInventory().setItemInMainHand(WandUtil.createWand(b[0], b[1]));
|
||||
p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1]));
|
||||
p.updateInventory();
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f);
|
||||
}
|
||||
@ -196,7 +196,7 @@ public class CommandIsh implements CommandExecutor
|
||||
if(args[0].equalsIgnoreCase("shift"))
|
||||
{
|
||||
int amt = Integer.valueOf(args[1]);
|
||||
Location[] b = WandUtil.getCuboid(p.getInventory().getItemInMainHand());
|
||||
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();
|
||||
@ -205,14 +205,14 @@ public class CommandIsh implements CommandExecutor
|
||||
Cuboid cursor = new Cuboid(a1, a2);
|
||||
b[0] = cursor.getLowerNE();
|
||||
b[1] = cursor.getUpperSW();
|
||||
p.getInventory().setItemInMainHand(WandUtil.createWand(b[0], b[1]));
|
||||
p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1]));
|
||||
p.updateInventory();
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f);
|
||||
}
|
||||
|
||||
if(args[0].equalsIgnoreCase("xvert"))
|
||||
{
|
||||
Location[] b = WandUtil.getCuboid(p.getInventory().getItemInMainHand());
|
||||
Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand());
|
||||
Location a1 = b[0].clone();
|
||||
Location a2 = b[1].clone();
|
||||
Location a1x = b[0].clone();
|
||||
@ -248,7 +248,7 @@ public class CommandIsh implements CommandExecutor
|
||||
cursor = cursor.contract(CuboidDirection.West);
|
||||
b[0] = cursor.getLowerNE();
|
||||
b[1] = cursor.getUpperSW();
|
||||
p.getInventory().setItemInMainHand(WandUtil.createWand(b[0], b[1]));
|
||||
p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1]));
|
||||
p.updateInventory();
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f);
|
||||
}
|
||||
|
@ -1,223 +1,76 @@
|
||||
package ninja.bytecode.iris;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Enumeration;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import ninja.bytecode.iris.controller.PackController;
|
||||
import ninja.bytecode.iris.generator.IrisGenerator;
|
||||
import ninja.bytecode.iris.schematic.Schematic;
|
||||
import ninja.bytecode.iris.schematic.SchematicGroup;
|
||||
import ninja.bytecode.iris.spec.IrisBiome;
|
||||
import ninja.bytecode.iris.spec.IrisDimension;
|
||||
import ninja.bytecode.iris.spec.IrisPack;
|
||||
import ninja.bytecode.iris.util.Direction;
|
||||
import ninja.bytecode.shuriken.bench.PrecisionStopwatch;
|
||||
import ninja.bytecode.shuriken.bench.Profiler;
|
||||
import ninja.bytecode.shuriken.collections.GMap;
|
||||
import ninja.bytecode.shuriken.collections.GSet;
|
||||
import ninja.bytecode.shuriken.execution.J;
|
||||
import ninja.bytecode.shuriken.execution.TaskExecutor;
|
||||
import ninja.bytecode.shuriken.execution.TaskExecutor.TaskGroup;
|
||||
import ninja.bytecode.shuriken.format.F;
|
||||
import ninja.bytecode.shuriken.io.IO;
|
||||
import ninja.bytecode.shuriken.json.JSONException;
|
||||
import ninja.bytecode.shuriken.json.JSONObject;
|
||||
import ninja.bytecode.iris.util.IrisController;
|
||||
import ninja.bytecode.iris.util.IrisControllerSet;
|
||||
import ninja.bytecode.shuriken.logging.L;
|
||||
|
||||
public class Iris extends JavaPlugin implements Listener
|
||||
{
|
||||
public static GSet<Chunk> refresh = new GSet<>();
|
||||
public static Profiler profiler;
|
||||
public static TaskExecutor genPool;
|
||||
public static IrisGenerator gen;
|
||||
public IrisControllerSet controllerSet;
|
||||
|
||||
public static Settings settings;
|
||||
public static Iris instance;
|
||||
public static GMap<String, GMap<String, Function<Vector, Double>>> values;
|
||||
public static GMap<String, IrisDimension> dimensions;
|
||||
public static GMap<String, IrisBiome> biomes;
|
||||
public static GMap<String, SchematicGroup> schematics;
|
||||
|
||||
public void onEnable()
|
||||
{
|
||||
L.consoleConsumer = (s) -> Bukkit.getConsoleSender().sendMessage(s);
|
||||
Direction.calculatePermutations();
|
||||
dimensions = new GMap<>();
|
||||
biomes = new GMap<>();
|
||||
schematics = new GMap<>();
|
||||
profiler = new Profiler(512);
|
||||
values = new GMap<>();
|
||||
instance = this;
|
||||
settings = new Settings();
|
||||
J.attempt(() -> createTempCache());
|
||||
loadContent();
|
||||
gen = new IrisGenerator();
|
||||
genPool = new TaskExecutor(getTC(), settings.performance.threadPriority, "Iris Generator");
|
||||
getServer().getPluginManager().registerEvents((Listener) this, this);
|
||||
getCommand("iris").setExecutor(new CommandIris());
|
||||
getCommand("ish").setExecutor(new CommandIsh());
|
||||
new WandManager();
|
||||
loadComplete();
|
||||
}
|
||||
|
||||
public static void started(String obj)
|
||||
{
|
||||
profiler.start(obj);
|
||||
}
|
||||
|
||||
public static void stopped(String obj)
|
||||
{
|
||||
profiler.stop(obj);
|
||||
}
|
||||
|
||||
private void loadComplete()
|
||||
{
|
||||
if(settings.performance.loadonstart)
|
||||
{
|
||||
GSet<String> ws = new GSet<>();
|
||||
|
||||
World w = createIrisWorld();
|
||||
for(Player i : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
Location m = i.getLocation();
|
||||
ws.add(i.getWorld().getName());
|
||||
i.teleport(new Location(w, m.getX(), m.getY(), m.getZ(), m.getYaw(), m.getPitch()));
|
||||
i.setFlying(true);
|
||||
i.setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
|
||||
for(String i : ws)
|
||||
{
|
||||
Bukkit.unloadWorld(i, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private void createTempCache() throws Throwable
|
||||
{
|
||||
File temp = new File(System.getProperty("java.io.tmpdir") + "/Iris/");
|
||||
temp.mkdirs();
|
||||
L.i("Iris Cache: " + temp.getAbsolutePath());
|
||||
ZipFile zipFile = new ZipFile(getFile());
|
||||
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||
while(entries.hasMoreElements())
|
||||
{
|
||||
ZipEntry entry = entries.nextElement();
|
||||
if(entry.getName().startsWith("pack/") && !entry.isDirectory())
|
||||
{
|
||||
File f = new File(temp, entry.getName());
|
||||
f.getParentFile().mkdirs();
|
||||
InputStream stream = zipFile.getInputStream(entry);
|
||||
FileOutputStream fos = new FileOutputStream(f);
|
||||
IO.fullTransfer(stream, fos, 16921);
|
||||
fos.close();
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
|
||||
zipFile.close();
|
||||
}
|
||||
|
||||
private void loadContent()
|
||||
{
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
L.i("Loading Content");
|
||||
controllerSet = new IrisControllerSet();
|
||||
L.consoleConsumer = (s) -> Bukkit.getConsoleSender().sendMessage(s);
|
||||
|
||||
try
|
||||
{
|
||||
IrisPack master = new IrisPack(loadJSON("pack/manifest.json"));
|
||||
master.load();
|
||||
controllerSet.startControllers(getFile());
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
catch(IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
L.ex(e);
|
||||
}
|
||||
|
||||
int m = 0;
|
||||
L.i("Controllers: " + controllerSet.size());
|
||||
|
||||
for(SchematicGroup i : schematics.v())
|
||||
Direction.calculatePermutations();
|
||||
settings = new Settings();
|
||||
getServer().getPluginManager().registerEvents((Listener) this, this);
|
||||
getCommand("iris").setExecutor(new CommandIris());
|
||||
getCommand("ish").setExecutor(new CommandIsh());
|
||||
getController(PackController.class).createTempCache(getFile());
|
||||
|
||||
if(!settings.performance.debugMode)
|
||||
{
|
||||
m += i.size();
|
||||
getController(PackController.class).loadContent();
|
||||
}
|
||||
|
||||
L.v(ChatColor.LIGHT_PURPLE + "Processing Content");
|
||||
|
||||
TaskExecutor exf = new TaskExecutor(settings.performance.compilerThreads, settings.performance.compilerPriority, "Iris Compiler");
|
||||
TaskGroup gg = exf.startWork();
|
||||
for(SchematicGroup i : schematics.v())
|
||||
{
|
||||
gg.queue(i::processVariants);
|
||||
}
|
||||
gg.execute();
|
||||
exf.close();
|
||||
L.i(ChatColor.LIGHT_PURPLE + "Dimensions: " + ChatColor.WHITE + dimensions.size());
|
||||
L.i(ChatColor.LIGHT_PURPLE + "Biomes: " + ChatColor.WHITE + biomes.size());
|
||||
L.i(ChatColor.LIGHT_PURPLE + "Object Groups: " + ChatColor.WHITE + F.f(schematics.size()));
|
||||
L.i(ChatColor.LIGHT_PURPLE + "Objects: " + ChatColor.WHITE + F.f(m));
|
||||
L.i(ChatColor.LIGHT_PURPLE + "Compilation Time: " + ChatColor.WHITE + F.duration(p.getMilliseconds(), 2));
|
||||
L.i(ChatColor.GREEN + "Iris Dimensions Successfully Compiled!");
|
||||
L.flush();
|
||||
}
|
||||
|
||||
private int getTC()
|
||||
{
|
||||
switch(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 settings.performance.threadCount;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return Math.max(Runtime.getRuntime().availableProcessors() / 2, 1);
|
||||
}
|
||||
|
||||
public void onDisable()
|
||||
{
|
||||
genPool.close();
|
||||
controllerSet.stopControllers();
|
||||
HandlerList.unregisterAll((Plugin) this);
|
||||
Bukkit.getScheduler().cancelTasks(this);
|
||||
}
|
||||
|
||||
public void reload()
|
||||
{
|
||||
onDisable();
|
||||
onEnable();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends IrisController> T getController(Class<? extends T> c)
|
||||
{
|
||||
return (T) instance.controllerSet.get(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -225,90 +78,4 @@ public class Iris extends JavaPlugin implements Listener
|
||||
{
|
||||
return new IrisGenerator();
|
||||
}
|
||||
|
||||
public World createIrisWorld()
|
||||
{
|
||||
World ww = Bukkit.createWorld(new WorldCreator("iris-worlds/" + UUID.randomUUID().toString()).generator(new IrisGenerator()).seed(5944323));
|
||||
ww.setSpawnFlags(false, false);
|
||||
ww.setAutoSave(false);
|
||||
ww.setKeepSpawnInMemory(false);
|
||||
ww.setSpawnLocation(0, 256, 0);
|
||||
return ww;
|
||||
}
|
||||
|
||||
public static void v(String w, String t, Function<Vector, Double> d)
|
||||
{
|
||||
if(!values.containsKey(w))
|
||||
{
|
||||
values.put(w, new GMap<>());
|
||||
}
|
||||
|
||||
values.get(w).put(t, d);
|
||||
}
|
||||
|
||||
public static IrisDimension loadDimension(String s) throws JSONException, IOException
|
||||
{
|
||||
return new IrisDimension(loadJSON("pack/dimensions/" + s + ".json"));
|
||||
}
|
||||
|
||||
public static IrisBiome loadBiome(String s) throws JSONException, IOException
|
||||
{
|
||||
return new IrisBiome(loadJSON("pack/biomes/" + s + ".json"));
|
||||
}
|
||||
|
||||
public static SchematicGroup loadSchematicGroup(String s)
|
||||
{
|
||||
SchematicGroup g = SchematicGroup.load("pack/objects/" + s);
|
||||
|
||||
if(g != null)
|
||||
{
|
||||
schematics.put(s, g);
|
||||
return g;
|
||||
}
|
||||
|
||||
L.i("Cannot load Object Group: " + s);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Schematic loadSchematic(String s) throws IOException
|
||||
{
|
||||
return Schematic.load(loadResource("pack/objects/" + s + ".ish"));
|
||||
}
|
||||
|
||||
public static JSONObject loadJSON(String s) throws JSONException, IOException
|
||||
{
|
||||
return new JSONObject(IO.readAll(loadResource(s)));
|
||||
}
|
||||
|
||||
public static 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 static InputStream loadResource(String string) throws IOException
|
||||
{
|
||||
File internal = internalResource(string);
|
||||
|
||||
if(internal.exists())
|
||||
{
|
||||
L.v(ChatColor.DARK_PURPLE + "Loading Resource: " + ChatColor.GRAY + internal.getAbsolutePath());
|
||||
L.flush();
|
||||
return new FileInputStream(internal);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
L.f(ChatColor.RED + "Cannot find Resource: " + ChatColor.YELLOW + internal.getAbsolutePath());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ public class Settings
|
||||
public PerformanceMode performanceMode = PerformanceMode.DOUBLE_CPU;
|
||||
public int threadCount = 1;
|
||||
public int threadPriority = Thread.MIN_PRIORITY;
|
||||
public boolean loadonstart = true;
|
||||
public int compilerThreads = 4;
|
||||
public boolean debugMode = true;
|
||||
public int compilerThreads = 12;
|
||||
public int compilerPriority = Thread.MAX_PRIORITY;
|
||||
public int decorationAccuracy = 1;
|
||||
}
|
||||
|
@ -1,156 +0,0 @@
|
||||
package ninja.bytecode.iris;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import ninja.bytecode.iris.util.ParticleEffect;
|
||||
import ninja.bytecode.iris.util.ParticleRedstone;
|
||||
import ninja.bytecode.iris.util.WandUtil;
|
||||
|
||||
public class WandManager implements Listener
|
||||
{
|
||||
@SuppressWarnings("deprecation")
|
||||
public WandManager()
|
||||
{
|
||||
Bukkit.getPluginManager().registerEvents(this, Iris.instance);
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, () ->
|
||||
{
|
||||
for(Player i : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
tick(i);
|
||||
}
|
||||
|
||||
for(Chunk i : Iris.refresh)
|
||||
{
|
||||
i.getWorld().refreshChunk(i.getX(), i.getZ());
|
||||
}
|
||||
|
||||
Iris.refresh.clear();
|
||||
}, 0, 2);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void tick(Player p)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(WandUtil.isWand(p.getInventory().getItemInMainHand()))
|
||||
{
|
||||
Location[] d = WandUtil.getCuboid(p.getInventory().getItemInMainHand());
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void on(PlayerInteractEvent e)
|
||||
{
|
||||
if(e.getHand().equals(EquipmentSlot.HAND) && WandUtil.isWand(e.getPlayer().getInventory().getItemInMainHand()))
|
||||
{
|
||||
if(e.getAction().equals(Action.LEFT_CLICK_BLOCK))
|
||||
{
|
||||
e.setCancelled(true);
|
||||
e.getPlayer().getInventory().setItemInMainHand(WandUtil.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(WandUtil.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
132
src/main/java/ninja/bytecode/iris/command/CommandIris.java
Normal file
132
src/main/java/ninja/bytecode/iris/command/CommandIris.java
Normal file
@ -0,0 +1,132 @@
|
||||
package ninja.bytecode.iris.command;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import ninja.bytecode.iris.Iris;
|
||||
import ninja.bytecode.iris.controller.TimingsController;
|
||||
import ninja.bytecode.iris.controller.WorldController;
|
||||
import ninja.bytecode.iris.generator.IrisGenerator;
|
||||
import ninja.bytecode.iris.pack.IrisBiome;
|
||||
import ninja.bytecode.shuriken.format.F;
|
||||
|
||||
public class CommandIris implements CommandExecutor
|
||||
{
|
||||
public void msg(CommandSender s, String msg)
|
||||
{
|
||||
s.sendMessage(ChatColor.DARK_PURPLE + "[" + ChatColor.GRAY + "Iris" + ChatColor.DARK_PURPLE + "]" + ChatColor.GRAY + ": " + msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
|
||||
{
|
||||
if(args.length == 0)
|
||||
{
|
||||
msg(sender, "/iris timings - Iris Timings");
|
||||
msg(sender, "/iris rtp [biome] - RTP to a biome");
|
||||
msg(sender, "/iris gen - Gen a new Iris World");
|
||||
msg(sender, "/ish - Iris Schematic Commands");
|
||||
}
|
||||
|
||||
if(args.length > 0)
|
||||
{
|
||||
if(args[0].equalsIgnoreCase("timings"))
|
||||
{
|
||||
double t = Iris.getController(TimingsController.class).getResult("terrain");
|
||||
double d = Iris.getController(TimingsController.class).getResult("decor");
|
||||
msg(sender, "Generation: " + ChatColor.BOLD + ChatColor.WHITE + F.duration(t + d, 2));
|
||||
msg(sender, " \\Terrain: " + ChatColor.BOLD + ChatColor.WHITE + F.duration(t, 2));
|
||||
msg(sender, " \\Decor: " + ChatColor.BOLD + ChatColor.WHITE + F.duration(d, 2));
|
||||
}
|
||||
|
||||
if(args[0].equalsIgnoreCase("rtp"))
|
||||
{
|
||||
if(sender instanceof Player)
|
||||
{
|
||||
Player p = (Player) sender;
|
||||
World w = p.getWorld();
|
||||
|
||||
if(w.getGenerator() instanceof IrisGenerator)
|
||||
{
|
||||
if(args.length > 1)
|
||||
{
|
||||
IrisGenerator g = (IrisGenerator) w.getGenerator();
|
||||
IrisBiome b = null;
|
||||
for(IrisBiome i : g.getLoadedBiomes())
|
||||
{
|
||||
if(args[1].toLowerCase().equals(i.getName().toLowerCase().replaceAll("\\Q \\E", "_")))
|
||||
{
|
||||
b = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(b == null)
|
||||
{
|
||||
msg(sender, "Unknown Biome: " + args[1]);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
msg(sender, "Looking for " + 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(x, z).equals(b))
|
||||
{
|
||||
f = true;
|
||||
p.teleport(w.getHighestBlockAt(x, z).getLocation());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!f)
|
||||
{
|
||||
msg(sender, "Looked for " + b.getName() + " in 10,000 different locations and could not find it. Try again!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
int x = (int) ((int) (29999983 / 1.2) * Math.random());
|
||||
int z = (int) ((int) (29999983 / 1.2) * Math.random());
|
||||
p.teleport(w.getHighestBlockAt(x, z).getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(args[0].equalsIgnoreCase("gen"))
|
||||
{
|
||||
if(sender instanceof Player)
|
||||
{
|
||||
World wold = ((Player) sender).getWorld();
|
||||
World w = Iris.getController(WorldController.class).createIrisWorld(null, 0, true);
|
||||
((Player) sender).teleport(new Location(w, 0, 256, 0));
|
||||
((Player) sender).setFlying(true);
|
||||
((Player) sender).setGameMode(GameMode.CREATIVE);
|
||||
wold.setAutoSave(false);
|
||||
Bukkit.unloadWorld(wold, false);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Iris.getController(WorldController.class).createIrisWorld(null, 0, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
261
src/main/java/ninja/bytecode/iris/command/CommandIsh.java
Normal file
261
src/main/java/ninja/bytecode/iris/command/CommandIsh.java
Normal file
@ -0,0 +1,261 @@
|
||||
package ninja.bytecode.iris.command;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import ninja.bytecode.iris.Iris;
|
||||
import ninja.bytecode.iris.controller.WandController;
|
||||
import ninja.bytecode.iris.generator.genobject.GenObject;
|
||||
import ninja.bytecode.iris.util.Cuboid;
|
||||
import ninja.bytecode.iris.util.Cuboid.CuboidDirection;
|
||||
import ninja.bytecode.iris.util.Direction;
|
||||
import ninja.bytecode.shuriken.format.F;
|
||||
|
||||
public class CommandIsh implements CommandExecutor
|
||||
{
|
||||
public void msg(CommandSender s, String msg)
|
||||
{
|
||||
s.sendMessage(ChatColor.DARK_PURPLE + "[" + ChatColor.GRAY + "Iris" + ChatColor.DARK_PURPLE + "]" + ChatColor.GRAY + ": " + msg);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
|
||||
{
|
||||
if(args.length == 0)
|
||||
{
|
||||
msg(sender, "/ish wand - Get an Iris Wand");
|
||||
msg(sender, "/ish save <name> - Save Schematic");
|
||||
msg(sender, "/ish load <name> [cursor] - Paste Schematic");
|
||||
msg(sender, "/ish expand <amount> - Expand Cuboid in direction");
|
||||
msg(sender, "/ish shift <amount> - Shift Cuboid in direction");
|
||||
msg(sender, "/ish shrinkwrap - Shrink to blocks");
|
||||
msg(sender, "/ish xup - Shift up, Expand up, Contract in.");
|
||||
msg(sender, "/ish xvert - Expand up, Expand down, Contract in.");
|
||||
msg(sender, "/ish id - What id am i looking at");
|
||||
}
|
||||
|
||||
if(args.length > 0)
|
||||
{
|
||||
if(sender instanceof Player)
|
||||
{
|
||||
Player p = (Player) sender;
|
||||
if(args[0].equalsIgnoreCase("wand"))
|
||||
{
|
||||
p.getInventory().addItem(WandController.createWand());
|
||||
p.playSound(p.getLocation(), Sound.ITEM_ARMOR_EQUIP_DIAMOND, 1f, 1.55f);
|
||||
}
|
||||
|
||||
if(args[0].equalsIgnoreCase("id"))
|
||||
{
|
||||
|
||||
Block b = p.getTargetBlock(null, 64);
|
||||
msg(p, b.getType().getId() + ":" + b.getData() + " (" + b.getType().toString() + ":" + b.getData() + ")");
|
||||
}
|
||||
|
||||
if(args[0].equalsIgnoreCase("save"))
|
||||
{
|
||||
GenObject s = WandController.createSchematic(p.getInventory().getItemInMainHand(), p.getLocation());
|
||||
File f = new File(Iris.instance.getDataFolder(), "schematics/" + args[1] + ".ish");
|
||||
f.getParentFile().mkdirs();
|
||||
try
|
||||
{
|
||||
FileOutputStream fos = new FileOutputStream(f);
|
||||
s.write(fos);
|
||||
msg(p, "Saved " + args[1] + " (" + F.f(s.getSchematic().size()) + " Entries)");
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 0.45f);
|
||||
}
|
||||
|
||||
catch(Throwable e1)
|
||||
{
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if(args[0].equalsIgnoreCase("load"))
|
||||
{
|
||||
GenObject s = new GenObject(1, 1, 1);
|
||||
File f = new File(Iris.instance.getDataFolder(), "schematics/" + args[1] + ".ish");
|
||||
if(!f.exists())
|
||||
{
|
||||
msg(p, "Not Found");
|
||||
return true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
FileInputStream fin = new FileInputStream(f);
|
||||
s.read(fin);
|
||||
|
||||
boolean cursor = false;
|
||||
for(String i : args)
|
||||
{
|
||||
if(i.equalsIgnoreCase("cursor"))
|
||||
{
|
||||
cursor = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Location at = p.getLocation();
|
||||
|
||||
if(cursor)
|
||||
{
|
||||
at = p.getTargetBlock(null, 64).getLocation();
|
||||
}
|
||||
|
||||
WandController.pasteSchematic(s, at);
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.25f);
|
||||
msg(p, "Pasted " + args[1] + " (" + F.f(s.getSchematic().size()) + " Blocks Modified)");
|
||||
}
|
||||
|
||||
catch(Throwable e1)
|
||||
{
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if(args[0].equalsIgnoreCase("xup"))
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
if(args[0].equalsIgnoreCase("shrinkwrap") || args[0].equalsIgnoreCase("shrink"))
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
if(args[0].equalsIgnoreCase("expand"))
|
||||
{
|
||||
int amt = Integer.valueOf(args[1]);
|
||||
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);
|
||||
}
|
||||
|
||||
if(args[0].equalsIgnoreCase("shift"))
|
||||
{
|
||||
int amt = Integer.valueOf(args[1]);
|
||||
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);
|
||||
}
|
||||
|
||||
if(args[0].equalsIgnoreCase("xvert"))
|
||||
{
|
||||
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 false;
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package ninja.bytecode.iris.controller;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import ninja.bytecode.iris.Iris;
|
||||
import ninja.bytecode.iris.util.IrisController;
|
||||
import ninja.bytecode.shuriken.collections.GSet;
|
||||
import ninja.bytecode.shuriken.execution.J;
|
||||
|
||||
public class DebugController implements IrisController
|
||||
{
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () ->
|
||||
{
|
||||
if(Iris.settings.performance.debugMode)
|
||||
{
|
||||
J.a(() ->
|
||||
{
|
||||
J.a(() ->
|
||||
{
|
||||
J.sleep(1000);
|
||||
while(!Iris.getController(PackController.class).isReady())
|
||||
{
|
||||
J.sleep(250);
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () ->
|
||||
{
|
||||
if(Iris.settings.performance.debugMode)
|
||||
{
|
||||
GSet<String> ws = new GSet<>();
|
||||
|
||||
World w = Iris.getController(WorldController.class).createIrisWorld(null, 0, true);
|
||||
for(Player i : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
Location m = i.getLocation();
|
||||
ws.add(i.getWorld().getName());
|
||||
i.teleport(new Location(w, m.getX(), m.getY(), m.getZ(), m.getYaw(), m.getPitch()));
|
||||
i.setFlying(true);
|
||||
i.setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
|
||||
for(String i : ws)
|
||||
{
|
||||
Bukkit.unloadWorld(i, false);
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
});
|
||||
Iris.getController(PackController.class).loadContent();
|
||||
});
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package ninja.bytecode.iris.controller;
|
||||
|
||||
import org.bukkit.World;
|
||||
|
||||
import ninja.bytecode.iris.Iris;
|
||||
import ninja.bytecode.iris.util.IrisController;
|
||||
import ninja.bytecode.shuriken.collections.GMap;
|
||||
import ninja.bytecode.shuriken.execution.TaskExecutor;
|
||||
|
||||
public class ExecutionController implements IrisController
|
||||
{
|
||||
GMap<String, TaskExecutor> executors;
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
executors = new GMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public TaskExecutor getExecutor(World world)
|
||||
{
|
||||
TaskExecutor x = new TaskExecutor(getTC(), Iris.settings.performance.threadPriority, "Iris Generator (" + world.getName() + ")");
|
||||
executors.put(world.getWorldFolder().getAbsolutePath() + " (" + world + ")", x);
|
||||
return x;
|
||||
}
|
||||
|
||||
private 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);
|
||||
}
|
||||
}
|
230
src/main/java/ninja/bytecode/iris/controller/PackController.java
Normal file
230
src/main/java/ninja/bytecode/iris/controller/PackController.java
Normal file
@ -0,0 +1,230 @@
|
||||
package ninja.bytecode.iris.controller;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Enumeration;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
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.IrisBiome;
|
||||
import ninja.bytecode.iris.pack.IrisDimension;
|
||||
import ninja.bytecode.iris.pack.IrisPack;
|
||||
import ninja.bytecode.iris.util.IrisController;
|
||||
import ninja.bytecode.shuriken.bench.PrecisionStopwatch;
|
||||
import ninja.bytecode.shuriken.collections.GMap;
|
||||
import ninja.bytecode.shuriken.execution.TaskExecutor;
|
||||
import ninja.bytecode.shuriken.execution.TaskExecutor.TaskGroup;
|
||||
import ninja.bytecode.shuriken.format.F;
|
||||
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 implements IrisController
|
||||
{
|
||||
private GMap<String, IrisDimension> dimensions;
|
||||
private GMap<String, IrisBiome> biomes;
|
||||
private GMap<String, GenObjectGroup> genObjectGroups;
|
||||
private boolean ready;
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
dimensions = new GMap<>();
|
||||
biomes = new GMap<>();
|
||||
genObjectGroups = new GMap<>();
|
||||
ready = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public boolean isReady()
|
||||
{
|
||||
return ready;
|
||||
}
|
||||
|
||||
public void createTempCache(File jar)
|
||||
{
|
||||
try
|
||||
{
|
||||
File temp = new File(System.getProperty("java.io.tmpdir") + "/Iris/");
|
||||
temp.mkdirs();
|
||||
L.i("Iris Cache: " + temp.getAbsolutePath());
|
||||
ZipFile zipFile = new ZipFile(jar);
|
||||
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||
while(entries.hasMoreElements())
|
||||
{
|
||||
ZipEntry entry = entries.nextElement();
|
||||
if(entry.getName().startsWith("pack/") && !entry.isDirectory())
|
||||
{
|
||||
File f = new File(temp, entry.getName());
|
||||
f.getParentFile().mkdirs();
|
||||
InputStream stream = zipFile.getInputStream(entry);
|
||||
FileOutputStream fos = new FileOutputStream(f);
|
||||
IO.fullTransfer(stream, fos, 16921);
|
||||
fos.close();
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
|
||||
zipFile.close();
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
L.w(ChatColor.YELLOW + "Failed to cache internal resources. Did you reload Iris externally?");
|
||||
}
|
||||
}
|
||||
|
||||
public void loadContent()
|
||||
{
|
||||
dimensions = new GMap<>();
|
||||
biomes = new GMap<>();
|
||||
genObjectGroups = new GMap<>();
|
||||
ready = false;
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
L.i("Loading Content");
|
||||
|
||||
try
|
||||
{
|
||||
IrisPack master = new IrisPack(loadJSON("pack/manifest.json"));
|
||||
master.load();
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
L.v(ChatColor.LIGHT_PURPLE + "Processing Content");
|
||||
|
||||
TaskExecutor exf = new TaskExecutor(Iris.settings.performance.compilerThreads, Iris.settings.performance.compilerPriority, "Iris Compiler");
|
||||
TaskGroup gg = exf.startWork();
|
||||
for(GenObjectGroup i : getGenObjectGroups().v())
|
||||
{
|
||||
gg.queue(i::processVariants);
|
||||
}
|
||||
|
||||
gg.execute();
|
||||
exf.close();
|
||||
int m = 0;
|
||||
|
||||
for(GenObjectGroup i : getGenObjectGroups().v())
|
||||
{
|
||||
m += i.size();
|
||||
}
|
||||
|
||||
L.i(ChatColor.LIGHT_PURPLE + "Dimensions: " + ChatColor.WHITE + getDimensions().size());
|
||||
L.i(ChatColor.LIGHT_PURPLE + "Biomes: " + ChatColor.WHITE + getBiomes().size());
|
||||
L.i(ChatColor.LIGHT_PURPLE + "Object Groups: " + ChatColor.WHITE + F.f(getGenObjectGroups().size()));
|
||||
L.i(ChatColor.LIGHT_PURPLE + "Objects: " + ChatColor.WHITE + F.f(m));
|
||||
L.i(ChatColor.LIGHT_PURPLE + "Compilation Time: " + ChatColor.WHITE + F.duration(p.getMilliseconds(), 2));
|
||||
L.flush();
|
||||
L.i(ChatColor.GREEN + "Iris Dimensions Successfully Compiled!");
|
||||
ready = true;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Iris.getController(PackController.class).getGenObjectGroups().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());
|
||||
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 GMap<String, IrisDimension> getDimensions()
|
||||
{
|
||||
return dimensions;
|
||||
}
|
||||
|
||||
public GMap<String, IrisBiome> getBiomes()
|
||||
{
|
||||
return biomes;
|
||||
}
|
||||
|
||||
public GMap<String, GenObjectGroup> getGenObjectGroups()
|
||||
{
|
||||
return genObjectGroups;
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package ninja.bytecode.iris.controller;
|
||||
|
||||
import ninja.bytecode.iris.util.IrisController;
|
||||
import ninja.bytecode.shuriken.bench.Profiler;
|
||||
|
||||
public class TimingsController implements IrisController
|
||||
{
|
||||
public Profiler profiler;
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
profiler = new Profiler(768);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void started(String obj)
|
||||
{
|
||||
profiler.start(obj);
|
||||
}
|
||||
|
||||
public void stopped(String obj)
|
||||
{
|
||||
profiler.stop(obj);
|
||||
}
|
||||
|
||||
public double getResult(String tag)
|
||||
{
|
||||
return profiler.getResult(tag).getAverage();
|
||||
}
|
||||
}
|
304
src/main/java/ninja/bytecode/iris/controller/WandController.java
Normal file
304
src/main/java/ninja/bytecode/iris/controller/WandController.java
Normal file
@ -0,0 +1,304 @@
|
||||
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 ninja.bytecode.iris.Iris;
|
||||
import ninja.bytecode.iris.generator.genobject.GenObject;
|
||||
import ninja.bytecode.iris.util.Cuboid;
|
||||
import ninja.bytecode.iris.util.IrisController;
|
||||
import ninja.bytecode.iris.util.MB;
|
||||
import ninja.bytecode.iris.util.ParticleEffect;
|
||||
import ninja.bytecode.iris.util.ParticleRedstone;
|
||||
import ninja.bytecode.shuriken.collections.GList;
|
||||
|
||||
public class WandController implements IrisController
|
||||
{
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
//TODO: Optimize
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, () ->
|
||||
{
|
||||
for(Player i : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
tick(i);
|
||||
}
|
||||
}, 0, 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void tick(Player p)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(isWand(p.getInventory().getItemInMainHand()))
|
||||
{
|
||||
Location[] d = getCuboid(p.getInventory().getItemInMainHand());
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@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.getWorld(), at.getBlockX(), at.getBlockY(), at.getBlockZ());
|
||||
}
|
||||
|
||||
@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 GList<String>().add(locationToString(a), locationToString(b)));
|
||||
is.setItemMeta(im);
|
||||
|
||||
return 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;
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package ninja.bytecode.iris.controller;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
|
||||
import ninja.bytecode.iris.Iris;
|
||||
import ninja.bytecode.iris.generator.IrisGenerator;
|
||||
import ninja.bytecode.iris.pack.IrisDimension;
|
||||
import ninja.bytecode.iris.util.IrisController;
|
||||
import ninja.bytecode.shuriken.execution.J;
|
||||
import ninja.bytecode.shuriken.io.IO;
|
||||
|
||||
public class WorldController implements IrisController
|
||||
{
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
J.attemptAsync(() ->
|
||||
{
|
||||
for(File i : new File(Iris.instance.getDataFolder().getParentFile().getParentFile(), "iris-worlds").listFiles())
|
||||
{
|
||||
if(new File(i, ".garbage").exists())
|
||||
{
|
||||
IO.delete(i);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public World createIrisWorld(IrisDimension dimension, long seed, boolean temp)
|
||||
{
|
||||
if(dimension == null)
|
||||
{
|
||||
dimension = Iris.getController(PackController.class).getDimensions().get("overworld");
|
||||
}
|
||||
|
||||
//@builder
|
||||
World ww = Bukkit.createWorld(new WorldCreator("iris-worlds/" + UUID.randomUUID().toString())
|
||||
.generator(new IrisGenerator(dimension))
|
||||
.environment(dimension.getEnvironment())
|
||||
.seed(seed));
|
||||
//@done
|
||||
ww.setSpawnFlags(false, false);
|
||||
ww.setAutoSave(false);
|
||||
ww.setKeepSpawnInMemory(false);
|
||||
ww.setSpawnLocation(0, 256, 0);
|
||||
|
||||
if(temp)
|
||||
{
|
||||
J.attempt(() -> new File(ww.getWorldFolder(), ".garbage").createNewFile());
|
||||
}
|
||||
|
||||
return ww;
|
||||
}
|
||||
}
|
@ -9,15 +9,16 @@ import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
|
||||
import ninja.bytecode.iris.Iris;
|
||||
import ninja.bytecode.iris.controller.PackController;
|
||||
import ninja.bytecode.iris.generator.genobject.GenObjectDecorator;
|
||||
import ninja.bytecode.iris.generator.genobject.GenObjectGroup;
|
||||
import ninja.bytecode.iris.generator.layer.GenLayerBase;
|
||||
import ninja.bytecode.iris.generator.layer.GenLayerBiome;
|
||||
import ninja.bytecode.iris.generator.layer.GenLayerCaves;
|
||||
import ninja.bytecode.iris.generator.layer.GenLayerLayeredNoise;
|
||||
import ninja.bytecode.iris.generator.layer.GenLayerRidge;
|
||||
import ninja.bytecode.iris.generator.populator.ObjectPopulator;
|
||||
import ninja.bytecode.iris.schematic.SchematicGroup;
|
||||
import ninja.bytecode.iris.spec.IrisBiome;
|
||||
import ninja.bytecode.iris.spec.IrisDimension;
|
||||
import ninja.bytecode.iris.pack.IrisBiome;
|
||||
import ninja.bytecode.iris.pack.IrisDimension;
|
||||
import ninja.bytecode.iris.util.AtomicChunkData;
|
||||
import ninja.bytecode.iris.util.ChunkPlan;
|
||||
import ninja.bytecode.iris.util.IrisInterpolation;
|
||||
@ -61,11 +62,11 @@ public class IrisGenerator extends ParallelChunkGenerator
|
||||
private RNG rTerrain;
|
||||
private IrisDimension dim;
|
||||
private World world;
|
||||
private GMap<String, SchematicGroup> schematicCache = new GMap<>();
|
||||
private GMap<String, GenObjectGroup> schematicCache = new GMap<>();
|
||||
|
||||
public IrisGenerator()
|
||||
{
|
||||
this(Iris.dimensions.get("overworld"));
|
||||
this(Iris.getController(PackController.class).getDimensions().get("overworld"));
|
||||
}
|
||||
|
||||
public GList<IrisBiome> getLoadedBiomes()
|
||||
@ -230,15 +231,15 @@ public class IrisGenerator extends ParallelChunkGenerator
|
||||
|
||||
if(Iris.settings.gen.doSchematics)
|
||||
{
|
||||
p.add(new ObjectPopulator(this));
|
||||
p.add(new GenObjectDecorator(this));
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
public SchematicGroup loadSchematics(String folder)
|
||||
public GenObjectGroup loadSchematics(String folder)
|
||||
{
|
||||
return Iris.schematics.get(folder);
|
||||
return Iris.getController(PackController.class).getGenObjectGroups().get(folder);
|
||||
}
|
||||
|
||||
private double getBiomedHeight(int x, int z, ChunkPlan plan)
|
||||
@ -260,12 +261,12 @@ public class IrisGenerator extends ParallelChunkGenerator
|
||||
return world;
|
||||
}
|
||||
|
||||
public GMap<String, SchematicGroup> getSchematicCache()
|
||||
public GMap<String, GenObjectGroup> getSchematicCache()
|
||||
{
|
||||
return schematicCache;
|
||||
}
|
||||
|
||||
public void setSchematicCache(GMap<String, SchematicGroup> schematicCache)
|
||||
public void setSchematicCache(GMap<String, GenObjectGroup> schematicCache)
|
||||
{
|
||||
this.schematicCache = schematicCache;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package ninja.bytecode.iris.schematic;
|
||||
package ninja.bytecode.iris.generator.genobject;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@ -26,7 +26,7 @@ import ninja.bytecode.shuriken.collections.GMap;
|
||||
import ninja.bytecode.shuriken.io.CustomOutputStream;
|
||||
import ninja.bytecode.shuriken.logging.L;
|
||||
|
||||
public class Schematic
|
||||
public class GenObject
|
||||
{
|
||||
private boolean centeredHeight;
|
||||
private int w;
|
||||
@ -38,7 +38,7 @@ public class Schematic
|
||||
private int mountHeight;
|
||||
private BlockVector shift;
|
||||
|
||||
public Schematic(int w, int h, int d)
|
||||
public GenObject(int w, int h, int d)
|
||||
{
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
@ -180,9 +180,9 @@ public class Schematic
|
||||
s.put(new BlockVector(x, y, z), mb);
|
||||
}
|
||||
|
||||
public Schematic copy()
|
||||
public GenObject copy()
|
||||
{
|
||||
Schematic s = new Schematic(w, h, d);
|
||||
GenObject s = new GenObject(w, h, d);
|
||||
s.fill(this.s);
|
||||
s.centeredHeight = centeredHeight;
|
||||
s.name = name;
|
||||
@ -254,17 +254,17 @@ public class Schematic
|
||||
}
|
||||
}
|
||||
|
||||
public static Schematic load(InputStream in) throws IOException
|
||||
public static GenObject load(InputStream in) throws IOException
|
||||
{
|
||||
Schematic s = new Schematic(1, 1, 1);
|
||||
GenObject s = new GenObject(1, 1, 1);
|
||||
s.read(in);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
public static Schematic load(File f) throws IOException
|
||||
public static GenObject load(File f) throws IOException
|
||||
{
|
||||
Schematic s = new Schematic(1, 1, 1);
|
||||
GenObject s = new GenObject(1, 1, 1);
|
||||
s.name = f.getName().replaceAll("\\Q.ish\\E", "");
|
||||
FileInputStream fin = new FileInputStream(f);
|
||||
s.read(fin);
|
||||
|
@ -1,4 +1,4 @@
|
||||
package ninja.bytecode.iris.generator.populator;
|
||||
package ninja.bytecode.iris.generator.genobject;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@ -11,19 +11,20 @@ import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
|
||||
import ninja.bytecode.iris.Iris;
|
||||
import ninja.bytecode.iris.controller.PackController;
|
||||
import ninja.bytecode.iris.controller.TimingsController;
|
||||
import ninja.bytecode.iris.generator.IrisGenerator;
|
||||
import ninja.bytecode.iris.schematic.SchematicGroup;
|
||||
import ninja.bytecode.iris.spec.IrisBiome;
|
||||
import ninja.bytecode.iris.pack.IrisBiome;
|
||||
import ninja.bytecode.shuriken.collections.GMap;
|
||||
import ninja.bytecode.shuriken.collections.GSet;
|
||||
import ninja.bytecode.shuriken.math.M;
|
||||
|
||||
public class ObjectPopulator extends BlockPopulator
|
||||
public class GenObjectDecorator extends BlockPopulator
|
||||
{
|
||||
private GMap<Biome, IrisBiome> biomeMap;
|
||||
private GMap<Biome, GMap<SchematicGroup, Double>> populationCache;
|
||||
private GMap<Biome, GMap<GenObjectGroup, Double>> populationCache;
|
||||
|
||||
public ObjectPopulator(IrisGenerator generator)
|
||||
public GenObjectDecorator(IrisGenerator generator)
|
||||
{
|
||||
biomeMap = new GMap<>();
|
||||
populationCache = new GMap<>();
|
||||
@ -32,11 +33,11 @@ public class ObjectPopulator extends BlockPopulator
|
||||
{
|
||||
biomeMap.put(i.getRealBiome(), i);
|
||||
|
||||
GMap<SchematicGroup, Double> gk = new GMap<>();
|
||||
GMap<GenObjectGroup, Double> gk = new GMap<>();
|
||||
|
||||
for(String j : i.getSchematicGroups().k())
|
||||
{
|
||||
gk.put(Iris.schematics.get(j), i.getSchematicGroups().get(j));
|
||||
gk.put(Iris.getController(PackController.class).getGenObjectGroups().get(j), i.getSchematicGroups().get(j));
|
||||
}
|
||||
|
||||
populationCache.put(i.getRealBiome(), gk);
|
||||
@ -46,7 +47,7 @@ public class ObjectPopulator extends BlockPopulator
|
||||
@Override
|
||||
public void populate(World world, Random random, Chunk source)
|
||||
{
|
||||
Iris.started("decor");
|
||||
Iris.getController(TimingsController.class).started("decor");
|
||||
GSet<Biome> hits = new GSet<>();
|
||||
|
||||
for(int i = 0; i < Iris.settings.performance.decorationAccuracy; i++)
|
||||
@ -67,7 +68,7 @@ public class ObjectPopulator extends BlockPopulator
|
||||
continue;
|
||||
}
|
||||
|
||||
GMap<SchematicGroup, Double> objects = populationCache.get(biome);
|
||||
GMap<GenObjectGroup, Double> objects = populationCache.get(biome);
|
||||
|
||||
if(objects == null)
|
||||
{
|
||||
@ -78,12 +79,12 @@ public class ObjectPopulator extends BlockPopulator
|
||||
populate(world, random, source, biome, ibiome, objects);
|
||||
}
|
||||
|
||||
Iris.stopped("decor");
|
||||
Iris.getController(TimingsController.class).stopped("decor");
|
||||
}
|
||||
|
||||
private void populate(World world, Random random, Chunk source, Biome biome, IrisBiome ibiome, GMap<SchematicGroup, Double> objects)
|
||||
private void populate(World world, Random random, Chunk source, Biome biome, IrisBiome ibiome, GMap<GenObjectGroup, Double> objects)
|
||||
{
|
||||
for(SchematicGroup i : objects.k())
|
||||
for(GenObjectGroup i : objects.k())
|
||||
{
|
||||
for(int j = 0; j < getTries(objects.get(i)); j++)
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
package ninja.bytecode.iris.schematic;
|
||||
package ninja.bytecode.iris.generator.genobject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -6,6 +6,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import ninja.bytecode.iris.Iris;
|
||||
import ninja.bytecode.iris.controller.PackController;
|
||||
import ninja.bytecode.iris.util.Direction;
|
||||
import ninja.bytecode.shuriken.collections.GList;
|
||||
import ninja.bytecode.shuriken.execution.TaskExecutor;
|
||||
@ -14,14 +15,14 @@ import ninja.bytecode.shuriken.format.F;
|
||||
import ninja.bytecode.shuriken.io.IO;
|
||||
import ninja.bytecode.shuriken.logging.L;
|
||||
|
||||
public class SchematicGroup
|
||||
public class GenObjectGroup
|
||||
{
|
||||
private GList<Schematic> schematics;
|
||||
private GList<GenObject> schematics;
|
||||
private GList<String> flags;
|
||||
private String name;
|
||||
private int priority;
|
||||
|
||||
public SchematicGroup(String name)
|
||||
public GenObjectGroup(String name)
|
||||
{
|
||||
this.schematics = new GList<>();
|
||||
this.flags = new GList<>();
|
||||
@ -39,12 +40,12 @@ public class SchematicGroup
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public GList<Schematic> getSchematics()
|
||||
public GList<GenObject> getSchematics()
|
||||
{
|
||||
return schematics;
|
||||
}
|
||||
|
||||
public void setSchematics(GList<Schematic> schematics)
|
||||
public void setSchematics(GList<GenObject> schematics)
|
||||
{
|
||||
this.schematics = schematics;
|
||||
}
|
||||
@ -74,13 +75,13 @@ public class SchematicGroup
|
||||
return getSchematics().size();
|
||||
}
|
||||
|
||||
public static SchematicGroup load(String string)
|
||||
public static GenObjectGroup load(String string)
|
||||
{
|
||||
File folder = Iris.loadFolder(string);
|
||||
File folder = Iris.getController(PackController.class).loadFolder(string);
|
||||
|
||||
if(folder != null)
|
||||
{
|
||||
SchematicGroup g = new SchematicGroup(string);
|
||||
GenObjectGroup g = new GenObjectGroup(string);
|
||||
|
||||
for(File i : folder.listFiles())
|
||||
{
|
||||
@ -102,7 +103,7 @@ public class SchematicGroup
|
||||
{
|
||||
try
|
||||
{
|
||||
Schematic s = Schematic.load(i);
|
||||
GenObject s = GenObject.load(i);
|
||||
g.getSchematics().add(s);
|
||||
}
|
||||
|
||||
@ -122,19 +123,19 @@ public class SchematicGroup
|
||||
|
||||
public void processVariants()
|
||||
{
|
||||
GList<Schematic> inject = new GList<>();
|
||||
GList<GenObject> inject = new GList<>();
|
||||
String x = Thread.currentThread().getName();
|
||||
ReentrantLock rr = new ReentrantLock();
|
||||
TaskExecutor ex = new TaskExecutor(Iris.settings.performance.compilerThreads, Iris.settings.performance.compilerPriority, x + "/Subroutine ");
|
||||
TaskGroup gg = ex.startWork();
|
||||
for(Schematic i : getSchematics())
|
||||
for(GenObject i : getSchematics())
|
||||
{
|
||||
for(Direction j : new Direction[] {Direction.S, Direction.E, Direction.W})
|
||||
{
|
||||
Schematic cp = i.copy();
|
||||
GenObject cp = i.copy();
|
||||
|
||||
gg.queue(() -> {
|
||||
Schematic f = cp;
|
||||
GenObject f = cp;
|
||||
f.rotate(Direction.N, j);
|
||||
rr.lock();
|
||||
inject.add(f);
|
||||
@ -147,7 +148,7 @@ public class SchematicGroup
|
||||
gg = ex.startWork();
|
||||
getSchematics().add(inject);
|
||||
|
||||
for(Schematic i : getSchematics())
|
||||
for(GenObject i : getSchematics())
|
||||
{
|
||||
gg.queue(() -> {
|
||||
i.computeMountShift();
|
||||
@ -184,7 +185,7 @@ public class SchematicGroup
|
||||
return false;
|
||||
if(getClass() != obj.getClass())
|
||||
return false;
|
||||
SchematicGroup other = (SchematicGroup) obj;
|
||||
GenObjectGroup other = (GenObjectGroup) obj;
|
||||
if(flags == null)
|
||||
{
|
||||
if(other.flags != null)
|
||||
|
@ -8,7 +8,7 @@ import org.bukkit.World;
|
||||
|
||||
import ninja.bytecode.iris.Iris;
|
||||
import ninja.bytecode.iris.generator.IrisGenerator;
|
||||
import ninja.bytecode.iris.spec.IrisBiome;
|
||||
import ninja.bytecode.iris.pack.IrisBiome;
|
||||
import ninja.bytecode.iris.util.GenLayer;
|
||||
import ninja.bytecode.iris.util.MaxingGenerator;
|
||||
import ninja.bytecode.iris.util.MaxingGenerator.EnumMaxingGenerator;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package ninja.bytecode.iris.spec;
|
||||
package ninja.bytecode.iris.pack;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
@ -6,6 +6,7 @@ import org.bukkit.Material;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
import ninja.bytecode.iris.Iris;
|
||||
import ninja.bytecode.iris.controller.PackController;
|
||||
import ninja.bytecode.iris.util.MB;
|
||||
import ninja.bytecode.iris.util.PolygonGenerator;
|
||||
import ninja.bytecode.shuriken.collections.GList;
|
||||
@ -169,7 +170,7 @@ public class IrisBiome
|
||||
|
||||
for(String i : schematicGroups.k())
|
||||
{
|
||||
Iris.loadSchematicGroup(i);
|
||||
Iris.getController(PackController.class).loadSchematicGroup(i);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package ninja.bytecode.iris.spec;
|
||||
package ninja.bytecode.iris.pack;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
@ -6,6 +6,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
import org.bukkit.World.Environment;
|
||||
|
||||
import ninja.bytecode.iris.Iris;
|
||||
import ninja.bytecode.iris.controller.PackController;
|
||||
import ninja.bytecode.shuriken.collections.GList;
|
||||
import ninja.bytecode.shuriken.execution.J;
|
||||
import ninja.bytecode.shuriken.execution.TaskExecutor;
|
||||
@ -75,7 +76,7 @@ public class IrisDimension
|
||||
private GList<IrisBiome> biomesFromArray(JSONArray a) throws JSONException, IOException
|
||||
{
|
||||
GList<IrisBiome> b = new GList<>();
|
||||
TaskExecutor ex= new TaskExecutor(Iris.settings.performance.compilerThreads, Iris.settings.performance.compilerPriority, "Iris Dim Compiler");
|
||||
TaskExecutor ex= new TaskExecutor(Iris.settings.performance.compilerThreads, Iris.settings.performance.compilerPriority, "Iris Loader");
|
||||
TaskGroup g = ex.startWork();
|
||||
ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
@ -83,9 +84,9 @@ public class IrisDimension
|
||||
{
|
||||
int ii = i;
|
||||
g.queue(() -> {
|
||||
IrisBiome bb = Iris.loadBiome(a.getString(ii));
|
||||
IrisBiome bb = Iris.getController(PackController.class).loadBiome(a.getString(ii));
|
||||
lock.lock();
|
||||
Iris.biomes.put(a.getString(ii), bb);
|
||||
Iris.getController(PackController.class).getBiomes().put(a.getString(ii), bb);
|
||||
b.add(bb);
|
||||
lock.unlock();
|
||||
});
|
||||
@ -118,4 +119,9 @@ public class IrisDimension
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public Environment getEnvironment()
|
||||
{
|
||||
return environment;
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
package ninja.bytecode.iris.spec;
|
||||
package ninja.bytecode.iris.pack;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import ninja.bytecode.iris.Iris;
|
||||
import ninja.bytecode.iris.controller.PackController;
|
||||
import ninja.bytecode.shuriken.collections.GList;
|
||||
import ninja.bytecode.shuriken.execution.J;
|
||||
import ninja.bytecode.shuriken.json.JSONArray;
|
||||
@ -73,14 +74,14 @@ public class IrisPack
|
||||
{
|
||||
for(String i : dimensions)
|
||||
{
|
||||
IrisDimension d = Iris.loadDimension(i);
|
||||
Iris.dimensions.put(i, d);
|
||||
IrisDimension d = Iris.getController(PackController.class).loadDimension(i);
|
||||
Iris.getController(PackController.class).getDimensions().put(i, d);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadBiome(String s) throws JSONException, IOException
|
||||
{
|
||||
IrisBiome b = Iris.loadBiome(s);
|
||||
Iris.biomes.put(s, b);
|
||||
IrisBiome b = Iris.getController(PackController.class).loadBiome(s);
|
||||
Iris.getController(PackController.class).getBiomes().put(s, b);
|
||||
}
|
||||
}
|
||||
|
@ -4,15 +4,15 @@ import java.util.function.Supplier;
|
||||
|
||||
import org.bukkit.util.BlockVector;
|
||||
|
||||
import ninja.bytecode.iris.schematic.Schematic;
|
||||
import ninja.bytecode.iris.spec.IrisBiome;
|
||||
import ninja.bytecode.iris.generator.genobject.GenObject;
|
||||
import ninja.bytecode.iris.pack.IrisBiome;
|
||||
import ninja.bytecode.shuriken.collections.GMap;
|
||||
|
||||
public class ChunkPlan
|
||||
{
|
||||
private final GMap<ChunkedVector, Double> heightCache;
|
||||
private final GMap<ChunkedVector, IrisBiome> biomeCache;
|
||||
private final GMap<BlockVector, Schematic> schematics;
|
||||
private final GMap<BlockVector, GenObject> schematics;
|
||||
|
||||
public ChunkPlan()
|
||||
{
|
||||
@ -21,7 +21,7 @@ public class ChunkPlan
|
||||
this.biomeCache = new GMap<>();
|
||||
}
|
||||
|
||||
public void planSchematic(BlockVector b, Schematic s)
|
||||
public void planSchematic(BlockVector b, GenObject s)
|
||||
{
|
||||
schematics.put(b, s);
|
||||
}
|
||||
|
10
src/main/java/ninja/bytecode/iris/util/IrisController.java
Normal file
10
src/main/java/ninja/bytecode/iris/util/IrisController.java
Normal file
@ -0,0 +1,10 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public interface IrisController extends Listener
|
||||
{
|
||||
public void onStart();
|
||||
|
||||
public void onStop();
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
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.GMap;
|
||||
import ninja.bytecode.shuriken.logging.L;
|
||||
import ninja.bytecode.shuriken.tools.JarScanner;
|
||||
|
||||
public class IrisControllerSet
|
||||
{
|
||||
private GMap<Class<?>, IrisController> controllers;
|
||||
|
||||
public IrisControllerSet()
|
||||
{
|
||||
controllers = new GMap<>();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
@ -8,7 +8,10 @@ import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import ninja.bytecode.iris.Iris;
|
||||
import ninja.bytecode.iris.controller.ExecutionController;
|
||||
import ninja.bytecode.iris.controller.TimingsController;
|
||||
import ninja.bytecode.shuriken.execution.ChronoLatch;
|
||||
import ninja.bytecode.shuriken.execution.TaskExecutor;
|
||||
import ninja.bytecode.shuriken.execution.TaskExecutor.TaskGroup;
|
||||
import ninja.bytecode.shuriken.execution.TaskExecutor.TaskResult;
|
||||
import ninja.bytecode.shuriken.math.RollingSequence;
|
||||
@ -27,6 +30,7 @@ public abstract class ParallelChunkGenerator extends ChunkGenerator
|
||||
private ChronoLatch cl = new ChronoLatch(1000);
|
||||
private RollingSequence rs = new RollingSequence(512);
|
||||
private World world;
|
||||
private TaskExecutor genPool;
|
||||
|
||||
public World getWorld()
|
||||
{
|
||||
@ -41,7 +45,11 @@ public abstract class ParallelChunkGenerator extends ChunkGenerator
|
||||
|
||||
public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome)
|
||||
{
|
||||
Iris.started("terrain");
|
||||
Iris.getController(TimingsController.class).started("terrain");
|
||||
if(genPool == null)
|
||||
{
|
||||
genPool = Iris.getController(ExecutionController.class).getExecutor(world);
|
||||
}
|
||||
this.world = world;
|
||||
data = new AtomicChunkData(world);
|
||||
|
||||
@ -53,7 +61,7 @@ public abstract class ParallelChunkGenerator extends ChunkGenerator
|
||||
ready = true;
|
||||
}
|
||||
|
||||
tg = Iris.genPool.startWork();
|
||||
tg = genPool.startWork();
|
||||
O<ChunkPlan> plan = new O<ChunkPlan>();
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
@ -93,7 +101,7 @@ public abstract class ParallelChunkGenerator extends ChunkGenerator
|
||||
}
|
||||
}
|
||||
|
||||
Iris.stopped("terrain");
|
||||
Iris.getController(TimingsController.class).stopped("terrain");
|
||||
|
||||
return data.toChunkData();
|
||||
}
|
||||
|
@ -1,157 +0,0 @@
|
||||
package ninja.bytecode.iris.util;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.util.BlockVector;
|
||||
|
||||
import ninja.bytecode.iris.schematic.Schematic;
|
||||
import ninja.bytecode.shuriken.collections.GList;
|
||||
|
||||
public class WandUtil
|
||||
{
|
||||
public static void pasteSchematic(Schematic s, Location at)
|
||||
{
|
||||
s.place(at.getWorld(), at.getBlockX(), at.getBlockY(), at.getBlockZ());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Schematic createSchematic(ItemStack wand, Location at)
|
||||
{
|
||||
if(!isWand(wand))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Location[] f = getCuboid(wand);
|
||||
Cuboid c = new Cuboid(f[0], f[1]);
|
||||
Schematic s = new Schematic(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 GList<String>().add(locationToString(a), locationToString(b)));
|
||||
is.setItemMeta(im);
|
||||
|
||||
return 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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user