diff --git a/src/main/java/com/volmit/iris/ProjectManager.java b/src/main/java/com/volmit/iris/ProjectManager.java index 7cbd226f9..5de4bfd45 100644 --- a/src/main/java/com/volmit/iris/ProjectManager.java +++ b/src/main/java/com/volmit/iris/ProjectManager.java @@ -19,6 +19,8 @@ import com.volmit.iris.object.IrisDimension; import com.volmit.iris.object.IrisGenerator; import com.volmit.iris.object.IrisObjectPlacement; import com.volmit.iris.object.IrisRegion; +import com.volmit.iris.object.IrisStructure; +import com.volmit.iris.object.IrisStructureTile; import com.volmit.iris.util.Form; import com.volmit.iris.util.IO; import com.volmit.iris.util.J; @@ -57,7 +59,27 @@ public class ProjectManager public void open(MortarSender sender, String dimm, Runnable onDone) { IrisDimension d = Iris.data.getDimensionLoader().load(dimm); + J.attemptAsync(() -> + { + try + { + File f = d.getLoadFile().getParentFile().getParentFile(); + for(File i : f.listFiles()) + { + if(i.getName().endsWith(".code-workspace")) + { + Desktop.getDesktop().open(i); + break; + } + } + } + + catch(Throwable e) + { + e.printStackTrace(); + } + }); if(d == null) { sender.sendMessage("Can't find dimension: " + dimm); @@ -121,27 +143,6 @@ public class ProjectManager sender.player().setGameMode(GameMode.SPECTATOR); } - J.attemptAsync(() -> - { - try - { - File f = d.getLoadFile().getParentFile().getParentFile(); - - for(File i : f.listFiles()) - { - if(i.getName().endsWith(".code-workspace")) - { - Desktop.getDesktop().open(i); - break; - } - } - } - - catch(Throwable e) - { - e.printStackTrace(); - } - }); onDone.run(); }, 0); } @@ -172,15 +173,43 @@ public class ProjectManager Iris.info("Packaging Dimension " + dimension.getName() + " " + (obfuscate ? "(Obfuscated)" : "")); KSet regions = new KSet<>(); KSet biomes = new KSet<>(); + KSet structures = new KSet<>(); KSet generators = new KSet<>(); dimension.getRegions().forEach((i) -> regions.add(Iris.data.getRegionLoader().load(i))); regions.forEach((i) -> biomes.addAll(i.getAllBiomes())); biomes.forEach((i) -> i.getGenerators().forEach((j) -> generators.add(j.getCachedGenerator()))); + regions.forEach((i) -> i.getStructures().forEach((j) -> structures.add(j.getStructure()))); + biomes.forEach((i) -> i.getStructures().forEach((j) -> structures.add(j.getStructure()))); KMap renameObjects = new KMap<>(); String a = ""; StringBuilder b = new StringBuilder(); StringBuilder c = new StringBuilder(); + for(IrisStructure i : structures) + { + for(IrisStructureTile j : i.getTiles()) + { + b.append(j.hashCode()); + KList newNames = new KList<>(); + + for(String k : j.getObjects()) + { + if(renameObjects.containsKey(k)) + { + newNames.add(renameObjects.get(k)); + continue; + } + + String name = UUID.randomUUID().toString().replaceAll("-", ""); + b.append(name); + newNames.add(name); + renameObjects.put(k, name); + } + + j.setObjects(newNames); + } + } + for(IrisBiome i : biomes) { for(IrisObjectPlacement j : i.getObjects()) @@ -224,6 +253,21 @@ public class ProjectManager } }))); + structures.forEach((i) -> i.getTiles().forEach((j) -> j.getObjects().forEach((k) -> + { + try + { + File f = Iris.data.getObjectLoader().findFile(lookupObjects.get(k).get(0)); + IO.copyFile(f, new File(folder, "objects/" + k + ".iob")); + gb.append(IO.hash(f)); + } + + catch(Throwable e) + { + + } + }))); + b.append(IO.hash(gb.toString())); c.append(IO.hash(b.toString())); b = new StringBuilder(); @@ -251,6 +295,13 @@ public class ProjectManager b.append(IO.hash(a)); } + for(IrisStructure i : structures) + { + a = new JSONObject(new Gson().toJson(i)).toString(0); + IO.writeAll(new File(folder, "structures/" + i.getLoadKey() + ".json"), a); + b.append(IO.hash(a)); + } + for(IrisBiome i : biomes) { a = new JSONObject(new Gson().toJson(i)).toString(0); diff --git a/src/main/java/com/volmit/iris/gen/atomics/AtomicCache.java b/src/main/java/com/volmit/iris/gen/atomics/AtomicCache.java index a6a7c2409..67898fcfb 100644 --- a/src/main/java/com/volmit/iris/gen/atomics/AtomicCache.java +++ b/src/main/java/com/volmit/iris/gen/atomics/AtomicCache.java @@ -9,11 +9,16 @@ public class AtomicCache { private transient volatile T t; private transient volatile long a; - private boolean nullSupport; private transient volatile int validations; private final IrisLock check; private final IrisLock time; private final IrisLock write; + private final boolean nullSupport; + + public AtomicCache() + { + this(false); + } public AtomicCache(boolean nullSupport) { @@ -26,11 +31,6 @@ public class AtomicCache t = null; } - public AtomicCache() - { - this(false); - } - public void reset() { check.lock(); @@ -43,7 +43,51 @@ public class AtomicCache check.unlock(); } - public T aquireNullex(Supplier t) + public T aquire(Supplier t) + { + if(nullSupport) + { + return aquireNull(t); + } + + if(this.t != null && validations > 1000) + { + return this.t; + } + + if(this.t != null && M.ms() - a > 1000) + { + if(this.t != null) + { + validations++; + } + + return this.t; + } + + check.lock(); + + if(this.t == null) + { + write.lock(); + this.t = t.get(); + + time.lock(); + + if(a == -1) + { + a = M.ms(); + } + + time.unlock(); + write.unlock(); + } + + check.unlock(); + return this.t; + } + + public T aquireNull(Supplier t) { if(validations > 1000) { @@ -72,48 +116,4 @@ public class AtomicCache check.unlock(); return this.t; } - - public T aquire(Supplier t) - { - if(nullSupport) - { - return aquireNullex(t); - } - - if(this.t != null && validations > 1000) - { - return this.t; - } - - if(this.t != null && M.ms() - a > 1000) - { - if(this.t != null) - { - validations++; - } - - return this.t; - } - - check.lock(); - - if(this.t != null) - { - write.lock(); - this.t = t.get(); - - time.lock(); - - if(a == -1) - { - a = M.ms(); - } - - time.unlock(); - write.unlock(); - } - - check.unlock(); - return this.t; - } }