Reloading & Resource copying

This commit is contained in:
Daniel Mills 2020-01-08 19:07:28 -05:00
parent 1b88e132cc
commit da55612726
4 changed files with 33 additions and 20 deletions

View File

@ -19,6 +19,7 @@ import ninja.bytecode.iris.pack.IrisPack;
import ninja.bytecode.iris.util.IrisController; import ninja.bytecode.iris.util.IrisController;
import ninja.bytecode.shuriken.bench.PrecisionStopwatch; import ninja.bytecode.shuriken.bench.PrecisionStopwatch;
import ninja.bytecode.shuriken.collections.GMap; import ninja.bytecode.shuriken.collections.GMap;
import ninja.bytecode.shuriken.execution.J;
import ninja.bytecode.shuriken.execution.TaskExecutor; import ninja.bytecode.shuriken.execution.TaskExecutor;
import ninja.bytecode.shuriken.execution.TaskExecutor.TaskGroup; import ninja.bytecode.shuriken.execution.TaskExecutor.TaskGroup;
import ninja.bytecode.shuriken.format.F; import ninja.bytecode.shuriken.format.F;
@ -48,17 +49,18 @@ public class PackController implements IrisController
{ {
} }
public boolean isReady() public boolean isReady()
{ {
return ready; return ready;
} }
public void createTempCache(File jar) public void createTempCache(File jar)
{ {
try 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(); temp.mkdirs();
L.i("Iris Cache: " + temp.getAbsolutePath()); L.i("Iris Cache: " + temp.getAbsolutePath());
ZipFile zipFile = new ZipFile(jar); ZipFile zipFile = new ZipFile(jar);
@ -80,7 +82,7 @@ public class PackController implements IrisController
zipFile.close(); zipFile.close();
} }
catch(Throwable e) catch(Throwable e)
{ {
L.w(ChatColor.YELLOW + "Failed to cache internal resources. Did you reload Iris externally?"); 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(); gg.execute();
exf.close(); exf.close();
int m = 0; int m = 0;
for(GenObjectGroup i : getGenObjectGroups().v()) for(GenObjectGroup i : getGenObjectGroups().v())
{ {
m += i.size(); m += i.size();

View File

@ -284,7 +284,7 @@ public class GenObject
for(BlockVector i : g.k()) 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); s.put(VectorMath.rotate(from, to, i).toBlockVector(), mb);
} }

View File

@ -10,6 +10,7 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.BlockPopulator;
import net.md_5.bungee.api.ChatColor;
import ninja.bytecode.iris.Iris; import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.controller.PackController; import ninja.bytecode.iris.controller.PackController;
import ninja.bytecode.iris.controller.TimingsController; 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.iris.pack.IrisBiome;
import ninja.bytecode.shuriken.collections.GMap; import ninja.bytecode.shuriken.collections.GMap;
import ninja.bytecode.shuriken.collections.GSet; import ninja.bytecode.shuriken.collections.GSet;
import ninja.bytecode.shuriken.logging.L;
import ninja.bytecode.shuriken.math.M; import ninja.bytecode.shuriken.math.M;
public class GenObjectDecorator extends BlockPopulator public class GenObjectDecorator extends BlockPopulator
@ -37,7 +39,16 @@ public class GenObjectDecorator extends BlockPopulator
for(String j : i.getSchematicGroups().k()) 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); populationCache.put(i.getRealBiome(), gk);
@ -49,39 +60,39 @@ public class GenObjectDecorator extends BlockPopulator
{ {
Iris.getController(TimingsController.class).started("decor"); Iris.getController(TimingsController.class).started("decor");
GSet<Biome> hits = new GSet<>(); GSet<Biome> hits = new GSet<>();
for(int i = 0; i < Iris.settings.performance.decorationAccuracy; i++) for(int i = 0; i < Iris.settings.performance.decorationAccuracy; i++)
{ {
int x = (source.getX() << 4) + random.nextInt(16); int x = (source.getX() << 4) + random.nextInt(16);
int z = (source.getZ() << 4) + random.nextInt(16); int z = (source.getZ() << 4) + random.nextInt(16);
Biome biome = world.getBiome(x, z); Biome biome = world.getBiome(x, z);
if(hits.contains(biome)) if(hits.contains(biome))
{ {
continue; continue;
} }
IrisBiome ibiome = biomeMap.get(biome); IrisBiome ibiome = biomeMap.get(biome);
if(ibiome == null) if(ibiome == null)
{ {
continue; continue;
} }
GMap<GenObjectGroup, Double> objects = populationCache.get(biome); GMap<GenObjectGroup, Double> objects = populationCache.get(biome);
if(objects == null) if(objects == null)
{ {
continue; continue;
} }
hits.add(biome); hits.add(biome);
populate(world, random, source, biome, ibiome, objects); populate(world, random, source, biome, ibiome, objects);
} }
Iris.getController(TimingsController.class).stopped("decor"); Iris.getController(TimingsController.class).stopped("decor");
} }
private void populate(World world, Random random, Chunk source, Biome biome, IrisBiome ibiome, GMap<GenObjectGroup, Double> objects) private void populate(World world, Random random, Chunk source, Biome biome, IrisBiome ibiome, GMap<GenObjectGroup, Double> objects)
{ {
for(GenObjectGroup i : objects.k()) for(GenObjectGroup i : objects.k())
@ -92,12 +103,12 @@ public class GenObjectDecorator extends BlockPopulator
int z = (source.getZ() << 4) + random.nextInt(16); int z = (source.getZ() << 4) + random.nextInt(16);
Block b = world.getHighestBlockAt(x, z).getRelative(BlockFace.DOWN); Block b = world.getHighestBlockAt(x, z).getRelative(BlockFace.DOWN);
Material t = b.getType(); Material t = b.getType();
if(!t.isSolid() || !ibiome.isSurface(t)) if(!t.isSolid() || !ibiome.isSurface(t))
{ {
return; return;
} }
i.getSchematics().get(random.nextInt(i.getSchematics().size())).place(world, x, b.getY(), z); 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; return (int) chance;
} }
int floor = (int) Math.floor(chance); int floor = (int) Math.floor(chance);
if(chance - floor > 0 && M.r(chance - floor)) if(chance - floor > 0 && M.r(chance - floor))
{ {
floor++; floor++;
} }
return floor; return floor;
} }
} }

View File

@ -6,7 +6,7 @@
"LONG_GRASS:2=0.09" "LONG_GRASS:2=0.09"
], ],
"objects": [ "objects": [
"tree/serrulata/alt/medium=0.33", "tree/serrulata/bleeding/alt/medium=0.33",
"tree/serrulata/bleeding/large=0.42", "tree/serrulata/bleeding/large=0.42",
"tree/serrulata/bleeding/medium=0.42", "tree/serrulata/bleeding/medium=0.42",
"tree/serrulata/nobleed/medium=0.42", "tree/serrulata/nobleed/medium=0.42",