diff --git a/build.gradle b/build.gradle index 09d93cc4a..4fa37f3b3 100644 --- a/build.gradle +++ b/build.gradle @@ -32,7 +32,7 @@ plugins { } group 'com.volmit.iris' -version '1.7.9' +version '1.7.10' def apiVersion = '1.17' def name = getRootProject().getName() // See settings.gradle def main = 'com.volmit.iris.Iris' diff --git a/src/main/java/com/volmit/iris/engine/IrisEngine.java b/src/main/java/com/volmit/iris/engine/IrisEngine.java index 916a96008..2deecbe4a 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngine.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngine.java @@ -177,12 +177,21 @@ public class IrisEngine implements Engine { @Override public void hotload() { + hotloadSilently(); + Iris.callEvent(new IrisEngineHotloadEvent(this)); + } + + public void hotloadComplex() { + complex.close(); + complex = new IrisComplex(this); + } + + public void hotloadSilently() { getData().dump(); getData().clearLists(); getTarget().setDimension(getData().getDimensionLoader().load(getDimension().getLoadKey())); prehotload(); setupEngine(); - Iris.callEvent(new IrisEngineHotloadEvent(this)); } @Override diff --git a/src/main/java/com/volmit/iris/engine/framework/Engine.java b/src/main/java/com/volmit/iris/engine/framework/Engine.java index a10ae8e6d..87cb2ee4e 100644 --- a/src/main/java/com/volmit/iris/engine/framework/Engine.java +++ b/src/main/java/com/volmit/iris/engine/framework/Engine.java @@ -24,6 +24,7 @@ import com.volmit.iris.core.gui.components.Renderer; import com.volmit.iris.core.project.loader.IrisData; import com.volmit.iris.engine.IrisComplex; import com.volmit.iris.engine.data.cache.Cache; +import com.volmit.iris.engine.data.chunk.TerrainChunk; import com.volmit.iris.engine.mantle.EngineMantle; import com.volmit.iris.engine.object.basic.IrisColor; import com.volmit.iris.engine.object.basic.IrisPosition; @@ -66,6 +67,7 @@ import org.bukkit.block.Biome; import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; import org.bukkit.command.CommandSender; +import org.bukkit.generator.ChunkGenerator; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; @@ -86,6 +88,10 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat EngineMantle getMantle(); + void hotloadSilently(); + + void hotloadComplex(); + void recycle(); EngineActuator getTerrainActuator(); @@ -140,6 +146,12 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat @BlockCoordinates double modifyZ(double z); + @BlockCoordinates + default void generate(int x, int z, TerrainChunk tc, boolean multicore) throws WrongEngineBroException + { + generate(x, z, Hunk.view((ChunkGenerator.ChunkData) tc), Hunk.view((ChunkGenerator.BiomeGrid) tc), multicore); + } + @BlockCoordinates void generate(int x, int z, Hunk blocks, Hunk biomes, boolean multicore) throws WrongEngineBroException; diff --git a/src/main/java/com/volmit/iris/engine/object/dimensional/IrisDimension.java b/src/main/java/com/volmit/iris/engine/object/dimensional/IrisDimension.java index c11b89f92..0ca653a4f 100644 --- a/src/main/java/com/volmit/iris/engine/object/dimensional/IrisDimension.java +++ b/src/main/java/com/volmit/iris/engine/object/dimensional/IrisDimension.java @@ -92,6 +92,9 @@ public class IrisDimension extends IrisRegistrant { @Desc("Vertically split up the biome palettes with 3 air blocks in between to visualize them") private boolean explodeBiomePalettes = false; + @Desc("Studio Mode for testing different parts of the world") + private StudioMode studioMode = StudioMode.NORMAL; + @MinNumber(1) @MaxNumber(16) @Desc("Customize the palette height explosion") diff --git a/src/main/java/com/volmit/iris/engine/object/dimensional/StudioMode.java b/src/main/java/com/volmit/iris/engine/object/dimensional/StudioMode.java new file mode 100644 index 000000000..414893bea --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/object/dimensional/StudioMode.java @@ -0,0 +1,52 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.engine.object.dimensional; + +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.platform.BukkitChunkGenerator; +import com.volmit.iris.engine.platform.studio.generators.BiomeBuffetGenerator; + +import java.util.function.Consumer; + +@Desc("Represents a studio mode") +public enum StudioMode { + NORMAL(i -> i.setStudioGenerator(null)), + BIOME_BUFFET_1x1(i -> i.setStudioGenerator(new BiomeBuffetGenerator(i.getEngine(), 1))), + BIOME_BUFFET_3x3(i -> i.setStudioGenerator(new BiomeBuffetGenerator(i.getEngine(), 3))), + BIOME_BUFFET_5x5(i -> i.setStudioGenerator(new BiomeBuffetGenerator(i.getEngine(), 5))), + BIOME_BUFFET_9x9(i -> i.setStudioGenerator(new BiomeBuffetGenerator(i.getEngine(), 9))), + BIOME_BUFFET_18x18(i -> i.setStudioGenerator(new BiomeBuffetGenerator(i.getEngine(), 18))), + BIOME_BUFFET_36x36(i -> i.setStudioGenerator(new BiomeBuffetGenerator(i.getEngine(), 36))), + REGION_BUFFET(i -> i.setStudioGenerator(null)), + OBJECT_BUFFET(i -> i.setStudioGenerator(null)), + + ; + + private final Consumer injector; + + StudioMode(Consumer injector) + { + this.injector = injector; + } + + public void inject(BukkitChunkGenerator c) + { + injector.accept(c); + } +} diff --git a/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java b/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java index e9ae4e2d0..b1a4ae32d 100644 --- a/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java +++ b/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java @@ -28,6 +28,8 @@ import com.volmit.iris.engine.framework.EngineTarget; import com.volmit.iris.engine.framework.WrongEngineBroException; import com.volmit.iris.engine.object.common.IrisWorld; import com.volmit.iris.engine.object.dimensional.IrisDimension; +import com.volmit.iris.engine.object.dimensional.StudioMode; +import com.volmit.iris.engine.platform.studio.StudioGenerator; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.data.IrisBiomeStorage; import com.volmit.iris.util.hunk.Hunk; @@ -38,6 +40,7 @@ import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.Looper; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.Setter; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Material; @@ -72,10 +75,15 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun private final KList populators; private final ChronoLatch hotloadChecker; private final Looper hotloader; + private StudioMode lastMode; + + @Setter + private StudioGenerator studioGenerator; private final boolean studio; private long lastSeed; public BukkitChunkGenerator(IrisWorld world, boolean studio, File dataLocation, String dimensionKey) { + studioGenerator = null; populators = new KList<>(); lastSeed = world.seed(); loadLock = new Semaphore(LOAD_LOCKS); @@ -130,6 +138,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun } } + lastMode = StudioMode.NORMAL; engine = new IrisEngine(new EngineTarget(world, dimension, data), studio); populators.clear(); } @@ -156,7 +165,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun Hunk blocks = Hunk.view((ChunkData) tc); Hunk biomes = Hunk.view((BiomeGrid) tc); this.world.bind(world); - getEngine().generate(x * 16, z * 16, blocks, biomes, true); + getEngine().generate(x << 4, z << 4, blocks, biomes, true); Iris.debug("Regenerated " + x + " " + z); int t = 0; for(int i = getEngine().getHeight() >> 4; i >= 0; i--) @@ -271,11 +280,22 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun } loadLock.acquire(); + computeStudioGenerator(); TerrainChunk tc = TerrainChunk.create(world, biome); - Hunk blocks = Hunk.view((ChunkData) tc); - Hunk biomes = Hunk.view((BiomeGrid) tc); this.world.bind(world); - getEngine().generate(x * 16, z * 16, blocks, biomes, true); + + if(studioGenerator != null) + { + studioGenerator.generateChunk(getEngine(), tc, x, z); + } + + else + { + Hunk blocks = Hunk.view((ChunkData) tc); + Hunk biomes = Hunk.view((BiomeGrid) tc); + getEngine().generate(x << 4, z << 4, blocks, biomes, true); + } + ChunkData c = tc.getRaw(); Iris.debug("Generated " + x + " " + z); loadLock.release(); @@ -312,6 +332,14 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun } } + private void computeStudioGenerator() { + if(!getEngine().getDimension().getStudioMode().equals(lastMode)) + { + lastMode = getEngine().getDimension().getStudioMode(); + getEngine().getDimension().getStudioMode().inject(this); + } + } + @NotNull @Override public List getDefaultPopulators(@NotNull World world) { diff --git a/src/main/java/com/volmit/iris/engine/platform/studio/EnginedStudioGenerator.java b/src/main/java/com/volmit/iris/engine/platform/studio/EnginedStudioGenerator.java new file mode 100644 index 000000000..6d3278d16 --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/platform/studio/EnginedStudioGenerator.java @@ -0,0 +1,32 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.engine.platform.studio; + +import com.volmit.iris.engine.data.chunk.TerrainChunk; +import com.volmit.iris.engine.framework.Engine; +import com.volmit.iris.engine.framework.WrongEngineBroException; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public abstract class EnginedStudioGenerator implements StudioGenerator{ + private final Engine engine; + + @Override + public abstract void generateChunk(Engine engine, TerrainChunk tc, int x, int z) throws WrongEngineBroException; +} diff --git a/src/main/java/com/volmit/iris/engine/platform/studio/StudioGenerator.java b/src/main/java/com/volmit/iris/engine/platform/studio/StudioGenerator.java new file mode 100644 index 000000000..8cd6b3ae4 --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/platform/studio/StudioGenerator.java @@ -0,0 +1,27 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.engine.platform.studio; + +import com.volmit.iris.engine.data.chunk.TerrainChunk; +import com.volmit.iris.engine.framework.Engine; +import com.volmit.iris.engine.framework.WrongEngineBroException; + +public interface StudioGenerator { + void generateChunk(Engine engine, TerrainChunk tc, int x, int z) throws WrongEngineBroException; +} diff --git a/src/main/java/com/volmit/iris/engine/platform/studio/generators/BiomeBuffetGenerator.java b/src/main/java/com/volmit/iris/engine/platform/studio/generators/BiomeBuffetGenerator.java new file mode 100644 index 000000000..0823dc11e --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/platform/studio/generators/BiomeBuffetGenerator.java @@ -0,0 +1,67 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.engine.platform.studio.generators; + +import com.volmit.iris.engine.data.cache.Cache; +import com.volmit.iris.engine.data.chunk.TerrainChunk; +import com.volmit.iris.engine.framework.Engine; +import com.volmit.iris.engine.framework.WrongEngineBroException; +import com.volmit.iris.engine.object.biome.IrisBiome; +import com.volmit.iris.engine.platform.studio.EnginedStudioGenerator; +import org.bukkit.Material; +import org.bukkit.block.data.BlockData; + +import java.util.Objects; + +public class BiomeBuffetGenerator extends EnginedStudioGenerator { + private static final BlockData FLOOR = Material.BARRIER.createBlockData(); + private final IrisBiome[] biomes; + private final int width; + private final int biomeSize; + + public BiomeBuffetGenerator(Engine engine, int biomeSize) { + super(engine); + this.biomeSize = biomeSize; + biomes = engine.getDimension().getAllBiomes(engine).toArray(new IrisBiome[0]); + width = Math.max((int) Math.sqrt(biomes.length), 1); + } + + @Override + public void generateChunk(Engine engine, TerrainChunk tc, int x, int z) throws WrongEngineBroException { + int id = Cache.to1D(x/biomeSize, 0, z/biomeSize, width, 1); + + if(id >= 0 && id < biomes.length) + { + IrisBiome biome = biomes[id]; + String foc = engine.getDimension().getFocus(); + + if(!Objects.equals(foc, biome.getLoadKey())) + { + engine.getDimension().setFocus(biome.getLoadKey()); + engine.hotloadComplex(); + } + + engine.generate(x << 4, z << 4, tc, true); + } + + else { + tc.setRegion(0,0,0,16, 1, 16, FLOOR); + } + } +}