From da55612726b3a2694d003480d1051a9a2edcfcf4 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Wed, 8 Jan 2020 19:07:28 -0500 Subject: [PATCH] Reloading & Resource copying --- .../iris/controller/PackController.java | 12 +++--- .../iris/generator/genobject/GenObject.java | 2 +- .../genobject/GenObjectDecorator.java | 37 ++++++++++++------- src/main/resources/pack/biomes/plains.json | 2 +- 4 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/main/java/ninja/bytecode/iris/controller/PackController.java b/src/main/java/ninja/bytecode/iris/controller/PackController.java index 3ef10af2a..7ed1bfc82 100644 --- a/src/main/java/ninja/bytecode/iris/controller/PackController.java +++ b/src/main/java/ninja/bytecode/iris/controller/PackController.java @@ -19,6 +19,7 @@ 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.J; import ninja.bytecode.shuriken.execution.TaskExecutor; import ninja.bytecode.shuriken.execution.TaskExecutor.TaskGroup; import ninja.bytecode.shuriken.format.F; @@ -48,17 +49,18 @@ public class PackController implements IrisController { } - + public boolean isReady() { return ready; } - + public void createTempCache(File jar) { try { - File temp = new File(System.getProperty("java.io.tmpdir") + "/Iris/"); + J.a(() -> IO.delete(new File(Iris.instance.getDataFolder(), "pack"))); + File temp = Iris.instance.getDataFolder(); temp.mkdirs(); L.i("Iris Cache: " + temp.getAbsolutePath()); ZipFile zipFile = new ZipFile(jar); @@ -80,7 +82,7 @@ public class PackController implements IrisController zipFile.close(); } - + catch(Throwable e) { L.w(ChatColor.YELLOW + "Failed to cache internal resources. Did you reload Iris externally?"); @@ -119,7 +121,7 @@ public class PackController implements IrisController gg.execute(); exf.close(); int m = 0; - + for(GenObjectGroup i : getGenObjectGroups().v()) { m += i.size(); diff --git a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObject.java b/src/main/java/ninja/bytecode/iris/generator/genobject/GenObject.java index aab925206..2570d8b4f 100644 --- a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObject.java +++ b/src/main/java/ninja/bytecode/iris/generator/genobject/GenObject.java @@ -284,7 +284,7 @@ public class GenObject for(BlockVector i : g.k()) { - MB mb = rotate(from, to, g.get(i)); + MB mb = g.get(i); s.put(VectorMath.rotate(from, to, i).toBlockVector(), mb); } diff --git a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectDecorator.java b/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectDecorator.java index e13446fd0..934778e82 100644 --- a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectDecorator.java +++ b/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectDecorator.java @@ -10,6 +10,7 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.generator.BlockPopulator; +import net.md_5.bungee.api.ChatColor; import ninja.bytecode.iris.Iris; import ninja.bytecode.iris.controller.PackController; import ninja.bytecode.iris.controller.TimingsController; @@ -17,6 +18,7 @@ import ninja.bytecode.iris.generator.IrisGenerator; import ninja.bytecode.iris.pack.IrisBiome; import ninja.bytecode.shuriken.collections.GMap; import ninja.bytecode.shuriken.collections.GSet; +import ninja.bytecode.shuriken.logging.L; import ninja.bytecode.shuriken.math.M; public class GenObjectDecorator extends BlockPopulator @@ -37,7 +39,16 @@ public class GenObjectDecorator extends BlockPopulator for(String j : i.getSchematicGroups().k()) { - gk.put(Iris.getController(PackController.class).getGenObjectGroups().get(j), i.getSchematicGroups().get(j)); + try + { + gk.put(Iris.getController(PackController.class).getGenObjectGroups().get(j), i.getSchematicGroups().get(j)); + } + + catch(Throwable e) + { + L.f(ChatColor.RED + "Failed to inject " + j + " into GenObjectDecorator"); + L.ex(e); + } } populationCache.put(i.getRealBiome(), gk); @@ -49,39 +60,39 @@ public class GenObjectDecorator extends BlockPopulator { Iris.getController(TimingsController.class).started("decor"); GSet hits = new GSet<>(); - + for(int i = 0; i < Iris.settings.performance.decorationAccuracy; i++) { int x = (source.getX() << 4) + random.nextInt(16); int z = (source.getZ() << 4) + random.nextInt(16); Biome biome = world.getBiome(x, z); - + if(hits.contains(biome)) { continue; } - + IrisBiome ibiome = biomeMap.get(biome); - + if(ibiome == null) { continue; } - + GMap objects = populationCache.get(biome); - + if(objects == null) { continue; } - + hits.add(biome); populate(world, random, source, biome, ibiome, objects); } Iris.getController(TimingsController.class).stopped("decor"); } - + private void populate(World world, Random random, Chunk source, Biome biome, IrisBiome ibiome, GMap objects) { for(GenObjectGroup i : objects.k()) @@ -92,12 +103,12 @@ public class GenObjectDecorator extends BlockPopulator int z = (source.getZ() << 4) + random.nextInt(16); Block b = world.getHighestBlockAt(x, z).getRelative(BlockFace.DOWN); Material t = b.getType(); - + if(!t.isSolid() || !ibiome.isSurface(t)) { return; } - + i.getSchematics().get(random.nextInt(i.getSchematics().size())).place(world, x, b.getY(), z); } } @@ -114,14 +125,14 @@ public class GenObjectDecorator extends BlockPopulator { return (int) chance; } - + int floor = (int) Math.floor(chance); if(chance - floor > 0 && M.r(chance - floor)) { floor++; } - + return floor; } } diff --git a/src/main/resources/pack/biomes/plains.json b/src/main/resources/pack/biomes/plains.json index c46e734fe..12465d7f8 100644 --- a/src/main/resources/pack/biomes/plains.json +++ b/src/main/resources/pack/biomes/plains.json @@ -6,7 +6,7 @@ "LONG_GRASS:2=0.09" ], "objects": [ - "tree/serrulata/alt/medium=0.33", + "tree/serrulata/bleeding/alt/medium=0.33", "tree/serrulata/bleeding/large=0.42", "tree/serrulata/bleeding/medium=0.42", "tree/serrulata/nobleed/medium=0.42",