mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 02:36:59 +00:00
Engine fixes
This commit is contained in:
parent
708959a0c5
commit
0e86e942ce
@ -1,13 +0,0 @@
|
||||
package com.volmit.iris.v2.generator.compound;
|
||||
|
||||
import com.volmit.iris.v2.scaffold.engine.Engine;
|
||||
import org.bukkit.World;
|
||||
|
||||
public interface EngineCompound
|
||||
{
|
||||
public World getWorld();
|
||||
|
||||
public int getSize();
|
||||
|
||||
public Engine getEngine(int index);
|
||||
}
|
@ -1,9 +1,14 @@
|
||||
package com.volmit.iris.v2.scaffold.engine;
|
||||
|
||||
import com.volmit.iris.v2.scaffold.hunk.Hunk;
|
||||
import com.volmit.iris.v2.scaffold.hunk.io.BlockDataHunkIOAdapter;
|
||||
import com.volmit.iris.v2.scaffold.parallax.ParallaxAccess;
|
||||
import com.volmit.iris.manager.IrisDataManager;
|
||||
import com.volmit.iris.object.IrisDimension;
|
||||
import com.volmit.iris.v2.scaffold.parallel.MultiBurst;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
public interface Engine
|
||||
{
|
||||
@ -15,6 +20,8 @@ public interface Engine
|
||||
|
||||
public EngineFramework getFramework();
|
||||
|
||||
public void generate(int x, int z, Hunk<BlockData> blocks, Hunk<Biome> biomes);
|
||||
|
||||
public default IrisDataManager getData()
|
||||
{
|
||||
return getTarget().getData();
|
||||
|
@ -0,0 +1,166 @@
|
||||
package com.volmit.iris.v2.scaffold.engine;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.manager.IrisDataManager;
|
||||
import com.volmit.iris.object.IrisDimension;
|
||||
import com.volmit.iris.v2.generator.IrisEngineCompound;
|
||||
import com.volmit.iris.v2.scaffold.hunk.Hunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class EngineCompositeGenerator extends ChunkGenerator {
|
||||
private EngineCompound compound;
|
||||
private final AtomicBoolean initialized;
|
||||
private final String dimensionHint;
|
||||
private final boolean production;
|
||||
|
||||
public EngineCompositeGenerator() {
|
||||
this(null, true);
|
||||
}
|
||||
|
||||
public EngineCompositeGenerator(String hint, boolean production) {
|
||||
super();
|
||||
this.production = production;
|
||||
this.dimensionHint = hint;
|
||||
initialized = new AtomicBoolean(false);
|
||||
}
|
||||
|
||||
private synchronized IrisDimension getDimension(World world) {
|
||||
String hint = dimensionHint;
|
||||
IrisDimension dim = null;
|
||||
|
||||
if (hint == null) {
|
||||
File iris = new File(world.getWorldFolder(), "iris");
|
||||
|
||||
searching:
|
||||
for (File i : iris.listFiles()) {
|
||||
// Look for v1 location
|
||||
if (i.isDirectory() && i.getName().equals("dimensions")) {
|
||||
for (File j : i.listFiles()) {
|
||||
if (j.isFile() && j.getName().endsWith(".json")) {
|
||||
hint = j.getName().replaceAll("\\Q.json\\E", "");
|
||||
break searching;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Look for v2 location
|
||||
else if (i.isFile() && i.getName().equals("engine-metadata.json")) {
|
||||
EngineData metadata = EngineData.load(i);
|
||||
hint = metadata.getDimension();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hint == null) {
|
||||
throw new RuntimeException("Cannot find iris dimension data for world: " + world.getName() + "! FAILED");
|
||||
}
|
||||
|
||||
dim = Iris.globaldata.getDimensionLoader().load(hint);
|
||||
|
||||
if (dim == null) {
|
||||
throw new RuntimeException("Cannot find dimension: " + hint);
|
||||
}
|
||||
|
||||
if (production) {
|
||||
dim = new IrisDataManager(getDataFolder(world), true).getDimensionLoader().load(dim.getLoadKey());
|
||||
|
||||
if (dim == null) {
|
||||
throw new RuntimeException("Cannot find dimension: " + hint);
|
||||
}
|
||||
}
|
||||
|
||||
return dim;
|
||||
}
|
||||
|
||||
private synchronized void initialize(World world) {
|
||||
if (initialized.get()) {
|
||||
return;
|
||||
}
|
||||
|
||||
IrisDataManager data = production ? new IrisDataManager(getDataFolder(world)) : Iris.globaldata.copy();
|
||||
compound = new IrisEngineCompound(world, getDimension(world), data, Iris.getThreadCount());
|
||||
initialized.set(true);
|
||||
}
|
||||
|
||||
private File getDataFolder(World world) {
|
||||
return new File(world.getWorldFolder(), "iris/pack");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ChunkData generateChunkData(@NotNull World world, @NotNull Random ignored, int x, int z, @NotNull BiomeGrid biome) {
|
||||
initialize(world);
|
||||
ChunkData chunk = createChunkData(world);
|
||||
Hunk<BlockData> blocks = Hunk.view(chunk);
|
||||
Hunk<Biome> biomes = Hunk.view(biome);
|
||||
compound.generate(x * 16, z * 16, blocks, biomes);
|
||||
return chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSpawn(@NotNull World world, int x, int z) {
|
||||
return super.canSpawn(world, x, z);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<BlockPopulator> getDefaultPopulators(@NotNull World world) {
|
||||
return super.getDefaultPopulators(world);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Location getFixedSpawnLocation(@NotNull World world, @NotNull Random random) {
|
||||
return super.getFixedSpawnLocation(world, random);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isParallelCapable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerateCaves() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerateDecorations() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerateMobs() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerateStructures() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static EngineCompositeGenerator newStudioWorld(String dimension) {
|
||||
return new EngineCompositeGenerator(dimension, false);
|
||||
}
|
||||
|
||||
public static EngineCompositeGenerator newProductionWorld(String dimension) {
|
||||
return new EngineCompositeGenerator(dimension, true);
|
||||
}
|
||||
|
||||
public static EngineCompositeGenerator newProductionWorld() {
|
||||
return new EngineCompositeGenerator(null, true);
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.volmit.iris.v2.scaffold.engine;
|
||||
|
||||
import com.volmit.iris.v2.scaffold.engine.Engine;
|
||||
import com.volmit.iris.v2.scaffold.hunk.Hunk;
|
||||
import com.volmit.iris.v2.scaffold.parallel.MultiBurst;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
public interface EngineCompound
|
||||
{
|
||||
public void generate(int x, int z, Hunk<BlockData> blocks, Hunk<Biome> biomes);
|
||||
|
||||
public World getWorld();
|
||||
|
||||
public int getSize();
|
||||
|
||||
public Engine getEngine(int index);
|
||||
|
||||
public MultiBurst getBurster();
|
||||
|
||||
public EngineData getEngineMetadata();
|
||||
|
||||
public void saveEngineMetadata();
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.volmit.iris.v2.scaffold.engine;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.iris.util.IO;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
@Data
|
||||
public class EngineData {
|
||||
private String dimension;
|
||||
private String lastVersion;
|
||||
|
||||
public void save(File f)
|
||||
{
|
||||
try {
|
||||
f.getParentFile().mkdirs();
|
||||
IO.writeAll(f, new Gson().toJson(this));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static EngineData load(File f)
|
||||
{
|
||||
try
|
||||
{
|
||||
f.getParentFile().mkdirs();
|
||||
return new Gson().fromJson(IO.readAll(f), EngineData.class);
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return new EngineData();
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ import org.bukkit.block.data.BlockData;
|
||||
|
||||
public interface EngineFramework
|
||||
{
|
||||
public IrisEngine getEngine();
|
||||
public Engine getEngine();
|
||||
|
||||
public IrisComplex getComplex();
|
||||
|
||||
|
@ -3,6 +3,7 @@ package com.volmit.iris.v2.scaffold.engine;
|
||||
import com.volmit.iris.v2.scaffold.parallax.ParallaxWorld;
|
||||
import com.volmit.iris.manager.IrisDataManager;
|
||||
import com.volmit.iris.object.IrisDimension;
|
||||
import com.volmit.iris.v2.scaffold.parallel.MultiBurst;
|
||||
import lombok.Data;
|
||||
import org.bukkit.World;
|
||||
|
||||
@ -11,16 +12,27 @@ import java.io.File;
|
||||
@Data
|
||||
public class EngineTarget
|
||||
{
|
||||
private final MultiBurst burster;
|
||||
private final IrisDimension dimension;
|
||||
private final World world;
|
||||
private final int height;
|
||||
private final IrisDataManager data;
|
||||
private final ParallaxWorld parallaxWorld;
|
||||
private final boolean inverted;
|
||||
|
||||
public EngineTarget(World world, IrisDimension dimension, IrisDataManager data)
|
||||
public EngineTarget(World world, IrisDimension dimension, IrisDataManager data, int height, boolean inverted, int threads)
|
||||
{
|
||||
this.world = world;
|
||||
this.height = height;
|
||||
this.dimension = dimension;
|
||||
this.data = data;
|
||||
this.parallaxWorld = new ParallaxWorld(256, new File(world.getWorldFolder(), "iris/" + dimension.getLoadKey() + "/parallax"));
|
||||
this.inverted = inverted;
|
||||
this.burster = new MultiBurst(threads);
|
||||
}
|
||||
|
||||
public EngineTarget(World world, IrisDimension dimension, IrisDataManager data, int height, int threads)
|
||||
{
|
||||
this(world, dimension, data, height, false, threads);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user