From 37c46042c3a62fd3da006faa1941f4242c2b6358 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 8 Sep 2021 05:49:40 -0400 Subject: [PATCH 01/15] Engine stages --- src/main/java/com/volmit/iris/Iris.java | 2 + .../com/volmit/iris/engine/IrisEngine.java | 33 +++++++++--- .../volmit/iris/engine/framework/Engine.java | 4 ++ .../iris/engine/framework/EngineStage.java | 29 +++++++++++ .../iris/engine/object/IrisFluidBodies.java | 23 ++++----- .../volmit/iris/engine/object/IrisRiver.java | 51 +++++++++++++++++++ 6 files changed, 122 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/volmit/iris/engine/framework/EngineStage.java diff --git a/src/main/java/com/volmit/iris/Iris.java b/src/main/java/com/volmit/iris/Iris.java index c14a75d2e..980fed36b 100644 --- a/src/main/java/com/volmit/iris/Iris.java +++ b/src/main/java/com/volmit/iris/Iris.java @@ -25,7 +25,9 @@ import com.volmit.iris.core.link.MythicMobsLink; import com.volmit.iris.core.link.OraxenLink; import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.core.nms.INMS; +import com.volmit.iris.core.service.CommandSVC; import com.volmit.iris.core.service.StudioSVC; +import com.volmit.iris.core.service.WandSVC; import com.volmit.iris.engine.object.*; import com.volmit.iris.engine.platform.BukkitChunkGenerator; import com.volmit.iris.engine.platform.DummyChunkGenerator; diff --git a/src/main/java/com/volmit/iris/engine/IrisEngine.java b/src/main/java/com/volmit/iris/engine/IrisEngine.java index 96a686191..9cba53bb6 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngine.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngine.java @@ -37,6 +37,7 @@ import com.volmit.iris.engine.modifier.IrisPostModifier; import com.volmit.iris.engine.object.*; import com.volmit.iris.engine.scripting.EngineExecutionEnvironment; import com.volmit.iris.util.atomics.AtomicRollingSequence; +import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.context.IrisContext; import com.volmit.iris.util.documentation.BlockCoordinates; @@ -85,6 +86,7 @@ public class IrisEngine implements Engine { private boolean failing; private boolean closed; private int cacheId; + private final KList stages; private final AtomicRollingSequence wallClock; private final int art; private double maxBiomeObjectDensity; @@ -105,6 +107,7 @@ public class IrisEngine implements Engine { public IrisEngine(EngineTarget target, boolean studio) { this.studio = studio; this.target = target; + stages = new KList<>(); getEngineData(); verifySeed(); this.seedManager = new SeedManager(target.getWorld().getRawWorldSeed()); @@ -180,6 +183,7 @@ public class IrisEngine implements Engine { postModifier = new IrisPostModifier(this); caveModifier = new IrisCarveModifier(this); effects = new IrisEngineEffects(this); + setupStages(); J.a(this::computeBiomeMaxes); } catch (Throwable e) { Iris.error("FAILED TO SETUP ENGINE!"); @@ -189,6 +193,17 @@ public class IrisEngine implements Engine { Iris.debug("Engine Setup Complete " + getCacheID()); } + private void setupStages() { + registerStage((x, z, k, p, m) -> getMantle().generateMatter(x >> 4, z >> 4, m)); + registerStage((x, z, k, p, m) -> getTerrainActuator().actuate(x, z, k, m)); + registerStage((x, z, k, p, m) -> getBiomeActuator().actuate(x, z, p, m)); + registerStage((x, z, k, p, m) -> getDecorantActuator().actuate(x, z, k, m)); + registerStage((x, z, k, p, m) -> getCaveModifier().modify(x >> 4, z >> 4, k, m)); + registerStage((x, z, k, p, m) -> getPostModifier().modify(x, z, k, m)); + registerStage((x, z, k, p, m) -> getDepositModifier().modify(x, z, k, m)); + registerStage((x, z, K, p, m) -> getMantle().insertMatter(x >> 4, z >> 4, BlockData.class, K, m)); + } + @Override public void hotload() { hotloadSilently(); @@ -289,6 +304,11 @@ public class IrisEngine implements Engine { } } + @Override + public void registerStage(EngineStage stage) { + stages.add(stage); + } + @Override public int getBlockUpdatesPerSecond() { return buds.get(); @@ -434,15 +454,12 @@ public class IrisEngine implements Engine { } } } else { - getMantle().generateMatter(x >> 4, z >> 4, multicore); - getTerrainActuator().actuate(x, z, blocks, multicore); - getBiomeActuator().actuate(x, z, vbiomes, multicore); - getDecorantActuator().actuate(x, z, blocks, multicore); - getCaveModifier().modify(x >> 4, z >> 4, blocks, multicore); - getPostModifier().modify(x, z, blocks, multicore); - getDepositModifier().modify(x, z, blocks, multicore); - getMantle().insertMatter(x >> 4, z >> 4, BlockData.class, blocks, multicore); + for(EngineStage i : stages) + { + i.generate(x, z, blocks, vbiomes, multicore); + } } + getMetrics().getTotal().put(p.getMilliseconds()); generated.incrementAndGet(); recycle(); 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 cddb4e4a7..3b3968cc0 100644 --- a/src/main/java/com/volmit/iris/engine/framework/Engine.java +++ b/src/main/java/com/volmit/iris/engine/framework/Engine.java @@ -73,6 +73,10 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdater, Renderer, Hotloadable { + KList getStages(); + + public void registerStage(EngineStage stage); + IrisComplex getComplex(); int getBlockUpdatesPerSecond(); diff --git a/src/main/java/com/volmit/iris/engine/framework/EngineStage.java b/src/main/java/com/volmit/iris/engine/framework/EngineStage.java new file mode 100644 index 000000000..ab8f47610 --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/framework/EngineStage.java @@ -0,0 +1,29 @@ +/* + * 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.framework; + +import com.volmit.iris.util.documentation.BlockCoordinates; +import com.volmit.iris.util.hunk.Hunk; +import org.bukkit.block.Biome; +import org.bukkit.block.data.BlockData; + +public interface EngineStage { + @BlockCoordinates + void generate(int x, int z, Hunk blocks, Hunk biomes, boolean multicore); +} diff --git a/src/main/java/com/volmit/iris/engine/object/IrisFluidBodies.java b/src/main/java/com/volmit/iris/engine/object/IrisFluidBodies.java index 8efe74893..806c0e671 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisFluidBodies.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisFluidBodies.java @@ -49,18 +49,17 @@ public class IrisFluidBodies { @BlockCoordinates public void generate(MantleWriter writer, RNG rng, Engine engine, int x, int y, int z) { - //TODO: Impl -// if (rivers.isNotEmpty()) { -// for (IrisRiver i : rivers) { -// i.generate(writer, rng, engine, x, y, z); -// } -// } -// -// if (lakes.isNotEmpty()) { -// for (IrisLake i : lakes) { -// i.generate(writer, rng, engine, x, y, z); -// } -// } + if (rivers.isNotEmpty()) { + for (IrisRiver i : rivers) { + i.generate(writer, rng, engine, x, y, z); + } + } + + if (lakes.isNotEmpty()) { + for (IrisLake i : lakes) { + i.generate(writer, rng, engine, x, y, z); + } + } } public int getMaxRange(IrisData data) { diff --git a/src/main/java/com/volmit/iris/engine/object/IrisRiver.java b/src/main/java/com/volmit/iris/engine/object/IrisRiver.java index d2a81833f..454ba65a6 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisRiver.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisRiver.java @@ -22,7 +22,11 @@ import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.mantle.MantleWriter; import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.math.RNG; +import com.volmit.iris.util.matter.MatterFluidBody; +import com.volmit.iris.util.matter.slices.FluidBodyMatter; +import com.volmit.iris.util.noise.CNG; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -50,10 +54,57 @@ public class IrisRiver implements IRare { @Desc("Force this river to only generate the specified custom biome") private String customBiome = ""; + @Desc("The width style of this lake") + private IrisShapedGeneratorStyle widthStyle = new IrisShapedGeneratorStyle(NoiseStyle.PERLIN.style(), 5, 9); + + @Desc("The depth style of this lake") + private IrisShapedGeneratorStyle depthStyle = new IrisShapedGeneratorStyle(NoiseStyle.PERLIN.style(), 4, 7); + public int getSize(IrisData data) { return worm.getMaxDistance(); } public void generate(MantleWriter writer, RNG rng, Engine engine, int x, int y, int z) { + KList pos = getWorm().generate(rng, engine.getData(), writer, null, x, y, z, (at) -> { + }); + CNG dg = depthStyle.getGenerator().createNoCache(rng, engine.getData()); + CNG bw = widthStyle.getGenerator().createNoCache(rng, engine.getData()); + IrisPosition avg; + double ax = 0; + double ay = 0; + double az = 0; + double[] surfaces = new double[pos.size()]; + int i = 0; + + for (IrisPosition p : pos) { + surfaces[i] = engine.getComplex().getHeightStream().get(x, z); + ax += p.getX(); + ay += surfaces[i]; + az += p.getZ(); + i++; + } + + avg = new IrisPosition(ax / pos.size(), ay / pos.size(), az / pos.size()); + MatterFluidBody body = FluidBodyMatter.get(customBiome, false); + i = 0; + + for (IrisPosition p : pos) { + + double surface = surfaces[i]; + double depth = dg.fitDouble(depthStyle.getMin(), depthStyle.getMax(), p.getX(), p.getZ()) + (surface - avg.getY()); + double width = bw.fitDouble(widthStyle.getMin(), widthStyle.getMax(), p.getX(), p.getZ()); + + if (depth > 1) { + writer.setElipsoidFunction(p.getX(), avg.getY(), p.getZ(), width, depth, width, true, (xx, yy, zz) -> { + if (yy > avg.getY()) { + return null; + } + + return body; + }); + } + + i++; + } } } From 9421cd0b2dbe67f685a3f53960461c1b3d9fa058 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 8 Sep 2021 05:55:06 -0400 Subject: [PATCH 02/15] Engine tweaks for multi-stage ease of use --- .../com/volmit/iris/engine/IrisEngine.java | 47 +++++++------------ .../iris/engine/framework/EngineStage.java | 7 +++ 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/IrisEngine.java b/src/main/java/com/volmit/iris/engine/IrisEngine.java index 9cba53bb6..9b06734f2 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngine.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngine.java @@ -93,12 +93,6 @@ public class IrisEngine implements Engine { private double maxBiomeLayerDensity; private double maxBiomeDecoratorDensity; private IrisComplex complex; - private EngineActuator terrainActuator; - private EngineActuator decorantActuator; - private EngineActuator biomeActuator; - private EngineModifier depositModifier; - private EngineModifier caveModifier; - private EngineModifier postModifier; private final AtomicCache engineData = new AtomicCache<>(); private final AtomicBoolean cleaning; private final ChronoLatch cleanLatch; @@ -159,12 +153,8 @@ public class IrisEngine implements Engine { worldManager.close(); complex.close(); execution.close(); - terrainActuator.close(); - decorantActuator.close(); - biomeActuator.close(); - depositModifier.close(); - caveModifier.close(); - postModifier.close(); + stages.forEach(EngineStage::close); + stages.clear(); effects.close(); J.a(() -> new IrisProject(getData().getDataFolder()).updateWorkspace()); } @@ -176,12 +166,6 @@ public class IrisEngine implements Engine { worldManager = new IrisWorldManager(this); complex = new IrisComplex(this); execution = new IrisExecutionEnvironment(this); - terrainActuator = new IrisTerrainNormalActuator(this); - decorantActuator = new IrisDecorantActuator(this); - biomeActuator = new IrisBiomeActuator(this); - depositModifier = new IrisDepositModifier(this); - postModifier = new IrisPostModifier(this); - caveModifier = new IrisCarveModifier(this); effects = new IrisEngineEffects(this); setupStages(); J.a(this::computeBiomeMaxes); @@ -194,13 +178,20 @@ public class IrisEngine implements Engine { } private void setupStages() { + var terrain = new IrisTerrainNormalActuator(this); + var biome = new IrisBiomeActuator(this); + var decorant = new IrisDecorantActuator(this); + var cave = new IrisCarveModifier(this); + var post = new IrisPostModifier(this); + var deposit = new IrisDepositModifier(this); + registerStage((x, z, k, p, m) -> getMantle().generateMatter(x >> 4, z >> 4, m)); - registerStage((x, z, k, p, m) -> getTerrainActuator().actuate(x, z, k, m)); - registerStage((x, z, k, p, m) -> getBiomeActuator().actuate(x, z, p, m)); - registerStage((x, z, k, p, m) -> getDecorantActuator().actuate(x, z, k, m)); - registerStage((x, z, k, p, m) -> getCaveModifier().modify(x >> 4, z >> 4, k, m)); - registerStage((x, z, k, p, m) -> getPostModifier().modify(x, z, k, m)); - registerStage((x, z, k, p, m) -> getDepositModifier().modify(x, z, k, m)); + registerStage((x, z, k, p, m) -> terrain.actuate(x, z, k, m)); + registerStage((x, z, k, p, m) -> biome.actuate(x, z, p, m)); + registerStage((x, z, k, p, m) -> decorant.actuate(x, z, k, m)); + registerStage((x, z, k, p, m) -> cave.modify(x >> 4, z >> 4, k, m)); + registerStage((x, z, k, p, m) -> post.modify(x, z, k, m)); + registerStage((x, z, k, p, m) -> deposit.modify(x, z, k, m)); registerStage((x, z, K, p, m) -> getMantle().insertMatter(x >> 4, z >> 4, BlockData.class, K, m)); } @@ -376,12 +367,8 @@ public class IrisEngine implements Engine { getWorldManager().close(); getTarget().close(); saveEngineData(); - getTerrainActuator().close(); - getDecorantActuator().close(); - getBiomeActuator().close(); - getDepositModifier().close(); - getPostModifier().close(); - getCaveModifier().close(); + stages.forEach(EngineStage::close); + stages.clear(); getMantle().close(); getComplex().close(); getData().dump(); diff --git a/src/main/java/com/volmit/iris/engine/framework/EngineStage.java b/src/main/java/com/volmit/iris/engine/framework/EngineStage.java index ab8f47610..4b13499b8 100644 --- a/src/main/java/com/volmit/iris/engine/framework/EngineStage.java +++ b/src/main/java/com/volmit/iris/engine/framework/EngineStage.java @@ -26,4 +26,11 @@ import org.bukkit.block.data.BlockData; public interface EngineStage { @BlockCoordinates void generate(int x, int z, Hunk blocks, Hunk biomes, boolean multicore); + + default void close() { + if(this instanceof EngineComponent c) + { + c.close(); + } + } } From 8e874afbd5421bd3546a043880e7b1832467dd4d Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 8 Sep 2021 05:58:05 -0400 Subject: [PATCH 03/15] Bodies --- .../iris/engine/framework/SeedManager.java | 2 + .../engine/modifier/IrisBodyModifier.java | 65 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 src/main/java/com/volmit/iris/engine/modifier/IrisBodyModifier.java diff --git a/src/main/java/com/volmit/iris/engine/framework/SeedManager.java b/src/main/java/com/volmit/iris/engine/framework/SeedManager.java index a42b95b50..8bb3d0036 100644 --- a/src/main/java/com/volmit/iris/engine/framework/SeedManager.java +++ b/src/main/java/com/volmit/iris/engine/framework/SeedManager.java @@ -55,6 +55,7 @@ public class SeedManager private final long carve; private final long deposit; private final long post; + private final long bodies; public SeedManager(long seed) { @@ -77,6 +78,7 @@ public class SeedManager carve = of("carve"); deposit = of("deposit"); post = of("post"); + bodies = of("bodies"); } private long of(String name) diff --git a/src/main/java/com/volmit/iris/engine/modifier/IrisBodyModifier.java b/src/main/java/com/volmit/iris/engine/modifier/IrisBodyModifier.java new file mode 100644 index 000000000..cb36e0a93 --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/modifier/IrisBodyModifier.java @@ -0,0 +1,65 @@ +/* + * 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.modifier; + +import com.volmit.iris.engine.IrisEngine; +import com.volmit.iris.engine.actuator.IrisDecorantActuator; +import com.volmit.iris.engine.data.cache.Cache; +import com.volmit.iris.engine.framework.Engine; +import com.volmit.iris.engine.framework.EngineAssignedModifier; +import com.volmit.iris.engine.object.InferredType; +import com.volmit.iris.engine.object.IrisBiome; +import com.volmit.iris.engine.object.IrisDecorationPart; +import com.volmit.iris.engine.object.IrisDecorator; +import com.volmit.iris.engine.object.IrisPosition; +import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.collection.KMap; +import com.volmit.iris.util.data.B; +import com.volmit.iris.util.function.Consumer4; +import com.volmit.iris.util.hunk.Hunk; +import com.volmit.iris.util.mantle.Mantle; +import com.volmit.iris.util.mantle.MantleChunk; +import com.volmit.iris.util.math.M; +import com.volmit.iris.util.math.RNG; +import com.volmit.iris.util.matter.MatterCavern; +import com.volmit.iris.util.matter.slices.MarkerMatter; +import com.volmit.iris.util.scheduling.PrecisionStopwatch; +import lombok.Data; +import org.bukkit.Material; +import org.bukkit.block.data.BlockData; + +import java.util.Objects; +import java.util.function.Supplier; + +public class IrisBodyModifier extends EngineAssignedModifier { + private final RNG rng; + private final BlockData AIR = Material.CAVE_AIR.createBlockData(); + private final BlockData WATER = Material.WATER.createBlockData(); + private final BlockData LAVA = Material.LAVA.createBlockData(); + + public IrisBodyModifier(Engine engine) { + super(engine, "Bodies"); + rng = new RNG(getEngine().getSeedManager().getBodies()); + } + + @Override + public void onModify(int x, int z, Hunk output, boolean multicore) { + + } +} From bcc89d91f75444b7bead977db906edeb8ac7f3cb Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 8 Sep 2021 05:58:16 -0400 Subject: [PATCH 04/15] New stage system use dep for decorants --- .../com/volmit/iris/engine/modifier/IrisCarveModifier.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/modifier/IrisCarveModifier.java b/src/main/java/com/volmit/iris/engine/modifier/IrisCarveModifier.java index cd2eb9346..7b5eddf44 100644 --- a/src/main/java/com/volmit/iris/engine/modifier/IrisCarveModifier.java +++ b/src/main/java/com/volmit/iris/engine/modifier/IrisCarveModifier.java @@ -48,10 +48,12 @@ public class IrisCarveModifier extends EngineAssignedModifier { private final BlockData AIR = Material.CAVE_AIR.createBlockData(); private final BlockData WATER = Material.WATER.createBlockData(); private final BlockData LAVA = Material.LAVA.createBlockData(); + private final IrisDecorantActuator decorant; public IrisCarveModifier(Engine engine) { super(engine, "Carve"); rng = new RNG(getEngine().getSeedManager().getCarve()); + decorant = new IrisDecorantActuator(engine); } @Override @@ -206,12 +208,11 @@ public class IrisCarveModifier extends EngineAssignedModifier { biome.setInferredType(InferredType.CAVE); - IrisDecorantActuator actuator = (IrisDecorantActuator) ((IrisEngine) getEngine()).getDecorantActuator(); for (IrisDecorator i : biome.getDecorators()) { if (i.getPartOf().equals(IrisDecorationPart.NONE) && B.isSolid(output.get(rx, zone.getFloor() - 1, rz))) { - actuator.getSurfaceDecorator().decorate(rx, rz, xx, xx, xx, zz, zz, zz, output, biome, zone.getFloor() - 1, zone.airThickness()); + decorant.getSurfaceDecorator().decorate(rx, rz, xx, xx, xx, zz, zz, zz, output, biome, zone.getFloor() - 1, zone.airThickness()); } else if (i.getPartOf().equals(IrisDecorationPart.CEILING) && B.isSolid(output.get(rx, zone.getCeiling() + 1, rz))) { - actuator.getCeilingDecorator().decorate(rx, rz, xx, xx, xx, zz, zz, zz, output, biome, zone.getCeiling(), zone.airThickness()); + decorant.getCeilingDecorator().decorate(rx, rz, xx, xx, xx, zz, zz, zz, output, biome, zone.getCeiling(), zone.airThickness()); } } From 6c116e261de5514c0607570e906a21640fc1e82a Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 8 Sep 2021 06:07:41 -0400 Subject: [PATCH 05/15] Update adventure api --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 80ecdc864..20190c573 100644 --- a/build.gradle +++ b/build.gradle @@ -179,7 +179,7 @@ dependencies { implementation 'io.papermc:paperlib:1.0.5' implementation "net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT" implementation "net.kyori:adventure-platform-bukkit:4.0.0-SNAPSHOT" - implementation 'net.kyori:adventure-api:4.8.1' + implementation 'net.kyori:adventure-api:4.9.0' // Dynamically Loaded implementation 'io.timeandspace:smoothie-map:2.0.2' From 621155f06f746039b863460059e8a9e67253a10c Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 8 Sep 2021 06:34:34 -0400 Subject: [PATCH 06/15] Attempt to deal with adventure api failing now... until it gets fixed. --- build.gradle | 4 +- src/main/java/com/volmit/iris/Iris.java | 79 ++++++++++++++++++- .../com/volmit/iris/engine/IrisEngine.java | 5 +- .../volmit/iris/util/plugin/VolmitSender.java | 15 +++- 4 files changed, 98 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 20190c573..13ef9d925 100644 --- a/build.gradle +++ b/build.gradle @@ -177,9 +177,9 @@ dependencies { // Shaded implementation 'com.dfsek:Paralithic:0.4.0' implementation 'io.papermc:paperlib:1.0.5' - implementation "net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT" + implementation "net.kyori:adventure-text-minimessage:4.2.0-SNAPSHOT" implementation "net.kyori:adventure-platform-bukkit:4.0.0-SNAPSHOT" - implementation 'net.kyori:adventure-api:4.9.0' + implementation 'net.kyori:adventure-api:4.9.1' // Dynamically Loaded implementation 'io.timeandspace:smoothie-map:2.0.2' diff --git a/src/main/java/com/volmit/iris/Iris.java b/src/main/java/com/volmit/iris/Iris.java index 980fed36b..ef1cc5971 100644 --- a/src/main/java/com/volmit/iris/Iris.java +++ b/src/main/java/com/volmit/iris/Iris.java @@ -54,6 +54,8 @@ import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.Queue; import com.volmit.iris.util.scheduling.ShurikenQueue; import io.papermc.lib.PaperLib; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.key.Key; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.text.serializer.ComponentSerializer; import org.bukkit.Bukkit; @@ -67,12 +69,15 @@ import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.generator.ChunkGenerator; import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; import java.io.*; import java.lang.annotation.Annotation; import java.net.URL; import java.util.Date; import java.util.Map; +import java.util.UUID; +import java.util.function.Predicate; @SuppressWarnings("CanBeFinal") public class Iris extends VolmitPlugin implements Listener { @@ -103,7 +108,7 @@ public class Iris extends VolmitPlugin implements Listener { } private void enable() { - audiences = BukkitAudiences.create(this); + setupAudience(); sender = new VolmitSender(Bukkit.getConsoleSender()); sender.setTag(getTag()); instance = this; @@ -116,6 +121,78 @@ public class Iris extends VolmitPlugin implements Listener { services.values().forEach(this::registerListener); } + private void setupAudience() { + try + { + audiences = BukkitAudiences.create(this); + } + + catch(Throwable e) + { + e.printStackTrace(); + Audience dummy = new Audience() {}; + IrisSettings.get().getGeneral().setUseConsoleCustomColors(false); + IrisSettings.get().getGeneral().setUseCustomColorsIngame(false); + Iris.error("Failed to setup Adventure API... No custom colors :("); + audiences = new BukkitAudiences() { + @Override + public @NotNull Audience sender(@NotNull CommandSender sender) { + return dummy; + } + + @Override + public @NotNull Audience player(@NotNull Player player) { + return dummy; + } + + @Override + public @NotNull Audience filter(@NotNull Predicate filter) { + return dummy; + } + + @Override + public @NotNull Audience all() { + return dummy; + } + + @Override + public @NotNull Audience console() { + return dummy; + } + + @Override + public @NotNull Audience players() { + return dummy; + } + + @Override + public @NotNull Audience player(@NotNull UUID playerId) { + return dummy; + } + + @Override + public @NotNull Audience permission(@NotNull String permission) { + return dummy; + } + + @Override + public @NotNull Audience world(@NotNull Key world) { + return dummy; + } + + @Override + public @NotNull Audience server(@NotNull String serverName) { + return dummy; + } + + @Override + public void close() { + + } + }; + } + } + public void postShutdown(Runnable r) { postShutdown.add(r); } diff --git a/src/main/java/com/volmit/iris/engine/IrisEngine.java b/src/main/java/com/volmit/iris/engine/IrisEngine.java index 9b06734f2..beccb012d 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngine.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngine.java @@ -31,6 +31,7 @@ import com.volmit.iris.engine.actuator.IrisTerrainNormalActuator; import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.framework.*; import com.volmit.iris.engine.mantle.EngineMantle; +import com.volmit.iris.engine.modifier.IrisBodyModifier; import com.volmit.iris.engine.modifier.IrisCarveModifier; import com.volmit.iris.engine.modifier.IrisDepositModifier; import com.volmit.iris.engine.modifier.IrisPostModifier; @@ -184,12 +185,14 @@ public class IrisEngine implements Engine { var cave = new IrisCarveModifier(this); var post = new IrisPostModifier(this); var deposit = new IrisDepositModifier(this); + var bodies = new IrisBodyModifier(this); registerStage((x, z, k, p, m) -> getMantle().generateMatter(x >> 4, z >> 4, m)); registerStage((x, z, k, p, m) -> terrain.actuate(x, z, k, m)); registerStage((x, z, k, p, m) -> biome.actuate(x, z, p, m)); - registerStage((x, z, k, p, m) -> decorant.actuate(x, z, k, m)); registerStage((x, z, k, p, m) -> cave.modify(x >> 4, z >> 4, k, m)); + registerStage((x, z, k, p, m) -> bodies.modify(x >> 4, z >> 4, k, m)); + registerStage((x, z, k, p, m) -> decorant.actuate(x, z, k, m)); registerStage((x, z, k, p, m) -> post.modify(x, z, k, m)); registerStage((x, z, k, p, m) -> deposit.modify(x, z, k, m)); registerStage((x, z, K, p, m) -> getMantle().insertMatter(x >> 4, z >> 4, BlockData.class, K, m)); diff --git a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java index 5513c3c05..bb731cbbe 100644 --- a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java +++ b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java @@ -37,6 +37,7 @@ import net.kyori.adventure.title.Title; import org.bukkit.Server; import org.bukkit.Sound; import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionAttachment; @@ -315,8 +316,14 @@ public class VolmitSender implements CommandSender { return; } + if((!IrisSettings.get().getGeneral().isUseCustomColorsIngame() && s instanceof Player) || !IrisSettings.get().getGeneral().isUseConsoleCustomColors()) + { + s.sendMessage(C.translateAlternateColorCodes('&', getTag() + message)); + return; + } + if (message.contains("")) { - s.sendMessage(message.replaceAll("\\Q\\E", "")); + s.sendMessage(C.translateAlternateColorCodes('&', getTag() + message.replaceAll("\\Q\\E", ""))); return; } @@ -340,6 +347,12 @@ public class VolmitSender implements CommandSender { return; } + if((!IrisSettings.get().getGeneral().isUseCustomColorsIngame() && s instanceof Player) || !IrisSettings.get().getGeneral().isUseConsoleCustomColors()) + { + s.sendMessage(C.translateAlternateColorCodes('&', message)); + return; + } + if (message.contains("")) { s.sendMessage(message.replaceAll("\\Q\\E", "")); return; From 2a669618a26fdd56fbacc784f27d2978560c7c4a Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 8 Sep 2021 08:39:15 -0400 Subject: [PATCH 07/15] Oof --- src/main/java/com/volmit/iris/util/decree/DecreeSystem.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeSystem.java b/src/main/java/com/volmit/iris/util/decree/DecreeSystem.java index 09648640b..fd6c1590b 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeSystem.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeSystem.java @@ -72,6 +72,7 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter { default boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { if (!sender.hasPermission("iris.all")) { sender.sendMessage("You lack the Permission 'iris.all'"); + return true; } J.aBukkit(() -> { From effe93286a8051e7b3c2d8de57c47b0720a0cde6 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 8 Sep 2021 08:39:21 -0400 Subject: [PATCH 08/15] Fix block data issues --- .../java/com/volmit/iris/util/data/B.java | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/volmit/iris/util/data/B.java b/src/main/java/com/volmit/iris/util/data/B.java index 8ca8fd939..85f05c65c 100644 --- a/src/main/java/com/volmit/iris/util/data/B.java +++ b/src/main/java/com/volmit/iris/util/data/B.java @@ -32,6 +32,7 @@ import org.bukkit.block.data.type.PointedDripstone; import java.util.Arrays; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.stream.Collectors; @@ -344,6 +345,13 @@ public class B { public static boolean isFoliagePlantable(Material d) { return d.equals(Material.GRASS_BLOCK) || d.equals(Material.DIRT) + || d.equals(TALL_GRASS) + || d.equals(TALL_SEAGRASS) + || d.equals(LARGE_FERN) + || d.equals(SUNFLOWER) + || d.equals(PEONY) + || d.equals(LILAC) + || d.equals(ROSE_BUSH) || d.equals(Material.ROOTED_DIRT) || d.equals(Material.COARSE_DIRT) || d.equals(Material.PODZOL); @@ -426,7 +434,46 @@ public class B { } if (bx == null) { - bx = Bukkit.createBlockData(ix); + try + { + bx = Bukkit.createBlockData(ix.toLowerCase()); + } + + catch(Throwable e) + { + + } + } + + if(bx == null) + { + try + { + bx = Bukkit.createBlockData("minecraft:" + ix.toLowerCase()); + } + + catch(Throwable e) + { + + } + } + + if(bx == null) + { + try + { + bx = Material.valueOf(ix.toUpperCase()).createBlockData(); + } + + catch(Throwable e) + { + + } + } + + if(bx == null) + { + return null; } if (bx instanceof Leaves && IrisSettings.get().getGenerator().preventLeafDecay) { From e426172b1835aa6e095a12bf782afdacdb7a9d6d Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 8 Sep 2021 08:40:36 -0400 Subject: [PATCH 09/15] Perfection modifiers --- .../com/volmit/iris/engine/IrisEngine.java | 3 + .../modifier/IrisPerfectionModifier.java | 167 ++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 src/main/java/com/volmit/iris/engine/modifier/IrisPerfectionModifier.java diff --git a/src/main/java/com/volmit/iris/engine/IrisEngine.java b/src/main/java/com/volmit/iris/engine/IrisEngine.java index beccb012d..21660fccd 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngine.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngine.java @@ -34,6 +34,7 @@ import com.volmit.iris.engine.mantle.EngineMantle; import com.volmit.iris.engine.modifier.IrisBodyModifier; import com.volmit.iris.engine.modifier.IrisCarveModifier; import com.volmit.iris.engine.modifier.IrisDepositModifier; +import com.volmit.iris.engine.modifier.IrisPerfectionModifier; import com.volmit.iris.engine.modifier.IrisPostModifier; import com.volmit.iris.engine.object.*; import com.volmit.iris.engine.scripting.EngineExecutionEnvironment; @@ -186,6 +187,7 @@ public class IrisEngine implements Engine { var post = new IrisPostModifier(this); var deposit = new IrisDepositModifier(this); var bodies = new IrisBodyModifier(this); + var perfection = new IrisPerfectionModifier(this); registerStage((x, z, k, p, m) -> getMantle().generateMatter(x >> 4, z >> 4, m)); registerStage((x, z, k, p, m) -> terrain.actuate(x, z, k, m)); @@ -196,6 +198,7 @@ public class IrisEngine implements Engine { registerStage((x, z, k, p, m) -> post.modify(x, z, k, m)); registerStage((x, z, k, p, m) -> deposit.modify(x, z, k, m)); registerStage((x, z, K, p, m) -> getMantle().insertMatter(x >> 4, z >> 4, BlockData.class, K, m)); + registerStage((x, z, k, p, m) -> perfection.modify(x, z, k, m)); } @Override diff --git a/src/main/java/com/volmit/iris/engine/modifier/IrisPerfectionModifier.java b/src/main/java/com/volmit/iris/engine/modifier/IrisPerfectionModifier.java new file mode 100644 index 000000000..911cd7a79 --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/modifier/IrisPerfectionModifier.java @@ -0,0 +1,167 @@ +/* + * 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.modifier; + +import com.volmit.iris.Iris; +import com.volmit.iris.engine.framework.Engine; +import com.volmit.iris.engine.framework.EngineAssignedModifier; +import com.volmit.iris.engine.object.IrisBiome; +import com.volmit.iris.util.data.B; +import com.volmit.iris.util.data.HeightMap; +import com.volmit.iris.util.format.Form; +import com.volmit.iris.util.hunk.Hunk; +import com.volmit.iris.util.math.RNG; +import com.volmit.iris.util.scheduling.PrecisionStopwatch; +import net.minecraft.world.level.block.TallSeagrassBlock; +import org.bukkit.Material; +import org.bukkit.block.data.Bisected; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Levelled; +import org.bukkit.block.data.Waterlogged; +import org.bukkit.block.data.type.Slab; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; + +public class IrisPerfectionModifier extends EngineAssignedModifier { + private static final BlockData AIR = B.get("AIR"); + private static final BlockData WATER = B.get("WATER"); + private final RNG rng; + + public IrisPerfectionModifier(Engine engine) { + super(engine, "Perfection"); + rng = new RNG(getEngine().getSeedManager().getPost()); + } + + @Override + public void onModify(int x, int z, Hunk output, boolean multicore) { + PrecisionStopwatch p = PrecisionStopwatch.start(); + boolean changed = true; + int passes = 0; + int changes = 0; + List surfaces = new ArrayList<>(); + List ceilings = new ArrayList<>(); + + while(changed) + { + passes++; + changed = false; + for(int i = 0; i < 16; i++) + { + for(int j = 0; j < 16; j++) + { + surfaces.clear(); + ceilings.clear(); + int top = getHeight(output, i, j); + boolean inside = true; + surfaces.add(top); + + for(int k = top; k >= 0; k--) + { + BlockData b = output.get(i, k, j); + boolean now = b != null && !(B.isAir(b) || B.isFluid(b)); + + if(now != inside) + { + inside = now; + + if(inside) + { + surfaces.add(k); + } + + else + { + ceilings.add(k+1); + } + } + } + + for(int k : surfaces) + { + BlockData tip = output.get(i, k, j); + + if(tip == null) + { + continue; + } + + boolean remove = false; + boolean remove2 = false; + + if(B.isDecorant(tip)) + { + BlockData bel = output.get(i, k-1, j); + + if(bel == null) + { + remove = true; + } + + else if(!B.canPlaceOnto(tip.getMaterial(), bel.getMaterial())) + { + remove = true; + } + + else if(bel instanceof Bisected) + { + BlockData bb = output.get(i, k-2, j); + if(bb == null || !B.canPlaceOnto(bel.getMaterial(), bb.getMaterial())) + { + remove = true; + remove2 = true; + } + } + + if(remove) + { + changed = true; + changes++; + output.set(i, k, j, AIR); + + if(remove2) + { + changes++; + output.set(i, k-1, j, AIR); + } + } + } + } + } + } + } + + getEngine().getMetrics().getPerfection().put(p.getMilliseconds()); + } + + private int getHeight(Hunk output, int x, int z) { + for(int i = output.getHeight()-1; i >= 0; i--) + { + BlockData b = output.get(x, i, z); + + if(b != null && !B.isAir(b) && !B.isFluid(b)) + { + return i; + } + } + + return 0; + } +} From 1065079be62f0483915f4826c20318f76b250028 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 8 Sep 2021 08:40:48 -0400 Subject: [PATCH 10/15] Fix spawn radius issues --- .../engine/mantle/components/MantleJigsawComponent.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java b/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java index 44675c836..fcf206a31 100644 --- a/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java +++ b/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java @@ -18,6 +18,7 @@ package com.volmit.iris.engine.mantle.components; +import com.volmit.iris.Iris; import com.volmit.iris.engine.jigsaw.PlannedStructure; import com.volmit.iris.engine.mantle.EngineMantle; import com.volmit.iris.engine.mantle.IrisMantleComponent; @@ -110,6 +111,11 @@ public class MantleJigsawComponent extends IrisMantleComponent { } writer.setData(position.getX(), 0, position.getZ(), new IrisFeaturePositional(position.getX(), position.getZ(), structure.getFeature())); + + if(structure.getFeature().getEntitySpawners().isNotEmpty()) + { + Iris.info("Placed Structure MAIN SPAWN " + structure.getFeature().getEntitySpawners().get(0) + " @R " + structure.getFeature().getBlockRadius()); + } } new PlannedStructure(structure, position, rng).place(writer, getMantle(), post); From fc94fe30d0342a2d3871c4fde81aaa9f2ce51296 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 8 Sep 2021 08:40:55 -0400 Subject: [PATCH 11/15] Fixes for pieces --- .../iris/engine/jigsaw/PlannedStructure.java | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java b/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java index c39146439..0bc6cd63f 100644 --- a/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java +++ b/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java @@ -21,6 +21,7 @@ package com.volmit.iris.engine.jigsaw; import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap; import com.volmit.iris.Iris; import com.volmit.iris.core.loader.IrisData; +import com.volmit.iris.engine.data.cache.Cache; import com.volmit.iris.engine.object.*; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.interpolation.InterpolationMethod; @@ -101,6 +102,7 @@ public class PlannedStructure { int sz = (v.getD() / 2); int xx = i.getPosition().getX() + sx; int zz = i.getPosition().getZ() + sz; + RNG rngf = new RNG(Cache.key(xx, zz)); int offset = i.getPosition().getY() - startHeight; int height = 0; @@ -124,25 +126,7 @@ public class PlannedStructure { int h = vo.place(xx, height, zz, placer, options, rng, (b) -> e.set(b.getX(), b.getY(), b.getZ(), v.getLoadKey() + "@" + id), null, getData()); - for (IrisJigsawPieceConnector j : i.getAvailableConnectors()) { - if (j.getSpawnEntity() != null)// && h != -1) - { - IrisPosition p; - if (j.getEntityPosition() == null) { - p = i.getWorldPosition(j).add(new IrisPosition(j.getDirection().toVector().multiply(2))); - } else { - p = i.getWorldPosition(j).add(j.getEntityPosition()); - } - - if (options.getMode().equals(ObjectPlaceMode.PAINT) || options.isVacuum()) { - p.setY(placer.getHighest(xx, zz, getData()) + offset + (v.getH() / 2)); - } else { - p.setY(height); - } - } - } - - if (options.usesFeatures()) { + if (options.isVacuum()) { double a = Math.max(v.getW(), v.getD()); IrisFeature f = new IrisFeature(); f.setConvergeToHeight(h - (v.getH() >> 1) - 1); @@ -152,6 +136,17 @@ public class PlannedStructure { f.setStrength(1D); e.set(xx, 0, zz, new IrisFeaturePositional(xx, zz, f)); } + + if(options.getAddFeatures().isNotEmpty()) + { + for (IrisFeaturePotential j : options.getAddFeatures()) + { + if(rngf.nextInt(j.getRarity()) == 0) + { + e.set(xx, 0, zz, new IrisFeaturePositional(xx, zz, j.getZone())); + } + } + } } public void place(World world) { From e393442df970fca575e631fc1a0b452b7a6524fe Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 8 Sep 2021 08:41:07 -0400 Subject: [PATCH 12/15] Late engine start fix issues --- .../com/volmit/iris/core/tools/IrisCreator.java | 16 ++++++++++++++-- .../iris/engine/framework/EngineMetrics.java | 3 +++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/tools/IrisCreator.java b/src/main/java/com/volmit/iris/core/tools/IrisCreator.java index 6cc5e0aea..52cc30c97 100644 --- a/src/main/java/com/volmit/iris/core/tools/IrisCreator.java +++ b/src/main/java/com/volmit/iris/core/tools/IrisCreator.java @@ -40,6 +40,8 @@ import java.io.File; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Consumer; +import java.util.function.Supplier; /** * Makes it a lot easier to setup an engine, world, studio or whatever @@ -119,9 +121,19 @@ public class IrisCreator { J.a(() -> { int req = 441; + Supplier g = () -> { + try + { + return finalAccess1.getEngine().getGenerated(); + } - while (finalAccess1.getEngine().getGenerated() < req) { - double v = (double) finalAccess1.getEngine().getGenerated() / (double) req; + catch(Throwable e) + { + return 0; + } + }; + while (g.get() < req) { + double v = (double) g.get() / (double) req; if (sender.isPlayer()) { sender.sendProgress(v, "Generating"); diff --git a/src/main/java/com/volmit/iris/engine/framework/EngineMetrics.java b/src/main/java/com/volmit/iris/engine/framework/EngineMetrics.java index 3af80876c..fe9855497 100644 --- a/src/main/java/com/volmit/iris/engine/framework/EngineMetrics.java +++ b/src/main/java/com/volmit/iris/engine/framework/EngineMetrics.java @@ -31,6 +31,7 @@ public class EngineMetrics { private final AtomicRollingSequence parallax; private final AtomicRollingSequence parallaxInsert; private final AtomicRollingSequence post; + private final AtomicRollingSequence perfection; private final AtomicRollingSequence decoration; private final AtomicRollingSequence cave; private final AtomicRollingSequence ravine; @@ -40,6 +41,7 @@ public class EngineMetrics { this.total = new AtomicRollingSequence(mem); this.terrain = new AtomicRollingSequence(mem); this.biome = new AtomicRollingSequence(mem); + this.perfection = new AtomicRollingSequence(mem); this.parallax = new AtomicRollingSequence(mem); this.parallaxInsert = new AtomicRollingSequence(mem); this.post = new AtomicRollingSequence(mem); @@ -58,6 +60,7 @@ public class EngineMetrics { v.put("parallax", parallax.getAverage()); v.put("parallax.insert", parallaxInsert.getAverage()); v.put("post", post.getAverage()); + v.put("perfection", perfection.getAverage()); v.put("decoration", decoration.getAverage()); v.put("updates", updates.getAverage()); v.put("cave", cave.getAverage()); From 0c8c7157f68204673bfbb487b7f47f407d66247f Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 8 Sep 2021 08:41:15 -0400 Subject: [PATCH 13/15] Fix minimessage --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 13ef9d925..61aa39d6a 100644 --- a/build.gradle +++ b/build.gradle @@ -141,6 +141,7 @@ shadowJar { append("plugin.yml") relocate 'com.dfsek.paralithic', 'com.volmit.iris.util.paralithic' relocate 'io.papermc.lib', 'com.volmit.iris.util.paper' + relocate 'net.kyori', 'com.volmit.iris.util.kyori' dependencies { include(dependency('io.papermc:paperlib')) include(dependency('com.dfsek:Paralithic')) From d25633e213b4cbf3a3918514dc06b453f30709bb Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 8 Sep 2021 08:46:25 -0400 Subject: [PATCH 14/15] Cleanup --- src/main/java/com/volmit/iris/Iris.java | 969 +++++++++--------- .../com/volmit/iris/core/IrisSettings.java | 132 +-- .../iris/core/commands/CommandObject.java | 168 +-- .../iris/core/commands/CommandStudio.java | 35 +- .../volmit/iris/core/edit/BlockSignal.java | 50 +- .../volmit/iris/core/edit/DustRevealer.java | 36 +- .../volmit/iris/core/edit/JigsawEditor.java | 8 +- .../iris/core/events/IrisEngineEvent.java | 8 +- .../core/events/IrisEngineHotloadEvent.java | 8 +- .../iris/core/gui/NoiseExplorerGUI.java | 181 ++-- .../volmit/iris/core/gui/PregeneratorJob.java | 66 +- .../com/volmit/iris/core/gui/VisionGUI.java | 16 +- .../core/gui/components/IrisRenderer.java | 2 +- .../iris/core/gui/components/Renderer.java | 2 +- .../com/volmit/iris/core/loader/IrisData.java | 297 +++--- .../iris/core/loader/IrisRegistrant.java | 2 +- .../com/volmit/iris/core/nms/NMSVersion.java | 72 +- .../iris/core/nms/v17_1/NMSBinding17_1.java | 17 +- .../com/volmit/iris/core/pack/IrisPack.java | 158 +-- .../iris/core/pregenerator/PregenTask.java | 25 +- .../methods/SyndicatePregenMethod.java | 13 +- .../syndicate/SyndicateServer.java | 22 +- .../volmit/iris/core/project/IrisProject.java | 126 +-- .../iris/core/project/SchemaBuilder.java | 54 +- .../volmit/iris/core/service/BoardSVC.java | 2 +- .../iris/core/service/ConversionSVC.java | 13 +- .../volmit/iris/core/service/StudioSVC.java | 2 +- .../com/volmit/iris/core/service/TreeSVC.java | 16 +- .../com/volmit/iris/core/service/WandSVC.java | 404 ++++---- .../volmit/iris/core/tools/IrisCreator.java | 16 +- .../volmit/iris/core/wand/WandSelection.java | 2 +- .../com/volmit/iris/engine/IrisComplex.java | 48 +- .../com/volmit/iris/engine/IrisEngine.java | 45 +- .../volmit/iris/engine/IrisEngineMantle.java | 15 +- .../volmit/iris/engine/IrisWorldManager.java | 14 +- .../engine/actuator/IrisDecorantActuator.java | 6 +- .../volmit/iris/engine/data/cache/Cache.java | 8 +- .../engine/data/chunk/LinkedTerrainChunk.java | 2 +- .../engine/data/chunk/MCATerrainChunk.java | 13 +- .../iris/engine/data/chunk/TerrainChunk.java | 4 +- .../iris/engine/data/io/Deserializer.java | 7 +- .../iris/engine/data/io/Serializer.java | 7 +- .../engine/data/io/StringDeserializer.java | 8 +- .../iris/engine/data/io/StringSerializer.java | 8 +- .../volmit/iris/engine/framework/Engine.java | 25 +- .../iris/engine/framework/EngineData.java | 20 +- .../iris/engine/framework/EngineStage.java | 3 +- .../iris/engine/framework/EngineTarget.java | 2 +- .../iris/engine/framework/SeedManager.java | 18 +- .../iris/engine/jigsaw/PlannedPiece.java | 11 +- .../iris/engine/jigsaw/PlannedStructure.java | 35 +- .../iris/engine/mantle/EngineMantle.java | 6 +- .../iris/engine/mantle/MantleWriter.java | 113 +- .../components/MantleJigsawComponent.java | 11 +- .../components/MantleObjectComponent.java | 8 +- .../engine/modifier/IrisBodyModifier.java | 22 - .../engine/modifier/IrisCarveModifier.java | 7 +- .../modifier/IrisPerfectionModifier.java | 78 +- .../iris/engine/object/HeadlessWorld.java | 18 +- .../com/volmit/iris/engine/object/IRare.java | 4 +- .../engine/object/IrisAttributeModifier.java | 6 +- .../engine/object/IrisAxisRotationClamp.java | 7 +- .../volmit/iris/engine/object/IrisBiome.java | 244 ++--- .../iris/engine/object/IrisBiomeCustom.java | 10 +- .../object/IrisBiomeCustomParticle.java | 6 +- .../engine/object/IrisBiomeCustomSpawn.java | 6 +- .../engine/object/IrisBiomeGeneratorLink.java | 13 +- .../engine/object/IrisBiomePaletteLayer.java | 21 +- .../iris/engine/object/IrisBlockData.java | 115 ++- .../iris/engine/object/IrisBlockDrops.java | 7 +- .../iris/engine/object/IrisCavePlacer.java | 14 +- .../volmit/iris/engine/object/IrisColor.java | 48 +- .../volmit/iris/engine/object/IrisCompat.java | 216 ++-- .../object/IrisCompatabilityBlockFilter.java | 7 +- .../object/IrisCompatabilityItemFilter.java | 6 +- .../iris/engine/object/IrisDecorator.java | 31 +- .../engine/object/IrisDepositGenerator.java | 19 +- .../iris/engine/object/IrisDimension.java | 385 +++---- .../iris/engine/object/IrisDirection.java | 224 ++-- .../volmit/iris/engine/object/IrisEffect.java | 35 +- .../iris/engine/object/IrisElipsoid.java | 12 +- .../iris/engine/object/IrisEnchantment.java | 6 +- .../volmit/iris/engine/object/IrisEntity.java | 20 +- .../iris/engine/object/IrisEntitySpawn.java | 15 +- .../iris/engine/object/IrisFeature.java | 16 +- .../engine/object/IrisFeaturePositional.java | 13 +- .../iris/engine/object/IrisGenerator.java | 23 +- .../engine/object/IrisGeneratorStyle.java | 15 +- .../iris/engine/object/IrisInterpolator.java | 6 +- .../engine/object/IrisInterpolator3D.java | 6 +- .../object/IrisJigsawPieceConnector.java | 9 +- .../engine/object/IrisJigsawPlacement.java | 6 +- .../engine/object/IrisJigsawStructure.java | 7 +- .../volmit/iris/engine/object/IrisLake.java | 6 +- .../volmit/iris/engine/object/IrisLoot.java | 28 +- .../iris/engine/object/IrisLootReference.java | 11 +- .../engine/object/IrisMaterialPalette.java | 15 +- .../volmit/iris/engine/object/IrisMod.java | 7 +- .../engine/object/IrisModBiomeInjector.java | 6 +- .../engine/object/IrisModBiomeReplacer.java | 6 +- .../object/IrisModNoiseStyleReplacer.java | 6 +- .../IrisModObjectPlacementBiomeInjector.java | 6 +- .../IrisModObjectPlacementRegionInjector.java | 6 +- .../engine/object/IrisModObjectReplacer.java | 6 +- .../engine/object/IrisModRegionReplacer.java | 6 +- .../engine/object/IrisNoiseGenerator.java | 24 +- .../volmit/iris/engine/object/IrisObject.java | 112 +- .../iris/engine/object/IrisObjectLoot.java | 12 +- .../engine/object/IrisObjectPlacement.java | 54 +- .../iris/engine/object/IrisObjectReplace.java | 17 +- .../engine/object/IrisObjectRotation.java | 51 +- .../iris/engine/object/IrisObjectScale.java | 32 +- .../engine/object/IrisObjectTranslate.java | 6 +- .../iris/engine/object/IrisPotionEffect.java | 13 +- .../iris/engine/object/IrisPyramid.java | 11 +- .../iris/engine/object/IrisRareObject.java | 6 +- .../iris/engine/object/IrisRavinePlacer.java | 12 +- .../volmit/iris/engine/object/IrisRegion.java | 255 ++--- .../volmit/iris/engine/object/IrisRiver.java | 6 +- .../object/IrisShapedGeneratorStyle.java | 14 +- .../volmit/iris/engine/object/IrisSphere.java | 11 +- .../engine/object/IrisVillagerOverride.java | 6 +- .../iris/engine/object/IrisVillagerTrade.java | 7 +- .../volmit/iris/engine/object/IrisWorld.java | 12 +- .../engine/object/annotations/ArrayType.java | 2 +- .../engine/object/annotations/DependsOn.java | 4 +- .../iris/engine/object/annotations/Desc.java | 2 +- .../engine/object/annotations/MaxNumber.java | 4 +- .../engine/object/annotations/MinNumber.java | 4 +- .../RegistryListBiomeDownfallType.java | 2 +- .../annotations/RegistryListBlockType.java | 2 +- .../object/annotations/RegistryListFont.java | 2 +- .../annotations/RegistryListItemType.java | 2 +- .../annotations/RegistryListResource.java | 2 +- .../RegistryListSpecialEntity.java | 2 +- .../engine/object/annotations/Required.java | 2 +- .../engine/object/annotations/Snippet.java | 4 +- .../engine/platform/BukkitChunkGenerator.java | 17 +- .../iris/util/atomics/AtomicAverage.java | 2 +- .../util/atomics/AtomicRollingSequence.java | 8 +- .../volmit/iris/util/board/BoardManager.java | 8 +- .../volmit/iris/util/collection/KList.java | 49 +- .../volmit/iris/util/context/IrisContext.java | 2 +- .../java/com/volmit/iris/util/data/B.java | 40 +- .../com/volmit/iris/util/data/Cuboid.java | 130 +-- .../iris/util/data/CuboidException.java | 4 +- .../volmit/iris/util/data/DataPalette.java | 22 +- .../iris/util/data/IrisBiomeStorage.java | 7 +- .../volmit/iris/util/data/NibbleArray.java | 71 +- .../iris/util/data/VanillaBiomeMap.java | 64 +- .../volmit/iris/util/decree/DecreeSystem.java | 116 +-- .../decree/virtual/VirtualDecreeCommand.java | 26 +- .../java/com/volmit/iris/util/format/C.java | 213 ++-- .../com/volmit/iris/util/format/Form.java | 27 +- .../java/com/volmit/iris/util/hunk/Hunk.java | 438 ++++---- .../util/interpolation/IrisInterpolation.java | 4 +- .../iris/util/inventorygui/Element.java | 10 +- .../iris/util/inventorygui/RandomColor.java | 208 ++-- .../iris/util/inventorygui/UIElement.java | 12 +- .../iris/util/inventorygui/UIWindow.java | 24 +- .../volmit/iris/util/inventorygui/Window.java | 12 +- src/main/java/com/volmit/iris/util/io/IO.java | 124 ++- .../com/volmit/iris/util/json/JSONObject.java | 888 ++++++++-------- .../volmit/iris/util/json/JSONTokener.java | 39 +- .../com/volmit/iris/util/json/JSONWriter.java | 23 +- .../com/volmit/iris/util/mantle/Mantle.java | 77 +- .../volmit/iris/util/mantle/MantleChunk.java | 2 +- .../iris/util/mantle/TectonicPlate.java | 7 +- .../com/volmit/iris/util/math/Average.java | 2 +- .../volmit/iris/util/math/AxisAlignedBB.java | 16 +- .../volmit/iris/util/math/BlockPosition.java | 25 +- .../java/com/volmit/iris/util/math/CDou.java | 2 +- .../com/volmit/iris/util/math/Direction.java | 224 ++-- .../volmit/iris/util/math/IrisMathHelper.java | 30 +- .../java/com/volmit/iris/util/math/M.java | 12 +- .../com/volmit/iris/util/math/MathHelper.java | 32 +- .../java/com/volmit/iris/util/math/RNG.java | 2 +- .../iris/util/math/RollingSequence.java | 8 +- .../com/volmit/iris/util/math/Spiraler.java | 10 +- .../volmit/iris/util/math/VecMathUtil.java | 13 +- .../volmit/iris/util/matter/IrisMatter.java | 20 +- .../com/volmit/iris/util/matter/Matter.java | 99 +- .../iris/util/matter/slices/CavernMatter.java | 8 +- .../util/matter/slices/FluidBodyMatter.java | 8 +- .../iris/util/matter/slices/MarkerMatter.java | 2 +- .../iris/util/matter/slices/RawMatter.java | 4 +- .../iris/util/nbt/io/NBTInputStream.java | 57 +- .../iris/util/nbt/io/NBTOutputStream.java | 69 +- .../com/volmit/iris/util/nbt/io/NBTUtil.java | 8 +- .../com/volmit/iris/util/nbt/io/NamedTag.java | 16 +- .../volmit/iris/util/nbt/io/SNBTParser.java | 16 +- .../volmit/iris/util/nbt/io/SNBTWriter.java | 49 +- .../iris/util/nbt/io/StringPointer.java | 20 +- .../com/volmit/iris/util/nbt/mca/Chunk.java | 43 +- .../iris/util/nbt/mca/CompressionType.java | 18 +- .../com/volmit/iris/util/nbt/mca/MCAFile.java | 24 +- .../com/volmit/iris/util/nbt/mca/MCAUtil.java | 4 +- .../volmit/iris/util/nbt/mca/NBTWorld.java | 86 +- .../com/volmit/iris/util/nbt/mca/Section.java | 24 +- .../iris/util/nbt/mca/palette/IdMapper.java | 5 +- .../volmit/iris/util/nbt/mca/palette/Mth.java | 75 +- .../nbt/mca/palette/PalettedContainer.java | 5 +- .../volmit/iris/util/nbt/tag/CompoundTag.java | 14 +- .../com/volmit/iris/util/nbt/tag/ListTag.java | 44 +- .../com/volmit/iris/util/nbt/tag/Tag.java | 53 +- .../java/com/volmit/iris/util/network/DL.java | 7 +- .../java/com/volmit/iris/util/noise/CNG.java | 85 +- .../volmit/iris/util/noise/CloverNoise.java | 26 +- .../com/volmit/iris/util/noise/FastNoise.java | 393 ++++--- .../iris/util/noise/FastNoiseDouble.java | 391 ++++--- .../volmit/iris/util/parallel/MultiBurst.java | 9 +- .../iris/util/particle/ParticleType.java | 36 +- .../com/volmit/iris/util/plugin/Command.java | 4 +- .../com/volmit/iris/util/plugin/Control.java | 4 +- .../volmit/iris/util/plugin/Controller.java | 2 +- .../com/volmit/iris/util/plugin/Instance.java | 4 +- .../com/volmit/iris/util/plugin/Metrics.java | 183 ++-- .../volmit/iris/util/plugin/MetricsLite.java | 175 ++-- .../volmit/iris/util/plugin/Permission.java | 4 +- .../volmit/iris/util/plugin/VolmitPlugin.java | 5 +- .../volmit/iris/util/plugin/VolmitSender.java | 94 +- .../iris/util/scheduling/GroupedExecutor.java | 2 +- .../com/volmit/iris/util/scheduling/J.java | 7 +- .../util/scheduling/PrecisionStopwatch.java | 10 +- .../volmit/iris/util/scheduling/Queue.java | 18 +- .../iris/util/scheduling/TaskExecutor.java | 30 +- .../iris/util/scheduling/ThreadMonitor.java | 14 +- .../util/scheduling/jobs/JobCollection.java | 2 +- .../iris/util/scheduling/jobs/QueueJob.java | 2 +- .../iris/util/scheduling/jobs/SingleJob.java | 2 +- .../iris/util/stream/ProceduralStream.java | 34 +- .../stream/interpolation/Interpolated.java | 24 +- .../util/stream/utility/ProfiledStream.java | 90 +- 233 files changed, 5791 insertions(+), 5553 deletions(-) diff --git a/src/main/java/com/volmit/iris/Iris.java b/src/main/java/com/volmit/iris/Iris.java index ef1cc5971..158f0a948 100644 --- a/src/main/java/com/volmit/iris/Iris.java +++ b/src/main/java/com/volmit/iris/Iris.java @@ -25,10 +25,12 @@ import com.volmit.iris.core.link.MythicMobsLink; import com.volmit.iris.core.link.OraxenLink; import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.core.nms.INMS; -import com.volmit.iris.core.service.CommandSVC; import com.volmit.iris.core.service.StudioSVC; -import com.volmit.iris.core.service.WandSVC; -import com.volmit.iris.engine.object.*; +import com.volmit.iris.engine.object.IrisBiome; +import com.volmit.iris.engine.object.IrisBiomeCustom; +import com.volmit.iris.engine.object.IrisCompat; +import com.volmit.iris.engine.object.IrisDimension; +import com.volmit.iris.engine.object.IrisWorld; import com.volmit.iris.engine.platform.BukkitChunkGenerator; import com.volmit.iris.engine.platform.DummyChunkGenerator; import com.volmit.iris.util.collection.KList; @@ -71,7 +73,11 @@ import org.bukkit.generator.ChunkGenerator; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; -import java.io.*; +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; import java.lang.annotation.Annotation; import java.net.URL; import java.util.Date; @@ -81,175 +87,38 @@ import java.util.function.Predicate; @SuppressWarnings("CanBeFinal") public class Iris extends VolmitPlugin implements Listener { - private KMap, IrisService> services; + private static final Queue syncJobs = new ShurikenQueue<>(); public static Iris instance; public static BukkitAudiences audiences; public static MultiverseCoreLink linkMultiverseCore; public static OraxenLink linkOraxen; public static MythicMobsLink linkMythicMobs; - private static final Queue syncJobs = new ShurikenQueue<>(); public static IrisCompat compat; public static FileWatcher configWatcher; private static VolmitSender sender; + + static { + try { + InstanceState.updateInstanceId(); + } catch (Throwable ignored) { + + } + } + private final KList postShutdown = new KList<>(); - - public static VolmitSender getSender() { - return sender; - } - - private void preEnable() { - instance = this; - services = new KMap<>(); - initialize("com.volmit.iris.core.service").forEach((i) -> services.put((Class) i.getClass(), (IrisService) i)); - INMS.get(); - IO.delete(new File("iris")); - installDataPacks(); - fixShading(); - } - - private void enable() { - setupAudience(); - sender = new VolmitSender(Bukkit.getConsoleSender()); - sender.setTag(getTag()); - instance = this; - compat = IrisCompat.configured(getDataFile("compat.json")); - linkMultiverseCore = new MultiverseCoreLink(); - linkOraxen = new OraxenLink(); - linkMythicMobs = new MythicMobsLink(); - configWatcher = new FileWatcher(getDataFile("settings.json")); - services.values().forEach(IrisService::onEnable); - services.values().forEach(this::registerListener); - } - - private void setupAudience() { - try - { - audiences = BukkitAudiences.create(this); - } - - catch(Throwable e) - { - e.printStackTrace(); - Audience dummy = new Audience() {}; - IrisSettings.get().getGeneral().setUseConsoleCustomColors(false); - IrisSettings.get().getGeneral().setUseCustomColorsIngame(false); - Iris.error("Failed to setup Adventure API... No custom colors :("); - audiences = new BukkitAudiences() { - @Override - public @NotNull Audience sender(@NotNull CommandSender sender) { - return dummy; - } - - @Override - public @NotNull Audience player(@NotNull Player player) { - return dummy; - } - - @Override - public @NotNull Audience filter(@NotNull Predicate filter) { - return dummy; - } - - @Override - public @NotNull Audience all() { - return dummy; - } - - @Override - public @NotNull Audience console() { - return dummy; - } - - @Override - public @NotNull Audience players() { - return dummy; - } - - @Override - public @NotNull Audience player(@NotNull UUID playerId) { - return dummy; - } - - @Override - public @NotNull Audience permission(@NotNull String permission) { - return dummy; - } - - @Override - public @NotNull Audience world(@NotNull Key world) { - return dummy; - } - - @Override - public @NotNull Audience server(@NotNull String serverName) { - return dummy; - } - - @Override - public void close() { - - } - }; - } - } - - public void postShutdown(Runnable r) { - postShutdown.add(r); - } - - private void postEnable() { - J.a(() -> PaperLib.suggestPaper(this)); - J.a(() -> IO.delete(getTemp())); - J.a(this::bstats); - J.ar(this::checkConfigHotload, 60); - J.sr(this::tickQueue, 0); - J.s(this::setupPapi); - J.a(this::verifyDataPacksPost, 20); - splash(); - - if (IrisSettings.get().getGeneral().isAutoStartDefaultStudio()) { - Iris.info("Starting up auto Studio!"); - try { - Player r = new KList<>(getServer().getOnlinePlayers()).getRandom(); - Iris.service(StudioSVC.class).open(r != null ? new VolmitSender(r) : sender, 1337, IrisSettings.get().getGenerator().getDefaultWorldType(), (w) -> { - J.s(() -> { - for (Player i : getServer().getOnlinePlayers()) { - i.setGameMode(GameMode.SPECTATOR); - i.teleport(new Location(w, 0, 200, 0)); - } - }); - }); - } catch (IrisException e) { - e.printStackTrace(); - } - } - } - - @SuppressWarnings("unchecked") - public static T service(Class c) { - return (T) instance.services.get(c); - } + private KMap, IrisService> services; public Iris() { preEnable(); } - @SuppressWarnings("unchecked") - public void onEnable() { - enable(); - super.onEnable(); - Bukkit.getPluginManager().registerEvents(this, this); - J.s(this::postEnable); + public static VolmitSender getSender() { + return sender; } - public void onDisable() { - services.values().forEach(IrisService::onDisable); - Bukkit.getScheduler().cancelTasks(this); - HandlerList.unregisterAll((Plugin) this); - postShutdown.forEach(Runnable::run); - services.clear(); - MultiBurst.burst.close(); - super.onDisable(); + @SuppressWarnings("unchecked") + public static T service(Class c) { + return (T) instance.services.get(c); } public static void callEvent(Event e) { @@ -298,306 +167,16 @@ public class Iris extends VolmitPlugin implements Listener { return initialize(s, null); } - private void fixShading() { - ShadeFix.fix(ComponentSerializer.class); - } - - private void setupPapi() { - if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { - new IrisPapiExpansion().register(); - } - } - - public File getDatapacksFolder() { - if (!IrisSettings.get().getGeneral().forceMainWorld.isEmpty()) { - return new File(IrisSettings.get().getGeneral().forceMainWorld + "/datapacks"); - } - - File props = new File("server.properties"); - - if (props.exists()) { - try { - KList m = new KList<>(IO.readAll(props).split("\\Q\n\\E")); - - for (String i : m) { - if (i.trim().startsWith("level-name=")) { - return new File(i.trim().split("\\Q=\\E")[1] + "/datapacks"); - } - } - } catch (IOException e) { - Iris.reportError(e); - e.printStackTrace(); - } - } - - return null; - } - - public void installDataPacks() { - Iris.info("Checking Data Packs..."); - boolean reboot = false; - File packs = new File("plugins/Iris/packs"); - File dpacks = getDatapacksFolder(); - - if (dpacks == null) { - Iris.error("Cannot find the datapacks folder! Please try generating a default world first maybe? Is this a new server?"); - return; - } - - if (packs.exists()) { - for (File i : packs.listFiles()) { - if (i.isDirectory()) { - Iris.verbose("Checking Pack: " + i.getPath()); - IrisData data = IrisData.get(i); - File dims = new File(i, "dimensions"); - - if (dims.exists()) { - for (File j : dims.listFiles()) { - if (j.getName().endsWith(".json")) { - IrisDimension dim = data.getDimensionLoader().load(j.getName().split("\\Q.\\E")[0]); - - if (dim == null) { - continue; - } - - Iris.verbose(" Checking Dimension " + dim.getLoadFile().getPath()); - if (dim.installDataPack(() -> data, dpacks)) { - reboot = true; - } - } - } - } - } - } - } - - Iris.info("Data Packs Setup!"); - } - - @Override - public void start() { - - } - - @Override - public void stop() { - - } - - @Override - public String getTag(String subTag) { - return C.BOLD + "" + C.DARK_GRAY + "[" + C.BOLD + "" + C.IRIS + "Iris" + C.BOLD + C.DARK_GRAY + "]" + C.RESET + "" + C.GRAY + ": "; - } - - private void checkConfigHotload() { - if (configWatcher.checkModified()) { - IrisSettings.invalidate(); - IrisSettings.get(); - configWatcher.checkModified(); - Iris.info("Hotloaded settings.json "); - } - } - public static void sq(Runnable r) { synchronized (syncJobs) { syncJobs.queue(r); } } - private void tickQueue() { - synchronized (Iris.syncJobs) { - if (!Iris.syncJobs.hasNext()) { - return; - } - - long ms = M.ms(); - - while (Iris.syncJobs.hasNext() && M.ms() - ms < 25) { - try { - Iris.syncJobs.next().run(); - } catch (Throwable e) { - e.printStackTrace(); - Iris.reportError(e); - } - } - } - } - - private void bstats() { - if (IrisSettings.get().getGeneral().isPluginMetrics()) { - J.s(() -> new Metrics(Iris.instance, 8757)); - } - } - public static File getTemp() { return instance.getDataFolder("cache", "temp"); } - public void verifyDataPacksPost() { - File packs = new File("plugins/Iris/packs"); - File dpacks = getDatapacksFolder(); - - if (dpacks == null) { - Iris.error("Cannot find the datapacks folder! Please try generating a default world first maybe? Is this a new server?"); - return; - } - - boolean bad = false; - if (packs.exists()) { - for (File i : packs.listFiles()) { - if (i.isDirectory()) { - Iris.verbose("Checking Pack: " + i.getPath()); - IrisData data = IrisData.get(i); - File dims = new File(i, "dimensions"); - - if (dims.exists()) { - for (File j : dims.listFiles()) { - if (j.getName().endsWith(".json")) { - IrisDimension dim = data.getDimensionLoader().load(j.getName().split("\\Q.\\E")[0]); - - if (dim == null) { - Iris.error("Failed to load " + j.getPath()); - continue; - } - - if (!verifyDataPackInstalled(dim)) { - bad = true; - } - } - } - } - } - } - } - - if (bad && INMS.get().supportsDataPacks()) { - Iris.error("============================================================================"); - Iris.error(C.ITALIC + "You need to restart your server to properly generate custom biomes."); - Iris.error(C.ITALIC + "By continuing, Iris will use backup biomes in place of the custom biomes."); - Iris.error("----------------------------------------------------------------------------"); - Iris.error(C.UNDERLINE + "IT IS HIGHLY RECOMMENDED YOU RESTART THE SERVER BEFORE GENERATING!"); - Iris.error("============================================================================"); - - for (Player i : Bukkit.getOnlinePlayers()) { - if (i.isOp() || i.hasPermission("iris.all")) { - VolmitSender sender = new VolmitSender(i, getTag("WARNING")); - sender.sendMessage("There are some Iris Packs that have custom biomes in them"); - sender.sendMessage("You need to restart your server to use these packs."); - } - } - - J.sleep(3000); - } - } - - public boolean verifyDataPackInstalled(IrisDimension dimension) { - IrisData idm = IrisData.get(getDataFolder("packs", dimension.getLoadKey())); - KSet keys = new KSet<>(); - boolean warn = false; - - for (IrisBiome i : dimension.getAllBiomes(() -> idm)) { - if (i.isCustom()) { - for (IrisBiomeCustom j : i.getCustomDerivitives()) { - keys.add(dimension.getLoadKey() + ":" + j.getId()); - } - } - } - - if (!INMS.get().supportsDataPacks()) { - if (!keys.isEmpty()) { - Iris.warn("==================================================================================="); - Iris.warn("Pack " + dimension.getLoadKey() + " has " + keys.size() + " custom biome(s). "); - Iris.warn("Your server version does not yet support datapacks for iris."); - Iris.warn("The world will generate these biomes as backup biomes."); - Iris.warn("===================================================================================="); - } - - return true; - } - - for (String i : keys) { - Object o = INMS.get().getCustomBiomeBaseFor(i); - - if (o == null) { - Iris.warn("The Biome " + i + " is not registered on the server."); - warn = true; - } - } - - if (warn) { - Iris.error("The Pack " + dimension.getLoadKey() + " is INCAPABLE of generating custom biomes, restart your server before generating with this pack!"); - } - - return !warn; - } - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - return super.onCommand(sender, command, label, args); - } - - public void imsg(CommandSender s, String msg) { - s.sendMessage(C.IRIS + "[" + C.DARK_GRAY + "Iris" + C.IRIS + "]" + C.GRAY + ": " + msg); - } - - - @Override - public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) { - if (worldName.equals("test")) { - try { - throw new RuntimeException(); - } catch (Throwable e) { - Iris.info(e.getStackTrace()[1].getClassName()); - if (e.getStackTrace()[1].getClassName().contains("com.onarandombox.MultiverseCore")) { - Iris.debug("MVC Test detected, Quick! Send them the dummy!"); - return new DummyChunkGenerator(); - } - } - } - - IrisDimension dim; - if (id == null || id.isEmpty()) { - dim = IrisData.loadAnyDimension(IrisSettings.get().getGenerator().getDefaultWorldType()); - } else { - dim = IrisData.loadAnyDimension(id); - } - Iris.debug("Generator ID: " + id + " requested by bukkit/plugin"); - - if (dim == null) { - Iris.warn("Unable to find dimension type " + id + " Looking for online packs..."); - - service(StudioSVC.class).downloadSearch(new VolmitSender(Bukkit.getConsoleSender()), id, true); - dim = IrisData.loadAnyDimension(id); - - if (dim == null) { - throw new RuntimeException("Can't find dimension " + id + "!"); - } else { - Iris.info("Resolved missing dimension, proceeding with generation."); - } - } - - Iris.debug("Assuming IrisDimension: " + dim.getName()); - - IrisWorld w = IrisWorld.builder() - .name(worldName) - .seed(1337) - .environment(dim.getEnvironment()) - .worldFolder(new File(worldName)) - .minHeight(0) - .maxHeight(256) - .build(); - - Iris.debug("Generator Config: " + w.toString()); - - File ff = new File(w.worldFolder(), "iris/pack"); - if (!ff.exists() || ff.listFiles().length == 0) { - ff.mkdirs(); - service(StudioSVC.class).installIntoWorld(sender, dim.getLoadKey(), ff.getParentFile()); - } - - return new BukkitChunkGenerator(w, false, ff, dim.getLoadKey()); - } - public static void msg(String string) { try { sender.sendMessage(string); @@ -721,30 +300,6 @@ public class Iris extends VolmitPlugin implements Listener { msg(C.WHITE + string); } - public void splash() { - if (!IrisSettings.get().getGeneral().isSplashLogoStartup()) { - return; - } - - // @NoArgsConstructor - String padd = Form.repeat(" ", 8); - String padd2 = Form.repeat(" ", 4); - String[] info = {"", "", "", "", "", padd2 + C.IRIS + " Iris", padd2 + C.GRAY + " by " + "Volmit Software", padd2 + C.GRAY + " v" + C.IRIS + getDescription().getVersion(), - }; - String[] splash = {padd + C.GRAY + " @@@@@@@@@@@@@@" + C.DARK_GRAY + "@@@", padd + C.GRAY + " @@&&&&&&&&&" + C.DARK_GRAY + "&&&&&&" + C.IRIS + " .(((()))). ", padd + C.GRAY + "@@@&&&&&&&&" + C.DARK_GRAY + "&&&&&" + C.IRIS + " .((((((())))))). ", padd + C.GRAY + "@@@&&&&&" + C.DARK_GRAY + "&&&&&&&" + C.IRIS + " ((((((((())))))))) " + C.GRAY + " @", padd + C.GRAY + "@@@&&&&" + C.DARK_GRAY + "@@@@@&" + C.IRIS + " ((((((((-))))))))) " + C.GRAY + " @@", padd + C.GRAY + "@@@&&" + C.IRIS + " ((((((({ })))))))) " + C.GRAY + " &&@@@", padd + C.GRAY + "@@" + C.IRIS + " ((((((((-))))))))) " + C.DARK_GRAY + "&@@@@@" + C.GRAY + "&&&&@@@", padd + C.GRAY + "@" + C.IRIS + " ((((((((())))))))) " + C.DARK_GRAY + "&&&&&" + C.GRAY + "&&&&&&&@@@", padd + C.GRAY + "" + C.IRIS + " '((((((()))))))' " + C.DARK_GRAY + "&&&&&" + C.GRAY + "&&&&&&&&@@@", padd + C.GRAY + "" + C.IRIS + " '(((())))' " + C.DARK_GRAY + "&&&&&&&&" + C.GRAY + "&&&&&&&@@", padd + C.GRAY + " " + C.DARK_GRAY + "@@@" + C.GRAY + "@@@@@@@@@@@@@@" - }; - //@done - Iris.info("Server type & version: " + Bukkit.getVersion()); - Iris.info("Bukkit version: " + Bukkit.getBukkitVersion()); - Iris.info("Java version: " + getJavaVersion()); - Iris.info("Custom Biomes: " + INMS.get().countCustomBiomes()); - for (int i = 0; i < info.length; i++) { - splash[i] += info[i]; - } - - Iris.info("\n\n " + new KList<>(splash).toString("\n") + "\n"); - } - @SuppressWarnings("deprecation") public static void later(NastyRunnable object) { Bukkit.getScheduler().scheduleAsyncDelayedTask(instance, () -> @@ -781,10 +336,6 @@ public class Iris extends VolmitPlugin implements Listener { return Integer.parseInt(version); } - public boolean isMCA() { - return IrisSettings.get().getGenerator().isHeadlessPregeneration(); - } - public static void reportErrorChunk(int x, int z, Throwable e, String extra) { if (IrisSettings.get().getGeneral().isDebug()) { File f = instance.getDataFile("debug", "chunk-errors", "chunk." + x + "." + z + ".txt"); @@ -827,14 +378,6 @@ public class Iris extends VolmitPlugin implements Listener { } } - static { - try { - InstanceState.updateInstanceId(); - } catch (Throwable ignored) { - - } - } - public static void dump() { try { File fi = Iris.instance.getDataFile("dump", "td-" + new java.sql.Date(M.ms()) + ".txt"); @@ -860,4 +403,464 @@ public class Iris extends VolmitPlugin implements Listener { e.printStackTrace(); } } + + private void preEnable() { + instance = this; + services = new KMap<>(); + initialize("com.volmit.iris.core.service").forEach((i) -> services.put((Class) i.getClass(), (IrisService) i)); + INMS.get(); + IO.delete(new File("iris")); + installDataPacks(); + fixShading(); + } + + private void enable() { + setupAudience(); + sender = new VolmitSender(Bukkit.getConsoleSender()); + sender.setTag(getTag()); + instance = this; + compat = IrisCompat.configured(getDataFile("compat.json")); + linkMultiverseCore = new MultiverseCoreLink(); + linkOraxen = new OraxenLink(); + linkMythicMobs = new MythicMobsLink(); + configWatcher = new FileWatcher(getDataFile("settings.json")); + services.values().forEach(IrisService::onEnable); + services.values().forEach(this::registerListener); + } + + private void setupAudience() { + try { + audiences = BukkitAudiences.create(this); + } catch (Throwable e) { + e.printStackTrace(); + Audience dummy = new Audience() { + }; + IrisSettings.get().getGeneral().setUseConsoleCustomColors(false); + IrisSettings.get().getGeneral().setUseCustomColorsIngame(false); + Iris.error("Failed to setup Adventure API... No custom colors :("); + audiences = new BukkitAudiences() { + @Override + public @NotNull Audience sender(@NotNull CommandSender sender) { + return dummy; + } + + @Override + public @NotNull Audience player(@NotNull Player player) { + return dummy; + } + + @Override + public @NotNull Audience filter(@NotNull Predicate filter) { + return dummy; + } + + @Override + public @NotNull Audience all() { + return dummy; + } + + @Override + public @NotNull Audience console() { + return dummy; + } + + @Override + public @NotNull Audience players() { + return dummy; + } + + @Override + public @NotNull Audience player(@NotNull UUID playerId) { + return dummy; + } + + @Override + public @NotNull Audience permission(@NotNull String permission) { + return dummy; + } + + @Override + public @NotNull Audience world(@NotNull Key world) { + return dummy; + } + + @Override + public @NotNull Audience server(@NotNull String serverName) { + return dummy; + } + + @Override + public void close() { + + } + }; + } + } + + public void postShutdown(Runnable r) { + postShutdown.add(r); + } + + private void postEnable() { + J.a(() -> PaperLib.suggestPaper(this)); + J.a(() -> IO.delete(getTemp())); + J.a(this::bstats); + J.ar(this::checkConfigHotload, 60); + J.sr(this::tickQueue, 0); + J.s(this::setupPapi); + J.a(this::verifyDataPacksPost, 20); + splash(); + + if (IrisSettings.get().getGeneral().isAutoStartDefaultStudio()) { + Iris.info("Starting up auto Studio!"); + try { + Player r = new KList<>(getServer().getOnlinePlayers()).getRandom(); + Iris.service(StudioSVC.class).open(r != null ? new VolmitSender(r) : sender, 1337, IrisSettings.get().getGenerator().getDefaultWorldType(), (w) -> { + J.s(() -> { + for (Player i : getServer().getOnlinePlayers()) { + i.setGameMode(GameMode.SPECTATOR); + i.teleport(new Location(w, 0, 200, 0)); + } + }); + }); + } catch (IrisException e) { + e.printStackTrace(); + } + } + } + + @SuppressWarnings("unchecked") + public void onEnable() { + enable(); + super.onEnable(); + Bukkit.getPluginManager().registerEvents(this, this); + J.s(this::postEnable); + } + + public void onDisable() { + services.values().forEach(IrisService::onDisable); + Bukkit.getScheduler().cancelTasks(this); + HandlerList.unregisterAll((Plugin) this); + postShutdown.forEach(Runnable::run); + services.clear(); + MultiBurst.burst.close(); + super.onDisable(); + } + + private void fixShading() { + ShadeFix.fix(ComponentSerializer.class); + } + + private void setupPapi() { + if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { + new IrisPapiExpansion().register(); + } + } + + public File getDatapacksFolder() { + if (!IrisSettings.get().getGeneral().forceMainWorld.isEmpty()) { + return new File(IrisSettings.get().getGeneral().forceMainWorld + "/datapacks"); + } + + File props = new File("server.properties"); + + if (props.exists()) { + try { + KList m = new KList<>(IO.readAll(props).split("\\Q\n\\E")); + + for (String i : m) { + if (i.trim().startsWith("level-name=")) { + return new File(i.trim().split("\\Q=\\E")[1] + "/datapacks"); + } + } + } catch (IOException e) { + Iris.reportError(e); + e.printStackTrace(); + } + } + + return null; + } + + public void installDataPacks() { + Iris.info("Checking Data Packs..."); + boolean reboot = false; + File packs = new File("plugins/Iris/packs"); + File dpacks = getDatapacksFolder(); + + if (dpacks == null) { + Iris.error("Cannot find the datapacks folder! Please try generating a default world first maybe? Is this a new server?"); + return; + } + + if (packs.exists()) { + for (File i : packs.listFiles()) { + if (i.isDirectory()) { + Iris.verbose("Checking Pack: " + i.getPath()); + IrisData data = IrisData.get(i); + File dims = new File(i, "dimensions"); + + if (dims.exists()) { + for (File j : dims.listFiles()) { + if (j.getName().endsWith(".json")) { + IrisDimension dim = data.getDimensionLoader().load(j.getName().split("\\Q.\\E")[0]); + + if (dim == null) { + continue; + } + + Iris.verbose(" Checking Dimension " + dim.getLoadFile().getPath()); + if (dim.installDataPack(() -> data, dpacks)) { + reboot = true; + } + } + } + } + } + } + } + + Iris.info("Data Packs Setup!"); + } + + @Override + public void start() { + + } + + @Override + public void stop() { + + } + + @Override + public String getTag(String subTag) { + return C.BOLD + "" + C.DARK_GRAY + "[" + C.BOLD + "" + C.IRIS + "Iris" + C.BOLD + C.DARK_GRAY + "]" + C.RESET + "" + C.GRAY + ": "; + } + + private void checkConfigHotload() { + if (configWatcher.checkModified()) { + IrisSettings.invalidate(); + IrisSettings.get(); + configWatcher.checkModified(); + Iris.info("Hotloaded settings.json "); + } + } + + private void tickQueue() { + synchronized (Iris.syncJobs) { + if (!Iris.syncJobs.hasNext()) { + return; + } + + long ms = M.ms(); + + while (Iris.syncJobs.hasNext() && M.ms() - ms < 25) { + try { + Iris.syncJobs.next().run(); + } catch (Throwable e) { + e.printStackTrace(); + Iris.reportError(e); + } + } + } + } + + private void bstats() { + if (IrisSettings.get().getGeneral().isPluginMetrics()) { + J.s(() -> new Metrics(Iris.instance, 8757)); + } + } + + public void verifyDataPacksPost() { + File packs = new File("plugins/Iris/packs"); + File dpacks = getDatapacksFolder(); + + if (dpacks == null) { + Iris.error("Cannot find the datapacks folder! Please try generating a default world first maybe? Is this a new server?"); + return; + } + + boolean bad = false; + if (packs.exists()) { + for (File i : packs.listFiles()) { + if (i.isDirectory()) { + Iris.verbose("Checking Pack: " + i.getPath()); + IrisData data = IrisData.get(i); + File dims = new File(i, "dimensions"); + + if (dims.exists()) { + for (File j : dims.listFiles()) { + if (j.getName().endsWith(".json")) { + IrisDimension dim = data.getDimensionLoader().load(j.getName().split("\\Q.\\E")[0]); + + if (dim == null) { + Iris.error("Failed to load " + j.getPath()); + continue; + } + + if (!verifyDataPackInstalled(dim)) { + bad = true; + } + } + } + } + } + } + } + + if (bad && INMS.get().supportsDataPacks()) { + Iris.error("============================================================================"); + Iris.error(C.ITALIC + "You need to restart your server to properly generate custom biomes."); + Iris.error(C.ITALIC + "By continuing, Iris will use backup biomes in place of the custom biomes."); + Iris.error("----------------------------------------------------------------------------"); + Iris.error(C.UNDERLINE + "IT IS HIGHLY RECOMMENDED YOU RESTART THE SERVER BEFORE GENERATING!"); + Iris.error("============================================================================"); + + for (Player i : Bukkit.getOnlinePlayers()) { + if (i.isOp() || i.hasPermission("iris.all")) { + VolmitSender sender = new VolmitSender(i, getTag("WARNING")); + sender.sendMessage("There are some Iris Packs that have custom biomes in them"); + sender.sendMessage("You need to restart your server to use these packs."); + } + } + + J.sleep(3000); + } + } + + public boolean verifyDataPackInstalled(IrisDimension dimension) { + IrisData idm = IrisData.get(getDataFolder("packs", dimension.getLoadKey())); + KSet keys = new KSet<>(); + boolean warn = false; + + for (IrisBiome i : dimension.getAllBiomes(() -> idm)) { + if (i.isCustom()) { + for (IrisBiomeCustom j : i.getCustomDerivitives()) { + keys.add(dimension.getLoadKey() + ":" + j.getId()); + } + } + } + + if (!INMS.get().supportsDataPacks()) { + if (!keys.isEmpty()) { + Iris.warn("==================================================================================="); + Iris.warn("Pack " + dimension.getLoadKey() + " has " + keys.size() + " custom biome(s). "); + Iris.warn("Your server version does not yet support datapacks for iris."); + Iris.warn("The world will generate these biomes as backup biomes."); + Iris.warn("===================================================================================="); + } + + return true; + } + + for (String i : keys) { + Object o = INMS.get().getCustomBiomeBaseFor(i); + + if (o == null) { + Iris.warn("The Biome " + i + " is not registered on the server."); + warn = true; + } + } + + if (warn) { + Iris.error("The Pack " + dimension.getLoadKey() + " is INCAPABLE of generating custom biomes, restart your server before generating with this pack!"); + } + + return !warn; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + return super.onCommand(sender, command, label, args); + } + + public void imsg(CommandSender s, String msg) { + s.sendMessage(C.IRIS + "[" + C.DARK_GRAY + "Iris" + C.IRIS + "]" + C.GRAY + ": " + msg); + } + + @Override + public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) { + if (worldName.equals("test")) { + try { + throw new RuntimeException(); + } catch (Throwable e) { + Iris.info(e.getStackTrace()[1].getClassName()); + if (e.getStackTrace()[1].getClassName().contains("com.onarandombox.MultiverseCore")) { + Iris.debug("MVC Test detected, Quick! Send them the dummy!"); + return new DummyChunkGenerator(); + } + } + } + + IrisDimension dim; + if (id == null || id.isEmpty()) { + dim = IrisData.loadAnyDimension(IrisSettings.get().getGenerator().getDefaultWorldType()); + } else { + dim = IrisData.loadAnyDimension(id); + } + Iris.debug("Generator ID: " + id + " requested by bukkit/plugin"); + + if (dim == null) { + Iris.warn("Unable to find dimension type " + id + " Looking for online packs..."); + + service(StudioSVC.class).downloadSearch(new VolmitSender(Bukkit.getConsoleSender()), id, true); + dim = IrisData.loadAnyDimension(id); + + if (dim == null) { + throw new RuntimeException("Can't find dimension " + id + "!"); + } else { + Iris.info("Resolved missing dimension, proceeding with generation."); + } + } + + Iris.debug("Assuming IrisDimension: " + dim.getName()); + + IrisWorld w = IrisWorld.builder() + .name(worldName) + .seed(1337) + .environment(dim.getEnvironment()) + .worldFolder(new File(worldName)) + .minHeight(0) + .maxHeight(256) + .build(); + + Iris.debug("Generator Config: " + w.toString()); + + File ff = new File(w.worldFolder(), "iris/pack"); + if (!ff.exists() || ff.listFiles().length == 0) { + ff.mkdirs(); + service(StudioSVC.class).installIntoWorld(sender, dim.getLoadKey(), ff.getParentFile()); + } + + return new BukkitChunkGenerator(w, false, ff, dim.getLoadKey()); + } + + public void splash() { + if (!IrisSettings.get().getGeneral().isSplashLogoStartup()) { + return; + } + + // @NoArgsConstructor + String padd = Form.repeat(" ", 8); + String padd2 = Form.repeat(" ", 4); + String[] info = {"", "", "", "", "", padd2 + C.IRIS + " Iris", padd2 + C.GRAY + " by " + "Volmit Software", padd2 + C.GRAY + " v" + C.IRIS + getDescription().getVersion(), + }; + String[] splash = {padd + C.GRAY + " @@@@@@@@@@@@@@" + C.DARK_GRAY + "@@@", padd + C.GRAY + " @@&&&&&&&&&" + C.DARK_GRAY + "&&&&&&" + C.IRIS + " .(((()))). ", padd + C.GRAY + "@@@&&&&&&&&" + C.DARK_GRAY + "&&&&&" + C.IRIS + " .((((((())))))). ", padd + C.GRAY + "@@@&&&&&" + C.DARK_GRAY + "&&&&&&&" + C.IRIS + " ((((((((())))))))) " + C.GRAY + " @", padd + C.GRAY + "@@@&&&&" + C.DARK_GRAY + "@@@@@&" + C.IRIS + " ((((((((-))))))))) " + C.GRAY + " @@", padd + C.GRAY + "@@@&&" + C.IRIS + " ((((((({ })))))))) " + C.GRAY + " &&@@@", padd + C.GRAY + "@@" + C.IRIS + " ((((((((-))))))))) " + C.DARK_GRAY + "&@@@@@" + C.GRAY + "&&&&@@@", padd + C.GRAY + "@" + C.IRIS + " ((((((((())))))))) " + C.DARK_GRAY + "&&&&&" + C.GRAY + "&&&&&&&@@@", padd + C.GRAY + "" + C.IRIS + " '((((((()))))))' " + C.DARK_GRAY + "&&&&&" + C.GRAY + "&&&&&&&&@@@", padd + C.GRAY + "" + C.IRIS + " '(((())))' " + C.DARK_GRAY + "&&&&&&&&" + C.GRAY + "&&&&&&&@@", padd + C.GRAY + " " + C.DARK_GRAY + "@@@" + C.GRAY + "@@@@@@@@@@@@@@" + }; + //@done + Iris.info("Server type & version: " + Bukkit.getVersion()); + Iris.info("Bukkit version: " + Bukkit.getBukkitVersion()); + Iris.info("Java version: " + getJavaVersion()); + Iris.info("Custom Biomes: " + INMS.get().countCustomBiomes()); + for (int i = 0; i < info.length; i++) { + splash[i] += info[i]; + } + + Iris.info("\n\n " + new KList<>(splash).toString("\n") + "\n"); + } + + public boolean isMCA() { + return IrisSettings.get().getGenerator().isHeadlessPregeneration(); + } } diff --git a/src/main/java/com/volmit/iris/core/IrisSettings.java b/src/main/java/com/volmit/iris/core/IrisSettings.java index b885450a3..7e85dc155 100644 --- a/src/main/java/com/volmit/iris/core/IrisSettings.java +++ b/src/main/java/com/volmit/iris/core/IrisSettings.java @@ -33,6 +33,7 @@ import java.io.IOException; @Data public class IrisSettings { public static transient IrisSettings settings; + public int configurationVersion = 3; private IrisSettingsCache cache = new IrisSettingsCache(); private IrisSettingsConcurrency concurrency = new IrisSettingsConcurrency(); private IrisSettingsParallax parallax = new IrisSettingsParallax(); @@ -40,7 +41,71 @@ public class IrisSettings { private IrisSettingsGUI gui = new IrisSettingsGUI(); private IrisSettingsGenerator generator = new IrisSettingsGenerator(); private IrisSettingsStudio studio = new IrisSettingsStudio(); - public int configurationVersion = 3; + + public static int getPriority(int c) { + return Math.max(Math.min(c, Thread.MAX_PRIORITY), Thread.MIN_PRIORITY); + } + + public static int getThreadCount(int c) { + if (c < 2 && c >= 0) { + return 2; + } + + return Math.max(2, c < 0 ? Runtime.getRuntime().availableProcessors() / -c : c); + } + + public static IrisSettings get() { + if (settings != null) { + return settings; + } + + IrisSettings defaults = new IrisSettings(); + JSONObject def = new JSONObject(new Gson().toJson(defaults)); + if (settings == null) { + settings = new IrisSettings(); + + File s = Iris.instance.getDataFile("settings.json"); + + if (!s.exists()) { + try { + IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4)); + } catch (JSONException | IOException e) { + e.printStackTrace(); + Iris.reportError(e); + } + } else { + try { + String ss = IO.readAll(s); + settings = new Gson().fromJson(ss, IrisSettings.class); + try { + IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4)); + } catch (IOException e) { + e.printStackTrace(); + } + } catch (Throwable ee) { + Iris.reportError(ee); + Iris.error("Configuration Error in settings.json! " + ee.getClass().getSimpleName() + ": " + ee.getMessage()); + } + } + + if (!s.exists()) { + try { + IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4)); + } catch (JSONException | IOException e) { + Iris.reportError(e); + e.printStackTrace(); + } + } + } + + return settings; + } + + public static void invalidate() { + synchronized (settings) { + settings = null; + } + } public boolean isStudio() { return getStudio().isStudio(); @@ -55,18 +120,6 @@ public class IrisSettings { return getParallax().getParallaxRegionEvictionMS(); } - public static int getPriority(int c) { - return Math.max(Math.min(c, Thread.MAX_PRIORITY), Thread.MIN_PRIORITY); - } - - public static int getThreadCount(int c) { - if (c < 2 && c >= 0) { - return 2; - } - - return Math.max(2, c < 0 ? Runtime.getRuntime().availableProcessors() / -c : c); - } - public void forceSave() { File s = Iris.instance.getDataFile("settings.json"); @@ -138,57 +191,4 @@ public class IrisSettings { public boolean openVSCode = true; public boolean disableTimeAndWeather = true; } - - public static IrisSettings get() { - if (settings != null) { - return settings; - } - - IrisSettings defaults = new IrisSettings(); - JSONObject def = new JSONObject(new Gson().toJson(defaults)); - if (settings == null) { - settings = new IrisSettings(); - - File s = Iris.instance.getDataFile("settings.json"); - - if (!s.exists()) { - try { - IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4)); - } catch (JSONException | IOException e) { - e.printStackTrace(); - Iris.reportError(e); - } - } else { - try { - String ss = IO.readAll(s); - settings = new Gson().fromJson(ss, IrisSettings.class); - try { - IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4)); - } catch (IOException e) { - e.printStackTrace(); - } - } catch (Throwable ee) { - Iris.reportError(ee); - Iris.error("Configuration Error in settings.json! " + ee.getClass().getSimpleName() + ": " + ee.getMessage()); - } - } - - if (!s.exists()) { - try { - IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4)); - } catch (JSONException | IOException e) { - Iris.reportError(e); - e.printStackTrace(); - } - } - } - - return settings; - } - - public static void invalidate() { - synchronized (settings) { - settings = null; - } - } } diff --git a/src/main/java/com/volmit/iris/core/commands/CommandObject.java b/src/main/java/com/volmit/iris/core/commands/CommandObject.java index 06384b16f..040374c23 100644 --- a/src/main/java/com/volmit/iris/core/commands/CommandObject.java +++ b/src/main/java/com/volmit/iris/core/commands/CommandObject.java @@ -5,7 +5,13 @@ import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.core.service.ObjectSVC; import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.service.WandSVC; -import com.volmit.iris.engine.object.*; +import com.volmit.iris.engine.object.IObjectPlacer; +import com.volmit.iris.engine.object.IrisDimension; +import com.volmit.iris.engine.object.IrisObject; +import com.volmit.iris.engine.object.IrisObjectPlacement; +import com.volmit.iris.engine.object.IrisObjectPlacementScaleInterpolator; +import com.volmit.iris.engine.object.IrisObjectRotation; +import com.volmit.iris.engine.object.TileData; import com.volmit.iris.util.data.Cuboid; import com.volmit.iris.util.decree.DecreeExecutor; import com.volmit.iris.util.decree.DecreeOrigin; @@ -16,7 +22,12 @@ import com.volmit.iris.util.format.C; import com.volmit.iris.util.math.Direction; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.scheduling.Queue; -import org.bukkit.*; +import org.bukkit.ChatColor; +import org.bukkit.HeightMap; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.block.TileState; @@ -27,12 +38,91 @@ import org.bukkit.util.Vector; import java.io.File; import java.io.IOException; import java.text.NumberFormat; -import java.util.*; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; import java.util.stream.Collectors; @Decree(name = "object", aliases = "o", origin = DecreeOrigin.PLAYER, studio = true, description = "Iris object manipulation") public class CommandObject implements DecreeExecutor { + private static final Set skipBlocks = Set.of(Material.GRASS, Material.SNOW, Material.VINE, Material.TORCH, Material.DEAD_BUSH, + Material.POPPY, Material.DANDELION); + + public static IObjectPlacer createPlacer(World world, Map futureBlockChanges) { + + return new IObjectPlacer() { + @Override + public int getHighest(int x, int z, IrisData data) { + return world.getHighestBlockYAt(x, z); + } + + @Override + public int getHighest(int x, int z, IrisData data, boolean ignoreFluid) { + return world.getHighestBlockYAt(x, z, ignoreFluid ? HeightMap.OCEAN_FLOOR : HeightMap.MOTION_BLOCKING); + } + + @Override + public void set(int x, int y, int z, BlockData d) { + Block block = world.getBlockAt(x, y, z); + + //Prevent blocks being set in or bellow bedrock + if (y <= world.getMinHeight() || block.getType() == Material.BEDROCK) return; + + futureBlockChanges.put(block, block.getBlockData()); + + block.setBlockData(d); + } + + @Override + public BlockData get(int x, int y, int z) { + return world.getBlockAt(x, y, z).getBlockData(); + } + + @Override + public boolean isPreventingDecay() { + return false; + } + + @Override + public boolean isCarved(int x, int y, int z) { + return false; + } + + @Override + public boolean isSolid(int x, int y, int z) { + return world.getBlockAt(x, y, z).getType().isSolid(); + } + + @Override + public boolean isUnderwater(int x, int z) { + return false; + } + + @Override + public int getFluidHeight() { + return 63; + } + + @Override + public boolean isDebugSmartBore() { + return false; + } + + @Override + public void setTile(int xx, int yy, int zz, TileData tile) { + BlockState state = world.getBlockAt(xx, yy, zz).getState(); + tile.toBukkitTry(state); + state.update(); + } + }; + } + @Decree(description = "Check the composition of an object") public void analyze( @Param(description = "The object to analyze", customHandler = ObjectHandler.class) @@ -182,9 +272,6 @@ public class CommandObject implements DecreeExecutor { } } - private static final Set skipBlocks = Set.of(Material.GRASS, Material.SNOW, Material.VINE, Material.TORCH, Material.DEAD_BUSH, - Material.POPPY, Material.DANDELION); - @Decree(description = "Paste an object", sync = true) public void paste( @Param(description = "The object to paste", customHandler = ObjectHandler.class) @@ -243,75 +330,6 @@ public class CommandObject implements DecreeExecutor { } } - public static IObjectPlacer createPlacer(World world, Map futureBlockChanges) { - - return new IObjectPlacer() { - @Override - public int getHighest(int x, int z, IrisData data) { - return world.getHighestBlockYAt(x, z); - } - - @Override - public int getHighest(int x, int z, IrisData data, boolean ignoreFluid) { - return world.getHighestBlockYAt(x, z, ignoreFluid ? HeightMap.OCEAN_FLOOR : HeightMap.MOTION_BLOCKING); - } - - @Override - public void set(int x, int y, int z, BlockData d) { - Block block = world.getBlockAt(x, y, z); - - //Prevent blocks being set in or bellow bedrock - if (y <= world.getMinHeight() || block.getType() == Material.BEDROCK) return; - - futureBlockChanges.put(block, block.getBlockData()); - - block.setBlockData(d); - } - - @Override - public BlockData get(int x, int y, int z) { - return world.getBlockAt(x, y, z).getBlockData(); - } - - @Override - public boolean isPreventingDecay() { - return false; - } - - @Override - public boolean isCarved(int x, int y, int z) { - return false; - } - - @Override - public boolean isSolid(int x, int y, int z) { - return world.getBlockAt(x, y, z).getType().isSolid(); - } - - @Override - public boolean isUnderwater(int x, int z) { - return false; - } - - @Override - public int getFluidHeight() { - return 63; - } - - @Override - public boolean isDebugSmartBore() { - return false; - } - - @Override - public void setTile(int xx, int yy, int zz, TileData tile) { - BlockState state = world.getBlockAt(xx, yy, zz).getState(); - tile.toBukkitTry(state); - state.update(); - } - }; - } - @Decree(description = "Save an object") public void save( @Param(description = "The dimension to store the object in", contextual = true) diff --git a/src/main/java/com/volmit/iris/core/commands/CommandStudio.java b/src/main/java/com/volmit/iris/core/commands/CommandStudio.java index aa4ae0645..e6682f17b 100644 --- a/src/main/java/com/volmit/iris/core/commands/CommandStudio.java +++ b/src/main/java/com/volmit/iris/core/commands/CommandStudio.java @@ -29,7 +29,22 @@ import com.volmit.iris.core.service.ConversionSVC; import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.engine.framework.Engine; -import com.volmit.iris.engine.object.*; +import com.volmit.iris.engine.object.InventorySlotType; +import com.volmit.iris.engine.object.IrisBiome; +import com.volmit.iris.engine.object.IrisBiomePaletteLayer; +import com.volmit.iris.engine.object.IrisDimension; +import com.volmit.iris.engine.object.IrisEntity; +import com.volmit.iris.engine.object.IrisFeaturePositional; +import com.volmit.iris.engine.object.IrisGenerator; +import com.volmit.iris.engine.object.IrisInterpolator; +import com.volmit.iris.engine.object.IrisLootTable; +import com.volmit.iris.engine.object.IrisNoiseGenerator; +import com.volmit.iris.engine.object.IrisObject; +import com.volmit.iris.engine.object.IrisObjectPlacement; +import com.volmit.iris.engine.object.IrisPosition; +import com.volmit.iris.engine.object.IrisRegion; +import com.volmit.iris.engine.object.IrisScript; +import com.volmit.iris.engine.object.NoiseStyle; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.collection.KSet; @@ -58,13 +73,18 @@ import com.volmit.iris.util.scheduling.jobs.JobCollection; import com.volmit.iris.util.scheduling.jobs.QueueJob; import com.volmit.iris.util.scheduling.jobs.SingleJob; import io.papermc.lib.PaperLib; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.Chunk; +import org.bukkit.FluidCollisionMode; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.World; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; import org.bukkit.util.BlockVector; import org.bukkit.util.Vector; -import java.awt.*; +import java.awt.Desktop; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; @@ -81,6 +101,10 @@ import java.util.function.Supplier; @Decree(name = "studio", aliases = {"std", "s"}, description = "Studio Commands", studio = true) public class CommandStudio implements DecreeExecutor { + public static String hrf(Duration duration) { + return duration.toString().substring(2).replaceAll("(\\d[HMS])(?!$)", "$1 ").toLowerCase(); + } + @Decree(description = "Open a new studio world", aliases = "o", sync = true) public void open( @Param(defaultValue = "overworld", description = "The dimension to open a studio for", aliases = "dim") @@ -261,7 +285,6 @@ public class CommandStudio implements DecreeExecutor { Iris.service(ConversionSVC.class).check(sender()); } - @Decree(description = "Edit the biome you are currently in", aliases = {"ebiome", "eb"}, origin = DecreeOrigin.PLAYER) public void editbiome( @Param(contextual = true, description = "The biome to edit") @@ -882,10 +905,6 @@ public class CommandStudio implements DecreeExecutor { } } - public static String hrf(Duration duration) { - return duration.toString().substring(2).replaceAll("(\\d[HMS])(?!$)", "$1 ").toLowerCase(); - } - /** * @return true if server GUIs are not enabled */ diff --git a/src/main/java/com/volmit/iris/core/edit/BlockSignal.java b/src/main/java/com/volmit/iris/core/edit/BlockSignal.java index 9d2ad94f5..efa0375b9 100644 --- a/src/main/java/com/volmit/iris/core/edit/BlockSignal.java +++ b/src/main/java/com/volmit/iris/core/edit/BlockSignal.java @@ -34,6 +34,31 @@ import java.util.concurrent.atomic.AtomicInteger; public class BlockSignal { public static final AtomicInteger active = new AtomicInteger(0); + public BlockSignal(Block block, int ticks) { + active.incrementAndGet(); + Location tg = block.getLocation().clone().add(0.5, 0, 0.5).clone(); + FallingBlock e = block.getWorld().spawnFallingBlock(tg.clone(), block.getBlockData()); + e.setGravity(false); + e.setInvulnerable(true); + e.setGlowing(true); + e.teleport(tg.clone()); + e.setDropItem(false); + e.setHurtEntities(false); + e.setSilent(true); + e.setTicksLived(1); + e.setVelocity(new Vector(0, 0, 0)); + J.s(() -> { + e.remove(); + active.decrementAndGet(); + BlockData type = block.getBlockData(); + MultiBurst.burst.lazy(() -> { + for (Player i : block.getWorld().getPlayers()) { + i.sendBlockChange(block.getLocation(), block.getBlockData()); + } + }); + }, ticks); + } + public static void of(Block block, int ticks) { new BlockSignal(block, ticks); } @@ -80,29 +105,4 @@ public class BlockSignal { }); }; } - - public BlockSignal(Block block, int ticks) { - active.incrementAndGet(); - Location tg = block.getLocation().clone().add(0.5, 0, 0.5).clone(); - FallingBlock e = block.getWorld().spawnFallingBlock(tg.clone(), block.getBlockData()); - e.setGravity(false); - e.setInvulnerable(true); - e.setGlowing(true); - e.teleport(tg.clone()); - e.setDropItem(false); - e.setHurtEntities(false); - e.setSilent(true); - e.setTicksLived(1); - e.setVelocity(new Vector(0, 0, 0)); - J.s(() -> { - e.remove(); - active.decrementAndGet(); - BlockData type = block.getBlockData(); - MultiBurst.burst.lazy(() -> { - for (Player i : block.getWorld().getPlayers()) { - i.sendBlockChange(block.getLocation(), block.getBlockData()); - } - }); - }, ticks); - } } diff --git a/src/main/java/com/volmit/iris/core/edit/DustRevealer.java b/src/main/java/com/volmit/iris/core/edit/DustRevealer.java index 1cff294c8..9a5934dd7 100644 --- a/src/main/java/com/volmit/iris/core/edit/DustRevealer.java +++ b/src/main/java/com/volmit/iris/core/edit/DustRevealer.java @@ -41,24 +41,6 @@ public class DustRevealer { private final String key; private final KList hits; - public static void spawn(Block block, VolmitSender sender) { - World world = block.getWorld(); - Engine access = IrisToolbelt.access(world).getEngine(); - - if (access != null) { - String a = access.getObjectPlacementKey(block.getX(), block.getY(), block.getZ()); - - if (a != null) { - world.playSound(block.getLocation(), Sound.ITEM_LODESTONE_COMPASS_LOCK, 1f, 0.1f); - - sender.sendMessage("Found object " + a); - J.a(() -> { - new DustRevealer(access, world, new BlockPosition(block.getX(), block.getY(), block.getZ()), a, new KList<>()); - }); - } - } - } - public DustRevealer(Engine engine, World world, BlockPosition block, String key, KList hits) { this.engine = engine; this.world = world; @@ -111,6 +93,24 @@ public class DustRevealer { }, RNG.r.i(2, 8)); } + public static void spawn(Block block, VolmitSender sender) { + World world = block.getWorld(); + Engine access = IrisToolbelt.access(world).getEngine(); + + if (access != null) { + String a = access.getObjectPlacementKey(block.getX(), block.getY(), block.getZ()); + + if (a != null) { + world.playSound(block.getLocation(), Sound.ITEM_LODESTONE_COMPASS_LOCK, 1f, 0.1f); + + sender.sendMessage("Found object " + a); + J.a(() -> { + new DustRevealer(access, world, new BlockPosition(block.getX(), block.getY(), block.getZ()), a, new KList<>()); + }); + } + } + } + private boolean is(BlockPosition a) { if (isValidTry(a) && engine.getObjectPlacementKey(a.getX(), a.getY(), a.getZ()) != null && engine.getObjectPlacementKey(a.getX(), a.getY(), a.getZ()).equals(key)) { hits.add(a); diff --git a/src/main/java/com/volmit/iris/core/edit/JigsawEditor.java b/src/main/java/com/volmit/iris/core/edit/JigsawEditor.java index bb82f77aa..709fa6f12 100644 --- a/src/main/java/com/volmit/iris/core/edit/JigsawEditor.java +++ b/src/main/java/com/volmit/iris/core/edit/JigsawEditor.java @@ -21,7 +21,11 @@ package com.volmit.iris.core.edit; import com.google.gson.Gson; import com.volmit.iris.Iris; import com.volmit.iris.core.service.WandSVC; -import com.volmit.iris.engine.object.*; +import com.volmit.iris.engine.object.IrisDirection; +import com.volmit.iris.engine.object.IrisJigsawPiece; +import com.volmit.iris.engine.object.IrisJigsawPieceConnector; +import com.volmit.iris.engine.object.IrisObject; +import com.volmit.iris.engine.object.IrisPosition; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.data.Cuboid; import com.volmit.iris.util.io.IO; @@ -53,9 +57,9 @@ public class JigsawEditor implements Listener { private final Location origin; private final Cuboid cuboid; private final int ticker; - private Location target; private final KMap falling = new KMap<>(); private final ChronoLatch cl = new ChronoLatch(100); + private Location target; public JigsawEditor(Player player, IrisJigsawPiece piece, IrisObject object, File saveLocation) { if (editors.containsKey(player)) { diff --git a/src/main/java/com/volmit/iris/core/events/IrisEngineEvent.java b/src/main/java/com/volmit/iris/core/events/IrisEngineEvent.java index c33c5a37b..0d134380e 100644 --- a/src/main/java/com/volmit/iris/core/events/IrisEngineEvent.java +++ b/src/main/java/com/volmit/iris/core/events/IrisEngineEvent.java @@ -36,12 +36,12 @@ public class IrisEngineEvent extends Event { super(true); } + public static HandlerList getHandlerList() { + return handlers; + } + @Override public HandlerList getHandlers() { return handlers; } - - public static HandlerList getHandlerList() { - return handlers; - } } diff --git a/src/main/java/com/volmit/iris/core/events/IrisEngineHotloadEvent.java b/src/main/java/com/volmit/iris/core/events/IrisEngineHotloadEvent.java index cebbfc532..7cf0638a6 100644 --- a/src/main/java/com/volmit/iris/core/events/IrisEngineHotloadEvent.java +++ b/src/main/java/com/volmit/iris/core/events/IrisEngineHotloadEvent.java @@ -28,12 +28,12 @@ public class IrisEngineHotloadEvent extends IrisEngineEvent { super(engine); } + public static HandlerList getHandlerList() { + return handlers; + } + @Override public HandlerList getHandlers() { return handlers; } - - public static HandlerList getHandlerList() { - return handlers; - } } diff --git a/src/main/java/com/volmit/iris/core/gui/NoiseExplorerGUI.java b/src/main/java/com/volmit/iris/core/gui/NoiseExplorerGUI.java index 6969ed1e3..75cb1065c 100644 --- a/src/main/java/com/volmit/iris/core/gui/NoiseExplorerGUI.java +++ b/src/main/java/com/volmit/iris/core/gui/NoiseExplorerGUI.java @@ -35,9 +35,24 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import javax.imageio.ImageIO; -import javax.swing.*; -import java.awt.*; -import java.awt.event.*; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JLayeredPane; +import javax.swing.JPanel; +import javax.swing.JViewport; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionListener; +import java.awt.event.MouseWheelEvent; +import java.awt.event.MouseWheelListener; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; @@ -50,13 +65,19 @@ public class NoiseExplorerGUI extends JPanel implements MouseWheelListener, List static JComboBox combo; @SuppressWarnings("CanBeFinal") + static boolean hd = false; + static double ascale = 10; + static double oxp = 0; + static double ozp = 0; + static double mxx = 0; + static double mzz = 0; + @SuppressWarnings("CanBeFinal") + static boolean down = false; + @SuppressWarnings("CanBeFinal") RollingSequence r = new RollingSequence(20); @SuppressWarnings("CanBeFinal") boolean colorMode = true; double scale = 1; - @SuppressWarnings("CanBeFinal") - static boolean hd = false; - static double ascale = 10; CNG cng = NoiseStyle.STATIC.create(new RNG(RNG.r.nextLong())); @SuppressWarnings("CanBeFinal") MultiBurst gx = MultiBurst.burst; @@ -66,16 +87,10 @@ public class NoiseExplorerGUI extends JPanel implements MouseWheelListener, List int h = 0; Function2 generator; Supplier> loader; - static double oxp = 0; - static double ozp = 0; double ox = 0; //Offset X double oz = 0; //Offset Y double mx = 0; double mz = 0; - static double mxx = 0; - static double mzz = 0; - @SuppressWarnings("CanBeFinal") - static boolean down = false; double lx = Double.MAX_VALUE; //MouseX double lz = Double.MAX_VALUE; //MouseY double t; @@ -106,6 +121,77 @@ public class NoiseExplorerGUI extends JPanel implements MouseWheelListener, List }); } + private static void createAndShowGUI(Supplier> loader, String genName) { + JFrame frame = new JFrame("Noise Explorer: " + genName); + NoiseExplorerGUI nv = new NoiseExplorerGUI(); + frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); + JLayeredPane pane = new JLayeredPane(); + nv.setSize(new Dimension(1440, 820)); + pane.add(nv, 1, 0); + nv.loader = loader; + nv.generator = loader.get(); + frame.add(pane); + File file = Iris.getCached("Iris Icon", "https://raw.githubusercontent.com/VolmitSoftware/Iris/master/icon.png"); + + if (file != null) { + try { + frame.setIconImage(ImageIO.read(file)); + } catch (IOException e) { + Iris.reportError(e); + } + } + frame.setSize(1440, 820); + frame.setVisible(true); + } + + private static void createAndShowGUI() { + JFrame frame = new JFrame("Noise Explorer"); + NoiseExplorerGUI nv = new NoiseExplorerGUI(); + frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); + KList li = new KList<>(NoiseStyle.values()).toStringList(); + combo = new JComboBox<>(li.toArray(new String[0])); + combo.setSelectedItem("STATIC"); + combo.setFocusable(false); + combo.addActionListener(e -> { + @SuppressWarnings("unchecked") + String b = (String) (((JComboBox) e.getSource()).getSelectedItem()); + NoiseStyle s = NoiseStyle.valueOf(b); + nv.cng = s.create(RNG.r.nextParallelRNG(RNG.r.imax())); + }); + + combo.setSize(500, 30); + JLayeredPane pane = new JLayeredPane(); + nv.setSize(new Dimension(1440, 820)); + pane.add(nv, 1, 0); + pane.add(combo, 2, 0); + frame.add(pane); + File file = Iris.getCached("Iris Icon", "https://raw.githubusercontent.com/VolmitSoftware/Iris/master/icon.png"); + + if (file != null) { + try { + frame.setIconImage(ImageIO.read(file)); + } catch (IOException e) { + Iris.reportError(e); + } + } + frame.setSize(1440, 820); + frame.setVisible(true); + frame.addWindowListener(new java.awt.event.WindowAdapter() { + @Override + public void windowClosing(java.awt.event.WindowEvent windowEvent) { + Iris.instance.unregisterListener(nv); + } + }); + } + + public static void launch(Supplier> gen, String genName) { + EventQueue.invokeLater(() -> createAndShowGUI(gen, genName)); + } + + public static void launch() { + EventQueue.invokeLater(NoiseExplorerGUI::createAndShowGUI); + } + @EventHandler public void on(IrisEngineHotloadEvent e) { if (generator != null) @@ -241,77 +327,6 @@ public class NoiseExplorerGUI extends JPanel implements MouseWheelListener, List }); } - private static void createAndShowGUI(Supplier> loader, String genName) { - JFrame frame = new JFrame("Noise Explorer: " + genName); - NoiseExplorerGUI nv = new NoiseExplorerGUI(); - frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); - JLayeredPane pane = new JLayeredPane(); - nv.setSize(new Dimension(1440, 820)); - pane.add(nv, 1, 0); - nv.loader = loader; - nv.generator = loader.get(); - frame.add(pane); - File file = Iris.getCached("Iris Icon", "https://raw.githubusercontent.com/VolmitSoftware/Iris/master/icon.png"); - - if (file != null) { - try { - frame.setIconImage(ImageIO.read(file)); - } catch (IOException e) { - Iris.reportError(e); - } - } - frame.setSize(1440, 820); - frame.setVisible(true); - } - - private static void createAndShowGUI() { - JFrame frame = new JFrame("Noise Explorer"); - NoiseExplorerGUI nv = new NoiseExplorerGUI(); - frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); - KList li = new KList<>(NoiseStyle.values()).toStringList(); - combo = new JComboBox<>(li.toArray(new String[0])); - combo.setSelectedItem("STATIC"); - combo.setFocusable(false); - combo.addActionListener(e -> { - @SuppressWarnings("unchecked") - String b = (String) (((JComboBox) e.getSource()).getSelectedItem()); - NoiseStyle s = NoiseStyle.valueOf(b); - nv.cng = s.create(RNG.r.nextParallelRNG(RNG.r.imax())); - }); - - combo.setSize(500, 30); - JLayeredPane pane = new JLayeredPane(); - nv.setSize(new Dimension(1440, 820)); - pane.add(nv, 1, 0); - pane.add(combo, 2, 0); - frame.add(pane); - File file = Iris.getCached("Iris Icon", "https://raw.githubusercontent.com/VolmitSoftware/Iris/master/icon.png"); - - if (file != null) { - try { - frame.setIconImage(ImageIO.read(file)); - } catch (IOException e) { - Iris.reportError(e); - } - } - frame.setSize(1440, 820); - frame.setVisible(true); - frame.addWindowListener(new java.awt.event.WindowAdapter() { - @Override - public void windowClosing(java.awt.event.WindowEvent windowEvent) { - Iris.instance.unregisterListener(nv); - } - }); - } - - public static void launch(Supplier> gen, String genName) { - EventQueue.invokeLater(() -> createAndShowGUI(gen, genName)); - } - - public static void launch() { - EventQueue.invokeLater(NoiseExplorerGUI::createAndShowGUI); - } - static class HandScrollListener extends MouseAdapter { private static final Point pp = new Point(); diff --git a/src/main/java/com/volmit/iris/core/gui/PregeneratorJob.java b/src/main/java/com/volmit/iris/core/gui/PregeneratorJob.java index 6757a5a7f..ec7fa4d30 100644 --- a/src/main/java/com/volmit/iris/core/gui/PregeneratorJob.java +++ b/src/main/java/com/volmit/iris/core/gui/PregeneratorJob.java @@ -31,8 +31,12 @@ import com.volmit.iris.util.math.M; import com.volmit.iris.util.math.Position2; import com.volmit.iris.util.scheduling.J; -import javax.swing.*; -import java.awt.*; +import javax.swing.JFrame; +import javax.swing.JPanel; +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.Graphics2D; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.image.BufferedImage; @@ -40,22 +44,22 @@ import java.util.concurrent.locks.ReentrantLock; import java.util.function.Consumer; public class PregeneratorJob implements PregenListener { - public static PregeneratorJob instance; private static final Color COLOR_EXISTS = parseColor("#4d7d5b"); private static final Color COLOR_GENERATING = parseColor("#0062ff"); private static final Color COLOR_NETWORK = parseColor("#a863c2"); private static final Color COLOR_NETWORK_GENERATING = parseColor("#836b8c"); private static final Color COLOR_GENERATED = parseColor("#34eb93"); - private JFrame frame; + public static PregeneratorJob instance; private final PregenTask task; private final boolean saving; private final KList> onProgress = new KList<>(); private final KList whenDone = new KList<>(); private final IrisPregenerator pregenerator; - private PregenRenderer renderer; - private String[] info; private final Position2 min; private final Position2 max; + private JFrame frame; + private PregenRenderer renderer; + private String[] info; public PregeneratorJob(PregenTask task, PregeneratorMethod method) { instance = this; @@ -80,16 +84,6 @@ public class PregeneratorJob implements PregenListener { J.a(this.pregenerator::start, 20); } - public PregeneratorJob onProgress(Consumer c) { - onProgress.add(c); - return this; - } - - public PregeneratorJob whenDone(Runnable r) { - whenDone.add(r); - return this; - } - public static boolean shutdownInstance() { if (instance == null) { return false; @@ -124,6 +118,28 @@ public class PregeneratorJob implements PregenListener { return instance.paused(); } + private static Color parseColor(String c) { + String v = (c.startsWith("#") ? c : "#" + c).trim(); + try { + return Color.decode(v); + } catch (Throwable e) { + Iris.reportError(e); + Iris.error("Error Parsing 'color', (" + c + ")"); + } + + return Color.RED; + } + + public PregeneratorJob onProgress(Consumer c) { + onProgress.add(c); + return this; + } + + public PregeneratorJob whenDone(Runnable r) { + whenDone.add(r); + return this; + } + public void drawRegion(int x, int z, Color color) { J.a(() -> { PregenTask.iterateRegion(x, z, (xx, zz) -> { @@ -284,13 +300,13 @@ public class PregeneratorJob implements PregenListener { } public static class PregenRenderer extends JPanel implements KeyListener { - private PregeneratorJob job; private static final long serialVersionUID = 2094606939770332040L; private final KList order = new KList<>(); private final int res = 512; - Graphics2D bg; - private ReentrantLock l; private final BufferedImage image = new BufferedImage(res, res, BufferedImage.TYPE_INT_RGB); + Graphics2D bg; + private PregeneratorJob job; + private ReentrantLock l; private Consumer2 func; private JFrame frame; @@ -375,16 +391,4 @@ public class PregeneratorJob implements PregenListener { frame.setVisible(false); } } - - private static Color parseColor(String c) { - String v = (c.startsWith("#") ? c : "#" + c).trim(); - try { - return Color.decode(v); - } catch (Throwable e) { - Iris.reportError(e); - Iris.error("Error Parsing 'color', (" + c + ")"); - } - - return Color.RED; - } } diff --git a/src/main/java/com/volmit/iris/core/gui/VisionGUI.java b/src/main/java/com/volmit/iris/core/gui/VisionGUI.java index f0862d4dd..ef33dab76 100644 --- a/src/main/java/com/volmit/iris/core/gui/VisionGUI.java +++ b/src/main/java/com/volmit/iris/core/gui/VisionGUI.java @@ -44,10 +44,20 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import javax.imageio.ImageIO; -import javax.swing.*; +import javax.swing.JFrame; +import javax.swing.JPanel; import javax.swing.event.MouseInputListener; -import java.awt.*; -import java.awt.event.*; +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionListener; +import java.awt.event.MouseWheelEvent; +import java.awt.event.MouseWheelListener; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; diff --git a/src/main/java/com/volmit/iris/core/gui/components/IrisRenderer.java b/src/main/java/com/volmit/iris/core/gui/components/IrisRenderer.java index 944b4af3a..cbc8cadb8 100644 --- a/src/main/java/com/volmit/iris/core/gui/components/IrisRenderer.java +++ b/src/main/java/com/volmit/iris/core/gui/components/IrisRenderer.java @@ -21,7 +21,7 @@ package com.volmit.iris.core.gui.components; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.util.interpolation.IrisInterpolation; -import java.awt.*; +import java.awt.Color; import java.awt.image.BufferedImage; import java.util.function.BiFunction; diff --git a/src/main/java/com/volmit/iris/core/gui/components/Renderer.java b/src/main/java/com/volmit/iris/core/gui/components/Renderer.java index ca33e0ec5..446437299 100644 --- a/src/main/java/com/volmit/iris/core/gui/components/Renderer.java +++ b/src/main/java/com/volmit/iris/core/gui/components/Renderer.java @@ -18,7 +18,7 @@ package com.volmit.iris.core.gui.components; -import java.awt.*; +import java.awt.Color; @FunctionalInterface public interface Renderer { diff --git a/src/main/java/com/volmit/iris/core/loader/IrisData.java b/src/main/java/com/volmit/iris/core/loader/IrisData.java index b3fe3f6be..7cfd0e4e1 100644 --- a/src/main/java/com/volmit/iris/core/loader/IrisData.java +++ b/src/main/java/com/volmit/iris/core/loader/IrisData.java @@ -18,7 +18,12 @@ package com.volmit.iris.core.loader; -import com.google.gson.*; +import com.google.gson.ExclusionStrategy; +import com.google.gson.FieldAttributes; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; import com.google.gson.reflect.TypeToken; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonToken; @@ -26,7 +31,23 @@ import com.google.gson.stream.JsonWriter; import com.volmit.iris.Iris; import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.framework.Engine; -import com.volmit.iris.engine.object.*; +import com.volmit.iris.engine.object.IrisBiome; +import com.volmit.iris.engine.object.IrisBlockData; +import com.volmit.iris.engine.object.IrisCave; +import com.volmit.iris.engine.object.IrisDimension; +import com.volmit.iris.engine.object.IrisEntity; +import com.volmit.iris.engine.object.IrisExpression; +import com.volmit.iris.engine.object.IrisGenerator; +import com.volmit.iris.engine.object.IrisJigsawPiece; +import com.volmit.iris.engine.object.IrisJigsawPool; +import com.volmit.iris.engine.object.IrisJigsawStructure; +import com.volmit.iris.engine.object.IrisLootTable; +import com.volmit.iris.engine.object.IrisMod; +import com.volmit.iris.engine.object.IrisObject; +import com.volmit.iris.engine.object.IrisRavine; +import com.volmit.iris.engine.object.IrisRegion; +import com.volmit.iris.engine.object.IrisScript; +import com.volmit.iris.engine.object.IrisSpawner; import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; @@ -46,6 +67,8 @@ import java.util.function.Function; @Data public class IrisData implements ExclusionStrategy, TypeAdapterFactory { private static final KMap dataLoaders = new KMap<>(); + private final File dataFolder; + private final int id; private ResourceLoader biomeLoader; private ResourceLoader lootLoader; private ResourceLoader regionLoader; @@ -68,13 +91,7 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory { private Gson snippetLoader; private GsonBuilder builder; private KMap, ResourceLoader> loaders = new KMap<>(); - private final File dataFolder; private Engine engine; - private final int id; - - public static IrisData get(File dataFolder) { - return dataLoaders.compute(dataFolder, (k, v) -> v == null ? new IrisData(dataFolder) : v); - } private IrisData(File dataFolder) { this.engine = null; @@ -83,31 +100,14 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory { hotloaded(); } + public static IrisData get(File dataFolder) { + return dataLoaders.compute(dataFolder, (k, v) -> v == null ? new IrisData(dataFolder) : v); + } + public static void dereference() { dataLoaders.v().forEach(IrisData::cleanupEngine); } - public ResourceLoader getTypedLoaderFor(File f) { - String[] k = f.getPath().split("\\Q" + File.separator + "\\E"); - - for (String i : k) { - for (ResourceLoader j : loaders.values()) { - if (j.getFolderName().equals(i)) { - return j; - } - } - } - - return null; - } - - public void cleanupEngine() { - if (engine != null && engine.isClosed()) { - engine = null; - Iris.debug("Dereferenced Data " + getId() + " " + getDataFolder()); - } - } - public static int cacheSize() { int m = 0; for (IrisData i : dataLoaders.values()) { @@ -119,119 +119,10 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory { return m; } - public void preprocessObject(IrisRegistrant t) { - try { - IrisContext ctx = IrisContext.get(); - Engine engine = this.engine; - - if (engine == null && ctx != null && ctx.getEngine() != null) { - engine = ctx.getEngine(); - } - - if (engine == null && t.getPreprocessors().isNotEmpty()) { - Iris.error("Failed to preprocess object " + t.getLoadKey() + " because there is no engine context here. (See stack below)"); - try { - throw new RuntimeException(); - } catch (Throwable ex) { - ex.printStackTrace(); - } - } - - if (engine != null && t.getPreprocessors().isNotEmpty()) { - synchronized (this) { - engine.getExecution().getAPI().setPreprocessorObject(t); - - for (String i : t.getPreprocessors()) { - engine.getExecution().execute(i); - Iris.debug("Loader<" + C.GREEN + t.getTypeName() + C.LIGHT_PURPLE + "> iprocess " + C.YELLOW + t.getLoadKey() + C.LIGHT_PURPLE + " in " + i); - } - } - } - } catch (Throwable e) { - Iris.error("Failed to preprocess object!"); - e.printStackTrace(); - } - } - - public void close() { - dump(); - } - private static void printData(ResourceLoader rl) { Iris.warn(" " + rl.getResourceTypeName() + " @ /" + rl.getFolderName() + ": Cache=" + rl.getLoadCache().size() + " Folders=" + rl.getFolders().size()); } - public IrisData copy() { - return IrisData.get(dataFolder); - } - - private ResourceLoader registerLoader(Class registrant) { - try { - IrisRegistrant rr = registrant.getConstructor().newInstance(); - ResourceLoader r = null; - if (registrant.equals(IrisObject.class)) { - r = (ResourceLoader) new ObjectResourceLoader(dataFolder, this, rr.getFolderName(), rr.getTypeName()); - } else if (registrant.equals(IrisScript.class)) { - r = (ResourceLoader) new ScriptResourceLoader(dataFolder, this, rr.getFolderName(), rr.getTypeName()); - } else { - J.attempt(() -> registrant.getConstructor().newInstance().registerTypeAdapters(builder)); - r = new ResourceLoader<>(dataFolder, this, rr.getFolderName(), rr.getTypeName(), registrant); - } - - loaders.put(registrant, r); - - return r; - } catch (Throwable e) { - e.printStackTrace(); - Iris.error("Failed to create loader! " + registrant.getCanonicalName()); - } - - return null; - } - - public synchronized void hotloaded() { - possibleSnippets = new KMap<>(); - builder = new GsonBuilder() - .addDeserializationExclusionStrategy(this) - .addSerializationExclusionStrategy(this) - .setLenient() - .registerTypeAdapterFactory(this) - .setPrettyPrinting(); - loaders.clear(); - File packs = dataFolder; - packs.mkdirs(); - this.lootLoader = registerLoader(IrisLootTable.class); - this.spawnerLoader = registerLoader(IrisSpawner.class); - this.entityLoader = registerLoader(IrisEntity.class); - this.regionLoader = registerLoader(IrisRegion.class); - this.biomeLoader = registerLoader(IrisBiome.class); - this.modLoader = registerLoader(IrisMod.class); - this.dimensionLoader = registerLoader(IrisDimension.class); - this.jigsawPoolLoader = registerLoader(IrisJigsawPool.class); - this.jigsawStructureLoader = registerLoader(IrisJigsawStructure.class); - this.jigsawPieceLoader = registerLoader(IrisJigsawPiece.class); - this.generatorLoader = registerLoader(IrisGenerator.class); - this.caveLoader = registerLoader(IrisCave.class); - this.ravineLoader = registerLoader(IrisRavine.class); - this.blockLoader = registerLoader(IrisBlockData.class); - this.expressionLoader = registerLoader(IrisExpression.class); - this.objectLoader = registerLoader(IrisObject.class); - this.scriptLoader = registerLoader(IrisScript.class); - gson = builder.create(); - } - - public void dump() { - for (ResourceLoader i : loaders.values()) { - i.clearCache(); - } - } - - public void clearLists() { - for (ResourceLoader i : loaders.values()) { - i.clearList(); - } - } - public static IrisObject loadAnyObject(String key) { return loadAny(key, (dm) -> dm.getObjectLoader().load(key, false)); } @@ -320,6 +211,136 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory { return null; } + public ResourceLoader getTypedLoaderFor(File f) { + String[] k = f.getPath().split("\\Q" + File.separator + "\\E"); + + for (String i : k) { + for (ResourceLoader j : loaders.values()) { + if (j.getFolderName().equals(i)) { + return j; + } + } + } + + return null; + } + + public void cleanupEngine() { + if (engine != null && engine.isClosed()) { + engine = null; + Iris.debug("Dereferenced Data " + getId() + " " + getDataFolder()); + } + } + + public void preprocessObject(IrisRegistrant t) { + try { + IrisContext ctx = IrisContext.get(); + Engine engine = this.engine; + + if (engine == null && ctx != null && ctx.getEngine() != null) { + engine = ctx.getEngine(); + } + + if (engine == null && t.getPreprocessors().isNotEmpty()) { + Iris.error("Failed to preprocess object " + t.getLoadKey() + " because there is no engine context here. (See stack below)"); + try { + throw new RuntimeException(); + } catch (Throwable ex) { + ex.printStackTrace(); + } + } + + if (engine != null && t.getPreprocessors().isNotEmpty()) { + synchronized (this) { + engine.getExecution().getAPI().setPreprocessorObject(t); + + for (String i : t.getPreprocessors()) { + engine.getExecution().execute(i); + Iris.debug("Loader<" + C.GREEN + t.getTypeName() + C.LIGHT_PURPLE + "> iprocess " + C.YELLOW + t.getLoadKey() + C.LIGHT_PURPLE + " in " + i); + } + } + } + } catch (Throwable e) { + Iris.error("Failed to preprocess object!"); + e.printStackTrace(); + } + } + + public void close() { + dump(); + } + + public IrisData copy() { + return IrisData.get(dataFolder); + } + + private ResourceLoader registerLoader(Class registrant) { + try { + IrisRegistrant rr = registrant.getConstructor().newInstance(); + ResourceLoader r = null; + if (registrant.equals(IrisObject.class)) { + r = (ResourceLoader) new ObjectResourceLoader(dataFolder, this, rr.getFolderName(), rr.getTypeName()); + } else if (registrant.equals(IrisScript.class)) { + r = (ResourceLoader) new ScriptResourceLoader(dataFolder, this, rr.getFolderName(), rr.getTypeName()); + } else { + J.attempt(() -> registrant.getConstructor().newInstance().registerTypeAdapters(builder)); + r = new ResourceLoader<>(dataFolder, this, rr.getFolderName(), rr.getTypeName(), registrant); + } + + loaders.put(registrant, r); + + return r; + } catch (Throwable e) { + e.printStackTrace(); + Iris.error("Failed to create loader! " + registrant.getCanonicalName()); + } + + return null; + } + + public synchronized void hotloaded() { + possibleSnippets = new KMap<>(); + builder = new GsonBuilder() + .addDeserializationExclusionStrategy(this) + .addSerializationExclusionStrategy(this) + .setLenient() + .registerTypeAdapterFactory(this) + .setPrettyPrinting(); + loaders.clear(); + File packs = dataFolder; + packs.mkdirs(); + this.lootLoader = registerLoader(IrisLootTable.class); + this.spawnerLoader = registerLoader(IrisSpawner.class); + this.entityLoader = registerLoader(IrisEntity.class); + this.regionLoader = registerLoader(IrisRegion.class); + this.biomeLoader = registerLoader(IrisBiome.class); + this.modLoader = registerLoader(IrisMod.class); + this.dimensionLoader = registerLoader(IrisDimension.class); + this.jigsawPoolLoader = registerLoader(IrisJigsawPool.class); + this.jigsawStructureLoader = registerLoader(IrisJigsawStructure.class); + this.jigsawPieceLoader = registerLoader(IrisJigsawPiece.class); + this.generatorLoader = registerLoader(IrisGenerator.class); + this.caveLoader = registerLoader(IrisCave.class); + this.ravineLoader = registerLoader(IrisRavine.class); + this.blockLoader = registerLoader(IrisBlockData.class); + this.expressionLoader = registerLoader(IrisExpression.class); + this.objectLoader = registerLoader(IrisObject.class); + this.scriptLoader = registerLoader(IrisScript.class); + gson = builder.create(); + } + + public void dump() { + for (ResourceLoader i : loaders.values()) { + i.clearCache(); + } + } + + public void clearLists() { + for (ResourceLoader i : loaders.values()) { + i.clearList(); + } + } + public String toLoadKey(File f) { if (f.getPath().startsWith(getDataFolder().getPath())) { String[] full = f.getPath().split("\\Q" + File.separator + "\\E"); diff --git a/src/main/java/com/volmit/iris/core/loader/IrisRegistrant.java b/src/main/java/com/volmit/iris/core/loader/IrisRegistrant.java index 3797c14c1..51bad94a4 100644 --- a/src/main/java/com/volmit/iris/core/loader/IrisRegistrant.java +++ b/src/main/java/com/volmit/iris/core/loader/IrisRegistrant.java @@ -29,7 +29,7 @@ import com.volmit.iris.util.json.JSONObject; import com.volmit.iris.util.plugin.VolmitSender; import lombok.Data; -import java.awt.*; +import java.awt.Desktop; import java.io.File; @Data diff --git a/src/main/java/com/volmit/iris/core/nms/NMSVersion.java b/src/main/java/com/volmit/iris/core/nms/NMSVersion.java index e8a161932..c6e629039 100644 --- a/src/main/java/com/volmit/iris/core/nms/NMSVersion.java +++ b/src/main/java/com/volmit/iris/core/nms/NMSVersion.java @@ -36,42 +36,6 @@ public enum NMSVersion { R1_9_2, R1_8; - public List getAboveInclusive() { - List n = new ArrayList<>(); - - for (NMSVersion i : values()) { - if (i.ordinal() >= ordinal()) { - n.add(i); - } - } - - return n; - } - - public List betweenInclusive(NMSVersion other) { - List n = new ArrayList<>(); - - for (NMSVersion i : values()) { - if (i.ordinal() <= Math.max(other.ordinal(), ordinal()) && i.ordinal() >= Math.min(ordinal(), other.ordinal())) { - n.add(i); - } - } - - return n; - } - - public List getBelowInclusive() { - List n = new ArrayList<>(); - - for (NMSVersion i : values()) { - if (i.ordinal() <= ordinal()) { - n.add(i); - } - } - - return n; - } - public static NMSVersion getMinimum() { return values()[values().length - 1]; } @@ -138,4 +102,40 @@ public enum NMSVersion { return false; } + + public List getAboveInclusive() { + List n = new ArrayList<>(); + + for (NMSVersion i : values()) { + if (i.ordinal() >= ordinal()) { + n.add(i); + } + } + + return n; + } + + public List betweenInclusive(NMSVersion other) { + List n = new ArrayList<>(); + + for (NMSVersion i : values()) { + if (i.ordinal() <= Math.max(other.ordinal(), ordinal()) && i.ordinal() >= Math.min(ordinal(), other.ordinal())) { + n.add(i); + } + } + + return n; + } + + public List getBelowInclusive() { + List n = new ArrayList<>(); + + for (NMSVersion i : values()) { + if (i.ordinal() <= ordinal()) { + n.add(i); + } + } + + return n; + } } diff --git a/src/main/java/com/volmit/iris/core/nms/v17_1/NMSBinding17_1.java b/src/main/java/com/volmit/iris/core/nms/v17_1/NMSBinding17_1.java index c0161633e..a157effbe 100644 --- a/src/main/java/com/volmit/iris/core/nms/v17_1/NMSBinding17_1.java +++ b/src/main/java/com/volmit/iris/core/nms/v17_1/NMSBinding17_1.java @@ -24,7 +24,15 @@ import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.nbt.io.NBTUtil; import com.volmit.iris.util.nbt.mca.NBTWorld; -import com.volmit.iris.util.nbt.mca.palette.*; +import com.volmit.iris.util.nbt.mca.palette.BiomeContainer; +import com.volmit.iris.util.nbt.mca.palette.ChunkBiomeContainer; +import com.volmit.iris.util.nbt.mca.palette.GlobalPalette; +import com.volmit.iris.util.nbt.mca.palette.IdMap; +import com.volmit.iris.util.nbt.mca.palette.IdMapper; +import com.volmit.iris.util.nbt.mca.palette.Palette; +import com.volmit.iris.util.nbt.mca.palette.PaletteAccess; +import com.volmit.iris.util.nbt.mca.palette.PalettedContainer; +import com.volmit.iris.util.nbt.mca.palette.WrappedPalettedContainer; import com.volmit.iris.util.nbt.tag.CompoundTag; import net.minecraft.core.BlockPosition; import net.minecraft.core.IRegistry; @@ -58,7 +66,12 @@ import org.bukkit.entity.EntityType; import org.bukkit.generator.ChunkGenerator; import org.jetbrains.annotations.NotNull; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInput; +import java.io.DataInputStream; +import java.io.DataOutput; +import java.io.DataOutputStream; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.IdentityHashMap; diff --git a/src/main/java/com/volmit/iris/core/pack/IrisPack.java b/src/main/java/com/volmit/iris/core/pack/IrisPack.java index 57da51085..1dbc64cf0 100644 --- a/src/main/java/com/volmit/iris/core/pack/IrisPack.java +++ b/src/main/java/com/volmit/iris/core/pack/IrisPack.java @@ -79,15 +79,6 @@ public class IrisPack { this.data = IrisData.get(folder); } - /** - * Delete this pack. This invalidates this pack and you should - * probably no longer use this instance after deleting this pack - */ - public void delete() { - IO.delete(folder); - folder.delete(); - } - /** * Create a new pack from the input url * @@ -109,6 +100,85 @@ public class IrisPack { } } + /** + * Create a pack from a repo + * + * @param sender the sender + * @param repo the repo + * @return the pack + * @throws MalformedURLException shit happens + */ + public static Future from(VolmitSender sender, IrisPackRepository repo) throws MalformedURLException { + CompletableFuture pack = new CompletableFuture<>(); + repo.install(sender, () -> { + pack.complete(new IrisPack(repo.getRepo())); + }); + return pack; + } + + /** + * Create a blank pack with a given name + * + * @param name the name of the pack + * @return the pack + * @throws IrisException if the pack already exists or another error + */ + public static IrisPack blank(String name) throws IrisException { + File f = packsPack(name); + + if (f.exists()) { + throw new IrisException("Already exists"); + } + + File fd = new File(f, "dimensions/" + name + ".json"); + fd.getParentFile().mkdirs(); + try { + IO.writeAll(fd, "{\n" + + " \"name\": \"" + Form.capitalize(name) + "\",\n" + + " \"version\": 1\n" + + "}\n"); + } catch (IOException e) { + throw new IrisException(e.getMessage(), e); + } + + IrisPack pack = new IrisPack(f); + pack.updateWorkspace(); + return pack; + } + + /** + * Get a packs pack folder for a name. Such that overworld would resolve as Iris/packs/overworld + * + * @param name the name + * @return the file path + */ + public static File packsPack(String name) { + return Iris.instance.getDataFolderNoCreate(StudioSVC.WORKSPACE_NAME, name); + } + + private static KList collectFiles(File f, String fileExtension) { + KList l = new KList<>(); + + if (f.isDirectory()) { + for (File i : f.listFiles()) { + l.addAll(collectFiles(i, fileExtension)); + } + } else if (f.getName().endsWith("." + fileExtension)) { + l.add(f); + } + + return l; + } + + /** + * Delete this pack. This invalidates this pack and you should + * probably no longer use this instance after deleting this pack + */ + public void delete() { + IO.delete(folder); + folder.delete(); + } + /** * Get the name of this pack * @@ -311,74 +381,4 @@ public class IrisPack { return ws; } - - /** - * Create a pack from a repo - * - * @param sender the sender - * @param repo the repo - * @return the pack - * @throws MalformedURLException shit happens - */ - public static Future from(VolmitSender sender, IrisPackRepository repo) throws MalformedURLException { - CompletableFuture pack = new CompletableFuture<>(); - repo.install(sender, () -> { - pack.complete(new IrisPack(repo.getRepo())); - }); - return pack; - } - - /** - * Create a blank pack with a given name - * - * @param name the name of the pack - * @return the pack - * @throws IrisException if the pack already exists or another error - */ - public static IrisPack blank(String name) throws IrisException { - File f = packsPack(name); - - if (f.exists()) { - throw new IrisException("Already exists"); - } - - File fd = new File(f, "dimensions/" + name + ".json"); - fd.getParentFile().mkdirs(); - try { - IO.writeAll(fd, "{\n" + - " \"name\": \"" + Form.capitalize(name) + "\",\n" + - " \"version\": 1\n" + - "}\n"); - } catch (IOException e) { - throw new IrisException(e.getMessage(), e); - } - - IrisPack pack = new IrisPack(f); - pack.updateWorkspace(); - return pack; - } - - /** - * Get a packs pack folder for a name. Such that overworld would resolve as Iris/packs/overworld - * - * @param name the name - * @return the file path - */ - public static File packsPack(String name) { - return Iris.instance.getDataFolderNoCreate(StudioSVC.WORKSPACE_NAME, name); - } - - private static KList collectFiles(File f, String fileExtension) { - KList l = new KList<>(); - - if (f.isDirectory()) { - for (File i : f.listFiles()) { - l.addAll(collectFiles(i, fileExtension)); - } - } else if (f.getName().endsWith("." + fileExtension)) { - l.add(f); - } - - return l; - } } diff --git a/src/main/java/com/volmit/iris/core/pregenerator/PregenTask.java b/src/main/java/com/volmit/iris/core/pregenerator/PregenTask.java index 5a1907ca3..1edd376c9 100644 --- a/src/main/java/com/volmit/iris/core/pregenerator/PregenTask.java +++ b/src/main/java/com/volmit/iris/core/pregenerator/PregenTask.java @@ -30,33 +30,20 @@ import java.util.Comparator; @Builder @Data public class PregenTask { + private static final KList order = computeChunkOrder(); @Builder.Default private Position2 center = new Position2(0, 0); - @Builder.Default private int width = 1; - @Builder.Default private int height = 1; - private static final KList order = computeChunkOrder(); - - public void iterateRegions(Spiraled s) { - new Spiraler(getWidth() * 2, getHeight() * 2, s) - .setOffset(center.getX(), center.getZ()).drain(); - } - public static void iterateRegion(int xr, int zr, Spiraled s) { for (Position2 i : order) { s.on(i.getX() + (xr << 5), i.getZ() + (zr << 5)); } } - public void iterateAllChunks(Spiraled s) { - new Spiraler(getWidth() * 2, getHeight() * 2, (x, z) -> iterateRegion(x, z, s)) - .setOffset(center.getX(), center.getZ()).drain(); - } - private static KList computeChunkOrder() { Position2 center = new Position2(15, 15); KList p = new KList<>(); @@ -72,4 +59,14 @@ public class PregenTask { p.sort(Comparator.comparing((i) -> i.distance(center))); return p; } + + public void iterateRegions(Spiraled s) { + new Spiraler(getWidth() * 2, getHeight() * 2, s) + .setOffset(center.getX(), center.getZ()).drain(); + } + + public void iterateAllChunks(Spiraled s) { + new Spiraler(getWidth() * 2, getHeight() * 2, (x, z) -> iterateRegion(x, z, s)) + .setOffset(center.getX(), center.getZ()).drain(); + } } diff --git a/src/main/java/com/volmit/iris/core/pregenerator/methods/SyndicatePregenMethod.java b/src/main/java/com/volmit/iris/core/pregenerator/methods/SyndicatePregenMethod.java index 6b2f30afa..8b75241d5 100644 --- a/src/main/java/com/volmit/iris/core/pregenerator/methods/SyndicatePregenMethod.java +++ b/src/main/java/com/volmit/iris/core/pregenerator/methods/SyndicatePregenMethod.java @@ -24,7 +24,14 @@ import com.volmit.iris.core.pregenerator.PregenListener; import com.volmit.iris.core.pregenerator.PregenTask; import com.volmit.iris.core.pregenerator.PregeneratorMethod; import com.volmit.iris.core.pregenerator.syndicate.SyndicateClient; -import com.volmit.iris.core.pregenerator.syndicate.command.*; +import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateBusy; +import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateClose; +import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateGenerate; +import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateGetProgress; +import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateInstallFirst; +import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateInstallPack; +import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateOK; +import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateSendProgress; import com.volmit.iris.engine.object.IrisDimension; import com.volmit.iris.util.io.IO; import com.volmit.iris.util.scheduling.J; @@ -39,14 +46,14 @@ import java.util.concurrent.atomic.AtomicInteger; public class SyndicatePregenMethod implements PregeneratorMethod { @Getter private final String address; - private String nickname; private final int port; private final String password; private final IrisDimension dimension; - private boolean ready = false; private final File worldFolder; private final UUID pack = UUID.randomUUID(); private final long seed; + private String nickname; + private boolean ready = false; public SyndicatePregenMethod(String nickname, File worldFolder, String address, int port, String password, IrisDimension dimension, long seed) { this.seed = seed; diff --git a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/SyndicateServer.java b/src/main/java/com/volmit/iris/core/pregenerator/syndicate/SyndicateServer.java index 8a6b84f13..91b9f4778 100644 --- a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/SyndicateServer.java +++ b/src/main/java/com/volmit/iris/core/pregenerator/syndicate/SyndicateServer.java @@ -19,14 +19,26 @@ package com.volmit.iris.core.pregenerator.syndicate; import com.volmit.iris.core.pregenerator.PregenListener; -import com.volmit.iris.core.pregenerator.syndicate.command.*; +import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateBusy; +import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateClose; +import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateCommand; +import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateGenerate; +import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateGetProgress; +import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateInstallFirst; +import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateInstallPack; +import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateOK; +import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateSendProgress; import com.volmit.iris.engine.object.HeadlessWorld; import com.volmit.iris.engine.platform.HeadlessGenerator; import com.volmit.iris.util.io.IO; import com.volmit.iris.util.scheduling.J; import org.zeroturnaround.zip.ZipUtil; -import java.io.*; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; import java.net.SocketTimeoutException; @@ -37,13 +49,13 @@ import java.util.concurrent.atomic.AtomicInteger; public class SyndicateServer extends Thread implements PregenListener { private final int port; private final String password; - private boolean busy; private final int tc; - private HeadlessGenerator generator; private final ServerSocket server; private final File cache; - private UUID currentId = null; private final AtomicInteger g = new AtomicInteger(0); + private boolean busy; + private HeadlessGenerator generator; + private UUID currentId = null; private File lastGeneratedRegion = null; public SyndicateServer(File cache, int port, String password, int tc) throws IOException { diff --git a/src/main/java/com/volmit/iris/core/project/IrisProject.java b/src/main/java/com/volmit/iris/core/project/IrisProject.java index 7ba21934b..b47e5e559 100644 --- a/src/main/java/com/volmit/iris/core/project/IrisProject.java +++ b/src/main/java/com/volmit/iris/core/project/IrisProject.java @@ -25,7 +25,16 @@ import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.core.loader.IrisRegistrant; import com.volmit.iris.core.loader.ResourceLoader; import com.volmit.iris.core.tools.IrisToolbelt; -import com.volmit.iris.engine.object.*; +import com.volmit.iris.engine.object.IrisBiome; +import com.volmit.iris.engine.object.IrisBlockData; +import com.volmit.iris.engine.object.IrisDimension; +import com.volmit.iris.engine.object.IrisEntity; +import com.volmit.iris.engine.object.IrisGenerator; +import com.volmit.iris.engine.object.IrisLootTable; +import com.volmit.iris.engine.object.IrisObject; +import com.volmit.iris.engine.object.IrisObjectPlacement; +import com.volmit.iris.engine.object.IrisRegion; +import com.volmit.iris.engine.object.IrisSpawner; import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.engine.platform.PlatformChunkGenerator; import com.volmit.iris.util.collection.KList; @@ -51,7 +60,8 @@ import org.bukkit.GameMode; import org.bukkit.World; import org.zeroturnaround.zip.ZipUtil; -import java.awt.*; +import java.awt.Desktop; +import java.awt.GraphicsEnvironment; import java.io.File; import java.io.IOException; import java.util.Objects; @@ -70,6 +80,62 @@ public class IrisProject { this.name = path.getName(); } + public static int clean(VolmitSender s, File clean) { + int c = 0; + if (clean.isDirectory()) { + for (File i : clean.listFiles()) { + c += clean(s, i); + } + } else if (clean.getName().endsWith(".json")) { + try { + clean(clean); + } catch (Throwable e) { + Iris.reportError(e); + Iris.error("Failed to beautify " + clean.getAbsolutePath() + " You may have errors in your json!"); + } + + c++; + } + + return c; + } + + public static void clean(File clean) throws IOException { + JSONObject obj = new JSONObject(IO.readAll(clean)); + fixBlocks(obj, clean); + + IO.writeAll(clean, obj.toString(4)); + } + + public static void fixBlocks(JSONObject obj, File f) { + for (String i : obj.keySet()) { + Object o = obj.get(i); + + if (i.equals("block") && o instanceof String && !o.toString().trim().isEmpty() && !o.toString().contains(":")) { + obj.put(i, "minecraft:" + o); + Iris.debug("Updated Block Key: " + o + " to " + obj.getString(i) + " in " + f.getPath()); + } + + if (o instanceof JSONObject) { + fixBlocks((JSONObject) o, f); + } else if (o instanceof JSONArray) { + fixBlocks((JSONArray) o, f); + } + } + } + + public static void fixBlocks(JSONArray obj, File f) { + for (int i = 0; i < obj.length(); i++) { + Object o = obj.get(i); + + if (o instanceof JSONObject) { + fixBlocks((JSONObject) o, f); + } else if (o instanceof JSONArray) { + fixBlocks((JSONArray) o, f); + } + } + } + public boolean isOpen() { return activeProvider != null; } @@ -479,62 +545,6 @@ public class IrisProject { return null; } - public static int clean(VolmitSender s, File clean) { - int c = 0; - if (clean.isDirectory()) { - for (File i : clean.listFiles()) { - c += clean(s, i); - } - } else if (clean.getName().endsWith(".json")) { - try { - clean(clean); - } catch (Throwable e) { - Iris.reportError(e); - Iris.error("Failed to beautify " + clean.getAbsolutePath() + " You may have errors in your json!"); - } - - c++; - } - - return c; - } - - public static void clean(File clean) throws IOException { - JSONObject obj = new JSONObject(IO.readAll(clean)); - fixBlocks(obj, clean); - - IO.writeAll(clean, obj.toString(4)); - } - - public static void fixBlocks(JSONObject obj, File f) { - for (String i : obj.keySet()) { - Object o = obj.get(i); - - if (i.equals("block") && o instanceof String && !o.toString().trim().isEmpty() && !o.toString().contains(":")) { - obj.put(i, "minecraft:" + o); - Iris.debug("Updated Block Key: " + o + " to " + obj.getString(i) + " in " + f.getPath()); - } - - if (o instanceof JSONObject) { - fixBlocks((JSONObject) o, f); - } else if (o instanceof JSONArray) { - fixBlocks((JSONArray) o, f); - } - } - } - - public static void fixBlocks(JSONArray obj, File f) { - for (int i = 0; i < obj.length(); i++) { - Object o = obj.get(i); - - if (o instanceof JSONObject) { - fixBlocks((JSONObject) o, f); - } else if (o instanceof JSONArray) { - fixBlocks((JSONArray) o, f); - } - } - } - public void compile(VolmitSender sender) { IrisData data = IrisData.get(getPath()); KList jobs = new KList(); diff --git a/src/main/java/com/volmit/iris/core/project/SchemaBuilder.java b/src/main/java/com/volmit/iris/core/project/SchemaBuilder.java index ef1a364d2..a64ae2706 100644 --- a/src/main/java/com/volmit/iris/core/project/SchemaBuilder.java +++ b/src/main/java/com/volmit/iris/core/project/SchemaBuilder.java @@ -22,7 +22,17 @@ import com.volmit.iris.Iris; import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.core.loader.IrisRegistrant; import com.volmit.iris.core.loader.ResourceLoader; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListBlockType; +import com.volmit.iris.engine.object.annotations.RegistryListFont; +import com.volmit.iris.engine.object.annotations.RegistryListItemType; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.RegistryListSpecialEntity; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.data.B; @@ -31,7 +41,7 @@ import com.volmit.iris.util.json.JSONObject; import org.bukkit.enchantments.Enchantment; import org.bukkit.potion.PotionEffectType; -import java.awt.*; +import java.awt.GraphicsEnvironment; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.List; @@ -57,6 +67,26 @@ public class SchemaBuilder { this.root = root; } + private static JSONArray getEnchantmentTypes() { + JSONArray a = new JSONArray(); + + for (Field gg : Enchantment.class.getDeclaredFields()) { + a.put(gg.getName()); + } + + return a; + } + + private static JSONArray getPotionTypes() { + JSONArray a = new JSONArray(); + + for (PotionEffectType gg : PotionEffectType.values()) { + a.put(gg.getName().toUpperCase().replaceAll("\\Q \\E", "_")); + } + + return a; + } + public JSONObject compute() { JSONObject schema = new JSONObject(); schema.put("$schema", "http://json-schema.org/draft-07/schema#"); @@ -649,24 +679,4 @@ public class SchemaBuilder { } return ""; } - - private static JSONArray getEnchantmentTypes() { - JSONArray a = new JSONArray(); - - for (Field gg : Enchantment.class.getDeclaredFields()) { - a.put(gg.getName()); - } - - return a; - } - - private static JSONArray getPotionTypes() { - JSONArray a = new JSONArray(); - - for (PotionEffectType gg : PotionEffectType.values()) { - a.put(gg.getName().toUpperCase().replaceAll("\\Q \\E", "_")); - } - - return a; - } } diff --git a/src/main/java/com/volmit/iris/core/service/BoardSVC.java b/src/main/java/com/volmit/iris/core/service/BoardSVC.java index 3308c3da6..a4dd3ae42 100644 --- a/src/main/java/com/volmit/iris/core/service/BoardSVC.java +++ b/src/main/java/com/volmit/iris/core/service/BoardSVC.java @@ -42,8 +42,8 @@ import org.bukkit.event.player.PlayerJoinEvent; import java.util.List; public class BoardSVC implements IrisService, BoardProvider { - private com.volmit.iris.util.board.BoardManager manager; private final KMap boards = new KMap<>(); + private com.volmit.iris.util.board.BoardManager manager; @Override public void onEnable() { diff --git a/src/main/java/com/volmit/iris/core/service/ConversionSVC.java b/src/main/java/com/volmit/iris/core/service/ConversionSVC.java index 356dc4716..ac58a918d 100644 --- a/src/main/java/com/volmit/iris/core/service/ConversionSVC.java +++ b/src/main/java/com/volmit/iris/core/service/ConversionSVC.java @@ -20,7 +20,12 @@ package com.volmit.iris.core.service; import com.google.gson.Gson; import com.volmit.iris.Iris; -import com.volmit.iris.engine.object.*; +import com.volmit.iris.engine.object.IrisDirection; +import com.volmit.iris.engine.object.IrisJigsawPiece; +import com.volmit.iris.engine.object.IrisJigsawPieceConnector; +import com.volmit.iris.engine.object.IrisJigsawPool; +import com.volmit.iris.engine.object.IrisObject; +import com.volmit.iris.engine.object.IrisPosition; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.format.Form; @@ -46,6 +51,9 @@ import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; public class ConversionSVC implements IrisService { + private KList converters; + private File folder; + @Override public void onEnable() { folder = Iris.instance.getDataFolder("convert"); @@ -63,9 +71,6 @@ public class ConversionSVC implements IrisService { } - private KList converters; - private File folder; - private String toPoolName(String poolReference) { return poolReference.split("\\Q:\\E")[1]; } diff --git a/src/main/java/com/volmit/iris/core/service/StudioSVC.java b/src/main/java/com/volmit/iris/core/service/StudioSVC.java index f3db03a1c..1227d1475 100644 --- a/src/main/java/com/volmit/iris/core/service/StudioSVC.java +++ b/src/main/java/com/volmit/iris/core/service/StudioSVC.java @@ -50,9 +50,9 @@ import java.util.function.Consumer; public class StudioSVC implements IrisService { public static final String LISTING = "https://raw.githubusercontent.com/IrisDimensions/_listing/main/listing-v2.json"; public static final String WORKSPACE_NAME = "packs"; + private static final AtomicCache counter = new AtomicCache<>(); private final KMap cacheListing = null; private IrisProject activeProject; - private static final AtomicCache counter = new AtomicCache<>(); @Override public void onEnable() { diff --git a/src/main/java/com/volmit/iris/core/service/TreeSVC.java b/src/main/java/com/volmit/iris/core/service/TreeSVC.java index 9d00e830e..f9bc6f5d9 100644 --- a/src/main/java/com/volmit/iris/core/service/TreeSVC.java +++ b/src/main/java/com/volmit/iris/core/service/TreeSVC.java @@ -21,7 +21,14 @@ package com.volmit.iris.core.service; import com.volmit.iris.Iris; import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.core.tools.IrisToolbelt; -import com.volmit.iris.engine.object.*; +import com.volmit.iris.engine.object.IObjectPlacer; +import com.volmit.iris.engine.object.IrisBiome; +import com.volmit.iris.engine.object.IrisObject; +import com.volmit.iris.engine.object.IrisObjectPlacement; +import com.volmit.iris.engine.object.IrisRegion; +import com.volmit.iris.engine.object.IrisTreeModes; +import com.volmit.iris.engine.object.IrisTreeSize; +import com.volmit.iris.engine.object.TileData; import com.volmit.iris.engine.platform.PlatformChunkGenerator; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; @@ -30,7 +37,12 @@ import com.volmit.iris.util.math.BlockPosition; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.plugin.IrisService; import com.volmit.iris.util.scheduling.J; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.HeightMap; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.TreeType; +import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.block.TileState; diff --git a/src/main/java/com/volmit/iris/core/service/WandSVC.java b/src/main/java/com/volmit/iris/core/service/WandSVC.java index 24c51c3db..494a8c48e 100644 --- a/src/main/java/com/volmit/iris/core/service/WandSVC.java +++ b/src/main/java/com/volmit/iris/core/service/WandSVC.java @@ -31,7 +31,11 @@ import com.volmit.iris.util.matter.WorldMatter; import com.volmit.iris.util.plugin.IrisService; import com.volmit.iris.util.plugin.VolmitSender; import com.volmit.iris.util.scheduling.J; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; @@ -53,6 +57,205 @@ public class WandSVC implements IrisService { private static ItemStack wand; private static ItemStack dust; + public static void pasteSchematic(IrisObject s, Location at) { + s.place(at); + } + + /** + * Creates an Iris Object from the 2 coordinates selected with a wand + * + * @param wand The wand itemstack + * @return The new object + */ + public static IrisObject createSchematic(ItemStack wand) { + if (!isWand(wand)) { + return null; + } + + try { + Location[] f = getCuboid(wand); + Cuboid c = new Cuboid(f[0], f[1]); + IrisObject s = new IrisObject(c.getSizeX(), c.getSizeY(), c.getSizeZ()); + for (Block b : c) { + if (b.getType().equals(Material.AIR)) { + continue; + } + + BlockVector bv = b.getLocation().subtract(c.getLowerNE().toVector()).toVector().toBlockVector(); + s.setUnsigned(bv.getBlockX(), bv.getBlockY(), bv.getBlockZ(), b); + } + + return s; + } catch (Throwable e) { + e.printStackTrace(); + Iris.reportError(e); + } + + return null; + } + + /** + * Creates an Iris Object from the 2 coordinates selected with a wand + * + * @param wand The wand itemstack + * @return The new object + */ + public static Matter createMatterSchem(Player p, ItemStack wand) { + if (!isWand(wand)) { + return null; + } + + try { + Location[] f = getCuboid(wand); + + return WorldMatter.createMatter(p.getName(), f[0], f[1]); + } catch (Throwable e) { + e.printStackTrace(); + Iris.reportError(e); + } + + return null; + } + + /** + * Converts a user friendly location string to an actual Location + * + * @param s The string + * @return The location + */ + public static Location stringToLocation(String s) { + try { + String[] f = s.split("\\Q in \\E"); + String[] g = f[0].split("\\Q,\\E"); + return new Location(Bukkit.getWorld(f[1]), Integer.parseInt(g[0]), Integer.parseInt(g[1]), Integer.parseInt(g[2])); + } catch (Throwable e) { + Iris.reportError(e); + return null; + } + } + + /** + * Get a user friendly string of a location + * + * @param loc The location + * @return The string + */ + public static String locationToString(Location loc) { + if (loc == null) { + return "<#>"; + } + + return loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ() + " in " + loc.getWorld().getName(); + } + + /** + * Create a new blank Iris wand + * + * @return The wand itemstack + */ + public static ItemStack createWand() { + return createWand(null, null); + } + + /** + * Create a new dust itemstack + * + * @return The stack + */ + public static ItemStack createDust() { + ItemStack is = new ItemStack(Material.GLOWSTONE_DUST); + is.addUnsafeEnchantment(Enchantment.ARROW_INFINITE, 1); + ItemMeta im = is.getItemMeta(); + im.setDisplayName(C.BOLD + "" + C.YELLOW + "Dust of Revealing"); + im.setUnbreakable(true); + im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_PLACED_ON, ItemFlag.HIDE_POTION_EFFECTS, ItemFlag.HIDE_DESTROYS, ItemFlag.HIDE_ENCHANTS); + im.setLore(new KList().qadd("Right click on a block to reveal it's placement structure!")); + is.setItemMeta(im); + + return is; + } + + /** + * Finds an existing wand in a users inventory + * + * @param inventory The inventory to search + * @return The slot number the wand is in. Or -1 if none are found + */ + public static int findWand(Inventory inventory) { + ItemStack wand = createWand(); //Create blank wand + ItemMeta meta = wand.getItemMeta(); + meta.setLore(new ArrayList<>()); //We are resetting the lore as the lore differs between wands + wand.setItemMeta(meta); + + for (int s = 0; s < inventory.getSize(); s++) { + ItemStack stack = inventory.getItem(s); + if (stack == null) continue; + meta = stack.getItemMeta(); + meta.setLore(new ArrayList<>()); //Reset the lore on this too so we can compare them + stack.setItemMeta(meta); //We dont need to clone the item as items from .get are cloned + + if (wand.isSimilar(stack)) return s; //If the name, material and NBT is the same + } + return -1; + } + + /** + * Creates an Iris wand. The locations should be the currently selected locations, or null + * + * @param a Location A + * @param b Location B + * @return A new wand + */ + public static ItemStack createWand(Location a, Location b) { + ItemStack is = new ItemStack(Material.BLAZE_ROD); + is.addUnsafeEnchantment(Enchantment.ARROW_INFINITE, 1); + ItemMeta im = is.getItemMeta(); + im.setDisplayName(C.BOLD + "" + C.GOLD + "Wand of Iris"); + im.setUnbreakable(true); + im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_PLACED_ON, ItemFlag.HIDE_POTION_EFFECTS, ItemFlag.HIDE_DESTROYS, ItemFlag.HIDE_ENCHANTS); + im.setLore(new KList().add(locationToString(a), locationToString(b))); + is.setItemMeta(im); + + return is; + } + + /** + * Get a pair of locations that are selected in an Iris wand + * + * @param is The wand item + * @return An array with the 2 locations + */ + public static Location[] getCuboid(ItemStack is) { + ItemMeta im = is.getItemMeta(); + return new Location[]{stringToLocation(im.getLore().get(0)), stringToLocation(im.getLore().get(1))}; + } + + /** + * Is a player holding an Iris wand + * + * @param p The player + * @return True if they are + */ + public static boolean isHoldingWand(Player p) { + ItemStack is = p.getInventory().getItemInMainHand(); + return is != null && isWand(is); + } + + /** + * Is the itemstack passed an Iris wand + * + * @param is The itemstack + * @return True if it is + */ + public static boolean isWand(ItemStack is) { + ItemStack wand = createWand(); + if (is.getItemMeta() == null) return false; + return is.getType().equals(wand.getType()) && + is.getItemMeta().getDisplayName().equals(wand.getItemMeta().getDisplayName()) && + is.getItemMeta().getEnchants().equals(wand.getItemMeta().getEnchants()) && + is.getItemMeta().getItemFlags().equals(wand.getItemMeta().getItemFlags()); + } + @Override public void onEnable() { wand = createWand(); @@ -200,124 +403,6 @@ public class WandSVC implements IrisService { } } - public static void pasteSchematic(IrisObject s, Location at) { - s.place(at); - } - - /** - * Creates an Iris Object from the 2 coordinates selected with a wand - * - * @param wand The wand itemstack - * @return The new object - */ - public static IrisObject createSchematic(ItemStack wand) { - if (!isWand(wand)) { - return null; - } - - try { - Location[] f = getCuboid(wand); - Cuboid c = new Cuboid(f[0], f[1]); - IrisObject s = new IrisObject(c.getSizeX(), c.getSizeY(), c.getSizeZ()); - for (Block b : c) { - if (b.getType().equals(Material.AIR)) { - continue; - } - - BlockVector bv = b.getLocation().subtract(c.getLowerNE().toVector()).toVector().toBlockVector(); - s.setUnsigned(bv.getBlockX(), bv.getBlockY(), bv.getBlockZ(), b); - } - - return s; - } catch (Throwable e) { - e.printStackTrace(); - Iris.reportError(e); - } - - return null; - } - - /** - * Creates an Iris Object from the 2 coordinates selected with a wand - * - * @param wand The wand itemstack - * @return The new object - */ - public static Matter createMatterSchem(Player p, ItemStack wand) { - if (!isWand(wand)) { - return null; - } - - try { - Location[] f = getCuboid(wand); - - return WorldMatter.createMatter(p.getName(), f[0], f[1]); - } catch (Throwable e) { - e.printStackTrace(); - Iris.reportError(e); - } - - return null; - } - - /** - * Converts a user friendly location string to an actual Location - * - * @param s The string - * @return The location - */ - public static Location stringToLocation(String s) { - try { - String[] f = s.split("\\Q in \\E"); - String[] g = f[0].split("\\Q,\\E"); - return new Location(Bukkit.getWorld(f[1]), Integer.parseInt(g[0]), Integer.parseInt(g[1]), Integer.parseInt(g[2])); - } catch (Throwable e) { - Iris.reportError(e); - return null; - } - } - - /** - * Get a user friendly string of a location - * - * @param loc The location - * @return The string - */ - public static String locationToString(Location loc) { - if (loc == null) { - return "<#>"; - } - - return loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ() + " in " + loc.getWorld().getName(); - } - - /** - * Create a new blank Iris wand - * - * @return The wand itemstack - */ - public static ItemStack createWand() { - return createWand(null, null); - } - - /** - * Create a new dust itemstack - * - * @return The stack - */ - public static ItemStack createDust() { - ItemStack is = new ItemStack(Material.GLOWSTONE_DUST); - is.addUnsafeEnchantment(Enchantment.ARROW_INFINITE, 1); - ItemMeta im = is.getItemMeta(); - im.setDisplayName(C.BOLD + "" + C.YELLOW + "Dust of Revealing"); - im.setUnbreakable(true); - im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_PLACED_ON, ItemFlag.HIDE_POTION_EFFECTS, ItemFlag.HIDE_DESTROYS, ItemFlag.HIDE_ENCHANTS); - im.setLore(new KList().qadd("Right click on a block to reveal it's placement structure!")); - is.setItemMeta(im); - - return is; - } - /** * Is the player holding Dust? * @@ -361,85 +446,4 @@ public class WandSVC implements IrisService { return createWand(left ? a : other, left ? other : a); } - - /** - * Finds an existing wand in a users inventory - * - * @param inventory The inventory to search - * @return The slot number the wand is in. Or -1 if none are found - */ - public static int findWand(Inventory inventory) { - ItemStack wand = createWand(); //Create blank wand - ItemMeta meta = wand.getItemMeta(); - meta.setLore(new ArrayList<>()); //We are resetting the lore as the lore differs between wands - wand.setItemMeta(meta); - - for (int s = 0; s < inventory.getSize(); s++) { - ItemStack stack = inventory.getItem(s); - if (stack == null) continue; - meta = stack.getItemMeta(); - meta.setLore(new ArrayList<>()); //Reset the lore on this too so we can compare them - stack.setItemMeta(meta); //We dont need to clone the item as items from .get are cloned - - if (wand.isSimilar(stack)) return s; //If the name, material and NBT is the same - } - return -1; - } - - /** - * Creates an Iris wand. The locations should be the currently selected locations, or null - * - * @param a Location A - * @param b Location B - * @return A new wand - */ - public static ItemStack createWand(Location a, Location b) { - ItemStack is = new ItemStack(Material.BLAZE_ROD); - is.addUnsafeEnchantment(Enchantment.ARROW_INFINITE, 1); - ItemMeta im = is.getItemMeta(); - im.setDisplayName(C.BOLD + "" + C.GOLD + "Wand of Iris"); - im.setUnbreakable(true); - im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_PLACED_ON, ItemFlag.HIDE_POTION_EFFECTS, ItemFlag.HIDE_DESTROYS, ItemFlag.HIDE_ENCHANTS); - im.setLore(new KList().add(locationToString(a), locationToString(b))); - is.setItemMeta(im); - - return is; - } - - /** - * Get a pair of locations that are selected in an Iris wand - * - * @param is The wand item - * @return An array with the 2 locations - */ - public static Location[] getCuboid(ItemStack is) { - ItemMeta im = is.getItemMeta(); - return new Location[]{stringToLocation(im.getLore().get(0)), stringToLocation(im.getLore().get(1))}; - } - - /** - * Is a player holding an Iris wand - * - * @param p The player - * @return True if they are - */ - public static boolean isHoldingWand(Player p) { - ItemStack is = p.getInventory().getItemInMainHand(); - return is != null && isWand(is); - } - - /** - * Is the itemstack passed an Iris wand - * - * @param is The itemstack - * @return True if it is - */ - public static boolean isWand(ItemStack is) { - ItemStack wand = createWand(); - if (is.getItemMeta() == null) return false; - return is.getType().equals(wand.getType()) && - is.getItemMeta().getDisplayName().equals(wand.getItemMeta().getDisplayName()) && - is.getItemMeta().getEnchants().equals(wand.getItemMeta().getEnchants()) && - is.getItemMeta().getItemFlags().equals(wand.getItemMeta().getItemFlags()); - } } diff --git a/src/main/java/com/volmit/iris/core/tools/IrisCreator.java b/src/main/java/com/volmit/iris/core/tools/IrisCreator.java index 52cc30c97..f05b8752b 100644 --- a/src/main/java/com/volmit/iris/core/tools/IrisCreator.java +++ b/src/main/java/com/volmit/iris/core/tools/IrisCreator.java @@ -28,19 +28,21 @@ import com.volmit.iris.engine.platform.PlatformChunkGenerator; import com.volmit.iris.util.exceptions.IrisException; import com.volmit.iris.util.format.C; import com.volmit.iris.util.format.Form; -import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.plugin.VolmitSender; import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.O; import lombok.Data; import lombok.experimental.Accessors; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.GameRule; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.WorldCreator; import java.io.File; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Consumer; import java.util.function.Supplier; /** @@ -122,13 +124,9 @@ public class IrisCreator { { int req = 441; Supplier g = () -> { - try - { + try { return finalAccess1.getEngine().getGenerated(); - } - - catch(Throwable e) - { + } catch (Throwable e) { return 0; } }; diff --git a/src/main/java/com/volmit/iris/core/wand/WandSelection.java b/src/main/java/com/volmit/iris/core/wand/WandSelection.java index 1a85cbd00..7554b58f8 100644 --- a/src/main/java/com/volmit/iris/core/wand/WandSelection.java +++ b/src/main/java/com/volmit/iris/core/wand/WandSelection.java @@ -26,7 +26,7 @@ import org.bukkit.Particle; import org.bukkit.entity.Player; import org.bukkit.util.Vector; -import java.awt.*; +import java.awt.Color; public class WandSelection { private final Cuboid c; diff --git a/src/main/java/com/volmit/iris/engine/IrisComplex.java b/src/main/java/com/volmit/iris/engine/IrisComplex.java index 5a3643b8d..0c720c9f6 100644 --- a/src/main/java/com/volmit/iris/engine/IrisComplex.java +++ b/src/main/java/com/volmit/iris/engine/IrisComplex.java @@ -23,7 +23,13 @@ import com.volmit.iris.Iris; import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.engine.data.cache.Cache; import com.volmit.iris.engine.framework.Engine; -import com.volmit.iris.engine.object.*; +import com.volmit.iris.engine.object.InferredType; +import com.volmit.iris.engine.object.IrisBiome; +import com.volmit.iris.engine.object.IrisDecorationPart; +import com.volmit.iris.engine.object.IrisDecorator; +import com.volmit.iris.engine.object.IrisFeaturePositional; +import com.volmit.iris.engine.object.IrisGenerator; +import com.volmit.iris.engine.object.IrisRegion; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.data.DataProvider; @@ -41,11 +47,11 @@ import java.util.UUID; @Data public class IrisComplex implements DataProvider { + private static final BlockData AIR = Material.AIR.createBlockData(); private RNG rng; private double fluidHeight; private IrisData data; private KList generators; - private static final BlockData AIR = Material.AIR.createBlockData(); private ProceduralStream regionStream; private ProceduralStream regionStyleStream; private ProceduralStream regionIdentityStream; @@ -81,24 +87,6 @@ public class IrisComplex implements DataProvider { private ProceduralStream fluidStream; private IrisBiome focus; - public ProceduralStream getBiomeStream(InferredType type) { - switch (type) { - case CAVE: - return caveBiomeStream; - case LAND: - return landBiomeStream; - case SEA: - return seaBiomeStream; - case SHORE: - return shoreBiomeStream; - case DEFER: - default: - break; - } - - return null; - } - public IrisComplex(Engine engine) { this(engine, false); } @@ -316,6 +304,24 @@ public class IrisComplex implements DataProvider { //@done } + public ProceduralStream getBiomeStream(InferredType type) { + switch (type) { + case CAVE: + return caveBiomeStream; + case LAND: + return landBiomeStream; + case SEA: + return seaBiomeStream; + case SHORE: + return shoreBiomeStream; + case DEFER: + default: + break; + } + + return null; + } + private IrisRegion findRegion(IrisBiome focus, Engine engine) { for (IrisRegion i : engine.getDimension().getAllRegions(engine)) { if (i.getAllBiomeIds().contains(focus.getLoadKey())) { @@ -327,7 +333,7 @@ public class IrisComplex implements DataProvider { } private IrisDecorator decorateFor(IrisBiome b, double x, double z, IrisDecorationPart part) { - RNG rngc = new RNG(Cache.key(((int)x), ((int)z))); + RNG rngc = new RNG(Cache.key(((int) x), ((int) z))); for (IrisDecorator i : b.getDecorators()) { if (!i.getPartOf().equals(part)) { diff --git a/src/main/java/com/volmit/iris/engine/IrisEngine.java b/src/main/java/com/volmit/iris/engine/IrisEngine.java index 21660fccd..bd761671f 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngine.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngine.java @@ -29,14 +29,25 @@ import com.volmit.iris.engine.actuator.IrisBiomeActuator; import com.volmit.iris.engine.actuator.IrisDecorantActuator; import com.volmit.iris.engine.actuator.IrisTerrainNormalActuator; import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.framework.*; +import com.volmit.iris.engine.framework.Engine; +import com.volmit.iris.engine.framework.EngineEffects; +import com.volmit.iris.engine.framework.EngineMetrics; +import com.volmit.iris.engine.framework.EngineStage; +import com.volmit.iris.engine.framework.EngineTarget; +import com.volmit.iris.engine.framework.EngineWorldManager; +import com.volmit.iris.engine.framework.SeedManager; +import com.volmit.iris.engine.framework.WrongEngineBroException; import com.volmit.iris.engine.mantle.EngineMantle; import com.volmit.iris.engine.modifier.IrisBodyModifier; import com.volmit.iris.engine.modifier.IrisCarveModifier; import com.volmit.iris.engine.modifier.IrisDepositModifier; import com.volmit.iris.engine.modifier.IrisPerfectionModifier; import com.volmit.iris.engine.modifier.IrisPostModifier; -import com.volmit.iris.engine.object.*; +import com.volmit.iris.engine.object.IrisBiome; +import com.volmit.iris.engine.object.IrisBiomePaletteLayer; +import com.volmit.iris.engine.object.IrisDecorator; +import com.volmit.iris.engine.object.IrisEngineData; +import com.volmit.iris.engine.object.IrisObjectPlacement; import com.volmit.iris.engine.scripting.EngineExecutionEnvironment; import com.volmit.iris.util.atomics.AtomicRollingSequence; import com.volmit.iris.util.collection.KList; @@ -75,30 +86,30 @@ public class IrisEngine implements Engine { private final AtomicLong lastGPS; private final EngineTarget target; private final IrisContext context; - private EngineEffects effects; private final EngineMantle mantle; private final ChronoLatch perSecondLatch; private final ChronoLatch perSecondBudLatch; - private EngineExecutionEnvironment execution; - private EngineWorldManager worldManager; - private volatile int parallelism; private final EngineMetrics metrics; - private volatile int minHeight; private final boolean studio; - private boolean failing; - private boolean closed; - private int cacheId; private final KList stages; private final AtomicRollingSequence wallClock; private final int art; - private double maxBiomeObjectDensity; - private double maxBiomeLayerDensity; - private double maxBiomeDecoratorDensity; - private IrisComplex complex; private final AtomicCache engineData = new AtomicCache<>(); private final AtomicBoolean cleaning; private final ChronoLatch cleanLatch; private final SeedManager seedManager; + private EngineEffects effects; + private EngineExecutionEnvironment execution; + private EngineWorldManager worldManager; + private volatile int parallelism; + private volatile int minHeight; + private boolean failing; + private boolean closed; + private int cacheId; + private double maxBiomeObjectDensity; + private double maxBiomeLayerDensity; + private double maxBiomeDecoratorDensity; + private IrisComplex complex; public IrisEngine(EngineTarget target, boolean studio) { this.studio = studio; @@ -134,8 +145,7 @@ public class IrisEngine implements Engine { } private void verifySeed() { - if(getEngineData().getSeed() != null && getEngineData().getSeed() != target.getWorld().getRawWorldSeed()) - { + if (getEngineData().getSeed() != null && getEngineData().getSeed() != target.getWorld().getRawWorldSeed()) { target.getWorld().setRawWorldSeed(getEngineData().getSeed()); } } @@ -447,8 +457,7 @@ public class IrisEngine implements Engine { } } } else { - for(EngineStage i : stages) - { + for (EngineStage i : stages) { i.generate(x, z, blocks, vbiomes, multicore); } } diff --git a/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java b/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java index 695f1b437..a16f20ddb 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java @@ -23,8 +23,19 @@ import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.mantle.EngineMantle; import com.volmit.iris.engine.mantle.MantleComponent; -import com.volmit.iris.engine.mantle.components.*; -import com.volmit.iris.engine.object.*; +import com.volmit.iris.engine.mantle.components.MantleCarvingComponent; +import com.volmit.iris.engine.mantle.components.MantleFeatureComponent; +import com.volmit.iris.engine.mantle.components.MantleFluidBodyComponent; +import com.volmit.iris.engine.mantle.components.MantleJigsawComponent; +import com.volmit.iris.engine.mantle.components.MantleObjectComponent; +import com.volmit.iris.engine.object.IrisBiome; +import com.volmit.iris.engine.object.IrisDepositGenerator; +import com.volmit.iris.engine.object.IrisFeaturePotential; +import com.volmit.iris.engine.object.IrisJigsawStructurePlacement; +import com.volmit.iris.engine.object.IrisObject; +import com.volmit.iris.engine.object.IrisObjectPlacement; +import com.volmit.iris.engine.object.IrisObjectScale; +import com.volmit.iris.engine.object.IrisRegion; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.collection.KSet; diff --git a/src/main/java/com/volmit/iris/engine/IrisWorldManager.java b/src/main/java/com/volmit/iris/engine/IrisWorldManager.java index be850807f..5705e3439 100644 --- a/src/main/java/com/volmit/iris/engine/IrisWorldManager.java +++ b/src/main/java/com/volmit/iris/engine/IrisWorldManager.java @@ -22,7 +22,15 @@ import com.volmit.iris.Iris; import com.volmit.iris.engine.data.cache.Cache; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.framework.EngineAssignedWorldManager; -import com.volmit.iris.engine.object.*; +import com.volmit.iris.engine.object.IRare; +import com.volmit.iris.engine.object.IrisBiome; +import com.volmit.iris.engine.object.IrisBlockDrops; +import com.volmit.iris.engine.object.IrisEngineChunkData; +import com.volmit.iris.engine.object.IrisEngineData; +import com.volmit.iris.engine.object.IrisEngineSpawnerCooldown; +import com.volmit.iris.engine.object.IrisEntitySpawn; +import com.volmit.iris.engine.object.IrisRegion; +import com.volmit.iris.engine.object.IrisSpawner; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.format.Form; @@ -56,13 +64,13 @@ public class IrisWorldManager extends EngineAssignedWorldManager { private final int id; private final KMap chunkCooldowns; private final KList updateQueue = new KList<>(); - private double energy = 25; - private int entityCount = 0; private final ChronoLatch cl; private final ChronoLatch clw; private final ChronoLatch ecl; private final ChronoLatch cln; private final ChronoLatch chunkUpdater; + private double energy = 25; + private int entityCount = 0; private long charge = 0; private int actuallySpawned = 0; private int cooldown = 0; diff --git a/src/main/java/com/volmit/iris/engine/actuator/IrisDecorantActuator.java b/src/main/java/com/volmit/iris/engine/actuator/IrisDecorantActuator.java index c94f96588..a75f9ea02 100644 --- a/src/main/java/com/volmit/iris/engine/actuator/IrisDecorantActuator.java +++ b/src/main/java/com/volmit/iris/engine/actuator/IrisDecorantActuator.java @@ -18,7 +18,11 @@ package com.volmit.iris.engine.actuator; -import com.volmit.iris.engine.decorator.*; +import com.volmit.iris.engine.decorator.IrisCeilingDecorator; +import com.volmit.iris.engine.decorator.IrisSeaFloorDecorator; +import com.volmit.iris.engine.decorator.IrisSeaSurfaceDecorator; +import com.volmit.iris.engine.decorator.IrisShoreLineDecorator; +import com.volmit.iris.engine.decorator.IrisSurfaceDecorator; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.framework.EngineAssignedActuator; import com.volmit.iris.engine.framework.EngineDecorator; diff --git a/src/main/java/com/volmit/iris/engine/data/cache/Cache.java b/src/main/java/com/volmit/iris/engine/data/cache/Cache.java index f99bfa309..c549d450a 100644 --- a/src/main/java/com/volmit/iris/engine/data/cache/Cache.java +++ b/src/main/java/com/volmit/iris/engine/data/cache/Cache.java @@ -25,10 +25,6 @@ public interface Cache { return key(chunk.getX(), chunk.getZ()); } - int getId(); - - V get(int x, int z); - static long key(int x, int z) { return (((long) x) << 32) | (z & 0xffffffffL); } @@ -52,4 +48,8 @@ public interface Cache { final int x = idx % w; return new int[]{x, y, z}; } + + int getId(); + + V get(int x, int z); } diff --git a/src/main/java/com/volmit/iris/engine/data/chunk/LinkedTerrainChunk.java b/src/main/java/com/volmit/iris/engine/data/chunk/LinkedTerrainChunk.java index f82dde7f8..7bc829aa9 100644 --- a/src/main/java/com/volmit/iris/engine/data/chunk/LinkedTerrainChunk.java +++ b/src/main/java/com/volmit/iris/engine/data/chunk/LinkedTerrainChunk.java @@ -34,8 +34,8 @@ import org.bukkit.material.MaterialData; @SuppressWarnings("deprecation") public class LinkedTerrainChunk implements TerrainChunk { private final IrisBiomeStorage biome3D; - private ChunkData rawChunkData; private final BiomeGrid storage; + private ChunkData rawChunkData; @Setter private boolean unsafe = false; diff --git a/src/main/java/com/volmit/iris/engine/data/chunk/MCATerrainChunk.java b/src/main/java/com/volmit/iris/engine/data/chunk/MCATerrainChunk.java index a461dbb48..449b85567 100644 --- a/src/main/java/com/volmit/iris/engine/data/chunk/MCATerrainChunk.java +++ b/src/main/java/com/volmit/iris/engine/data/chunk/MCATerrainChunk.java @@ -46,18 +46,11 @@ public class MCATerrainChunk implements TerrainChunk { return injector; } - @Override - public void setRaw(ChunkGenerator.ChunkData data) { - - } - - @Override public Biome getBiome(int x, int z) { return Biome.THE_VOID; } - @Override public Biome getBiome(int x, int y, int z) { return Biome.THE_VOID; @@ -99,7 +92,6 @@ public class MCATerrainChunk implements TerrainChunk { mcaChunk.setBlockStateAt(xx, y, zz, NBTWorld.getCompound(blockData), false); } - @Override public org.bukkit.block.data.BlockData getBlockData(int x, int y, int z) { if (y > getMaxHeight()) { @@ -118,6 +110,11 @@ public class MCATerrainChunk implements TerrainChunk { return null; } + @Override + public void setRaw(ChunkGenerator.ChunkData data) { + + } + @Override public void inject(ChunkGenerator.BiomeGrid biome) { diff --git a/src/main/java/com/volmit/iris/engine/data/chunk/TerrainChunk.java b/src/main/java/com/volmit/iris/engine/data/chunk/TerrainChunk.java index 62c64b4e2..adfb30fe3 100644 --- a/src/main/java/com/volmit/iris/engine/data/chunk/TerrainChunk.java +++ b/src/main/java/com/volmit/iris/engine/data/chunk/TerrainChunk.java @@ -46,8 +46,6 @@ public interface TerrainChunk extends BiomeGrid, ChunkData { BiomeBaseInjector getBiomeBaseInjector(); - void setRaw(ChunkData data); - /** * Get biome at x, z within chunk being generated * @@ -129,5 +127,7 @@ public interface TerrainChunk extends BiomeGrid, ChunkData { ChunkData getRaw(); + void setRaw(ChunkData data); + void inject(BiomeGrid biome); } diff --git a/src/main/java/com/volmit/iris/engine/data/io/Deserializer.java b/src/main/java/com/volmit/iris/engine/data/io/Deserializer.java index 40bae9763..183886689 100644 --- a/src/main/java/com/volmit/iris/engine/data/io/Deserializer.java +++ b/src/main/java/com/volmit/iris/engine/data/io/Deserializer.java @@ -18,7 +18,12 @@ package com.volmit.iris.engine.data.io; -import java.io.*; +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; import java.net.URL; public interface Deserializer { diff --git a/src/main/java/com/volmit/iris/engine/data/io/Serializer.java b/src/main/java/com/volmit/iris/engine/data/io/Serializer.java index e140d6298..0e0102282 100644 --- a/src/main/java/com/volmit/iris/engine/data/io/Serializer.java +++ b/src/main/java/com/volmit/iris/engine/data/io/Serializer.java @@ -18,7 +18,12 @@ package com.volmit.iris.engine.data.io; -import java.io.*; +import java.io.BufferedOutputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; public interface Serializer { diff --git a/src/main/java/com/volmit/iris/engine/data/io/StringDeserializer.java b/src/main/java/com/volmit/iris/engine/data/io/StringDeserializer.java index 065e6e3e1..59321afba 100644 --- a/src/main/java/com/volmit/iris/engine/data/io/StringDeserializer.java +++ b/src/main/java/com/volmit/iris/engine/data/io/StringDeserializer.java @@ -18,7 +18,13 @@ package com.volmit.iris.engine.data.io; -import java.io.*; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; public interface StringDeserializer extends Deserializer { diff --git a/src/main/java/com/volmit/iris/engine/data/io/StringSerializer.java b/src/main/java/com/volmit/iris/engine/data/io/StringSerializer.java index 389c64e29..c1a482017 100644 --- a/src/main/java/com/volmit/iris/engine/data/io/StringSerializer.java +++ b/src/main/java/com/volmit/iris/engine/data/io/StringSerializer.java @@ -18,7 +18,13 @@ package com.volmit.iris.engine.data.io; -import java.io.*; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.StringWriter; +import java.io.Writer; public interface StringSerializer extends Serializer { 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 3b3968cc0..9a0f50999 100644 --- a/src/main/java/com/volmit/iris/engine/framework/Engine.java +++ b/src/main/java/com/volmit/iris/engine/framework/Engine.java @@ -26,7 +26,18 @@ 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.*; +import com.volmit.iris.engine.object.InventorySlotType; +import com.volmit.iris.engine.object.IrisBiome; +import com.volmit.iris.engine.object.IrisColor; +import com.volmit.iris.engine.object.IrisDimension; +import com.volmit.iris.engine.object.IrisEngineData; +import com.volmit.iris.engine.object.IrisLootMode; +import com.volmit.iris.engine.object.IrisLootReference; +import com.volmit.iris.engine.object.IrisLootTable; +import com.volmit.iris.engine.object.IrisObjectPlacement; +import com.volmit.iris.engine.object.IrisPosition; +import com.volmit.iris.engine.object.IrisRegion; +import com.volmit.iris.engine.object.IrisWorld; import com.volmit.iris.engine.scripting.EngineExecutionEnvironment; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; @@ -63,7 +74,7 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; -import java.awt.*; +import java.awt.Color; import java.util.Arrays; import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; @@ -75,7 +86,7 @@ import java.util.function.Consumer; public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdater, Renderer, Hotloadable { KList getStages(); - public void registerStage(EngineStage stage); + void registerStage(EngineStage stage); IrisComplex getComplex(); @@ -107,22 +118,22 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat EngineWorldManager getWorldManager(); - void setParallelism(int parallelism); - default UUID getBiomeID(int x, int z) { return getComplex().getBaseBiomeIDStream().get(x, z); } int getParallelism(); - EngineTarget getTarget(); + void setParallelism(int parallelism); - void setMinHeight(int min); + EngineTarget getTarget(); default int getMinHeight() { return getTarget().getWorld().minHeight(); } + void setMinHeight(int min); + @BlockCoordinates double modifyX(double x); diff --git a/src/main/java/com/volmit/iris/engine/framework/EngineData.java b/src/main/java/com/volmit/iris/engine/framework/EngineData.java index 0228616d7..5dc173a8e 100644 --- a/src/main/java/com/volmit/iris/engine/framework/EngineData.java +++ b/src/main/java/com/volmit/iris/engine/framework/EngineData.java @@ -34,16 +34,6 @@ public class EngineData { private String lastVersion; private List strongholdPositions; - public void save(File f) { - try { - f.getParentFile().mkdirs(); - IO.writeAll(f, new Gson().toJson(this)); - } catch (IOException e) { - Iris.reportError(e); - e.printStackTrace(); - } - } - public static EngineData load(File f) { try { f.getParentFile().mkdirs(); @@ -55,4 +45,14 @@ public class EngineData { return new EngineData(); } + + public void save(File f) { + try { + f.getParentFile().mkdirs(); + IO.writeAll(f, new Gson().toJson(this)); + } catch (IOException e) { + Iris.reportError(e); + e.printStackTrace(); + } + } } diff --git a/src/main/java/com/volmit/iris/engine/framework/EngineStage.java b/src/main/java/com/volmit/iris/engine/framework/EngineStage.java index 4b13499b8..21d7e541a 100644 --- a/src/main/java/com/volmit/iris/engine/framework/EngineStage.java +++ b/src/main/java/com/volmit/iris/engine/framework/EngineStage.java @@ -28,8 +28,7 @@ public interface EngineStage { void generate(int x, int z, Hunk blocks, Hunk biomes, boolean multicore); default void close() { - if(this instanceof EngineComponent c) - { + if (this instanceof EngineComponent c) { c.close(); } } diff --git a/src/main/java/com/volmit/iris/engine/framework/EngineTarget.java b/src/main/java/com/volmit/iris/engine/framework/EngineTarget.java index 2bb7db7c2..a3164d026 100644 --- a/src/main/java/com/volmit/iris/engine/framework/EngineTarget.java +++ b/src/main/java/com/volmit/iris/engine/framework/EngineTarget.java @@ -27,9 +27,9 @@ import lombok.Data; @Data public class EngineTarget { private final MultiBurst burster; + private final IrisData data; private IrisDimension dimension; private IrisWorld world; - private final IrisData data; public EngineTarget(IrisWorld world, IrisDimension dimension, IrisData data) { this.world = world; diff --git a/src/main/java/com/volmit/iris/engine/framework/SeedManager.java b/src/main/java/com/volmit/iris/engine/framework/SeedManager.java index 8bb3d0036..d4051b5fe 100644 --- a/src/main/java/com/volmit/iris/engine/framework/SeedManager.java +++ b/src/main/java/com/volmit/iris/engine/framework/SeedManager.java @@ -23,19 +23,14 @@ import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.noise.CNG; import lombok.AccessLevel; import lombok.Data; -import lombok.Getter; import lombok.Setter; @Data -public class SeedManager -{ +public class SeedManager { //////////////////////////////////////////////////////////////////// private static final String IRIS_SIGNATURE = "Iris World Generator"; private static final long IRIS_TERRAIN_VERSION = 1; //////////////////////////////////////////////////////////////////// - - @Setter(AccessLevel.NONE) - private long fullMixedSeed; private final RNG rlock; private final CNG soup; private final long seed; @@ -56,9 +51,10 @@ public class SeedManager private final long deposit; private final long post; private final long bodies; + @Setter(AccessLevel.NONE) + private long fullMixedSeed; - public SeedManager(long seed) - { + public SeedManager(long seed) { soup = createSoup(seed); rlock = new RNG(Double.doubleToLongBits(soup.fitDouble(Double.MIN_VALUE, Double.MAX_VALUE, seed + 1337, seed * 69, seed))); this.seed = seed; @@ -81,8 +77,7 @@ public class SeedManager bodies = of("bodies"); } - private long of(String name) - { + private long of(String name) { RNG rng = new RNG(name + IRIS_SIGNATURE + "::" + IRIS_TERRAIN_VERSION + ((seed + rlock.imax()) * rlock.lmax())); long f = rlock.imax() * ((rlock.chance(0.5) ? 1 : -1) * (name.hashCode() + Double.doubleToLongBits(soup.fitDouble(Double.MIN_VALUE, Double.MAX_VALUE, rng.imax(), rng.imax(), rng.imax())))); fullMixedSeed += (f * rlock.imax()); @@ -97,8 +92,7 @@ public class SeedManager RNG e = new RNG((IRIS_TERRAIN_VERSION * 42) + IRIS_SIGNATURE); double gsoup = 0; int gk = a.i(1_000, 10_000); - for(char i : (a.s(4) + b.s(4) + c.s(4) + d.s(4) + e.s(4)).toCharArray()) - { + for (char i : (a.s(4) + b.s(4) + c.s(4) + d.s(4) + e.s(4)).toCharArray()) { gsoup += ((gk * b.d(3, Math.PI)) / c.d(10, 18 * Math.E)) + 6_549; gsoup *= d.d(90.5, 1_234_567); gsoup += e.d(39.95, 99.25); diff --git a/src/main/java/com/volmit/iris/engine/jigsaw/PlannedPiece.java b/src/main/java/com/volmit/iris/engine/jigsaw/PlannedPiece.java index 5df15341f..70c08985d 100644 --- a/src/main/java/com/volmit/iris/engine/jigsaw/PlannedPiece.java +++ b/src/main/java/com/volmit/iris/engine/jigsaw/PlannedPiece.java @@ -21,7 +21,16 @@ package com.volmit.iris.engine.jigsaw; import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.engine.framework.Engine; -import com.volmit.iris.engine.object.*; +import com.volmit.iris.engine.object.IObjectPlacer; +import com.volmit.iris.engine.object.InventorySlotType; +import com.volmit.iris.engine.object.IrisJigsawPiece; +import com.volmit.iris.engine.object.IrisJigsawPieceConnector; +import com.volmit.iris.engine.object.IrisLootTable; +import com.volmit.iris.engine.object.IrisObject; +import com.volmit.iris.engine.object.IrisObjectRotation; +import com.volmit.iris.engine.object.IrisObjectTranslate; +import com.volmit.iris.engine.object.IrisPosition; +import com.volmit.iris.engine.object.TileData; import com.volmit.iris.engine.platform.PlatformChunkGenerator; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.math.AxisAlignedBB; diff --git a/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java b/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java index 0bc6cd63f..4e33c90aa 100644 --- a/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java +++ b/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java @@ -22,7 +22,19 @@ import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap; import com.volmit.iris.Iris; import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.engine.data.cache.Cache; -import com.volmit.iris.engine.object.*; +import com.volmit.iris.engine.object.IObjectPlacer; +import com.volmit.iris.engine.object.IrisDirection; +import com.volmit.iris.engine.object.IrisFeature; +import com.volmit.iris.engine.object.IrisFeaturePositional; +import com.volmit.iris.engine.object.IrisFeaturePotential; +import com.volmit.iris.engine.object.IrisJigsawPiece; +import com.volmit.iris.engine.object.IrisJigsawPieceConnector; +import com.volmit.iris.engine.object.IrisJigsawStructure; +import com.volmit.iris.engine.object.IrisObject; +import com.volmit.iris.engine.object.IrisObjectPlacement; +import com.volmit.iris.engine.object.IrisObjectRotation; +import com.volmit.iris.engine.object.IrisPosition; +import com.volmit.iris.engine.object.ObjectPlaceMode; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.interpolation.InterpolationMethod; import com.volmit.iris.util.mantle.Mantle; @@ -35,6 +47,12 @@ import java.util.function.Consumer; @Data public class PlannedStructure { + private static transient ConcurrentLinkedHashMap objectRotationCache + = new ConcurrentLinkedHashMap.Builder() + .initialCapacity(64) + .maximumWeightedCapacity(1024) + .concurrencyLevel(32) + .build(); private KList pieces; private IrisJigsawStructure structure; private IrisPosition position; @@ -42,12 +60,6 @@ public class PlannedStructure { private RNG rng; private boolean verbose; private boolean terminating; - private static transient ConcurrentLinkedHashMap objectRotationCache - = new ConcurrentLinkedHashMap.Builder() - .initialCapacity(64) - .maximumWeightedCapacity(1024) - .concurrencyLevel(32) - .build(); public PlannedStructure(IrisJigsawStructure structure, IrisPosition position, RNG rng) { terminating = false; @@ -137,12 +149,9 @@ public class PlannedStructure { e.set(xx, 0, zz, new IrisFeaturePositional(xx, zz, f)); } - if(options.getAddFeatures().isNotEmpty()) - { - for (IrisFeaturePotential j : options.getAddFeatures()) - { - if(rngf.nextInt(j.getRarity()) == 0) - { + if (options.getAddFeatures().isNotEmpty()) { + for (IrisFeaturePotential j : options.getAddFeatures()) { + if (rngf.nextInt(j.getRarity()) == 0) { e.set(xx, 0, zz, new IrisFeaturePositional(xx, zz, j.getZone())); } } diff --git a/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java b/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java index 936520b9c..43f8b60fb 100644 --- a/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java +++ b/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java @@ -23,7 +23,11 @@ import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.engine.IrisComplex; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.framework.EngineTarget; -import com.volmit.iris.engine.object.*; +import com.volmit.iris.engine.object.IObjectPlacer; +import com.volmit.iris.engine.object.IrisDimension; +import com.volmit.iris.engine.object.IrisFeaturePositional; +import com.volmit.iris.engine.object.IrisPosition; +import com.volmit.iris.engine.object.TileData; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.data.B; import com.volmit.iris.util.documentation.BlockCoordinates; diff --git a/src/main/java/com/volmit/iris/engine/mantle/MantleWriter.java b/src/main/java/com/volmit/iris/engine/mantle/MantleWriter.java index e8b8c9030..fda423046 100644 --- a/src/main/java/com/volmit/iris/engine/mantle/MantleWriter.java +++ b/src/main/java/com/volmit/iris/engine/mantle/MantleWriter.java @@ -65,6 +65,62 @@ public class MantleWriter implements IObjectPlacer { } } + private static Set getBallooned(Set vset, double radius) { + Set returnset = new HashSet<>(); + int ceilrad = (int) Math.ceil(radius); + + for (IrisPosition v : vset) { + int tipx = v.getX(); + int tipy = v.getY(); + int tipz = v.getZ(); + + for (int loopx = tipx - ceilrad; loopx <= tipx + ceilrad; loopx++) { + for (int loopy = tipy - ceilrad; loopy <= tipy + ceilrad; loopy++) { + for (int loopz = tipz - ceilrad; loopz <= tipz + ceilrad; loopz++) { + if (hypot(loopx - tipx, loopy - tipy, loopz - tipz) <= radius) { + returnset.add(new IrisPosition(loopx, loopy, loopz)); + } + } + } + } + } + return returnset; + } + + private static Set getHollowed(Set vset) { + Set returnset = new KSet<>(); + for (IrisPosition v : vset) { + double x = v.getX(); + double y = v.getY(); + double z = v.getZ(); + if (!(vset.contains(new IrisPosition(x + 1, y, z)) + && vset.contains(new IrisPosition(x - 1, y, z)) + && vset.contains(new IrisPosition(x, y + 1, z)) + && vset.contains(new IrisPosition(x, y - 1, z)) + && vset.contains(new IrisPosition(x, y, z + 1)) + && vset.contains(new IrisPosition(x, y, z - 1)))) { + returnset.add(v); + } + } + return returnset; + } + + private static double hypot(double... pars) { + double sum = 0; + for (double d : pars) { + sum += Math.pow(d, 2); + } + return Math.sqrt(sum); + } + + private static double lengthSq(double x, double y, double z) { + return (x * x) + (y * y) + (z * z); + } + + private static double lengthSq(double x, double z) { + return (x * x) + (z * z); + } + public void setData(int x, int y, int z, T t) { if (t == null) { return; @@ -307,7 +363,6 @@ public class MantleWriter implements IObjectPlacer { setLine(ImmutableList.of(a, b), radius, filled, data); } - public void setLine(List vectors, double radius, boolean filled, T data) { setLineConsumer(vectors, radius, filled, (_x, _y, _z) -> data); } @@ -489,62 +544,6 @@ public class MantleWriter implements IObjectPlacer { } } - private static Set getBallooned(Set vset, double radius) { - Set returnset = new HashSet<>(); - int ceilrad = (int) Math.ceil(radius); - - for (IrisPosition v : vset) { - int tipx = v.getX(); - int tipy = v.getY(); - int tipz = v.getZ(); - - for (int loopx = tipx - ceilrad; loopx <= tipx + ceilrad; loopx++) { - for (int loopy = tipy - ceilrad; loopy <= tipy + ceilrad; loopy++) { - for (int loopz = tipz - ceilrad; loopz <= tipz + ceilrad; loopz++) { - if (hypot(loopx - tipx, loopy - tipy, loopz - tipz) <= radius) { - returnset.add(new IrisPosition(loopx, loopy, loopz)); - } - } - } - } - } - return returnset; - } - - private static Set getHollowed(Set vset) { - Set returnset = new KSet<>(); - for (IrisPosition v : vset) { - double x = v.getX(); - double y = v.getY(); - double z = v.getZ(); - if (!(vset.contains(new IrisPosition(x + 1, y, z)) - && vset.contains(new IrisPosition(x - 1, y, z)) - && vset.contains(new IrisPosition(x, y + 1, z)) - && vset.contains(new IrisPosition(x, y - 1, z)) - && vset.contains(new IrisPosition(x, y, z + 1)) - && vset.contains(new IrisPosition(x, y, z - 1)))) { - returnset.add(v); - } - } - return returnset; - } - - private static double hypot(double... pars) { - double sum = 0; - for (double d : pars) { - sum += Math.pow(d, 2); - } - return Math.sqrt(sum); - } - - private static double lengthSq(double x, double y, double z) { - return (x * x) + (y * y) + (z * z); - } - - private static double lengthSq(double x, double z) { - return (x * x) + (z * z); - } - public boolean isWithin(Vector pos) { return isWithin(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()); } diff --git a/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java b/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java index fcf206a31..d8dfcafc4 100644 --- a/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java +++ b/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java @@ -23,7 +23,13 @@ import com.volmit.iris.engine.jigsaw.PlannedStructure; import com.volmit.iris.engine.mantle.EngineMantle; import com.volmit.iris.engine.mantle.IrisMantleComponent; import com.volmit.iris.engine.mantle.MantleWriter; -import com.volmit.iris.engine.object.*; +import com.volmit.iris.engine.object.IrisBiome; +import com.volmit.iris.engine.object.IrisFeaturePositional; +import com.volmit.iris.engine.object.IrisJigsawStructure; +import com.volmit.iris.engine.object.IrisJigsawStructurePlacement; +import com.volmit.iris.engine.object.IrisPosition; +import com.volmit.iris.engine.object.IrisRegion; +import com.volmit.iris.engine.object.NoiseStyle; import com.volmit.iris.util.documentation.BlockCoordinates; import com.volmit.iris.util.documentation.ChunkCoordinates; import com.volmit.iris.util.mantle.MantleFlag; @@ -112,8 +118,7 @@ public class MantleJigsawComponent extends IrisMantleComponent { writer.setData(position.getX(), 0, position.getZ(), new IrisFeaturePositional(position.getX(), position.getZ(), structure.getFeature())); - if(structure.getFeature().getEntitySpawners().isNotEmpty()) - { + if (structure.getFeature().getEntitySpawners().isNotEmpty()) { Iris.info("Placed Structure MAIN SPAWN " + structure.getFeature().getEntitySpawners().get(0) + " @R " + structure.getFeature().getBlockRadius()); } } diff --git a/src/main/java/com/volmit/iris/engine/mantle/components/MantleObjectComponent.java b/src/main/java/com/volmit/iris/engine/mantle/components/MantleObjectComponent.java index 73b734521..10b2c22e0 100644 --- a/src/main/java/com/volmit/iris/engine/mantle/components/MantleObjectComponent.java +++ b/src/main/java/com/volmit/iris/engine/mantle/components/MantleObjectComponent.java @@ -23,7 +23,13 @@ import com.volmit.iris.engine.data.cache.Cache; import com.volmit.iris.engine.mantle.EngineMantle; import com.volmit.iris.engine.mantle.IrisMantleComponent; import com.volmit.iris.engine.mantle.MantleWriter; -import com.volmit.iris.engine.object.*; +import com.volmit.iris.engine.object.IrisBiome; +import com.volmit.iris.engine.object.IrisFeature; +import com.volmit.iris.engine.object.IrisFeaturePositional; +import com.volmit.iris.engine.object.IrisFeaturePotential; +import com.volmit.iris.engine.object.IrisObject; +import com.volmit.iris.engine.object.IrisObjectPlacement; +import com.volmit.iris.engine.object.IrisRegion; import com.volmit.iris.util.documentation.BlockCoordinates; import com.volmit.iris.util.documentation.ChunkCoordinates; import com.volmit.iris.util.mantle.MantleFlag; diff --git a/src/main/java/com/volmit/iris/engine/modifier/IrisBodyModifier.java b/src/main/java/com/volmit/iris/engine/modifier/IrisBodyModifier.java index cb36e0a93..0cf9c45ff 100644 --- a/src/main/java/com/volmit/iris/engine/modifier/IrisBodyModifier.java +++ b/src/main/java/com/volmit/iris/engine/modifier/IrisBodyModifier.java @@ -18,35 +18,13 @@ package com.volmit.iris.engine.modifier; -import com.volmit.iris.engine.IrisEngine; -import com.volmit.iris.engine.actuator.IrisDecorantActuator; -import com.volmit.iris.engine.data.cache.Cache; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.framework.EngineAssignedModifier; -import com.volmit.iris.engine.object.InferredType; -import com.volmit.iris.engine.object.IrisBiome; -import com.volmit.iris.engine.object.IrisDecorationPart; -import com.volmit.iris.engine.object.IrisDecorator; -import com.volmit.iris.engine.object.IrisPosition; -import com.volmit.iris.util.collection.KList; -import com.volmit.iris.util.collection.KMap; -import com.volmit.iris.util.data.B; -import com.volmit.iris.util.function.Consumer4; import com.volmit.iris.util.hunk.Hunk; -import com.volmit.iris.util.mantle.Mantle; -import com.volmit.iris.util.mantle.MantleChunk; -import com.volmit.iris.util.math.M; import com.volmit.iris.util.math.RNG; -import com.volmit.iris.util.matter.MatterCavern; -import com.volmit.iris.util.matter.slices.MarkerMatter; -import com.volmit.iris.util.scheduling.PrecisionStopwatch; -import lombok.Data; import org.bukkit.Material; import org.bukkit.block.data.BlockData; -import java.util.Objects; -import java.util.function.Supplier; - public class IrisBodyModifier extends EngineAssignedModifier { private final RNG rng; private final BlockData AIR = Material.CAVE_AIR.createBlockData(); diff --git a/src/main/java/com/volmit/iris/engine/modifier/IrisCarveModifier.java b/src/main/java/com/volmit/iris/engine/modifier/IrisCarveModifier.java index 7b5eddf44..fb5d723c8 100644 --- a/src/main/java/com/volmit/iris/engine/modifier/IrisCarveModifier.java +++ b/src/main/java/com/volmit/iris/engine/modifier/IrisCarveModifier.java @@ -18,12 +18,15 @@ package com.volmit.iris.engine.modifier; -import com.volmit.iris.engine.IrisEngine; import com.volmit.iris.engine.actuator.IrisDecorantActuator; import com.volmit.iris.engine.data.cache.Cache; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.framework.EngineAssignedModifier; -import com.volmit.iris.engine.object.*; +import com.volmit.iris.engine.object.InferredType; +import com.volmit.iris.engine.object.IrisBiome; +import com.volmit.iris.engine.object.IrisDecorationPart; +import com.volmit.iris.engine.object.IrisDecorator; +import com.volmit.iris.engine.object.IrisPosition; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.data.B; diff --git a/src/main/java/com/volmit/iris/engine/modifier/IrisPerfectionModifier.java b/src/main/java/com/volmit/iris/engine/modifier/IrisPerfectionModifier.java index 911cd7a79..a294a24f7 100644 --- a/src/main/java/com/volmit/iris/engine/modifier/IrisPerfectionModifier.java +++ b/src/main/java/com/volmit/iris/engine/modifier/IrisPerfectionModifier.java @@ -18,27 +18,17 @@ package com.volmit.iris.engine.modifier; -import com.volmit.iris.Iris; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.framework.EngineAssignedModifier; -import com.volmit.iris.engine.object.IrisBiome; import com.volmit.iris.util.data.B; -import com.volmit.iris.util.data.HeightMap; -import com.volmit.iris.util.format.Form; import com.volmit.iris.util.hunk.Hunk; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.scheduling.PrecisionStopwatch; -import net.minecraft.world.level.block.TallSeagrassBlock; -import org.bukkit.Material; import org.bukkit.block.data.Bisected; import org.bukkit.block.data.BlockData; -import org.bukkit.block.data.Levelled; -import org.bukkit.block.data.Waterlogged; -import org.bukkit.block.data.type.Slab; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; public class IrisPerfectionModifier extends EngineAssignedModifier { private static final BlockData AIR = B.get("AIR"); @@ -59,87 +49,65 @@ public class IrisPerfectionModifier extends EngineAssignedModifier { List surfaces = new ArrayList<>(); List ceilings = new ArrayList<>(); - while(changed) - { + while (changed) { passes++; changed = false; - for(int i = 0; i < 16; i++) - { - for(int j = 0; j < 16; j++) - { + for (int i = 0; i < 16; i++) { + for (int j = 0; j < 16; j++) { surfaces.clear(); ceilings.clear(); int top = getHeight(output, i, j); boolean inside = true; surfaces.add(top); - for(int k = top; k >= 0; k--) - { + for (int k = top; k >= 0; k--) { BlockData b = output.get(i, k, j); boolean now = b != null && !(B.isAir(b) || B.isFluid(b)); - if(now != inside) - { + if (now != inside) { inside = now; - if(inside) - { + if (inside) { surfaces.add(k); - } - - else - { - ceilings.add(k+1); + } else { + ceilings.add(k + 1); } } } - for(int k : surfaces) - { + for (int k : surfaces) { BlockData tip = output.get(i, k, j); - if(tip == null) - { + if (tip == null) { continue; } boolean remove = false; boolean remove2 = false; - if(B.isDecorant(tip)) - { - BlockData bel = output.get(i, k-1, j); + if (B.isDecorant(tip)) { + BlockData bel = output.get(i, k - 1, j); - if(bel == null) - { + if (bel == null) { remove = true; - } - - else if(!B.canPlaceOnto(tip.getMaterial(), bel.getMaterial())) - { + } else if (!B.canPlaceOnto(tip.getMaterial(), bel.getMaterial())) { remove = true; - } - - else if(bel instanceof Bisected) - { - BlockData bb = output.get(i, k-2, j); - if(bb == null || !B.canPlaceOnto(bel.getMaterial(), bb.getMaterial())) - { + } else if (bel instanceof Bisected) { + BlockData bb = output.get(i, k - 2, j); + if (bb == null || !B.canPlaceOnto(bel.getMaterial(), bb.getMaterial())) { remove = true; remove2 = true; } } - if(remove) - { + if (remove) { changed = true; changes++; output.set(i, k, j, AIR); - if(remove2) - { + if (remove2) { changes++; - output.set(i, k-1, j, AIR); + output.set(i, k - 1, j, AIR); } } } @@ -152,12 +120,10 @@ public class IrisPerfectionModifier extends EngineAssignedModifier { } private int getHeight(Hunk output, int x, int z) { - for(int i = output.getHeight()-1; i >= 0; i--) - { + for (int i = output.getHeight() - 1; i >= 0; i--) { BlockData b = output.get(x, i, z); - if(b != null && !B.isAir(b) && !B.isFluid(b)) - { + if (b != null && !B.isAir(b) && !B.isFluid(b)) { return i; } } diff --git a/src/main/java/com/volmit/iris/engine/object/HeadlessWorld.java b/src/main/java/com/volmit/iris/engine/object/HeadlessWorld.java index 01a552e71..708714c34 100644 --- a/src/main/java/com/volmit/iris/engine/object/HeadlessWorld.java +++ b/src/main/java/com/volmit/iris/engine/object/HeadlessWorld.java @@ -65,6 +65,15 @@ public class HeadlessWorld { } } + public static HeadlessWorld from(World world) { + return new HeadlessWorld(world.getName(), IrisToolbelt.access(world) + .getEngine().getTarget().getDimension(), world.getSeed()); + } + + public static HeadlessWorld from(String name, String dimension, long seed) { + return new HeadlessWorld(name, IrisData.loadAnyDimension(dimension), seed); + } + @SuppressWarnings("ConstantConditions") public HeadlessGenerator generate() { Engine e = null; @@ -92,13 +101,4 @@ public class HeadlessWorld { world.realWorld(w); return w; } - - public static HeadlessWorld from(World world) { - return new HeadlessWorld(world.getName(), IrisToolbelt.access(world) - .getEngine().getTarget().getDimension(), world.getSeed()); - } - - public static HeadlessWorld from(String name, String dimension, long seed) { - return new HeadlessWorld(name, IrisData.loadAnyDimension(dimension), seed); - } } diff --git a/src/main/java/com/volmit/iris/engine/object/IRare.java b/src/main/java/com/volmit/iris/engine/object/IRare.java index 3e2f59f7b..f1c0dda91 100644 --- a/src/main/java/com/volmit/iris/engine/object/IRare.java +++ b/src/main/java/com/volmit/iris/engine/object/IRare.java @@ -19,9 +19,9 @@ package com.volmit.iris.engine.object; public interface IRare { - int getRarity(); - static int get(Object v) { return v instanceof IRare ? Math.max(1, ((IRare) v).getRarity()) : 1; } + + int getRarity(); } diff --git a/src/main/java/com/volmit/iris/engine/object/IrisAttributeModifier.java b/src/main/java/com/volmit/iris/engine/object/IrisAttributeModifier.java index 9391df538..27463aae4 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisAttributeModifier.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisAttributeModifier.java @@ -18,7 +18,11 @@ package com.volmit.iris.engine.object; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.math.RNG; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisAxisRotationClamp.java b/src/main/java/com/volmit/iris/engine/object/IrisAxisRotationClamp.java index 051b03105..09ac16d1e 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisAxisRotationClamp.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisAxisRotationClamp.java @@ -18,7 +18,12 @@ package com.volmit.iris.engine.object; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.DependsOn; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.math.M; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisBiome.java b/src/main/java/com/volmit/iris/engine/object/IrisBiome.java index 12592b8ed..dc86b8bea 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisBiome.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisBiome.java @@ -25,7 +25,13 @@ import com.volmit.iris.core.loader.IrisRegistrant; import com.volmit.iris.engine.IrisComplex; import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.framework.Engine; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.DependsOn; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.collection.KSet; @@ -46,7 +52,7 @@ import org.bukkit.Material; import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; -import java.awt.*; +import java.awt.Color; @SuppressWarnings("DefaultAnnotationParam") @Accessors(chain = true) @@ -56,140 +62,6 @@ import java.awt.*; @Data @EqualsAndHashCode(callSuper = false) public class IrisBiome extends IrisRegistrant implements IRare { - @MinNumber(2) - @Required - @Desc("This is the human readable name for this biome. This can and should be different than the file name. This is not used for loading biomes in other objects.") - private String name = "A Biome"; - - @ArrayType(min = 1, type = IrisBiomeCustom.class) - @Desc("If the biome type custom is defined, specify this") - private KList customDerivitives; - - @Desc("Spawn Entities in this area over time. Iris will continually replenish these mobs just like vanilla does.") - @ArrayType(min = 1, type = String.class) - @RegistryListResource(IrisSpawner.class) - private KList entitySpawners = new KList<>(); - - @Desc("Add random chances for terrain features") - @ArrayType(min = 1, type = IrisFeaturePotential.class) - private KList features = new KList<>(); - - @ArrayType(min = 1, type = IrisEffect.class) - @Desc("Effects are ambient effects such as potion effects, random sounds, or even particles around each player. All of these effects are played via packets so two players won't see/hear each others effects.\nDue to performance reasons, effects will play around the player even if where the effect was played is no longer in the biome the player is in.") - private KList effects = new KList<>(); - - @DependsOn({"biomeStyle", "biomeZoom", "biomeScatter"}) - @Desc("This changes the dispersion of the biome colors if multiple derivatives are chosen.") - private IrisGeneratorStyle biomeStyle = NoiseStyle.SIMPLEX.style(); - - @ArrayType(min = 1, type = IrisBlockDrops.class) - @Desc("Define custom block drops for this biome") - private KList blockDrops = new KList<>(); - - @Desc("Reference loot tables in this area") - private IrisLootReference loot = new IrisLootReference(); - - @MinNumber(0.0001) - @DependsOn({"biomeStyle", "biomeZoom", "biomeScatter"}) - @Desc("This zooms in the biome colors if multiple derivatives are chosen") - private double biomeZoom = 1; - - @Desc("Layers no longer descend from the surface block, they descend from the max possible height the biome can produce (constant) creating mesa like layers.") - private boolean lockLayers = false; - - @Desc("The max layers to iterate below the surface for locked layer biomes (mesa).") - private int lockLayersMax = 7; - - @Desc("Carving configuration for the dimension") - private IrisCarving carving = new IrisCarving(); - - @Desc("Configuration of fluid bodies such as rivers & lakes") - private IrisFluidBodies fluidBodies = new IrisFluidBodies(); - - @MinNumber(1) - @MaxNumber(512) - @Desc("The rarity of this biome (integer)") - private int rarity = 1; - - @Desc("A color for visualizing this biome with a color. I.e. #F13AF5. This will show up on the map.") - private String color = null; - - @Required - @Desc("The raw derivative of this biome. This is required or the terrain will not properly generate. Use any vanilla biome type. Look in examples/biome-list.txt") - private Biome derivative = Biome.THE_VOID; - - @Required - @Desc("Override the derivative when vanilla places structures to this derivative. This is useful for example if you have an ocean biome, but you have set the derivative to desert to get a brown-ish color. To prevent desert structures from spawning on top of your ocean, you can set your vanillaDerivative to ocean, to allow for vanilla structures. Not defining this value will simply select the derivative.") - private Biome vanillaDerivative = null; - - @ArrayType(min = 1, type = Biome.class) - @Desc("You can instead specify multiple biome derivatives to randomly scatter colors in this biome") - private KList biomeScatter = new KList<>(); - - @ArrayType(min = 1, type = Biome.class) - @Desc("Since 1.13 supports 3D biomes, you can add different derivative colors for anything above the terrain. (Think swampy tree leaves with a desert looking grass surface)") - private KList biomeSkyScatter = new KList<>(); - - @DependsOn({"children"}) - @Desc("If this biome has children biomes, and the gen layer chooses one of this biomes children, how much smaller will it be (inside of this biome). Higher values means a smaller biome relative to this biome's size. Set higher than 1.0 and below 3.0 for best results.") - private double childShrinkFactor = 1.5; - - @DependsOn({"children"}) - @Desc("If this biome has children biomes, and the gen layer chooses one of this biomes children, How will it be shaped?") - private IrisGeneratorStyle childStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style(); - - @RegistryListResource(IrisBiome.class) - @ArrayType(min = 1, type = String.class) - @Desc("List any biome names (file names without.json) here as children. Portions of this biome can sometimes morph into their children. Iris supports cyclic relationships such as A > B > A > B. Iris will stop checking 9 biomes down the tree.") - private KList children = new KList<>(); - - @ArrayType(min = 1, type = IrisJigsawStructurePlacement.class) - @Desc("Jigsaw structures") - private KList jigsawStructures = new KList<>(); - - @RegistryListResource(IrisBiome.class) - @Desc("The carving biome. If specified the biome will be used when under a carving instead of this current biome.") - private String carvingBiome = ""; - - @Desc("The default slab if iris decides to place a slab in this biome. Default is no slab.") - private IrisBiomePaletteLayer slab = new IrisBiomePaletteLayer().zero(); - - @Desc("The default wall if iris decides to place a wall higher than 2 blocks (steep hills or possibly cliffs)") - private IrisBiomePaletteLayer wall = new IrisBiomePaletteLayer().zero(); - - @Required - @ArrayType(min = 1, type = IrisBiomePaletteLayer.class) - @Desc("This defines the layers of materials in this biome. Each layer has a palette and min/max height and some other properties. Usually a grassy/sandy layer then a dirt layer then a stone layer. Iris will fill in the remaining blocks below your layers with stone.") - private KList layers = new KList().qadd(new IrisBiomePaletteLayer()); - - @Required - @ArrayType(min = 1, type = IrisBiomePaletteLayer.class) - @Desc("This defines the layers of materials in this biome. Each layer has a palette and min/max height and some other properties. Usually a grassy/sandy layer then a dirt layer then a stone layer. Iris will fill in the remaining blocks below your layers with stone.") - private KList caveCeilingLayers = new KList().qadd(new IrisBiomePaletteLayer()); - - @ArrayType(min = 1, type = IrisBiomePaletteLayer.class) - @Desc("This defines the layers of materials in this biome. Each layer has a palette and min/max height and some other properties. Usually a grassy/sandy layer then a dirt layer then a stone layer. Iris will fill in the remaining blocks below your layers with stone.") - private KList seaLayers = new KList<>(); - - @ArrayType(min = 1, type = IrisDecorator.class) - @Desc("Decorators are used for things like tall grass, bisected flowers, and even kelp or cactus (random heights)") - private KList decorators = new KList<>(); - - @ArrayType(min = 1, type = IrisObjectPlacement.class) - @Desc("Objects define what schematics (iob files) iris will place in this biome") - private KList objects = new KList<>(); - - @Required - @ArrayType(min = 1, type = IrisBiomeGeneratorLink.class) - @Desc("Generators for this biome. Multiple generators with different interpolation sizes will mix with other biomes how you would expect. This defines your biome height relative to the fluid height. Use negative for oceans.") - private KList generators = new KList().qadd(new IrisBiomeGeneratorLink()); - - @ArrayType(min = 1, type = IrisDepositGenerator.class) - @Desc("Define biome deposit generators that add onto the existing regional and global deposit generators") - private KList deposits = new KList<>(); - - private transient InferredType inferredType; - private static final BlockData BARRIER = Material.BARRIER.createBlockData(); private final transient AtomicCache> genCache = new AtomicCache<>(); private final transient AtomicCache> genCacheMax = new AtomicCache<>(); @@ -209,6 +81,106 @@ public class IrisBiome extends IrisRegistrant implements IRare { private final transient AtomicCache> realChildren = new AtomicCache<>(); private final transient AtomicCache> layerHeightGenerators = new AtomicCache<>(); private final transient AtomicCache> layerSeaHeightGenerators = new AtomicCache<>(); + @MinNumber(2) + @Required + @Desc("This is the human readable name for this biome. This can and should be different than the file name. This is not used for loading biomes in other objects.") + private String name = "A Biome"; + @ArrayType(min = 1, type = IrisBiomeCustom.class) + @Desc("If the biome type custom is defined, specify this") + private KList customDerivitives; + @Desc("Spawn Entities in this area over time. Iris will continually replenish these mobs just like vanilla does.") + @ArrayType(min = 1, type = String.class) + @RegistryListResource(IrisSpawner.class) + private KList entitySpawners = new KList<>(); + @Desc("Add random chances for terrain features") + @ArrayType(min = 1, type = IrisFeaturePotential.class) + private KList features = new KList<>(); + @ArrayType(min = 1, type = IrisEffect.class) + @Desc("Effects are ambient effects such as potion effects, random sounds, or even particles around each player. All of these effects are played via packets so two players won't see/hear each others effects.\nDue to performance reasons, effects will play around the player even if where the effect was played is no longer in the biome the player is in.") + private KList effects = new KList<>(); + @DependsOn({"biomeStyle", "biomeZoom", "biomeScatter"}) + @Desc("This changes the dispersion of the biome colors if multiple derivatives are chosen.") + private IrisGeneratorStyle biomeStyle = NoiseStyle.SIMPLEX.style(); + @ArrayType(min = 1, type = IrisBlockDrops.class) + @Desc("Define custom block drops for this biome") + private KList blockDrops = new KList<>(); + @Desc("Reference loot tables in this area") + private IrisLootReference loot = new IrisLootReference(); + @MinNumber(0.0001) + @DependsOn({"biomeStyle", "biomeZoom", "biomeScatter"}) + @Desc("This zooms in the biome colors if multiple derivatives are chosen") + private double biomeZoom = 1; + @Desc("Layers no longer descend from the surface block, they descend from the max possible height the biome can produce (constant) creating mesa like layers.") + private boolean lockLayers = false; + @Desc("The max layers to iterate below the surface for locked layer biomes (mesa).") + private int lockLayersMax = 7; + @Desc("Carving configuration for the dimension") + private IrisCarving carving = new IrisCarving(); + @Desc("Configuration of fluid bodies such as rivers & lakes") + private IrisFluidBodies fluidBodies = new IrisFluidBodies(); + @MinNumber(1) + @MaxNumber(512) + @Desc("The rarity of this biome (integer)") + private int rarity = 1; + @Desc("A color for visualizing this biome with a color. I.e. #F13AF5. This will show up on the map.") + private String color = null; + @Required + @Desc("The raw derivative of this biome. This is required or the terrain will not properly generate. Use any vanilla biome type. Look in examples/biome-list.txt") + private Biome derivative = Biome.THE_VOID; + @Required + @Desc("Override the derivative when vanilla places structures to this derivative. This is useful for example if you have an ocean biome, but you have set the derivative to desert to get a brown-ish color. To prevent desert structures from spawning on top of your ocean, you can set your vanillaDerivative to ocean, to allow for vanilla structures. Not defining this value will simply select the derivative.") + private Biome vanillaDerivative = null; + @ArrayType(min = 1, type = Biome.class) + @Desc("You can instead specify multiple biome derivatives to randomly scatter colors in this biome") + private KList biomeScatter = new KList<>(); + @ArrayType(min = 1, type = Biome.class) + @Desc("Since 1.13 supports 3D biomes, you can add different derivative colors for anything above the terrain. (Think swampy tree leaves with a desert looking grass surface)") + private KList biomeSkyScatter = new KList<>(); + @DependsOn({"children"}) + @Desc("If this biome has children biomes, and the gen layer chooses one of this biomes children, how much smaller will it be (inside of this biome). Higher values means a smaller biome relative to this biome's size. Set higher than 1.0 and below 3.0 for best results.") + private double childShrinkFactor = 1.5; + @DependsOn({"children"}) + @Desc("If this biome has children biomes, and the gen layer chooses one of this biomes children, How will it be shaped?") + private IrisGeneratorStyle childStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style(); + @RegistryListResource(IrisBiome.class) + @ArrayType(min = 1, type = String.class) + @Desc("List any biome names (file names without.json) here as children. Portions of this biome can sometimes morph into their children. Iris supports cyclic relationships such as A > B > A > B. Iris will stop checking 9 biomes down the tree.") + private KList children = new KList<>(); + @ArrayType(min = 1, type = IrisJigsawStructurePlacement.class) + @Desc("Jigsaw structures") + private KList jigsawStructures = new KList<>(); + @RegistryListResource(IrisBiome.class) + @Desc("The carving biome. If specified the biome will be used when under a carving instead of this current biome.") + private String carvingBiome = ""; + @Desc("The default slab if iris decides to place a slab in this biome. Default is no slab.") + private IrisBiomePaletteLayer slab = new IrisBiomePaletteLayer().zero(); + @Desc("The default wall if iris decides to place a wall higher than 2 blocks (steep hills or possibly cliffs)") + private IrisBiomePaletteLayer wall = new IrisBiomePaletteLayer().zero(); + @Required + @ArrayType(min = 1, type = IrisBiomePaletteLayer.class) + @Desc("This defines the layers of materials in this biome. Each layer has a palette and min/max height and some other properties. Usually a grassy/sandy layer then a dirt layer then a stone layer. Iris will fill in the remaining blocks below your layers with stone.") + private KList layers = new KList().qadd(new IrisBiomePaletteLayer()); + @Required + @ArrayType(min = 1, type = IrisBiomePaletteLayer.class) + @Desc("This defines the layers of materials in this biome. Each layer has a palette and min/max height and some other properties. Usually a grassy/sandy layer then a dirt layer then a stone layer. Iris will fill in the remaining blocks below your layers with stone.") + private KList caveCeilingLayers = new KList().qadd(new IrisBiomePaletteLayer()); + @ArrayType(min = 1, type = IrisBiomePaletteLayer.class) + @Desc("This defines the layers of materials in this biome. Each layer has a palette and min/max height and some other properties. Usually a grassy/sandy layer then a dirt layer then a stone layer. Iris will fill in the remaining blocks below your layers with stone.") + private KList seaLayers = new KList<>(); + @ArrayType(min = 1, type = IrisDecorator.class) + @Desc("Decorators are used for things like tall grass, bisected flowers, and even kelp or cactus (random heights)") + private KList decorators = new KList<>(); + @ArrayType(min = 1, type = IrisObjectPlacement.class) + @Desc("Objects define what schematics (iob files) iris will place in this biome") + private KList objects = new KList<>(); + @Required + @ArrayType(min = 1, type = IrisBiomeGeneratorLink.class) + @Desc("Generators for this biome. Multiple generators with different interpolation sizes will mix with other biomes how you would expect. This defines your biome height relative to the fluid height. Use negative for oceans.") + private KList generators = new KList().qadd(new IrisBiomeGeneratorLink()); + @ArrayType(min = 1, type = IrisDepositGenerator.class) + @Desc("Define biome deposit generators that add onto the existing regional and global deposit generators") + private KList deposits = new KList<>(); + private transient InferredType inferredType; public Biome getVanillaDerivative() { return vanillaDerivative == null ? derivative : vanillaDerivative; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisBiomeCustom.java b/src/main/java/com/volmit/iris/engine/object/IrisBiomeCustom.java index 154bc8528..6786478aa 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisBiomeCustom.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisBiomeCustom.java @@ -19,7 +19,13 @@ package com.volmit.iris.engine.object; import com.volmit.iris.Iris; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.DependsOn; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.json.JSONArray; @@ -29,7 +35,7 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.Accessors; -import java.awt.*; +import java.awt.Color; import java.util.Locale; @Snippet("custom-biome") diff --git a/src/main/java/com/volmit/iris/engine/object/IrisBiomeCustomParticle.java b/src/main/java/com/volmit/iris/engine/object/IrisBiomeCustomParticle.java index cb6b90633..9edfcad8b 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisBiomeCustomParticle.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisBiomeCustomParticle.java @@ -18,7 +18,11 @@ package com.volmit.iris.engine.object; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisBiomeCustomSpawn.java b/src/main/java/com/volmit/iris/engine/object/IrisBiomeCustomSpawn.java index 40d2b27ad..3a65f7f15 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisBiomeCustomSpawn.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisBiomeCustomSpawn.java @@ -18,7 +18,11 @@ package com.volmit.iris.engine.object; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisBiomeGeneratorLink.java b/src/main/java/com/volmit/iris/engine/object/IrisBiomeGeneratorLink.java index b8d09f080..d6aa2ebee 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisBiomeGeneratorLink.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisBiomeGeneratorLink.java @@ -19,7 +19,13 @@ package com.volmit.iris.engine.object; import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.DependsOn; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.data.DataProvider; import com.volmit.iris.util.interpolation.IrisInterpolation; import lombok.AllArgsConstructor; @@ -35,17 +41,16 @@ import lombok.experimental.Accessors; @Data public class IrisBiomeGeneratorLink { + private final transient AtomicCache gen = new AtomicCache<>(); @RegistryListResource(IrisGenerator.class) @Desc("The generator id") private String generator = "default"; - @DependsOn({"min", "max"}) @Required @MinNumber(-256) // TODO: WARNING HEIGHT @MaxNumber(256) // TODO: WARNING HEIGHT @Desc("The min block value (value + fluidHeight)") private int min = 0; - @DependsOn({"min", "max"}) @Required @MinNumber(-256) // TODO: WARNING HEIGHT @@ -53,8 +58,6 @@ public class IrisBiomeGeneratorLink { @Desc("The max block value (value + fluidHeight)") private int max = 0; - private final transient AtomicCache gen = new AtomicCache<>(); - public IrisGenerator getCachedGenerator(DataProvider g) { return gen.aquire(() -> { diff --git a/src/main/java/com/volmit/iris/engine/object/IrisBiomePaletteLayer.java b/src/main/java/com/volmit/iris/engine/object/IrisBiomePaletteLayer.java index f18639cbb..1b9ac6aa4 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisBiomePaletteLayer.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisBiomePaletteLayer.java @@ -20,7 +20,13 @@ package com.volmit.iris.engine.object; import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.DependsOn; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.noise.CNG; @@ -37,40 +43,33 @@ import org.bukkit.block.data.BlockData; @Desc("A layer of surface / subsurface material in biomes") @Data public class IrisBiomePaletteLayer { + private final transient AtomicCache> blockData = new AtomicCache<>(); + private final transient AtomicCache layerGenerator = new AtomicCache<>(); + private final transient AtomicCache heightGenerator = new AtomicCache<>(); @Desc("The style of noise") private IrisGeneratorStyle style = NoiseStyle.STATIC.style(); - @DependsOn({"minHeight", "maxHeight"}) @MinNumber(0) @MaxNumber(256) // TODO: WARNING HEIGHT @Desc("The min thickness of this layer") private int minHeight = 1; - @DependsOn({"minHeight", "maxHeight"}) @MinNumber(1) @MaxNumber(256) // TODO: WARNING HEIGHT @Desc("The max thickness of this layer") private int maxHeight = 1; - - @Desc("If set, this layer will change size depending on the slope. If in bounds, the layer will get larger (taller) the closer to the center of this slope clip it is. If outside of the slipe's bounds, this layer will not show.") private IrisSlopeClip slopeCondition = new IrisSlopeClip(); - @MinNumber(0.0001) @Desc("The terrain zoom mostly for zooming in on a wispy palette") private double zoom = 5; - @Required @ArrayType(min = 1, type = IrisBlockData.class) @Desc("The palette of blocks to be used in this layer") private KList palette = new KList().qadd(new IrisBlockData("GRASS_BLOCK")); - private final transient AtomicCache> blockData = new AtomicCache<>(); - private final transient AtomicCache layerGenerator = new AtomicCache<>(); - private final transient AtomicCache heightGenerator = new AtomicCache<>(); - public CNG getHeightGenerator(RNG rng, IrisData data) { return heightGenerator.aquire(() -> CNG.signature(rng.nextParallelRNG(minHeight * maxHeight + getBlockData(data).size()))); } diff --git a/src/main/java/com/volmit/iris/engine/object/IrisBlockData.java b/src/main/java/com/volmit/iris/engine/object/IrisBlockData.java index 290a302e5..8ce429751 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisBlockData.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisBlockData.java @@ -22,7 +22,11 @@ import com.volmit.iris.Iris; import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.core.loader.IrisRegistrant; import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListBlockType; +import com.volmit.iris.engine.object.annotations.Required; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.data.B; @@ -45,32 +49,77 @@ import java.util.Map; @Data @EqualsAndHashCode(callSuper = false) public class IrisBlockData extends IrisRegistrant { + private final transient AtomicCache blockdata = new AtomicCache<>(); + private final transient AtomicCache realProperties = new AtomicCache<>(); @RegistryListBlockType @Required @Desc("The block to use") private String block = "air"; - @Desc("Debug this block by printing it to the console when it's used. Must have debug turned on in settings.") private boolean debug = false; - @MinNumber(1) @MaxNumber(1000) @Desc("The weight is used when this block data is inside of a list of blockdata. A weight of two is just as if you placed two of the same block data values in the same list making it more common when randomly picked.") private int weight = 1; - @Desc("If the block cannot be created on this version, Iris will attempt to use this backup block data instead.") private IrisBlockData backup = null; - @Desc("Optional properties for this block data such as 'waterlogged': true") private KMap data = new KMap<>(); - private final transient AtomicCache blockdata = new AtomicCache<>(); - private final transient AtomicCache realProperties = new AtomicCache<>(); - public IrisBlockData(String b) { this.block = b; } + public static IrisBlockData from(String j) { + IrisBlockData b = new IrisBlockData(); + String v = j.toLowerCase().trim(); + + if (v.contains("[")) { + KList props = new KList<>(); + String rp = v.split("\\Q[\\E")[1].replaceAll("\\Q]\\E", ""); + b.setBlock(v.split("\\Q[\\E")[0]); + + if (rp.contains(",")) { + props.add(rp.split("\\Q,\\E")); + } else { + props.add(rp); + } + + for (String i : props) { + Object kg = filter(i.split("\\Q=\\E")[1]); + b.data.put(i.split("\\Q=\\E")[0], kg); + } + } else { + b.setBlock(v); + } + + return b; + } + + private static Object filter(String string) { + if (string.equals("true")) { + return true; + } + + if (string.equals("false")) { + return false; + } + + try { + return Integer.parseInt(string); + } catch (Throwable ignored) { + // Checks + } + + try { + return Double.valueOf(string).intValue(); + } catch (Throwable ignored) { + // Checks + } + + return string; + } + public String computeProperties(KMap data) { if (data.isEmpty()) { return ""; @@ -159,56 +208,6 @@ public class IrisBlockData extends IrisRegistrant { return "minecraft:" + dat; } - public static IrisBlockData from(String j) { - IrisBlockData b = new IrisBlockData(); - String v = j.toLowerCase().trim(); - - if (v.contains("[")) { - KList props = new KList<>(); - String rp = v.split("\\Q[\\E")[1].replaceAll("\\Q]\\E", ""); - b.setBlock(v.split("\\Q[\\E")[0]); - - if (rp.contains(",")) { - props.add(rp.split("\\Q,\\E")); - } else { - props.add(rp); - } - - for (String i : props) { - Object kg = filter(i.split("\\Q=\\E")[1]); - b.data.put(i.split("\\Q=\\E")[0], kg); - } - } else { - b.setBlock(v); - } - - return b; - } - - private static Object filter(String string) { - if (string.equals("true")) { - return true; - } - - if (string.equals("false")) { - return false; - } - - try { - return Integer.parseInt(string); - } catch (Throwable ignored) { - // Checks - } - - try { - return Double.valueOf(string).intValue(); - } catch (Throwable ignored) { - // Checks - } - - return string; - } - @Override public String getFolderName() { return "blocks"; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisBlockDrops.java b/src/main/java/com/volmit/iris/engine/object/IrisBlockDrops.java index 961f18c83..4eda716af 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisBlockDrops.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisBlockDrops.java @@ -40,26 +40,21 @@ import org.bukkit.inventory.ItemStack; @Desc("Represents a block drop list") @Data public class IrisBlockDrops { + private final transient AtomicCache> data = new AtomicCache<>(); @Required @ArrayType(min = 1, type = IrisBlockData.class) @Desc("The blocks that drop loot") private KList blocks = new KList<>(); - @Desc("If exact blocks is set to true, minecraft:barrel[axis=x] will only drop for that axis. When exact is false (default) any barrel will drop the defined drops.") private boolean exactBlocks = false; - @Desc("Add in specific items to drop") @ArrayType(min = 1, type = IrisLoot.class) private KList drops = new KList<>(); - @Desc("If this is in a biome, setting skipParents to true will ignore the drops in the region and dimension for this block type. The default (false) will allow all three nodes to fire and add to a list of drops.") private boolean skipParents = false; - @Desc("Removes the default vanilla block drops and only drops the given items & any parent loot tables specified for this block type.") private boolean replaceVanillaDrops = false; - private final transient AtomicCache> data = new AtomicCache<>(); - public boolean shouldDropFor(BlockData data, IrisData rdata) { KList list = this.data.aquire(() -> { diff --git a/src/main/java/com/volmit/iris/engine/object/IrisCavePlacer.java b/src/main/java/com/volmit/iris/engine/object/IrisCavePlacer.java index 83b5b8f5f..1355b9801 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisCavePlacer.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisCavePlacer.java @@ -23,7 +23,11 @@ import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.mantle.MantleWriter; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.math.RNG; import lombok.AllArgsConstructor; import lombok.Data; @@ -39,26 +43,22 @@ import java.util.concurrent.atomic.AtomicBoolean; @Desc("Translate objects") @Data public class IrisCavePlacer implements IRare { + private transient final AtomicCache caveCache = new AtomicCache<>(); + private transient final AtomicBoolean fail = new AtomicBoolean(false); @Required @Desc("Typically a 1 in RARITY on a per chunk/fork basis") @MinNumber(1) private int rarity = 15; - @MinNumber(1) @Required @Desc("The cave to place") @RegistryListResource(IrisCave.class) private String cave; - @Desc("If set to true, this cave is allowed to break the surface") private boolean breakSurface = true; - @Desc("The height range this cave can spawn at. If breakSurface is false, the output of this range will be clamped by the current world height to prevent surface breaking.") private IrisStyledRange caveStartHeight = new IrisStyledRange(13, 120, new IrisGeneratorStyle(NoiseStyle.STATIC)); - private transient final AtomicCache caveCache = new AtomicCache<>(); - private transient final AtomicBoolean fail = new AtomicBoolean(false); - public IrisCave getRealCave(IrisData data) { return caveCache.aquire(() -> data.getCaveLoader().load(getCave())); } diff --git a/src/main/java/com/volmit/iris/engine/object/IrisColor.java b/src/main/java/com/volmit/iris/engine/object/IrisColor.java index e9f868f43..eb65495f2 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisColor.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisColor.java @@ -28,7 +28,7 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.Accessors; -import java.awt.*; +import java.awt.Color; @Snippet("color") @Accessors(chain = true) @@ -36,48 +36,24 @@ import java.awt.*; @Desc("Represents a color") @Data public class IrisColor { + private final transient AtomicCache color = new AtomicCache<>(); @MaxNumber(7) @MinNumber(6) @Desc("Pass in a 6 digit hexadecimal color to fill R G and B values. You can also include the # symbol, but it's not required.") private String hex = null; - @MaxNumber(255) @MinNumber(0) @Desc("Represents the red channel. Only define this if you are not defining the hex value.") private int red = 0; - @MaxNumber(255) @MinNumber(0) @Desc("Represents the green channel. Only define this if you are not defining the hex value.") private int green = 0; - @MaxNumber(255) @MinNumber(0) @Desc("Represents the blue channel. Only define this if you are not defining the hex value.") private int blue = 0; - private final transient AtomicCache color = new AtomicCache<>(); - - public Color getColor() { - return color.aquire(() -> { - if (hex != null) { - String v = (hex.startsWith("#") ? hex : "#" + hex).trim(); - try { - return Color.decode(v); - } catch (Throwable e) { - Iris.reportError(e); - - } - } - - return new Color(red, green, blue); - }); - } - - public org.bukkit.Color getBukkitColor() { - return org.bukkit.Color.fromRGB(getColor().getRGB()); - } - public static Color blend(Color... c) { if (c == null || c.length <= 0) { return null; @@ -104,6 +80,26 @@ public class IrisColor { return new Color(a << 24 | r << 16 | g << 8 | b); } + public Color getColor() { + return color.aquire(() -> { + if (hex != null) { + String v = (hex.startsWith("#") ? hex : "#" + hex).trim(); + try { + return Color.decode(v); + } catch (Throwable e) { + Iris.reportError(e); + + } + } + + return new Color(red, green, blue); + }); + } + + public org.bukkit.Color getBukkitColor() { + return org.bukkit.Color.fromRGB(getColor().getRGB()); + } + public int getAsRGB() { if (hex != null) { try { diff --git a/src/main/java/com/volmit/iris/engine/object/IrisCompat.java b/src/main/java/com/volmit/iris/engine/object/IrisCompat.java index a8197ca1d..9e5a19345 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisCompat.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisCompat.java @@ -42,114 +42,6 @@ public class IrisCompat { itemFilters = getDefaultItemCompatabilityFilters(); } - public BlockData getBlock(String n) { - String buf = n; - int err = 16; - - BlockData tx = B.getOrNull(buf); - - if (tx != null) { - return tx; - } - - searching: - while (true) { - if (err-- <= 0) { - return B.get("STONE"); - } - - for (IrisCompatabilityBlockFilter i : blockFilters) { - if (i.getWhen().equalsIgnoreCase(buf)) { - BlockData b = i.getReplace(); - - if (b != null) { - return b; - } - - buf = i.getSupplement(); - continue searching; - } - } - - return B.get("STONE"); - } - } - - public Material getItem(String n) { - String buf = n; - int err = 16; - Material txf = B.getMaterialOrNull(buf); - - if (txf != null) { - return txf; - } - - int nomore = 64; - - searching: - while (true) { - if (nomore < 0) { - return B.getMaterial("STONE"); - } - - nomore--; - if (err-- <= 0) { - break; - } - - for (IrisCompatabilityItemFilter i : itemFilters) { - if (i.getWhen().equalsIgnoreCase(buf)) { - Material b = i.getReplace(); - - if (b != null) { - return b; - } - - buf = i.getSupplement(); - continue searching; - } - } - - break; - } - - buf = n; - BlockData tx = B.getOrNull(buf); - - if (tx != null) { - return tx.getMaterial(); - } - nomore = 64; - - searching: - while (true) { - if (nomore < 0) { - return B.getMaterial("STONE"); - } - - nomore--; - - if (err-- <= 0) { - return B.getMaterial("STONE"); - } - - for (IrisCompatabilityBlockFilter i : blockFilters) { - if (i.getWhen().equalsIgnoreCase(buf)) { - BlockData b = i.getReplace(); - - if (b != null) { - return b.getMaterial(); - } - - buf = i.getSupplement(); - continue searching; - } - } - - return B.getMaterial("STONE"); - } - } - public static IrisCompat configured(File f) { IrisCompat def = new IrisCompat(); String defa = new JSONObject(new Gson().toJson(def)).toString(4); @@ -365,4 +257,112 @@ public class IrisCompat { return filters; } + + public BlockData getBlock(String n) { + String buf = n; + int err = 16; + + BlockData tx = B.getOrNull(buf); + + if (tx != null) { + return tx; + } + + searching: + while (true) { + if (err-- <= 0) { + return B.get("STONE"); + } + + for (IrisCompatabilityBlockFilter i : blockFilters) { + if (i.getWhen().equalsIgnoreCase(buf)) { + BlockData b = i.getReplace(); + + if (b != null) { + return b; + } + + buf = i.getSupplement(); + continue searching; + } + } + + return B.get("STONE"); + } + } + + public Material getItem(String n) { + String buf = n; + int err = 16; + Material txf = B.getMaterialOrNull(buf); + + if (txf != null) { + return txf; + } + + int nomore = 64; + + searching: + while (true) { + if (nomore < 0) { + return B.getMaterial("STONE"); + } + + nomore--; + if (err-- <= 0) { + break; + } + + for (IrisCompatabilityItemFilter i : itemFilters) { + if (i.getWhen().equalsIgnoreCase(buf)) { + Material b = i.getReplace(); + + if (b != null) { + return b; + } + + buf = i.getSupplement(); + continue searching; + } + } + + break; + } + + buf = n; + BlockData tx = B.getOrNull(buf); + + if (tx != null) { + return tx.getMaterial(); + } + nomore = 64; + + searching: + while (true) { + if (nomore < 0) { + return B.getMaterial("STONE"); + } + + nomore--; + + if (err-- <= 0) { + return B.getMaterial("STONE"); + } + + for (IrisCompatabilityBlockFilter i : blockFilters) { + if (i.getWhen().equalsIgnoreCase(buf)) { + BlockData b = i.getReplace(); + + if (b != null) { + return b.getMaterial(); + } + + buf = i.getSupplement(); + continue searching; + } + } + + return B.getMaterial("STONE"); + } + } } diff --git a/src/main/java/com/volmit/iris/engine/object/IrisCompatabilityBlockFilter.java b/src/main/java/com/volmit/iris/engine/object/IrisCompatabilityBlockFilter.java index 06926ee85..bef92b2ef 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisCompatabilityBlockFilter.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisCompatabilityBlockFilter.java @@ -35,20 +35,17 @@ import org.bukkit.block.data.BlockData; @Desc("Find and replace object materials for compatability") @Data public class IrisCompatabilityBlockFilter { + private final transient AtomicCache findData = new AtomicCache<>(true); + private final transient AtomicCache replaceData = new AtomicCache<>(true); @Required @Desc("When iris sees this block, and it's not reconized") private String when = ""; - @Required @Desc("Replace it with this block. Dont worry if this block is also not reconized, iris repeat this compat check.") private String supplement = ""; - @Desc("If exact is true, it compares block data for example minecraft:some_log[axis=x]") private boolean exact = false; - private final transient AtomicCache findData = new AtomicCache<>(true); - private final transient AtomicCache replaceData = new AtomicCache<>(true); - public IrisCompatabilityBlockFilter(String when, String supplement) { this(when, supplement, false); } diff --git a/src/main/java/com/volmit/iris/engine/object/IrisCompatabilityItemFilter.java b/src/main/java/com/volmit/iris/engine/object/IrisCompatabilityItemFilter.java index 4fbd7d789..105eb7648 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisCompatabilityItemFilter.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisCompatabilityItemFilter.java @@ -33,17 +33,15 @@ import org.bukkit.Material; @Desc("Find and replace object items for compatability") @Data public class IrisCompatabilityItemFilter { + private final transient AtomicCache findData = new AtomicCache<>(true); + private final transient AtomicCache replaceData = new AtomicCache<>(true); @Required @Desc("When iris sees this block, and it's not reconized") private String when = ""; - @Required @Desc("Replace it with this block. Dont worry if this block is also not reconized, iris repeat this compat check.") private String supplement = ""; - private final transient AtomicCache findData = new AtomicCache<>(true); - private final transient AtomicCache replaceData = new AtomicCache<>(true); - public IrisCompatabilityItemFilter(String when, String supplement) { this.when = when; this.supplement = supplement; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisDecorator.java b/src/main/java/com/volmit/iris/engine/object/IrisDecorator.java index 9ba563b95..79b7e6de5 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisDecorator.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisDecorator.java @@ -21,7 +21,13 @@ package com.volmit.iris.engine.object; import com.volmit.iris.Iris; import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.DependsOn; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.noise.CNG; @@ -38,71 +44,58 @@ import org.bukkit.block.data.BlockData; @Desc("A biome decorator is used for placing flowers, grass, cacti and so on") @Data public class IrisDecorator { + private final transient AtomicCache layerGenerator = new AtomicCache<>(); + private final transient AtomicCache varianceGenerator = new AtomicCache<>(); + private final transient AtomicCache heightGenerator = new AtomicCache<>(); + private final transient AtomicCache> blockData = new AtomicCache<>(); + private final transient AtomicCache> blockDataTops = new AtomicCache<>(); @Desc("The varience dispersion is used when multiple blocks are put in the palette. Scatter scrambles them, Wispy shows streak-looking varience") private IrisGeneratorStyle variance = NoiseStyle.STATIC.style(); - @Desc("Forcefully place this decorant anywhere it is supposed to go even if it should not go on a specific surface block. For example, you could force tallgrass to place on top of stone by using this.") private boolean forcePlace = false; - @DependsOn({"scaleStack", "stackMin", "stackMax"}) @Desc("If stackMax is set to true, use this to limit its max height for large caverns") private int absoluteMaxStack = 30; - @Desc("Dispersion is used to pick places to spawn. Scatter randomly places them (vanilla) or Wispy for a streak like patch system.") private IrisGeneratorStyle style = NoiseStyle.STATIC.style(); - @DependsOn({"stackMin", "stackMax"}) @Desc("If this decorator has a height more than 1 this changes how it picks the height between your maxes. Scatter = random, Wispy = wavy heights") private IrisGeneratorStyle heightVariance = NoiseStyle.STATIC.style(); - @Desc("Tells iris where this decoration is a part of. I.e. SHORE_LINE or SEA_SURFACE") private IrisDecorationPart partOf = IrisDecorationPart.NONE; - @DependsOn({"stackMin", "stackMax"}) @MinNumber(1) @MaxNumber(256) // TODO: WARNING HEIGHT @Desc("The minimum repeat stack height (setting to 3 would stack 3 of on top of each other") private int stackMin = 1; - @DependsOn({"stackMin", "stackMax"}) @MinNumber(1) @MaxNumber(256) // TODO: WARNING HEIGHT @Desc("The maximum repeat stack height") private int stackMax = 1; - @DependsOn({"stackMin", "stackMax"}) @Desc("Changes stackMin and stackMin from being absolute block heights and instead uses them as a percentage to scale the stack based on the cave height" + "\n\nWithin a cave, setting them stackMin/max to 50 would make the stack 50% of the cave height") private boolean scaleStack = false; - @Required @MinNumber(0) @MaxNumber(1) @Desc("The chance for this decorator to decorate at a given X,Y coordinate. This is hit 256 times per chunk (per surface block)") // TODO: WARNING HEIGHT private double chance = 0.1; - @Required @ArrayType(min = 1, type = IrisBlockData.class) @Desc("The palette of blocks to pick from when this decorator needs to place.") private KList palette = new KList().qadd(new IrisBlockData("grass")); - @ArrayType(min = 1, type = IrisBlockData.class) @Desc("The palette of blocks used at the very top of a 'stackMax' of higher than 1. For example, bamboo tops.") private KList topPalette = new KList<>(); - @DependsOn("topPalette") @MinNumber(0.01) @MaxNumber(1.0) @Desc("When the stack passes the top threshold, the top palette will start being used instead of the normal palette.") private double topThreshold = 1.0; - private final transient AtomicCache layerGenerator = new AtomicCache<>(); - private final transient AtomicCache varianceGenerator = new AtomicCache<>(); - private final transient AtomicCache heightGenerator = new AtomicCache<>(); - private final transient AtomicCache> blockData = new AtomicCache<>(); - private final transient AtomicCache> blockDataTops = new AtomicCache<>(); - public int getHeight(RNG rng, double x, double z, IrisData data) { if (stackMin == stackMax) { return stackMin; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisDepositGenerator.java b/src/main/java/com/volmit/iris/engine/object/IrisDepositGenerator.java index bf64398a3..38113072d 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisDepositGenerator.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisDepositGenerator.java @@ -20,7 +20,12 @@ package com.volmit.iris.engine.object; import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.math.RNG; import lombok.AllArgsConstructor; @@ -37,55 +42,47 @@ import org.bukkit.util.BlockVector; @Desc("Creates ore & other block deposits underground") @Data public class IrisDepositGenerator { + private final transient AtomicCache> objects = new AtomicCache<>(); + private final transient AtomicCache> blockData = new AtomicCache<>(); @Required @MinNumber(0) @MaxNumber(256) // TODO: WARNING HEIGHT @Desc("The minimum height this deposit can generate at") private int minHeight = 7; - @Required @MinNumber(0) @MaxNumber(256) // TODO: WARNING HEIGHT @Desc("The maximum height this deposit can generate at") private int maxHeight = 55; - @Required @MinNumber(1) @MaxNumber(8192) @Desc("The minimum amount of deposit blocks per clump") private int minSize = 3; - @Required @MinNumber(1) @MaxNumber(8192) @Desc("The maximum amount of deposit blocks per clump") private int maxSize = 64; - @Required @MinNumber(1) @MaxNumber(128) @Desc("The maximum amount of clumps per chunk") private int maxPerChunk = 3; - @Required @MinNumber(0) @MaxNumber(128) @Desc("The minimum amount of clumps per chunk") private int minPerChunk = 1; - @Required @ArrayType(min = 1, type = IrisBlockData.class) @Desc("The palette of blocks to be used in this deposit generator") private KList palette = new KList<>(); - @MinNumber(1) @MaxNumber(64) @Desc("Ore varience is how many different objects clumps iris will create") private int varience = 3; - private final transient AtomicCache> objects = new AtomicCache<>(); - private final transient AtomicCache> blockData = new AtomicCache<>(); - public IrisObject getClump(RNG rng, IrisData rdata) { KList objects = this.objects.aquire(() -> { diff --git a/src/main/java/com/volmit/iris/engine/object/IrisDimension.java b/src/main/java/com/volmit/iris/engine/object/IrisDimension.java index 5206c4534..047006753 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisDimension.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisDimension.java @@ -22,7 +22,12 @@ import com.volmit.iris.Iris; import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.core.loader.IrisRegistrant; import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.data.DataProvider; import com.volmit.iris.util.io.IO; @@ -53,224 +58,6 @@ import java.io.IOException; public class IrisDimension extends IrisRegistrant { public static final BlockData STONE = Material.STONE.createBlockData(); public static final BlockData WATER = Material.WATER.createBlockData(); - - @MinNumber(2) - @Required - @Desc("The human readable name of this dimension") - private String name = "A Dimension"; - - @RegistryListResource(IrisJigsawStructure.class) - @Desc("If defined, Iris will place the given jigsaw structure where minecraft should place the overworld stronghold.") - private String stronghold; - - @Desc("If set to true, Iris will remove chunks to allow visualizing cross sections of chunks easily") - private boolean debugChunkCrossSections = false; - - @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") - private int explodeBiomePaletteSize = 3; - - @MinNumber(2) - @MaxNumber(16) - @Desc("Every X/Z % debugCrossSectionsMod == 0 cuts the chunk") - private int debugCrossSectionsMod = 3; - - @Desc("The average distance between strongholds") - private int strongholdJumpDistance = 1280; - - @Desc("Define the maximum strongholds to place") - private int maxStrongholds = 14; - - @Desc("Improves the biome grid variation by shuffling the cell grid more depending on the seed. This makes biomes across multiple seeds look far different than before.") - private boolean aggressiveBiomeReshuffle = false; - - @Desc("Tree growth override settings") - private IrisTreeSettings treeSettings = new IrisTreeSettings(); - - @Desc("Upon joining this world, Iris will send a resource pack request to the client. If they have previously selected yes, it will auto-switch depending on which dimension they go to.") - private String resourcePack = ""; - - @Desc("Spawn Entities in this dimension over time. Iris will continually replenish these mobs just like vanilla does.") - @ArrayType(min = 1, type = String.class) - @RegistryListResource(IrisSpawner.class) - private KList entitySpawners = new KList<>(); - - @Desc("Add specific features in exact positions") - @ArrayType(min = 1, type = IrisFeaturePositional.class) - private KList specificFeatures = new KList<>(); - - @Desc("Add random chances for terrain features") - @ArrayType(min = 1, type = IrisFeaturePotential.class) - private KList features = new KList<>(); - - @Desc("Reference loot tables in this area") - private IrisLootReference loot = new IrisLootReference(); - - @MinNumber(0) - @Desc("The version of this dimension. Changing this will stop users from accidentally upgrading (and breaking their worlds).") - private int version = 1; - - @ArrayType(min = 1, type = IrisBlockDrops.class) - @Desc("Define custom block drops for this dimension") - private KList blockDrops = new KList<>(); - - @Desc("Should bedrock be generated or not.") - private boolean bedrock = true; - - @MinNumber(0) - @MaxNumber(1) - @Desc("The land chance. Up to 1.0 for total land or 0.0 for total sea") - private double landChance = 0.625; - - @Desc("The placement style of regions") - private IrisGeneratorStyle regionStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style(); - - @Desc("The placement style of land/sea") - private IrisGeneratorStyle continentalStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style(); - - @Desc("The placement style of biomes") - private IrisGeneratorStyle landBiomeStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style(); - - @Desc("The placement style of biomes") - private IrisGeneratorStyle shoreBiomeStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style(); - - @Desc("The placement style of biomes") - private IrisGeneratorStyle seaBiomeStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style(); - - @Desc("The placement style of biomes") - private IrisGeneratorStyle caveBiomeStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style(); - - @Desc("Instead of filling objects with air, fills them with cobweb so you can see them") - private boolean debugSmartBore = false; - - @Desc("Generate decorations or not") - private boolean decorate = true; - - @Desc("Use post processing or not") - private boolean postProcessing = true; - - @Desc("Add slabs in post processing") - private boolean postProcessingSlabs = true; - - @Desc("Add painted walls in post processing") - private boolean postProcessingWalls = true; - - @Desc("Carving configuration for the dimension") - private IrisCarving carving = new IrisCarving(); - - @Desc("Configuration of fluid bodies such as rivers & lakes") - private IrisFluidBodies fluidBodies = new IrisFluidBodies(); - - @Desc("The world environment") - private Environment environment = Environment.NORMAL; - - @RegistryListResource(IrisRegion.class) - @Required - @ArrayType(min = 1, type = String.class) - @Desc("Define all of the regions to include in this dimension. Dimensions -> Regions -> Biomes -> Objects etc") - private KList regions = new KList<>(); - - @ArrayType(min = 1, type = IrisJigsawStructurePlacement.class) - @Desc("Jigsaw structures") - private KList jigsawStructures = new KList<>(); - - @Required - @MinNumber(0) - @MaxNumber(255) - @Desc("The fluid height for this dimension") - private int fluidHeight = 63; - - @RegistryListResource(IrisBiome.class) - @Desc("Keep this either undefined or empty. Setting any biome name into this will force iris to only generate the specified biome. Great for testing.") - private String focus = ""; - - @RegistryListResource(IrisBiome.class) - @Desc("Keep this either undefined or empty. Setting any region name into this will force iris to only generate the specified region. Great for testing.") - private String focusRegion = ""; - - @MinNumber(0.0001) - @MaxNumber(512) - @Desc("Zoom in or out the biome size. Higher = bigger biomes") - private double biomeZoom = 5D; - - @MinNumber(0.0001) - @MaxNumber(512) - @Desc("Zoom in or out the terrain. This stretches the terrain. Due to performance improvements, Higher than 2.0 may cause weird rounding artifacts. Lower = more terrain changes per block. Its a true zoom-out.") - private double terrainZoom = 1D; - - @MinNumber(0) - @MaxNumber(360) - @Desc("You can rotate the input coordinates by an angle. This can make terrain appear more natural (less sharp corners and lines). This literally rotates the entire dimension by an angle. Hint: Try 12 degrees or something not on a 90 or 45 degree angle.") - private double dimensionAngleDeg = 0; - - @MinNumber(0) - @MaxNumber(8192) - @Desc("Coordinate fracturing applies noise to the input coordinates. This creates the 'iris swirls' and wavy features. The distance pushes these waves further into places they shouldnt be. This is a block value multiplier.") - private double coordFractureDistance = 20; - - @MinNumber(0.0001) - @MaxNumber(512) - @Desc("Coordinate fracturing zoom. Higher = less frequent warping, Lower = more frequent and rapid warping / swirls.") - private double coordFractureZoom = 8; - - @MinNumber(0.0001) - @MaxNumber(512) - @Desc("This zooms in the land space") - private double landZoom = 1; - - @MinNumber(0.0001) - @MaxNumber(512) - @Desc("This zooms oceanic biomes") - private double seaZoom = 1; - - @MinNumber(0.0001) - @MaxNumber(512) - @Desc("Zoom in continents") - private double continentZoom = 1; - - @MinNumber(0.0001) - @MaxNumber(512) - @Desc("Change the size of regions") - private double regionZoom = 1; - - @Desc("Disable this to stop placing objects, entities, features & updates") - private boolean useMantle = true; - - @Desc("Prevent Leaf decay as if placed in creative mode") - private boolean preventLeafDecay = false; - - @ArrayType(min = 1, type = IrisDepositGenerator.class) - @Desc("Define global deposit generators") - private KList deposits = new KList<>(); - - @ArrayType(min = 1, type = IrisShapedGeneratorStyle.class) - @Desc("Overlay additional noise on top of the interoplated terrain.") - private KList overlayNoise = new KList<>(); - - @Desc("If true, the spawner system has infinite energy. This is NOT recommended because it would allow for mobs to keep spawning over and over without a rate limit") - private boolean infiniteEnergy = false; - - @MinNumber(0.0001) - @MaxNumber(512) - @Desc("The rock zoom mostly for zooming in on a wispy palette") - private double rockZoom = 5; - - @Desc("The palette of blocks for 'stone'") - private IrisMaterialPalette rockPalette = new IrisMaterialPalette().qclear().qadd("stone"); - - @Desc("The palette of blocks for 'water'") - private IrisMaterialPalette fluidPalette = new IrisMaterialPalette().qclear().qadd("water"); - - @Desc("Cartographer map trade overrides") - private IrisVillagerOverride patchCartographers = new IrisVillagerOverride().setDisableTrade(false); - private final transient AtomicCache parallaxSize = new AtomicCache<>(); private final transient AtomicCache rockLayerGenerator = new AtomicCache<>(); private final transient AtomicCache fluidLayerGenerator = new AtomicCache<>(); @@ -280,6 +67,166 @@ public class IrisDimension extends IrisRegistrant { private final transient AtomicCache rad = new AtomicCache<>(); private final transient AtomicCache featuresUsed = new AtomicCache<>(); private final transient AtomicCache> strongholdsCache = new AtomicCache<>(); + @MinNumber(2) + @Required + @Desc("The human readable name of this dimension") + private String name = "A Dimension"; + @RegistryListResource(IrisJigsawStructure.class) + @Desc("If defined, Iris will place the given jigsaw structure where minecraft should place the overworld stronghold.") + private String stronghold; + @Desc("If set to true, Iris will remove chunks to allow visualizing cross sections of chunks easily") + private boolean debugChunkCrossSections = false; + @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") + private int explodeBiomePaletteSize = 3; + @MinNumber(2) + @MaxNumber(16) + @Desc("Every X/Z % debugCrossSectionsMod == 0 cuts the chunk") + private int debugCrossSectionsMod = 3; + @Desc("The average distance between strongholds") + private int strongholdJumpDistance = 1280; + @Desc("Define the maximum strongholds to place") + private int maxStrongholds = 14; + @Desc("Improves the biome grid variation by shuffling the cell grid more depending on the seed. This makes biomes across multiple seeds look far different than before.") + private boolean aggressiveBiomeReshuffle = false; + @Desc("Tree growth override settings") + private IrisTreeSettings treeSettings = new IrisTreeSettings(); + @Desc("Upon joining this world, Iris will send a resource pack request to the client. If they have previously selected yes, it will auto-switch depending on which dimension they go to.") + private String resourcePack = ""; + @Desc("Spawn Entities in this dimension over time. Iris will continually replenish these mobs just like vanilla does.") + @ArrayType(min = 1, type = String.class) + @RegistryListResource(IrisSpawner.class) + private KList entitySpawners = new KList<>(); + @Desc("Add specific features in exact positions") + @ArrayType(min = 1, type = IrisFeaturePositional.class) + private KList specificFeatures = new KList<>(); + @Desc("Add random chances for terrain features") + @ArrayType(min = 1, type = IrisFeaturePotential.class) + private KList features = new KList<>(); + @Desc("Reference loot tables in this area") + private IrisLootReference loot = new IrisLootReference(); + @MinNumber(0) + @Desc("The version of this dimension. Changing this will stop users from accidentally upgrading (and breaking their worlds).") + private int version = 1; + @ArrayType(min = 1, type = IrisBlockDrops.class) + @Desc("Define custom block drops for this dimension") + private KList blockDrops = new KList<>(); + @Desc("Should bedrock be generated or not.") + private boolean bedrock = true; + @MinNumber(0) + @MaxNumber(1) + @Desc("The land chance. Up to 1.0 for total land or 0.0 for total sea") + private double landChance = 0.625; + @Desc("The placement style of regions") + private IrisGeneratorStyle regionStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style(); + @Desc("The placement style of land/sea") + private IrisGeneratorStyle continentalStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style(); + @Desc("The placement style of biomes") + private IrisGeneratorStyle landBiomeStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style(); + @Desc("The placement style of biomes") + private IrisGeneratorStyle shoreBiomeStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style(); + @Desc("The placement style of biomes") + private IrisGeneratorStyle seaBiomeStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style(); + @Desc("The placement style of biomes") + private IrisGeneratorStyle caveBiomeStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style(); + @Desc("Instead of filling objects with air, fills them with cobweb so you can see them") + private boolean debugSmartBore = false; + @Desc("Generate decorations or not") + private boolean decorate = true; + @Desc("Use post processing or not") + private boolean postProcessing = true; + @Desc("Add slabs in post processing") + private boolean postProcessingSlabs = true; + @Desc("Add painted walls in post processing") + private boolean postProcessingWalls = true; + @Desc("Carving configuration for the dimension") + private IrisCarving carving = new IrisCarving(); + @Desc("Configuration of fluid bodies such as rivers & lakes") + private IrisFluidBodies fluidBodies = new IrisFluidBodies(); + @Desc("The world environment") + private Environment environment = Environment.NORMAL; + @RegistryListResource(IrisRegion.class) + @Required + @ArrayType(min = 1, type = String.class) + @Desc("Define all of the regions to include in this dimension. Dimensions -> Regions -> Biomes -> Objects etc") + private KList regions = new KList<>(); + @ArrayType(min = 1, type = IrisJigsawStructurePlacement.class) + @Desc("Jigsaw structures") + private KList jigsawStructures = new KList<>(); + @Required + @MinNumber(0) + @MaxNumber(255) + @Desc("The fluid height for this dimension") + private int fluidHeight = 63; + @RegistryListResource(IrisBiome.class) + @Desc("Keep this either undefined or empty. Setting any biome name into this will force iris to only generate the specified biome. Great for testing.") + private String focus = ""; + @RegistryListResource(IrisBiome.class) + @Desc("Keep this either undefined or empty. Setting any region name into this will force iris to only generate the specified region. Great for testing.") + private String focusRegion = ""; + @MinNumber(0.0001) + @MaxNumber(512) + @Desc("Zoom in or out the biome size. Higher = bigger biomes") + private double biomeZoom = 5D; + @MinNumber(0.0001) + @MaxNumber(512) + @Desc("Zoom in or out the terrain. This stretches the terrain. Due to performance improvements, Higher than 2.0 may cause weird rounding artifacts. Lower = more terrain changes per block. Its a true zoom-out.") + private double terrainZoom = 1D; + @MinNumber(0) + @MaxNumber(360) + @Desc("You can rotate the input coordinates by an angle. This can make terrain appear more natural (less sharp corners and lines). This literally rotates the entire dimension by an angle. Hint: Try 12 degrees or something not on a 90 or 45 degree angle.") + private double dimensionAngleDeg = 0; + @MinNumber(0) + @MaxNumber(8192) + @Desc("Coordinate fracturing applies noise to the input coordinates. This creates the 'iris swirls' and wavy features. The distance pushes these waves further into places they shouldnt be. This is a block value multiplier.") + private double coordFractureDistance = 20; + @MinNumber(0.0001) + @MaxNumber(512) + @Desc("Coordinate fracturing zoom. Higher = less frequent warping, Lower = more frequent and rapid warping / swirls.") + private double coordFractureZoom = 8; + @MinNumber(0.0001) + @MaxNumber(512) + @Desc("This zooms in the land space") + private double landZoom = 1; + @MinNumber(0.0001) + @MaxNumber(512) + @Desc("This zooms oceanic biomes") + private double seaZoom = 1; + @MinNumber(0.0001) + @MaxNumber(512) + @Desc("Zoom in continents") + private double continentZoom = 1; + @MinNumber(0.0001) + @MaxNumber(512) + @Desc("Change the size of regions") + private double regionZoom = 1; + @Desc("Disable this to stop placing objects, entities, features & updates") + private boolean useMantle = true; + @Desc("Prevent Leaf decay as if placed in creative mode") + private boolean preventLeafDecay = false; + @ArrayType(min = 1, type = IrisDepositGenerator.class) + @Desc("Define global deposit generators") + private KList deposits = new KList<>(); + @ArrayType(min = 1, type = IrisShapedGeneratorStyle.class) + @Desc("Overlay additional noise on top of the interoplated terrain.") + private KList overlayNoise = new KList<>(); + @Desc("If true, the spawner system has infinite energy. This is NOT recommended because it would allow for mobs to keep spawning over and over without a rate limit") + private boolean infiniteEnergy = false; + @MinNumber(0.0001) + @MaxNumber(512) + @Desc("The rock zoom mostly for zooming in on a wispy palette") + private double rockZoom = 5; + @Desc("The palette of blocks for 'stone'") + private IrisMaterialPalette rockPalette = new IrisMaterialPalette().qclear().qadd("stone"); + @Desc("The palette of blocks for 'water'") + private IrisMaterialPalette fluidPalette = new IrisMaterialPalette().qclear().qadd("water"); + @Desc("Cartographer map trade overrides") + private IrisVillagerOverride patchCartographers = new IrisVillagerOverride().setDisableTrade(false); public KList getStrongholds(long seed) { return strongholdsCache.aquire(() -> { diff --git a/src/main/java/com/volmit/iris/engine/object/IrisDirection.java b/src/main/java/com/volmit/iris/engine/object/IrisDirection.java index d8ec7e9b5..9cc17a8be 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisDirection.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisDirection.java @@ -59,6 +59,13 @@ public enum IrisDirection { private final int z; private final CuboidDirection f; + IrisDirection(int x, int y, int z, CuboidDirection f) { + this.x = x; + this.y = y; + this.z = z; + this.f = f; + } + public static IrisDirection getDirection(BlockFace f) { return switch (f) { case DOWN -> DOWN_NEGATIVE_Y; @@ -92,23 +99,6 @@ public enum IrisDirection { } - @Override - public String toString() { - return switch (this) { - case DOWN_NEGATIVE_Y -> "Down"; - case EAST_POSITIVE_X -> "East"; - case NORTH_NEGATIVE_Z -> "North"; - case SOUTH_POSITIVE_Z -> "South"; - case UP_POSITIVE_Y -> "Up"; - case WEST_NEGATIVE_X -> "West"; - }; - - } - - public boolean isVertical() { - return equals(DOWN_NEGATIVE_Y) || equals(UP_POSITIVE_Y); - } - public static IrisDirection closest(Vector v) { double m = Double.MAX_VALUE; IrisDirection s = null; @@ -160,75 +150,6 @@ public enum IrisDirection { return s; } - public Vector toVector() { - return new Vector(x, y, z); - } - - public boolean isCrooked(IrisDirection to) { - if (equals(to.reverse())) { - return false; - } - - return !equals(to); - } - - IrisDirection(int x, int y, int z, CuboidDirection f) { - this.x = x; - this.y = y; - this.z = z; - this.f = f; - } - - public Vector angle(Vector initial, IrisDirection d) { - calculatePermutations(); - - for (Map.Entry, DOP> entry : permute.entrySet()) { - GBiset i = entry.getKey(); - if (i.getA().equals(this) && i.getB().equals(d)) { - return entry.getValue().op(initial); - } - } - - return initial; - } - - public IrisDirection reverse() { - switch (this) { - case DOWN_NEGATIVE_Y: - return UP_POSITIVE_Y; - case EAST_POSITIVE_X: - return WEST_NEGATIVE_X; - case NORTH_NEGATIVE_Z: - return SOUTH_POSITIVE_Z; - case SOUTH_POSITIVE_Z: - return NORTH_NEGATIVE_Z; - case UP_POSITIVE_Y: - return DOWN_NEGATIVE_Y; - case WEST_NEGATIVE_X: - return EAST_POSITIVE_X; - default: - break; - } - - return EAST_POSITIVE_X; - } - - public int x() { - return x; - } - - public int y() { - return y; - } - - public int z() { - return z; - } - - public CuboidDirection f() { - return f; - } - public static KList news() { return new KList().add(NORTH_NEGATIVE_Z, EAST_POSITIVE_X, WEST_NEGATIVE_X, SOUTH_POSITIVE_Z); } @@ -277,32 +198,6 @@ public enum IrisDirection { } } - /** - * Get the byte value represented in some directional blocks - * - * @return the byte value - */ - public byte byteValue() { - switch (this) { - case DOWN_NEGATIVE_Y: - return 0; - case EAST_POSITIVE_X: - return 5; - case NORTH_NEGATIVE_Z: - return 2; - case SOUTH_POSITIVE_Z: - return 3; - case UP_POSITIVE_Y: - return 1; - case WEST_NEGATIVE_X: - return 4; - default: - break; - } - - return -1; - } - public static void calculatePermutations() { if (permute != null) { return; @@ -391,6 +286,111 @@ public enum IrisDirection { } } + @Override + public String toString() { + return switch (this) { + case DOWN_NEGATIVE_Y -> "Down"; + case EAST_POSITIVE_X -> "East"; + case NORTH_NEGATIVE_Z -> "North"; + case SOUTH_POSITIVE_Z -> "South"; + case UP_POSITIVE_Y -> "Up"; + case WEST_NEGATIVE_X -> "West"; + }; + + } + + public boolean isVertical() { + return equals(DOWN_NEGATIVE_Y) || equals(UP_POSITIVE_Y); + } + + public Vector toVector() { + return new Vector(x, y, z); + } + + public boolean isCrooked(IrisDirection to) { + if (equals(to.reverse())) { + return false; + } + + return !equals(to); + } + + public Vector angle(Vector initial, IrisDirection d) { + calculatePermutations(); + + for (Map.Entry, DOP> entry : permute.entrySet()) { + GBiset i = entry.getKey(); + if (i.getA().equals(this) && i.getB().equals(d)) { + return entry.getValue().op(initial); + } + } + + return initial; + } + + public IrisDirection reverse() { + switch (this) { + case DOWN_NEGATIVE_Y: + return UP_POSITIVE_Y; + case EAST_POSITIVE_X: + return WEST_NEGATIVE_X; + case NORTH_NEGATIVE_Z: + return SOUTH_POSITIVE_Z; + case SOUTH_POSITIVE_Z: + return NORTH_NEGATIVE_Z; + case UP_POSITIVE_Y: + return DOWN_NEGATIVE_Y; + case WEST_NEGATIVE_X: + return EAST_POSITIVE_X; + default: + break; + } + + return EAST_POSITIVE_X; + } + + public int x() { + return x; + } + + public int y() { + return y; + } + + public int z() { + return z; + } + + public CuboidDirection f() { + return f; + } + + /** + * Get the byte value represented in some directional blocks + * + * @return the byte value + */ + public byte byteValue() { + switch (this) { + case DOWN_NEGATIVE_Y: + return 0; + case EAST_POSITIVE_X: + return 5; + case NORTH_NEGATIVE_Z: + return 2; + case SOUTH_POSITIVE_Z: + return 3; + case UP_POSITIVE_Y: + return 1; + case WEST_NEGATIVE_X: + return 4; + default: + break; + } + + return -1; + } + public BlockFace getFace() { return switch (this) { case DOWN_NEGATIVE_Y -> BlockFace.DOWN; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisEffect.java b/src/main/java/com/volmit/iris/engine/object/IrisEffect.java index e8fad9b77..9a7e01c25 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisEffect.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisEffect.java @@ -21,7 +21,12 @@ package com.volmit.iris.engine.object; import com.volmit.iris.Iris; import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.framework.Engine; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.DependsOn; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.scheduling.ChronoLatch; import com.volmit.iris.util.scheduling.J; @@ -45,132 +50,108 @@ import org.bukkit.util.Vector; @Desc("An iris effect") @Data public class IrisEffect { + private final transient AtomicCache pt = new AtomicCache<>(); + private final transient AtomicCache latch = new AtomicCache<>(); @Desc("The potion effect to apply in this area") private String potionEffect = ""; - @Desc("The particle effect to apply in the area") private Particle particleEffect = null; - @DependsOn({"particleEffect"}) @MinNumber(-32) @MaxNumber(32) @Desc("Randomly offset from the surface to this surface+value") private int particleOffset = 0; - @DependsOn({"particleEffect"}) @MinNumber(-8) @MaxNumber(8) @Desc("The alt x, usually represents motion if the particle count is zero. Otherwise an offset.") private double particleAltX = 0; - @DependsOn({"particleEffect"}) @MinNumber(-8) @MaxNumber(8) @Desc("The alt y, usually represents motion if the particle count is zero. Otherwise an offset.") private double particleAltY = 0; - @DependsOn({"particleEffect"}) @MinNumber(-8) @MaxNumber(8) @Desc("The alt z, usually represents motion if the particle count is zero. Otherwise an offset.") private double particleAltZ = 0; - @DependsOn({"particleEffect"}) @Desc("Randomize the altX by -altX to altX") private boolean randomAltX = true; - @DependsOn({"particleEffect"}) @Desc("Randomize the altY by -altY to altY") private boolean randomAltY = false; - @DependsOn({"particleEffect"}) @Desc("Randomize the altZ by -altZ to altZ") private boolean randomAltZ = true; - @Desc("The sound to play") private Sound sound = null; - @DependsOn({"sound"}) @MinNumber(0) @MaxNumber(512) @Desc("The max distance from the player the sound will play") private int soundDistance = 12; - @DependsOn({"sound", "maxPitch"}) @MinNumber(0.01) @MaxNumber(1.99) @Desc("The minimum sound pitch") private double minPitch = 0.5D; - @DependsOn({"sound", "minVolume"}) @MinNumber(0.01) @MaxNumber(1.99) @Desc("The max sound pitch") private double maxPitch = 1.5D; - @DependsOn({"sound"}) @MinNumber(0.001) @MaxNumber(512) @Desc("The sound volume.") private double volume = 1.5D; - @DependsOn({"particleEffect"}) @MinNumber(0) @MaxNumber(512) @Desc("The particle count. Try setting to zero for using the alt xyz to a motion value instead of an offset") private int particleCount = 0; - @DependsOn({"particleEffect"}) @MinNumber(0) @MaxNumber(64) @Desc("How far away from the player particles can play") private int particleDistance = 20; - @DependsOn({"particleEffect"}) @MinNumber(0) @MaxNumber(128) @Desc("How wide the particles can play (player's view left and right) RADIUS") private int particleDistanceWidth = 24; - @DependsOn({"particleEffect"}) @Desc("An extra value for some particles... Which bukkit doesn't even document.") private double extra = 0; - @DependsOn({"potionEffect"}) @MinNumber(-1) @MaxNumber(1024) @Desc("The Potion Strength or -1 to disable") private int potionStrength = -1; - @DependsOn({"potionEffect", "potionTicksMin"}) @MinNumber(1) @Desc("The max time the potion will last for") private int potionTicksMax = 155; - @DependsOn({"potionEffect", "potionTicksMax"}) @MinNumber(1) @Desc("The min time the potion will last for") private int potionTicksMin = 75; - @Required @MinNumber(0) @Desc("The effect interval in milliseconds") private int interval = 150; - @DependsOn({"particleEffect"}) @MinNumber(0) @MaxNumber(16) @Desc("The effect distance start away") private int particleAway = 5; - @Required @MinNumber(1) @Desc("The chance is 1 in CHANCE per interval") private int chance = 50; - private final transient AtomicCache pt = new AtomicCache<>(); - private final transient AtomicCache latch = new AtomicCache<>(); - public boolean canTick() { return latch.aquire(() -> new ChronoLatch(interval)).flip(); } diff --git a/src/main/java/com/volmit/iris/engine/object/IrisElipsoid.java b/src/main/java/com/volmit/iris/engine/object/IrisElipsoid.java index b15b6cf8c..35ff3c9ac 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisElipsoid.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisElipsoid.java @@ -21,7 +21,11 @@ package com.volmit.iris.engine.object; import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.mantle.MantleWriter; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.matter.MatterCavern; import com.volmit.iris.util.matter.slices.CavernMatter; @@ -31,24 +35,20 @@ import lombok.Data; @Desc("Represents an procedural eliptical shape") @Data public class IrisElipsoid implements IRare { + private transient final AtomicCache matterNodeCache = new AtomicCache<>(); @Required @Desc("Typically a 1 in RARITY on a per fork basis") @MinNumber(1) private int rarity = 1; - @RegistryListResource(IrisBiome.class) @Desc("Force this cave to only generate the specified custom biome") private String customBiome = ""; - @Desc("The styled random radius for x") private IrisStyledRange xRadius = new IrisStyledRange(1, 5, new IrisGeneratorStyle(NoiseStyle.STATIC)); - @Desc("The styled random radius for y") private IrisStyledRange yRadius = new IrisStyledRange(1, 5, new IrisGeneratorStyle(NoiseStyle.STATIC)); - @Desc("The styled random radius for z") private IrisStyledRange zRadius = new IrisStyledRange(1, 5, new IrisGeneratorStyle(NoiseStyle.STATIC)); - private transient final AtomicCache matterNodeCache = new AtomicCache<>(); @SuppressWarnings("SuspiciousNameCombination") public void generate(RNG rng, Engine engine, MantleWriter writer, int x, int y, int z) { diff --git a/src/main/java/com/volmit/iris/engine/object/IrisEnchantment.java b/src/main/java/com/volmit/iris/engine/object/IrisEnchantment.java index e98a40dde..2988d6807 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisEnchantment.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisEnchantment.java @@ -19,7 +19,11 @@ package com.volmit.iris.engine.object; import com.volmit.iris.Iris; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.math.RNG; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisEntity.java b/src/main/java/com/volmit/iris/engine/object/IrisEntity.java index e3fb62723..497e0e19d 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisEntity.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisEntity.java @@ -21,7 +21,11 @@ package com.volmit.iris.engine.object; import com.volmit.iris.Iris; import com.volmit.iris.core.loader.IrisRegistrant; import com.volmit.iris.engine.framework.Engine; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.RegistryListSpecialEntity; +import com.volmit.iris.engine.object.annotations.Required; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.format.C; import com.volmit.iris.util.json.JSONObject; @@ -36,10 +40,20 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.experimental.Accessors; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.NamespacedKey; +import org.bukkit.Particle; +import org.bukkit.Sound; import org.bukkit.attribute.Attributable; -import org.bukkit.entity.*; +import org.bukkit.entity.Ageable; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Mob; +import org.bukkit.entity.Panda; import org.bukkit.entity.Panda.Gene; +import org.bukkit.entity.Villager; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.loot.LootContext; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisEntitySpawn.java b/src/main/java/com/volmit/iris/engine/object/IrisEntitySpawn.java index a348eb5cd..3c48938ae 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisEntitySpawn.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisEntitySpawn.java @@ -21,7 +21,11 @@ package com.volmit.iris.engine.object; import com.volmit.iris.Iris; import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.framework.Engine; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.format.C; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.matter.slices.MarkerMatter; @@ -40,29 +44,24 @@ import org.bukkit.entity.Entity; @Desc("Represents an entity spawn during initial chunk generation") @Data public class IrisEntitySpawn implements IRare { + private final transient AtomicCache rng = new AtomicCache<>(); + private final transient AtomicCache ent = new AtomicCache<>(); @RegistryListResource(IrisEntity.class) @Required @Desc("The entity") private String entity = ""; - @Desc("The energy multiplier when calculating spawn energy usage") private double energyMultiplier = 1; - @MinNumber(1) @Desc("The 1 in RARITY chance for this entity to spawn") private int rarity = 1; - @MinNumber(1) @Desc("The minumum of this entity to spawn") private int minSpawns = 1; - @MinNumber(1) @Desc("The max of this entity to spawn") private int maxSpawns = 1; - private transient IrisSpawner referenceSpawner; - private final transient AtomicCache rng = new AtomicCache<>(); - private final transient AtomicCache ent = new AtomicCache<>(); public int spawn(Engine gen, Chunk c, RNG rng) { int spawns = minSpawns == maxSpawns ? minSpawns : rng.i(Math.min(minSpawns, maxSpawns), Math.max(minSpawns, maxSpawns)); diff --git a/src/main/java/com/volmit/iris/engine/object/IrisFeature.java b/src/main/java/com/volmit/iris/engine/object/IrisFeature.java index 93cc55204..e23186cd9 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisFeature.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisFeature.java @@ -20,7 +20,13 @@ package com.volmit.iris.engine.object; import com.google.gson.Gson; import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.interpolation.InterpolationMethod; import com.volmit.iris.util.interpolation.IrisInterpolation; @@ -89,6 +95,10 @@ public class IrisFeature { private transient AtomicCache actualRadius = new AtomicCache<>(); + public static IrisFeature read(DataInputStream s) throws IOException { + return new Gson().fromJson(s.readUTF(), IrisFeature.class); + } + public double getActualRadius() { return actualRadius.aquire(() -> { double o = 0; @@ -101,10 +111,6 @@ public class IrisFeature { }); } - public static IrisFeature read(DataInputStream s) throws IOException { - return new Gson().fromJson(s.readUTF(), IrisFeature.class); - } - public void write(DataOutputStream s) throws IOException { s.writeUTF(new Gson().toJson(this)); } diff --git a/src/main/java/com/volmit/iris/engine/object/IrisFeaturePositional.java b/src/main/java/com/volmit/iris/engine/object/IrisFeaturePositional.java index b4d359383..8ac36b5eb 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisFeaturePositional.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisFeaturePositional.java @@ -42,12 +42,7 @@ import java.io.IOException; @NoArgsConstructor @Desc("Represents an Iris zone") public class IrisFeaturePositional { - public IrisFeaturePositional(int x, int z, IrisFeature feature) { - this.x = x; - this.z = z; - this.feature = feature; - } - + private static double BLOCK = 1D / 256D; // TODO: WARNING HEIGHT @Required @Desc("The x coordinate of this zone") private int x; @@ -61,7 +56,11 @@ public class IrisFeaturePositional { private IrisFeature feature; private transient AtomicCache provider = new AtomicCache<>(); - private static double BLOCK = 1D / 256D; // TODO: WARNING HEIGHT + public IrisFeaturePositional(int x, int z, IrisFeature feature) { + this.x = x; + this.z = z; + this.feature = feature; + } public static IrisFeaturePositional read(DataInputStream s) throws IOException { String sx = s.readUTF(); diff --git a/src/main/java/com/volmit/iris/engine/object/IrisGenerator.java b/src/main/java/com/volmit/iris/engine/object/IrisGenerator.java index ec722b1ee..ffd2532ed 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisGenerator.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisGenerator.java @@ -21,7 +21,11 @@ package com.volmit.iris.engine.object; import com.volmit.iris.Iris; import com.volmit.iris.core.loader.IrisRegistrant; import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.Required; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.interpolation.IrisInterpolation; import com.volmit.iris.util.json.JSONObject; @@ -44,66 +48,51 @@ import java.util.List; @Data @EqualsAndHashCode(callSuper = false) public class IrisGenerator extends IrisRegistrant { + private final transient AtomicCache cellGen = new AtomicCache<>(); @MinNumber(0.001) @Desc("The zoom or frequency.") private double zoom = 1; - @MinNumber(0) @Desc("The opacity, essentially a multiplier on the output.") private double opacity = 1; - @Desc("Multiply the compsites instead of adding them") private boolean multiplicitive = false; - @MinNumber(0.001) @Desc("The size of the cell fractures") private double cellFractureZoom = 1D; - @MinNumber(0) @Desc("Cell Fracture Coordinate Shuffling") private double cellFractureShuffle = 12D; - @Desc("The height of fracture cells. Set to 0 to disable") private double cellFractureHeight = 0D; - @MinNumber(0) @MaxNumber(1) @Desc("How big are the cells (X,Z) relative to the veins that touch them. Between 0 and 1. 0.1 means thick veins, small cells.") private double cellPercentSize = 0.75D; - @Desc("The offset to shift this noise x") private double offsetX = 0; - @Desc("The offset to shift this noise z") private double offsetZ = 0; - @Required @Desc("The seed for this generator") private long seed = 1; - @Required @Desc("The interpolator to use when smoothing this generator into other regions & generators") private IrisInterpolator interpolator = new IrisInterpolator(); - @MinNumber(0) @MaxNumber(8192) @Desc("Cliff Height Max. Disable with 0 for min and max") private double cliffHeightMax = 0; - @MinNumber(0) @MaxNumber(8192) @Desc("Cliff Height Min. Disable with 0 for min and max") private double cliffHeightMin = 0; - @ArrayType(min = 1, type = IrisNoiseGenerator.class) @Desc("The list of noise gens this gen contains.") private KList composite = new KList<>(); - @Desc("The noise gen for cliff height.") private IrisNoiseGenerator cliffHeightGenerator = new IrisNoiseGenerator(); - private final transient AtomicCache cellGen = new AtomicCache<>(); - public double getMax() { return opacity; } diff --git a/src/main/java/com/volmit/iris/engine/object/IrisGeneratorStyle.java b/src/main/java/com/volmit/iris/engine/object/IrisGeneratorStyle.java index c28b76070..7981ec1ce 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisGeneratorStyle.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisGeneratorStyle.java @@ -20,7 +20,11 @@ package com.volmit.iris.engine.object; import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.noise.CNG; import com.volmit.iris.util.noise.ExpressionNoise; @@ -36,34 +40,27 @@ import lombok.experimental.Accessors; @Desc("A gen style") @Data public class IrisGeneratorStyle { + private final transient AtomicCache cng = new AtomicCache<>(); @Desc("The chance is 1 in CHANCE per interval") private NoiseStyle style = NoiseStyle.FLAT; - @MinNumber(0.00001) @Desc("The zoom of this style") private double zoom = 1; - @Desc("Instead of using the style property, use a custom expression to represent this style.") @RegistryListResource(IrisExpression.class) private String expression = null; - @MinNumber(0.00001) @Desc("The Output multiplier. Only used if parent is fracture.") private double multiplier = 1; - @Desc("If set to true, each dimension will be fractured with a different order of input coordinates. This is usually 2 or 3 times slower than normal.") private boolean axialFracturing = false; - @Desc("Apply a generator to the coordinate field fed into this parent generator. I.e. Distort your generator with another generator.") private IrisGeneratorStyle fracture = null; - @MinNumber(0.01562) @MaxNumber(64) @Desc("The exponent") private double exponent = 1; - private final transient AtomicCache cng = new AtomicCache<>(); - public IrisGeneratorStyle(NoiseStyle s) { this.style = s; } diff --git a/src/main/java/com/volmit/iris/engine/object/IrisInterpolator.java b/src/main/java/com/volmit/iris/engine/object/IrisInterpolator.java index 724b72225..90998844c 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisInterpolator.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisInterpolator.java @@ -18,7 +18,11 @@ package com.volmit.iris.engine.object; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.function.NoiseProvider; import com.volmit.iris.util.interpolation.InterpolationMethod; import com.volmit.iris.util.interpolation.IrisInterpolation; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisInterpolator3D.java b/src/main/java/com/volmit/iris/engine/object/IrisInterpolator3D.java index 6e707d2a3..26786c12d 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisInterpolator3D.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisInterpolator3D.java @@ -18,7 +18,11 @@ package com.volmit.iris.engine.object; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.function.NoiseProvider3; import com.volmit.iris.util.interpolation.InterpolationMethod3D; import com.volmit.iris.util.interpolation.IrisInterpolation; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisJigsawPieceConnector.java b/src/main/java/com/volmit/iris/engine/object/IrisJigsawPieceConnector.java index 97d352bf4..65881e9e4 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisJigsawPieceConnector.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisJigsawPieceConnector.java @@ -18,7 +18,14 @@ package com.volmit.iris.engine.object; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.DependsOn; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisJigsawPlacement.java b/src/main/java/com/volmit/iris/engine/object/IrisJigsawPlacement.java index 8f976f2eb..a3d7f6ea5 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisJigsawPlacement.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisJigsawPlacement.java @@ -18,7 +18,11 @@ package com.volmit.iris.engine.object; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisJigsawStructure.java b/src/main/java/com/volmit/iris/engine/object/IrisJigsawStructure.java index afc09a072..7acbab6b1 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisJigsawStructure.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisJigsawStructure.java @@ -21,7 +21,12 @@ package com.volmit.iris.engine.object; import com.volmit.iris.Iris; import com.volmit.iris.core.loader.IrisRegistrant; import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.json.JSONObject; import com.volmit.iris.util.plugin.VolmitSender; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisLake.java b/src/main/java/com/volmit/iris/engine/object/IrisLake.java index a8a47728f..dbe33cfaf 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisLake.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisLake.java @@ -21,7 +21,11 @@ package com.volmit.iris.engine.object; import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.mantle.MantleWriter; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.matter.MatterFluidBody; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisLoot.java b/src/main/java/com/volmit/iris/engine/object/IrisLoot.java index 5600a0380..d266752b6 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisLoot.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisLoot.java @@ -20,7 +20,13 @@ package com.volmit.iris.engine.object; import com.volmit.iris.Iris; import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListItemType; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.data.B; import com.volmit.iris.util.format.C; @@ -40,7 +46,7 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.LeatherArmorMeta; import org.bukkit.material.Colorable; -import java.awt.*; +import java.awt.Color; @Snippet("loot") @Accessors(chain = true) @@ -49,70 +55,54 @@ import java.awt.*; @Desc("Represents a loot entry") @Data public class IrisLoot { + private final transient AtomicCache chance = new AtomicCache<>(); @Desc("The target inventory slot types to fill this loot with") private InventorySlotType slotTypes = InventorySlotType.STORAGE; - @MinNumber(1) @Desc("The sub rarity of this loot. Calculated after this loot table has been picked.") private int rarity = 1; - @MinNumber(1) @Desc("Minimum amount of this loot") private int minAmount = 1; - @MinNumber(1) @Desc("Maximum amount of this loot") private int maxAmount = 1; - @MinNumber(1) @Desc("The display name of this item") private String displayName = null; - @MinNumber(0) @MaxNumber(1) @Desc("Minimum durability percent") private double minDurability = 0; - @MinNumber(0) @MaxNumber(1) @Desc("Maximum durability percent") private double maxDurability = 1; - @Desc("Define a custom model identifier 1.14+ only") private Integer customModel = null; - @Desc("Set this to true to prevent it from being broken") private boolean unbreakable = false; - @ArrayType(min = 1, type = ItemFlag.class) @Desc("The item flags to add") private KList itemFlags = new KList<>(); - @Desc("Apply enchantments to this item") @ArrayType(min = 1, type = IrisEnchantment.class) private KList enchantments = new KList<>(); - @Desc("Apply attribute modifiers to this item") @ArrayType(min = 1, type = IrisAttributeModifier.class) private KList attributes = new KList<>(); - @ArrayType(min = 1, type = String.class) @Desc("Add lore to this item") private KList lore = new KList<>(); - @RegistryListItemType @Required @Desc("This is the item or block type. Does not accept minecraft:*. Only materials such as DIAMOND_SWORD or DIRT.") private String type = ""; - @Desc("The dye color") private DyeColor dyeColor = null; - @Desc("The leather armor color") private String leatherColor = null; - private final transient AtomicCache chance = new AtomicCache<>(); - public Material getType() { return B.getMaterial(type); } diff --git a/src/main/java/com/volmit/iris/engine/object/IrisLootReference.java b/src/main/java/com/volmit/iris/engine/object/IrisLootReference.java index 7718ae226..e7563e091 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisLootReference.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisLootReference.java @@ -19,7 +19,11 @@ package com.volmit.iris.engine.object; import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.data.DataProvider; import lombok.AllArgsConstructor; @@ -34,20 +38,17 @@ import lombok.experimental.Accessors; @Desc("Represents a loot entry") @Data public class IrisLootReference { + private final transient AtomicCache> tt = new AtomicCache<>(); @Desc("Add = add on top of parent tables, Replace = clear first then add these. Clear = Remove all and dont add loot from this or parent.") private IrisLootMode mode = IrisLootMode.ADD; - @RegistryListResource(IrisLootTable.class) @ArrayType(min = 1, type = String.class) @Desc("Add loot table registries here") private KList tables = new KList<>(); - @MinNumber(0) @Desc("Increase the chance of loot in this area") private double multiplier = 1D; - private final transient AtomicCache> tt = new AtomicCache<>(); - public KList getLootTables(DataProvider g) { return tt.aquire(() -> { diff --git a/src/main/java/com/volmit/iris/engine/object/IrisMaterialPalette.java b/src/main/java/com/volmit/iris/engine/object/IrisMaterialPalette.java index 0cec5fec3..b4133662e 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisMaterialPalette.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisMaterialPalette.java @@ -20,7 +20,11 @@ package com.volmit.iris.engine.object; import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.noise.CNG; @@ -37,22 +41,19 @@ import org.bukkit.block.data.BlockData; @Desc("A palette of materials") @Data public class IrisMaterialPalette { + private final transient AtomicCache> blockData = new AtomicCache<>(); + private final transient AtomicCache layerGenerator = new AtomicCache<>(); + private final transient AtomicCache heightGenerator = new AtomicCache<>(); @Desc("The style of noise") private IrisGeneratorStyle style = NoiseStyle.STATIC.style(); - @MinNumber(0.0001) @Desc("The terrain zoom mostly for zooming in on a wispy palette") private double zoom = 5; - @Required @ArrayType(min = 1, type = IrisBlockData.class) @Desc("The palette of blocks to be used in this layer") private KList palette = new KList().qadd(new IrisBlockData("STONE")); - private final transient AtomicCache> blockData = new AtomicCache<>(); - private final transient AtomicCache layerGenerator = new AtomicCache<>(); - private final transient AtomicCache heightGenerator = new AtomicCache<>(); - public BlockData get(RNG rng, double x, double y, double z, IrisData rdata) { if (getBlockData(rdata).isEmpty()) { return null; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisMod.java b/src/main/java/com/volmit/iris/engine/object/IrisMod.java index d8f2724da..1ce56f6b6 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisMod.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisMod.java @@ -19,7 +19,12 @@ package com.volmit.iris.engine.object; import com.volmit.iris.core.loader.IrisRegistrant; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.json.JSONObject; import com.volmit.iris.util.plugin.VolmitSender; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisModBiomeInjector.java b/src/main/java/com/volmit/iris/engine/object/IrisModBiomeInjector.java index 3947a0632..b9ff78642 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisModBiomeInjector.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisModBiomeInjector.java @@ -18,7 +18,11 @@ package com.volmit.iris.engine.object; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisModBiomeReplacer.java b/src/main/java/com/volmit/iris/engine/object/IrisModBiomeReplacer.java index ff5fae59d..3f92bed92 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisModBiomeReplacer.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisModBiomeReplacer.java @@ -18,7 +18,11 @@ package com.volmit.iris.engine.object; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisModNoiseStyleReplacer.java b/src/main/java/com/volmit/iris/engine/object/IrisModNoiseStyleReplacer.java index 3dc31ffef..47d453496 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisModNoiseStyleReplacer.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisModNoiseStyleReplacer.java @@ -18,7 +18,11 @@ package com.volmit.iris.engine.object; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisModObjectPlacementBiomeInjector.java b/src/main/java/com/volmit/iris/engine/object/IrisModObjectPlacementBiomeInjector.java index 7a53f92fd..17106a686 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisModObjectPlacementBiomeInjector.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisModObjectPlacementBiomeInjector.java @@ -18,7 +18,11 @@ package com.volmit.iris.engine.object; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisModObjectPlacementRegionInjector.java b/src/main/java/com/volmit/iris/engine/object/IrisModObjectPlacementRegionInjector.java index 4c6bb3b53..a0a3d466c 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisModObjectPlacementRegionInjector.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisModObjectPlacementRegionInjector.java @@ -18,7 +18,11 @@ package com.volmit.iris.engine.object; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisModObjectReplacer.java b/src/main/java/com/volmit/iris/engine/object/IrisModObjectReplacer.java index bfdd92ab1..eddc0d0fe 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisModObjectReplacer.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisModObjectReplacer.java @@ -18,7 +18,11 @@ package com.volmit.iris.engine.object; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisModRegionReplacer.java b/src/main/java/com/volmit/iris/engine/object/IrisModRegionReplacer.java index 00acdaf54..0afd0a74b 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisModRegionReplacer.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisModRegionReplacer.java @@ -18,7 +18,11 @@ package com.volmit.iris.engine.object; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisNoiseGenerator.java b/src/main/java/com/volmit/iris/engine/object/IrisNoiseGenerator.java index 50e476b20..5f8dadbfe 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisNoiseGenerator.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisNoiseGenerator.java @@ -20,7 +20,12 @@ package com.volmit.iris.engine.object; import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.interpolation.IrisInterpolation; import com.volmit.iris.util.math.RNG; @@ -37,60 +42,45 @@ import lombok.experimental.Accessors; @Desc("A noise generator") @Data public class IrisNoiseGenerator { + private final transient AtomicCache generator = new AtomicCache<>(); @MinNumber(0.0001) @Desc("The coordinate input zoom") private double zoom = 1; - @Desc("Reverse the output. So that noise = -noise + opacity") private boolean negative = false; - @MinNumber(0) @MaxNumber(1) @Desc("The output multiplier") private double opacity = 1; - @Desc("Coordinate offset x") private double offsetX = 0; - @Desc("Height output offset y. Avoid using with terrain generation.") private double offsetY = 0; - @Desc("Coordinate offset z") private double offsetZ = 0; - @Required @Desc("The seed") private long seed = 0; - @Desc("Apply a parametric curve on the output") private boolean parametric = false; - @Desc("Apply a bezier curve on the output") private boolean bezier = false; - @Desc("Apply a sin-center curve on the output (0, and 1 = 0 and 0.5 = 1.0 using a sinoid shape.)") private boolean sinCentered = false; - @Desc("The exponent noise^EXPONENT") private double exponent = 1; - @Desc("Enable / disable. Outputs offsetY if disabled") private boolean enabled = true; - @Required @Desc("The Noise Style") private IrisGeneratorStyle style = NoiseStyle.IRIS.style(); - @MinNumber(1) @Desc("Multiple octaves for multple generators of changing zooms added together") private int octaves = 1; - @ArrayType(min = 1, type = IrisNoiseGenerator.class) @Desc("Apply a child noise generator to fracture the input coordinates of this generator") private KList fracture = new KList<>(); - private final transient AtomicCache generator = new AtomicCache<>(); - public IrisNoiseGenerator(boolean enabled) { this(); this.enabled = enabled; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObject.java b/src/main/java/com/volmit/iris/engine/object/IrisObject.java index 9b833beb5..f449acd8a 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObject.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObject.java @@ -49,8 +49,19 @@ import org.bukkit.block.data.type.Leaves; import org.bukkit.util.BlockVector; import org.bukkit.util.Vector; -import java.io.*; -import java.util.*; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; import java.util.function.Consumer; @SuppressWarnings("DefaultAnnotationParam") @@ -62,7 +73,15 @@ public class IrisObject extends IrisRegistrant { protected static final BlockData VAIR = B.get("VOID_AIR"); protected static final BlockData VAIR_DEBUG = B.get("COBWEB"); protected static final BlockData[] SNOW_LAYERS = new BlockData[]{B.get("minecraft:snow[layers=1]"), B.get("minecraft:snow[layers=2]"), B.get("minecraft:snow[layers=3]"), B.get("minecraft:snow[layers=4]"), B.get("minecraft:snow[layers=5]"), B.get("minecraft:snow[layers=6]"), B.get("minecraft:snow[layers=7]"), B.get("minecraft:snow[layers=8]")}; - + protected transient final IrisLock readLock = new IrisLock("read-conclock"); + @Getter + @Setter + protected transient volatile boolean smartBored = false; + @Getter + @Setter + protected transient IrisLock lock = new IrisLock("Preloadcache"); + @Setter + protected transient AtomicCache aabb = new AtomicCache<>(); private KMap blocks; private KMap> states; @Getter @@ -74,18 +93,9 @@ public class IrisObject extends IrisRegistrant { @Getter @Setter private int h; - protected transient final IrisLock readLock = new IrisLock("read-conclock"); @Getter @Setter private transient BlockVector center; - @Getter - @Setter - protected transient volatile boolean smartBored = false; - @Getter - @Setter - protected transient IrisLock lock = new IrisLock("Preloadcache"); - @Setter - protected transient AtomicCache aabb = new AtomicCache<>(); public IrisObject(int w, int h, int d) { blocks = new KMap<>(); @@ -100,10 +110,6 @@ public class IrisObject extends IrisRegistrant { this(0, 0, 0); } - public AxisAlignedBB getAABB() { - return aabb.aquire(() -> getAABBFor(new BlockVector(w, h, d))); - } - public static BlockVector getCenterForSize(BlockVector size) { return new BlockVector(size.getX() / 2, size.getY() / 2, size.getZ() / 2); } @@ -114,6 +120,38 @@ public class IrisObject extends IrisRegistrant { new IrisPosition(new BlockVector(size.getX() - 1, size.getY() - 1, size.getZ() - 1).subtract(center).toBlockVector())); } + @SuppressWarnings({"resource", "RedundantSuppression"}) + public static BlockVector sampleSize(File file) throws IOException { + FileInputStream in = new FileInputStream(file); + DataInputStream din = new DataInputStream(in); + BlockVector bv = new BlockVector(din.readInt(), din.readInt(), din.readInt()); + Iris.later(din::close); + return bv; + } + + private static List blocksBetweenTwoPoints(Vector loc1, Vector loc2) { + List locations = new ArrayList<>(); + int topBlockX = Math.max(loc1.getBlockX(), loc2.getBlockX()); + int bottomBlockX = Math.min(loc1.getBlockX(), loc2.getBlockX()); + int topBlockY = Math.max(loc1.getBlockY(), loc2.getBlockY()); + int bottomBlockY = Math.min(loc1.getBlockY(), loc2.getBlockY()); + int topBlockZ = Math.max(loc1.getBlockZ(), loc2.getBlockZ()); + int bottomBlockZ = Math.min(loc1.getBlockZ(), loc2.getBlockZ()); + + for (int x = bottomBlockX; x <= topBlockX; x++) { + for (int z = bottomBlockZ; z <= topBlockZ; z++) { + for (int y = bottomBlockY; y <= topBlockY; y++) { + locations.add(new BlockVector(x, y, z)); + } + } + } + return locations; + } + + public AxisAlignedBB getAABB() { + return aabb.aquire(() -> getAABBFor(new BlockVector(w, h, d))); + } + public void ensureSmartBored(boolean debug) { if (smartBored) { return; @@ -240,15 +278,6 @@ public class IrisObject extends IrisRegistrant { return o; } - @SuppressWarnings({"resource", "RedundantSuppression"}) - public static BlockVector sampleSize(File file) throws IOException { - FileInputStream in = new FileInputStream(file); - DataInputStream din = new DataInputStream(in); - BlockVector bv = new BlockVector(din.readInt(), din.readInt(), din.readInt()); - Iris.later(din::close); - return bv; - } - public void readLegacy(InputStream in) throws IOException { DataInputStream din = new DataInputStream(in); this.w = din.readInt(); @@ -471,7 +500,7 @@ public class IrisObject extends IrisRegistrant { for (int j = z - (rotatedDimensions.getBlockZ() / 2) + offset.getBlockZ(); j <= z + (rotatedDimensions.getBlockZ() / 2) + offset.getBlockZ(); j++) { int h = placer.getHighest(i, j, getLoader(), config.isUnderwater()) + rty; - if (placer.isCarved(i, h, j) || placer.isCarved(i, h-1, j) || placer.isCarved(i, h-2, j) || placer.isCarved(i, h-3, j)) { + if (placer.isCarved(i, h, j) || placer.isCarved(i, h - 1, j) || placer.isCarved(i, h - 2, j) || placer.isCarved(i, h - 3, j)) { bail = true; break; } @@ -489,7 +518,7 @@ public class IrisObject extends IrisRegistrant { for (int j = z - (rotatedDimensions.getBlockZ() / 2) + offset.getBlockZ(); j <= z + (rotatedDimensions.getBlockZ() / 2) + offset.getBlockZ(); j += (rotatedDimensions.getBlockZ() / 2) + 1) { int h = placer.getHighest(i, j, getLoader(), config.isUnderwater()) + rty; - if (placer.isCarved(i, h, j) || placer.isCarved(i, h-1, j) || placer.isCarved(i, h-2, j) || placer.isCarved(i, h-3, j)) { + if (placer.isCarved(i, h, j) || placer.isCarved(i, h - 1, j) || placer.isCarved(i, h - 2, j) || placer.isCarved(i, h - 3, j)) { bail = true; break; } @@ -507,7 +536,7 @@ public class IrisObject extends IrisRegistrant { for (int i = x - (rotatedDimensions.getBlockX() / 2) + offset.getBlockX(); i <= x + (rotatedDimensions.getBlockX() / 2) + offset.getBlockX(); i++) { for (int j = z - (rotatedDimensions.getBlockZ() / 2) + offset.getBlockZ(); j <= z + (rotatedDimensions.getBlockZ() / 2) + offset.getBlockZ(); j++) { int h = placer.getHighest(i, j, getLoader(), config.isUnderwater()) + rty; - if (placer.isCarved(i, h, j) || placer.isCarved(i, h-1, j) || placer.isCarved(i, h-2, j) || placer.isCarved(i, h-3, j)) { + if (placer.isCarved(i, h, j) || placer.isCarved(i, h - 1, j) || placer.isCarved(i, h - 2, j) || placer.isCarved(i, h - 3, j)) { bail = true; break; } @@ -524,7 +553,7 @@ public class IrisObject extends IrisRegistrant { for (int i = x - (rotatedDimensions.getBlockX() / 2) + offset.getBlockX(); i <= x + (rotatedDimensions.getBlockX() / 2) + offset.getBlockX(); i += (rotatedDimensions.getBlockX() / 2) + 1) { for (int j = z - (rotatedDimensions.getBlockZ() / 2) + offset.getBlockZ(); j <= z + (rotatedDimensions.getBlockZ() / 2) + offset.getBlockZ(); j += (rotatedDimensions.getBlockZ() / 2) + 1) { int h = placer.getHighest(i, j, getLoader(), config.isUnderwater()) + rty; - if (placer.isCarved(i, h, j) || placer.isCarved(i, h-1, j) || placer.isCarved(i, h-2, j) || placer.isCarved(i, h-3, j)) { + if (placer.isCarved(i, h, j) || placer.isCarved(i, h - 1, j) || placer.isCarved(i, h - 2, j) || placer.isCarved(i, h - 3, j)) { bail = true; break; } @@ -535,20 +564,20 @@ public class IrisObject extends IrisRegistrant { } } else if (config.getMode().equals(ObjectPlaceMode.PAINT)) { y = placer.getHighest(x, z, getLoader(), config.isUnderwater()) + rty; - if (placer.isCarved(x, y, z) || placer.isCarved(x, y-1, z)|| placer.isCarved(x, y-2, z)|| placer.isCarved(x, y-3, z)) { + if (placer.isCarved(x, y, z) || placer.isCarved(x, y - 1, z) || placer.isCarved(x, y - 2, z) || placer.isCarved(x, y - 3, z)) { bail = true; } } } else { y = yv; - if (placer.isCarved(x, y, z) || placer.isCarved(x, y-1, z)|| placer.isCarved(x, y-2, z)|| placer.isCarved(x, y-3, z)) { + if (placer.isCarved(x, y, z) || placer.isCarved(x, y - 1, z) || placer.isCarved(x, y - 2, z) || placer.isCarved(x, y - 3, z)) { bail = true; } } if (yv >= 0 && config.isBottom()) { y += Math.floorDiv(h, 2); - bail = placer.isCarved(x, y, z) || placer.isCarved(x, y-1, z)|| placer.isCarved(x, y-2, z)|| placer.isCarved(x, y-3, z); + bail = placer.isCarved(x, y, z) || placer.isCarved(x, y - 1, z) || placer.isCarved(x, y - 2, z) || placer.isCarved(x, y - 3, z); } if (bail) { @@ -991,25 +1020,6 @@ public class IrisObject extends IrisRegistrant { return r; } - private static List blocksBetweenTwoPoints(Vector loc1, Vector loc2) { - List locations = new ArrayList<>(); - int topBlockX = Math.max(loc1.getBlockX(), loc2.getBlockX()); - int bottomBlockX = Math.min(loc1.getBlockX(), loc2.getBlockX()); - int topBlockY = Math.max(loc1.getBlockY(), loc2.getBlockY()); - int bottomBlockY = Math.min(loc1.getBlockY(), loc2.getBlockY()); - int topBlockZ = Math.max(loc1.getBlockZ(), loc2.getBlockZ()); - int bottomBlockZ = Math.min(loc1.getBlockZ(), loc2.getBlockZ()); - - for (int x = bottomBlockX; x <= topBlockX; x++) { - for (int z = bottomBlockZ; z <= topBlockZ; z++) { - for (int y = bottomBlockY; y <= topBlockY; y++) { - locations.add(new BlockVector(x, y, z)); - } - } - } - return locations; - } - public int volume() { return blocks.size(); } diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObjectLoot.java b/src/main/java/com/volmit/iris/engine/object/IrisObjectLoot.java index 5c57f1685..d67f603b7 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObjectLoot.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObjectLoot.java @@ -20,7 +20,11 @@ package com.volmit.iris.engine.object; import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import lombok.AllArgsConstructor; import lombok.Data; @@ -35,23 +39,19 @@ import org.bukkit.block.data.BlockData; @Desc("Represents loot within this object or jigsaw piece") @Data public class IrisObjectLoot { + private final transient AtomicCache> filterCache = new AtomicCache<>(); @ArrayType(min = 1, type = IrisBlockData.class) @Desc("The list of blocks this loot table should apply to") private KList filter = new KList<>(); - @Desc("Exactly match the block data or not") private boolean exact = false; - @Desc("The loot table name") @Required @RegistryListResource(IrisLootTable.class) private String name; - @Desc("The weight of this loot table being chosen") private int weight = 1; - private final transient AtomicCache> filterCache = new AtomicCache<>(); - public KList getFilter(IrisData rdata) { return filterCache.aquire(() -> { diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java b/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java index c200f6cb4..87b96369a 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java @@ -21,7 +21,13 @@ package com.volmit.iris.engine.object; import com.volmit.iris.Iris; import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.data.B; @@ -47,114 +53,88 @@ import org.bukkit.block.data.BlockData; @Desc("Represents an iris object placer. It places objects.") @Data public class IrisObjectPlacement { + private final transient AtomicCache surfaceWarp = new AtomicCache<>(); @RegistryListResource(IrisObject.class) @Required @ArrayType(min = 1, type = String.class) @Desc("List of objects to place") private KList place = new KList<>(); - @Desc("Rotate this objects placement") private IrisObjectRotation rotation = new IrisObjectRotation(); - @Desc("Limit the max height or min height of placement.") private IrisObjectLimit clamp = new IrisObjectLimit(); - @ArrayType(min = 1, type = IrisFeaturePotential.class) @Desc("Place additional noise features in the object's place location") private KList addFeatures = new KList<>(); - @MinNumber(0) @MaxNumber(1) @Desc("The maximum layer level of a snow filter overtop of this placement. Set to 0 to disable. Max of 1.") private double snow = 0; - @MinNumber(0) @MaxNumber(1) @Desc("The chance for this to place in a chunk. If you need multiple per chunk, set this to 1 and use density.") private double chance = 1; - @MinNumber(1) @Desc("If the chance check passes, place this many in a single chunk") private int density = 1; - @MaxNumber(64) @MinNumber(0) @Desc("If the place mode is set to stilt, you can over-stilt it even further into the ground. Especially useful when using fast stilt due to inaccuracies.") private int overStilt = 0; - @MaxNumber(64) @MinNumber(0) @Desc("When bore is enabled, expand max-y of the cuboid it removes") private int boreExtendMaxY = 0; - @MaxNumber(64) @MinNumber(-1) @Desc("When bore is enabled, lower min-y of the cuboid it removes") private int boreExtendMinY = 0; - @MaxNumber(64) @MinNumber(4) @Desc("When vacuum is enabled, define the interpolation radius") private int vacuumInterpolationRadius = 16; - @MaxNumber(64) @MinNumber(4) @Desc("When vacuum is enabled, define the interpolation method") private InterpolationMethod vacuumInterpolationMethod = InterpolationMethod.BILINEAR_STARCAST_9; - @Desc("If set to true, objects will place on the terrain height, ignoring the water surface.") private boolean underwater = false; - @Desc("If set to true, objects will place in carvings (such as underground) or under an overhang.") private CarvingMode carvingSupport = CarvingMode.SURFACE_ONLY; - @Desc("If this is defined, this object wont place on the terrain heightmap, but instead on this virtual heightmap") private IrisNoiseGenerator heightmap; - @Desc("If set to true, Iris will try to fill the insides of 'rooms' and 'pockets' where air should fit based off of raytrace checks. This prevents a village house placing in an area where a tree already exists, and instead replaces the parts of the tree where the interior of the structure is. \n\nThis operation does not affect warmed-up generation speed however it does slow down loading objects.") private boolean smartBore = false; - @Desc("If set to true, Blocks placed underwater that could be waterlogged are waterlogged.") private boolean waterloggable = false; - @Desc("If set to true, objects will place on the fluid height level Such as boats.") private boolean onwater = false; - @Desc("If set to true, this object will only place parts of itself where blocks already exist. Warning: Melding is very performance intensive!") private boolean meld = false; - @Desc("If set to true, this object will place from the ground up instead of height checks when not y locked to the surface. This is not compatable with X and Z axis rotations (it may look off)") private boolean bottom = false; - @Desc("If set to true, air will be placed before the schematic places.") private boolean bore = false; - @Desc("Use a generator to warp the field of coordinates. Using simplex for example would make a square placement warp like a flag") private IrisGeneratorStyle warp = new IrisGeneratorStyle(NoiseStyle.FLAT); - @Desc("If the place mode is set to CENTER_HEIGHT_RIGID and you have an X/Z translation, Turning on translate center will also translate the center height check.") private boolean translateCenter = false; - @Desc("The placement mode") private ObjectPlaceMode mode = ObjectPlaceMode.CENTER_HEIGHT; - @ArrayType(min = 1, type = IrisObjectReplace.class) @Desc("Find and replace blocks") private KList edit = new KList<>(); - @Desc("Translate this object's placement") private IrisObjectTranslate translate = new IrisObjectTranslate(); - @Desc("Scale Objects") private IrisObjectScale scale = new IrisObjectScale(); - @ArrayType(min = 1, type = IrisObjectLoot.class) @Desc("The loot tables to apply to these objects") private KList loot = new KList<>(); - @Desc("This object / these objects override the following trees when they grow...") @ArrayType(min = 1, type = IrisTree.class) private KList trees = new KList<>(); + private transient AtomicCache cache = new AtomicCache<>(); public IrisObjectPlacement toPlacement(String... place) { IrisObjectPlacement p = new IrisObjectPlacement(); @@ -184,8 +164,6 @@ public class IrisObjectPlacement { return p; } - private final transient AtomicCache surfaceWarp = new AtomicCache<>(); - public CNG getSurfaceWarp(RNG rng, IrisData data) { return surfaceWarp.aquire(() -> getWarp().create(rng, data)); @@ -223,8 +201,6 @@ public class IrisObjectPlacement { return isVacuum() || getAddFeatures().isNotEmpty(); } - private transient AtomicCache cache = new AtomicCache<>(); - public boolean matches(IrisTreeSize size, TreeType type) { for (IrisTree i : getTrees()) { if (i.matches(size, type)) { @@ -235,12 +211,6 @@ public class IrisObjectPlacement { return false; } - private static class TableCache { - final transient WeightedRandom global = new WeightedRandom<>(); - final transient KMap> basic = new KMap<>(); - final transient KMap>> exact = new KMap<>(); - } - private TableCache getCache(IrisData manager) { return cache.aquire(() -> { TableCache tc = new TableCache(); @@ -308,4 +278,10 @@ public class IrisObjectPlacement { return null; } + + private static class TableCache { + final transient WeightedRandom global = new WeightedRandom<>(); + final transient KMap> basic = new KMap<>(); + final transient KMap>> exact = new KMap<>(); + } } diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObjectReplace.java b/src/main/java/com/volmit/iris/engine/object/IrisObjectReplace.java index acfc66da7..10bd495de 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObjectReplace.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObjectReplace.java @@ -20,7 +20,12 @@ package com.volmit.iris.engine.object; import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.noise.CNG; @@ -37,27 +42,23 @@ import org.bukkit.block.data.BlockData; @Desc("Find and replace object materials") @Data public class IrisObjectReplace { + private final transient AtomicCache replaceGen = new AtomicCache<>(); + private final transient AtomicCache> findData = new AtomicCache<>(); + private final transient AtomicCache> replaceData = new AtomicCache<>(); @ArrayType(min = 1, type = IrisBlockData.class) @Required @Desc("Find this block") private KList find = new KList<>(); - @Required @Desc("Replace it with this block palette") private IrisMaterialPalette replace = new IrisMaterialPalette(); - @Desc("Exactly match the block data or not") private boolean exact = false; - @MinNumber(0) @MaxNumber(1) @Desc("Modifies the chance the block is replaced") private float chance = 1; - private final transient AtomicCache replaceGen = new AtomicCache<>(); - private final transient AtomicCache> findData = new AtomicCache<>(); - private final transient AtomicCache> replaceData = new AtomicCache<>(); - public KList getFind(IrisData rdata) { return findData.aquire(() -> { diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObjectRotation.java b/src/main/java/com/volmit/iris/engine/object/IrisObjectRotation.java index fe540763e..f9742ff64 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObjectRotation.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObjectRotation.java @@ -29,7 +29,11 @@ import lombok.experimental.Accessors; import org.bukkit.Axis; import org.bukkit.Material; import org.bukkit.block.BlockFace; -import org.bukkit.block.data.*; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Directional; +import org.bukkit.block.data.MultipleFacing; +import org.bukkit.block.data.Orientable; +import org.bukkit.block.data.Rotatable; import org.bukkit.util.BlockVector; import java.util.List; @@ -53,6 +57,28 @@ public class IrisObjectRotation { @Desc("The z axis rotation") private IrisAxisRotationClamp zAxis = new IrisAxisRotationClamp(); + public static IrisObjectRotation of(double x, double y, double z) { + IrisObjectRotation rt = new IrisObjectRotation(); + IrisAxisRotationClamp rtx = new IrisAxisRotationClamp(); + IrisAxisRotationClamp rty = new IrisAxisRotationClamp(); + IrisAxisRotationClamp rtz = new IrisAxisRotationClamp(); + rt.setEnabled(x != 0 || y != 0 || z != 0); + rt.setXAxis(rtx); + rt.setYAxis(rty); + rt.setZAxis(rtz); + rtx.setEnabled(x != 0); + rty.setEnabled(y != 0); + rtz.setEnabled(z != 0); + rtx.setInterval(90); + rty.setInterval(90); + rtz.setInterval(90); + rtx.minMax(x); + rty.minMax(y); + rtz.minMax(z); + + return rt; + } + public double getYRotation(int spin) { return getRotation(spin, yAxis); } @@ -83,7 +109,6 @@ public class IrisObjectRotation { return piece; } - public BlockVector rotate(BlockVector direction) { return rotate(direction, 0, 0, 0); } @@ -93,28 +118,6 @@ public class IrisObjectRotation { return IrisDirection.closest(v); } - public static IrisObjectRotation of(double x, double y, double z) { - IrisObjectRotation rt = new IrisObjectRotation(); - IrisAxisRotationClamp rtx = new IrisAxisRotationClamp(); - IrisAxisRotationClamp rty = new IrisAxisRotationClamp(); - IrisAxisRotationClamp rtz = new IrisAxisRotationClamp(); - rt.setEnabled(x != 0 || y != 0 || z != 0); - rt.setXAxis(rtx); - rt.setYAxis(rty); - rt.setZAxis(rtz); - rtx.setEnabled(x != 0); - rty.setEnabled(y != 0); - rtz.setEnabled(z != 0); - rtx.setInterval(90); - rty.setInterval(90); - rtz.setInterval(90); - rtx.minMax(x); - rty.minMax(y); - rtz.minMax(z); - - return rt; - } - public double getRotation(int spin, IrisAxisRotationClamp clamp) { if (!enabled) { return 0; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObjectScale.java b/src/main/java/com/volmit/iris/engine/object/IrisObjectScale.java index a74779e84..d99bb836e 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObjectScale.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObjectScale.java @@ -37,30 +37,26 @@ import lombok.experimental.Accessors; @Desc("Scale objects") @Data public class IrisObjectScale { - @MinNumber(1) - @MaxNumber(32) - @Desc("Iris Objects are scaled and cached to speed up placements. Because of this extra memory is used, so we evenly distribute variations across the defined scale range, then pick one randomly. If the differences is small, use a lower number. For more possibilities on the scale spectrum, increase this at the cost of memory.") - private int variations = 7; - - @MinNumber(0.01) - @MaxNumber(50) - @Desc("The minimum scale") - private double minimumScale = 1; - - @MinNumber(0.01) - @MaxNumber(50) - @Desc("The maximum height for placement (top of object)") - private double maximumScale = 1; - - @Desc("If this object is scaled up beyond its origin size, specify a 3D interpolator") - private IrisObjectPlacementScaleInterpolator interpolation = IrisObjectPlacementScaleInterpolator.NONE; - private static transient ConcurrentLinkedHashMap> cache = new ConcurrentLinkedHashMap.Builder>() .initialCapacity(64) .maximumWeightedCapacity(1024) .concurrencyLevel(32) .build(); + @MinNumber(1) + @MaxNumber(32) + @Desc("Iris Objects are scaled and cached to speed up placements. Because of this extra memory is used, so we evenly distribute variations across the defined scale range, then pick one randomly. If the differences is small, use a lower number. For more possibilities on the scale spectrum, increase this at the cost of memory.") + private int variations = 7; + @MinNumber(0.01) + @MaxNumber(50) + @Desc("The minimum scale") + private double minimumScale = 1; + @MinNumber(0.01) + @MaxNumber(50) + @Desc("The maximum height for placement (top of object)") + private double maximumScale = 1; + @Desc("If this object is scaled up beyond its origin size, specify a 3D interpolator") + private IrisObjectPlacementScaleInterpolator interpolation = IrisObjectPlacementScaleInterpolator.NONE; public boolean shouldScale() { return ((minimumScale == maximumScale) && maximumScale == 1) || variations <= 0; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObjectTranslate.java b/src/main/java/com/volmit/iris/engine/object/IrisObjectTranslate.java index ccd91a93e..f5f0f1f27 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObjectTranslate.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObjectTranslate.java @@ -18,7 +18,11 @@ package com.volmit.iris.engine.object; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisPotionEffect.java b/src/main/java/com/volmit/iris/engine/object/IrisPotionEffect.java index d02fd8b0e..f58902864 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisPotionEffect.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisPotionEffect.java @@ -20,7 +20,11 @@ package com.volmit.iris.engine.object; import com.volmit.iris.Iris; import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -37,29 +41,24 @@ import org.bukkit.potion.PotionEffectType; @Desc("An iris potion effect") @Data public class IrisPotionEffect { + private final transient AtomicCache pt = new AtomicCache<>(); @Required @Desc("The potion effect to apply in this area") private String potionEffect = ""; - @Required @MinNumber(-1) @MaxNumber(1024) @Desc("The Potion Strength or -1 to disable") private int strength = -1; - @Required @MinNumber(1) @Desc("The time the potion will last for") private int ticks = 200; - @Desc("Is the effect ambient") private boolean ambient = false; - @Desc("Is the effect showing particles") private boolean particles = true; - private final transient AtomicCache pt = new AtomicCache<>(); - public PotionEffectType getRealType() { return pt.aquire(() -> { diff --git a/src/main/java/com/volmit/iris/engine/object/IrisPyramid.java b/src/main/java/com/volmit/iris/engine/object/IrisPyramid.java index 8e6d23db9..4d47602b1 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisPyramid.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisPyramid.java @@ -21,7 +21,11 @@ package com.volmit.iris.engine.object; import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.mantle.MantleWriter; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.matter.MatterCavern; import com.volmit.iris.util.matter.slices.CavernMatter; @@ -31,20 +35,17 @@ import lombok.Data; @Desc("Represents an procedural eliptical shape") @Data public class IrisPyramid implements IRare { + private transient final AtomicCache matterNodeCache = new AtomicCache<>(); @Required @Desc("Typically a 1 in RARITY on a per fork basis") @MinNumber(1) private int rarity = 1; - @RegistryListResource(IrisBiome.class) @Desc("Force this cave to only generate the specified custom biome") private String customBiome = ""; - @Desc("The styled random radius for x") private IrisStyledRange baseWidth = new IrisStyledRange(1, 5, new IrisGeneratorStyle(NoiseStyle.STATIC)); - private transient final AtomicCache matterNodeCache = new AtomicCache<>(); - public void generate(RNG rng, Engine engine, MantleWriter writer, int x, int y, int z) { writer.setPyramid(x, y, z, matterNodeCache.aquire(() -> CavernMatter.get(getCustomBiome(), 0)), (int) baseWidth.get(rng, z, y, engine.getData()), true); diff --git a/src/main/java/com/volmit/iris/engine/object/IrisRareObject.java b/src/main/java/com/volmit/iris/engine/object/IrisRareObject.java index d05b9f060..a964598f4 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisRareObject.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisRareObject.java @@ -18,7 +18,11 @@ package com.volmit.iris.engine.object; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisRavinePlacer.java b/src/main/java/com/volmit/iris/engine/object/IrisRavinePlacer.java index b033df686..bff31b3c2 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisRavinePlacer.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisRavinePlacer.java @@ -23,7 +23,11 @@ import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.mantle.MantleWriter; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.math.RNG; import lombok.AllArgsConstructor; import lombok.Data; @@ -39,20 +43,18 @@ import java.util.concurrent.atomic.AtomicBoolean; @Desc("Translate objects") @Data public class IrisRavinePlacer implements IRare { + private transient final AtomicCache ravineCache = new AtomicCache<>(); + private transient final AtomicBoolean fail = new AtomicBoolean(false); @Required @Desc("Typically a 1 in RARITY on a per chunk/fork basis") @MinNumber(1) private int rarity = 15; - @MinNumber(1) @Required @Desc("The ravine to place") @RegistryListResource(IrisRavine.class) private String ravine; - private transient final AtomicCache ravineCache = new AtomicCache<>(); - private transient final AtomicBoolean fail = new AtomicBoolean(false); - public IrisRavine getRealRavine(IrisData data) { return ravineCache.aquire(() -> data.getRavineLoader().load(getRavine())); } diff --git a/src/main/java/com/volmit/iris/engine/object/IrisRegion.java b/src/main/java/com/volmit/iris/engine/object/IrisRegion.java index 338ee67fb..c73b06167 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisRegion.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisRegion.java @@ -23,7 +23,12 @@ import com.volmit.iris.core.gui.components.RenderType; import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.core.loader.IrisRegistrant; import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.collection.KSet; @@ -40,7 +45,7 @@ import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.experimental.Accessors; -import java.awt.*; +import java.awt.Color; import java.util.Random; @@ -52,146 +57,6 @@ import java.util.Random; @Data @EqualsAndHashCode(callSuper = false) public class IrisRegion extends IrisRegistrant implements IRare { - @MinNumber(2) - @Required - @Desc("The name of the region") - private String name = "A Region"; - - @ArrayType(min = 1, type = IrisJigsawStructurePlacement.class) - @Desc("Jigsaw structures") - private KList jigsawStructures = new KList<>(); - - @Desc("Add random chances for terrain features") - @ArrayType(min = 1, type = IrisFeaturePotential.class) - private KList features = new KList<>(); - - @ArrayType(min = 1, type = IrisEffect.class) - @Desc("Effects are ambient effects such as potion effects, random sounds, or even particles around each player. All of these effects are played via packets so two players won't see/hear each others effects.\nDue to performance reasons, effects will play arround the player even if where the effect was played is no longer in the biome the player is in.") - private KList effects = new KList<>(); - - @Desc("Spawn Entities in this region over time. Iris will continually replenish these mobs just like vanilla does.") - @ArrayType(min = 1, type = String.class) - @RegistryListResource(IrisSpawner.class) - private KList entitySpawners = new KList<>(); - - @MinNumber(1) - @MaxNumber(128) - @Desc("The rarity of the region") - private int rarity = 1; - - @ArrayType(min = 1, type = IrisBlockDrops.class) - @Desc("Define custom block drops for this region") - private KList blockDrops = new KList<>(); - - @MinNumber(0.0001) - @MaxNumber(1) - @Desc("The shore ration (How much percent of land should be a shore)") - private double shoreRatio = 0.13; - - @ArrayType(min = 1, type = IrisObjectPlacement.class) - @Desc("Objects define what schematics (iob files) iris will place in this region") - private KList objects = new KList<>(); - - @MinNumber(0) - @Desc("The min shore height") - private double shoreHeightMin = 1.2; - - @Desc("Reference loot tables in this area") - private IrisLootReference loot = new IrisLootReference(); - - @MinNumber(0) - @Desc("The the max shore height") - private double shoreHeightMax = 3.2; - - @MinNumber(0.0001) - @Desc("The varience of the shore height") - private double shoreHeightZoom = 3.14; - - @MinNumber(0.0001) - @Desc("How large land biomes are in this region") - private double landBiomeZoom = 1; - - @MinNumber(0.0001) - @Desc("How large shore biomes are in this region") - private double shoreBiomeZoom = 1; - - @MinNumber(0.0001) - @Desc("How large sea biomes are in this region") - private double seaBiomeZoom = 1; - - @MinNumber(0.0001) - @Desc("How large cave biomes are in this region") - private double caveBiomeZoom = 1; - - @MinNumber(0.0001) - @MaxNumber(1) - @Desc("The biome implosion ratio, how much to implode biomes into children (chance)") - private double biomeImplosionRatio = 0.4; - - @Desc("Carving configuration for the dimension") - private IrisCarving carving = new IrisCarving(); - - @Desc("Configuration of fluid bodies such as rivers & lakes") - private IrisFluidBodies fluidBodies = new IrisFluidBodies(); - - @RegistryListResource(IrisBiome.class) - @Required - @ArrayType(min = 1, type = String.class) - @Desc("A list of root-level biomes in this region. Don't specify child biomes of other biomes here. Just the root parents.") - private KList landBiomes = new KList<>(); - - @RegistryListResource(IrisBiome.class) - @Required - @ArrayType(min = 1, type = String.class) - @Desc("A list of root-level biomes in this region. Don't specify child biomes of other biomes here. Just the root parents.") - private KList seaBiomes = new KList<>(); - - @RegistryListResource(IrisBiome.class) - @Required - @ArrayType(min = 1, type = String.class) - @Desc("A list of root-level biomes in this region. Don't specify child biomes of other biomes here. Just the root parents.") - private KList shoreBiomes = new KList<>(); - - @RegistryListResource(IrisBiome.class) - @ArrayType(min = 1, type = String.class) - @Desc("A list of root-level biomes in this region. Don't specify child biomes of other biomes here. Just the root parents.") - private KList caveBiomes = new KList<>(); - - @ArrayType(min = 1, type = IrisDepositGenerator.class) - @Desc("Define regional deposit generators that add onto the global deposit generators") - private KList deposits = new KList<>(); - - @Desc("The style of rivers") - private IrisGeneratorStyle riverStyle = NoiseStyle.VASCULAR_THIN.style().zoomed(7.77); - - @Desc("The style of lakes") - private IrisGeneratorStyle lakeStyle = NoiseStyle.CELLULAR_IRIS_THICK.style(); - - @Desc("The style of river chances") - private IrisGeneratorStyle riverChanceStyle = NoiseStyle.SIMPLEX.style().zoomed(4); - - @Desc("Generate lakes in this region") - private boolean lakes = true; - - @Desc("Generate rivers in this region") - private boolean rivers = true; - - @MinNumber(1) - @Desc("Generate lakes in this region") - private int lakeRarity = 22; - - @MinNumber(1) - @Desc("Generate rivers in this region") - private int riverRarity = 3; - - @MinNumber(0) - @MaxNumber(1) - @Desc("Generate rivers in this region") - private double riverThickness = 0.1; - - @Desc("A color for visualizing this region with a color. I.e. #F13AF5. This will show up on the map.") - private String color = null; - private final transient AtomicCache> surfaceObjectsCache = new AtomicCache<>(); private final transient AtomicCache> carveObjectsCache = new AtomicCache<>(); private final transient AtomicCache> cacheRidge = new AtomicCache<>(); @@ -207,6 +72,112 @@ public class IrisRegion extends IrisRegistrant implements IRare { private final transient AtomicCache riverGen = new AtomicCache<>(); private final transient AtomicCache riverChanceGen = new AtomicCache<>(); private final transient AtomicCache cacheColor = new AtomicCache<>(); + @MinNumber(2) + @Required + @Desc("The name of the region") + private String name = "A Region"; + @ArrayType(min = 1, type = IrisJigsawStructurePlacement.class) + @Desc("Jigsaw structures") + private KList jigsawStructures = new KList<>(); + @Desc("Add random chances for terrain features") + @ArrayType(min = 1, type = IrisFeaturePotential.class) + private KList features = new KList<>(); + @ArrayType(min = 1, type = IrisEffect.class) + @Desc("Effects are ambient effects such as potion effects, random sounds, or even particles around each player. All of these effects are played via packets so two players won't see/hear each others effects.\nDue to performance reasons, effects will play arround the player even if where the effect was played is no longer in the biome the player is in.") + private KList effects = new KList<>(); + @Desc("Spawn Entities in this region over time. Iris will continually replenish these mobs just like vanilla does.") + @ArrayType(min = 1, type = String.class) + @RegistryListResource(IrisSpawner.class) + private KList entitySpawners = new KList<>(); + @MinNumber(1) + @MaxNumber(128) + @Desc("The rarity of the region") + private int rarity = 1; + @ArrayType(min = 1, type = IrisBlockDrops.class) + @Desc("Define custom block drops for this region") + private KList blockDrops = new KList<>(); + @MinNumber(0.0001) + @MaxNumber(1) + @Desc("The shore ration (How much percent of land should be a shore)") + private double shoreRatio = 0.13; + @ArrayType(min = 1, type = IrisObjectPlacement.class) + @Desc("Objects define what schematics (iob files) iris will place in this region") + private KList objects = new KList<>(); + @MinNumber(0) + @Desc("The min shore height") + private double shoreHeightMin = 1.2; + @Desc("Reference loot tables in this area") + private IrisLootReference loot = new IrisLootReference(); + @MinNumber(0) + @Desc("The the max shore height") + private double shoreHeightMax = 3.2; + @MinNumber(0.0001) + @Desc("The varience of the shore height") + private double shoreHeightZoom = 3.14; + @MinNumber(0.0001) + @Desc("How large land biomes are in this region") + private double landBiomeZoom = 1; + @MinNumber(0.0001) + @Desc("How large shore biomes are in this region") + private double shoreBiomeZoom = 1; + @MinNumber(0.0001) + @Desc("How large sea biomes are in this region") + private double seaBiomeZoom = 1; + @MinNumber(0.0001) + @Desc("How large cave biomes are in this region") + private double caveBiomeZoom = 1; + @MinNumber(0.0001) + @MaxNumber(1) + @Desc("The biome implosion ratio, how much to implode biomes into children (chance)") + private double biomeImplosionRatio = 0.4; + @Desc("Carving configuration for the dimension") + private IrisCarving carving = new IrisCarving(); + @Desc("Configuration of fluid bodies such as rivers & lakes") + private IrisFluidBodies fluidBodies = new IrisFluidBodies(); + @RegistryListResource(IrisBiome.class) + @Required + @ArrayType(min = 1, type = String.class) + @Desc("A list of root-level biomes in this region. Don't specify child biomes of other biomes here. Just the root parents.") + private KList landBiomes = new KList<>(); + @RegistryListResource(IrisBiome.class) + @Required + @ArrayType(min = 1, type = String.class) + @Desc("A list of root-level biomes in this region. Don't specify child biomes of other biomes here. Just the root parents.") + private KList seaBiomes = new KList<>(); + @RegistryListResource(IrisBiome.class) + @Required + @ArrayType(min = 1, type = String.class) + @Desc("A list of root-level biomes in this region. Don't specify child biomes of other biomes here. Just the root parents.") + private KList shoreBiomes = new KList<>(); + @RegistryListResource(IrisBiome.class) + @ArrayType(min = 1, type = String.class) + @Desc("A list of root-level biomes in this region. Don't specify child biomes of other biomes here. Just the root parents.") + private KList caveBiomes = new KList<>(); + @ArrayType(min = 1, type = IrisDepositGenerator.class) + @Desc("Define regional deposit generators that add onto the global deposit generators") + private KList deposits = new KList<>(); + @Desc("The style of rivers") + private IrisGeneratorStyle riverStyle = NoiseStyle.VASCULAR_THIN.style().zoomed(7.77); + @Desc("The style of lakes") + private IrisGeneratorStyle lakeStyle = NoiseStyle.CELLULAR_IRIS_THICK.style(); + @Desc("The style of river chances") + private IrisGeneratorStyle riverChanceStyle = NoiseStyle.SIMPLEX.style().zoomed(4); + @Desc("Generate lakes in this region") + private boolean lakes = true; + @Desc("Generate rivers in this region") + private boolean rivers = true; + @MinNumber(1) + @Desc("Generate lakes in this region") + private int lakeRarity = 22; + @MinNumber(1) + @Desc("Generate rivers in this region") + private int riverRarity = 3; + @MinNumber(0) + @MaxNumber(1) + @Desc("Generate rivers in this region") + private double riverThickness = 0.1; + @Desc("A color for visualizing this region with a color. I.e. #F13AF5. This will show up on the map.") + private String color = null; public String getName() { return name; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisRiver.java b/src/main/java/com/volmit/iris/engine/object/IrisRiver.java index 454ba65a6..35a2b2216 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisRiver.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisRiver.java @@ -21,7 +21,11 @@ package com.volmit.iris.engine.object; import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.mantle.MantleWriter; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.matter.MatterFluidBody; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisShapedGeneratorStyle.java b/src/main/java/com/volmit/iris/engine/object/IrisShapedGeneratorStyle.java index ad4deb88d..e87038fb4 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisShapedGeneratorStyle.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisShapedGeneratorStyle.java @@ -19,7 +19,11 @@ package com.volmit.iris.engine.object; import com.volmit.iris.core.loader.IrisData; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.math.RNG; import lombok.AllArgsConstructor; import lombok.Data; @@ -49,10 +53,6 @@ public class IrisShapedGeneratorStyle { @Desc("The max block value") private int max = 0; - public double get(RNG rng, IrisData data, double... dim) { - return generator.create(rng, data).fitDouble(min, max, dim); - } - public IrisShapedGeneratorStyle(NoiseStyle style, int min, int max) { this(style); this.min = min; @@ -63,6 +63,10 @@ public class IrisShapedGeneratorStyle { this.generator = new IrisGeneratorStyle(style); } + public double get(RNG rng, IrisData data, double... dim) { + return generator.create(rng, data).fitDouble(min, max, dim); + } + public boolean isFlat() { return min == max || getGenerator().isFlat(); } diff --git a/src/main/java/com/volmit/iris/engine/object/IrisSphere.java b/src/main/java/com/volmit/iris/engine/object/IrisSphere.java index 8bc0ac611..4720508e7 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisSphere.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisSphere.java @@ -21,7 +21,11 @@ package com.volmit.iris.engine.object; import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.mantle.MantleWriter; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.matter.MatterCavern; import com.volmit.iris.util.matter.slices.CavernMatter; @@ -31,20 +35,17 @@ import lombok.Data; @Desc("Represents an procedural eliptical shape") @Data public class IrisSphere implements IRare { + private transient final AtomicCache matterNodeCache = new AtomicCache<>(); @Required @Desc("Typically a 1 in RARITY on a per fork basis") @MinNumber(1) private int rarity = 1; - @RegistryListResource(IrisBiome.class) @Desc("Force this cave to only generate the specified custom biome") private String customBiome = ""; - @Desc("The styled random radius for x") private IrisStyledRange radius = new IrisStyledRange(1, 5, new IrisGeneratorStyle(NoiseStyle.STATIC)); - private transient final AtomicCache matterNodeCache = new AtomicCache<>(); - public void generate(RNG rng, Engine engine, MantleWriter writer, int x, int y, int z) { writer.setSphere(x, y, z, radius.get(rng, z, y, engine.getData()), true, matterNodeCache.aquire(() -> CavernMatter.get(getCustomBiome(), 0))); } diff --git a/src/main/java/com/volmit/iris/engine/object/IrisVillagerOverride.java b/src/main/java/com/volmit/iris/engine/object/IrisVillagerOverride.java index 19eebdd93..bc1776d78 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisVillagerOverride.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisVillagerOverride.java @@ -18,7 +18,11 @@ package com.volmit.iris.engine.object; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.ArrayType; +import com.volmit.iris.engine.object.annotations.DependsOn; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisVillagerTrade.java b/src/main/java/com/volmit/iris/engine/object/IrisVillagerTrade.java index db2c984f9..25919b58c 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisVillagerTrade.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisVillagerTrade.java @@ -20,7 +20,12 @@ package com.volmit.iris.engine.object; import com.volmit.iris.Iris; -import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.MaxNumber; +import com.volmit.iris.engine.object.annotations.MinNumber; +import com.volmit.iris.engine.object.annotations.RegistryListItemType; +import com.volmit.iris.engine.object.annotations.Required; +import com.volmit.iris.engine.object.annotations.Snippet; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.math.RNG; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/volmit/iris/engine/object/IrisWorld.java b/src/main/java/com/volmit/iris/engine/object/IrisWorld.java index bb5e16876..cdd296bfb 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisWorld.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisWorld.java @@ -21,7 +21,11 @@ package com.volmit.iris.engine.object; import com.volmit.iris.Iris; import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.util.collection.KList; -import lombok.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Data; +import lombok.Getter; +import lombok.Setter; import lombok.experimental.Accessors; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -63,13 +67,11 @@ public class IrisWorld { .environment(world.getEnvironment()); } - public long getRawWorldSeed() - { + public long getRawWorldSeed() { return seed; } - public void setRawWorldSeed(long seed) - { + public void setRawWorldSeed(long seed) { this.seed = seed; } diff --git a/src/main/java/com/volmit/iris/engine/object/annotations/ArrayType.java b/src/main/java/com/volmit/iris/engine/object/annotations/ArrayType.java index 6c13cf148..99f19e638 100644 --- a/src/main/java/com/volmit/iris/engine/object/annotations/ArrayType.java +++ b/src/main/java/com/volmit/iris/engine/object/annotations/ArrayType.java @@ -22,7 +22,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.RetentionPolicy.*; @Retention(RUNTIME) @Target({PARAMETER, TYPE, FIELD}) diff --git a/src/main/java/com/volmit/iris/engine/object/annotations/DependsOn.java b/src/main/java/com/volmit/iris/engine/object/annotations/DependsOn.java index 4b41ec05a..3484600da 100644 --- a/src/main/java/com/volmit/iris/engine/object/annotations/DependsOn.java +++ b/src/main/java/com/volmit/iris/engine/object/annotations/DependsOn.java @@ -21,8 +21,8 @@ package com.volmit.iris.engine.object.annotations; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; @Retention(RUNTIME) @Target({FIELD}) diff --git a/src/main/java/com/volmit/iris/engine/object/annotations/Desc.java b/src/main/java/com/volmit/iris/engine/object/annotations/Desc.java index 58cb8bf9f..d901b3c8f 100644 --- a/src/main/java/com/volmit/iris/engine/object/annotations/Desc.java +++ b/src/main/java/com/volmit/iris/engine/object/annotations/Desc.java @@ -22,7 +22,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.RetentionPolicy.*; @Retention(RUNTIME) @Target({PARAMETER, TYPE, FIELD}) diff --git a/src/main/java/com/volmit/iris/engine/object/annotations/MaxNumber.java b/src/main/java/com/volmit/iris/engine/object/annotations/MaxNumber.java index 891f5e0fc..26fe46860 100644 --- a/src/main/java/com/volmit/iris/engine/object/annotations/MaxNumber.java +++ b/src/main/java/com/volmit/iris/engine/object/annotations/MaxNumber.java @@ -21,8 +21,8 @@ package com.volmit.iris.engine.object.annotations; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; @Retention(RUNTIME) @Target({FIELD}) diff --git a/src/main/java/com/volmit/iris/engine/object/annotations/MinNumber.java b/src/main/java/com/volmit/iris/engine/object/annotations/MinNumber.java index 371389dd0..8945c13d5 100644 --- a/src/main/java/com/volmit/iris/engine/object/annotations/MinNumber.java +++ b/src/main/java/com/volmit/iris/engine/object/annotations/MinNumber.java @@ -21,8 +21,8 @@ package com.volmit.iris.engine.object.annotations; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; @Retention(RUNTIME) @Target({FIELD}) diff --git a/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListBiomeDownfallType.java b/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListBiomeDownfallType.java index fe33ff346..07cdb27bc 100644 --- a/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListBiomeDownfallType.java +++ b/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListBiomeDownfallType.java @@ -22,7 +22,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.RetentionPolicy.*; @Retention(RUNTIME) @Target({PARAMETER, TYPE, FIELD}) diff --git a/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListBlockType.java b/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListBlockType.java index e61aae5cb..b5efaa00a 100644 --- a/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListBlockType.java +++ b/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListBlockType.java @@ -22,7 +22,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.RetentionPolicy.*; @Retention(RUNTIME) @Target({PARAMETER, TYPE, FIELD}) diff --git a/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListFont.java b/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListFont.java index 5460e5c06..edb936873 100644 --- a/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListFont.java +++ b/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListFont.java @@ -22,7 +22,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.RetentionPolicy.*; @Retention(RUNTIME) @Target({PARAMETER, TYPE, FIELD}) diff --git a/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListItemType.java b/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListItemType.java index 6a1739a23..d40d238b6 100644 --- a/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListItemType.java +++ b/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListItemType.java @@ -22,7 +22,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.RetentionPolicy.*; @Retention(RUNTIME) @Target({PARAMETER, TYPE, FIELD}) diff --git a/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListResource.java b/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListResource.java index 5478658b5..2e543a020 100644 --- a/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListResource.java +++ b/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListResource.java @@ -24,7 +24,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.RetentionPolicy.*; @Retention(RUNTIME) @Target({PARAMETER, TYPE, FIELD}) diff --git a/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListSpecialEntity.java b/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListSpecialEntity.java index 7bcd8c345..c7e75c9a9 100644 --- a/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListSpecialEntity.java +++ b/src/main/java/com/volmit/iris/engine/object/annotations/RegistryListSpecialEntity.java @@ -22,7 +22,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.RetentionPolicy.*; @Retention(RUNTIME) @Target({PARAMETER, TYPE, FIELD}) diff --git a/src/main/java/com/volmit/iris/engine/object/annotations/Required.java b/src/main/java/com/volmit/iris/engine/object/annotations/Required.java index 703d70ce6..6e206d411 100644 --- a/src/main/java/com/volmit/iris/engine/object/annotations/Required.java +++ b/src/main/java/com/volmit/iris/engine/object/annotations/Required.java @@ -22,7 +22,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.RetentionPolicy.*; @Retention(RUNTIME) @Target({PARAMETER, TYPE, FIELD}) diff --git a/src/main/java/com/volmit/iris/engine/object/annotations/Snippet.java b/src/main/java/com/volmit/iris/engine/object/annotations/Snippet.java index bd0afc43c..fcbc41738 100644 --- a/src/main/java/com/volmit/iris/engine/object/annotations/Snippet.java +++ b/src/main/java/com/volmit/iris/engine/object/annotations/Snippet.java @@ -21,8 +21,8 @@ package com.volmit.iris.engine.object.annotations; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; @Retention(RUNTIME) @Target({TYPE}) 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 80b093c51..f7f479841 100644 --- a/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java +++ b/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java @@ -25,7 +25,6 @@ import com.volmit.iris.engine.IrisEngine; import com.volmit.iris.engine.data.chunk.TerrainChunk; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.framework.EngineTarget; -import com.volmit.iris.engine.framework.WrongEngineBroException; import com.volmit.iris.engine.object.IrisDimension; import com.volmit.iris.engine.object.IrisWorld; import com.volmit.iris.engine.object.StudioMode; @@ -67,20 +66,19 @@ import java.util.function.Consumer; public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChunkGenerator { private static final int LOAD_LOCKS = 1_000_000; private final Semaphore loadLock; - private Engine engine; private final IrisWorld world; private final File dataLocation; private final String dimensionKey; private final ReactiveFolder folder; private final KList populators; private final ChronoLatch hotloadChecker; - private Looper hotloader; private final AtomicBoolean setup; + private final boolean studio; + private Engine engine; + private Looper hotloader; private StudioMode lastMode; - @Setter private StudioGenerator studioGenerator; - private final boolean studio; public BukkitChunkGenerator(IrisWorld world, boolean studio, File dataLocation, String dimensionKey) { setup = new AtomicBoolean(false); @@ -197,15 +195,12 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun } } - private Engine getEngine(World world) - { - if(setup.get()) - { + private Engine getEngine(World world) { + if (setup.get()) { return getEngine(); } - synchronized (this) - { + synchronized (this) { getWorld().setRawWorldSeed(world.getSeed()); setupEngine(); this.hotloader = studio ? new Looper() { diff --git a/src/main/java/com/volmit/iris/util/atomics/AtomicAverage.java b/src/main/java/com/volmit/iris/util/atomics/AtomicAverage.java index e5a2572e9..d3198af6d 100644 --- a/src/main/java/com/volmit/iris/util/atomics/AtomicAverage.java +++ b/src/main/java/com/volmit/iris/util/atomics/AtomicAverage.java @@ -31,10 +31,10 @@ import com.volmit.iris.util.data.DoubleArrayUtils; */ public class AtomicAverage { protected final AtomicDoubleArray values; + protected int cursor; private double average; private double lastSum; private boolean dirty; - protected int cursor; private boolean brandNew; /** diff --git a/src/main/java/com/volmit/iris/util/atomics/AtomicRollingSequence.java b/src/main/java/com/volmit/iris/util/atomics/AtomicRollingSequence.java index 790eb94d2..671eb7345 100644 --- a/src/main/java/com/volmit/iris/util/atomics/AtomicRollingSequence.java +++ b/src/main/java/com/volmit/iris/util/atomics/AtomicRollingSequence.java @@ -47,14 +47,14 @@ public class AtomicRollingSequence extends AtomicAverage { return f; } - public void setPrecision(boolean p) { - this.precision = p; - } - public boolean isPrecision() { return precision; } + public void setPrecision(boolean p) { + this.precision = p; + } + public double getMin() { if (dirtyExtremes > (isPrecision() ? 0 : values.length())) { resetExtremes(); diff --git a/src/main/java/com/volmit/iris/util/board/BoardManager.java b/src/main/java/com/volmit/iris/util/board/BoardManager.java index 7f3fbdb29..a5356f0bf 100644 --- a/src/main/java/com/volmit/iris/util/board/BoardManager.java +++ b/src/main/java/com/volmit/iris/util/board/BoardManager.java @@ -33,15 +33,9 @@ import java.util.concurrent.ConcurrentHashMap; public class BoardManager { private final JavaPlugin plugin; - - - private BoardSettings boardSettings; - - private final Map scoreboards; - - private final BukkitTask updateTask; + private BoardSettings boardSettings; public BoardManager(JavaPlugin plugin, BoardSettings boardSettings) { diff --git a/src/main/java/com/volmit/iris/util/collection/KList.java b/src/main/java/com/volmit/iris/util/collection/KList.java index cbf114148..cd3c8fb62 100644 --- a/src/main/java/com/volmit/iris/util/collection/KList.java +++ b/src/main/java/com/volmit/iris/util/collection/KList.java @@ -23,7 +23,13 @@ import com.volmit.iris.util.json.JSONArray; import com.volmit.iris.util.math.M; import com.volmit.iris.util.math.RNG; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Random; import java.util.function.Function; import java.util.function.Predicate; @@ -55,6 +61,26 @@ public class KList extends ArrayList implements List { add(e); } + public static KList fromJSONAny(JSONArray oo) { + KList s = new KList(); + + for (int i = 0; i < oo.length(); i++) { + s.add(oo.get(i).toString()); + } + + return s; + } + + public static KList asStringList(List oo) { + KList s = new KList(); + + for (Object i : oo) { + s.add(i.toString()); + } + + return s; + } + public int indexOfAddIfNeeded(T v) { addIfMissing(v); return indexOf(v); @@ -203,7 +229,6 @@ public class KList extends ArrayList implements List { return this; } - public KList shuffle(Random rng) { Collections.shuffle(this, rng); return this; @@ -484,16 +509,6 @@ public class KList extends ArrayList implements List { return remove(rng.i(0, last())); } - public static KList fromJSONAny(JSONArray oo) { - KList s = new KList(); - - for (int i = 0; i < oo.length(); i++) { - s.add(oo.get(i).toString()); - } - - return s; - } - public KList sub(int f, int t) { KList g = new KList<>(); @@ -514,16 +529,6 @@ public class KList extends ArrayList implements List { return j; } - public static KList asStringList(List oo) { - KList s = new KList(); - - for (Object i : oo) { - s.add(i.toString()); - } - - return s; - } - @SuppressWarnings("unchecked") public KList forceAdd(Object[] values) { for (Object i : values) { diff --git a/src/main/java/com/volmit/iris/util/context/IrisContext.java b/src/main/java/com/volmit/iris/util/context/IrisContext.java index 799530d13..06b072715 100644 --- a/src/main/java/com/volmit/iris/util/context/IrisContext.java +++ b/src/main/java/com/volmit/iris/util/context/IrisContext.java @@ -30,8 +30,8 @@ import lombok.Data; @Data @AllArgsConstructor public class IrisContext { - private static ChronoLatch cl = new ChronoLatch(60000); private static final KMap context = new KMap<>(); + private static ChronoLatch cl = new ChronoLatch(60000); private final Engine engine; public static IrisContext get() { diff --git a/src/main/java/com/volmit/iris/util/data/B.java b/src/main/java/com/volmit/iris/util/data/B.java index 85f05c65c..d34d39258 100644 --- a/src/main/java/com/volmit/iris/util/data/B.java +++ b/src/main/java/com/volmit/iris/util/data/B.java @@ -22,7 +22,11 @@ import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.scheduling.ChronoLatch; -import it.unimi.dsi.fastutil.ints.*; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; +import it.unimi.dsi.fastutil.ints.IntSets; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.data.BlockData; @@ -32,7 +36,6 @@ import org.bukkit.block.data.type.PointedDripstone; import java.util.Arrays; import java.util.HashMap; -import java.util.Locale; import java.util.Map; import java.util.stream.Collectors; @@ -434,45 +437,30 @@ public class B { } if (bx == null) { - try - { + try { bx = Bukkit.createBlockData(ix.toLowerCase()); - } - - catch(Throwable e) - { + } catch (Throwable e) { } } - if(bx == null) - { - try - { + if (bx == null) { + try { bx = Bukkit.createBlockData("minecraft:" + ix.toLowerCase()); - } - - catch(Throwable e) - { + } catch (Throwable e) { } } - if(bx == null) - { - try - { + if (bx == null) { + try { bx = Material.valueOf(ix.toUpperCase()).createBlockData(); - } - - catch(Throwable e) - { + } catch (Throwable e) { } } - if(bx == null) - { + if (bx == null) { return null; } diff --git a/src/main/java/com/volmit/iris/util/data/Cuboid.java b/src/main/java/com/volmit/iris/util/data/Cuboid.java index 06e663db9..41db33c2c 100644 --- a/src/main/java/com/volmit/iris/util/data/Cuboid.java +++ b/src/main/java/com/volmit/iris/util/data/Cuboid.java @@ -20,12 +20,20 @@ package com.volmit.iris.util.data; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.math.Direction; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.Chunk; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.entity.Entity; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; /** * Cuboids @@ -58,35 +66,6 @@ public class Cuboid implements Iterable, Cloneable, ConfigurationSerializ z2 = Math.max(l1.getBlockZ(), l2.getBlockZ()); } - public KList getEntities() { - KList en = new KList<>(); - - for (Chunk i : getChunks()) { - for (Entity j : i.getEntities()) { - if (contains(j.getLocation())) { - en.add(j); - } - } - } - - return en; - } - - /** - * Set the locations - * - * @param l1 a - * @param l2 b - */ - public void set(Location l1, Location l2) { - x1 = Math.min(l1.getBlockX(), l2.getBlockX()); - y1 = Math.min(l1.getBlockY(), l2.getBlockY()); - z1 = Math.min(l1.getBlockZ(), l2.getBlockZ()); - x2 = Math.max(l1.getBlockX(), l2.getBlockX()); - y2 = Math.max(l1.getBlockY(), l2.getBlockY()); - z2 = Math.max(l1.getBlockZ(), l2.getBlockZ()); - } - /** * Construct a one-block Cuboid at the given Location of the Cuboid. * @@ -157,6 +136,35 @@ public class Cuboid implements Iterable, Cloneable, ConfigurationSerializ z2 = (Integer) map.get("z2"); } + public KList getEntities() { + KList en = new KList<>(); + + for (Chunk i : getChunks()) { + for (Entity j : i.getEntities()) { + if (contains(j.getLocation())) { + en.add(j); + } + } + } + + return en; + } + + /** + * Set the locations + * + * @param l1 a + * @param l2 b + */ + public void set(Location l1, Location l2) { + x1 = Math.min(l1.getBlockX(), l2.getBlockX()); + y1 = Math.min(l1.getBlockY(), l2.getBlockY()); + z1 = Math.min(l1.getBlockZ(), l2.getBlockZ()); + x2 = Math.max(l1.getBlockX(), l2.getBlockX()); + y2 = Math.max(l1.getBlockY(), l2.getBlockY()); + z2 = Math.max(l1.getBlockZ(), l2.getBlockZ()); + } + @Override public Map serialize() { Map map = new HashMap<>(); @@ -671,15 +679,44 @@ public class Cuboid implements Iterable, Cloneable, ConfigurationSerializ return "Cuboid: " + worldName + "," + x1 + "," + y1 + "," + z1 + "=>" + x2 + "," + y2 + "," + z2; } + public enum CuboidDirection { + + North, + East, + South, + West, + Up, + Down, + Horizontal, + Vertical, + Both, + Unknown; + + public CuboidDirection opposite() { + return switch (this) { + case North -> South; + case East -> West; + case South -> North; + case West -> East; + case Horizontal -> Vertical; + case Vertical -> Horizontal; + case Up -> Down; + case Down -> Up; + case Both -> Both; + default -> Unknown; + }; + } + } + public static class CuboidIterator implements Iterator { private final World w; private final int baseX; private final int baseY; private final int baseZ; - private int x, y, z; private final int sizeX; private final int sizeY; private final int sizeZ; + private int x, y, z; public CuboidIterator(World w, int x1, int y1, int z1, int x2, int y2, int z2) { this.w = w; @@ -716,33 +753,4 @@ public class Cuboid implements Iterable, Cloneable, ConfigurationSerializ } } - public enum CuboidDirection { - - North, - East, - South, - West, - Up, - Down, - Horizontal, - Vertical, - Both, - Unknown; - - public CuboidDirection opposite() { - return switch (this) { - case North -> South; - case East -> West; - case South -> North; - case West -> East; - case Horizontal -> Vertical; - case Vertical -> Horizontal; - case Up -> Down; - case Down -> Up; - case Both -> Both; - default -> Unknown; - }; - } - } - } \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/data/CuboidException.java b/src/main/java/com/volmit/iris/util/data/CuboidException.java index 82650b943..cacc36d86 100644 --- a/src/main/java/com/volmit/iris/util/data/CuboidException.java +++ b/src/main/java/com/volmit/iris/util/data/CuboidException.java @@ -24,9 +24,9 @@ package com.volmit.iris.util.data; * @author cyberpwn */ public class CuboidException extends Exception { + private static final long serialVersionUID = 1L; + public CuboidException(String string) { super(string); } - - private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/data/DataPalette.java b/src/main/java/com/volmit/iris/util/data/DataPalette.java index 95d9edc11..81687ddf5 100644 --- a/src/main/java/com/volmit/iris/util/data/DataPalette.java +++ b/src/main/java/com/volmit/iris/util/data/DataPalette.java @@ -35,6 +35,17 @@ public class DataPalette { this.palette = palette; } + public static DataPalette getPalette(IOAdapter adapter, DataInputStream din) throws IOException { + KList palette = new KList<>(); + int s = din.readShort() - Short.MIN_VALUE; + + for (int i = 0; i < s; i++) { + palette.add(adapter.read(din)); + } + + return new DataPalette<>(palette); + } + public KList getPalette() { return palette; } @@ -73,15 +84,4 @@ public class DataPalette { } } } - - public static DataPalette getPalette(IOAdapter adapter, DataInputStream din) throws IOException { - KList palette = new KList<>(); - int s = din.readShort() - Short.MIN_VALUE; - - for (int i = 0; i < s; i++) { - palette.add(adapter.read(din)); - } - - return new DataPalette<>(palette); - } } diff --git a/src/main/java/com/volmit/iris/util/data/IrisBiomeStorage.java b/src/main/java/com/volmit/iris/util/data/IrisBiomeStorage.java index 6fc24fa7f..75610422a 100644 --- a/src/main/java/com/volmit/iris/util/data/IrisBiomeStorage.java +++ b/src/main/java/com/volmit/iris/util/data/IrisBiomeStorage.java @@ -24,12 +24,11 @@ import org.bukkit.generator.ChunkGenerator.BiomeGrid; import org.jetbrains.annotations.NotNull; public class IrisBiomeStorage implements BiomeGrid { - private static final int e; - private static final int f; public static final int a; public static final int b; public static final int c; - private final Biome[] g; + private static final int e; + private static final int f; static { e = (int) Math.round(Math.log(16.0) / Math.log(2.0)) - 2; @@ -39,6 +38,8 @@ public class IrisBiomeStorage implements BiomeGrid { c = (1 << IrisBiomeStorage.f) - 1; } + private final Biome[] g; + public IrisBiomeStorage(final Biome[] aBiome) { this.g = aBiome; } diff --git a/src/main/java/com/volmit/iris/util/data/NibbleArray.java b/src/main/java/com/volmit/iris/util/data/NibbleArray.java index 3c549d9a5..8cf0bdacf 100644 --- a/src/main/java/com/volmit/iris/util/data/NibbleArray.java +++ b/src/main/java/com/volmit/iris/util/data/NibbleArray.java @@ -26,11 +26,20 @@ import java.util.Arrays; import java.util.StringJoiner; public class NibbleArray implements Writable { + private static final int[] MASKS = new int[8]; + + static { + for (int i = 0; i < MASKS.length; i++) { + MASKS[i] = maskFor(i); + } + } + + private final int size; + private final Object lock = new Object(); private byte[] data; private int depth; - private final int size; private byte mask; - private final Object lock = new Object(); + private transient int bitIndex, byteIndex, bitInByte; public NibbleArray(int capacity, DataInputStream in) throws IOException { size = capacity; @@ -66,6 +75,30 @@ public class NibbleArray implements Writable { } } + public static int maskFor(int amountOfBits) { + return powerOfTwo(amountOfBits) - 1; + } + + public static int powerOfTwo(int power) { + int result = 1; + + for (int i = 0; i < power; i++) { + result *= 2; + } + + return result; + } + + public static String binaryString(byte b, ByteOrder byteOrder) { + String str = String.format("%8s", Integer.toBinaryString(b & 0xff)).replace(' ', '0'); + + return byteOrder.equals(ByteOrder.BIG_ENDIAN) ? str : reverse(str); + } + + public static String reverse(String str) { + return new StringBuilder(str).reverse().toString(); + } + @Override public void write(DataOutputStream o) throws IOException { o.writeByte(depth + Byte.MIN_VALUE); @@ -108,8 +141,6 @@ public class NibbleArray implements Writable { return y << 8 | z << 4 | x; } - private transient int bitIndex, byteIndex, bitInByte; - public void set(int x, int y, int z, int nibble) { set(index(x, y, z), nibble); } @@ -160,36 +191,4 @@ public class NibbleArray implements Writable { set(i, (byte) nibble); } } - - public static int maskFor(int amountOfBits) { - return powerOfTwo(amountOfBits) - 1; - } - - public static int powerOfTwo(int power) { - int result = 1; - - for (int i = 0; i < power; i++) { - result *= 2; - } - - return result; - } - - private static final int[] MASKS = new int[8]; - - static { - for (int i = 0; i < MASKS.length; i++) { - MASKS[i] = maskFor(i); - } - } - - public static String binaryString(byte b, ByteOrder byteOrder) { - String str = String.format("%8s", Integer.toBinaryString(b & 0xff)).replace(' ', '0'); - - return byteOrder.equals(ByteOrder.BIG_ENDIAN) ? str : reverse(str); - } - - public static String reverse(String str) { - return new StringBuilder(str).reverse().toString(); - } } \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/data/VanillaBiomeMap.java b/src/main/java/com/volmit/iris/util/data/VanillaBiomeMap.java index 540aeba57..967d4ef7b 100644 --- a/src/main/java/com/volmit/iris/util/data/VanillaBiomeMap.java +++ b/src/main/java/com/volmit/iris/util/data/VanillaBiomeMap.java @@ -32,38 +32,6 @@ public class VanillaBiomeMap { private static final KMap BIOME_SATURATION = new KMap<>(); private static final KMap BIOME_IDs = new KMap<>(); - private static void add(Biome biome, int color, short id, Color randomColor, Luminosity luminosity, SaturationType saturation) { - BIOME_HEX.put(biome, color); - BIOME_COLOR.put(biome, randomColor); - if (luminosity != null) BIOME_LUMINOSITY.put(biome, luminosity); - if (saturation != null) BIOME_SATURATION.put(biome, saturation); - BIOME_IDs.put(biome, id); - } - - private static void add(Biome biome, int color, short id, Color randomColor, Luminosity luminosity) { - add(biome, color, id, randomColor, luminosity, null); - } - - public static int getColor(Biome biome) { - return BIOME_HEX.get(biome); - } - - public static Color getColorType(Biome biome) { - return BIOME_COLOR.get(biome); - } - - public static Luminosity getColorLuminosity(Biome biome) { - return BIOME_LUMINOSITY.get(biome); - } - - public static SaturationType getColorSaturatiom(Biome biome) { - return BIOME_SATURATION.get(biome); - } - - public static short getId(Biome biome) { - return BIOME_IDs.get(biome); - } - static { add(Biome.OCEAN, 0x000070, (short) 0, Color.BLUE, Luminosity.BRIGHT, SaturationType.MEDIUM); add(Biome.PLAINS, 0x8DB360, (short) 1, Color.GREEN, Luminosity.LIGHT, SaturationType.MEDIUM); @@ -144,4 +112,36 @@ public class VanillaBiomeMap { add(Biome.WARPED_FOREST, 0x49907B, (short) 172, Color.BLUE, Luminosity.BRIGHT); add(Biome.BASALT_DELTAS, 0x403636, (short) 173, Color.MONOCHROME, Luminosity.DARK); } + + private static void add(Biome biome, int color, short id, Color randomColor, Luminosity luminosity, SaturationType saturation) { + BIOME_HEX.put(biome, color); + BIOME_COLOR.put(biome, randomColor); + if (luminosity != null) BIOME_LUMINOSITY.put(biome, luminosity); + if (saturation != null) BIOME_SATURATION.put(biome, saturation); + BIOME_IDs.put(biome, id); + } + + private static void add(Biome biome, int color, short id, Color randomColor, Luminosity luminosity) { + add(biome, color, id, randomColor, luminosity, null); + } + + public static int getColor(Biome biome) { + return BIOME_HEX.get(biome); + } + + public static Color getColorType(Biome biome) { + return BIOME_COLOR.get(biome); + } + + public static Luminosity getColorLuminosity(Biome biome) { + return BIOME_LUMINOSITY.get(biome); + } + + public static SaturationType getColorSaturatiom(Biome biome) { + return BIOME_SATURATION.get(biome); + } + + public static short getId(Biome biome) { + return BIOME_IDs.get(biome); + } } diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeSystem.java b/src/main/java/com/volmit/iris/util/decree/DecreeSystem.java index fd6c1590b..70d1b8688 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeSystem.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeSystem.java @@ -40,64 +40,6 @@ import java.util.List; public interface DecreeSystem extends CommandExecutor, TabCompleter { KList> handlers = Iris.initialize("com.volmit.iris.util.decree.handlers", null).convert((i) -> (DecreeParameterHandler) i); - /** - * The root class to start command searching from - * - * @return - */ - VirtualDecreeCommand getRoot(); - - default boolean call(VolmitSender sender, String[] args) { - DecreeContext.touch(sender); - return getRoot().invoke(sender, enhanceArgs(args)); - } - - @Nullable - @Override - default List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) { - KList enhanced = new KList<>(args); - KList v = getRoot().tabComplete(enhanced, enhanced.toString(" ")); - v.removeDuplicates(); - - if (sender instanceof Player) { - if (IrisSettings.get().getGeneral().isCommandSounds()) { - ((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_AMETHYST_BLOCK_CHIME, 0.25f, RNG.r.f(0.125f, 1.95f)); - } - } - - return v; - } - - @Override - default boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - if (!sender.hasPermission("iris.all")) { - sender.sendMessage("You lack the Permission 'iris.all'"); - return true; - } - - J.aBukkit(() -> { - if (!call(new VolmitSender(sender), args)) { - - if (IrisSettings.get().getGeneral().isCommandSounds()) { - if (sender instanceof Player) { - ((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_AMETHYST_CLUSTER_BREAK, 0.77f, 0.25f); - ((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 0.2f, 0.45f); - } - } - - sender.sendMessage(C.RED + "Unknown Iris Command"); - } else { - if (IrisSettings.get().getGeneral().isCommandSounds()) { - if (sender instanceof Player) { - ((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_AMETHYST_CLUSTER_BREAK, 0.77f, 1.65f); - ((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_RESPAWN_ANCHOR_CHARGE, 0.125f, 2.99f); - } - } - } - }); - return true; - } - static KList enhanceArgs(String[] args) { return enhanceArgs(args, true); } @@ -183,4 +125,62 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter { Iris.error("Unhandled type in Decree Parameter: " + type.getName() + ". This is bad!"); return null; } + + /** + * The root class to start command searching from + * + * @return + */ + VirtualDecreeCommand getRoot(); + + default boolean call(VolmitSender sender, String[] args) { + DecreeContext.touch(sender); + return getRoot().invoke(sender, enhanceArgs(args)); + } + + @Nullable + @Override + default List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) { + KList enhanced = new KList<>(args); + KList v = getRoot().tabComplete(enhanced, enhanced.toString(" ")); + v.removeDuplicates(); + + if (sender instanceof Player) { + if (IrisSettings.get().getGeneral().isCommandSounds()) { + ((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_AMETHYST_BLOCK_CHIME, 0.25f, RNG.r.f(0.125f, 1.95f)); + } + } + + return v; + } + + @Override + default boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (!sender.hasPermission("iris.all")) { + sender.sendMessage("You lack the Permission 'iris.all'"); + return true; + } + + J.aBukkit(() -> { + if (!call(new VolmitSender(sender), args)) { + + if (IrisSettings.get().getGeneral().isCommandSounds()) { + if (sender instanceof Player) { + ((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_AMETHYST_CLUSTER_BREAK, 0.77f, 0.25f); + ((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 0.2f, 0.45f); + } + } + + sender.sendMessage(C.RED + "Unknown Iris Command"); + } else { + if (IrisSettings.get().getGeneral().isCommandSounds()) { + if (sender instanceof Player) { + ((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_AMETHYST_CLUSTER_BREAK, 0.77f, 1.65f); + ((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_RESPAWN_ANCHOR_CHARGE, 0.125f, 2.99f); + } + } + } + }); + return true; + } } diff --git a/src/main/java/com/volmit/iris/util/decree/virtual/VirtualDecreeCommand.java b/src/main/java/com/volmit/iris/util/decree/virtual/VirtualDecreeCommand.java index 942d3b6ef..9b4492945 100644 --- a/src/main/java/com/volmit/iris/util/decree/virtual/VirtualDecreeCommand.java +++ b/src/main/java/com/volmit/iris/util/decree/virtual/VirtualDecreeCommand.java @@ -24,7 +24,11 @@ import com.volmit.iris.core.service.CommandSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.collection.KSet; -import com.volmit.iris.util.decree.*; +import com.volmit.iris.util.decree.DecreeContext; +import com.volmit.iris.util.decree.DecreeContextHandler; +import com.volmit.iris.util.decree.DecreeNode; +import com.volmit.iris.util.decree.DecreeParameter; +import com.volmit.iris.util.decree.DecreeParameterHandler; import com.volmit.iris.util.decree.annotations.Decree; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; import com.volmit.iris.util.decree.exceptions.DecreeWhichException; @@ -53,6 +57,15 @@ public class VirtualDecreeCommand { private final VirtualDecreeCommand parent; private final KList nodes; private final DecreeNode node; + String[] gradients = new String[]{ + "", + "", + "", + "", + "", + "" + }; + private ChronoLatch cl = new ChronoLatch(1000); private VirtualDecreeCommand(Class type, VirtualDecreeCommand parent, KList nodes, DecreeNode node) { this.parent = parent; @@ -103,8 +116,6 @@ public class VirtualDecreeCommand { return c; } - private ChronoLatch cl = new ChronoLatch(1000); - public void cacheAll() { VolmitSender sender = new VolmitSender(new CommandDummy()); @@ -504,15 +515,6 @@ public class VirtualDecreeCommand { return true; } - String[] gradients = new String[]{ - "", - "", - "", - "", - "", - "" - }; - private String pickValidOption(VolmitSender sender, KList validOptions, DecreeParameterHandler handler, String name, String type) { sender.sendHeader("Pick a " + name + " (" + type + ")"); sender.sendMessageRaw("This query will expire in 15 seconds."); diff --git a/src/main/java/com/volmit/iris/util/format/C.java b/src/main/java/com/volmit/iris/util/format/C.java index e5619e1fe..cbad69f37 100644 --- a/src/main/java/com/volmit/iris/util/format/C.java +++ b/src/main/java/com/volmit/iris/util/format/C.java @@ -253,14 +253,9 @@ public enum C { * need to dynamically convert colour codes from your custom format. */ public static final char COLOR_CHAR = '\u00A7'; - private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + COLOR_CHAR + "[0-9A-FK-OR]"); public final static C[] COLORCYCLE = new C[]{C.GOLD, C.YELLOW, C.GREEN, C.AQUA, C.LIGHT_PURPLE, C.AQUA, C.GREEN, C.YELLOW, C.GOLD, C.RED}; + private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + COLOR_CHAR + "[0-9A-FK-OR]"); private final static C[] COLORS = new C[]{C.BLACK, C.DARK_BLUE, C.DARK_GREEN, C.DARK_AQUA, C.DARK_RED, C.DARK_PURPLE, C.GOLD, C.GRAY, C.DARK_GRAY, C.BLUE, C.GREEN, C.AQUA, C.RED, C.LIGHT_PURPLE, C.YELLOW, C.WHITE}; - private final int intCode; - private final char code; - private final String token; - private final boolean isFormat; - private final String toString; @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") private final static Map BY_ID = new HashMap<>(); private final static Map BY_CHAR = new HashMap<>(); @@ -320,6 +315,19 @@ public enum C { dyeHexMap.put(DyeColor.YELLOW, "#c2b51c"); } + static { + for (C color : values()) { + BY_ID.put(color.intCode, color); + BY_CHAR.put(color.code, color); + } + } + + private final int intCode; + private final char code; + private final String token; + private final boolean isFormat; + private final String toString; + C(char code, int intCode) { this("^", code, intCode, false); } @@ -415,57 +423,6 @@ public enum C { return BaseComponent.toLegacyText(TextComponent.fromLegacyText(c)); } - public net.md_5.bungee.api.ChatColor asBungee() { - return net.md_5.bungee.api.ChatColor.RESET; - } - - /** - * Gets the char value associated with this color - * - * @return A char value of this color code - */ - public char getChar() { - return code; - } - - @Override - public String toString() { - return intCode == -1 ? token : toString; - } - - /** - * get the dye color for the chatcolor - */ - public DyeColor dye() { - return chatToDye(chatColor()); - } - - public String hex() { - return chatToHex(this); - } - - public java.awt.Color awtColor() { - return java.awt.Color.decode(hex()); - } - - /** - * Checks if this code is a format code as opposed to a color code. - * - * @return whether this ChatColor is a format code - */ - public boolean isFormat() { - return isFormat; - } - - /** - * Checks if this code is a color code as opposed to a format code. - * - * @return whether this ChatColor is a color code - */ - public boolean isColor() { - return !isFormat && this != RESET; - } - /** * Gets the color represented by the specified color code * @@ -613,13 +570,6 @@ public enum C { return str.toString(); } - /** - * Get the ChatColor enum instance instead of C - */ - public ChatColor chatColor() { - return ChatColor.getByChar(code); - } - /** * Translates a string using an alternate color code character into a string * that uses the internal ChatColor.COLOR_CODE color code character. The @@ -655,6 +605,99 @@ public enum C { return null; } + public static C randomColor() { + return COLORS[(int) (Math.random() * (COLORS.length - 1))]; + } + + /** + * Gets the ChatColors used at the end of the given input string. + * + * @param input Input string to retrieve the colors from. + * @return Any remaining ChatColors to pass onto the next line. + */ + public static String getLastColors(String input) { + StringBuilder result = new StringBuilder(); + int length = input.length(); + + // Search backwards from the end as it is faster + for (int index = length - 1; index > -1; index--) { + char section = input.charAt(index); + if (section == COLOR_CHAR && index < length - 1) { + char c = input.charAt(index + 1); + C color = getByChar(c); + + if (color != null) { + result.insert(0, color); + + // Once we find a color or reset we can stop searching + if (color.isColor() || color.equals(RESET)) { + break; + } + } + } + } + + return result.toString(); + } + + public net.md_5.bungee.api.ChatColor asBungee() { + return net.md_5.bungee.api.ChatColor.RESET; + } + + /** + * Gets the char value associated with this color + * + * @return A char value of this color code + */ + public char getChar() { + return code; + } + + @Override + public String toString() { + return intCode == -1 ? token : toString; + } + + /** + * get the dye color for the chatcolor + */ + public DyeColor dye() { + return chatToDye(chatColor()); + } + + public String hex() { + return chatToHex(this); + } + + public java.awt.Color awtColor() { + return java.awt.Color.decode(hex()); + } + + /** + * Checks if this code is a format code as opposed to a color code. + * + * @return whether this ChatColor is a format code + */ + public boolean isFormat() { + return isFormat; + } + + /** + * Checks if this code is a color code as opposed to a format code. + * + * @return whether this ChatColor is a color code + */ + public boolean isColor() { + return !isFormat && this != RESET; + } + + /** + * Get the ChatColor enum instance instead of C + */ + public ChatColor chatColor() { + return ChatColor.getByChar(code); + } + public byte getMeta() { return switch (this) { case AQUA -> (byte) 11; @@ -696,46 +739,4 @@ public enum C { default -> (byte) 15; }; } - - public static C randomColor() { - return COLORS[(int) (Math.random() * (COLORS.length - 1))]; - } - - /** - * Gets the ChatColors used at the end of the given input string. - * - * @param input Input string to retrieve the colors from. - * @return Any remaining ChatColors to pass onto the next line. - */ - public static String getLastColors(String input) { - StringBuilder result = new StringBuilder(); - int length = input.length(); - - // Search backwards from the end as it is faster - for (int index = length - 1; index > -1; index--) { - char section = input.charAt(index); - if (section == COLOR_CHAR && index < length - 1) { - char c = input.charAt(index + 1); - C color = getByChar(c); - - if (color != null) { - result.insert(0, color); - - // Once we find a color or reset we can stop searching - if (color.isColor() || color.equals(RESET)) { - break; - } - } - } - } - - return result.toString(); - } - - static { - for (C color : values()) { - BY_ID.put(color.intCode, color); - BY_CHAR.put(color.code, color); - } - } } \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/format/Form.java b/src/main/java/com/volmit/iris/util/format/Form.java index beac89d4d..b4a1fd2f0 100644 --- a/src/main/java/com/volmit/iris/util/format/Form.java +++ b/src/main/java/com/volmit/iris/util/format/Form.java @@ -24,19 +24,31 @@ import com.volmit.iris.util.math.RollingSequence; import java.math.BigInteger; import java.text.DecimalFormat; import java.text.NumberFormat; -import java.util.*; +import java.util.Calendar; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.Locale; +import java.util.Map; import java.util.Map.Entry; +import java.util.NavigableMap; +import java.util.TreeMap; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Form { - private static NumberFormat NF; - private static DecimalFormat DF; - private static final String[] NAMES = new String[]{"Thousand", "Million", "Billion", "Trillion", "Quadrillion", "Quintillion", "Sextillion", "Septillion", "Octillion", "Nonillion", "Decillion", "Undecillion", "Duodecillion", "Tredecillion", "Quattuordecillion", "Quindecillion", "Sexdecillion", "Septendecillion", "Octodecillion", "Novemdecillion", "Vigintillion",}; private static final BigInteger THOUSAND = BigInteger.valueOf(1000); private static final NavigableMap MAP; + private static NumberFormat NF; + private static DecimalFormat DF; + + static { + MAP = new TreeMap<>(); + for (int i = 0; i < NAMES.length; i++) { + MAP.put(THOUSAND.pow(i + 1), NAMES[i]); + } + } public static String getNumberSuffixThStRd(int day) { if (day >= 11 && day <= 13) { @@ -50,13 +62,6 @@ public class Form { }; } - static { - MAP = new TreeMap<>(); - for (int i = 0; i < NAMES.length; i++) { - MAP.put(THOUSAND.pow(i + 1), NAMES[i]); - } - } - private static void instantiate() { if (NF == null) { NF = NumberFormat.getInstance(Locale.US); diff --git a/src/main/java/com/volmit/iris/util/hunk/Hunk.java b/src/main/java/com/volmit/iris/util/hunk/Hunk.java index de8e6d359..7efdc417f 100644 --- a/src/main/java/com/volmit/iris/util/hunk/Hunk.java +++ b/src/main/java/com/volmit/iris/util/hunk/Hunk.java @@ -20,9 +20,37 @@ package com.volmit.iris.util.hunk; import com.volmit.iris.engine.object.IrisPosition; import com.volmit.iris.util.collection.KList; -import com.volmit.iris.util.function.*; -import com.volmit.iris.util.hunk.storage.*; -import com.volmit.iris.util.hunk.view.*; +import com.volmit.iris.util.function.Consumer2; +import com.volmit.iris.util.function.Consumer3; +import com.volmit.iris.util.function.Consumer4; +import com.volmit.iris.util.function.Consumer4IO; +import com.volmit.iris.util.function.Consumer5; +import com.volmit.iris.util.function.Consumer6; +import com.volmit.iris.util.function.Consumer8; +import com.volmit.iris.util.function.Function3; +import com.volmit.iris.util.function.NoiseProvider; +import com.volmit.iris.util.function.NoiseProvider3; +import com.volmit.iris.util.function.Supplier3R; +import com.volmit.iris.util.hunk.storage.ArrayHunk; +import com.volmit.iris.util.hunk.storage.AtomicDoubleHunk; +import com.volmit.iris.util.hunk.storage.AtomicHunk; +import com.volmit.iris.util.hunk.storage.AtomicIntegerHunk; +import com.volmit.iris.util.hunk.storage.AtomicLongHunk; +import com.volmit.iris.util.hunk.storage.MappedHunk; +import com.volmit.iris.util.hunk.storage.SynchronizedArrayHunk; +import com.volmit.iris.util.hunk.view.BiomeGridHunkView; +import com.volmit.iris.util.hunk.view.ChunkBiomeHunkView; +import com.volmit.iris.util.hunk.view.ChunkDataHunkView; +import com.volmit.iris.util.hunk.view.ChunkHunkView; +import com.volmit.iris.util.hunk.view.DriftHunkView; +import com.volmit.iris.util.hunk.view.FringedHunkView; +import com.volmit.iris.util.hunk.view.FunctionalHunkView; +import com.volmit.iris.util.hunk.view.HunkView; +import com.volmit.iris.util.hunk.view.InvertedHunkView; +import com.volmit.iris.util.hunk.view.ListeningHunk; +import com.volmit.iris.util.hunk.view.ReadOnlyHunk; +import com.volmit.iris.util.hunk.view.SynchronizedHunkView; +import com.volmit.iris.util.hunk.view.WriteTrackHunk; import com.volmit.iris.util.interpolation.InterpolationMethod; import com.volmit.iris.util.interpolation.InterpolationMethod3D; import com.volmit.iris.util.interpolation.IrisInterpolation; @@ -57,14 +85,6 @@ public interface Hunk { return new HunkView(src); } - default boolean isMapped() { - return false; - } - - default int getEntryCount() { - return getWidth() * getHeight() * getDepth(); - } - static Hunk convertedReadView(Hunk src, Function reader) { return new FunctionalHunkView(src, reader, null); } @@ -106,18 +126,6 @@ public interface Hunk { return newCombinedArrayHunk(hunks); } - default Hunk listen(Consumer4 l) { - return new ListeningHunk<>(this, l); - } - - default Hunk synchronize() { - return new SynchronizedHunkView<>(this); - } - - default Hunk trackWrite(AtomicBoolean b) { - return new WriteTrackHunk(this, b); - } - static Hunk newArrayHunk(int w, int h, int d) { return new ArrayHunk<>(w, h, d); } @@ -214,6 +222,208 @@ public interface Hunk { return b; } + static void computeDual2D(int parallelism, Hunk a, Hunk b, Consumer5, Hunk> v) { + if (a.getWidth() != b.getWidth() || a.getHeight() != b.getHeight() || a.getDepth() != b.getDepth()) { + throw new RuntimeException("Hunk sizes must match!"); + } + + if (a.get2DDimension(parallelism) == 1) { + v.accept(0, 0, 0, a, b); + return; + } + + BurstExecutor e = MultiBurst.burst.burst(parallelism); + KList rq = new KList(parallelism); + getDualSections2D(parallelism, a, b, (xx, yy, zz, ha, hr, r) -> e.queue(() -> + { + v.accept(xx, yy, zz, ha, hr); + + synchronized (rq) { + rq.add(r); + } + }), (x, y, z, hax, hbx) -> + { + a.insert(x, y, z, hax); + b.insert(x, y, z, hbx); + }); + e.complete(); + rq.forEach(Runnable::run); + return; + } + + static void getDualSections2D(int sections, Hunk a, Hunk b, Consumer6, Hunk, Runnable> v, Consumer5, Hunk> inserterAB) { + if (a.getWidth() != b.getWidth() || a.getHeight() != b.getHeight() || a.getDepth() != b.getDepth()) { + throw new RuntimeException("Hunk sizes must match!"); + } + + int dim = a.get2DDimension(sections); + + if (sections <= 1) { + getDualSection(0, 0, 0, a.getWidth(), a.getHeight(), a.getDepth(), a, b, (ha, hr, r) -> v.accept(0, 0, 0, ha, hr, r), inserterAB); + return; + } + + int w = a.getWidth() / dim; + int wr = a.getWidth() - (w * dim); + int d = a.getDepth() / dim; + int dr = a.getDepth() - (d * dim); + int i, j; + + for (i = 0; i < a.getWidth(); i += w) { + int ii = i; + + for (j = 0; j < a.getDepth(); j += d) { + int jj = j; + getDualSection(i, 0, j, i + w + (i == 0 ? wr : 0), a.getHeight(), j + d + (j == 0 ? dr : 0), a, b, (ha, hr, r) -> v.accept(ii, 0, jj, ha, hr, r), inserterAB); + i = i == 0 ? i + wr : i; + j = j == 0 ? j + dr : j; + } + } + } + + static void getDualSection(int x, int y, int z, int x1, int y1, int z1, Hunk a, Hunk b, Consumer3, Hunk, Runnable> v, Consumer5, Hunk> inserter) { + Hunk copya = a.crop(x, y, z, x1, y1, z1); + Hunk copyb = b.crop(x, y, z, x1, y1, z1); + v.accept(copya, copyb, () -> inserter.accept(x, y, z, copya, copyb)); + } + + /** + * Create a hunk that is optimized for specific uses + * + * @param w width + * @param h height + * @param d depth + * @param type the class type + * @param packed if the hunk is generally more than 50% full (non-null nodes) + * @param concurrent if this hunk must be thread safe + * @param the type + * @return the hunk + */ + static Hunk newHunk(int w, int h, int d, Class type, boolean packed, boolean concurrent) { + if (type.equals(Double.class)) { + return concurrent ? + packed ? (Hunk) newAtomicDoubleHunk(w, h, d) : newMappedHunk(w, h, d) + : packed ? newArrayHunk(w, h, d) : newMappedHunkSynced(w, h, d); + } + + if (type.equals(Integer.class)) { + return concurrent ? + packed ? (Hunk) newAtomicIntegerHunk(w, h, d) : newMappedHunk(w, h, d) + : packed ? newArrayHunk(w, h, d) : newMappedHunkSynced(w, h, d); + } + + if (type.equals(Long.class)) { + return concurrent ? + packed ? (Hunk) newAtomicLongHunk(w, h, d) : newMappedHunk(w, h, d) + : packed ? newArrayHunk(w, h, d) : newMappedHunkSynced(w, h, d); + } + + return concurrent ? + packed ? newAtomicHunk(w, h, d) : newMappedHunk(w, h, d) + : packed ? newArrayHunk(w, h, d) : newMappedHunkSynced(w, h, d); + } + + static IrisPosition rotatedBounding(int w, int h, int d, double x, double y, double z) { + int[] iii = {0, 0, 0}; + int[] aaa = {w, h, d}; + int[] aai = {w, h, 0}; + int[] iaa = {0, h, d}; + int[] aia = {w, 0, d}; + int[] iai = {0, h, 0}; + int[] iia = {0, 0, d}; + int[] aii = {w, 0, 0}; + rotate(x, y, z, iii); + rotate(x, y, z, aaa); + rotate(x, y, z, aai); + rotate(x, y, z, iaa); + rotate(x, y, z, aia); + rotate(x, y, z, iai); + rotate(x, y, z, iia); + rotate(x, y, z, aii); + int maxX = max(iii[0], aaa[0], aai[0], iaa[0], aia[0], iai[0], iia[0], aii[0]); + int minX = min(iii[0], aaa[0], aai[0], iaa[0], aia[0], iai[0], iia[0], aii[0]); + int maxY = max(iii[1], aaa[1], aai[1], iaa[1], aia[1], iai[1], iia[1], aii[1]); + int minY = min(iii[1], aaa[1], aai[1], iaa[1], aia[1], iai[1], iia[1], aii[1]); + int maxZ = max(iii[2], aaa[2], aai[2], iaa[2], aia[2], iai[2], iia[2], aii[2]); + int minZ = min(iii[2], aaa[2], aai[2], iaa[2], aia[2], iai[2], iia[2], aii[2]); + return new IrisPosition(maxX - minX, maxY - minY, maxZ - minZ); + } + + static int max(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { + return Math.max(Math.max(Math.max(a5, a6), Math.max(a7, a8)), Math.max(Math.max(a1, a2), Math.max(a3, a4))); + } + + static int min(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { + return Math.min(Math.min(Math.min(a5, a6), Math.min(a7, a8)), Math.min(Math.min(a1, a2), Math.min(a3, a4))); + } + + static void rotate(double x, double y, double z, int[] c) { + if (x % 360 != 0) { + rotateAroundX(Math.toRadians(x), c); + } + + if (y % 360 != 0) { + rotateAroundY(Math.toRadians(y), c); + } + + if (z % 360 != 0) { + rotateAroundZ(Math.toRadians(z), c); + } + } + + static void rotateAroundX(double a, int[] c) { + rotateAroundX(Math.cos(a), Math.sin(a), c); + } + + static void rotateAroundX(double cos, double sin, int[] c) { + int y = (int) Math.floor(cos * (double) (c[1] + 0.5) - sin * (double) (c[2] + 0.5)); + int z = (int) Math.floor(sin * (double) (c[1] + 0.5) + cos * (double) (c[2] + 0.5)); + c[1] = y; + c[2] = z; + } + + static void rotateAroundY(double a, int[] c) { + rotateAroundY(Math.cos(a), Math.sin(a), c); + } + + static void rotateAroundY(double cos, double sin, int[] c) { + int x = (int) Math.floor(cos * (double) (c[0] + 0.5) + sin * (double) (c[2] + 0.5)); + int z = (int) Math.floor(-sin * (double) (c[0] + 0.5) + cos * (double) (c[2] + 0.5)); + c[0] = x; + c[2] = z; + } + + static void rotateAroundZ(double a, int[] c) { + rotateAroundZ(Math.cos(a), Math.sin(a), c); + } + + static void rotateAroundZ(double cos, double sin, int[] c) { + int x = (int) Math.floor(cos * (double) (c[0] + 0.5) - sin * (double) (c[1] + 0.5)); + int y = (int) Math.floor(sin * (double) (c[0] + 0.5) + cos * (double) (c[1] + 0.5)); + c[0] = x; + c[1] = y; + } + + default boolean isMapped() { + return false; + } + + default int getEntryCount() { + return getWidth() * getHeight() * getDepth(); + } + + default Hunk listen(Consumer4 l) { + return new ListeningHunk<>(this, l); + } + + default Hunk synchronize() { + return new SynchronizedHunkView<>(this); + } + + default Hunk trackWrite(AtomicBoolean b) { + return new WriteTrackHunk(this, b); + } + default Hunk readOnly() { return new ReadOnlyHunk<>(this); } @@ -589,71 +799,6 @@ public interface Hunk { return compute2D(getIdeal2DParallelism(), v); } - static void computeDual2D(int parallelism, Hunk a, Hunk b, Consumer5, Hunk> v) { - if (a.getWidth() != b.getWidth() || a.getHeight() != b.getHeight() || a.getDepth() != b.getDepth()) { - throw new RuntimeException("Hunk sizes must match!"); - } - - if (a.get2DDimension(parallelism) == 1) { - v.accept(0, 0, 0, a, b); - return; - } - - BurstExecutor e = MultiBurst.burst.burst(parallelism); - KList rq = new KList(parallelism); - getDualSections2D(parallelism, a, b, (xx, yy, zz, ha, hr, r) -> e.queue(() -> - { - v.accept(xx, yy, zz, ha, hr); - - synchronized (rq) { - rq.add(r); - } - }), (x, y, z, hax, hbx) -> - { - a.insert(x, y, z, hax); - b.insert(x, y, z, hbx); - }); - e.complete(); - rq.forEach(Runnable::run); - return; - } - - static void getDualSections2D(int sections, Hunk a, Hunk b, Consumer6, Hunk, Runnable> v, Consumer5, Hunk> inserterAB) { - if (a.getWidth() != b.getWidth() || a.getHeight() != b.getHeight() || a.getDepth() != b.getDepth()) { - throw new RuntimeException("Hunk sizes must match!"); - } - - int dim = a.get2DDimension(sections); - - if (sections <= 1) { - getDualSection(0, 0, 0, a.getWidth(), a.getHeight(), a.getDepth(), a, b, (ha, hr, r) -> v.accept(0, 0, 0, ha, hr, r), inserterAB); - return; - } - - int w = a.getWidth() / dim; - int wr = a.getWidth() - (w * dim); - int d = a.getDepth() / dim; - int dr = a.getDepth() - (d * dim); - int i, j; - - for (i = 0; i < a.getWidth(); i += w) { - int ii = i; - - for (j = 0; j < a.getDepth(); j += d) { - int jj = j; - getDualSection(i, 0, j, i + w + (i == 0 ? wr : 0), a.getHeight(), j + d + (j == 0 ? dr : 0), a, b, (ha, hr, r) -> v.accept(ii, 0, jj, ha, hr, r), inserterAB); - i = i == 0 ? i + wr : i; - j = j == 0 ? j + dr : j; - } - } - } - - static void getDualSection(int x, int y, int z, int x1, int y1, int z1, Hunk a, Hunk b, Consumer3, Hunk, Runnable> v, Consumer5, Hunk> inserter) { - Hunk copya = a.crop(x, y, z, x1, y1, z1); - Hunk copyb = b.crop(x, y, z, x1, y1, z1); - v.accept(copya, copyb, () -> inserter.accept(x, y, z, copya, copyb)); - } - default Hunk compute2D(int parallelism, Consumer4> v) { if (get2DDimension(parallelism) == 1) { v.accept(0, 0, 0, this); @@ -1051,42 +1196,6 @@ public interface Hunk { setRaw(x, y, z, t); } - /** - * Create a hunk that is optimized for specific uses - * - * @param w width - * @param h height - * @param d depth - * @param type the class type - * @param packed if the hunk is generally more than 50% full (non-null nodes) - * @param concurrent if this hunk must be thread safe - * @param the type - * @return the hunk - */ - static Hunk newHunk(int w, int h, int d, Class type, boolean packed, boolean concurrent) { - if (type.equals(Double.class)) { - return concurrent ? - packed ? (Hunk) newAtomicDoubleHunk(w, h, d) : newMappedHunk(w, h, d) - : packed ? newArrayHunk(w, h, d) : newMappedHunkSynced(w, h, d); - } - - if (type.equals(Integer.class)) { - return concurrent ? - packed ? (Hunk) newAtomicIntegerHunk(w, h, d) : newMappedHunk(w, h, d) - : packed ? newArrayHunk(w, h, d) : newMappedHunkSynced(w, h, d); - } - - if (type.equals(Long.class)) { - return concurrent ? - packed ? (Hunk) newAtomicLongHunk(w, h, d) : newMappedHunk(w, h, d) - : packed ? newArrayHunk(w, h, d) : newMappedHunkSynced(w, h, d); - } - - return concurrent ? - packed ? newAtomicHunk(w, h, d) : newMappedHunk(w, h, d) - : packed ? newArrayHunk(w, h, d) : newMappedHunkSynced(w, h, d); - } - default void setIfExists(int x, int y, int z, T t) { if (x < 0 || x >= getWidth() || y < 0 || y >= getHeight() || z < 0 || z >= getDepth()) { return; @@ -1297,32 +1406,6 @@ public interface Hunk { return t; } - static IrisPosition rotatedBounding(int w, int h, int d, double x, double y, double z) { - int[] iii = {0, 0, 0}; - int[] aaa = {w, h, d}; - int[] aai = {w, h, 0}; - int[] iaa = {0, h, d}; - int[] aia = {w, 0, d}; - int[] iai = {0, h, 0}; - int[] iia = {0, 0, d}; - int[] aii = {w, 0, 0}; - rotate(x, y, z, iii); - rotate(x, y, z, aaa); - rotate(x, y, z, aai); - rotate(x, y, z, iaa); - rotate(x, y, z, aia); - rotate(x, y, z, iai); - rotate(x, y, z, iia); - rotate(x, y, z, aii); - int maxX = max(iii[0], aaa[0], aai[0], iaa[0], aia[0], iai[0], iia[0], aii[0]); - int minX = min(iii[0], aaa[0], aai[0], iaa[0], aia[0], iai[0], iia[0], aii[0]); - int maxY = max(iii[1], aaa[1], aai[1], iaa[1], aia[1], iai[1], iia[1], aii[1]); - int minY = min(iii[1], aaa[1], aai[1], iaa[1], aia[1], iai[1], iia[1], aii[1]); - int maxZ = max(iii[2], aaa[2], aai[2], iaa[2], aia[2], iai[2], iia[2], aii[2]); - int minZ = min(iii[2], aaa[2], aai[2], iaa[2], aia[2], iai[2], iia[2], aii[2]); - return new IrisPosition(maxX - minX, maxY - minY, maxZ - minZ); - } - default Hunk rotate(double x, double y, double z, Supplier3R> builder) { int w = getWidth(); int h = getHeight(); @@ -1375,61 +1458,6 @@ public interface Hunk { return r; } - static int max(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { - return Math.max(Math.max(Math.max(a5, a6), Math.max(a7, a8)), Math.max(Math.max(a1, a2), Math.max(a3, a4))); - } - - static int min(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) { - return Math.min(Math.min(Math.min(a5, a6), Math.min(a7, a8)), Math.min(Math.min(a1, a2), Math.min(a3, a4))); - } - - static void rotate(double x, double y, double z, int[] c) { - if (x % 360 != 0) { - rotateAroundX(Math.toRadians(x), c); - } - - if (y % 360 != 0) { - rotateAroundY(Math.toRadians(y), c); - } - - if (z % 360 != 0) { - rotateAroundZ(Math.toRadians(z), c); - } - } - - static void rotateAroundX(double a, int[] c) { - rotateAroundX(Math.cos(a), Math.sin(a), c); - } - - static void rotateAroundX(double cos, double sin, int[] c) { - int y = (int) Math.floor(cos * (double) (c[1] + 0.5) - sin * (double) (c[2] + 0.5)); - int z = (int) Math.floor(sin * (double) (c[1] + 0.5) + cos * (double) (c[2] + 0.5)); - c[1] = y; - c[2] = z; - } - - static void rotateAroundY(double a, int[] c) { - rotateAroundY(Math.cos(a), Math.sin(a), c); - } - - static void rotateAroundY(double cos, double sin, int[] c) { - int x = (int) Math.floor(cos * (double) (c[0] + 0.5) + sin * (double) (c[2] + 0.5)); - int z = (int) Math.floor(-sin * (double) (c[0] + 0.5) + cos * (double) (c[2] + 0.5)); - c[0] = x; - c[2] = z; - } - - static void rotateAroundZ(double a, int[] c) { - rotateAroundZ(Math.cos(a), Math.sin(a), c); - } - - static void rotateAroundZ(double cos, double sin, int[] c) { - int x = (int) Math.floor(cos * (double) (c[0] + 0.5) - sin * (double) (c[1] + 0.5)); - int y = (int) Math.floor(sin * (double) (c[0] + 0.5) + cos * (double) (c[1] + 0.5)); - c[0] = x; - c[1] = y; - } - default boolean isEmpty() { return false; } diff --git a/src/main/java/com/volmit/iris/util/interpolation/IrisInterpolation.java b/src/main/java/com/volmit/iris/util/interpolation/IrisInterpolation.java index 2c581486c..ba549ef89 100644 --- a/src/main/java/com/volmit/iris/util/interpolation/IrisInterpolation.java +++ b/src/main/java/com/volmit/iris/util/interpolation/IrisInterpolation.java @@ -29,6 +29,8 @@ import com.volmit.iris.util.noise.CNG; import java.util.HashMap; public class IrisInterpolation { + public static CNG cng = NoiseStyle.SIMPLEX.create(new RNG()); + public static double bezier(double t) { return t * t * (3.0d - 2.0d * t); } @@ -278,8 +280,6 @@ public class IrisInterpolation { //@done } - public static CNG cng = NoiseStyle.SIMPLEX.create(new RNG()); - public static double getBilinearNoise(int x, int z, double rad, NoiseProvider n) { int fx = (int) Math.floor(x / rad); int fz = (int) Math.floor(z / rad); diff --git a/src/main/java/com/volmit/iris/util/inventorygui/Element.java b/src/main/java/com/volmit/iris/util/inventorygui/Element.java index bf1d23d08..c8ef9b0b8 100644 --- a/src/main/java/com/volmit/iris/util/inventorygui/Element.java +++ b/src/main/java/com/volmit/iris/util/inventorygui/Element.java @@ -37,24 +37,24 @@ public interface Element { String getName(); - Element setProgress(double progress); + Element setName(String name); double getProgress(); + Element setProgress(double progress); + short getEffectiveDurability(); - Element setCount(int c); - int getCount(); + Element setCount(int c); + ItemStack computeItemStack(); Element setBackground(boolean bg); boolean isBackgrond(); - Element setName(String name); - Element addLore(String loreLine); KList getLore(); diff --git a/src/main/java/com/volmit/iris/util/inventorygui/RandomColor.java b/src/main/java/com/volmit/iris/util/inventorygui/RandomColor.java index b25d4c1e6..dfa7f04b0 100644 --- a/src/main/java/com/volmit/iris/util/inventorygui/RandomColor.java +++ b/src/main/java/com/volmit/iris/util/inventorygui/RandomColor.java @@ -29,112 +29,7 @@ import java.util.Random; public class RandomColor { public static int hueOffset = 0; - - public static class ColorInfo { - Range hueRange; - Range saturationRange; - Range brightnessRange; - List lowerBounds; - - public ColorInfo(Range hueRange, Range saturationRange, Range brightnessRange, List lowerBounds) { - this.hueRange = hueRange; - this.saturationRange = saturationRange; - this.brightnessRange = brightnessRange; - this.lowerBounds = lowerBounds; - } - - public Range getHueRange() { - return hueRange; - } - - public void setHueRange(Range hueRange) { - this.hueRange = hueRange; - } - - public Range getSaturationRange() { - return saturationRange; - } - - public void setSaturationRange(Range saturationRange) { - this.saturationRange = saturationRange; - } - - public Range getBrightnessRange() { - return brightnessRange; - } - - public void setBrightnessRange(Range brightnessRange) { - this.brightnessRange = brightnessRange; - } - - public List getLowerBounds() { - return lowerBounds; - } - - public void setLowerBounds(List lowerBounds) { - this.lowerBounds = lowerBounds; - } - } - - public static class Range { - int start; - int end; - - public Range(int start, int end) { - this.start = start; - this.end = end; - } - - public boolean contain(int value) { - return value >= start && value <= end; - } - - @Override - public String toString() { - return "start: " + start + " end: " + end; - } - } - private final Random random; - - public enum SaturationType { - RANDOM, MONOCHROME, HIGH, LOW, MEDIUM - } - - public enum Luminosity { - BRIGHT, LIGHT, DARK, RANDOM - } - - public static class Options { - int hue; - SaturationType saturationType; - Luminosity luminosity; - - public int getHue() { - return hue; - } - - public void setHue(int hue) { - this.hue = hue; - } - - public SaturationType getSaturationType() { - return saturationType; - } - - public void setSaturationType(SaturationType saturationType) { - this.saturationType = saturationType; - } - - public Luminosity getLuminosity() { - return luminosity; - } - - public void setLuminosity(Luminosity luminosity) { - this.luminosity = luminosity; - } - } - private final HashMap colors = new HashMap<>(); public RandomColor() { @@ -520,10 +415,113 @@ public class RandomColor { ); } + public enum SaturationType { + RANDOM, MONOCHROME, HIGH, LOW, MEDIUM + } + + public enum Luminosity { + BRIGHT, LIGHT, DARK, RANDOM + } + public enum Color { MONOCHROME, RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE, PINK } + public static class ColorInfo { + Range hueRange; + Range saturationRange; + Range brightnessRange; + List lowerBounds; + + public ColorInfo(Range hueRange, Range saturationRange, Range brightnessRange, List lowerBounds) { + this.hueRange = hueRange; + this.saturationRange = saturationRange; + this.brightnessRange = brightnessRange; + this.lowerBounds = lowerBounds; + } + + public Range getHueRange() { + return hueRange; + } + + public void setHueRange(Range hueRange) { + this.hueRange = hueRange; + } + + public Range getSaturationRange() { + return saturationRange; + } + + public void setSaturationRange(Range saturationRange) { + this.saturationRange = saturationRange; + } + + public Range getBrightnessRange() { + return brightnessRange; + } + + public void setBrightnessRange(Range brightnessRange) { + this.brightnessRange = brightnessRange; + } + + public List getLowerBounds() { + return lowerBounds; + } + + public void setLowerBounds(List lowerBounds) { + this.lowerBounds = lowerBounds; + } + } + + public static class Range { + int start; + int end; + + public Range(int start, int end) { + this.start = start; + this.end = end; + } + + public boolean contain(int value) { + return value >= start && value <= end; + } + + @Override + public String toString() { + return "start: " + start + " end: " + end; + } + } + + public static class Options { + int hue; + SaturationType saturationType; + Luminosity luminosity; + + public int getHue() { + return hue; + } + + public void setHue(int hue) { + this.hue = hue; + } + + public SaturationType getSaturationType() { + return saturationType; + } + + public void setSaturationType(SaturationType saturationType) { + this.saturationType = saturationType; + } + + public Luminosity getLuminosity() { + return luminosity; + } + + public void setLuminosity(Luminosity luminosity) { + this.luminosity = luminosity; + } + } + } diff --git a/src/main/java/com/volmit/iris/util/inventorygui/UIElement.java b/src/main/java/com/volmit/iris/util/inventorygui/UIElement.java index 339a5554a..331122202 100644 --- a/src/main/java/com/volmit/iris/util/inventorygui/UIElement.java +++ b/src/main/java/com/volmit/iris/util/inventorygui/UIElement.java @@ -28,13 +28,13 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; public class UIElement implements Element { + private final String id; + private final KList lore; private MaterialBlock material; private boolean enchanted; - private final String id; private String name; private double progress; private boolean bg; - private final KList lore; private Callback eLeft; private Callback eRight; private Callback eShiftLeft; @@ -56,16 +56,16 @@ public class UIElement implements Element { return material; } - public Double clip(double value, double min, double max) { - return Math.min(max, Math.max(min, value)); - } - @Override public UIElement setMaterial(MaterialBlock material) { this.material = material; return this; } + public Double clip(double value, double min, double max) { + return Math.min(max, Math.max(min, value)); + } + @Override public boolean isEnchanted() { return enchanted; diff --git a/src/main/java/com/volmit/iris/util/inventorygui/UIWindow.java b/src/main/java/com/volmit/iris/util/inventorygui/UIWindow.java index ad76278e9..45824aa91 100644 --- a/src/main/java/com/volmit/iris/util/inventorygui/UIWindow.java +++ b/src/main/java/com/volmit/iris/util/inventorygui/UIWindow.java @@ -35,11 +35,11 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; public class UIWindow implements Window, Listener { - private WindowDecorator decorator; private final Player viewer; + private final KMap elements; + private WindowDecorator decorator; private Callback eClose; private WindowResolution resolution; - private final KMap elements; private String title; private boolean visible; private int viewportPosition; @@ -195,14 +195,14 @@ public class UIWindow implements Window, Listener { } @Override - public UIWindow setDecorator(WindowDecorator decorator) { - this.decorator = decorator; - return this; + public WindowDecorator getDecorator() { + return decorator; } @Override - public WindowDecorator getDecorator() { - return decorator; + public UIWindow setDecorator(WindowDecorator decorator) { + this.decorator = decorator; + return this; } @Override @@ -217,6 +217,11 @@ public class UIWindow implements Window, Listener { return this; } + @Override + public boolean isVisible() { + return visible; + } + @Override public UIWindow setVisible(boolean visible) { if (isVisible() == visible) { @@ -245,11 +250,6 @@ public class UIWindow implements Window, Listener { return this; } - @Override - public boolean isVisible() { - return visible; - } - @Override public int getViewportPosition() { return viewportPosition; diff --git a/src/main/java/com/volmit/iris/util/inventorygui/Window.java b/src/main/java/com/volmit/iris/util/inventorygui/Window.java index e279e9f36..35e3730f6 100644 --- a/src/main/java/com/volmit/iris/util/inventorygui/Window.java +++ b/src/main/java/com/volmit/iris/util/inventorygui/Window.java @@ -23,10 +23,10 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; public interface Window { - Window setDecorator(WindowDecorator decorator); - WindowDecorator getDecorator(); + Window setDecorator(WindowDecorator decorator); + WindowResolution getResolution(); Window setResolution(WindowResolution resolution); @@ -41,8 +41,6 @@ public interface Window { Window updateInventory(); - Window setVisible(boolean visible); - ItemStack computeItemStack(int viewportSlot); int getLayoutRow(int viewportSlottedPosition); @@ -59,12 +57,14 @@ public interface Window { boolean isVisible(); + Window setVisible(boolean visible); + int getViewportPosition(); - int getViewportSlots(); - Window setViewportPosition(int position); + int getViewportSlots(); + int getMaxViewportPosition(); Window scroll(int direction); diff --git a/src/main/java/com/volmit/iris/util/io/IO.java b/src/main/java/com/volmit/iris/util/io/IO.java index ac6f53e7c..9d27f42e0 100644 --- a/src/main/java/com/volmit/iris/util/io/IO.java +++ b/src/main/java/com/volmit/iris/util/io/IO.java @@ -20,12 +20,36 @@ package com.volmit.iris.util.io; import com.volmit.iris.Iris; -import java.io.*; +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.CharArrayWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.StringWriter; +import java.io.Writer; import java.nio.charset.StandardCharsets; import java.security.DigestInputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.util.*; +import java.util.ArrayList; +import java.util.Base64; +import java.util.Collection; +import java.util.Enumeration; +import java.util.Iterator; +import java.util.List; import java.util.function.Consumer; import java.util.zip.GZIPInputStream; import java.util.zip.ZipEntry; @@ -64,6 +88,14 @@ public class IO { private static final int DEFAULT_BUFFER_SIZE = 1024 * 4; private final static char[] hexArray = "0123456789ABCDEF".toCharArray(); + static { + // avoid security issues + StringWriter buf = new StringWriter(4); + PrintWriter out = new PrintWriter(buf); + out.println(); + LINE_SEPARATOR = buf.toString(); + } + public static String decompress(String gz) throws IOException { ByteArrayInputStream bin = new ByteArrayInputStream(Base64.getUrlDecoder().decode(gz)); GZIPInputStream gzi = new GZIPInputStream(bin); @@ -451,6 +483,8 @@ public class IO { doCopyFile(srcFile, destFile, preserveFileDate); } + // ----------------------------------------------------------------------- + /** * Internal copy file method. * @@ -484,8 +518,6 @@ public class IO { } } - // ----------------------------------------------------------------------- - /** * Unconditionally close an Reader. *

@@ -543,6 +575,9 @@ public class IO { } } + // read toByteArray + // ----------------------------------------------------------------------- + /** * Unconditionally close an OutputStream. *

@@ -562,9 +597,6 @@ public class IO { } } - // read toByteArray - // ----------------------------------------------------------------------- - /** * Get the contents of an InputStream as a byte[]. *

@@ -623,6 +655,9 @@ public class IO { return output.toByteArray(); } + // read char[] + // ----------------------------------------------------------------------- + /** * Get the contents of a String as a byte[] using the * default character encoding of the platform. @@ -638,9 +673,6 @@ public class IO { return input.getBytes(); } - // read char[] - // ----------------------------------------------------------------------- - /** * Get the contents of an InputStream as a character array using * the default character encoding of the platform. @@ -683,6 +715,9 @@ public class IO { return output.toCharArray(); } + // read toString + // ----------------------------------------------------------------------- + /** * Get the contents of a Reader as a character array. *

@@ -701,9 +736,6 @@ public class IO { return sw.toCharArray(); } - // read toString - // ----------------------------------------------------------------------- - /** * Get the contents of an InputStream as a String using the default * character encoding of the platform. @@ -774,6 +806,9 @@ public class IO { return new String(input); } + // readLines + // ----------------------------------------------------------------------- + /** * Get the contents of a byte[] as a String using the specified * character encoding. @@ -797,9 +832,6 @@ public class IO { } } - // readLines - // ----------------------------------------------------------------------- - /** * Get the contents of an InputStream as a list of Strings, one * entry per line, using the default character encoding of the platform. @@ -844,6 +876,8 @@ public class IO { } } + // ----------------------------------------------------------------------- + /** * Get the contents of a Reader as a list of Strings, one entry per * line. @@ -868,8 +902,6 @@ public class IO { return list; } - // ----------------------------------------------------------------------- - /** * Convert the specified string to an input stream, encoded as bytes using the * default character encoding of the platform. @@ -883,6 +915,9 @@ public class IO { return new ByteArrayInputStream(bytes); } + // write byte[] + // ----------------------------------------------------------------------- + /** * Convert the specified string to an input stream, encoded as bytes using the * specified character encoding. @@ -901,9 +936,6 @@ public class IO { return new ByteArrayInputStream(bytes); } - // write byte[] - // ----------------------------------------------------------------------- - /** * Writes bytes from a byte[] to an OutputStream. * @@ -937,6 +969,9 @@ public class IO { } } + // write char[] + // ----------------------------------------------------------------------- + /** * Writes bytes from a byte[] to chars on a Writer * using the specified character encoding. @@ -963,9 +998,6 @@ public class IO { } } - // write char[] - // ----------------------------------------------------------------------- - /** * Writes chars from a char[] to a Writer using the * default character encoding of the platform. @@ -1000,6 +1032,9 @@ public class IO { } } + // write String + // ----------------------------------------------------------------------- + /** * Writes chars from a char[] to bytes on an * OutputStream using the specified character encoding. @@ -1027,9 +1062,6 @@ public class IO { } } - // write String - // ----------------------------------------------------------------------- - /** * Writes chars from a String to a Writer. * @@ -1064,6 +1096,9 @@ public class IO { } } + // write StringBuffer + // ----------------------------------------------------------------------- + /** * Writes chars from a String to bytes on an * OutputStream using the specified character encoding. @@ -1090,9 +1125,6 @@ public class IO { } } - // write StringBuffer - // ----------------------------------------------------------------------- - /** * Writes chars from a StringBuffer to a Writer. * @@ -1127,6 +1159,9 @@ public class IO { } } + // writeLines + // ----------------------------------------------------------------------- + /** * Writes chars from a StringBuffer to bytes on an * OutputStream using the specified character encoding. @@ -1153,9 +1188,6 @@ public class IO { } } - // writeLines - // ----------------------------------------------------------------------- - /** * Writes the toString() value of each item in a collection to an * OutputStream line by line, using the default character encoding @@ -1220,6 +1252,9 @@ public class IO { } } + // copy from InputStream + // ----------------------------------------------------------------------- + /** * Writes the toString() value of each item in a collection to a * Writer line by line, using the specified line ending. @@ -1247,9 +1282,6 @@ public class IO { } } - // copy from InputStream - // ----------------------------------------------------------------------- - /** * Copy bytes from an InputStream to an OutputStream. *

@@ -1322,6 +1354,9 @@ public class IO { copy(in, output); } + // copy from Reader + // ----------------------------------------------------------------------- + /** * Copy bytes from an InputStream to chars on a Writer * using the specified character encoding. @@ -1350,9 +1385,6 @@ public class IO { } } - // copy from Reader - // ----------------------------------------------------------------------- - /** * Copy chars from a Reader to a Writer. *

@@ -1431,6 +1463,9 @@ public class IO { out.flush(); } + // content equals + // ----------------------------------------------------------------------- + /** * Copy chars from a Reader to bytes on an * OutputStream using the specified character encoding, and calling @@ -1465,9 +1500,6 @@ public class IO { } } - // content equals - // ----------------------------------------------------------------------- - /** * Compare the contents of two Streams to determine if they are equal or not. *

@@ -1536,12 +1568,4 @@ public class IO { int ch2 = input2.read(); return (ch2 == -1); } - - static { - // avoid security issues - StringWriter buf = new StringWriter(4); - PrintWriter out = new PrintWriter(buf); - out.println(); - LINE_SEPARATOR = buf.toString(); - } } diff --git a/src/main/java/com/volmit/iris/util/json/JSONObject.java b/src/main/java/com/volmit/iris/util/json/JSONObject.java index 440a36a28..87b502b5c 100644 --- a/src/main/java/com/volmit/iris/util/json/JSONObject.java +++ b/src/main/java/com/volmit/iris/util/json/JSONObject.java @@ -28,8 +28,15 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.math.BigDecimal; import java.math.BigInteger; -import java.util.*; +import java.util.Collection; +import java.util.Enumeration; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Locale; +import java.util.Map; import java.util.Map.Entry; +import java.util.ResourceBundle; +import java.util.Set; /** * A JSONObject is an unordered collection of name/value pairs. Its external @@ -83,51 +90,6 @@ import java.util.Map.Entry; */ @SuppressWarnings("ALL") public class JSONObject { - /** - * JSONObject.NULL is equivalent to the value that JavaScript calls null, - * whilst Java's null is equivalent to the value that JavaScript calls - * undefined. - */ - private static final class Null { - - /** - * There is only intended to be a single instance of the NULL object, so - * the clone method returns itself. - * - * @return NULL. - */ - @Override - protected final Object clone() { - return this; - } - - /** - * A Null object is equal to the null value and to itself. - * - * @param object An object to test for nullness. - * @return true if the object parameter is the JSONObject.NULL object or - * null. - */ - @Override - public boolean equals(Object object) { - return object == null || object == this; - } - - /** - * Get the "null" string value. - * - * @return The string "null". - */ - public String toString() { - return "null"; - } - } - - /** - * The map where the JSONObject's properties are kept. - */ - private final LinkedHashMap map; - /** * It is sometimes more convenient and less ambiguous to have a * NULL object than to use Java's null value. @@ -135,6 +97,10 @@ public class JSONObject { * JSONObject.NULL.toString() returns "null". */ public static final Object NULL = new Null(); + /** + * The map where the JSONObject's properties are kept. + */ + private final LinkedHashMap map; /** * Construct an empty JSONObject. @@ -344,6 +310,401 @@ public class JSONObject { } } + /** + * Produce a string from a double. The string "null" will be returned if the + * number is not finite. + * + * @param d A double. + * @return A String. + */ + public static String doubleToString(double d) { + if (Double.isInfinite(d) || Double.isNaN(d)) { + return "null"; + } + + // Shave off trailing zeros and decimal point, if possible. + + String string = Double.toString(d); + if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && string.indexOf('E') < 0) { + while (string.endsWith("0")) { + string = string.substring(0, string.length() - 1); + } + if (string.endsWith(".")) { + string = string.substring(0, string.length() - 1); + } + } + return string; + } + + /** + * Get an array of field names from a JSONObject. + * + * @return An array of field names, or null if there are no names. + */ + public static String[] getNames(JSONObject jo) { + int length = jo.length(); + if (length == 0) { + return null; + } + Iterator iterator = jo.keys(); + String[] names = new String[length]; + int i = 0; + while (iterator.hasNext()) { + names[i] = iterator.next(); + i += 1; + } + return names; + } + + /** + * Get an array of field names from an Object. + * + * @return An array of field names, or null if there are no names. + */ + public static String[] getNames(Object object) { + if (object == null) { + return null; + } + Class klass = object.getClass(); + Field[] fields = klass.getFields(); + int length = fields.length; + if (length == 0) { + return null; + } + String[] names = new String[length]; + for (int i = 0; i < length; i += 1) { + names[i] = fields[i].getName(); + } + return names; + } + + /** + * Produce a string from a Number. + * + * @param number A Number + * @return A String. + * @throws JSONException If n is a non-finite number. + */ + public static String numberToString(Number number) throws JSONException { + if (number == null) { + throw new JSONException("Null pointer"); + } + testValidity(number); + + // Shave off trailing zeros and decimal point, if possible. + + String string = number.toString(); + if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && string.indexOf('E') < 0) { + while (string.endsWith("0")) { + string = string.substring(0, string.length() - 1); + } + if (string.endsWith(".")) { + string = string.substring(0, string.length() - 1); + } + } + return string; + } + + /** + * Produce a string in double quotes with backslash sequences in all the + * right places. A backslash will be inserted within = '\u0080' && c < '\u00a0') || (c >= '\u2000' && c < '\u2100')) { + w.write("\\u"); + hhhh = Integer.toHexString(c); + w.write("0000", 0, 4 - hhhh.length()); + w.write(hhhh); + } else { + w.write(c); + } + } + } + w.write('"'); + return w; + } + + /** + * Try to convert a string into a number, boolean, or null. If the string + * can't be converted, return the string. + * + * @param string A String. + * @return A simple JSON value. + */ + public static Object stringToValue(String string) { + Double d; + if (string.equals("")) { + return string; + } + if (string.equalsIgnoreCase("true")) { + return Boolean.TRUE; + } + if (string.equalsIgnoreCase("false")) { + return Boolean.FALSE; + } + if (string.equalsIgnoreCase("null")) { + return JSONObject.NULL; + } + + /* + * If it might be a number, try converting it. If a number cannot be + * produced, then the value will just be a string. + */ + + char b = string.charAt(0); + if ((b >= '0' && b <= '9') || b == '-') { + try { + if (string.indexOf('.') > -1 || string.indexOf('e') > -1 || string.indexOf('E') > -1) { + d = Double.valueOf(string); + if (!d.isInfinite() && !d.isNaN()) { + return d; + } + } else { + Long myLong = Long.valueOf(string); + if (string.equals(myLong.toString())) { + if (myLong == myLong.intValue()) { + return myLong.intValue(); + } else { + return myLong; + } + } + } + } catch (Exception e) { + Iris.reportError(e); + } + } + return string; + } + + /** + * Throw an exception if the object is a NaN or infinite number. + * + * @param o The object to test. + * @throws JSONException If o is a non-finite number. + */ + public static void testValidity(Object o) throws JSONException { + if (o != null) { + if (o instanceof Double) { + if (((Double) o).isInfinite() || ((Double) o).isNaN()) { + throw new JSONException("JSON does not allow non-finite numbers."); + } + } else if (o instanceof Float) { + if (((Float) o).isInfinite() || ((Float) o).isNaN()) { + throw new JSONException("JSON does not allow non-finite numbers."); + } + } + } + } + + /** + * Make a JSON text of an Object value. If the object has an + * value.toJSONString() method, then that method will be used to produce the + * JSON text. The method is required to produce a strictly conforming text. + * If the object does not contain a toJSONString method (which is the most + * common case), then a text will be produced by other means. If the value + * is an array or Collection, then a JSONArray will be made from it and its + * toJSONString method will be called. If the value is a MAP, then a + * JSONObject will be made from it and its toJSONString method will be + * called. Otherwise, the value's toString method will be called, and the + * result will be quoted. + * + *

+ * Warning: This method assumes that the data structure is acyclical. + * + * @param value The value to be serialized. + * @return a printable, displayable, transmittable representation of the + * object, beginning with { (left + * brace) and ending with } (right + * brace). + * @throws JSONException If the value is or contains an invalid number. + */ + public static String valueToString(Object value) throws JSONException { + if (value == null || value.equals(null)) { + return "null"; + } + if (value instanceof JSONString) { + Object object; + try { + object = ((JSONString) value).toJSONString(); + } catch (Exception e) { + Iris.reportError(e); + throw new JSONException(e); + } + if (object instanceof String) { + return (String) object; + } + throw new JSONException("Bad value from toJSONString: " + object); + } + if (value instanceof Number) { + return numberToString((Number) value); + } + if (value instanceof Boolean || value instanceof JSONObject || value instanceof JSONArray) { + return value.toString(); + } + if (value instanceof Map) { + @SuppressWarnings("unchecked") + Map map = (Map) value; + return new JSONObject(map).toString(); + } + if (value instanceof Collection) { + @SuppressWarnings("unchecked") + Collection coll = (Collection) value; + return new JSONArray(coll).toString(); + } + if (value.getClass().isArray()) { + return new JSONArray(value).toString(); + } + return quote(value.toString()); + } + + /** + * Wrap an object, if necessary. If the object is null, return the NULL + * object. If it is an array or collection, wrap it in a JSONArray. If it is + * a map, wrap it in a JSONObject. If it is a standard property (Double, + * String, et al) then it is already wrapped. Otherwise, if it comes from + * one of the java packages, turn it into a string. And if it doesn't, try + * to wrap it in a JSONObject. If the wrapping fails, then null is returned. + * + * @param object The object to wrap + * @return The wrapped value + */ + public static Object wrap(Object object) { + try { + if (object == null) { + return NULL; + } + if (object instanceof JSONObject || object instanceof JSONArray || NULL.equals(object) || object instanceof JSONString || object instanceof Byte || object instanceof Character || object instanceof Short || object instanceof Integer || object instanceof Long || object instanceof Boolean || object instanceof Float || object instanceof Double || object instanceof String || object instanceof BigInteger || object instanceof BigDecimal) { + return object; + } + + if (object instanceof Collection) { + @SuppressWarnings("unchecked") + Collection coll = (Collection) object; + return new JSONArray(coll); + } + if (object.getClass().isArray()) { + return new JSONArray(object); + } + if (object instanceof Map) { + @SuppressWarnings("unchecked") + Map map = (Map) object; + return new JSONObject(map); + } + Package objectPackage = object.getClass().getPackage(); + String objectPackageName = objectPackage != null ? objectPackage.getName() : ""; + if (objectPackageName.startsWith("java.") || objectPackageName.startsWith("javax.") || object.getClass().getClassLoader() == null) { + return object.toString(); + } + return new JSONObject(object); + } catch (Exception e) { + Iris.reportError(e); + return null; + } + } + + static final Writer writeValue(Writer writer, Object value, int indentFactor, int indent) throws JSONException, IOException { + if (value == null || value.equals(null)) { + writer.write("null"); + } else if (value instanceof JSONObject) { + ((JSONObject) value).write(writer, indentFactor, indent); + } else if (value instanceof JSONArray) { + ((JSONArray) value).write(writer, indentFactor, indent); + } else if (value instanceof Map) { + @SuppressWarnings("unchecked") + Map map = (Map) value; + new JSONObject(map).write(writer, indentFactor, indent); + } else if (value instanceof Collection) { + @SuppressWarnings("unchecked") + Collection coll = (Collection) value; + new JSONArray(coll).write(writer, indentFactor, indent); + } else if (value.getClass().isArray()) { + new JSONArray(value).write(writer, indentFactor, indent); + } else if (value instanceof Number) { + writer.write(numberToString((Number) value)); + } else if (value instanceof Boolean) { + writer.write(value.toString()); + } else if (value instanceof JSONString) { + Object o; + try { + o = ((JSONString) value).toJSONString(); + } catch (Exception e) { + Iris.reportError(e); + throw new JSONException(e); + } + writer.write(o != null ? o.toString() : quote(value.toString())); + } else { + quote(value.toString(), writer); + } + return writer; + } + + static final void indent(Writer writer, int indent) throws IOException { + for (int i = 0; i < indent; i += 1) { + writer.write(' '); + } + } + /** * Accumulate values under a key. It is similar to the put method except * that if there is already an object stored under the key then a JSONArray @@ -398,32 +759,6 @@ public class JSONObject { return this; } - /** - * Produce a string from a double. The string "null" will be returned if the - * number is not finite. - * - * @param d A double. - * @return A String. - */ - public static String doubleToString(double d) { - if (Double.isInfinite(d) || Double.isNaN(d)) { - return "null"; - } - - // Shave off trailing zeros and decimal point, if possible. - - String string = Double.toString(d); - if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && string.indexOf('E') < 0) { - while (string.endsWith("0")) { - string = string.substring(0, string.length() - 1); - } - if (string.endsWith(".")) { - string = string.substring(0, string.length() - 1); - } - } - return string; - } - /** * Get the value object associated with a key. * @@ -600,48 +935,6 @@ public class JSONObject { } } - /** - * Get an array of field names from a JSONObject. - * - * @return An array of field names, or null if there are no names. - */ - public static String[] getNames(JSONObject jo) { - int length = jo.length(); - if (length == 0) { - return null; - } - Iterator iterator = jo.keys(); - String[] names = new String[length]; - int i = 0; - while (iterator.hasNext()) { - names[i] = iterator.next(); - i += 1; - } - return names; - } - - /** - * Get an array of field names from an Object. - * - * @return An array of field names, or null if there are no names. - */ - public static String[] getNames(Object object) { - if (object == null) { - return null; - } - Class klass = object.getClass(); - Field[] fields = klass.getFields(); - int length = fields.length; - if (length == 0) { - return null; - } - String[] names = new String[length]; - for (int i = 0; i < length; i += 1) { - names[i] = fields[i].getName(); - } - return names; - } - /** * Get the string associated with a key. * @@ -754,33 +1047,6 @@ public class JSONObject { return ja.length() == 0 ? null : ja; } - /** - * Produce a string from a Number. - * - * @param number A Number - * @return A String. - * @throws JSONException If n is a non-finite number. - */ - public static String numberToString(Number number) throws JSONException { - if (number == null) { - throw new JSONException("Null pointer"); - } - testValidity(number); - - // Shave off trailing zeros and decimal point, if possible. - - String string = number.toString(); - if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && string.indexOf('E') < 0) { - while (string.endsWith("0")) { - string = string.substring(0, string.length() - 1); - } - if (string.endsWith(".")) { - string = string.substring(0, string.length() - 1); - } - } - return string; - } - /** * Get an optional value associated with a key. * @@ -1221,86 +1487,6 @@ public class JSONObject { return this; } - /** - * Produce a string in double quotes with backslash sequences in all the - * right places. A backslash will be inserted within = '\u0080' && c < '\u00a0') || (c >= '\u2000' && c < '\u2100')) { - w.write("\\u"); - hhhh = Integer.toHexString(c); - w.write("0000", 0, 4 - hhhh.length()); - w.write(hhhh); - } else { - w.write(c); - } - } - } - w.write('"'); - return w; - } - /** * Remove a name and its value, if present. * @@ -1353,78 +1539,6 @@ public class JSONObject { } } - /** - * Try to convert a string into a number, boolean, or null. If the string - * can't be converted, return the string. - * - * @param string A String. - * @return A simple JSON value. - */ - public static Object stringToValue(String string) { - Double d; - if (string.equals("")) { - return string; - } - if (string.equalsIgnoreCase("true")) { - return Boolean.TRUE; - } - if (string.equalsIgnoreCase("false")) { - return Boolean.FALSE; - } - if (string.equalsIgnoreCase("null")) { - return JSONObject.NULL; - } - - /* - * If it might be a number, try converting it. If a number cannot be - * produced, then the value will just be a string. - */ - - char b = string.charAt(0); - if ((b >= '0' && b <= '9') || b == '-') { - try { - if (string.indexOf('.') > -1 || string.indexOf('e') > -1 || string.indexOf('E') > -1) { - d = Double.valueOf(string); - if (!d.isInfinite() && !d.isNaN()) { - return d; - } - } else { - Long myLong = Long.valueOf(string); - if (string.equals(myLong.toString())) { - if (myLong == myLong.intValue()) { - return myLong.intValue(); - } else { - return myLong; - } - } - } - } catch (Exception e) { - Iris.reportError(e); - } - } - return string; - } - - /** - * Throw an exception if the object is a NaN or infinite number. - * - * @param o The object to test. - * @throws JSONException If o is a non-finite number. - */ - public static void testValidity(Object o) throws JSONException { - if (o != null) { - if (o instanceof Double) { - if (((Double) o).isInfinite() || ((Double) o).isNaN()) { - throw new JSONException("JSON does not allow non-finite numbers."); - } - } else if (o instanceof Float) { - if (((Float) o).isInfinite() || ((Float) o).isNaN()) { - throw new JSONException("JSON does not allow non-finite numbers."); - } - } - } - } - /** * Produce a JSONArray containing the values of the members of this * JSONObject. @@ -1485,112 +1599,6 @@ public class JSONObject { } } - /** - * Make a JSON text of an Object value. If the object has an - * value.toJSONString() method, then that method will be used to produce the - * JSON text. The method is required to produce a strictly conforming text. - * If the object does not contain a toJSONString method (which is the most - * common case), then a text will be produced by other means. If the value - * is an array or Collection, then a JSONArray will be made from it and its - * toJSONString method will be called. If the value is a MAP, then a - * JSONObject will be made from it and its toJSONString method will be - * called. Otherwise, the value's toString method will be called, and the - * result will be quoted. - * - *

- * Warning: This method assumes that the data structure is acyclical. - * - * @param value The value to be serialized. - * @return a printable, displayable, transmittable representation of the - * object, beginning with { (left - * brace) and ending with } (right - * brace). - * @throws JSONException If the value is or contains an invalid number. - */ - public static String valueToString(Object value) throws JSONException { - if (value == null || value.equals(null)) { - return "null"; - } - if (value instanceof JSONString) { - Object object; - try { - object = ((JSONString) value).toJSONString(); - } catch (Exception e) { - Iris.reportError(e); - throw new JSONException(e); - } - if (object instanceof String) { - return (String) object; - } - throw new JSONException("Bad value from toJSONString: " + object); - } - if (value instanceof Number) { - return numberToString((Number) value); - } - if (value instanceof Boolean || value instanceof JSONObject || value instanceof JSONArray) { - return value.toString(); - } - if (value instanceof Map) { - @SuppressWarnings("unchecked") - Map map = (Map) value; - return new JSONObject(map).toString(); - } - if (value instanceof Collection) { - @SuppressWarnings("unchecked") - Collection coll = (Collection) value; - return new JSONArray(coll).toString(); - } - if (value.getClass().isArray()) { - return new JSONArray(value).toString(); - } - return quote(value.toString()); - } - - /** - * Wrap an object, if necessary. If the object is null, return the NULL - * object. If it is an array or collection, wrap it in a JSONArray. If it is - * a map, wrap it in a JSONObject. If it is a standard property (Double, - * String, et al) then it is already wrapped. Otherwise, if it comes from - * one of the java packages, turn it into a string. And if it doesn't, try - * to wrap it in a JSONObject. If the wrapping fails, then null is returned. - * - * @param object The object to wrap - * @return The wrapped value - */ - public static Object wrap(Object object) { - try { - if (object == null) { - return NULL; - } - if (object instanceof JSONObject || object instanceof JSONArray || NULL.equals(object) || object instanceof JSONString || object instanceof Byte || object instanceof Character || object instanceof Short || object instanceof Integer || object instanceof Long || object instanceof Boolean || object instanceof Float || object instanceof Double || object instanceof String || object instanceof BigInteger || object instanceof BigDecimal) { - return object; - } - - if (object instanceof Collection) { - @SuppressWarnings("unchecked") - Collection coll = (Collection) object; - return new JSONArray(coll); - } - if (object.getClass().isArray()) { - return new JSONArray(object); - } - if (object instanceof Map) { - @SuppressWarnings("unchecked") - Map map = (Map) object; - return new JSONObject(map); - } - Package objectPackage = object.getClass().getPackage(); - String objectPackageName = objectPackage != null ? objectPackage.getName() : ""; - if (objectPackageName.startsWith("java.") || objectPackageName.startsWith("javax.") || object.getClass().getClassLoader() == null) { - return object.toString(); - } - return new JSONObject(object); - } catch (Exception e) { - Iris.reportError(e); - return null; - } - } - /** * Write the contents of the JSONObject as JSON text to a writer. For * compactness, no whitespace is added. @@ -1604,48 +1612,6 @@ public class JSONObject { return this.write(writer, 0, 0); } - static final Writer writeValue(Writer writer, Object value, int indentFactor, int indent) throws JSONException, IOException { - if (value == null || value.equals(null)) { - writer.write("null"); - } else if (value instanceof JSONObject) { - ((JSONObject) value).write(writer, indentFactor, indent); - } else if (value instanceof JSONArray) { - ((JSONArray) value).write(writer, indentFactor, indent); - } else if (value instanceof Map) { - @SuppressWarnings("unchecked") - Map map = (Map) value; - new JSONObject(map).write(writer, indentFactor, indent); - } else if (value instanceof Collection) { - @SuppressWarnings("unchecked") - Collection coll = (Collection) value; - new JSONArray(coll).write(writer, indentFactor, indent); - } else if (value.getClass().isArray()) { - new JSONArray(value).write(writer, indentFactor, indent); - } else if (value instanceof Number) { - writer.write(numberToString((Number) value)); - } else if (value instanceof Boolean) { - writer.write(value.toString()); - } else if (value instanceof JSONString) { - Object o; - try { - o = ((JSONString) value).toJSONString(); - } catch (Exception e) { - Iris.reportError(e); - throw new JSONException(e); - } - writer.write(o != null ? o.toString() : quote(value.toString())); - } else { - quote(value.toString(), writer); - } - return writer; - } - - static final void indent(Writer writer, int indent) throws IOException { - for (int i = 0; i < indent; i += 1) { - writer.write(' '); - } - } - /** * Write the contents of the JSONObject as JSON text to a writer. For * compactness, no whitespace is added. @@ -1701,4 +1667,44 @@ public class JSONObject { throw new JSONException(e); } } + + /** + * JSONObject.NULL is equivalent to the value that JavaScript calls null, + * whilst Java's null is equivalent to the value that JavaScript calls + * undefined. + */ + private static final class Null { + + /** + * There is only intended to be a single instance of the NULL object, so + * the clone method returns itself. + * + * @return NULL. + */ + @Override + protected final Object clone() { + return this; + } + + /** + * A Null object is equal to the null value and to itself. + * + * @param object An object to test for nullness. + * @return true if the object parameter is the JSONObject.NULL object or + * null. + */ + @Override + public boolean equals(Object object) { + return object == null || object == this; + } + + /** + * Get the "null" string value. + * + * @return The string "null". + */ + public String toString() { + return "null"; + } + } } diff --git a/src/main/java/com/volmit/iris/util/json/JSONTokener.java b/src/main/java/com/volmit/iris/util/json/JSONTokener.java index 52dac1efb..2753cf173 100644 --- a/src/main/java/com/volmit/iris/util/json/JSONTokener.java +++ b/src/main/java/com/volmit/iris/util/json/JSONTokener.java @@ -21,7 +21,12 @@ package com.volmit.iris.util.json; import com.volmit.iris.Iris; -import java.io.*; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; /** * A JSONTokener takes a source string and extracts characters and tokens from @@ -34,12 +39,12 @@ import java.io.*; @SuppressWarnings("ALL") public class JSONTokener { + private final Reader reader; private long character; private boolean eof; private long index; private long line; private char previous; - private final Reader reader; private boolean usePrevious; /** @@ -75,21 +80,6 @@ public class JSONTokener { this(new StringReader(s)); } - /** - * Back up one character. This provides a sort of lookahead capability, so - * that you can test for a digit or letter before attempting to parse the - * next number or identifier. - */ - public void back() throws JSONException { - if (this.usePrevious || this.index <= 0) { - throw new JSONException("Stepping back two steps is not supported"); - } - this.index -= 1; - this.character -= 1; - this.usePrevious = true; - this.eof = false; - } - /** * Get the hex value of a character (base16). * @@ -110,6 +100,21 @@ public class JSONTokener { return -1; } + /** + * Back up one character. This provides a sort of lookahead capability, so + * that you can test for a digit or letter before attempting to parse the + * next number or identifier. + */ + public void back() throws JSONException { + if (this.usePrevious || this.index <= 0) { + throw new JSONException("Stepping back two steps is not supported"); + } + this.index -= 1; + this.character -= 1; + this.usePrevious = true; + this.eof = false; + } + public boolean end() { return this.eof && !this.usePrevious; } diff --git a/src/main/java/com/volmit/iris/util/json/JSONWriter.java b/src/main/java/com/volmit/iris/util/json/JSONWriter.java index b45cceb46..737ea7956 100644 --- a/src/main/java/com/volmit/iris/util/json/JSONWriter.java +++ b/src/main/java/com/volmit/iris/util/json/JSONWriter.java @@ -59,34 +59,29 @@ import java.io.Writer; */ public class JSONWriter { private static final int maxdepth = 200; - /** - * The comma flag determines if a comma should be output before the next - * value. + * The writer that will receive the output. */ - private boolean comma; - + protected final Writer writer; + /** + * The object/array stack. + */ + private final JSONObject[] stack; /** * The current mode. Values: 'a' (array), 'd' (done), 'i' (initial), 'k' * (key), 'o' (object). */ protected char mode; - /** - * The object/array stack. + * The comma flag determines if a comma should be output before the next + * value. */ - private final JSONObject[] stack; - + private boolean comma; /** * The stack top index. A value of 0 indicates that the stack is empty. */ private int top; - /** - * The writer that will receive the output. - */ - protected final Writer writer; - /** * Make a fresh JSONWriter. It can be used to build one JSON text. */ diff --git a/src/main/java/com/volmit/iris/util/mantle/Mantle.java b/src/main/java/com/volmit/iris/util/mantle/Mantle.java index 1b4be5b1f..eaa3004f8 100644 --- a/src/main/java/com/volmit/iris/util/mantle/Mantle.java +++ b/src/main/java/com/volmit/iris/util/mantle/Mantle.java @@ -82,6 +82,44 @@ public class Mantle { Iris.debug("Opened The Mantle " + C.DARK_AQUA + dataFolder.getAbsolutePath()); } + /** + * Get the file for a region + * + * @param folder the folder + * @param x the x coord + * @param z the z coord + * @return the file + */ + public static File fileForRegion(File folder, int x, int z) { + return fileForRegion(folder, key(x, z)); + } + + /** + * Get the file for the given region + * + * @param folder the data folder + * @param key the region key + * @return the file + */ + public static File fileForRegion(File folder, Long key) { + File f = new File(folder, "p." + key + ".ttp"); + if (!f.getParentFile().exists()) { + f.getParentFile().mkdirs(); + } + return f; + } + + /** + * Get the long value representing a chunk or region coordinate + * + * @param x the x + * @param z the z + * @return the value + */ + public static Long key(int x, int z) { + return Cache.key(x, z); + } + /** * Raise a flag if it is lowered currently, If the flag was raised, execute the runnable * @@ -391,7 +429,6 @@ public class Mantle { return get(x, z); } - /** * This retreives a future of the Tectonic Plate at the given coordinates. * All methods accessing tectonic plates should go through this method @@ -449,44 +486,6 @@ public class Mantle { })); } - /** - * Get the file for a region - * - * @param folder the folder - * @param x the x coord - * @param z the z coord - * @return the file - */ - public static File fileForRegion(File folder, int x, int z) { - return fileForRegion(folder, key(x, z)); - } - - /** - * Get the file for the given region - * - * @param folder the data folder - * @param key the region key - * @return the file - */ - public static File fileForRegion(File folder, Long key) { - File f = new File(folder, "p." + key + ".ttp"); - if (!f.getParentFile().exists()) { - f.getParentFile().mkdirs(); - } - return f; - } - - /** - * Get the long value representing a chunk or region coordinate - * - * @param x the x - * @param z the z - * @return the value - */ - public static Long key(int x, int z) { - return Cache.key(x, z); - } - public void saveAll() { } diff --git a/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java b/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java index 896961e9b..a894004f7 100644 --- a/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java +++ b/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java @@ -40,11 +40,11 @@ import java.util.concurrent.atomic.AtomicReferenceArray; * Mantle Chunks are fully atomic & thread safe */ public class MantleChunk { + private static final ZoneMatter zm = new ZoneMatter(); @Getter private final int x; @Getter private final int z; - private static final ZoneMatter zm = new ZoneMatter(); private final AtomicIntegerArray flags; private final AtomicReferenceArray sections; private final CopyOnWriteArrayList features; diff --git a/src/main/java/com/volmit/iris/util/mantle/TectonicPlate.java b/src/main/java/com/volmit/iris/util/mantle/TectonicPlate.java index e5532774b..2cca77286 100644 --- a/src/main/java/com/volmit/iris/util/mantle/TectonicPlate.java +++ b/src/main/java/com/volmit/iris/util/mantle/TectonicPlate.java @@ -26,7 +26,12 @@ import com.volmit.iris.util.format.Form; import com.volmit.iris.util.scheduling.PrecisionStopwatch; import lombok.Getter; -import java.io.*; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; import java.util.concurrent.atomic.AtomicReferenceArray; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; diff --git a/src/main/java/com/volmit/iris/util/math/Average.java b/src/main/java/com/volmit/iris/util/math/Average.java index 545bdf654..d68d6c0c4 100644 --- a/src/main/java/com/volmit/iris/util/math/Average.java +++ b/src/main/java/com/volmit/iris/util/math/Average.java @@ -29,10 +29,10 @@ import com.volmit.iris.util.data.DoubleArrayUtils; */ public class Average { protected final double[] values; + protected int cursor; private double average; private double lastSum; private boolean dirty; - protected int cursor; private boolean brandNew; /** diff --git a/src/main/java/com/volmit/iris/util/math/AxisAlignedBB.java b/src/main/java/com/volmit/iris/util/math/AxisAlignedBB.java index 10603e5ac..2873f0e8c 100644 --- a/src/main/java/com/volmit/iris/util/math/AxisAlignedBB.java +++ b/src/main/java/com/volmit/iris/util/math/AxisAlignedBB.java @@ -40,14 +40,6 @@ public class AxisAlignedBB { this.zb = zb; } - public AxisAlignedBB shifted(IrisPosition p) { - return shifted(p.getX(), p.getY(), p.getZ()); - } - - public AxisAlignedBB shifted(double x, double y, double z) { - return new AxisAlignedBB(min().add(new IrisPosition((int) x, (int) y, (int) z)), max().add(new IrisPosition((int) x, (int) y, (int) z))); - } - public AxisAlignedBB(AlignedPoint a, AlignedPoint b) { this(a.getX(), b.getX(), a.getY(), b.getY(), a.getZ(), b.getZ()); } @@ -56,6 +48,14 @@ public class AxisAlignedBB { this(a.getX(), b.getX(), a.getY(), b.getY(), a.getZ(), b.getZ()); } + public AxisAlignedBB shifted(IrisPosition p) { + return shifted(p.getX(), p.getY(), p.getZ()); + } + + public AxisAlignedBB shifted(double x, double y, double z) { + return new AxisAlignedBB(min().add(new IrisPosition((int) x, (int) y, (int) z)), max().add(new IrisPosition((int) x, (int) y, (int) z))); + } + public boolean contains(AlignedPoint p) { return p.getX() >= xa && p.getX() <= xb && p.getY() >= ya && p.getZ() <= yb && p.getZ() >= za && p.getZ() <= zb; } diff --git a/src/main/java/com/volmit/iris/util/math/BlockPosition.java b/src/main/java/com/volmit/iris/util/math/BlockPosition.java index 0b9877f4e..3d8a886ff 100644 --- a/src/main/java/com/volmit/iris/util/math/BlockPosition.java +++ b/src/main/java/com/volmit/iris/util/math/BlockPosition.java @@ -26,17 +26,16 @@ import java.util.Objects; @Data public class BlockPosition { - private int x; - private int y; - private int z; - //Magic numbers private static final int m1 = 1 + MathHelper.f(MathHelper.c(30000000)); private static final int m2 = 64 - (m1 * 2); private static final long m3 = m1 + m2; - private static final long m4 = (1L << m1) - 1L; private static final long m5 = (1L << m2) - 1L; + private static final long m4 = (1L << m1) - 1L; private static final long m6 = (1L << m1) - 1L; + private int x; + private int y; + private int z; public BlockPosition(int x, int y, int z) { this.x = x; @@ -44,6 +43,14 @@ public class BlockPosition { this.z = z; } + public static long toLong(int x, int y, int z) { + long var3 = 0L; + var3 |= (x & m4) << m3; + var3 |= (y & m5); + var3 |= (z & m6) << m2; + return var3; + } + @Override public int hashCode() { return Objects.hash(x, y, z); @@ -82,14 +89,6 @@ public class BlockPosition { return toLong(getX(), getY(), getZ()); } - public static long toLong(int x, int y, int z) { - long var3 = 0L; - var3 |= (x & m4) << m3; - var3 |= (y & m5); - var3 |= (z & m6) << m2; - return var3; - } - public Block toBlock(World world) { return world.getBlockAt(x, y, z); } diff --git a/src/main/java/com/volmit/iris/util/math/CDou.java b/src/main/java/com/volmit/iris/util/math/CDou.java index 76323fb71..2cce3ab4c 100644 --- a/src/main/java/com/volmit/iris/util/math/CDou.java +++ b/src/main/java/com/volmit/iris/util/math/CDou.java @@ -20,8 +20,8 @@ package com.volmit.iris.util.math; @SuppressWarnings("ALL") public class CDou { - private double number; private final double max; + private double number; public CDou(double max) { number = 0; diff --git a/src/main/java/com/volmit/iris/util/math/Direction.java b/src/main/java/com/volmit/iris/util/math/Direction.java index 7565c7733..103495c1b 100644 --- a/src/main/java/com/volmit/iris/util/math/Direction.java +++ b/src/main/java/com/volmit/iris/util/math/Direction.java @@ -48,6 +48,13 @@ public enum Direction { private final int z; private final CuboidDirection f; + Direction(int x, int y, int z, CuboidDirection f) { + this.x = x; + this.y = y; + this.z = z; + this.f = f; + } + public static Direction getDirection(BlockFace f) { return switch (f) { case DOWN -> D; @@ -60,23 +67,6 @@ public enum Direction { } - @Override - public String toString() { - return switch (this) { - case D -> "Down"; - case E -> "East"; - case N -> "North"; - case S -> "South"; - case U -> "Up"; - case W -> "West"; - }; - - } - - public boolean isVertical() { - return equals(D) || equals(U); - } - public static Direction closest(Vector v) { double m = Double.MAX_VALUE; Direction s = null; @@ -128,75 +118,6 @@ public enum Direction { return s; } - public Vector toVector() { - return new Vector(x, y, z); - } - - public boolean isCrooked(Direction to) { - if (equals(to.reverse())) { - return false; - } - - return !equals(to); - } - - Direction(int x, int y, int z, CuboidDirection f) { - this.x = x; - this.y = y; - this.z = z; - this.f = f; - } - - public Vector angle(Vector initial, Direction d) { - calculatePermutations(); - - for (Map.Entry, DOP> entry : permute.entrySet()) { - GBiset i = entry.getKey(); - if (i.getA().equals(this) && i.getB().equals(d)) { - return entry.getValue().op(initial); - } - } - - return initial; - } - - public Direction reverse() { - switch (this) { - case D: - return U; - case E: - return W; - case N: - return S; - case S: - return N; - case U: - return D; - case W: - return E; - default: - break; - } - - return null; - } - - public int x() { - return x; - } - - public int y() { - return y; - } - - public int z() { - return z; - } - - public CuboidDirection f() { - return f; - } - public static KList news() { return new KList().add(N, E, W, S); } @@ -245,32 +166,6 @@ public enum Direction { } } - /** - * Get the byte value represented in some directional blocks - * - * @return the byte value - */ - public byte byteValue() { - switch (this) { - case D: - return 0; - case E: - return 5; - case N: - return 2; - case S: - return 3; - case U: - return 1; - case W: - return 4; - default: - break; - } - - return -1; - } - public static void calculatePermutations() { if (permute != null) { return; @@ -359,6 +254,111 @@ public enum Direction { } } + @Override + public String toString() { + return switch (this) { + case D -> "Down"; + case E -> "East"; + case N -> "North"; + case S -> "South"; + case U -> "Up"; + case W -> "West"; + }; + + } + + public boolean isVertical() { + return equals(D) || equals(U); + } + + public Vector toVector() { + return new Vector(x, y, z); + } + + public boolean isCrooked(Direction to) { + if (equals(to.reverse())) { + return false; + } + + return !equals(to); + } + + public Vector angle(Vector initial, Direction d) { + calculatePermutations(); + + for (Map.Entry, DOP> entry : permute.entrySet()) { + GBiset i = entry.getKey(); + if (i.getA().equals(this) && i.getB().equals(d)) { + return entry.getValue().op(initial); + } + } + + return initial; + } + + public Direction reverse() { + switch (this) { + case D: + return U; + case E: + return W; + case N: + return S; + case S: + return N; + case U: + return D; + case W: + return E; + default: + break; + } + + return null; + } + + public int x() { + return x; + } + + public int y() { + return y; + } + + public int z() { + return z; + } + + public CuboidDirection f() { + return f; + } + + /** + * Get the byte value represented in some directional blocks + * + * @return the byte value + */ + public byte byteValue() { + switch (this) { + case D: + return 0; + case E: + return 5; + case N: + return 2; + case S: + return 3; + case U: + return 1; + case W: + return 4; + default: + break; + } + + return -1; + } + public BlockFace getFace() { return switch (this) { case D -> BlockFace.DOWN; diff --git a/src/main/java/com/volmit/iris/util/math/IrisMathHelper.java b/src/main/java/com/volmit/iris/util/math/IrisMathHelper.java index 1b7b7c426..b26ac688f 100644 --- a/src/main/java/com/volmit/iris/util/math/IrisMathHelper.java +++ b/src/main/java/com/volmit/iris/util/math/IrisMathHelper.java @@ -30,6 +30,21 @@ public class IrisMathHelper { private static final double[] f; private static final double[] g; + static { + a = c(2.0f); + c = new Random(); + d = new int[]{0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9}; + e = Double.longBitsToDouble(4805340802404319232L); + f = new double[257]; + g = new double[257]; + for (int var2 = 0; var2 < 257; ++var2) { + final double var3 = var2 / 256.0; + final double var4 = Math.asin(var3); + IrisMathHelper.g[var2] = Math.cos(var4); + IrisMathHelper.f[var2] = var4; + } + } + public static float c(final float var0) { return (float) Math.sqrt(var0); } @@ -436,19 +451,4 @@ public class IrisMathHelper { public static float k(final float var0) { return var0 * var0; } - - static { - a = c(2.0f); - c = new Random(); - d = new int[]{0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9}; - e = Double.longBitsToDouble(4805340802404319232L); - f = new double[257]; - g = new double[257]; - for (int var2 = 0; var2 < 257; ++var2) { - final double var3 = var2 / 256.0; - final double var4 = Math.asin(var3); - IrisMathHelper.g[var2] = Math.cos(var4); - IrisMathHelper.f[var2] = var4; - } - } } \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/math/M.java b/src/main/java/com/volmit/iris/util/math/M.java index 093d39ff5..6e25a5571 100644 --- a/src/main/java/com/volmit/iris/util/math/M.java +++ b/src/main/java/com/volmit/iris/util/math/M.java @@ -34,6 +34,12 @@ public class M { private static final float[] sin = new float[modulus]; public static int tick = 0; + static { + for (int i = 0; i < sin.length; i++) { + sin[i] = (float) Math.sin((i * Math.PI) / (precision * 180)); + } + } + /** * Scales B by an external range change so that
*
@@ -355,12 +361,6 @@ public class M { return ms / 1000 / 60 / 60 / 24; } - static { - for (int i = 0; i < sin.length; i++) { - sin[i] = (float) Math.sin((i * Math.PI) / (precision * 180)); - } - } - private static float sinLookup(int a) { return a >= 0 ? sin[a % (modulus)] : -sin[-a % (modulus)]; } diff --git a/src/main/java/com/volmit/iris/util/math/MathHelper.java b/src/main/java/com/volmit/iris/util/math/MathHelper.java index b7286e4d6..cf4d70c46 100644 --- a/src/main/java/com/volmit/iris/util/math/MathHelper.java +++ b/src/main/java/com/volmit/iris/util/math/MathHelper.java @@ -29,12 +29,6 @@ import java.util.UUID; import java.util.function.IntPredicate; public class MathHelper { - private static final int h = 1024; - private static final float i = 1024.0F; - private static final long j = 61440L; - private static final long k = 16384L; - private static final long l = -4611686018427387904L; - private static final long m = -9223372036854775808L; public static final float a = 3.1415927F; public static final float b = 1.5707964F; public static final float c = 6.2831855F; @@ -42,6 +36,12 @@ public class MathHelper { public static final float e = 57.295776F; public static final float f = 1.0E-5F; public static final float g = c(2.0F); + private static final int h = 1024; + private static final float i = 1024.0F; + private static final long j = 61440L; + private static final long k = 16384L; + private static final long l = -4611686018427387904L; + private static final long m = -9223372036854775808L; private static final float n = 10430.378F; private static final float[] o = SystemUtils.a(new float[65536], (var0x) -> { for (int var1 = 0; var1 < var0x.length; ++var1) { @@ -58,6 +58,16 @@ public class MathHelper { private static final double[] v = new double[257]; private static final double[] w = new double[257]; + static { + for (int var0 = 0; var0 < 257; ++var0) { + double var1 = (double) var0 / 256.0D; + double var3 = Math.asin(var1); + w[var0] = Math.cos(var3); + v[var0] = var3; + } + + } + public MathHelper() { } @@ -794,14 +804,4 @@ public class MathHelper { public static double a(int var0, double var1, int var3) { return Math.sqrt((double) (var0 * var0) + var1 * var1 + (double) (var3 * var3)); } - - static { - for (int var0 = 0; var0 < 257; ++var0) { - double var1 = (double) var0 / 256.0D; - double var3 = Math.asin(var1); - w[var0] = Math.cos(var3); - v[var0] = var3; - } - - } } \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/math/RNG.java b/src/main/java/com/volmit/iris/util/math/RNG.java index dc7daf220..901d64868 100644 --- a/src/main/java/com/volmit/iris/util/math/RNG.java +++ b/src/main/java/com/volmit/iris/util/math/RNG.java @@ -24,9 +24,9 @@ import java.util.Random; import java.util.UUID; public class RNG extends Random { + public static final RNG r = new RNG(); private static final char[] CHARGEN = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-=!@#$%^&*()_+`~[];',./<>?:\\\"{}|\\\\".toCharArray(); private static final long serialVersionUID = 5222938581174415179L; - public static final RNG r = new RNG(); private final long sx; public RNG() { diff --git a/src/main/java/com/volmit/iris/util/math/RollingSequence.java b/src/main/java/com/volmit/iris/util/math/RollingSequence.java index a4f2e5a0d..76bebd524 100644 --- a/src/main/java/com/volmit/iris/util/math/RollingSequence.java +++ b/src/main/java/com/volmit/iris/util/math/RollingSequence.java @@ -46,14 +46,14 @@ public class RollingSequence extends Average { return f; } - public void setPrecision(boolean p) { - this.precision = p; - } - public boolean isPrecision() { return precision; } + public void setPrecision(boolean p) { + this.precision = p; + } + public double getMin() { if (dirtyExtremes > (isPrecision() ? 0 : values.length)) { resetExtremes(); diff --git a/src/main/java/com/volmit/iris/util/math/Spiraler.java b/src/main/java/com/volmit/iris/util/math/Spiraler.java index a10ea3950..9166218a4 100644 --- a/src/main/java/com/volmit/iris/util/math/Spiraler.java +++ b/src/main/java/com/volmit/iris/util/math/Spiraler.java @@ -20,9 +20,9 @@ package com.volmit.iris.util.math; @SuppressWarnings("EmptyMethod") public class Spiraler { + private final Spiraled spiraled; int x, z, dx, dz, sizeX, sizeZ, t, maxI, i; int ox, oz; - private final Spiraled spiraled; public Spiraler(int sizeX, int sizeZ, Spiraled spiraled) { ox = 0; @@ -31,16 +31,16 @@ public class Spiraler { retarget(sizeX, sizeZ); } + static void Spiral(int X, int Y) { + + } + public void drain() { while (hasNext()) { next(); } } - static void Spiral(int X, int Y) { - - } - public Spiraler setOffset(int ox, int oz) { this.ox = ox; this.oz = oz; diff --git a/src/main/java/com/volmit/iris/util/math/VecMathUtil.java b/src/main/java/com/volmit/iris/util/math/VecMathUtil.java index 8dd50ccc7..fd1f6a61d 100644 --- a/src/main/java/com/volmit/iris/util/math/VecMathUtil.java +++ b/src/main/java/com/volmit/iris/util/math/VecMathUtil.java @@ -23,6 +23,12 @@ package com.volmit.iris.util.math; * objects containing float or double values. This fixes Issue 36. */ class VecMathUtil { + /** + * Do not construct an instance of this class. + */ + private VecMathUtil() { + } + /** * Returns the representation of the specified floating-point * value according to the IEEE 754 floating-point "single format" @@ -78,11 +84,4 @@ class VecMathUtil { return Double.doubleToLongBits(d); } } - - - /** - * Do not construct an instance of this class. - */ - private VecMathUtil() { - } } diff --git a/src/main/java/com/volmit/iris/util/matter/IrisMatter.java b/src/main/java/com/volmit/iris/util/matter/IrisMatter.java index 48412ace9..d52052418 100644 --- a/src/main/java/com/volmit/iris/util/matter/IrisMatter.java +++ b/src/main/java/com/volmit/iris/util/matter/IrisMatter.java @@ -48,6 +48,16 @@ public class IrisMatter implements Matter { this.sliceMap = new KMap<>(); } + private static KMap, MatterSlice> buildSlicers() { + KMap, MatterSlice> c = new KMap<>(); + for (Object i : Iris.initialize("com.volmit.iris.util.matter.slices", Sliced.class)) { + MatterSlice s = (MatterSlice) i; + c.put(s.getType(), s); + } + + return c; + } + @Override public MatterSlice createSlice(Class type, Matter m) { MatterSlice slice = slicers.get(type); @@ -64,14 +74,4 @@ public class IrisMatter implements Matter { return null; } - - private static KMap, MatterSlice> buildSlicers() { - KMap, MatterSlice> c = new KMap<>(); - for (Object i : Iris.initialize("com.volmit.iris.util.matter.slices", Sliced.class)) { - MatterSlice s = (MatterSlice) i; - c.put(s.getType(), s); - } - - return c; - } } diff --git a/src/main/java/com/volmit/iris/util/matter/Matter.java b/src/main/java/com/volmit/iris/util/matter/Matter.java index 893eaef54..1ca0988b3 100644 --- a/src/main/java/com/volmit/iris/util/matter/Matter.java +++ b/src/main/java/com/volmit/iris/util/matter/Matter.java @@ -27,7 +27,14 @@ import org.bukkit.World; import org.bukkit.block.data.BlockData; import org.bukkit.entity.Entity; -import java.io.*; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.Map; import java.util.Set; import java.util.function.Function; @@ -50,6 +57,51 @@ import java.util.function.Function; public interface Matter { int VERSION = 1; + static Matter read(File f) throws IOException, ClassNotFoundException { + FileInputStream in = new FileInputStream(f); + Matter m = read(in); + in.close(); + return m; + } + + static Matter read(InputStream in) throws IOException, ClassNotFoundException { + return read(in, (b) -> new IrisMatter(b.getX(), b.getY(), b.getZ())); + } + + /** + * Reads the input stream into a matter object using a matter factory. + * Does not close the input stream. Be a man, close it yourself. + * + * @param in the input stream + * @param matterFactory the matter factory (size) -> new MatterImpl(size); + * @return the matter object + * @throws IOException shit happens yo + */ + static Matter read(InputStream in, Function matterFactory) throws IOException, ClassNotFoundException { + DataInputStream din = new DataInputStream(in); + Matter matter = matterFactory.apply(new BlockPosition( + Varint.readUnsignedVarInt(din), + Varint.readUnsignedVarInt(din), + Varint.readUnsignedVarInt(din))); + int sliceCount = din.readByte(); + matter.getHeader().read(din); + + while (sliceCount-- > 0) { + String cn = din.readUTF(); + try { + Class type = Class.forName(cn); + MatterSlice slice = matter.createSlice(type, matter); + slice.read(din); + matter.putSlice(type, slice); + } catch (Throwable e) { + e.printStackTrace(); + throw new IOException("Can't read class '" + cn + "' (slice count reverse at " + sliceCount + ")"); + } + } + + return matter; + } + /** * Get the header information * @@ -313,51 +365,6 @@ public interface Matter { } } - static Matter read(File f) throws IOException, ClassNotFoundException { - FileInputStream in = new FileInputStream(f); - Matter m = read(in); - in.close(); - return m; - } - - static Matter read(InputStream in) throws IOException, ClassNotFoundException { - return read(in, (b) -> new IrisMatter(b.getX(), b.getY(), b.getZ())); - } - - /** - * Reads the input stream into a matter object using a matter factory. - * Does not close the input stream. Be a man, close it yourself. - * - * @param in the input stream - * @param matterFactory the matter factory (size) -> new MatterImpl(size); - * @return the matter object - * @throws IOException shit happens yo - */ - static Matter read(InputStream in, Function matterFactory) throws IOException, ClassNotFoundException { - DataInputStream din = new DataInputStream(in); - Matter matter = matterFactory.apply(new BlockPosition( - Varint.readUnsignedVarInt(din), - Varint.readUnsignedVarInt(din), - Varint.readUnsignedVarInt(din))); - int sliceCount = din.readByte(); - matter.getHeader().read(din); - - while (sliceCount-- > 0) { - String cn = din.readUTF(); - try { - Class type = Class.forName(cn); - MatterSlice slice = matter.createSlice(type, matter); - slice.read(din); - matter.putSlice(type, slice); - } catch (Throwable e) { - e.printStackTrace(); - throw new IOException("Can't read class '" + cn + "' (slice count reverse at " + sliceCount + ")"); - } - } - - return matter; - } - default int getTotalCount() { int m = 0; diff --git a/src/main/java/com/volmit/iris/util/matter/slices/CavernMatter.java b/src/main/java/com/volmit/iris/util/matter/slices/CavernMatter.java index 612df6ed6..8ed8cf38c 100644 --- a/src/main/java/com/volmit/iris/util/matter/slices/CavernMatter.java +++ b/src/main/java/com/volmit/iris/util/matter/slices/CavernMatter.java @@ -27,10 +27,6 @@ import java.io.IOException; @Sliced public class CavernMatter extends RawMatter { - public static MatterCavern get(String customBiome, int liquid) { - return new MatterCavern(true, customBiome, (byte) liquid); - } - public CavernMatter() { this(1, 1, 1); } @@ -39,6 +35,10 @@ public class CavernMatter extends RawMatter { super(width, height, depth, MatterCavern.class); } + public static MatterCavern get(String customBiome, int liquid) { + return new MatterCavern(true, customBiome, (byte) liquid); + } + @Override public void writeNode(MatterCavern b, DataOutputStream dos) throws IOException { dos.writeBoolean(b.isCavern()); diff --git a/src/main/java/com/volmit/iris/util/matter/slices/FluidBodyMatter.java b/src/main/java/com/volmit/iris/util/matter/slices/FluidBodyMatter.java index 9354bbcbf..3d12eb428 100644 --- a/src/main/java/com/volmit/iris/util/matter/slices/FluidBodyMatter.java +++ b/src/main/java/com/volmit/iris/util/matter/slices/FluidBodyMatter.java @@ -27,10 +27,6 @@ import java.io.IOException; @Sliced public class FluidBodyMatter extends RawMatter { - public static MatterFluidBody get(String customBiome, boolean lava) { - return new MatterFluidBody(true, customBiome, lava); - } - public FluidBodyMatter() { this(1, 1, 1); } @@ -39,6 +35,10 @@ public class FluidBodyMatter extends RawMatter { super(width, height, depth, MatterFluidBody.class); } + public static MatterFluidBody get(String customBiome, boolean lava) { + return new MatterFluidBody(true, customBiome, lava); + } + @Override public void writeNode(MatterFluidBody b, DataOutputStream dos) throws IOException { dos.writeBoolean(b.isBody()); diff --git a/src/main/java/com/volmit/iris/util/matter/slices/MarkerMatter.java b/src/main/java/com/volmit/iris/util/matter/slices/MarkerMatter.java index 5a23306fa..e5cbd6fc2 100644 --- a/src/main/java/com/volmit/iris/util/matter/slices/MarkerMatter.java +++ b/src/main/java/com/volmit/iris/util/matter/slices/MarkerMatter.java @@ -28,9 +28,9 @@ import java.io.IOException; @Sliced public class MarkerMatter extends RawMatter { - private static final KMap markers = new KMap<>(); public static final MatterMarker CAVE_FLOOR = new MatterMarker("cave_floor"); public static final MatterMarker CAVE_CEILING = new MatterMarker("cave_ceiling"); + private static final KMap markers = new KMap<>(); public MarkerMatter() { this(1, 1, 1); diff --git a/src/main/java/com/volmit/iris/util/matter/slices/RawMatter.java b/src/main/java/com/volmit/iris/util/matter/slices/RawMatter.java index 7566f9c91..d2215217a 100644 --- a/src/main/java/com/volmit/iris/util/matter/slices/RawMatter.java +++ b/src/main/java/com/volmit/iris/util/matter/slices/RawMatter.java @@ -30,10 +30,10 @@ import java.io.DataOutputStream; import java.io.IOException; public abstract class RawMatter extends MappedHunk implements MatterSlice { - @Getter - private final Class type; protected final KMap, MatterWriter> writers; protected final KMap, MatterReader> readers; + @Getter + private final Class type; public RawMatter(int width, int height, int depth, Class type) { super(width, height, depth); diff --git a/src/main/java/com/volmit/iris/util/nbt/io/NBTInputStream.java b/src/main/java/com/volmit/iris/util/nbt/io/NBTInputStream.java index 1d60bc28a..59e12d1e9 100644 --- a/src/main/java/com/volmit/iris/util/nbt/io/NBTInputStream.java +++ b/src/main/java/com/volmit/iris/util/nbt/io/NBTInputStream.java @@ -20,7 +20,20 @@ package com.volmit.iris.util.nbt.io; import com.volmit.iris.engine.data.io.ExceptionBiFunction; import com.volmit.iris.engine.data.io.MaxDepthIO; -import com.volmit.iris.util.nbt.tag.*; +import com.volmit.iris.util.nbt.tag.ByteArrayTag; +import com.volmit.iris.util.nbt.tag.ByteTag; +import com.volmit.iris.util.nbt.tag.CompoundTag; +import com.volmit.iris.util.nbt.tag.DoubleTag; +import com.volmit.iris.util.nbt.tag.EndTag; +import com.volmit.iris.util.nbt.tag.FloatTag; +import com.volmit.iris.util.nbt.tag.IntArrayTag; +import com.volmit.iris.util.nbt.tag.IntTag; +import com.volmit.iris.util.nbt.tag.ListTag; +import com.volmit.iris.util.nbt.tag.LongArrayTag; +import com.volmit.iris.util.nbt.tag.LongTag; +import com.volmit.iris.util.nbt.tag.ShortTag; +import com.volmit.iris.util.nbt.tag.StringTag; +import com.volmit.iris.util.nbt.tag.Tag; import java.io.DataInputStream; import java.io.IOException; @@ -49,31 +62,13 @@ public class NBTInputStream extends DataInputStream implements MaxDepthIO { put(LongArrayTag.ID, (i, d) -> readLongArray(i), LongArrayTag.class); } - private static void put(byte id, ExceptionBiFunction, IOException> reader, Class clazz) { - readers.put(id, reader); - idClassMapping.put(id, clazz); - } - public NBTInputStream(InputStream in) { super(in); } - public NamedTag readTag(int maxDepth) throws IOException { - byte id = readByte(); - return new NamedTag(readUTF(), readTag(id, maxDepth)); - } - - public Tag readRawTag(int maxDepth) throws IOException { - byte id = readByte(); - return readTag(id, maxDepth); - } - - private Tag readTag(byte type, int maxDepth) throws IOException { - ExceptionBiFunction, IOException> f; - if ((f = readers.get(type)) == null) { - throw new IOException("invalid tag id \"" + type + "\""); - } - return f.accept(this, maxDepth); + private static void put(byte id, ExceptionBiFunction, IOException> reader, Class clazz) { + readers.put(id, reader); + idClassMapping.put(id, clazz); } private static ByteTag readByte(NBTInputStream in) throws IOException { @@ -152,4 +147,22 @@ public class NBTInputStream extends DataInputStream implements MaxDepthIO { } return comp; } + + public NamedTag readTag(int maxDepth) throws IOException { + byte id = readByte(); + return new NamedTag(readUTF(), readTag(id, maxDepth)); + } + + public Tag readRawTag(int maxDepth) throws IOException { + byte id = readByte(); + return readTag(id, maxDepth); + } + + private Tag readTag(byte type, int maxDepth) throws IOException { + ExceptionBiFunction, IOException> f; + if ((f = readers.get(type)) == null) { + throw new IOException("invalid tag id \"" + type + "\""); + } + return f.accept(this, maxDepth); + } } diff --git a/src/main/java/com/volmit/iris/util/nbt/io/NBTOutputStream.java b/src/main/java/com/volmit/iris/util/nbt/io/NBTOutputStream.java index 79e1e9599..fe6fdc6e9 100644 --- a/src/main/java/com/volmit/iris/util/nbt/io/NBTOutputStream.java +++ b/src/main/java/com/volmit/iris/util/nbt/io/NBTOutputStream.java @@ -20,7 +20,20 @@ package com.volmit.iris.util.nbt.io; import com.volmit.iris.engine.data.io.ExceptionTriConsumer; import com.volmit.iris.engine.data.io.MaxDepthIO; -import com.volmit.iris.util.nbt.tag.*; +import com.volmit.iris.util.nbt.tag.ByteArrayTag; +import com.volmit.iris.util.nbt.tag.ByteTag; +import com.volmit.iris.util.nbt.tag.CompoundTag; +import com.volmit.iris.util.nbt.tag.DoubleTag; +import com.volmit.iris.util.nbt.tag.EndTag; +import com.volmit.iris.util.nbt.tag.FloatTag; +import com.volmit.iris.util.nbt.tag.IntArrayTag; +import com.volmit.iris.util.nbt.tag.IntTag; +import com.volmit.iris.util.nbt.tag.ListTag; +import com.volmit.iris.util.nbt.tag.LongArrayTag; +import com.volmit.iris.util.nbt.tag.LongTag; +import com.volmit.iris.util.nbt.tag.ShortTag; +import com.volmit.iris.util.nbt.tag.StringTag; +import com.volmit.iris.util.nbt.tag.Tag; import java.io.DataOutputStream; import java.io.IOException; @@ -50,37 +63,13 @@ public class NBTOutputStream extends DataOutputStream implements MaxDepthIO { put(LongArrayTag.ID, (o, t, d) -> writeLongArray(o, t), LongArrayTag.class); } - private static void put(byte id, ExceptionTriConsumer, Integer, IOException> f, Class clazz) { - writers.put(id, f); - classIdMapping.put(clazz, id); - } - public NBTOutputStream(OutputStream out) { super(out); } - public void writeTag(NamedTag tag, int maxDepth) throws IOException { - writeByte(tag.getTag().getID()); - if (tag.getTag().getID() != 0) { - writeUTF(tag.getName() == null ? "" : tag.getName()); - } - writeRawTag(tag.getTag(), maxDepth); - } - - public void writeTag(Tag tag, int maxDepth) throws IOException { - writeByte(tag.getID()); - if (tag.getID() != 0) { - writeUTF(""); - } - writeRawTag(tag, maxDepth); - } - - public void writeRawTag(Tag tag, int maxDepth) throws IOException { - ExceptionTriConsumer, Integer, IOException> f; - if ((f = writers.get(tag.getID())) == null) { - throw new IOException("invalid tag \"" + tag.getID() + "\""); - } - f.accept(this, tag, maxDepth); + private static void put(byte id, ExceptionTriConsumer, Integer, IOException> f, Class clazz) { + writers.put(id, f); + classIdMapping.put(clazz, id); } static byte idFromClass(Class clazz) { @@ -157,4 +146,28 @@ public class NBTOutputStream extends DataOutputStream implements MaxDepthIO { } out.writeByte(0); } + + public void writeTag(NamedTag tag, int maxDepth) throws IOException { + writeByte(tag.getTag().getID()); + if (tag.getTag().getID() != 0) { + writeUTF(tag.getName() == null ? "" : tag.getName()); + } + writeRawTag(tag.getTag(), maxDepth); + } + + public void writeTag(Tag tag, int maxDepth) throws IOException { + writeByte(tag.getID()); + if (tag.getID() != 0) { + writeUTF(""); + } + writeRawTag(tag, maxDepth); + } + + public void writeRawTag(Tag tag, int maxDepth) throws IOException { + ExceptionTriConsumer, Integer, IOException> f; + if ((f = writers.get(tag.getID())) == null) { + throw new IOException("invalid tag \"" + tag.getID() + "\""); + } + f.accept(this, tag, maxDepth); + } } diff --git a/src/main/java/com/volmit/iris/util/nbt/io/NBTUtil.java b/src/main/java/com/volmit/iris/util/nbt/io/NBTUtil.java index ff11d6d59..66458a911 100644 --- a/src/main/java/com/volmit/iris/util/nbt/io/NBTUtil.java +++ b/src/main/java/com/volmit/iris/util/nbt/io/NBTUtil.java @@ -20,7 +20,13 @@ package com.volmit.iris.util.nbt.io; import com.volmit.iris.util.nbt.tag.Tag; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PushbackInputStream; import java.util.zip.GZIPInputStream; public final class NBTUtil { diff --git a/src/main/java/com/volmit/iris/util/nbt/io/NamedTag.java b/src/main/java/com/volmit/iris/util/nbt/io/NamedTag.java index 5b4f4150b..acd484a98 100644 --- a/src/main/java/com/volmit/iris/util/nbt/io/NamedTag.java +++ b/src/main/java/com/volmit/iris/util/nbt/io/NamedTag.java @@ -30,19 +30,19 @@ public class NamedTag { this.tag = tag; } - public void setName(String name) { - this.name = name; - } - - public void setTag(Tag tag) { - this.tag = tag; - } - public String getName() { return name; } + public void setName(String name) { + this.name = name; + } + public Tag getTag() { return tag; } + + public void setTag(Tag tag) { + this.tag = tag; + } } diff --git a/src/main/java/com/volmit/iris/util/nbt/io/SNBTParser.java b/src/main/java/com/volmit/iris/util/nbt/io/SNBTParser.java index b0fcec6cd..affecc4e1 100644 --- a/src/main/java/com/volmit/iris/util/nbt/io/SNBTParser.java +++ b/src/main/java/com/volmit/iris/util/nbt/io/SNBTParser.java @@ -20,7 +20,21 @@ package com.volmit.iris.util.nbt.io; import com.volmit.iris.Iris; import com.volmit.iris.engine.data.io.MaxDepthIO; -import com.volmit.iris.util.nbt.tag.*; +import com.volmit.iris.util.nbt.tag.ArrayTag; +import com.volmit.iris.util.nbt.tag.ByteArrayTag; +import com.volmit.iris.util.nbt.tag.ByteTag; +import com.volmit.iris.util.nbt.tag.CompoundTag; +import com.volmit.iris.util.nbt.tag.DoubleTag; +import com.volmit.iris.util.nbt.tag.EndTag; +import com.volmit.iris.util.nbt.tag.FloatTag; +import com.volmit.iris.util.nbt.tag.IntArrayTag; +import com.volmit.iris.util.nbt.tag.IntTag; +import com.volmit.iris.util.nbt.tag.ListTag; +import com.volmit.iris.util.nbt.tag.LongArrayTag; +import com.volmit.iris.util.nbt.tag.LongTag; +import com.volmit.iris.util.nbt.tag.ShortTag; +import com.volmit.iris.util.nbt.tag.StringTag; +import com.volmit.iris.util.nbt.tag.Tag; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/com/volmit/iris/util/nbt/io/SNBTWriter.java b/src/main/java/com/volmit/iris/util/nbt/io/SNBTWriter.java index 0bae8a7f3..2d0f44f63 100644 --- a/src/main/java/com/volmit/iris/util/nbt/io/SNBTWriter.java +++ b/src/main/java/com/volmit/iris/util/nbt/io/SNBTWriter.java @@ -19,7 +19,20 @@ package com.volmit.iris.util.nbt.io; import com.volmit.iris.engine.data.io.MaxDepthIO; -import com.volmit.iris.util.nbt.tag.*; +import com.volmit.iris.util.nbt.tag.ByteArrayTag; +import com.volmit.iris.util.nbt.tag.ByteTag; +import com.volmit.iris.util.nbt.tag.CompoundTag; +import com.volmit.iris.util.nbt.tag.DoubleTag; +import com.volmit.iris.util.nbt.tag.EndTag; +import com.volmit.iris.util.nbt.tag.FloatTag; +import com.volmit.iris.util.nbt.tag.IntArrayTag; +import com.volmit.iris.util.nbt.tag.IntTag; +import com.volmit.iris.util.nbt.tag.ListTag; +import com.volmit.iris.util.nbt.tag.LongArrayTag; +import com.volmit.iris.util.nbt.tag.LongTag; +import com.volmit.iris.util.nbt.tag.ShortTag; +import com.volmit.iris.util.nbt.tag.StringTag; +import com.volmit.iris.util.nbt.tag.Tag; import java.io.IOException; import java.io.Writer; @@ -49,6 +62,23 @@ public final class SNBTWriter implements MaxDepthIO { write(tag, writer, Tag.DEFAULT_MAX_DEPTH); } + public static String escapeString(String s) { + if (!NON_QUOTE_PATTERN.matcher(s).matches()) { + StringBuilder sb = new StringBuilder(); + sb.append('"'); + for (int i = 0; i < s.length(); i++) { + char c = s.charAt(i); + if (c == '\\' || c == '"') { + sb.append('\\'); + } + sb.append(c); + } + sb.append('"'); + return sb.toString(); + } + return s; + } + private void writeAnything(Tag tag, int maxDepth) throws IOException { switch (tag.getID()) { case EndTag.ID: @@ -115,21 +145,4 @@ public final class SNBTWriter implements MaxDepthIO { } writer.write(']'); } - - public static String escapeString(String s) { - if (!NON_QUOTE_PATTERN.matcher(s).matches()) { - StringBuilder sb = new StringBuilder(); - sb.append('"'); - for (int i = 0; i < s.length(); i++) { - char c = s.charAt(i); - if (c == '\\' || c == '"') { - sb.append('\\'); - } - sb.append(c); - } - sb.append('"'); - return sb.toString(); - } - return s; - } } diff --git a/src/main/java/com/volmit/iris/util/nbt/io/StringPointer.java b/src/main/java/com/volmit/iris/util/nbt/io/StringPointer.java index 9978d6516..02227d9f6 100644 --- a/src/main/java/com/volmit/iris/util/nbt/io/StringPointer.java +++ b/src/main/java/com/volmit/iris/util/nbt/io/StringPointer.java @@ -27,6 +27,16 @@ public class StringPointer { this.value = value; } + private static boolean isSimpleChar(char c) { + return c >= 'a' && c <= 'z' + || c >= 'A' && c <= 'Z' + || c >= '0' && c <= '9' + || c == '-' + || c == '+' + || c == '.' + || c == '_'; + } + public String parseSimpleString() { int oldIndex = index; while (hasNext() && isSimpleChar(currentChar())) { @@ -117,16 +127,6 @@ public class StringPointer { return value.charAt(index + offset); } - private static boolean isSimpleChar(char c) { - return c >= 'a' && c <= 'z' - || c >= 'A' && c <= 'Z' - || c >= '0' && c <= '9' - || c == '-' - || c == '+' - || c == '.' - || c == '_'; - } - public ParseException parseException(String msg) { return new ParseException(msg, value, index); } diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/Chunk.java b/src/main/java/com/volmit/iris/util/nbt/mca/Chunk.java index 85ee8d4b3..0d25721d3 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/Chunk.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/Chunk.java @@ -27,13 +27,19 @@ import com.volmit.iris.util.nbt.mca.palette.BiomeContainer; import com.volmit.iris.util.nbt.tag.CompoundTag; import com.volmit.iris.util.nbt.tag.ListTag; -import java.io.*; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.RandomAccessFile; import java.util.concurrent.atomic.AtomicReferenceArray; import static com.volmit.iris.util.nbt.mca.LoadFlags.*; public class Chunk { public static final int DEFAULT_DATA_VERSION = 2730; + private final AtomicReferenceArray
sections = new AtomicReferenceArray<>(16); private boolean partial; private int lastMCAUpdate; private CompoundTag data; @@ -43,7 +49,6 @@ public class Chunk { private BiomeContainer biomes; private CompoundTag heightMaps; private CompoundTag carvingMasks; - private final AtomicReferenceArray
sections = new AtomicReferenceArray<>(16); private ListTag entities; private ListTag tileEntities; private ListTag tileTicks; @@ -70,6 +75,23 @@ public class Chunk { setStatus("full"); } + public static Chunk newChunk() { + Chunk c = new Chunk(0); + c.dataVersion = DEFAULT_DATA_VERSION; + c.data = new CompoundTag(); + c.biomes = INMS.get().newBiomeContainer(0, 256); + c.data.put("Level", defaultLevel()); + c.status = "full"; + return c; + } + + private static CompoundTag defaultLevel() { + CompoundTag level = new CompoundTag(); + level.putString("Status", "full"); + level.putString("Generator", "Iris Headless " + Iris.instance.getDescription().getVersion()); + return level; + } + private void initReferences(long loadFlags) { if (data == null) { throw new NullPointerException("data cannot be null"); @@ -550,23 +572,6 @@ public class Chunk { } } - public static Chunk newChunk() { - Chunk c = new Chunk(0); - c.dataVersion = DEFAULT_DATA_VERSION; - c.data = new CompoundTag(); - c.biomes = INMS.get().newBiomeContainer(0, 256); - c.data.put("Level", defaultLevel()); - c.status = "full"; - return c; - } - - private static CompoundTag defaultLevel() { - CompoundTag level = new CompoundTag(); - level.putString("Status", "full"); - level.putString("Generator", "Iris Headless " + Iris.instance.getDescription().getVersion()); - return level; - } - public CompoundTag updateHandle(int xPos, int zPos) { data.putInt("DataVersion", dataVersion); CompoundTag level = data.getCompoundTag("Level"); diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/CompressionType.java b/src/main/java/com/volmit/iris/util/nbt/mca/CompressionType.java index 07388e9ee..e73480c5d 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/CompressionType.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/CompressionType.java @@ -44,6 +44,15 @@ public enum CompressionType { this.decompressor = decompressor; } + public static CompressionType getFromID(byte id) { + for (CompressionType c : CompressionType.values()) { + if (c.id == id) { + return c; + } + } + return null; + } + public byte getID() { return id; } @@ -55,13 +64,4 @@ public enum CompressionType { public InputStream decompress(InputStream in) throws IOException { return decompressor.accept(in); } - - public static CompressionType getFromID(byte id) { - for (CompressionType c : CompressionType.values()) { - if (c.id == id) { - return c; - } - } - return null; - } } diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/MCAFile.java b/src/main/java/com/volmit/iris/util/nbt/mca/MCAFile.java index c8c7986c6..c2ba0ae87 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/MCAFile.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/MCAFile.java @@ -52,6 +52,18 @@ public class MCAFile { this.regionZ = regionZ; } + /** + * Calculates the index of a chunk from its x- and z-coordinates in this region. + * This works with absolute and relative coordinates. + * + * @param chunkX The x-coordinate of the chunk. + * @param chunkZ The z-coordinate of the chunk. + * @return The index of this chunk. + */ + public static int getChunkIndex(int chunkX, int chunkZ) { + return (chunkX & 0x1F) + (chunkZ & 0x1F) * 32; + } + /** * Reads an .mca file from a {@code RandomAccessFile} into this object. * This method does not perform any cleanups on the data. @@ -245,18 +257,6 @@ public class MCAFile { return getChunk(chunkX, chunkZ) != null; } - /** - * Calculates the index of a chunk from its x- and z-coordinates in this region. - * This works with absolute and relative coordinates. - * - * @param chunkX The x-coordinate of the chunk. - * @param chunkZ The z-coordinate of the chunk. - * @return The index of this chunk. - */ - public static int getChunkIndex(int chunkX, int chunkZ) { - return (chunkX & 0x1F) + (chunkZ & 0x1F) * 32; - } - private int checkIndex(int index) { if (index < 0 || index > 1023) { throw new IndexOutOfBoundsException(); diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/MCAUtil.java b/src/main/java/com/volmit/iris/util/nbt/mca/MCAUtil.java index b06d3c0ab..d2240fbd8 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/MCAUtil.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/MCAUtil.java @@ -35,6 +35,8 @@ import java.util.regex.Pattern; */ public final class MCAUtil { + private static final Pattern mcaFilePattern = Pattern.compile("^.*r\\.(?-?\\d+)\\.(?-?\\d+)\\.mca$"); + private MCAUtil() { } @@ -259,8 +261,6 @@ public final class MCAUtil { return chunk << 4; } - private static final Pattern mcaFilePattern = Pattern.compile("^.*r\\.(?-?\\d+)\\.(?-?\\d+)\\.mca$"); - public static MCAFile newMCAFile(File file) { Matcher m = mcaFilePattern.matcher(file.getName()); if (m.find()) { diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/NBTWorld.java b/src/main/java/com/volmit/iris/util/nbt/mca/NBTWorld.java index 7bda6369d..8bd01c6b5 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/NBTWorld.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/NBTWorld.java @@ -89,6 +89,49 @@ public class NBTWorld { }); } + public static BlockData getBlockData(CompoundTag tag) { + if (tag == null) { + return B.getAir(); + } + + StringBuilder p = new StringBuilder(tag.getString("Name")); + + if (tag.containsKey("Properties")) { + CompoundTag props = tag.getCompoundTag("Properties"); + p.append('['); + + for (String i : props.keySet()) { + p.append(i).append('=').append(props.getString(i)).append(','); + } + + p.deleteCharAt(p.length() - 1).append(']'); + } + + BlockData b = B.getOrNull(p.toString()); + + if (b == null) { + return B.getAir(); + } + + return b; + } + + public static CompoundTag getCompound(BlockData bd) { + return blockDataCache.computeIfAbsent(bd, BLOCK_DATA_COMPUTE).clone(); + } + + private static Map computeBiomeIDs() { + Map biomeIds = new KMap<>(); + + for (Biome biome : Biome.values()) { + if (!biome.name().equals("CUSTOM")) { + biomeIds.put(biome, INMS.get().getBiomeId(biome)); + } + } + + return biomeIds; + } + public void close() { for (Long i : loadedRegions.k()) { @@ -184,37 +227,6 @@ public class NBTWorld { return new File(worldFolder, "region/r." + x + "." + z + ".mca"); } - public static BlockData getBlockData(CompoundTag tag) { - if (tag == null) { - return B.getAir(); - } - - StringBuilder p = new StringBuilder(tag.getString("Name")); - - if (tag.containsKey("Properties")) { - CompoundTag props = tag.getCompoundTag("Properties"); - p.append('['); - - for (String i : props.keySet()) { - p.append(i).append('=').append(props.getString(i)).append(','); - } - - p.deleteCharAt(p.length() - 1).append(']'); - } - - BlockData b = B.getOrNull(p.toString()); - - if (b == null) { - return B.getAir(); - } - - return b; - } - - public static CompoundTag getCompound(BlockData bd) { - return blockDataCache.computeIfAbsent(bd, BLOCK_DATA_COMPUTE).clone(); - } - public BlockData getBlockData(int x, int y, int z) { try { CompoundTag tag = getChunkSection(x >> 4, y >> 4, z >> 4).getBlockStateAt(x & 15, y & 15, z & 15); @@ -317,16 +329,4 @@ public class NBTWorld { public int size() { return loadedRegions.size(); } - - private static Map computeBiomeIDs() { - Map biomeIds = new KMap<>(); - - for (Biome biome : Biome.values()) { - if (!biome.name().equals("CUSTOM")) { - biomeIds.put(biome, INMS.get().getBiomeId(biome)); - } - } - - return biomeIds; - } } diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/Section.java b/src/main/java/com/volmit/iris/util/nbt/mca/Section.java index 12817eea4..8e193bb99 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/Section.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/Section.java @@ -54,6 +54,18 @@ public class Section { Section() { } + /** + * Creates an empty Section with base values. + * + * @return An empty Section + */ + public static Section newSection() { + Section s = new Section(); + s.data = new CompoundTag(); + s.palette = INMS.get().createPalette(); + return s; + } + /** * Checks whether the data of this Section is empty. * @@ -141,18 +153,6 @@ public class Section { this.skyLight = skyLight; } - /** - * Creates an empty Section with base values. - * - * @return An empty Section - */ - public static Section newSection() { - Section s = new Section(); - s.data = new CompoundTag(); - s.palette = INMS.get().createPalette(); - return s; - } - /** * Updates the raw CompoundTag that this Section is based on. * This must be called before saving a Section to disk if the Section was manually created diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palette/IdMapper.java b/src/main/java/com/volmit/iris/util/nbt/mca/palette/IdMapper.java index b9c289ebc..d53bd1a43 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/palette/IdMapper.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palette/IdMapper.java @@ -28,12 +28,9 @@ import java.util.List; public class IdMapper implements IdMap { public static final int DEFAULT = -1; - - private int nextId; - private final IdentityHashMap tToId; - private final List idToT; + private int nextId; public IdMapper(IdentityHashMap tToId, List idToT, int nextId) { this.tToId = tToId; diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palette/Mth.java b/src/main/java/com/volmit/iris/util/nbt/mca/palette/Mth.java index 9eb5a683c..6b8dd7603 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/palette/Mth.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palette/Mth.java @@ -24,35 +24,34 @@ import java.util.function.Consumer; import java.util.function.Supplier; public class Mth { - private static final int BIG_ENOUGH_INT = 1024; - - private static final float BIG_ENOUGH_FLOAT = 1024.0F; - - private static final long UUID_VERSION = 61440L; - - private static final long UUID_VERSION_TYPE_4 = 16384L; - - private static final long UUID_VARIANT = -4611686018427387904L; - - private static final long UUID_VARIANT_2 = -9223372036854775808L; - public static final float PI = 3.1415927F; - public static final float HALF_PI = 1.5707964F; - public static final float TWO_PI = 6.2831855F; - public static final float DEG_TO_RAD = 0.017453292F; - public static final float RAD_TO_DEG = 57.295776F; - public static final float EPSILON = 1.0E-5F; - public static final float SQRT_OF_TWO = sqrt(2.0F); - + private static final int BIG_ENOUGH_INT = 1024; + private static final float BIG_ENOUGH_FLOAT = 1024.0F; + private static final long UUID_VERSION = 61440L; + private static final long UUID_VERSION_TYPE_4 = 16384L; + private static final long UUID_VARIANT = -4611686018427387904L; + private static final long UUID_VARIANT_2 = -9223372036854775808L; private static final float SIN_SCALE = 10430.378F; private static final float[] SIN; + private static final Random RANDOM = new Random(); + private static final int[] MULTIPLY_DE_BRUIJN_BIT_POSITION = new int[]{ + 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, + 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, + 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, + 10, 9}; + private static final double ONE_SIXTH = 0.16666666666666666D; + private static final int FRAC_EXP = 8; + private static final int LUT_SIZE = 257; + private static final double FRAC_BIAS = Double.longBitsToDouble(4805340802404319232L); + private static final double[] ASIN_TAB = new double[257]; + private static final double[] COS_TAB = new double[257]; static { SIN = make(new float[65536], var0 -> { @@ -61,6 +60,15 @@ public class Mth { }); } + static { + for (int var0 = 0; var0 < 257; var0++) { + double var1 = var0 / 256.0D; + double var3 = Math.asin(var1); + COS_TAB[var0] = Math.cos(var3); + ASIN_TAB[var0] = var3; + } + } + public static T make(Supplier var0) { return var0.get(); } @@ -70,8 +78,6 @@ public class Mth { return var0; } - private static final Random RANDOM = new Random(); - public static float sin(float var0) { return SIN[(int) (var0 * 10430.378F) & 0xFFFF]; } @@ -325,18 +331,6 @@ public class Mth { return (var0 != 0 && (var0 & var0 - 1) == 0); } - private static final int[] MULTIPLY_DE_BRUIJN_BIT_POSITION = new int[]{ - 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, - 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, - 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, - 10, 9}; - - private static final double ONE_SIXTH = 0.16666666666666666D; - - private static final int FRAC_EXP = 8; - - private static final int LUT_SIZE = 257; - public static int ceillog2(int var0) { var0 = isPowerOfTwo(var0) ? var0 : smallestEncompassingPowerOfTwo(var0); return MULTIPLY_DE_BRUIJN_BIT_POSITION[(int) (var0 * 125613361L >> 27L) & 0x1F]; @@ -471,21 +465,6 @@ public class Mth { return var2; } - private static final double FRAC_BIAS = Double.longBitsToDouble(4805340802404319232L); - - private static final double[] ASIN_TAB = new double[257]; - - private static final double[] COS_TAB = new double[257]; - - static { - for (int var0 = 0; var0 < 257; var0++) { - double var1 = var0 / 256.0D; - double var3 = Math.asin(var1); - COS_TAB[var0] = Math.cos(var3); - ASIN_TAB[var0] = var3; - } - } - public static int hsvToRgb(float var0, float var1, float var2) { float var8, var9, var10; int var11, var12, var13, var3 = (int) (var0 * 6.0F) % 6; diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palette/PalettedContainer.java b/src/main/java/com/volmit/iris/util/nbt/mca/palette/PalettedContainer.java index 86218ee53..2b1ce16fe 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/palette/PalettedContainer.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palette/PalettedContainer.java @@ -26,12 +26,9 @@ import java.util.function.Function; import java.util.function.Predicate; public class PalettedContainer implements PaletteResize { - private static final int SIZE = 4096; - public static final int GLOBAL_PALETTE_BITS = 9; - public static final int MIN_PALETTE_SIZE = 4; - + private static final int SIZE = 4096; private final Palette globalPalette; private final PaletteResize dummyPaletteResize = (var0, var1) -> 0; diff --git a/src/main/java/com/volmit/iris/util/nbt/tag/CompoundTag.java b/src/main/java/com/volmit/iris/util/nbt/tag/CompoundTag.java index 806c79ab7..68bd945cf 100644 --- a/src/main/java/com/volmit/iris/util/nbt/tag/CompoundTag.java +++ b/src/main/java/com/volmit/iris/util/nbt/tag/CompoundTag.java @@ -21,7 +21,11 @@ package com.volmit.iris.util.nbt.tag; import com.volmit.iris.engine.data.io.MaxDepthIO; import com.volmit.iris.util.collection.KMap; -import java.util.*; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; +import java.util.Objects; +import java.util.Set; import java.util.function.BiConsumer; @SuppressWarnings("ALL") @@ -33,15 +37,15 @@ public class CompoundTag extends Tag>> implements Iterable> createEmptyValue() { + return new KMap<>(); + } + @Override public byte getID() { return ID; } - private static Map> createEmptyValue() { - return new KMap<>(); - } - public int size() { return getValue().size(); } diff --git a/src/main/java/com/volmit/iris/util/nbt/tag/ListTag.java b/src/main/java/com/volmit/iris/util/nbt/tag/ListTag.java index 2bd18df08..1242619fe 100644 --- a/src/main/java/com/volmit/iris/util/nbt/tag/ListTag.java +++ b/src/main/java/com/volmit/iris/util/nbt/tag/ListTag.java @@ -21,7 +21,11 @@ package com.volmit.iris.util.nbt.tag; import com.volmit.iris.engine.data.io.MaxDepthIO; import com.volmit.iris.util.collection.KList; -import java.util.*; +import java.util.Collection; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.Objects; import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.Consumer; @@ -43,14 +47,17 @@ public class ListTag> extends Tag> implements Iterable< super(createEmptyValue(3)); } - public ListTag makeAtomic() { - setValue(new CopyOnWriteArrayList<>(getValue())); - return this; - } - - @Override - public byte getID() { - return ID; + /** + * @param typeClass The exact class of the elements + * @throws IllegalArgumentException When {@code typeClass} is {@link EndTag}{@code .class} + * @throws NullPointerException When {@code typeClass} is {@code null} + */ + public ListTag(Class typeClass) throws IllegalArgumentException, NullPointerException { + super(createEmptyValue(3)); + if (typeClass == EndTag.class) { + throw new IllegalArgumentException("cannot create ListTag with EndTag elements"); + } + this.typeClass = Objects.requireNonNull(typeClass); } /** @@ -79,17 +86,14 @@ public class ListTag> extends Tag> implements Iterable< return new KList<>(initialCapacity); } - /** - * @param typeClass The exact class of the elements - * @throws IllegalArgumentException When {@code typeClass} is {@link EndTag}{@code .class} - * @throws NullPointerException When {@code typeClass} is {@code null} - */ - public ListTag(Class typeClass) throws IllegalArgumentException, NullPointerException { - super(createEmptyValue(3)); - if (typeClass == EndTag.class) { - throw new IllegalArgumentException("cannot create ListTag with EndTag elements"); - } - this.typeClass = Objects.requireNonNull(typeClass); + public ListTag makeAtomic() { + setValue(new CopyOnWriteArrayList<>(getValue())); + return this; + } + + @Override + public byte getID() { + return ID; } public Class getTypeClass() { diff --git a/src/main/java/com/volmit/iris/util/nbt/tag/Tag.java b/src/main/java/com/volmit/iris/util/nbt/tag/Tag.java index f4faf2a9f..8d3748f49 100644 --- a/src/main/java/com/volmit/iris/util/nbt/tag/Tag.java +++ b/src/main/java/com/volmit/iris/util/nbt/tag/Tag.java @@ -59,6 +59,8 @@ public abstract class Tag implements Cloneable { public static final int DEFAULT_MAX_DEPTH = 512; private static final Map ESCAPE_CHARACTERS; + private static final Pattern ESCAPE_PATTERN = Pattern.compile("[\\\\\n\t\r\"]"); + private static final Pattern NON_QUOTE_PATTERN = Pattern.compile("[a-zA-Z0-9_\\-+]+"); static { final Map temp = new HashMap<>(); @@ -71,9 +73,6 @@ public abstract class Tag implements Cloneable { ESCAPE_CHARACTERS = Collections.unmodifiableMap(temp); } - private static final Pattern ESCAPE_PATTERN = Pattern.compile("[\\\\\n\t\r\"]"); - private static final Pattern NON_QUOTE_PATTERN = Pattern.compile("[a-zA-Z0-9_\\-+]+"); - private T value; /** @@ -86,6 +85,30 @@ public abstract class Tag implements Cloneable { setValue(value); } + /** + * Escapes a string to fit into a JSON-like string representation for Minecraft + * or to create the JSON string representation of a Tag returned from {@link Tag#toString()} + * + * @param s The string to be escaped. + * @param lenient {@code true} if it should force double quotes ({@code "}) at the start and + * the end of the string. + * @return The escaped string. + */ + @SuppressWarnings("StringBufferMayBeStringBuilder") + protected static String escapeString(String s, @SuppressWarnings("SameParameterValue") boolean lenient) { + StringBuffer sb = new StringBuffer(); + Matcher m = ESCAPE_PATTERN.matcher(s); + while (m.find()) { + m.appendReplacement(sb, ESCAPE_CHARACTERS.get(m.group())); + } + m.appendTail(sb); + m = NON_QUOTE_PATTERN.matcher(s); + if (!lenient || !m.matches()) { + sb.insert(0, "\"").append("\""); + } + return sb.toString(); + } + /** * @return This Tag's ID, usually used for serialization and deserialization. */ @@ -192,28 +215,4 @@ public abstract class Tag implements Cloneable { * @return A clone of this Tag. */ public abstract Tag clone(); - - /** - * Escapes a string to fit into a JSON-like string representation for Minecraft - * or to create the JSON string representation of a Tag returned from {@link Tag#toString()} - * - * @param s The string to be escaped. - * @param lenient {@code true} if it should force double quotes ({@code "}) at the start and - * the end of the string. - * @return The escaped string. - */ - @SuppressWarnings("StringBufferMayBeStringBuilder") - protected static String escapeString(String s, @SuppressWarnings("SameParameterValue") boolean lenient) { - StringBuffer sb = new StringBuffer(); - Matcher m = ESCAPE_PATTERN.matcher(s); - while (m.find()) { - m.appendReplacement(sb, ESCAPE_CHARACTERS.get(m.group())); - } - m.appendTail(sb); - m = NON_QUOTE_PATTERN.matcher(s); - if (!lenient || !m.matches()) { - sb.insert(0, "\"").append("\""); - } - return sb.toString(); - } } diff --git a/src/main/java/com/volmit/iris/util/network/DL.java b/src/main/java/com/volmit/iris/util/network/DL.java index e81286edc..bca5ff472 100644 --- a/src/main/java/com/volmit/iris/util/network/DL.java +++ b/src/main/java/com/volmit/iris/util/network/DL.java @@ -22,7 +22,12 @@ import com.volmit.iris.util.collection.KSet; import com.volmit.iris.util.io.IO; import com.volmit.iris.util.scheduling.ChronoLatch; -import java.io.*; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; import java.net.URL; import java.net.URLConnection; diff --git a/src/main/java/com/volmit/iris/util/noise/CNG.java b/src/main/java/com/volmit/iris/util/noise/CNG.java index 20a657190..962e79ecd 100644 --- a/src/main/java/com/volmit/iris/util/noise/CNG.java +++ b/src/main/java/com/volmit/iris/util/noise/CNG.java @@ -33,8 +33,6 @@ import java.util.List; @Data public class CNG { - public static long hits = 0; - public static long creates = 0; public static final NoiseInjector ADD = (s, v) -> new double[]{s + v, 1}; public static final NoiseInjector SRC_SUBTRACT = (s, v) -> new double[]{s - v < 0 ? 0 : s - v, -1}; public static final NoiseInjector DST_SUBTRACT = (s, v) -> new double[]{v - s < 0 ? 0 : s - v, -1}; @@ -45,6 +43,9 @@ public class CNG { public static final NoiseInjector SRC_POW = (s, v) -> new double[]{Math.pow(s, v), 0}; public static final NoiseInjector DST_MOD = (s, v) -> new double[]{v % s, 0}; public static final NoiseInjector DST_POW = (s, v) -> new double[]{Math.pow(v, s), 0}; + public static long hits = 0; + public static long creates = 0; + private final double opacity; private double scale; private double bakedScale; private double fscale; @@ -52,7 +53,6 @@ public class CNG { private KList children; private CNG fracture; private NoiseGenerator generator; - private final double opacity; private NoiseInjector injector; private RNG rng; private boolean noscale; @@ -63,16 +63,43 @@ public class CNG { private double power; private ProceduralStream customGenerator; - public NoiseGenerator getGen() { - return generator; + public CNG(RNG random) { + this(random, 1); } - public ProceduralStream stream() { - return new CNGStream(this); + public CNG(RNG random, int octaves) { + this(random, 1D, octaves); } - public ProceduralStream stream(double min, double max) { - return new FittedStream<>(stream(), min, max); + public CNG(RNG random, double opacity, int octaves) { + this(random, NoiseType.SIMPLEX, opacity, octaves); + } + + public CNG(RNG random, NoiseType type, double opacity, int octaves) { + this(random, type.create(random.nextParallelRNG((long) ((1113334944L * opacity) + 12922 + octaves)).lmax()), opacity, octaves); + } + + public CNG(RNG random, NoiseGenerator generator, double opacity, int octaves) { + customGenerator = null; + creates++; + noscale = generator.isNoScale(); + this.oct = octaves; + this.rng = random; + power = 1; + scale = 1; + patch = 1; + bakedScale = 1; + fscale = 1; + down = 0; + up = 0; + fracture = null; + this.generator = generator; + this.opacity = opacity; + this.injector = ADD; + + if (generator instanceof OctaveNoise) { + ((OctaveNoise) generator).setOctaves(octaves); + } } public static CNG signature(RNG rng) { @@ -95,7 +122,6 @@ public class CNG { return signatureThick(rng, t).fractureWith(signature(rng.nextParallelRNG(4956)), 93); } - public static CNG signatureDoubleFast(RNG rng, NoiseType t, NoiseType f) { return signatureThickFast(rng, t, f) .fractureWith(signatureFast(rng.nextParallelRNG(4956), t, f), 93); @@ -162,43 +188,16 @@ public class CNG { // @done } - public CNG(RNG random) { - this(random, 1); + public NoiseGenerator getGen() { + return generator; } - public CNG(RNG random, int octaves) { - this(random, 1D, octaves); + public ProceduralStream stream() { + return new CNGStream(this); } - public CNG(RNG random, double opacity, int octaves) { - this(random, NoiseType.SIMPLEX, opacity, octaves); - } - - public CNG(RNG random, NoiseType type, double opacity, int octaves) { - this(random, type.create(random.nextParallelRNG((long) ((1113334944L * opacity) + 12922 + octaves)).lmax()), opacity, octaves); - } - - public CNG(RNG random, NoiseGenerator generator, double opacity, int octaves) { - customGenerator = null; - creates++; - noscale = generator.isNoScale(); - this.oct = octaves; - this.rng = random; - power = 1; - scale = 1; - patch = 1; - bakedScale = 1; - fscale = 1; - down = 0; - up = 0; - fracture = null; - this.generator = generator; - this.opacity = opacity; - this.injector = ADD; - - if (generator instanceof OctaveNoise) { - ((OctaveNoise) generator).setOctaves(octaves); - } + public ProceduralStream stream(double min, double max) { + return new FittedStream<>(stream(), min, max); } public CNG bake() { diff --git a/src/main/java/com/volmit/iris/util/noise/CloverNoise.java b/src/main/java/com/volmit/iris/util/noise/CloverNoise.java index 422cda197..2590aecd5 100644 --- a/src/main/java/com/volmit/iris/util/noise/CloverNoise.java +++ b/src/main/java/com/volmit/iris/util/noise/CloverNoise.java @@ -50,6 +50,11 @@ public class CloverNoise implements NoiseGenerator { * Java implementation of 2D Clover Noise. See https://github.com/ValgoBoi/clover-noise */ public static class Noise2D { + private static final long HASH_A = 25214903917L; + private static final long HASH_C = 11L; + private static final long HASH_M = 0x1000000000000L; + private static final double POINT_SPREAD = 0.3; + private static final double CURL_DX = 0.0001; private final long seed; /** @@ -68,10 +73,6 @@ public class CloverNoise implements NoiseGenerator { this(System.currentTimeMillis()); } - private static final long HASH_A = 25214903917L; - private static final long HASH_C = 11L; - private static final long HASH_M = 0x1000000000000L; - private long doHash(long input, long seed) { input += seed; @@ -97,8 +98,6 @@ public class CloverNoise implements NoiseGenerator { return (double) hash / HASH_M; } - private static final double POINT_SPREAD = 0.3; - private Vector2 offset(Vector2 position) { double hash = hash(position); double scale = Math.floor(hash * 50 + 1) / 100; @@ -248,8 +247,6 @@ public class CloverNoise implements NoiseGenerator { return fractalNoise(new Vector2(x, y), iterations); } - private static final double CURL_DX = 0.0001; - /** * Generates curl 2D Clover Noise at a specific point. * @@ -366,6 +363,11 @@ public class CloverNoise implements NoiseGenerator { } public static class Noise3D { + private static final long HASH_A = 25214903917L; + private static final long HASH_C = 11L; + private static final long HASH_M = 0x1000000000000L; + private static final double POINT_SPREAD = 0.2; + private static final double CURL_DX = 0.0001; private final long seed; public Noise3D(long seed) { @@ -376,10 +378,6 @@ public class CloverNoise implements NoiseGenerator { this(System.currentTimeMillis()); } - private static final long HASH_A = 25214903917L; - private static final long HASH_C = 11L; - private static final long HASH_M = 0x1000000000000L; - private long doHash(long input, long seed) { input += seed; @@ -406,8 +404,6 @@ public class CloverNoise implements NoiseGenerator { return (double) hash / HASH_M; } - private static final double POINT_SPREAD = 0.2; - private Vector3 offset(Vector3 position) { double hash = hash(position); double theta = hash * Math.PI * 2000; @@ -720,8 +716,6 @@ public class CloverNoise implements NoiseGenerator { return fractalNoise(new Vector3(x, y, z), iterations); } - private static final double CURL_DX = 0.0001; - /** * Generates curl 3D Clover Noise at a specific point. * diff --git a/src/main/java/com/volmit/iris/util/noise/FastNoise.java b/src/main/java/com/volmit/iris/util/noise/FastNoise.java index ebce04eb6..23e21deb7 100644 --- a/src/main/java/com/volmit/iris/util/noise/FastNoise.java +++ b/src/main/java/com/volmit/iris/util/noise/FastNoise.java @@ -22,64 +22,43 @@ import com.volmit.iris.util.math.Vector2f; import com.volmit.iris.util.math.Vector3f; public class FastNoise { - public enum NoiseType { - Value, - ValueFractal, - Perlin, - PerlinFractal, - Simplex, - SimplexFractal, - Cellular, - WhiteNoise, - Cubic, - CubicFractal - } - - public enum Interp { - Linear, - Hermite, - Quintic - } - - public enum FractalType { - FBM, - Billow, - RigidMulti - } - - public enum CellularDistanceFunction { - Euclidean, - Manhattan, - Natural - } - - public enum CellularReturnType { - CellValue, - NoiseLookup, - Distance, - Distance2, - Distance2Add, - Distance2Sub, - Distance2Mul, - Distance2Div - } - + private static final Float2[] GRAD_2D = {new Float2(-1, -1), new Float2(1, -1), new Float2(-1, 1), new Float2(1, 1), new Float2(0, -1), new Float2(-1, 0), new Float2(0, 1), new Float2(1, 0), + }; + private static final Float3[] GRAD_3D = {new Float3(1, 1, 0), new Float3(-1, 1, 0), new Float3(1, -1, 0), new Float3(-1, -1, 0), new Float3(1, 0, 1), new Float3(-1, 0, 1), new Float3(1, 0, -1), new Float3(-1, 0, -1), new Float3(0, 1, 1), new Float3(0, -1, 1), new Float3(0, 1, -1), new Float3(0, -1, -1), new Float3(1, 1, 0), new Float3(0, -1, 1), new Float3(-1, 1, 0), new Float3(0, -1, -1), + }; + private static final Float2[] CELL_2D = {new Float2(-0.4313539279f, 0.1281943404f), new Float2(-0.1733316799f, 0.415278375f), new Float2(-0.2821957395f, -0.3505218461f), new Float2(-0.2806473808f, 0.3517627718f), new Float2(0.3125508975f, -0.3237467165f), new Float2(0.3383018443f, -0.2967353402f), new Float2(-0.4393982022f, -0.09710417025f), new Float2(-0.4460443703f, -0.05953502905f), new Float2(-0.302223039f, 0.3334085102f), new Float2(-0.212681052f, -0.3965687458f), new Float2(-0.2991156529f, 0.3361990872f), new Float2(0.2293323691f, 0.3871778202f), new Float2(0.4475439151f, -0.04695150755f), new Float2(0.1777518f, 0.41340573f), new Float2(0.1688522499f, -0.4171197882f), new Float2(-0.0976597166f, 0.4392750616f), new Float2(0.08450188373f, 0.4419948321f), new Float2(-0.4098760448f, -0.1857461384f), new Float2(0.3476585782f, -0.2857157906f), new Float2(-0.3350670039f, -0.30038326f), new Float2(0.2298190031f, -0.3868891648f), new Float2(-0.01069924099f, 0.449872789f), new Float2(-0.4460141246f, -0.05976119672f), new Float2(0.3650293864f, 0.2631606867f), new Float2(-0.349479423f, 0.2834856838f), new Float2(-0.4122720642f, 0.1803655873f), new Float2(-0.267327811f, 0.3619887311f), new Float2(0.322124041f, -0.3142230135f), new Float2(0.2880445931f, -0.3457315612f), new Float2(0.3892170926f, -0.2258540565f), new Float2(0.4492085018f, -0.02667811596f), new Float2(-0.4497724772f, 0.01430799601f), new Float2(0.1278175387f, -0.4314657307f), new Float2(-0.03572100503f, 0.4485799926f), new Float2(-0.4297407068f, -0.1335025276f), new Float2(-0.3217817723f, 0.3145735065f), new Float2(-0.3057158873f, 0.3302087162f), new Float2(-0.414503978f, 0.1751754899f), new Float2(-0.3738139881f, 0.2505256519f), new Float2(0.2236891408f, -0.3904653228f), new Float2(0.002967775577f, -0.4499902136f), new Float2(0.1747128327f, -0.4146991995f), new Float2(-0.4423772489f, -0.08247647938f), new Float2(-0.2763960987f, -0.355112935f), new Float2(-0.4019385906f, -0.2023496216f), new Float2(0.3871414161f, -0.2293938184f), new Float2(-0.430008727f, 0.1326367019f), new Float2(-0.03037574274f, -0.4489736231f), new Float2(-0.3486181573f, 0.2845441624f), new Float2(0.04553517144f, -0.4476902368f), new Float2(-0.0375802926f, 0.4484280562f), new Float2(0.3266408905f, 0.3095250049f), new Float2(0.06540017593f, -0.4452222108f), new Float2(0.03409025829f, 0.448706869f), new Float2(-0.4449193635f, 0.06742966669f), new Float2(-0.4255936157f, -0.1461850686f), new Float2(0.449917292f, 0.008627302568f), new Float2(0.05242606404f, 0.4469356864f), new Float2(-0.4495305179f, -0.02055026661f), new Float2(-0.1204775703f, 0.4335725488f), new Float2(-0.341986385f, -0.2924813028f), new Float2(0.3865320182f, 0.2304191809f), new Float2(0.04506097811f, -0.447738214f), new Float2(-0.06283465979f, 0.4455915232f), new Float2(0.3932600341f, -0.2187385324f), new Float2(0.4472261803f, -0.04988730975f), new Float2(0.3753571011f, -0.2482076684f), new Float2(-0.273662295f, 0.357223947f), new Float2(0.1700461538f, 0.4166344988f), new Float2(0.4102692229f, 0.1848760794f), new Float2(0.323227187f, -0.3130881435f), new Float2(-0.2882310238f, -0.3455761521f), new Float2(0.2050972664f, 0.4005435199f), new Float2(0.4414085979f, -0.08751256895f), new Float2(-0.1684700334f, 0.4172743077f), new Float2(-0.003978032396f, 0.4499824166f), new Float2(-0.2055133639f, 0.4003301853f), new Float2(-0.006095674897f, -0.4499587123f), new Float2(-0.1196228124f, -0.4338091548f), new Float2(0.3901528491f, -0.2242337048f), new Float2(0.01723531752f, 0.4496698165f), new Float2(-0.3015070339f, 0.3340561458f), new Float2(-0.01514262423f, -0.4497451511f), new Float2(-0.4142574071f, -0.1757577897f), new Float2(-0.1916377265f, -0.4071547394f), new Float2(0.3749248747f, 0.2488600778f), new Float2(-0.2237774255f, 0.3904147331f), new Float2(-0.4166343106f, -0.1700466149f), new Float2(0.3619171625f, 0.267424695f), new Float2(0.1891126846f, -0.4083336779f), new Float2(-0.3127425077f, 0.323561623f), new Float2(-0.3281807787f, 0.307891826f), new Float2(-0.2294806661f, 0.3870899429f), new Float2(-0.3445266136f, 0.2894847362f), new Float2(-0.4167095422f, -0.1698621719f), new Float2(-0.257890321f, -0.3687717212f), new Float2(-0.3612037825f, 0.2683874578f), new Float2(0.2267996491f, 0.3886668486f), new Float2(0.207157062f, 0.3994821043f), new Float2(0.08355176718f, -0.4421754202f), new Float2(-0.4312233307f, 0.1286329626f), new Float2(0.3257055497f, 0.3105090899f), new Float2(0.177701095f, -0.4134275279f), new Float2(-0.445182522f, 0.06566979625f), new Float2(0.3955143435f, 0.2146355146f), new Float2(-0.4264613988f, 0.1436338239f), new Float2(-0.3793799665f, -0.2420141339f), new Float2(0.04617599081f, -0.4476245948f), new Float2(-0.371405428f, -0.2540826796f), new Float2(0.2563570295f, -0.3698392535f), new Float2(0.03476646309f, 0.4486549822f), new Float2(-0.3065454405f, 0.3294387544f), new Float2(-0.2256979823f, 0.3893076172f), new Float2(0.4116448463f, -0.1817925206f), new Float2(-0.2907745828f, -0.3434387019f), new Float2(0.2842278468f, -0.348876097f), new Float2(0.3114589359f, -0.3247973695f), new Float2(0.4464155859f, -0.0566844308f), new Float2(-0.3037334033f, -0.3320331606f), new Float2(0.4079607166f, 0.1899159123f), new Float2(-0.3486948919f, -0.2844501228f), new Float2(0.3264821436f, 0.3096924441f), new Float2(0.3211142406f, 0.3152548881f), new Float2(0.01183382662f, 0.4498443737f), new Float2(0.4333844092f, 0.1211526057f), new Float2(0.3118668416f, 0.324405723f), new Float2(-0.272753471f, 0.3579183483f), new Float2(-0.422228622f, -0.1556373694f), new Float2(-0.1009700099f, -0.4385260051f), new Float2(-0.2741171231f, -0.3568750521f), new Float2(-0.1465125133f, 0.4254810025f), new Float2(0.2302279044f, -0.3866459777f), new Float2(-0.3699435608f, 0.2562064828f), new Float2(0.105700352f, -0.4374099171f), new Float2(-0.2646713633f, 0.3639355292f), new Float2(0.3521828122f, 0.2801200935f), new Float2(-0.1864187807f, -0.4095705534f), new Float2(0.1994492955f, -0.4033856449f), new Float2(0.3937065066f, 0.2179339044f), new Float2(-0.3226158377f, 0.3137180602f), new Float2(0.3796235338f, 0.2416318948f), new Float2(0.1482921929f, 0.4248640083f), new Float2(-0.407400394f, 0.1911149365f), new Float2(0.4212853031f, 0.1581729856f), new Float2(-0.2621297173f, 0.3657704353f), new Float2(-0.2536986953f, -0.3716678248f), new Float2(-0.2100236383f, 0.3979825013f), new Float2(0.3624152444f, 0.2667493029f), new Float2(-0.3645038479f, -0.2638881295f), new Float2(0.2318486784f, 0.3856762766f), new Float2(-0.3260457004f, 0.3101519002f), new Float2(-0.2130045332f, -0.3963950918f), new Float2(0.3814998766f, -0.2386584257f), new Float2(-0.342977305f, 0.2913186713f), new Float2(-0.4355865605f, 0.1129794154f), new Float2(-0.2104679605f, 0.3977477059f), new Float2(0.3348364681f, -0.3006402163f), new Float2(0.3430468811f, 0.2912367377f), new Float2(-0.2291836801f, -0.3872658529f), new Float2(0.2547707298f, -0.3709337882f), new Float2(0.4236174945f, -0.151816397f), new Float2(-0.15387742f, 0.4228731957f), new Float2(-0.4407449312f, 0.09079595574f), new Float2(-0.06805276192f, -0.444824484f), new Float2(0.4453517192f, -0.06451237284f), new Float2(0.2562464609f, -0.3699158705f), new Float2(0.3278198355f, -0.3082761026f), new Float2(-0.4122774207f, -0.1803533432f), new Float2(0.3354090914f, -0.3000012356f), new Float2(0.446632869f, -0.05494615882f), new Float2(-0.1608953296f, 0.4202531296f), new Float2(-0.09463954939f, 0.4399356268f), new Float2(-0.02637688324f, -0.4492262904f), new Float2(0.447102804f, -0.05098119915f), new Float2(-0.4365670908f, 0.1091291678f), new Float2(-0.3959858651f, 0.2137643437f), new Float2(-0.4240048207f, -0.1507312575f), new Float2(-0.3882794568f, 0.2274622243f), new Float2(-0.4283652566f, -0.1378521198f), new Float2(0.3303888091f, 0.305521251f), new Float2(0.3321434919f, -0.3036127481f), new Float2(-0.413021046f, -0.1786438231f), new Float2(0.08403060337f, -0.4420846725f), new Float2(-0.3822882919f, 0.2373934748f), new Float2(-0.3712395594f, -0.2543249683f), new Float2(0.4472363971f, -0.04979563372f), new Float2(-0.4466591209f, 0.05473234629f), new Float2(0.0486272539f, -0.4473649407f), new Float2(-0.4203101295f, -0.1607463688f), new Float2(0.2205360833f, 0.39225481f), new Float2(-0.3624900666f, 0.2666476169f), new Float2(-0.4036086833f, -0.1989975647f), new Float2(0.2152727807f, 0.3951678503f), new Float2(-0.4359392962f, -0.1116106179f), new Float2(0.4178354266f, 0.1670735057f), new Float2(0.2007630161f, 0.4027334247f), new Float2(-0.07278067175f, -0.4440754146f), new Float2(0.3644748615f, -0.2639281632f), new Float2(-0.4317451775f, 0.126870413f), new Float2(-0.297436456f, 0.3376855855f), new Float2(-0.2998672222f, 0.3355289094f), new Float2(-0.2673674124f, 0.3619594822f), new Float2(0.2808423357f, 0.3516071423f), new Float2(0.3498946567f, 0.2829730186f), new Float2(-0.2229685561f, 0.390877248f), new Float2(0.3305823267f, 0.3053118493f), new Float2(-0.2436681211f, -0.3783197679f), new Float2(-0.03402776529f, 0.4487116125f), new Float2(-0.319358823f, 0.3170330301f), new Float2(0.4454633477f, -0.06373700535f), new Float2(0.4483504221f, 0.03849544189f), new Float2(-0.4427358436f, -0.08052932871f), new Float2(0.05452298565f, 0.4466847255f), new Float2(-0.2812560807f, 0.3512762688f), new Float2(0.1266696921f, 0.4318041097f), new Float2(-0.3735981243f, 0.2508474468f), new Float2(0.2959708351f, -0.3389708908f), new Float2(-0.3714377181f, 0.254035473f), new Float2(-0.404467102f, -0.1972469604f), new Float2(0.1636165687f, -0.419201167f), new Float2(0.3289185495f, -0.3071035458f), new Float2(-0.2494824991f, -0.3745109914f), new Float2(0.03283133272f, 0.4488007393f), new Float2(-0.166306057f, -0.4181414777f), new Float2(-0.106833179f, 0.4371346153f), new Float2(0.06440260376f, -0.4453676062f), new Float2(-0.4483230967f, 0.03881238203f), new Float2(-0.421377757f, -0.1579265206f), new Float2(0.05097920662f, -0.4471030312f), new Float2(0.2050584153f, -0.4005634111f), new Float2(0.4178098529f, -0.167137449f), new Float2(-0.3565189504f, -0.2745801121f), new Float2(0.4478398129f, 0.04403977727f), new Float2(-0.3399999602f, -0.2947881053f), new Float2(0.3767121994f, 0.2461461331f), new Float2(-0.3138934434f, 0.3224451987f), new Float2(-0.1462001792f, -0.4255884251f), new Float2(0.3970290489f, -0.2118205239f), new Float2(0.4459149305f, -0.06049689889f), new Float2(-0.4104889426f, -0.1843877112f), new Float2(0.1475103971f, -0.4251360756f), new Float2(0.09258030352f, 0.4403735771f), new Float2(-0.1589664637f, -0.4209865359f), new Float2(0.2482445008f, 0.3753327428f), new Float2(0.4383624232f, -0.1016778537f), new Float2(0.06242802956f, 0.4456486745f), new Float2(0.2846591015f, -0.3485243118f), new Float2(-0.344202744f, -0.2898697484f), new Float2(0.1198188883f, -0.4337550392f), new Float2(-0.243590703f, 0.3783696201f), new Float2(0.2958191174f, -0.3391033025f), new Float2(-0.1164007991f, 0.4346847754f), new Float2(0.1274037151f, -0.4315881062f), new Float2(0.368047306f, 0.2589231171f), new Float2(0.2451436949f, 0.3773652989f), new Float2(-0.4314509715f, 0.12786735f), + }; + private static final Float3[] CELL_3D = {new Float3(0.1453787434f, -0.4149781685f, -0.0956981749f), new Float3(-0.01242829687f, -0.1457918398f, -0.4255470325f), new Float3(0.2877979582f, -0.02606483451f, -0.3449535616f), new Float3(-0.07732986802f, 0.2377094325f, 0.3741848704f), new Float3(0.1107205875f, -0.3552302079f, -0.2530858567f), new Float3(0.2755209141f, 0.2640521179f, -0.238463215f), new Float3(0.294168941f, 0.1526064594f, 0.3044271714f), new Float3(0.4000921098f, -0.2034056362f, 0.03244149937f), new Float3(-0.1697304074f, 0.3970864695f, -0.1265461359f), new Float3(-0.1483224484f, -0.3859694688f, 0.1775613147f), new Float3(0.2623596946f, -0.2354852944f, 0.2796677792f), new Float3(-0.2709003183f, 0.3505271138f, -0.07901746678f), new Float3(-0.03516550699f, 0.3885234328f, 0.2243054374f), new Float3(-0.1267712655f, 0.1920044036f, 0.3867342179f), new Float3(0.02952021915f, 0.4409685861f, 0.08470692262f), new Float3(-0.2806854217f, -0.266996757f, 0.2289725438f), new Float3(-0.171159547f, 0.2141185563f, 0.3568720405f), new Float3(0.2113227183f, 0.3902405947f, -0.07453178509f), new Float3(-0.1024352839f, 0.2128044156f, -0.3830421561f), new Float3(-0.3304249877f, -0.1566986703f, 0.2622305365f), new Float3(0.2091111325f, 0.3133278055f, -0.2461670583f), new Float3(0.344678154f, -0.1944240454f, -0.2142341261f), new Float3(0.1984478035f, -0.3214342325f, -0.2445373252f), new Float3(-0.2929008603f, 0.2262915116f, 0.2559320961f), new Float3(-0.1617332831f, 0.006314769776f, -0.4198838754f), new Float3(-0.3582060271f, -0.148303178f, -0.2284613961f), new Float3(-0.1852067326f, -0.3454119342f, -0.2211087107f), new Float3(0.3046301062f, 0.1026310383f, 0.314908508f), new Float3(-0.03816768434f, -0.2551766358f, -0.3686842991f), new Float3(-0.4084952196f, 0.1805950793f, 0.05492788837f), new Float3(-0.02687443361f, -0.2749741471f, 0.3551999201f), new Float3(-0.03801098351f, 0.3277859044f, 0.3059600725f), new Float3(0.2371120802f, 0.2900386767f, -0.2493099024f), new Float3(0.4447660503f, 0.03946930643f, 0.05590469027f), new Float3(0.01985147278f, -0.01503183293f, -0.4493105419f), new Float3(0.4274339143f, 0.03345994256f, -0.1366772882f), new Float3(-0.2072988631f, 0.2871414597f, -0.2776273824f), new Float3(-0.3791240978f, 0.1281177671f, 0.2057929936f), new Float3(-0.2098721267f, -0.1007087278f, -0.3851122467f), new Float3(0.01582798878f, 0.4263894424f, 0.1429738373f), new Float3(-0.1888129464f, -0.3160996813f, -0.2587096108f), new Float3(0.1612988974f, -0.1974805082f, -0.3707885038f), new Float3(-0.08974491322f, 0.229148752f, -0.3767448739f), new Float3(0.07041229526f, 0.4150230285f, -0.1590534329f), new Float3(-0.1082925611f, -0.1586061639f, 0.4069604477f), new Float3(0.2474100658f, -0.3309414609f, 0.1782302128f), new Float3(-0.1068836661f, -0.2701644537f, -0.3436379634f), new Float3(0.2396452163f, 0.06803600538f, -0.3747549496f), new Float3(-0.3063886072f, 0.2597428179f, 0.2028785103f), new Float3(0.1593342891f, -0.3114350249f, -0.2830561951f), new Float3(0.2709690528f, 0.1412648683f, -0.3303331794f), new Float3(-0.1519780427f, 0.3623355133f, 0.2193527988f), new Float3(0.1699773681f, 0.3456012883f, 0.2327390037f), new Float3(-0.1986155616f, 0.3836276443f, -0.1260225743f), new Float3(-0.1887482106f, -0.2050154888f, -0.353330953f), new Float3(0.2659103394f, 0.3015631259f, -0.2021172246f), new Float3(-0.08838976154f, -0.4288819642f, -0.1036702021f), new Float3(-0.04201869311f, 0.3099592485f, 0.3235115047f), new Float3(-0.3230334656f, 0.201549922f, -0.2398478873f), new Float3(0.2612720941f, 0.2759854499f, -0.2409749453f), new Float3(0.385713046f, 0.2193460345f, 0.07491837764f), new Float3(0.07654967953f, 0.3721732183f, 0.241095919f), new Float3(0.4317038818f, -0.02577753072f, 0.1243675091f), new Float3(-0.2890436293f, -0.3418179959f, -0.04598084447f), new Float3(-0.2201947582f, 0.383023377f, -0.08548310451f), new Float3(0.4161322773f, -0.1669634289f, -0.03817251927f), new Float3(0.2204718095f, 0.02654238946f, -0.391391981f), new Float3(-0.1040307469f, 0.3890079625f, -0.2008741118f), new Float3(-0.1432122615f, 0.371614387f, -0.2095065525f), new Float3(0.3978380468f, -0.06206669342f, 0.2009293758f), new Float3(-0.2599274663f, 0.2616724959f, -0.2578084893f), new Float3(0.4032618332f, -0.1124593585f, 0.1650235939f), new Float3(-0.08953470255f, -0.3048244735f, 0.3186935478f), new Float3(0.118937202f, -0.2875221847f, 0.325092195f), new Float3(0.02167047076f, -0.03284630549f, -0.4482761547f), new Float3(-0.3411343612f, 0.2500031105f, 0.1537068389f), new Float3(0.3162964612f, 0.3082064153f, -0.08640228117f), new Float3(0.2355138889f, -0.3439334267f, -0.1695376245f), new Float3(-0.02874541518f, -0.3955933019f, 0.2125550295f), new Float3(-0.2461455173f, 0.02020282325f, -0.3761704803f), new Float3(0.04208029445f, -0.4470439576f, 0.02968078139f), new Float3(0.2727458746f, 0.2288471896f, -0.2752065618f), new Float3(-0.1347522818f, -0.02720848277f, -0.4284874806f), new Float3(0.3829624424f, 0.1231931484f, -0.2016512234f), new Float3(-0.3547613644f, 0.1271702173f, 0.2459107769f), new Float3(0.2305790207f, 0.3063895591f, 0.2354968222f), new Float3(-0.08323845599f, -0.1922245118f, 0.3982726409f), new Float3(0.2993663085f, -0.2619918095f, -0.2103333191f), new Float3(-0.2154865723f, 0.2706747713f, 0.287751117f), new Float3(0.01683355354f, -0.2680655787f, -0.3610505186f), new Float3(0.05240429123f, 0.4335128183f, -0.1087217856f), new Float3(0.00940104872f, -0.4472890582f, 0.04841609928f), new Float3(0.3465688735f, 0.01141914583f, -0.2868093776f), new Float3(-0.3706867948f, -0.2551104378f, 0.003156692623f), new Float3(0.2741169781f, 0.2139972417f, -0.2855959784f), new Float3(0.06413433865f, 0.1708718512f, 0.4113266307f), new Float3(-0.388187972f, -0.03973280434f, -0.2241236325f), new Float3(0.06419469312f, -0.2803682491f, 0.3460819069f), new Float3(-0.1986120739f, -0.3391173584f, 0.2192091725f), new Float3(-0.203203009f, -0.3871641506f, 0.1063600375f), new Float3(-0.1389736354f, -0.2775901578f, -0.3257760473f), new Float3(-0.06555641638f, 0.342253257f, -0.2847192729f), new Float3(-0.2529246486f, -0.2904227915f, 0.2327739768f), new Float3(0.1444476522f, 0.1069184044f, 0.4125570634f), new Float3(-0.3643780054f, -0.2447099973f, -0.09922543227f), new Float3(0.4286142488f, -0.1358496089f, -0.01829506817f), new Float3(0.165872923f, -0.3136808464f, -0.2767498872f), new Float3(0.2219610524f, -0.3658139958f, 0.1393320198f), new Float3(0.04322940318f, -0.3832730794f, 0.2318037215f), new Float3(-0.08481269795f, -0.4404869674f, -0.03574965489f), new Float3(0.1822082075f, -0.3953259299f, 0.1140946023f), new Float3(-0.3269323334f, 0.3036542563f, 0.05838957105f), new Float3(-0.4080485344f, 0.04227858267f, -0.184956522f), new Float3(0.2676025294f, -0.01299671652f, 0.36155217f), new Float3(0.3024892441f, -0.1009990293f, -0.3174892964f), new Float3(0.1448494052f, 0.425921681f, -0.0104580805f), new Float3(0.4198402157f, 0.08062320474f, 0.1404780841f), new Float3(-0.3008872161f, -0.333040905f, -0.03241355801f), new Float3(0.3639310428f, -0.1291284382f, -0.2310412139f), new Float3(0.3295806598f, 0.0184175994f, -0.3058388149f), new Float3(0.2776259487f, -0.2974929052f, -0.1921504723f), new Float3(0.4149000507f, -0.144793182f, -0.09691688386f), new Float3(0.145016715f, -0.0398992945f, 0.4241205002f), new Float3(0.09299023471f, -0.299732164f, -0.3225111565f), new Float3(0.1028907093f, -0.361266869f, 0.247789732f), new Float3(0.2683057049f, -0.07076041213f, -0.3542668666f), new Float3(-0.4227307273f, -0.07933161816f, -0.1323073187f), new Float3(-0.1781224702f, 0.1806857196f, -0.3716517945f), new Float3(0.4390788626f, -0.02841848598f, -0.09435116353f), new Float3(0.2972583585f, 0.2382799621f, -0.2394997452f), new Float3(-0.1707002821f, 0.2215845691f, 0.3525077196f), new Float3(0.3806686614f, 0.1471852559f, -0.1895464869f), new Float3(-0.1751445661f, -0.274887877f, 0.3102596268f), new Float3(-0.2227237566f, -0.2316778837f, 0.3149912482f), new Float3(0.1369633021f, 0.1341343041f, -0.4071228836f), new Float3(-0.3529503428f, -0.2472893463f, -0.129514612f), new Float3(-0.2590744185f, -0.2985577559f, -0.2150435121f), new Float3(-0.3784019401f, 0.2199816631f, -0.1044989934f), new Float3(-0.05635805671f, 0.1485737441f, 0.4210102279f), new Float3(0.3251428613f, 0.09666046873f, -0.2957006485f), new Float3(-0.4190995804f, 0.1406751354f, -0.08405978803f), new Float3(-0.3253150961f, -0.3080335042f, -0.04225456877f), new Float3(0.2857945863f, -0.05796152095f, 0.3427271751f), new Float3(-0.2733604046f, 0.1973770973f, -0.2980207554f), new Float3(0.219003657f, 0.2410037886f, -0.3105713639f), new Float3(0.3182767252f, -0.271342949f, 0.1660509868f), new Float3(-0.03222023115f, -0.3331161506f, -0.300824678f), new Float3(-0.3087780231f, 0.1992794134f, -0.2596995338f), new Float3(-0.06487611647f, -0.4311322747f, 0.1114273361f), new Float3(0.3921171432f, -0.06294284106f, -0.2116183942f), new Float3(-0.1606404506f, -0.358928121f, -0.2187812825f), new Float3(-0.03767771199f, -0.2290351443f, 0.3855169162f), new Float3(0.1394866832f, -0.3602213994f, 0.2308332918f), new Float3(-0.4345093872f, 0.005751117145f, 0.1169124335f), new Float3(-0.1044637494f, 0.4168128432f, -0.1336202785f), new Float3(0.2658727501f, 0.2551943237f, 0.2582393035f), new Float3(0.2051461999f, 0.1975390727f, 0.3484154868f), new Float3(-0.266085566f, 0.23483312f, 0.2766800993f), new Float3(0.07849405464f, -0.3300346342f, -0.2956616708f), new Float3(-0.2160686338f, 0.05376451292f, -0.3910546287f), new Float3(-0.185779186f, 0.2148499206f, 0.3490352499f), new Float3(0.02492421743f, -0.3229954284f, -0.3123343347f), new Float3(-0.120167831f, 0.4017266681f, 0.1633259825f), new Float3(-0.02160084693f, -0.06885389554f, 0.4441762538f), new Float3(0.2597670064f, 0.3096300784f, 0.1978643903f), new Float3(-0.1611553854f, -0.09823036005f, 0.4085091653f), new Float3(-0.3278896792f, 0.1461670309f, 0.2713366126f), new Float3(0.2822734956f, 0.03754421121f, -0.3484423997f), new Float3(0.03169341113f, 0.347405252f, -0.2842624114f), new Float3(0.2202613604f, -0.3460788041f, -0.1849713341f), new Float3(0.2933396046f, 0.3031973659f, 0.1565989581f), new Float3(-0.3194922995f, 0.2453752201f, -0.200538455f), new Float3(-0.3441586045f, -0.1698856132f, -0.2349334659f), new Float3(0.2703645948f, -0.3574277231f, 0.04060059933f), new Float3(0.2298568861f, 0.3744156221f, 0.0973588921f), new Float3(0.09326603877f, -0.3170108894f, 0.3054595587f), new Float3(-0.1116165319f, -0.2985018719f, 0.3177080142f), new Float3(0.2172907365f, -0.3460005203f, -0.1885958001f), new Float3(0.1991339479f, 0.3820341668f, -0.1299829458f), new Float3(-0.0541918155f, -0.2103145071f, 0.39412061f), new Float3(0.08871336998f, 0.2012117383f, 0.3926114802f), new Float3(0.2787673278f, 0.3505404674f, 0.04370535101f), new Float3(-0.322166438f, 0.3067213525f, 0.06804996813f), new Float3(-0.4277366384f, 0.132066775f, 0.04582286686f), new Float3(0.240131882f, -0.1612516055f, 0.344723946f), new Float3(0.1448607981f, -0.2387819045f, 0.3528435224f), new Float3(-0.3837065682f, -0.2206398454f, 0.08116235683f), new Float3(-0.4382627882f, -0.09082753406f, -0.04664855374f), new Float3(-0.37728353f, 0.05445141085f, 0.2391488697f), new Float3(0.1259579313f, 0.348394558f, 0.2554522098f), new Float3(-0.1406285511f, -0.270877371f, -0.3306796947f), new Float3(-0.1580694418f, 0.4162931958f, -0.06491553533f), new Float3(0.2477612106f, -0.2927867412f, -0.2353514536f), new Float3(0.2916132853f, 0.3312535401f, 0.08793624968f), new Float3(0.07365265219f, -0.1666159848f, 0.411478311f), new Float3(-0.26126526f, -0.2422237692f, 0.2748965434f), new Float3(-0.3721862032f, 0.252790166f, 0.008634938242f), new Float3(-0.3691191571f, -0.255281188f, 0.03290232422f), new Float3(0.2278441737f, -0.3358364886f, 0.1944244981f), new Float3(0.363398169f, -0.2310190248f, 0.1306597909f), new Float3(-0.304231482f, -0.2698452035f, 0.1926830856f), new Float3(-0.3199312232f, 0.316332536f, -0.008816977938f), new Float3(0.2874852279f, 0.1642275508f, -0.304764754f), new Float3(-0.1451096801f, 0.3277541114f, -0.2720669462f), new Float3(0.3220090754f, 0.0511344108f, 0.3101538769f), new Float3(-0.1247400865f, -0.04333605335f, -0.4301882115f), new Float3(-0.2829555867f, -0.3056190617f, -0.1703910946f), new Float3(0.1069384374f, 0.3491024667f, -0.2630430352f), new Float3(-0.1420661144f, -0.3055376754f, -0.2982682484f), new Float3(-0.250548338f, 0.3156466809f, -0.2002316239f), new Float3(0.3265787872f, 0.1871229129f, 0.2466400438f), new Float3(0.07646097258f, -0.3026690852f, 0.324106687f), new Float3(0.3451771584f, 0.2757120714f, -0.0856480183f), new Float3(0.298137964f, 0.2852657134f, 0.179547284f), new Float3(0.2812250376f, 0.3466716415f, 0.05684409612f), new Float3(0.4390345476f, -0.09790429955f, -0.01278335452f), new Float3(0.2148373234f, 0.1850172527f, 0.3494474791f), new Float3(0.2595421179f, -0.07946825393f, 0.3589187731f), new Float3(0.3182823114f, -0.307355516f, -0.08203022006f), new Float3(-0.4089859285f, -0.04647718411f, 0.1818526372f), new Float3(-0.2826749061f, 0.07417482322f, 0.3421885344f), new Float3(0.3483864637f, 0.225442246f, -0.1740766085f), new Float3(-0.3226415069f, -0.1420585388f, -0.2796816575f), new Float3(0.4330734858f, -0.118868561f, -0.02859407492f), new Float3(-0.08717822568f, -0.3909896417f, -0.2050050172f), new Float3(-0.2149678299f, 0.3939973956f, -0.03247898316f), new Float3(-0.2687330705f, 0.322686276f, -0.1617284888f), new Float3(0.2105665099f, -0.1961317136f, -0.3459683451f), new Float3(0.4361845915f, -0.1105517485f, 0.004616608544f), new Float3(0.05333333359f, -0.313639498f, -0.3182543336f), new Float3(-0.05986216652f, 0.1361029153f, -0.4247264031f), new Float3(0.3664988455f, 0.2550543014f, -0.05590974511f), new Float3(-0.2341015558f, -0.182405731f, 0.3382670703f), new Float3(-0.04730947785f, -0.4222150243f, -0.1483114513f), new Float3(-0.2391566239f, -0.2577696514f, -0.2808182972f), new Float3(-0.1242081035f, 0.4256953395f, -0.07652336246f), new Float3(0.2614832715f, -0.3650179274f, 0.02980623099f), new Float3(-0.2728794681f, -0.3499628774f, 0.07458404908f), new Float3(0.007892900508f, -0.1672771315f, 0.4176793787f), new Float3(-0.01730330376f, 0.2978486637f, -0.3368779738f), new Float3(0.2054835762f, -0.3252600376f, -0.2334146693f), new Float3(-0.3231994983f, 0.1564282844f, -0.2712420987f), new Float3(-0.2669545963f, 0.2599343665f, -0.2523278991f), new Float3(-0.05554372779f, 0.3170813944f, -0.3144428146f), new Float3(-0.2083935713f, -0.310922837f, -0.2497981362f), new Float3(0.06989323478f, -0.3156141536f, 0.3130537363f), new Float3(0.3847566193f, -0.1605309138f, -0.1693876312f), new Float3(-0.3026215288f, -0.3001537679f, -0.1443188342f), new Float3(0.3450735512f, 0.08611519592f, 0.2756962409f), new Float3(0.1814473292f, -0.2788782453f, -0.3029914042f), new Float3(-0.03855010448f, 0.09795110726f, 0.4375151083f), new Float3(0.3533670318f, 0.2665752752f, 0.08105160988f), new Float3(-0.007945601311f, 0.140359426f, -0.4274764309f), new Float3(0.4063099273f, -0.1491768253f, -0.1231199324f), new Float3(-0.2016773589f, 0.008816271194f, -0.4021797064f), new Float3(-0.07527055435f, -0.425643481f, -0.1251477955f), + }; + // Hashing + private final static int X_PRIME = 1619; + private final static int Y_PRIME = 31337; + private final static int Z_PRIME = 6971; + private final static int W_PRIME = 1013; + private final static float F3 = (float) (1.0 / 3.0); + private final static float G3 = (float) (1.0 / 6.0); + private final static float G33 = G3 * 3 - 1; + private final static float SQRT3 = (float) 1.7320508075688772935274463415059; + private final static float F2 = 0.5f * (SQRT3 - 1.0f); + private final static float G2 = (3.0f - SQRT3) / 6.0f; + private static final byte[] SIMPLEX_4D = {0, 1, 2, 3, 0, 1, 3, 2, 0, 0, 0, 0, 0, 2, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 0, 0, 2, 1, 3, 0, 0, 0, 0, 0, 3, 1, 2, 0, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 3, 0, 0, 0, 0, 1, 3, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 1, 2, 3, 1, 0, 1, 0, 2, 3, 1, 0, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 1, 0, 0, 0, 0, 2, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1, 2, 3, 0, 2, 1, 0, 0, 0, 0, 3, 1, 2, 0, 2, 1, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 0, 2, 0, 0, 0, 0, 3, 2, 0, 1, 3, 2, 1, 0 + }; + private final static float F4 = (float) ((2.23606797 - 1.0) / 4.0); + private final static float G4 = (float) ((5.0 - 2.23606797) / 20.0); + private final static float CUBIC_3D_BOUNDING = 1 / (float) (1.5 * 1.5 * 1.5); + private final static float CUBIC_2D_BOUNDING = 1 / (float) (1.5 * 1.5); private int m_seed = 1337; private float m_frequency = (float) 0.01; private Interp m_interp = Interp.Quintic; private NoiseType m_noiseType = NoiseType.Simplex; - private int m_octaves = 3; private float m_lacunarity = (float) 2.0; private float m_gain = (float) 0.5; private FractalType m_fractalType = FractalType.FBM; - private float m_fractalBounding; - private CellularDistanceFunction m_cellularDistanceFunction = CellularDistanceFunction.Euclidean; private CellularReturnType m_cellularReturnType = CellularReturnType.CellValue; private FastNoise m_cellularNoiseLookup = null; - private float m_gradientPerturbAmp = (float) (1.0 / 0.45); public FastNoise() { @@ -96,125 +75,6 @@ public class FastNoise { return 0; } - // Returns the seed used by this object - public int GetSeed() { - return m_seed; - } - - // Sets seed used for all noise types - // Default: 1337 - public void SetSeed(int seed) { - m_seed = seed; - } - - // Sets frequency for all noise types - // Default: 0.01 - public void SetFrequency(float frequency) { - m_frequency = frequency; - } - - // Changes the interpolation method used to smooth between noise values - // Possible interpolation methods (lowest to highest quality) : - // - Linear - // - Hermite - // - Quintic - // Used in Value, Gradient Noise and Position Perturbing - // Default: Quintic - public void SetInterp(Interp interp) { - m_interp = interp; - } - - // Sets noise return type of GetNoise(...) - // Default: Simplex - public void SetNoiseType(NoiseType noiseType) { - m_noiseType = noiseType; - } - - // Sets octave count for all fractal noise types - // Default: 3 - public void SetFractalOctaves(int octaves) { - m_octaves = octaves; - CalculateFractalBounding(); - } - - // Sets octave lacunarity for all fractal noise types - // Default: 2.0 - public void SetFractalLacunarity(float lacunarity) { - m_lacunarity = lacunarity; - } - - // Sets octave gain for all fractal noise types - // Default: 0.5 - public void SetFractalGain(float gain) { - m_gain = gain; - CalculateFractalBounding(); - } - - // Sets method for combining octaves in all fractal noise types - // Default: FBM - public void SetFractalType(FractalType fractalType) { - m_fractalType = fractalType; - } - - // Sets return type from cellular noise calculations - // Note: NoiseLookup requires another FastNoise object be set with - // SetCellularNoiseLookup() to function - // Default: CellValue - public void SetCellularDistanceFunction(CellularDistanceFunction cellularDistanceFunction) { - m_cellularDistanceFunction = cellularDistanceFunction; - } - - // Sets distance function used in cellular noise calculations - // Default: Euclidean - public void SetCellularReturnType(CellularReturnType cellularReturnType) { - m_cellularReturnType = cellularReturnType; - } - - // Noise used to calculate a cell value if cellular return type is NoiseLookup - // The lookup value is acquired through GetNoise() so ensure you SetNoiseType() - // on the noise lookup, value, gradient or simplex is recommended - public void SetCellularNoiseLookup(FastNoise noise) { - m_cellularNoiseLookup = noise; - } - - // Sets the maximum perturb distance from original location when using - // GradientPerturb{Fractal}(...) - // Default: 1.0 - public void SetGradientPerturbAmp(float gradientPerturbAmp) { - m_gradientPerturbAmp = gradientPerturbAmp / (float) 0.45; - } - - private static class Float2 { - public final float x, y; - - public Float2(float x, float y) { - this.x = x; - this.y = y; - } - } - - private static class Float3 { - public final float x, y, z; - - public Float3(float x, float y, float z) { - this.x = x; - this.y = y; - this.z = z; - } - } - - private static final Float2[] GRAD_2D = {new Float2(-1, -1), new Float2(1, -1), new Float2(-1, 1), new Float2(1, 1), new Float2(0, -1), new Float2(-1, 0), new Float2(0, 1), new Float2(1, 0), - }; - - private static final Float3[] GRAD_3D = {new Float3(1, 1, 0), new Float3(-1, 1, 0), new Float3(1, -1, 0), new Float3(-1, -1, 0), new Float3(1, 0, 1), new Float3(-1, 0, 1), new Float3(1, 0, -1), new Float3(-1, 0, -1), new Float3(0, 1, 1), new Float3(0, -1, 1), new Float3(0, 1, -1), new Float3(0, -1, -1), new Float3(1, 1, 0), new Float3(0, -1, 1), new Float3(-1, 1, 0), new Float3(0, -1, -1), - }; - - private static final Float2[] CELL_2D = {new Float2(-0.4313539279f, 0.1281943404f), new Float2(-0.1733316799f, 0.415278375f), new Float2(-0.2821957395f, -0.3505218461f), new Float2(-0.2806473808f, 0.3517627718f), new Float2(0.3125508975f, -0.3237467165f), new Float2(0.3383018443f, -0.2967353402f), new Float2(-0.4393982022f, -0.09710417025f), new Float2(-0.4460443703f, -0.05953502905f), new Float2(-0.302223039f, 0.3334085102f), new Float2(-0.212681052f, -0.3965687458f), new Float2(-0.2991156529f, 0.3361990872f), new Float2(0.2293323691f, 0.3871778202f), new Float2(0.4475439151f, -0.04695150755f), new Float2(0.1777518f, 0.41340573f), new Float2(0.1688522499f, -0.4171197882f), new Float2(-0.0976597166f, 0.4392750616f), new Float2(0.08450188373f, 0.4419948321f), new Float2(-0.4098760448f, -0.1857461384f), new Float2(0.3476585782f, -0.2857157906f), new Float2(-0.3350670039f, -0.30038326f), new Float2(0.2298190031f, -0.3868891648f), new Float2(-0.01069924099f, 0.449872789f), new Float2(-0.4460141246f, -0.05976119672f), new Float2(0.3650293864f, 0.2631606867f), new Float2(-0.349479423f, 0.2834856838f), new Float2(-0.4122720642f, 0.1803655873f), new Float2(-0.267327811f, 0.3619887311f), new Float2(0.322124041f, -0.3142230135f), new Float2(0.2880445931f, -0.3457315612f), new Float2(0.3892170926f, -0.2258540565f), new Float2(0.4492085018f, -0.02667811596f), new Float2(-0.4497724772f, 0.01430799601f), new Float2(0.1278175387f, -0.4314657307f), new Float2(-0.03572100503f, 0.4485799926f), new Float2(-0.4297407068f, -0.1335025276f), new Float2(-0.3217817723f, 0.3145735065f), new Float2(-0.3057158873f, 0.3302087162f), new Float2(-0.414503978f, 0.1751754899f), new Float2(-0.3738139881f, 0.2505256519f), new Float2(0.2236891408f, -0.3904653228f), new Float2(0.002967775577f, -0.4499902136f), new Float2(0.1747128327f, -0.4146991995f), new Float2(-0.4423772489f, -0.08247647938f), new Float2(-0.2763960987f, -0.355112935f), new Float2(-0.4019385906f, -0.2023496216f), new Float2(0.3871414161f, -0.2293938184f), new Float2(-0.430008727f, 0.1326367019f), new Float2(-0.03037574274f, -0.4489736231f), new Float2(-0.3486181573f, 0.2845441624f), new Float2(0.04553517144f, -0.4476902368f), new Float2(-0.0375802926f, 0.4484280562f), new Float2(0.3266408905f, 0.3095250049f), new Float2(0.06540017593f, -0.4452222108f), new Float2(0.03409025829f, 0.448706869f), new Float2(-0.4449193635f, 0.06742966669f), new Float2(-0.4255936157f, -0.1461850686f), new Float2(0.449917292f, 0.008627302568f), new Float2(0.05242606404f, 0.4469356864f), new Float2(-0.4495305179f, -0.02055026661f), new Float2(-0.1204775703f, 0.4335725488f), new Float2(-0.341986385f, -0.2924813028f), new Float2(0.3865320182f, 0.2304191809f), new Float2(0.04506097811f, -0.447738214f), new Float2(-0.06283465979f, 0.4455915232f), new Float2(0.3932600341f, -0.2187385324f), new Float2(0.4472261803f, -0.04988730975f), new Float2(0.3753571011f, -0.2482076684f), new Float2(-0.273662295f, 0.357223947f), new Float2(0.1700461538f, 0.4166344988f), new Float2(0.4102692229f, 0.1848760794f), new Float2(0.323227187f, -0.3130881435f), new Float2(-0.2882310238f, -0.3455761521f), new Float2(0.2050972664f, 0.4005435199f), new Float2(0.4414085979f, -0.08751256895f), new Float2(-0.1684700334f, 0.4172743077f), new Float2(-0.003978032396f, 0.4499824166f), new Float2(-0.2055133639f, 0.4003301853f), new Float2(-0.006095674897f, -0.4499587123f), new Float2(-0.1196228124f, -0.4338091548f), new Float2(0.3901528491f, -0.2242337048f), new Float2(0.01723531752f, 0.4496698165f), new Float2(-0.3015070339f, 0.3340561458f), new Float2(-0.01514262423f, -0.4497451511f), new Float2(-0.4142574071f, -0.1757577897f), new Float2(-0.1916377265f, -0.4071547394f), new Float2(0.3749248747f, 0.2488600778f), new Float2(-0.2237774255f, 0.3904147331f), new Float2(-0.4166343106f, -0.1700466149f), new Float2(0.3619171625f, 0.267424695f), new Float2(0.1891126846f, -0.4083336779f), new Float2(-0.3127425077f, 0.323561623f), new Float2(-0.3281807787f, 0.307891826f), new Float2(-0.2294806661f, 0.3870899429f), new Float2(-0.3445266136f, 0.2894847362f), new Float2(-0.4167095422f, -0.1698621719f), new Float2(-0.257890321f, -0.3687717212f), new Float2(-0.3612037825f, 0.2683874578f), new Float2(0.2267996491f, 0.3886668486f), new Float2(0.207157062f, 0.3994821043f), new Float2(0.08355176718f, -0.4421754202f), new Float2(-0.4312233307f, 0.1286329626f), new Float2(0.3257055497f, 0.3105090899f), new Float2(0.177701095f, -0.4134275279f), new Float2(-0.445182522f, 0.06566979625f), new Float2(0.3955143435f, 0.2146355146f), new Float2(-0.4264613988f, 0.1436338239f), new Float2(-0.3793799665f, -0.2420141339f), new Float2(0.04617599081f, -0.4476245948f), new Float2(-0.371405428f, -0.2540826796f), new Float2(0.2563570295f, -0.3698392535f), new Float2(0.03476646309f, 0.4486549822f), new Float2(-0.3065454405f, 0.3294387544f), new Float2(-0.2256979823f, 0.3893076172f), new Float2(0.4116448463f, -0.1817925206f), new Float2(-0.2907745828f, -0.3434387019f), new Float2(0.2842278468f, -0.348876097f), new Float2(0.3114589359f, -0.3247973695f), new Float2(0.4464155859f, -0.0566844308f), new Float2(-0.3037334033f, -0.3320331606f), new Float2(0.4079607166f, 0.1899159123f), new Float2(-0.3486948919f, -0.2844501228f), new Float2(0.3264821436f, 0.3096924441f), new Float2(0.3211142406f, 0.3152548881f), new Float2(0.01183382662f, 0.4498443737f), new Float2(0.4333844092f, 0.1211526057f), new Float2(0.3118668416f, 0.324405723f), new Float2(-0.272753471f, 0.3579183483f), new Float2(-0.422228622f, -0.1556373694f), new Float2(-0.1009700099f, -0.4385260051f), new Float2(-0.2741171231f, -0.3568750521f), new Float2(-0.1465125133f, 0.4254810025f), new Float2(0.2302279044f, -0.3866459777f), new Float2(-0.3699435608f, 0.2562064828f), new Float2(0.105700352f, -0.4374099171f), new Float2(-0.2646713633f, 0.3639355292f), new Float2(0.3521828122f, 0.2801200935f), new Float2(-0.1864187807f, -0.4095705534f), new Float2(0.1994492955f, -0.4033856449f), new Float2(0.3937065066f, 0.2179339044f), new Float2(-0.3226158377f, 0.3137180602f), new Float2(0.3796235338f, 0.2416318948f), new Float2(0.1482921929f, 0.4248640083f), new Float2(-0.407400394f, 0.1911149365f), new Float2(0.4212853031f, 0.1581729856f), new Float2(-0.2621297173f, 0.3657704353f), new Float2(-0.2536986953f, -0.3716678248f), new Float2(-0.2100236383f, 0.3979825013f), new Float2(0.3624152444f, 0.2667493029f), new Float2(-0.3645038479f, -0.2638881295f), new Float2(0.2318486784f, 0.3856762766f), new Float2(-0.3260457004f, 0.3101519002f), new Float2(-0.2130045332f, -0.3963950918f), new Float2(0.3814998766f, -0.2386584257f), new Float2(-0.342977305f, 0.2913186713f), new Float2(-0.4355865605f, 0.1129794154f), new Float2(-0.2104679605f, 0.3977477059f), new Float2(0.3348364681f, -0.3006402163f), new Float2(0.3430468811f, 0.2912367377f), new Float2(-0.2291836801f, -0.3872658529f), new Float2(0.2547707298f, -0.3709337882f), new Float2(0.4236174945f, -0.151816397f), new Float2(-0.15387742f, 0.4228731957f), new Float2(-0.4407449312f, 0.09079595574f), new Float2(-0.06805276192f, -0.444824484f), new Float2(0.4453517192f, -0.06451237284f), new Float2(0.2562464609f, -0.3699158705f), new Float2(0.3278198355f, -0.3082761026f), new Float2(-0.4122774207f, -0.1803533432f), new Float2(0.3354090914f, -0.3000012356f), new Float2(0.446632869f, -0.05494615882f), new Float2(-0.1608953296f, 0.4202531296f), new Float2(-0.09463954939f, 0.4399356268f), new Float2(-0.02637688324f, -0.4492262904f), new Float2(0.447102804f, -0.05098119915f), new Float2(-0.4365670908f, 0.1091291678f), new Float2(-0.3959858651f, 0.2137643437f), new Float2(-0.4240048207f, -0.1507312575f), new Float2(-0.3882794568f, 0.2274622243f), new Float2(-0.4283652566f, -0.1378521198f), new Float2(0.3303888091f, 0.305521251f), new Float2(0.3321434919f, -0.3036127481f), new Float2(-0.413021046f, -0.1786438231f), new Float2(0.08403060337f, -0.4420846725f), new Float2(-0.3822882919f, 0.2373934748f), new Float2(-0.3712395594f, -0.2543249683f), new Float2(0.4472363971f, -0.04979563372f), new Float2(-0.4466591209f, 0.05473234629f), new Float2(0.0486272539f, -0.4473649407f), new Float2(-0.4203101295f, -0.1607463688f), new Float2(0.2205360833f, 0.39225481f), new Float2(-0.3624900666f, 0.2666476169f), new Float2(-0.4036086833f, -0.1989975647f), new Float2(0.2152727807f, 0.3951678503f), new Float2(-0.4359392962f, -0.1116106179f), new Float2(0.4178354266f, 0.1670735057f), new Float2(0.2007630161f, 0.4027334247f), new Float2(-0.07278067175f, -0.4440754146f), new Float2(0.3644748615f, -0.2639281632f), new Float2(-0.4317451775f, 0.126870413f), new Float2(-0.297436456f, 0.3376855855f), new Float2(-0.2998672222f, 0.3355289094f), new Float2(-0.2673674124f, 0.3619594822f), new Float2(0.2808423357f, 0.3516071423f), new Float2(0.3498946567f, 0.2829730186f), new Float2(-0.2229685561f, 0.390877248f), new Float2(0.3305823267f, 0.3053118493f), new Float2(-0.2436681211f, -0.3783197679f), new Float2(-0.03402776529f, 0.4487116125f), new Float2(-0.319358823f, 0.3170330301f), new Float2(0.4454633477f, -0.06373700535f), new Float2(0.4483504221f, 0.03849544189f), new Float2(-0.4427358436f, -0.08052932871f), new Float2(0.05452298565f, 0.4466847255f), new Float2(-0.2812560807f, 0.3512762688f), new Float2(0.1266696921f, 0.4318041097f), new Float2(-0.3735981243f, 0.2508474468f), new Float2(0.2959708351f, -0.3389708908f), new Float2(-0.3714377181f, 0.254035473f), new Float2(-0.404467102f, -0.1972469604f), new Float2(0.1636165687f, -0.419201167f), new Float2(0.3289185495f, -0.3071035458f), new Float2(-0.2494824991f, -0.3745109914f), new Float2(0.03283133272f, 0.4488007393f), new Float2(-0.166306057f, -0.4181414777f), new Float2(-0.106833179f, 0.4371346153f), new Float2(0.06440260376f, -0.4453676062f), new Float2(-0.4483230967f, 0.03881238203f), new Float2(-0.421377757f, -0.1579265206f), new Float2(0.05097920662f, -0.4471030312f), new Float2(0.2050584153f, -0.4005634111f), new Float2(0.4178098529f, -0.167137449f), new Float2(-0.3565189504f, -0.2745801121f), new Float2(0.4478398129f, 0.04403977727f), new Float2(-0.3399999602f, -0.2947881053f), new Float2(0.3767121994f, 0.2461461331f), new Float2(-0.3138934434f, 0.3224451987f), new Float2(-0.1462001792f, -0.4255884251f), new Float2(0.3970290489f, -0.2118205239f), new Float2(0.4459149305f, -0.06049689889f), new Float2(-0.4104889426f, -0.1843877112f), new Float2(0.1475103971f, -0.4251360756f), new Float2(0.09258030352f, 0.4403735771f), new Float2(-0.1589664637f, -0.4209865359f), new Float2(0.2482445008f, 0.3753327428f), new Float2(0.4383624232f, -0.1016778537f), new Float2(0.06242802956f, 0.4456486745f), new Float2(0.2846591015f, -0.3485243118f), new Float2(-0.344202744f, -0.2898697484f), new Float2(0.1198188883f, -0.4337550392f), new Float2(-0.243590703f, 0.3783696201f), new Float2(0.2958191174f, -0.3391033025f), new Float2(-0.1164007991f, 0.4346847754f), new Float2(0.1274037151f, -0.4315881062f), new Float2(0.368047306f, 0.2589231171f), new Float2(0.2451436949f, 0.3773652989f), new Float2(-0.4314509715f, 0.12786735f), - }; - - private static final Float3[] CELL_3D = {new Float3(0.1453787434f, -0.4149781685f, -0.0956981749f), new Float3(-0.01242829687f, -0.1457918398f, -0.4255470325f), new Float3(0.2877979582f, -0.02606483451f, -0.3449535616f), new Float3(-0.07732986802f, 0.2377094325f, 0.3741848704f), new Float3(0.1107205875f, -0.3552302079f, -0.2530858567f), new Float3(0.2755209141f, 0.2640521179f, -0.238463215f), new Float3(0.294168941f, 0.1526064594f, 0.3044271714f), new Float3(0.4000921098f, -0.2034056362f, 0.03244149937f), new Float3(-0.1697304074f, 0.3970864695f, -0.1265461359f), new Float3(-0.1483224484f, -0.3859694688f, 0.1775613147f), new Float3(0.2623596946f, -0.2354852944f, 0.2796677792f), new Float3(-0.2709003183f, 0.3505271138f, -0.07901746678f), new Float3(-0.03516550699f, 0.3885234328f, 0.2243054374f), new Float3(-0.1267712655f, 0.1920044036f, 0.3867342179f), new Float3(0.02952021915f, 0.4409685861f, 0.08470692262f), new Float3(-0.2806854217f, -0.266996757f, 0.2289725438f), new Float3(-0.171159547f, 0.2141185563f, 0.3568720405f), new Float3(0.2113227183f, 0.3902405947f, -0.07453178509f), new Float3(-0.1024352839f, 0.2128044156f, -0.3830421561f), new Float3(-0.3304249877f, -0.1566986703f, 0.2622305365f), new Float3(0.2091111325f, 0.3133278055f, -0.2461670583f), new Float3(0.344678154f, -0.1944240454f, -0.2142341261f), new Float3(0.1984478035f, -0.3214342325f, -0.2445373252f), new Float3(-0.2929008603f, 0.2262915116f, 0.2559320961f), new Float3(-0.1617332831f, 0.006314769776f, -0.4198838754f), new Float3(-0.3582060271f, -0.148303178f, -0.2284613961f), new Float3(-0.1852067326f, -0.3454119342f, -0.2211087107f), new Float3(0.3046301062f, 0.1026310383f, 0.314908508f), new Float3(-0.03816768434f, -0.2551766358f, -0.3686842991f), new Float3(-0.4084952196f, 0.1805950793f, 0.05492788837f), new Float3(-0.02687443361f, -0.2749741471f, 0.3551999201f), new Float3(-0.03801098351f, 0.3277859044f, 0.3059600725f), new Float3(0.2371120802f, 0.2900386767f, -0.2493099024f), new Float3(0.4447660503f, 0.03946930643f, 0.05590469027f), new Float3(0.01985147278f, -0.01503183293f, -0.4493105419f), new Float3(0.4274339143f, 0.03345994256f, -0.1366772882f), new Float3(-0.2072988631f, 0.2871414597f, -0.2776273824f), new Float3(-0.3791240978f, 0.1281177671f, 0.2057929936f), new Float3(-0.2098721267f, -0.1007087278f, -0.3851122467f), new Float3(0.01582798878f, 0.4263894424f, 0.1429738373f), new Float3(-0.1888129464f, -0.3160996813f, -0.2587096108f), new Float3(0.1612988974f, -0.1974805082f, -0.3707885038f), new Float3(-0.08974491322f, 0.229148752f, -0.3767448739f), new Float3(0.07041229526f, 0.4150230285f, -0.1590534329f), new Float3(-0.1082925611f, -0.1586061639f, 0.4069604477f), new Float3(0.2474100658f, -0.3309414609f, 0.1782302128f), new Float3(-0.1068836661f, -0.2701644537f, -0.3436379634f), new Float3(0.2396452163f, 0.06803600538f, -0.3747549496f), new Float3(-0.3063886072f, 0.2597428179f, 0.2028785103f), new Float3(0.1593342891f, -0.3114350249f, -0.2830561951f), new Float3(0.2709690528f, 0.1412648683f, -0.3303331794f), new Float3(-0.1519780427f, 0.3623355133f, 0.2193527988f), new Float3(0.1699773681f, 0.3456012883f, 0.2327390037f), new Float3(-0.1986155616f, 0.3836276443f, -0.1260225743f), new Float3(-0.1887482106f, -0.2050154888f, -0.353330953f), new Float3(0.2659103394f, 0.3015631259f, -0.2021172246f), new Float3(-0.08838976154f, -0.4288819642f, -0.1036702021f), new Float3(-0.04201869311f, 0.3099592485f, 0.3235115047f), new Float3(-0.3230334656f, 0.201549922f, -0.2398478873f), new Float3(0.2612720941f, 0.2759854499f, -0.2409749453f), new Float3(0.385713046f, 0.2193460345f, 0.07491837764f), new Float3(0.07654967953f, 0.3721732183f, 0.241095919f), new Float3(0.4317038818f, -0.02577753072f, 0.1243675091f), new Float3(-0.2890436293f, -0.3418179959f, -0.04598084447f), new Float3(-0.2201947582f, 0.383023377f, -0.08548310451f), new Float3(0.4161322773f, -0.1669634289f, -0.03817251927f), new Float3(0.2204718095f, 0.02654238946f, -0.391391981f), new Float3(-0.1040307469f, 0.3890079625f, -0.2008741118f), new Float3(-0.1432122615f, 0.371614387f, -0.2095065525f), new Float3(0.3978380468f, -0.06206669342f, 0.2009293758f), new Float3(-0.2599274663f, 0.2616724959f, -0.2578084893f), new Float3(0.4032618332f, -0.1124593585f, 0.1650235939f), new Float3(-0.08953470255f, -0.3048244735f, 0.3186935478f), new Float3(0.118937202f, -0.2875221847f, 0.325092195f), new Float3(0.02167047076f, -0.03284630549f, -0.4482761547f), new Float3(-0.3411343612f, 0.2500031105f, 0.1537068389f), new Float3(0.3162964612f, 0.3082064153f, -0.08640228117f), new Float3(0.2355138889f, -0.3439334267f, -0.1695376245f), new Float3(-0.02874541518f, -0.3955933019f, 0.2125550295f), new Float3(-0.2461455173f, 0.02020282325f, -0.3761704803f), new Float3(0.04208029445f, -0.4470439576f, 0.02968078139f), new Float3(0.2727458746f, 0.2288471896f, -0.2752065618f), new Float3(-0.1347522818f, -0.02720848277f, -0.4284874806f), new Float3(0.3829624424f, 0.1231931484f, -0.2016512234f), new Float3(-0.3547613644f, 0.1271702173f, 0.2459107769f), new Float3(0.2305790207f, 0.3063895591f, 0.2354968222f), new Float3(-0.08323845599f, -0.1922245118f, 0.3982726409f), new Float3(0.2993663085f, -0.2619918095f, -0.2103333191f), new Float3(-0.2154865723f, 0.2706747713f, 0.287751117f), new Float3(0.01683355354f, -0.2680655787f, -0.3610505186f), new Float3(0.05240429123f, 0.4335128183f, -0.1087217856f), new Float3(0.00940104872f, -0.4472890582f, 0.04841609928f), new Float3(0.3465688735f, 0.01141914583f, -0.2868093776f), new Float3(-0.3706867948f, -0.2551104378f, 0.003156692623f), new Float3(0.2741169781f, 0.2139972417f, -0.2855959784f), new Float3(0.06413433865f, 0.1708718512f, 0.4113266307f), new Float3(-0.388187972f, -0.03973280434f, -0.2241236325f), new Float3(0.06419469312f, -0.2803682491f, 0.3460819069f), new Float3(-0.1986120739f, -0.3391173584f, 0.2192091725f), new Float3(-0.203203009f, -0.3871641506f, 0.1063600375f), new Float3(-0.1389736354f, -0.2775901578f, -0.3257760473f), new Float3(-0.06555641638f, 0.342253257f, -0.2847192729f), new Float3(-0.2529246486f, -0.2904227915f, 0.2327739768f), new Float3(0.1444476522f, 0.1069184044f, 0.4125570634f), new Float3(-0.3643780054f, -0.2447099973f, -0.09922543227f), new Float3(0.4286142488f, -0.1358496089f, -0.01829506817f), new Float3(0.165872923f, -0.3136808464f, -0.2767498872f), new Float3(0.2219610524f, -0.3658139958f, 0.1393320198f), new Float3(0.04322940318f, -0.3832730794f, 0.2318037215f), new Float3(-0.08481269795f, -0.4404869674f, -0.03574965489f), new Float3(0.1822082075f, -0.3953259299f, 0.1140946023f), new Float3(-0.3269323334f, 0.3036542563f, 0.05838957105f), new Float3(-0.4080485344f, 0.04227858267f, -0.184956522f), new Float3(0.2676025294f, -0.01299671652f, 0.36155217f), new Float3(0.3024892441f, -0.1009990293f, -0.3174892964f), new Float3(0.1448494052f, 0.425921681f, -0.0104580805f), new Float3(0.4198402157f, 0.08062320474f, 0.1404780841f), new Float3(-0.3008872161f, -0.333040905f, -0.03241355801f), new Float3(0.3639310428f, -0.1291284382f, -0.2310412139f), new Float3(0.3295806598f, 0.0184175994f, -0.3058388149f), new Float3(0.2776259487f, -0.2974929052f, -0.1921504723f), new Float3(0.4149000507f, -0.144793182f, -0.09691688386f), new Float3(0.145016715f, -0.0398992945f, 0.4241205002f), new Float3(0.09299023471f, -0.299732164f, -0.3225111565f), new Float3(0.1028907093f, -0.361266869f, 0.247789732f), new Float3(0.2683057049f, -0.07076041213f, -0.3542668666f), new Float3(-0.4227307273f, -0.07933161816f, -0.1323073187f), new Float3(-0.1781224702f, 0.1806857196f, -0.3716517945f), new Float3(0.4390788626f, -0.02841848598f, -0.09435116353f), new Float3(0.2972583585f, 0.2382799621f, -0.2394997452f), new Float3(-0.1707002821f, 0.2215845691f, 0.3525077196f), new Float3(0.3806686614f, 0.1471852559f, -0.1895464869f), new Float3(-0.1751445661f, -0.274887877f, 0.3102596268f), new Float3(-0.2227237566f, -0.2316778837f, 0.3149912482f), new Float3(0.1369633021f, 0.1341343041f, -0.4071228836f), new Float3(-0.3529503428f, -0.2472893463f, -0.129514612f), new Float3(-0.2590744185f, -0.2985577559f, -0.2150435121f), new Float3(-0.3784019401f, 0.2199816631f, -0.1044989934f), new Float3(-0.05635805671f, 0.1485737441f, 0.4210102279f), new Float3(0.3251428613f, 0.09666046873f, -0.2957006485f), new Float3(-0.4190995804f, 0.1406751354f, -0.08405978803f), new Float3(-0.3253150961f, -0.3080335042f, -0.04225456877f), new Float3(0.2857945863f, -0.05796152095f, 0.3427271751f), new Float3(-0.2733604046f, 0.1973770973f, -0.2980207554f), new Float3(0.219003657f, 0.2410037886f, -0.3105713639f), new Float3(0.3182767252f, -0.271342949f, 0.1660509868f), new Float3(-0.03222023115f, -0.3331161506f, -0.300824678f), new Float3(-0.3087780231f, 0.1992794134f, -0.2596995338f), new Float3(-0.06487611647f, -0.4311322747f, 0.1114273361f), new Float3(0.3921171432f, -0.06294284106f, -0.2116183942f), new Float3(-0.1606404506f, -0.358928121f, -0.2187812825f), new Float3(-0.03767771199f, -0.2290351443f, 0.3855169162f), new Float3(0.1394866832f, -0.3602213994f, 0.2308332918f), new Float3(-0.4345093872f, 0.005751117145f, 0.1169124335f), new Float3(-0.1044637494f, 0.4168128432f, -0.1336202785f), new Float3(0.2658727501f, 0.2551943237f, 0.2582393035f), new Float3(0.2051461999f, 0.1975390727f, 0.3484154868f), new Float3(-0.266085566f, 0.23483312f, 0.2766800993f), new Float3(0.07849405464f, -0.3300346342f, -0.2956616708f), new Float3(-0.2160686338f, 0.05376451292f, -0.3910546287f), new Float3(-0.185779186f, 0.2148499206f, 0.3490352499f), new Float3(0.02492421743f, -0.3229954284f, -0.3123343347f), new Float3(-0.120167831f, 0.4017266681f, 0.1633259825f), new Float3(-0.02160084693f, -0.06885389554f, 0.4441762538f), new Float3(0.2597670064f, 0.3096300784f, 0.1978643903f), new Float3(-0.1611553854f, -0.09823036005f, 0.4085091653f), new Float3(-0.3278896792f, 0.1461670309f, 0.2713366126f), new Float3(0.2822734956f, 0.03754421121f, -0.3484423997f), new Float3(0.03169341113f, 0.347405252f, -0.2842624114f), new Float3(0.2202613604f, -0.3460788041f, -0.1849713341f), new Float3(0.2933396046f, 0.3031973659f, 0.1565989581f), new Float3(-0.3194922995f, 0.2453752201f, -0.200538455f), new Float3(-0.3441586045f, -0.1698856132f, -0.2349334659f), new Float3(0.2703645948f, -0.3574277231f, 0.04060059933f), new Float3(0.2298568861f, 0.3744156221f, 0.0973588921f), new Float3(0.09326603877f, -0.3170108894f, 0.3054595587f), new Float3(-0.1116165319f, -0.2985018719f, 0.3177080142f), new Float3(0.2172907365f, -0.3460005203f, -0.1885958001f), new Float3(0.1991339479f, 0.3820341668f, -0.1299829458f), new Float3(-0.0541918155f, -0.2103145071f, 0.39412061f), new Float3(0.08871336998f, 0.2012117383f, 0.3926114802f), new Float3(0.2787673278f, 0.3505404674f, 0.04370535101f), new Float3(-0.322166438f, 0.3067213525f, 0.06804996813f), new Float3(-0.4277366384f, 0.132066775f, 0.04582286686f), new Float3(0.240131882f, -0.1612516055f, 0.344723946f), new Float3(0.1448607981f, -0.2387819045f, 0.3528435224f), new Float3(-0.3837065682f, -0.2206398454f, 0.08116235683f), new Float3(-0.4382627882f, -0.09082753406f, -0.04664855374f), new Float3(-0.37728353f, 0.05445141085f, 0.2391488697f), new Float3(0.1259579313f, 0.348394558f, 0.2554522098f), new Float3(-0.1406285511f, -0.270877371f, -0.3306796947f), new Float3(-0.1580694418f, 0.4162931958f, -0.06491553533f), new Float3(0.2477612106f, -0.2927867412f, -0.2353514536f), new Float3(0.2916132853f, 0.3312535401f, 0.08793624968f), new Float3(0.07365265219f, -0.1666159848f, 0.411478311f), new Float3(-0.26126526f, -0.2422237692f, 0.2748965434f), new Float3(-0.3721862032f, 0.252790166f, 0.008634938242f), new Float3(-0.3691191571f, -0.255281188f, 0.03290232422f), new Float3(0.2278441737f, -0.3358364886f, 0.1944244981f), new Float3(0.363398169f, -0.2310190248f, 0.1306597909f), new Float3(-0.304231482f, -0.2698452035f, 0.1926830856f), new Float3(-0.3199312232f, 0.316332536f, -0.008816977938f), new Float3(0.2874852279f, 0.1642275508f, -0.304764754f), new Float3(-0.1451096801f, 0.3277541114f, -0.2720669462f), new Float3(0.3220090754f, 0.0511344108f, 0.3101538769f), new Float3(-0.1247400865f, -0.04333605335f, -0.4301882115f), new Float3(-0.2829555867f, -0.3056190617f, -0.1703910946f), new Float3(0.1069384374f, 0.3491024667f, -0.2630430352f), new Float3(-0.1420661144f, -0.3055376754f, -0.2982682484f), new Float3(-0.250548338f, 0.3156466809f, -0.2002316239f), new Float3(0.3265787872f, 0.1871229129f, 0.2466400438f), new Float3(0.07646097258f, -0.3026690852f, 0.324106687f), new Float3(0.3451771584f, 0.2757120714f, -0.0856480183f), new Float3(0.298137964f, 0.2852657134f, 0.179547284f), new Float3(0.2812250376f, 0.3466716415f, 0.05684409612f), new Float3(0.4390345476f, -0.09790429955f, -0.01278335452f), new Float3(0.2148373234f, 0.1850172527f, 0.3494474791f), new Float3(0.2595421179f, -0.07946825393f, 0.3589187731f), new Float3(0.3182823114f, -0.307355516f, -0.08203022006f), new Float3(-0.4089859285f, -0.04647718411f, 0.1818526372f), new Float3(-0.2826749061f, 0.07417482322f, 0.3421885344f), new Float3(0.3483864637f, 0.225442246f, -0.1740766085f), new Float3(-0.3226415069f, -0.1420585388f, -0.2796816575f), new Float3(0.4330734858f, -0.118868561f, -0.02859407492f), new Float3(-0.08717822568f, -0.3909896417f, -0.2050050172f), new Float3(-0.2149678299f, 0.3939973956f, -0.03247898316f), new Float3(-0.2687330705f, 0.322686276f, -0.1617284888f), new Float3(0.2105665099f, -0.1961317136f, -0.3459683451f), new Float3(0.4361845915f, -0.1105517485f, 0.004616608544f), new Float3(0.05333333359f, -0.313639498f, -0.3182543336f), new Float3(-0.05986216652f, 0.1361029153f, -0.4247264031f), new Float3(0.3664988455f, 0.2550543014f, -0.05590974511f), new Float3(-0.2341015558f, -0.182405731f, 0.3382670703f), new Float3(-0.04730947785f, -0.4222150243f, -0.1483114513f), new Float3(-0.2391566239f, -0.2577696514f, -0.2808182972f), new Float3(-0.1242081035f, 0.4256953395f, -0.07652336246f), new Float3(0.2614832715f, -0.3650179274f, 0.02980623099f), new Float3(-0.2728794681f, -0.3499628774f, 0.07458404908f), new Float3(0.007892900508f, -0.1672771315f, 0.4176793787f), new Float3(-0.01730330376f, 0.2978486637f, -0.3368779738f), new Float3(0.2054835762f, -0.3252600376f, -0.2334146693f), new Float3(-0.3231994983f, 0.1564282844f, -0.2712420987f), new Float3(-0.2669545963f, 0.2599343665f, -0.2523278991f), new Float3(-0.05554372779f, 0.3170813944f, -0.3144428146f), new Float3(-0.2083935713f, -0.310922837f, -0.2497981362f), new Float3(0.06989323478f, -0.3156141536f, 0.3130537363f), new Float3(0.3847566193f, -0.1605309138f, -0.1693876312f), new Float3(-0.3026215288f, -0.3001537679f, -0.1443188342f), new Float3(0.3450735512f, 0.08611519592f, 0.2756962409f), new Float3(0.1814473292f, -0.2788782453f, -0.3029914042f), new Float3(-0.03855010448f, 0.09795110726f, 0.4375151083f), new Float3(0.3533670318f, 0.2665752752f, 0.08105160988f), new Float3(-0.007945601311f, 0.140359426f, -0.4274764309f), new Float3(0.4063099273f, -0.1491768253f, -0.1231199324f), new Float3(-0.2016773589f, 0.008816271194f, -0.4021797064f), new Float3(-0.07527055435f, -0.425643481f, -0.1251477955f), - }; - private static int FastFloor(float f) { return (f >= 0 ? (int) f : (int) f - 1); } @@ -240,22 +100,6 @@ public class FastNoise { return t * t * t * p + t * t * ((a - b) - p) + t * (c - a) + b; } - private void CalculateFractalBounding() { - float amp = m_gain; - float ampFractal = 1; - for (int i = 1; i < m_octaves; i++) { - ampFractal += amp; - amp *= m_gain; - } - m_fractalBounding = 1 / ampFractal; - } - - // Hashing - private final static int X_PRIME = 1619; - private final static int Y_PRIME = 31337; - private final static int Z_PRIME = 6971; - private final static int W_PRIME = 1013; - private static int Hash2D(int seed, int x, int y) { int hash = seed; hash ^= X_PRIME * x; @@ -378,6 +222,106 @@ public class FastNoise { return ((hash & 4) == 0 ? -a : a) + ((hash & 2) == 0 ? -b : b) + ((hash & 1) == 0 ? -c : c); } + // Returns the seed used by this object + public int GetSeed() { + return m_seed; + } + + // Sets seed used for all noise types + // Default: 1337 + public void SetSeed(int seed) { + m_seed = seed; + } + + // Sets frequency for all noise types + // Default: 0.01 + public void SetFrequency(float frequency) { + m_frequency = frequency; + } + + // Changes the interpolation method used to smooth between noise values + // Possible interpolation methods (lowest to highest quality) : + // - Linear + // - Hermite + // - Quintic + // Used in Value, Gradient Noise and Position Perturbing + // Default: Quintic + public void SetInterp(Interp interp) { + m_interp = interp; + } + + // Sets noise return type of GetNoise(...) + // Default: Simplex + public void SetNoiseType(NoiseType noiseType) { + m_noiseType = noiseType; + } + + // Sets octave count for all fractal noise types + // Default: 3 + public void SetFractalOctaves(int octaves) { + m_octaves = octaves; + CalculateFractalBounding(); + } + + // Sets octave lacunarity for all fractal noise types + // Default: 2.0 + public void SetFractalLacunarity(float lacunarity) { + m_lacunarity = lacunarity; + } + + // Sets octave gain for all fractal noise types + // Default: 0.5 + public void SetFractalGain(float gain) { + m_gain = gain; + CalculateFractalBounding(); + } + + // Sets method for combining octaves in all fractal noise types + // Default: FBM + public void SetFractalType(FractalType fractalType) { + m_fractalType = fractalType; + } + + // Sets return type from cellular noise calculations + // Note: NoiseLookup requires another FastNoise object be set with + // SetCellularNoiseLookup() to function + // Default: CellValue + public void SetCellularDistanceFunction(CellularDistanceFunction cellularDistanceFunction) { + m_cellularDistanceFunction = cellularDistanceFunction; + } + + // Sets distance function used in cellular noise calculations + // Default: Euclidean + public void SetCellularReturnType(CellularReturnType cellularReturnType) { + m_cellularReturnType = cellularReturnType; + } + + // Noise used to calculate a cell value if cellular return type is NoiseLookup + // The lookup value is acquired through GetNoise() so ensure you SetNoiseType() + // on the noise lookup, value, gradient or simplex is recommended + public void SetCellularNoiseLookup(FastNoise noise) { + m_cellularNoiseLookup = noise; + } + + // White Noise + + // Sets the maximum perturb distance from original location when using + // GradientPerturb{Fractal}(...) + // Default: 1.0 + public void SetGradientPerturbAmp(float gradientPerturbAmp) { + m_gradientPerturbAmp = gradientPerturbAmp / (float) 0.45; + } + + private void CalculateFractalBounding() { + float amp = m_gain; + float ampFractal = 1; + for (int i = 1; i < m_octaves; i++) { + ampFractal += amp; + amp *= m_gain; + } + m_fractalBounding = 1 / ampFractal; + } + public float GetNoise(float x, float y, float z) { x *= m_frequency; y *= m_frequency; @@ -525,8 +469,6 @@ public class FastNoise { } } - // White Noise - private int FloatCast2Int(float f) { int i = Float.floatToRawIntBits(f); @@ -1071,10 +1013,6 @@ public class FastNoise { return SingleSimplex(m_seed, x * m_frequency, y * m_frequency, z * m_frequency); } - private final static float F3 = (float) (1.0 / 3.0); - private final static float G3 = (float) (1.0 / 6.0); - private final static float G33 = G3 * 3 - 1; - private float SingleSimplex(int seed, float x, float y, float z) { float t = (x + y + z) * F3; int i = FastFloor(x + t); @@ -1251,16 +1189,12 @@ public class FastNoise { return sum; } - public float GetSimplex(float x, float y) { - return SingleSimplex(m_seed, x * m_frequency, y * m_frequency); - } - // private final static float F2 = (float) (1.0 / 2.0); // private final static float G2 = (float) (1.0 / 4.0); - private final static float SQRT3 = (float) 1.7320508075688772935274463415059; - private final static float F2 = 0.5f * (SQRT3 - 1.0f); - private final static float G2 = (3.0f - SQRT3) / 6.0f; + public float GetSimplex(float x, float y) { + return SingleSimplex(m_seed, x * m_frequency, y * m_frequency); + } private float SingleSimplex(int seed, float x, float y) { float t = (x + y) * F2; @@ -1321,12 +1255,6 @@ public class FastNoise { return SingleSimplex(m_seed, x * m_frequency, y * m_frequency, z * m_frequency, w * m_frequency); } - private static final byte[] SIMPLEX_4D = {0, 1, 2, 3, 0, 1, 3, 2, 0, 0, 0, 0, 0, 2, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 0, 0, 2, 1, 3, 0, 0, 0, 0, 0, 3, 1, 2, 0, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 3, 0, 0, 0, 0, 1, 3, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 1, 2, 3, 1, 0, 1, 0, 2, 3, 1, 0, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 1, 0, 0, 0, 0, 2, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1, 2, 3, 0, 2, 1, 0, 0, 0, 0, 3, 1, 2, 0, 2, 1, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 0, 2, 0, 0, 0, 0, 3, 2, 0, 1, 3, 2, 1, 0 - }; - - private final static float F4 = (float) ((2.23606797 - 1.0) / 4.0); - private final static float G4 = (float) ((5.0 - 2.23606797) / 20.0); - private float SingleSimplex(int seed, float x, float y, float z, float w) { float n0, n1, n2, n3, n4; float t = (x + y + z + w) * F4; @@ -1497,8 +1425,6 @@ public class FastNoise { return SingleCubic(m_seed, x * m_frequency, y * m_frequency, z * m_frequency); } - private final static float CUBIC_3D_BOUNDING = 1 / (float) (1.5 * 1.5 * 1.5); - private float SingleCubic(int seed, float x, float y, float z) { int x1 = FastFloor(x); int y1 = FastFloor(y); @@ -1595,8 +1521,6 @@ public class FastNoise { return SingleCubic(0, x, y); } - private final static float CUBIC_2D_BOUNDING = 1 / (float) (1.5 * 1.5); - private float SingleCubic(int seed, float x, float y) { int x1 = FastFloor(x); int y1 = FastFloor(y); @@ -2118,4 +2042,65 @@ public class FastNoise { v2.y += Lerp(ly0x, ly1x, ys) * perturbAmp; } + public enum NoiseType { + Value, + ValueFractal, + Perlin, + PerlinFractal, + Simplex, + SimplexFractal, + Cellular, + WhiteNoise, + Cubic, + CubicFractal + } + + public enum Interp { + Linear, + Hermite, + Quintic + } + + public enum FractalType { + FBM, + Billow, + RigidMulti + } + + public enum CellularDistanceFunction { + Euclidean, + Manhattan, + Natural + } + + public enum CellularReturnType { + CellValue, + NoiseLookup, + Distance, + Distance2, + Distance2Add, + Distance2Sub, + Distance2Mul, + Distance2Div + } + + private static class Float2 { + public final float x, y; + + public Float2(float x, float y) { + this.x = x; + this.y = y; + } + } + + private static class Float3 { + public final float x, y, z; + + public Float3(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + } + } + } \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/noise/FastNoiseDouble.java b/src/main/java/com/volmit/iris/util/noise/FastNoiseDouble.java index 6db2b0c7f..86d65dce8 100644 --- a/src/main/java/com/volmit/iris/util/noise/FastNoiseDouble.java +++ b/src/main/java/com/volmit/iris/util/noise/FastNoiseDouble.java @@ -21,64 +21,42 @@ import com.volmit.iris.util.math.Vector2f; import com.volmit.iris.util.math.Vector3f; public class FastNoiseDouble { - public enum NoiseType { - Value, - ValueFractal, - Perlin, - PerlinFractal, - Simplex, - SimplexFractal, - Cellular, - WhiteNoise, - Cubic, - CubicFractal - } - - public enum Longerp { - Linear, - Hermite, - Qulongic - } - - public enum FractalType { - FBM, - Billow, - RigidMulti - } - - public enum CellularDistanceFunction { - Euclidean, - Manhattan, - Natural - } - - public enum CellularReturnType { - CellValue, - NoiseLookup, - Distance, - Distance2, - Distance2Add, - Distance2Sub, - Distance2Mul, - Distance2Div - } - + private static final Double2[] GRAD_2D = {new Double2(-1, -1), new Double2(1, -1), new Double2(-1, 1), new Double2(1, 1), new Double2(0, -1), new Double2(-1, 0), new Double2(0, 1), new Double2(1, 0), + }; + private static final Double3[] GRAD_3D = {new Double3(1, 1, 0), new Double3(-1, 1, 0), new Double3(1, -1, 0), new Double3(-1, -1, 0), new Double3(1, 0, 1), new Double3(-1, 0, 1), new Double3(1, 0, -1), new Double3(-1, 0, -1), new Double3(0, 1, 1), new Double3(0, -1, 1), new Double3(0, 1, -1), new Double3(0, -1, -1), new Double3(1, 1, 0), new Double3(0, -1, 1), new Double3(-1, 1, 0), new Double3(0, -1, -1), + }; + private static final Double2[] CELL_2D = {new Double2(-0.4313539279f, 0.1281943404f), new Double2(-0.1733316799f, 0.415278375f), new Double2(-0.2821957395f, -0.3505218461f), new Double2(-0.2806473808f, 0.3517627718f), new Double2(0.3125508975f, -0.3237467165f), new Double2(0.3383018443f, -0.2967353402f), new Double2(-0.4393982022f, -0.09710417025f), new Double2(-0.4460443703f, -0.05953502905f), new Double2(-0.302223039f, 0.3334085102f), new Double2(-0.212681052f, -0.3965687458f), new Double2(-0.2991156529f, 0.3361990872f), new Double2(0.2293323691f, 0.3871778202f), new Double2(0.4475439151f, -0.04695150755f), new Double2(0.1777518f, 0.41340573f), new Double2(0.1688522499f, -0.4171197882f), new Double2(-0.0976597166f, 0.4392750616f), new Double2(0.08450188373f, 0.4419948321f), new Double2(-0.4098760448f, -0.1857461384f), new Double2(0.3476585782f, -0.2857157906f), new Double2(-0.3350670039f, -0.30038326f), new Double2(0.2298190031f, -0.3868891648f), new Double2(-0.01069924099f, 0.449872789f), new Double2(-0.4460141246f, -0.05976119672f), new Double2(0.3650293864f, 0.2631606867f), new Double2(-0.349479423f, 0.2834856838f), new Double2(-0.4122720642f, 0.1803655873f), new Double2(-0.267327811f, 0.3619887311f), new Double2(0.322124041f, -0.3142230135f), new Double2(0.2880445931f, -0.3457315612f), new Double2(0.3892170926f, -0.2258540565f), new Double2(0.4492085018f, -0.02667811596f), new Double2(-0.4497724772f, 0.01430799601f), new Double2(0.1278175387f, -0.4314657307f), new Double2(-0.03572100503f, 0.4485799926f), new Double2(-0.4297407068f, -0.1335025276f), new Double2(-0.3217817723f, 0.3145735065f), new Double2(-0.3057158873f, 0.3302087162f), new Double2(-0.414503978f, 0.1751754899f), new Double2(-0.3738139881f, 0.2505256519f), new Double2(0.2236891408f, -0.3904653228f), new Double2(0.002967775577f, -0.4499902136f), new Double2(0.1747128327f, -0.4146991995f), new Double2(-0.4423772489f, -0.08247647938f), new Double2(-0.2763960987f, -0.355112935f), new Double2(-0.4019385906f, -0.2023496216f), new Double2(0.3871414161f, -0.2293938184f), new Double2(-0.430008727f, 0.1326367019f), new Double2(-0.03037574274f, -0.4489736231f), new Double2(-0.3486181573f, 0.2845441624f), new Double2(0.04553517144f, -0.4476902368f), new Double2(-0.0375802926f, 0.4484280562f), new Double2(0.3266408905f, 0.3095250049f), new Double2(0.06540017593f, -0.4452222108f), new Double2(0.03409025829f, 0.448706869f), new Double2(-0.4449193635f, 0.06742966669f), new Double2(-0.4255936157f, -0.1461850686f), new Double2(0.449917292f, 0.008627302568f), new Double2(0.05242606404f, 0.4469356864f), new Double2(-0.4495305179f, -0.02055026661f), new Double2(-0.1204775703f, 0.4335725488f), new Double2(-0.341986385f, -0.2924813028f), new Double2(0.3865320182f, 0.2304191809f), new Double2(0.04506097811f, -0.447738214f), new Double2(-0.06283465979f, 0.4455915232f), new Double2(0.3932600341f, -0.2187385324f), new Double2(0.4472261803f, -0.04988730975f), new Double2(0.3753571011f, -0.2482076684f), new Double2(-0.273662295f, 0.357223947f), new Double2(0.1700461538f, 0.4166344988f), new Double2(0.4102692229f, 0.1848760794f), new Double2(0.323227187f, -0.3130881435f), new Double2(-0.2882310238f, -0.3455761521f), new Double2(0.2050972664f, 0.4005435199f), new Double2(0.4414085979f, -0.08751256895f), new Double2(-0.1684700334f, 0.4172743077f), new Double2(-0.003978032396f, 0.4499824166f), new Double2(-0.2055133639f, 0.4003301853f), new Double2(-0.006095674897f, -0.4499587123f), new Double2(-0.1196228124f, -0.4338091548f), new Double2(0.3901528491f, -0.2242337048f), new Double2(0.01723531752f, 0.4496698165f), new Double2(-0.3015070339f, 0.3340561458f), new Double2(-0.01514262423f, -0.4497451511f), new Double2(-0.4142574071f, -0.1757577897f), new Double2(-0.1916377265f, -0.4071547394f), new Double2(0.3749248747f, 0.2488600778f), new Double2(-0.2237774255f, 0.3904147331f), new Double2(-0.4166343106f, -0.1700466149f), new Double2(0.3619171625f, 0.267424695f), new Double2(0.1891126846f, -0.4083336779f), new Double2(-0.3127425077f, 0.323561623f), new Double2(-0.3281807787f, 0.307891826f), new Double2(-0.2294806661f, 0.3870899429f), new Double2(-0.3445266136f, 0.2894847362f), new Double2(-0.4167095422f, -0.1698621719f), new Double2(-0.257890321f, -0.3687717212f), new Double2(-0.3612037825f, 0.2683874578f), new Double2(0.2267996491f, 0.3886668486f), new Double2(0.207157062f, 0.3994821043f), new Double2(0.08355176718f, -0.4421754202f), new Double2(-0.4312233307f, 0.1286329626f), new Double2(0.3257055497f, 0.3105090899f), new Double2(0.177701095f, -0.4134275279f), new Double2(-0.445182522f, 0.06566979625f), new Double2(0.3955143435f, 0.2146355146f), new Double2(-0.4264613988f, 0.1436338239f), new Double2(-0.3793799665f, -0.2420141339f), new Double2(0.04617599081f, -0.4476245948f), new Double2(-0.371405428f, -0.2540826796f), new Double2(0.2563570295f, -0.3698392535f), new Double2(0.03476646309f, 0.4486549822f), new Double2(-0.3065454405f, 0.3294387544f), new Double2(-0.2256979823f, 0.3893076172f), new Double2(0.4116448463f, -0.1817925206f), new Double2(-0.2907745828f, -0.3434387019f), new Double2(0.2842278468f, -0.348876097f), new Double2(0.3114589359f, -0.3247973695f), new Double2(0.4464155859f, -0.0566844308f), new Double2(-0.3037334033f, -0.3320331606f), new Double2(0.4079607166f, 0.1899159123f), new Double2(-0.3486948919f, -0.2844501228f), new Double2(0.3264821436f, 0.3096924441f), new Double2(0.3211142406f, 0.3152548881f), new Double2(0.01183382662f, 0.4498443737f), new Double2(0.4333844092f, 0.1211526057f), new Double2(0.3118668416f, 0.324405723f), new Double2(-0.272753471f, 0.3579183483f), new Double2(-0.422228622f, -0.1556373694f), new Double2(-0.1009700099f, -0.4385260051f), new Double2(-0.2741171231f, -0.3568750521f), new Double2(-0.1465125133f, 0.4254810025f), new Double2(0.2302279044f, -0.3866459777f), new Double2(-0.3699435608f, 0.2562064828f), new Double2(0.105700352f, -0.4374099171f), new Double2(-0.2646713633f, 0.3639355292f), new Double2(0.3521828122f, 0.2801200935f), new Double2(-0.1864187807f, -0.4095705534f), new Double2(0.1994492955f, -0.4033856449f), new Double2(0.3937065066f, 0.2179339044f), new Double2(-0.3226158377f, 0.3137180602f), new Double2(0.3796235338f, 0.2416318948f), new Double2(0.1482921929f, 0.4248640083f), new Double2(-0.407400394f, 0.1911149365f), new Double2(0.4212853031f, 0.1581729856f), new Double2(-0.2621297173f, 0.3657704353f), new Double2(-0.2536986953f, -0.3716678248f), new Double2(-0.2100236383f, 0.3979825013f), new Double2(0.3624152444f, 0.2667493029f), new Double2(-0.3645038479f, -0.2638881295f), new Double2(0.2318486784f, 0.3856762766f), new Double2(-0.3260457004f, 0.3101519002f), new Double2(-0.2130045332f, -0.3963950918f), new Double2(0.3814998766f, -0.2386584257f), new Double2(-0.342977305f, 0.2913186713f), new Double2(-0.4355865605f, 0.1129794154f), new Double2(-0.2104679605f, 0.3977477059f), new Double2(0.3348364681f, -0.3006402163f), new Double2(0.3430468811f, 0.2912367377f), new Double2(-0.2291836801f, -0.3872658529f), new Double2(0.2547707298f, -0.3709337882f), new Double2(0.4236174945f, -0.151816397f), new Double2(-0.15387742f, 0.4228731957f), new Double2(-0.4407449312f, 0.09079595574f), new Double2(-0.06805276192f, -0.444824484f), new Double2(0.4453517192f, -0.06451237284f), new Double2(0.2562464609f, -0.3699158705f), new Double2(0.3278198355f, -0.3082761026f), new Double2(-0.4122774207f, -0.1803533432f), new Double2(0.3354090914f, -0.3000012356f), new Double2(0.446632869f, -0.05494615882f), new Double2(-0.1608953296f, 0.4202531296f), new Double2(-0.09463954939f, 0.4399356268f), new Double2(-0.02637688324f, -0.4492262904f), new Double2(0.447102804f, -0.05098119915f), new Double2(-0.4365670908f, 0.1091291678f), new Double2(-0.3959858651f, 0.2137643437f), new Double2(-0.4240048207f, -0.1507312575f), new Double2(-0.3882794568f, 0.2274622243f), new Double2(-0.4283652566f, -0.1378521198f), new Double2(0.3303888091f, 0.305521251f), new Double2(0.3321434919f, -0.3036127481f), new Double2(-0.413021046f, -0.1786438231f), new Double2(0.08403060337f, -0.4420846725f), new Double2(-0.3822882919f, 0.2373934748f), new Double2(-0.3712395594f, -0.2543249683f), new Double2(0.4472363971f, -0.04979563372f), new Double2(-0.4466591209f, 0.05473234629f), new Double2(0.0486272539f, -0.4473649407f), new Double2(-0.4203101295f, -0.1607463688f), new Double2(0.2205360833f, 0.39225481f), new Double2(-0.3624900666f, 0.2666476169f), new Double2(-0.4036086833f, -0.1989975647f), new Double2(0.2152727807f, 0.3951678503f), new Double2(-0.4359392962f, -0.1116106179f), new Double2(0.4178354266f, 0.1670735057f), new Double2(0.2007630161f, 0.4027334247f), new Double2(-0.07278067175f, -0.4440754146f), new Double2(0.3644748615f, -0.2639281632f), new Double2(-0.4317451775f, 0.126870413f), new Double2(-0.297436456f, 0.3376855855f), new Double2(-0.2998672222f, 0.3355289094f), new Double2(-0.2673674124f, 0.3619594822f), new Double2(0.2808423357f, 0.3516071423f), new Double2(0.3498946567f, 0.2829730186f), new Double2(-0.2229685561f, 0.390877248f), new Double2(0.3305823267f, 0.3053118493f), new Double2(-0.2436681211f, -0.3783197679f), new Double2(-0.03402776529f, 0.4487116125f), new Double2(-0.319358823f, 0.3170330301f), new Double2(0.4454633477f, -0.06373700535f), new Double2(0.4483504221f, 0.03849544189f), new Double2(-0.4427358436f, -0.08052932871f), new Double2(0.05452298565f, 0.4466847255f), new Double2(-0.2812560807f, 0.3512762688f), new Double2(0.1266696921f, 0.4318041097f), new Double2(-0.3735981243f, 0.2508474468f), new Double2(0.2959708351f, -0.3389708908f), new Double2(-0.3714377181f, 0.254035473f), new Double2(-0.404467102f, -0.1972469604f), new Double2(0.1636165687f, -0.419201167f), new Double2(0.3289185495f, -0.3071035458f), new Double2(-0.2494824991f, -0.3745109914f), new Double2(0.03283133272f, 0.4488007393f), new Double2(-0.166306057f, -0.4181414777f), new Double2(-0.106833179f, 0.4371346153f), new Double2(0.06440260376f, -0.4453676062f), new Double2(-0.4483230967f, 0.03881238203f), new Double2(-0.421377757f, -0.1579265206f), new Double2(0.05097920662f, -0.4471030312f), new Double2(0.2050584153f, -0.4005634111f), new Double2(0.4178098529f, -0.167137449f), new Double2(-0.3565189504f, -0.2745801121f), new Double2(0.4478398129f, 0.04403977727f), new Double2(-0.3399999602f, -0.2947881053f), new Double2(0.3767121994f, 0.2461461331f), new Double2(-0.3138934434f, 0.3224451987f), new Double2(-0.1462001792f, -0.4255884251f), new Double2(0.3970290489f, -0.2118205239f), new Double2(0.4459149305f, -0.06049689889f), new Double2(-0.4104889426f, -0.1843877112f), new Double2(0.1475103971f, -0.4251360756f), new Double2(0.09258030352f, 0.4403735771f), new Double2(-0.1589664637f, -0.4209865359f), new Double2(0.2482445008f, 0.3753327428f), new Double2(0.4383624232f, -0.1016778537f), new Double2(0.06242802956f, 0.4456486745f), new Double2(0.2846591015f, -0.3485243118f), new Double2(-0.344202744f, -0.2898697484f), new Double2(0.1198188883f, -0.4337550392f), new Double2(-0.243590703f, 0.3783696201f), new Double2(0.2958191174f, -0.3391033025f), new Double2(-0.1164007991f, 0.4346847754f), new Double2(0.1274037151f, -0.4315881062f), new Double2(0.368047306f, 0.2589231171f), new Double2(0.2451436949f, 0.3773652989f), new Double2(-0.4314509715f, 0.12786735f), + }; + private static final Double3[] CELL_3D = {new Double3(0.1453787434f, -0.4149781685f, -0.0956981749f), new Double3(-0.01242829687f, -0.1457918398f, -0.4255470325f), new Double3(0.2877979582f, -0.02606483451f, -0.3449535616f), new Double3(-0.07732986802f, 0.2377094325f, 0.3741848704f), new Double3(0.1107205875f, -0.3552302079f, -0.2530858567f), new Double3(0.2755209141f, 0.2640521179f, -0.238463215f), new Double3(0.294168941f, 0.1526064594f, 0.3044271714f), new Double3(0.4000921098f, -0.2034056362f, 0.03244149937f), new Double3(-0.1697304074f, 0.3970864695f, -0.1265461359f), new Double3(-0.1483224484f, -0.3859694688f, 0.1775613147f), new Double3(0.2623596946f, -0.2354852944f, 0.2796677792f), new Double3(-0.2709003183f, 0.3505271138f, -0.07901746678f), new Double3(-0.03516550699f, 0.3885234328f, 0.2243054374f), new Double3(-0.1267712655f, 0.1920044036f, 0.3867342179f), new Double3(0.02952021915f, 0.4409685861f, 0.08470692262f), new Double3(-0.2806854217f, -0.266996757f, 0.2289725438f), new Double3(-0.171159547f, 0.2141185563f, 0.3568720405f), new Double3(0.2113227183f, 0.3902405947f, -0.07453178509f), new Double3(-0.1024352839f, 0.2128044156f, -0.3830421561f), new Double3(-0.3304249877f, -0.1566986703f, 0.2622305365f), new Double3(0.2091111325f, 0.3133278055f, -0.2461670583f), new Double3(0.344678154f, -0.1944240454f, -0.2142341261f), new Double3(0.1984478035f, -0.3214342325f, -0.2445373252f), new Double3(-0.2929008603f, 0.2262915116f, 0.2559320961f), new Double3(-0.1617332831f, 0.006314769776f, -0.4198838754f), new Double3(-0.3582060271f, -0.148303178f, -0.2284613961f), new Double3(-0.1852067326f, -0.3454119342f, -0.2211087107f), new Double3(0.3046301062f, 0.1026310383f, 0.314908508f), new Double3(-0.03816768434f, -0.2551766358f, -0.3686842991f), new Double3(-0.4084952196f, 0.1805950793f, 0.05492788837f), new Double3(-0.02687443361f, -0.2749741471f, 0.3551999201f), new Double3(-0.03801098351f, 0.3277859044f, 0.3059600725f), new Double3(0.2371120802f, 0.2900386767f, -0.2493099024f), new Double3(0.4447660503f, 0.03946930643f, 0.05590469027f), new Double3(0.01985147278f, -0.01503183293f, -0.4493105419f), new Double3(0.4274339143f, 0.03345994256f, -0.1366772882f), new Double3(-0.2072988631f, 0.2871414597f, -0.2776273824f), new Double3(-0.3791240978f, 0.1281177671f, 0.2057929936f), new Double3(-0.2098721267f, -0.1007087278f, -0.3851122467f), new Double3(0.01582798878f, 0.4263894424f, 0.1429738373f), new Double3(-0.1888129464f, -0.3160996813f, -0.2587096108f), new Double3(0.1612988974f, -0.1974805082f, -0.3707885038f), new Double3(-0.08974491322f, 0.229148752f, -0.3767448739f), new Double3(0.07041229526f, 0.4150230285f, -0.1590534329f), new Double3(-0.1082925611f, -0.1586061639f, 0.4069604477f), new Double3(0.2474100658f, -0.3309414609f, 0.1782302128f), new Double3(-0.1068836661f, -0.2701644537f, -0.3436379634f), new Double3(0.2396452163f, 0.06803600538f, -0.3747549496f), new Double3(-0.3063886072f, 0.2597428179f, 0.2028785103f), new Double3(0.1593342891f, -0.3114350249f, -0.2830561951f), new Double3(0.2709690528f, 0.1412648683f, -0.3303331794f), new Double3(-0.1519780427f, 0.3623355133f, 0.2193527988f), new Double3(0.1699773681f, 0.3456012883f, 0.2327390037f), new Double3(-0.1986155616f, 0.3836276443f, -0.1260225743f), new Double3(-0.1887482106f, -0.2050154888f, -0.353330953f), new Double3(0.2659103394f, 0.3015631259f, -0.2021172246f), new Double3(-0.08838976154f, -0.4288819642f, -0.1036702021f), new Double3(-0.04201869311f, 0.3099592485f, 0.3235115047f), new Double3(-0.3230334656f, 0.201549922f, -0.2398478873f), new Double3(0.2612720941f, 0.2759854499f, -0.2409749453f), new Double3(0.385713046f, 0.2193460345f, 0.07491837764f), new Double3(0.07654967953f, 0.3721732183f, 0.241095919f), new Double3(0.4317038818f, -0.02577753072f, 0.1243675091f), new Double3(-0.2890436293f, -0.3418179959f, -0.04598084447f), new Double3(-0.2201947582f, 0.383023377f, -0.08548310451f), new Double3(0.4161322773f, -0.1669634289f, -0.03817251927f), new Double3(0.2204718095f, 0.02654238946f, -0.391391981f), new Double3(-0.1040307469f, 0.3890079625f, -0.2008741118f), new Double3(-0.1432122615f, 0.371614387f, -0.2095065525f), new Double3(0.3978380468f, -0.06206669342f, 0.2009293758f), new Double3(-0.2599274663f, 0.2616724959f, -0.2578084893f), new Double3(0.4032618332f, -0.1124593585f, 0.1650235939f), new Double3(-0.08953470255f, -0.3048244735f, 0.3186935478f), new Double3(0.118937202f, -0.2875221847f, 0.325092195f), new Double3(0.02167047076f, -0.03284630549f, -0.4482761547f), new Double3(-0.3411343612f, 0.2500031105f, 0.1537068389f), new Double3(0.3162964612f, 0.3082064153f, -0.08640228117f), new Double3(0.2355138889f, -0.3439334267f, -0.1695376245f), new Double3(-0.02874541518f, -0.3955933019f, 0.2125550295f), new Double3(-0.2461455173f, 0.02020282325f, -0.3761704803f), new Double3(0.04208029445f, -0.4470439576f, 0.02968078139f), new Double3(0.2727458746f, 0.2288471896f, -0.2752065618f), new Double3(-0.1347522818f, -0.02720848277f, -0.4284874806f), new Double3(0.3829624424f, 0.1231931484f, -0.2016512234f), new Double3(-0.3547613644f, 0.1271702173f, 0.2459107769f), new Double3(0.2305790207f, 0.3063895591f, 0.2354968222f), new Double3(-0.08323845599f, -0.1922245118f, 0.3982726409f), new Double3(0.2993663085f, -0.2619918095f, -0.2103333191f), new Double3(-0.2154865723f, 0.2706747713f, 0.287751117f), new Double3(0.01683355354f, -0.2680655787f, -0.3610505186f), new Double3(0.05240429123f, 0.4335128183f, -0.1087217856f), new Double3(0.00940104872f, -0.4472890582f, 0.04841609928f), new Double3(0.3465688735f, 0.01141914583f, -0.2868093776f), new Double3(-0.3706867948f, -0.2551104378f, 0.003156692623f), new Double3(0.2741169781f, 0.2139972417f, -0.2855959784f), new Double3(0.06413433865f, 0.1708718512f, 0.4113266307f), new Double3(-0.388187972f, -0.03973280434f, -0.2241236325f), new Double3(0.06419469312f, -0.2803682491f, 0.3460819069f), new Double3(-0.1986120739f, -0.3391173584f, 0.2192091725f), new Double3(-0.203203009f, -0.3871641506f, 0.1063600375f), new Double3(-0.1389736354f, -0.2775901578f, -0.3257760473f), new Double3(-0.06555641638f, 0.342253257f, -0.2847192729f), new Double3(-0.2529246486f, -0.2904227915f, 0.2327739768f), new Double3(0.1444476522f, 0.1069184044f, 0.4125570634f), new Double3(-0.3643780054f, -0.2447099973f, -0.09922543227f), new Double3(0.4286142488f, -0.1358496089f, -0.01829506817f), new Double3(0.165872923f, -0.3136808464f, -0.2767498872f), new Double3(0.2219610524f, -0.3658139958f, 0.1393320198f), new Double3(0.04322940318f, -0.3832730794f, 0.2318037215f), new Double3(-0.08481269795f, -0.4404869674f, -0.03574965489f), new Double3(0.1822082075f, -0.3953259299f, 0.1140946023f), new Double3(-0.3269323334f, 0.3036542563f, 0.05838957105f), new Double3(-0.4080485344f, 0.04227858267f, -0.184956522f), new Double3(0.2676025294f, -0.01299671652f, 0.36155217f), new Double3(0.3024892441f, -0.1009990293f, -0.3174892964f), new Double3(0.1448494052f, 0.425921681f, -0.0104580805f), new Double3(0.4198402157f, 0.08062320474f, 0.1404780841f), new Double3(-0.3008872161f, -0.333040905f, -0.03241355801f), new Double3(0.3639310428f, -0.1291284382f, -0.2310412139f), new Double3(0.3295806598f, 0.0184175994f, -0.3058388149f), new Double3(0.2776259487f, -0.2974929052f, -0.1921504723f), new Double3(0.4149000507f, -0.144793182f, -0.09691688386f), new Double3(0.145016715f, -0.0398992945f, 0.4241205002f), new Double3(0.09299023471f, -0.299732164f, -0.3225111565f), new Double3(0.1028907093f, -0.361266869f, 0.247789732f), new Double3(0.2683057049f, -0.07076041213f, -0.3542668666f), new Double3(-0.4227307273f, -0.07933161816f, -0.1323073187f), new Double3(-0.1781224702f, 0.1806857196f, -0.3716517945f), new Double3(0.4390788626f, -0.02841848598f, -0.09435116353f), new Double3(0.2972583585f, 0.2382799621f, -0.2394997452f), new Double3(-0.1707002821f, 0.2215845691f, 0.3525077196f), new Double3(0.3806686614f, 0.1471852559f, -0.1895464869f), new Double3(-0.1751445661f, -0.274887877f, 0.3102596268f), new Double3(-0.2227237566f, -0.2316778837f, 0.3149912482f), new Double3(0.1369633021f, 0.1341343041f, -0.4071228836f), new Double3(-0.3529503428f, -0.2472893463f, -0.129514612f), new Double3(-0.2590744185f, -0.2985577559f, -0.2150435121f), new Double3(-0.3784019401f, 0.2199816631f, -0.1044989934f), new Double3(-0.05635805671f, 0.1485737441f, 0.4210102279f), new Double3(0.3251428613f, 0.09666046873f, -0.2957006485f), new Double3(-0.4190995804f, 0.1406751354f, -0.08405978803f), new Double3(-0.3253150961f, -0.3080335042f, -0.04225456877f), new Double3(0.2857945863f, -0.05796152095f, 0.3427271751f), new Double3(-0.2733604046f, 0.1973770973f, -0.2980207554f), new Double3(0.219003657f, 0.2410037886f, -0.3105713639f), new Double3(0.3182767252f, -0.271342949f, 0.1660509868f), new Double3(-0.03222023115f, -0.3331161506f, -0.300824678f), new Double3(-0.3087780231f, 0.1992794134f, -0.2596995338f), new Double3(-0.06487611647f, -0.4311322747f, 0.1114273361f), new Double3(0.3921171432f, -0.06294284106f, -0.2116183942f), new Double3(-0.1606404506f, -0.358928121f, -0.2187812825f), new Double3(-0.03767771199f, -0.2290351443f, 0.3855169162f), new Double3(0.1394866832f, -0.3602213994f, 0.2308332918f), new Double3(-0.4345093872f, 0.005751117145f, 0.1169124335f), new Double3(-0.1044637494f, 0.4168128432f, -0.1336202785f), new Double3(0.2658727501f, 0.2551943237f, 0.2582393035f), new Double3(0.2051461999f, 0.1975390727f, 0.3484154868f), new Double3(-0.266085566f, 0.23483312f, 0.2766800993f), new Double3(0.07849405464f, -0.3300346342f, -0.2956616708f), new Double3(-0.2160686338f, 0.05376451292f, -0.3910546287f), new Double3(-0.185779186f, 0.2148499206f, 0.3490352499f), new Double3(0.02492421743f, -0.3229954284f, -0.3123343347f), new Double3(-0.120167831f, 0.4017266681f, 0.1633259825f), new Double3(-0.02160084693f, -0.06885389554f, 0.4441762538f), new Double3(0.2597670064f, 0.3096300784f, 0.1978643903f), new Double3(-0.1611553854f, -0.09823036005f, 0.4085091653f), new Double3(-0.3278896792f, 0.1461670309f, 0.2713366126f), new Double3(0.2822734956f, 0.03754421121f, -0.3484423997f), new Double3(0.03169341113f, 0.347405252f, -0.2842624114f), new Double3(0.2202613604f, -0.3460788041f, -0.1849713341f), new Double3(0.2933396046f, 0.3031973659f, 0.1565989581f), new Double3(-0.3194922995f, 0.2453752201f, -0.200538455f), new Double3(-0.3441586045f, -0.1698856132f, -0.2349334659f), new Double3(0.2703645948f, -0.3574277231f, 0.04060059933f), new Double3(0.2298568861f, 0.3744156221f, 0.0973588921f), new Double3(0.09326603877f, -0.3170108894f, 0.3054595587f), new Double3(-0.1116165319f, -0.2985018719f, 0.3177080142f), new Double3(0.2172907365f, -0.3460005203f, -0.1885958001f), new Double3(0.1991339479f, 0.3820341668f, -0.1299829458f), new Double3(-0.0541918155f, -0.2103145071f, 0.39412061f), new Double3(0.08871336998f, 0.2012117383f, 0.3926114802f), new Double3(0.2787673278f, 0.3505404674f, 0.04370535101f), new Double3(-0.322166438f, 0.3067213525f, 0.06804996813f), new Double3(-0.4277366384f, 0.132066775f, 0.04582286686f), new Double3(0.240131882f, -0.1612516055f, 0.344723946f), new Double3(0.1448607981f, -0.2387819045f, 0.3528435224f), new Double3(-0.3837065682f, -0.2206398454f, 0.08116235683f), new Double3(-0.4382627882f, -0.09082753406f, -0.04664855374f), new Double3(-0.37728353f, 0.05445141085f, 0.2391488697f), new Double3(0.1259579313f, 0.348394558f, 0.2554522098f), new Double3(-0.1406285511f, -0.270877371f, -0.3306796947f), new Double3(-0.1580694418f, 0.4162931958f, -0.06491553533f), new Double3(0.2477612106f, -0.2927867412f, -0.2353514536f), new Double3(0.2916132853f, 0.3312535401f, 0.08793624968f), new Double3(0.07365265219f, -0.1666159848f, 0.411478311f), new Double3(-0.26126526f, -0.2422237692f, 0.2748965434f), new Double3(-0.3721862032f, 0.252790166f, 0.008634938242f), new Double3(-0.3691191571f, -0.255281188f, 0.03290232422f), new Double3(0.2278441737f, -0.3358364886f, 0.1944244981f), new Double3(0.363398169f, -0.2310190248f, 0.1306597909f), new Double3(-0.304231482f, -0.2698452035f, 0.1926830856f), new Double3(-0.3199312232f, 0.316332536f, -0.008816977938f), new Double3(0.2874852279f, 0.1642275508f, -0.304764754f), new Double3(-0.1451096801f, 0.3277541114f, -0.2720669462f), new Double3(0.3220090754f, 0.0511344108f, 0.3101538769f), new Double3(-0.1247400865f, -0.04333605335f, -0.4301882115f), new Double3(-0.2829555867f, -0.3056190617f, -0.1703910946f), new Double3(0.1069384374f, 0.3491024667f, -0.2630430352f), new Double3(-0.1420661144f, -0.3055376754f, -0.2982682484f), new Double3(-0.250548338f, 0.3156466809f, -0.2002316239f), new Double3(0.3265787872f, 0.1871229129f, 0.2466400438f), new Double3(0.07646097258f, -0.3026690852f, 0.324106687f), new Double3(0.3451771584f, 0.2757120714f, -0.0856480183f), new Double3(0.298137964f, 0.2852657134f, 0.179547284f), new Double3(0.2812250376f, 0.3466716415f, 0.05684409612f), new Double3(0.4390345476f, -0.09790429955f, -0.01278335452f), new Double3(0.2148373234f, 0.1850172527f, 0.3494474791f), new Double3(0.2595421179f, -0.07946825393f, 0.3589187731f), new Double3(0.3182823114f, -0.307355516f, -0.08203022006f), new Double3(-0.4089859285f, -0.04647718411f, 0.1818526372f), new Double3(-0.2826749061f, 0.07417482322f, 0.3421885344f), new Double3(0.3483864637f, 0.225442246f, -0.1740766085f), new Double3(-0.3226415069f, -0.1420585388f, -0.2796816575f), new Double3(0.4330734858f, -0.118868561f, -0.02859407492f), new Double3(-0.08717822568f, -0.3909896417f, -0.2050050172f), new Double3(-0.2149678299f, 0.3939973956f, -0.03247898316f), new Double3(-0.2687330705f, 0.322686276f, -0.1617284888f), new Double3(0.2105665099f, -0.1961317136f, -0.3459683451f), new Double3(0.4361845915f, -0.1105517485f, 0.004616608544f), new Double3(0.05333333359f, -0.313639498f, -0.3182543336f), new Double3(-0.05986216652f, 0.1361029153f, -0.4247264031f), new Double3(0.3664988455f, 0.2550543014f, -0.05590974511f), new Double3(-0.2341015558f, -0.182405731f, 0.3382670703f), new Double3(-0.04730947785f, -0.4222150243f, -0.1483114513f), new Double3(-0.2391566239f, -0.2577696514f, -0.2808182972f), new Double3(-0.1242081035f, 0.4256953395f, -0.07652336246f), new Double3(0.2614832715f, -0.3650179274f, 0.02980623099f), new Double3(-0.2728794681f, -0.3499628774f, 0.07458404908f), new Double3(0.007892900508f, -0.1672771315f, 0.4176793787f), new Double3(-0.01730330376f, 0.2978486637f, -0.3368779738f), new Double3(0.2054835762f, -0.3252600376f, -0.2334146693f), new Double3(-0.3231994983f, 0.1564282844f, -0.2712420987f), new Double3(-0.2669545963f, 0.2599343665f, -0.2523278991f), new Double3(-0.05554372779f, 0.3170813944f, -0.3144428146f), new Double3(-0.2083935713f, -0.310922837f, -0.2497981362f), new Double3(0.06989323478f, -0.3156141536f, 0.3130537363f), new Double3(0.3847566193f, -0.1605309138f, -0.1693876312f), new Double3(-0.3026215288f, -0.3001537679f, -0.1443188342f), new Double3(0.3450735512f, 0.08611519592f, 0.2756962409f), new Double3(0.1814473292f, -0.2788782453f, -0.3029914042f), new Double3(-0.03855010448f, 0.09795110726f, 0.4375151083f), new Double3(0.3533670318f, 0.2665752752f, 0.08105160988f), new Double3(-0.007945601311f, 0.140359426f, -0.4274764309f), new Double3(0.4063099273f, -0.1491768253f, -0.1231199324f), new Double3(-0.2016773589f, 0.008816271194f, -0.4021797064f), new Double3(-0.07527055435f, -0.425643481f, -0.1251477955f), + }; + // Hashing + private final static long X_PRIME = 1619; + private final static long Y_PRIME = 31337; + private final static long Z_PRIME = 6971; + private final static long W_PRIME = 1013; + private final static double F3 = 1.0 / 3.0; + private final static double G3 = 1.0 / 6.0; + private final static double G33 = G3 * 3 - 1; + private final static double F2 = 1.0 / 2.0; + private final static double G2 = 1.0 / 4.0; + private static final byte[] SIMPLEX_4D = {0, 1, 2, 3, 0, 1, 3, 2, 0, 0, 0, 0, 0, 2, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 0, 0, 2, 1, 3, 0, 0, 0, 0, 0, 3, 1, 2, 0, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 3, 0, 0, 0, 0, 1, 3, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 1, 2, 3, 1, 0, 1, 0, 2, 3, 1, 0, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 1, 0, 0, 0, 0, 2, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1, 2, 3, 0, 2, 1, 0, 0, 0, 0, 3, 1, 2, 0, 2, 1, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 0, 2, 0, 0, 0, 0, 3, 2, 0, 1, 3, 2, 1, 0 + }; + private final static double F4 = (2.23606797 - 1.0) / 4.0; + private final static double G4 = (5.0 - 2.23606797) / 20.0; + private final static double CUBIC_3D_BOUNDING = 1 / (1.5 * 1.5 * 1.5); + private final static double CUBIC_2D_BOUNDING = 1 / (1.5 * 1.5); + public Longerp m_longerp = Longerp.Linear; private long m_seed = 1337; private double m_frequency = 0.01; - public Longerp m_longerp = Longerp.Linear; private NoiseType m_noiseType = NoiseType.Simplex; - private long m_octaves = 3; private double m_lacunarity = 2.0; private double m_gain = 0.5; private FractalType m_fractalType = FractalType.FBM; - private double m_fractalBounding; - private CellularDistanceFunction m_cellularDistanceFunction = CellularDistanceFunction.Euclidean; private CellularReturnType m_cellularReturnType = CellularReturnType.CellValue; private FastNoiseDouble m_cellularNoiseLookup = null; - private double m_gradientPerturbAmp = 1.0 / 0.45; public FastNoiseDouble() { @@ -95,127 +73,6 @@ public class FastNoiseDouble { return 0; } - // Returns the seed used by this object - public long getSeed() { - return m_seed; - } - - // Sets seed used for all noise types - // Default: 1337 - public void setSeed(long seed) { - m_seed = seed; - } - - // Sets frequency for all noise types - // Default: 0.01 - public void setFrequency(double frequency) { - m_frequency = frequency; - } - - // Changes the longerpolation method used to smooth between noise values - // Possible longerpolation methods (lowest to highest quality) : - // - Linear - // - Hermite - // - Qulongic - // Used in Value, Gradient Noise and Position Perturbing - // Default: Qulongic - public void setLongerp(Longerp longerp) { - m_longerp = longerp; - } - - // Sets noise return type of GetNoise(...) - // Default: Simplex - public void setNoiseType(NoiseType noiseType) { - m_noiseType = noiseType; - } - - // Sets octave count for all fractal noise types - // Default: 3 - public void setFractalOctaves(long octaves) { - m_octaves = octaves; - calculateFractalBounding(); - } - - // Sets octave lacunarity for all fractal noise types - // Default: 2.0 - public void setFractalLacunarity(double lacunarity) { - m_lacunarity = lacunarity; - } - - // Sets octave gain for all fractal noise types - // Default: 0.5 - public void setFractalGain(double gain) { - m_gain = gain; - calculateFractalBounding(); - } - - // Sets method for combining octaves in all fractal noise types - // Default: FBM - public void setFractalType(FractalType fractalType) { - m_fractalType = fractalType; - } - - // Sets return type from cellular noise calculations - // Note: NoiseLookup requires another FastNoise object be set with - // SetCellularNoiseLookup() to function - // Default: CellValue - public void setCellularDistanceFunction(CellularDistanceFunction cellularDistanceFunction) { - m_cellularDistanceFunction = cellularDistanceFunction; - } - - // Sets distance function used in cellular noise calculations - // Default: Euclidean - public void setCellularReturnType(CellularReturnType cellularReturnType) { - m_cellularReturnType = cellularReturnType; - } - - // Noise used to calculate a cell value if cellular return type is NoiseLookup - // The lookup value is acquired through GetNoise() so ensure you SetNoiseType() - // on the noise lookup, value, gradient or simplex is recommended - public void setCellularNoiseLookup(FastNoiseDouble noise) { - m_cellularNoiseLookup = noise; - } - - // Sets the maximum perturb distance from original location when using - // GradientPerturb{Fractal}(...) - // Default: 1.0 - public void setGradientPerturbAmp(double gradientPerturbAmp) { - m_gradientPerturbAmp = gradientPerturbAmp / 0.45; - } - - @SuppressWarnings("ClassCanBeRecord") - private static class Double2 { - public final double x, y; - - public Double2(double x, double y) { - this.x = x; - this.y = y; - } - } - - @SuppressWarnings("ClassCanBeRecord") - private static class Double3 { - public final double x, y, z; - - public Double3(double x, double y, double z) { - this.x = x; - this.y = y; - this.z = z; - } - } - - private static final Double2[] GRAD_2D = {new Double2(-1, -1), new Double2(1, -1), new Double2(-1, 1), new Double2(1, 1), new Double2(0, -1), new Double2(-1, 0), new Double2(0, 1), new Double2(1, 0), - }; - - private static final Double3[] GRAD_3D = {new Double3(1, 1, 0), new Double3(-1, 1, 0), new Double3(1, -1, 0), new Double3(-1, -1, 0), new Double3(1, 0, 1), new Double3(-1, 0, 1), new Double3(1, 0, -1), new Double3(-1, 0, -1), new Double3(0, 1, 1), new Double3(0, -1, 1), new Double3(0, 1, -1), new Double3(0, -1, -1), new Double3(1, 1, 0), new Double3(0, -1, 1), new Double3(-1, 1, 0), new Double3(0, -1, -1), - }; - - private static final Double2[] CELL_2D = {new Double2(-0.4313539279f, 0.1281943404f), new Double2(-0.1733316799f, 0.415278375f), new Double2(-0.2821957395f, -0.3505218461f), new Double2(-0.2806473808f, 0.3517627718f), new Double2(0.3125508975f, -0.3237467165f), new Double2(0.3383018443f, -0.2967353402f), new Double2(-0.4393982022f, -0.09710417025f), new Double2(-0.4460443703f, -0.05953502905f), new Double2(-0.302223039f, 0.3334085102f), new Double2(-0.212681052f, -0.3965687458f), new Double2(-0.2991156529f, 0.3361990872f), new Double2(0.2293323691f, 0.3871778202f), new Double2(0.4475439151f, -0.04695150755f), new Double2(0.1777518f, 0.41340573f), new Double2(0.1688522499f, -0.4171197882f), new Double2(-0.0976597166f, 0.4392750616f), new Double2(0.08450188373f, 0.4419948321f), new Double2(-0.4098760448f, -0.1857461384f), new Double2(0.3476585782f, -0.2857157906f), new Double2(-0.3350670039f, -0.30038326f), new Double2(0.2298190031f, -0.3868891648f), new Double2(-0.01069924099f, 0.449872789f), new Double2(-0.4460141246f, -0.05976119672f), new Double2(0.3650293864f, 0.2631606867f), new Double2(-0.349479423f, 0.2834856838f), new Double2(-0.4122720642f, 0.1803655873f), new Double2(-0.267327811f, 0.3619887311f), new Double2(0.322124041f, -0.3142230135f), new Double2(0.2880445931f, -0.3457315612f), new Double2(0.3892170926f, -0.2258540565f), new Double2(0.4492085018f, -0.02667811596f), new Double2(-0.4497724772f, 0.01430799601f), new Double2(0.1278175387f, -0.4314657307f), new Double2(-0.03572100503f, 0.4485799926f), new Double2(-0.4297407068f, -0.1335025276f), new Double2(-0.3217817723f, 0.3145735065f), new Double2(-0.3057158873f, 0.3302087162f), new Double2(-0.414503978f, 0.1751754899f), new Double2(-0.3738139881f, 0.2505256519f), new Double2(0.2236891408f, -0.3904653228f), new Double2(0.002967775577f, -0.4499902136f), new Double2(0.1747128327f, -0.4146991995f), new Double2(-0.4423772489f, -0.08247647938f), new Double2(-0.2763960987f, -0.355112935f), new Double2(-0.4019385906f, -0.2023496216f), new Double2(0.3871414161f, -0.2293938184f), new Double2(-0.430008727f, 0.1326367019f), new Double2(-0.03037574274f, -0.4489736231f), new Double2(-0.3486181573f, 0.2845441624f), new Double2(0.04553517144f, -0.4476902368f), new Double2(-0.0375802926f, 0.4484280562f), new Double2(0.3266408905f, 0.3095250049f), new Double2(0.06540017593f, -0.4452222108f), new Double2(0.03409025829f, 0.448706869f), new Double2(-0.4449193635f, 0.06742966669f), new Double2(-0.4255936157f, -0.1461850686f), new Double2(0.449917292f, 0.008627302568f), new Double2(0.05242606404f, 0.4469356864f), new Double2(-0.4495305179f, -0.02055026661f), new Double2(-0.1204775703f, 0.4335725488f), new Double2(-0.341986385f, -0.2924813028f), new Double2(0.3865320182f, 0.2304191809f), new Double2(0.04506097811f, -0.447738214f), new Double2(-0.06283465979f, 0.4455915232f), new Double2(0.3932600341f, -0.2187385324f), new Double2(0.4472261803f, -0.04988730975f), new Double2(0.3753571011f, -0.2482076684f), new Double2(-0.273662295f, 0.357223947f), new Double2(0.1700461538f, 0.4166344988f), new Double2(0.4102692229f, 0.1848760794f), new Double2(0.323227187f, -0.3130881435f), new Double2(-0.2882310238f, -0.3455761521f), new Double2(0.2050972664f, 0.4005435199f), new Double2(0.4414085979f, -0.08751256895f), new Double2(-0.1684700334f, 0.4172743077f), new Double2(-0.003978032396f, 0.4499824166f), new Double2(-0.2055133639f, 0.4003301853f), new Double2(-0.006095674897f, -0.4499587123f), new Double2(-0.1196228124f, -0.4338091548f), new Double2(0.3901528491f, -0.2242337048f), new Double2(0.01723531752f, 0.4496698165f), new Double2(-0.3015070339f, 0.3340561458f), new Double2(-0.01514262423f, -0.4497451511f), new Double2(-0.4142574071f, -0.1757577897f), new Double2(-0.1916377265f, -0.4071547394f), new Double2(0.3749248747f, 0.2488600778f), new Double2(-0.2237774255f, 0.3904147331f), new Double2(-0.4166343106f, -0.1700466149f), new Double2(0.3619171625f, 0.267424695f), new Double2(0.1891126846f, -0.4083336779f), new Double2(-0.3127425077f, 0.323561623f), new Double2(-0.3281807787f, 0.307891826f), new Double2(-0.2294806661f, 0.3870899429f), new Double2(-0.3445266136f, 0.2894847362f), new Double2(-0.4167095422f, -0.1698621719f), new Double2(-0.257890321f, -0.3687717212f), new Double2(-0.3612037825f, 0.2683874578f), new Double2(0.2267996491f, 0.3886668486f), new Double2(0.207157062f, 0.3994821043f), new Double2(0.08355176718f, -0.4421754202f), new Double2(-0.4312233307f, 0.1286329626f), new Double2(0.3257055497f, 0.3105090899f), new Double2(0.177701095f, -0.4134275279f), new Double2(-0.445182522f, 0.06566979625f), new Double2(0.3955143435f, 0.2146355146f), new Double2(-0.4264613988f, 0.1436338239f), new Double2(-0.3793799665f, -0.2420141339f), new Double2(0.04617599081f, -0.4476245948f), new Double2(-0.371405428f, -0.2540826796f), new Double2(0.2563570295f, -0.3698392535f), new Double2(0.03476646309f, 0.4486549822f), new Double2(-0.3065454405f, 0.3294387544f), new Double2(-0.2256979823f, 0.3893076172f), new Double2(0.4116448463f, -0.1817925206f), new Double2(-0.2907745828f, -0.3434387019f), new Double2(0.2842278468f, -0.348876097f), new Double2(0.3114589359f, -0.3247973695f), new Double2(0.4464155859f, -0.0566844308f), new Double2(-0.3037334033f, -0.3320331606f), new Double2(0.4079607166f, 0.1899159123f), new Double2(-0.3486948919f, -0.2844501228f), new Double2(0.3264821436f, 0.3096924441f), new Double2(0.3211142406f, 0.3152548881f), new Double2(0.01183382662f, 0.4498443737f), new Double2(0.4333844092f, 0.1211526057f), new Double2(0.3118668416f, 0.324405723f), new Double2(-0.272753471f, 0.3579183483f), new Double2(-0.422228622f, -0.1556373694f), new Double2(-0.1009700099f, -0.4385260051f), new Double2(-0.2741171231f, -0.3568750521f), new Double2(-0.1465125133f, 0.4254810025f), new Double2(0.2302279044f, -0.3866459777f), new Double2(-0.3699435608f, 0.2562064828f), new Double2(0.105700352f, -0.4374099171f), new Double2(-0.2646713633f, 0.3639355292f), new Double2(0.3521828122f, 0.2801200935f), new Double2(-0.1864187807f, -0.4095705534f), new Double2(0.1994492955f, -0.4033856449f), new Double2(0.3937065066f, 0.2179339044f), new Double2(-0.3226158377f, 0.3137180602f), new Double2(0.3796235338f, 0.2416318948f), new Double2(0.1482921929f, 0.4248640083f), new Double2(-0.407400394f, 0.1911149365f), new Double2(0.4212853031f, 0.1581729856f), new Double2(-0.2621297173f, 0.3657704353f), new Double2(-0.2536986953f, -0.3716678248f), new Double2(-0.2100236383f, 0.3979825013f), new Double2(0.3624152444f, 0.2667493029f), new Double2(-0.3645038479f, -0.2638881295f), new Double2(0.2318486784f, 0.3856762766f), new Double2(-0.3260457004f, 0.3101519002f), new Double2(-0.2130045332f, -0.3963950918f), new Double2(0.3814998766f, -0.2386584257f), new Double2(-0.342977305f, 0.2913186713f), new Double2(-0.4355865605f, 0.1129794154f), new Double2(-0.2104679605f, 0.3977477059f), new Double2(0.3348364681f, -0.3006402163f), new Double2(0.3430468811f, 0.2912367377f), new Double2(-0.2291836801f, -0.3872658529f), new Double2(0.2547707298f, -0.3709337882f), new Double2(0.4236174945f, -0.151816397f), new Double2(-0.15387742f, 0.4228731957f), new Double2(-0.4407449312f, 0.09079595574f), new Double2(-0.06805276192f, -0.444824484f), new Double2(0.4453517192f, -0.06451237284f), new Double2(0.2562464609f, -0.3699158705f), new Double2(0.3278198355f, -0.3082761026f), new Double2(-0.4122774207f, -0.1803533432f), new Double2(0.3354090914f, -0.3000012356f), new Double2(0.446632869f, -0.05494615882f), new Double2(-0.1608953296f, 0.4202531296f), new Double2(-0.09463954939f, 0.4399356268f), new Double2(-0.02637688324f, -0.4492262904f), new Double2(0.447102804f, -0.05098119915f), new Double2(-0.4365670908f, 0.1091291678f), new Double2(-0.3959858651f, 0.2137643437f), new Double2(-0.4240048207f, -0.1507312575f), new Double2(-0.3882794568f, 0.2274622243f), new Double2(-0.4283652566f, -0.1378521198f), new Double2(0.3303888091f, 0.305521251f), new Double2(0.3321434919f, -0.3036127481f), new Double2(-0.413021046f, -0.1786438231f), new Double2(0.08403060337f, -0.4420846725f), new Double2(-0.3822882919f, 0.2373934748f), new Double2(-0.3712395594f, -0.2543249683f), new Double2(0.4472363971f, -0.04979563372f), new Double2(-0.4466591209f, 0.05473234629f), new Double2(0.0486272539f, -0.4473649407f), new Double2(-0.4203101295f, -0.1607463688f), new Double2(0.2205360833f, 0.39225481f), new Double2(-0.3624900666f, 0.2666476169f), new Double2(-0.4036086833f, -0.1989975647f), new Double2(0.2152727807f, 0.3951678503f), new Double2(-0.4359392962f, -0.1116106179f), new Double2(0.4178354266f, 0.1670735057f), new Double2(0.2007630161f, 0.4027334247f), new Double2(-0.07278067175f, -0.4440754146f), new Double2(0.3644748615f, -0.2639281632f), new Double2(-0.4317451775f, 0.126870413f), new Double2(-0.297436456f, 0.3376855855f), new Double2(-0.2998672222f, 0.3355289094f), new Double2(-0.2673674124f, 0.3619594822f), new Double2(0.2808423357f, 0.3516071423f), new Double2(0.3498946567f, 0.2829730186f), new Double2(-0.2229685561f, 0.390877248f), new Double2(0.3305823267f, 0.3053118493f), new Double2(-0.2436681211f, -0.3783197679f), new Double2(-0.03402776529f, 0.4487116125f), new Double2(-0.319358823f, 0.3170330301f), new Double2(0.4454633477f, -0.06373700535f), new Double2(0.4483504221f, 0.03849544189f), new Double2(-0.4427358436f, -0.08052932871f), new Double2(0.05452298565f, 0.4466847255f), new Double2(-0.2812560807f, 0.3512762688f), new Double2(0.1266696921f, 0.4318041097f), new Double2(-0.3735981243f, 0.2508474468f), new Double2(0.2959708351f, -0.3389708908f), new Double2(-0.3714377181f, 0.254035473f), new Double2(-0.404467102f, -0.1972469604f), new Double2(0.1636165687f, -0.419201167f), new Double2(0.3289185495f, -0.3071035458f), new Double2(-0.2494824991f, -0.3745109914f), new Double2(0.03283133272f, 0.4488007393f), new Double2(-0.166306057f, -0.4181414777f), new Double2(-0.106833179f, 0.4371346153f), new Double2(0.06440260376f, -0.4453676062f), new Double2(-0.4483230967f, 0.03881238203f), new Double2(-0.421377757f, -0.1579265206f), new Double2(0.05097920662f, -0.4471030312f), new Double2(0.2050584153f, -0.4005634111f), new Double2(0.4178098529f, -0.167137449f), new Double2(-0.3565189504f, -0.2745801121f), new Double2(0.4478398129f, 0.04403977727f), new Double2(-0.3399999602f, -0.2947881053f), new Double2(0.3767121994f, 0.2461461331f), new Double2(-0.3138934434f, 0.3224451987f), new Double2(-0.1462001792f, -0.4255884251f), new Double2(0.3970290489f, -0.2118205239f), new Double2(0.4459149305f, -0.06049689889f), new Double2(-0.4104889426f, -0.1843877112f), new Double2(0.1475103971f, -0.4251360756f), new Double2(0.09258030352f, 0.4403735771f), new Double2(-0.1589664637f, -0.4209865359f), new Double2(0.2482445008f, 0.3753327428f), new Double2(0.4383624232f, -0.1016778537f), new Double2(0.06242802956f, 0.4456486745f), new Double2(0.2846591015f, -0.3485243118f), new Double2(-0.344202744f, -0.2898697484f), new Double2(0.1198188883f, -0.4337550392f), new Double2(-0.243590703f, 0.3783696201f), new Double2(0.2958191174f, -0.3391033025f), new Double2(-0.1164007991f, 0.4346847754f), new Double2(0.1274037151f, -0.4315881062f), new Double2(0.368047306f, 0.2589231171f), new Double2(0.2451436949f, 0.3773652989f), new Double2(-0.4314509715f, 0.12786735f), - }; - - private static final Double3[] CELL_3D = {new Double3(0.1453787434f, -0.4149781685f, -0.0956981749f), new Double3(-0.01242829687f, -0.1457918398f, -0.4255470325f), new Double3(0.2877979582f, -0.02606483451f, -0.3449535616f), new Double3(-0.07732986802f, 0.2377094325f, 0.3741848704f), new Double3(0.1107205875f, -0.3552302079f, -0.2530858567f), new Double3(0.2755209141f, 0.2640521179f, -0.238463215f), new Double3(0.294168941f, 0.1526064594f, 0.3044271714f), new Double3(0.4000921098f, -0.2034056362f, 0.03244149937f), new Double3(-0.1697304074f, 0.3970864695f, -0.1265461359f), new Double3(-0.1483224484f, -0.3859694688f, 0.1775613147f), new Double3(0.2623596946f, -0.2354852944f, 0.2796677792f), new Double3(-0.2709003183f, 0.3505271138f, -0.07901746678f), new Double3(-0.03516550699f, 0.3885234328f, 0.2243054374f), new Double3(-0.1267712655f, 0.1920044036f, 0.3867342179f), new Double3(0.02952021915f, 0.4409685861f, 0.08470692262f), new Double3(-0.2806854217f, -0.266996757f, 0.2289725438f), new Double3(-0.171159547f, 0.2141185563f, 0.3568720405f), new Double3(0.2113227183f, 0.3902405947f, -0.07453178509f), new Double3(-0.1024352839f, 0.2128044156f, -0.3830421561f), new Double3(-0.3304249877f, -0.1566986703f, 0.2622305365f), new Double3(0.2091111325f, 0.3133278055f, -0.2461670583f), new Double3(0.344678154f, -0.1944240454f, -0.2142341261f), new Double3(0.1984478035f, -0.3214342325f, -0.2445373252f), new Double3(-0.2929008603f, 0.2262915116f, 0.2559320961f), new Double3(-0.1617332831f, 0.006314769776f, -0.4198838754f), new Double3(-0.3582060271f, -0.148303178f, -0.2284613961f), new Double3(-0.1852067326f, -0.3454119342f, -0.2211087107f), new Double3(0.3046301062f, 0.1026310383f, 0.314908508f), new Double3(-0.03816768434f, -0.2551766358f, -0.3686842991f), new Double3(-0.4084952196f, 0.1805950793f, 0.05492788837f), new Double3(-0.02687443361f, -0.2749741471f, 0.3551999201f), new Double3(-0.03801098351f, 0.3277859044f, 0.3059600725f), new Double3(0.2371120802f, 0.2900386767f, -0.2493099024f), new Double3(0.4447660503f, 0.03946930643f, 0.05590469027f), new Double3(0.01985147278f, -0.01503183293f, -0.4493105419f), new Double3(0.4274339143f, 0.03345994256f, -0.1366772882f), new Double3(-0.2072988631f, 0.2871414597f, -0.2776273824f), new Double3(-0.3791240978f, 0.1281177671f, 0.2057929936f), new Double3(-0.2098721267f, -0.1007087278f, -0.3851122467f), new Double3(0.01582798878f, 0.4263894424f, 0.1429738373f), new Double3(-0.1888129464f, -0.3160996813f, -0.2587096108f), new Double3(0.1612988974f, -0.1974805082f, -0.3707885038f), new Double3(-0.08974491322f, 0.229148752f, -0.3767448739f), new Double3(0.07041229526f, 0.4150230285f, -0.1590534329f), new Double3(-0.1082925611f, -0.1586061639f, 0.4069604477f), new Double3(0.2474100658f, -0.3309414609f, 0.1782302128f), new Double3(-0.1068836661f, -0.2701644537f, -0.3436379634f), new Double3(0.2396452163f, 0.06803600538f, -0.3747549496f), new Double3(-0.3063886072f, 0.2597428179f, 0.2028785103f), new Double3(0.1593342891f, -0.3114350249f, -0.2830561951f), new Double3(0.2709690528f, 0.1412648683f, -0.3303331794f), new Double3(-0.1519780427f, 0.3623355133f, 0.2193527988f), new Double3(0.1699773681f, 0.3456012883f, 0.2327390037f), new Double3(-0.1986155616f, 0.3836276443f, -0.1260225743f), new Double3(-0.1887482106f, -0.2050154888f, -0.353330953f), new Double3(0.2659103394f, 0.3015631259f, -0.2021172246f), new Double3(-0.08838976154f, -0.4288819642f, -0.1036702021f), new Double3(-0.04201869311f, 0.3099592485f, 0.3235115047f), new Double3(-0.3230334656f, 0.201549922f, -0.2398478873f), new Double3(0.2612720941f, 0.2759854499f, -0.2409749453f), new Double3(0.385713046f, 0.2193460345f, 0.07491837764f), new Double3(0.07654967953f, 0.3721732183f, 0.241095919f), new Double3(0.4317038818f, -0.02577753072f, 0.1243675091f), new Double3(-0.2890436293f, -0.3418179959f, -0.04598084447f), new Double3(-0.2201947582f, 0.383023377f, -0.08548310451f), new Double3(0.4161322773f, -0.1669634289f, -0.03817251927f), new Double3(0.2204718095f, 0.02654238946f, -0.391391981f), new Double3(-0.1040307469f, 0.3890079625f, -0.2008741118f), new Double3(-0.1432122615f, 0.371614387f, -0.2095065525f), new Double3(0.3978380468f, -0.06206669342f, 0.2009293758f), new Double3(-0.2599274663f, 0.2616724959f, -0.2578084893f), new Double3(0.4032618332f, -0.1124593585f, 0.1650235939f), new Double3(-0.08953470255f, -0.3048244735f, 0.3186935478f), new Double3(0.118937202f, -0.2875221847f, 0.325092195f), new Double3(0.02167047076f, -0.03284630549f, -0.4482761547f), new Double3(-0.3411343612f, 0.2500031105f, 0.1537068389f), new Double3(0.3162964612f, 0.3082064153f, -0.08640228117f), new Double3(0.2355138889f, -0.3439334267f, -0.1695376245f), new Double3(-0.02874541518f, -0.3955933019f, 0.2125550295f), new Double3(-0.2461455173f, 0.02020282325f, -0.3761704803f), new Double3(0.04208029445f, -0.4470439576f, 0.02968078139f), new Double3(0.2727458746f, 0.2288471896f, -0.2752065618f), new Double3(-0.1347522818f, -0.02720848277f, -0.4284874806f), new Double3(0.3829624424f, 0.1231931484f, -0.2016512234f), new Double3(-0.3547613644f, 0.1271702173f, 0.2459107769f), new Double3(0.2305790207f, 0.3063895591f, 0.2354968222f), new Double3(-0.08323845599f, -0.1922245118f, 0.3982726409f), new Double3(0.2993663085f, -0.2619918095f, -0.2103333191f), new Double3(-0.2154865723f, 0.2706747713f, 0.287751117f), new Double3(0.01683355354f, -0.2680655787f, -0.3610505186f), new Double3(0.05240429123f, 0.4335128183f, -0.1087217856f), new Double3(0.00940104872f, -0.4472890582f, 0.04841609928f), new Double3(0.3465688735f, 0.01141914583f, -0.2868093776f), new Double3(-0.3706867948f, -0.2551104378f, 0.003156692623f), new Double3(0.2741169781f, 0.2139972417f, -0.2855959784f), new Double3(0.06413433865f, 0.1708718512f, 0.4113266307f), new Double3(-0.388187972f, -0.03973280434f, -0.2241236325f), new Double3(0.06419469312f, -0.2803682491f, 0.3460819069f), new Double3(-0.1986120739f, -0.3391173584f, 0.2192091725f), new Double3(-0.203203009f, -0.3871641506f, 0.1063600375f), new Double3(-0.1389736354f, -0.2775901578f, -0.3257760473f), new Double3(-0.06555641638f, 0.342253257f, -0.2847192729f), new Double3(-0.2529246486f, -0.2904227915f, 0.2327739768f), new Double3(0.1444476522f, 0.1069184044f, 0.4125570634f), new Double3(-0.3643780054f, -0.2447099973f, -0.09922543227f), new Double3(0.4286142488f, -0.1358496089f, -0.01829506817f), new Double3(0.165872923f, -0.3136808464f, -0.2767498872f), new Double3(0.2219610524f, -0.3658139958f, 0.1393320198f), new Double3(0.04322940318f, -0.3832730794f, 0.2318037215f), new Double3(-0.08481269795f, -0.4404869674f, -0.03574965489f), new Double3(0.1822082075f, -0.3953259299f, 0.1140946023f), new Double3(-0.3269323334f, 0.3036542563f, 0.05838957105f), new Double3(-0.4080485344f, 0.04227858267f, -0.184956522f), new Double3(0.2676025294f, -0.01299671652f, 0.36155217f), new Double3(0.3024892441f, -0.1009990293f, -0.3174892964f), new Double3(0.1448494052f, 0.425921681f, -0.0104580805f), new Double3(0.4198402157f, 0.08062320474f, 0.1404780841f), new Double3(-0.3008872161f, -0.333040905f, -0.03241355801f), new Double3(0.3639310428f, -0.1291284382f, -0.2310412139f), new Double3(0.3295806598f, 0.0184175994f, -0.3058388149f), new Double3(0.2776259487f, -0.2974929052f, -0.1921504723f), new Double3(0.4149000507f, -0.144793182f, -0.09691688386f), new Double3(0.145016715f, -0.0398992945f, 0.4241205002f), new Double3(0.09299023471f, -0.299732164f, -0.3225111565f), new Double3(0.1028907093f, -0.361266869f, 0.247789732f), new Double3(0.2683057049f, -0.07076041213f, -0.3542668666f), new Double3(-0.4227307273f, -0.07933161816f, -0.1323073187f), new Double3(-0.1781224702f, 0.1806857196f, -0.3716517945f), new Double3(0.4390788626f, -0.02841848598f, -0.09435116353f), new Double3(0.2972583585f, 0.2382799621f, -0.2394997452f), new Double3(-0.1707002821f, 0.2215845691f, 0.3525077196f), new Double3(0.3806686614f, 0.1471852559f, -0.1895464869f), new Double3(-0.1751445661f, -0.274887877f, 0.3102596268f), new Double3(-0.2227237566f, -0.2316778837f, 0.3149912482f), new Double3(0.1369633021f, 0.1341343041f, -0.4071228836f), new Double3(-0.3529503428f, -0.2472893463f, -0.129514612f), new Double3(-0.2590744185f, -0.2985577559f, -0.2150435121f), new Double3(-0.3784019401f, 0.2199816631f, -0.1044989934f), new Double3(-0.05635805671f, 0.1485737441f, 0.4210102279f), new Double3(0.3251428613f, 0.09666046873f, -0.2957006485f), new Double3(-0.4190995804f, 0.1406751354f, -0.08405978803f), new Double3(-0.3253150961f, -0.3080335042f, -0.04225456877f), new Double3(0.2857945863f, -0.05796152095f, 0.3427271751f), new Double3(-0.2733604046f, 0.1973770973f, -0.2980207554f), new Double3(0.219003657f, 0.2410037886f, -0.3105713639f), new Double3(0.3182767252f, -0.271342949f, 0.1660509868f), new Double3(-0.03222023115f, -0.3331161506f, -0.300824678f), new Double3(-0.3087780231f, 0.1992794134f, -0.2596995338f), new Double3(-0.06487611647f, -0.4311322747f, 0.1114273361f), new Double3(0.3921171432f, -0.06294284106f, -0.2116183942f), new Double3(-0.1606404506f, -0.358928121f, -0.2187812825f), new Double3(-0.03767771199f, -0.2290351443f, 0.3855169162f), new Double3(0.1394866832f, -0.3602213994f, 0.2308332918f), new Double3(-0.4345093872f, 0.005751117145f, 0.1169124335f), new Double3(-0.1044637494f, 0.4168128432f, -0.1336202785f), new Double3(0.2658727501f, 0.2551943237f, 0.2582393035f), new Double3(0.2051461999f, 0.1975390727f, 0.3484154868f), new Double3(-0.266085566f, 0.23483312f, 0.2766800993f), new Double3(0.07849405464f, -0.3300346342f, -0.2956616708f), new Double3(-0.2160686338f, 0.05376451292f, -0.3910546287f), new Double3(-0.185779186f, 0.2148499206f, 0.3490352499f), new Double3(0.02492421743f, -0.3229954284f, -0.3123343347f), new Double3(-0.120167831f, 0.4017266681f, 0.1633259825f), new Double3(-0.02160084693f, -0.06885389554f, 0.4441762538f), new Double3(0.2597670064f, 0.3096300784f, 0.1978643903f), new Double3(-0.1611553854f, -0.09823036005f, 0.4085091653f), new Double3(-0.3278896792f, 0.1461670309f, 0.2713366126f), new Double3(0.2822734956f, 0.03754421121f, -0.3484423997f), new Double3(0.03169341113f, 0.347405252f, -0.2842624114f), new Double3(0.2202613604f, -0.3460788041f, -0.1849713341f), new Double3(0.2933396046f, 0.3031973659f, 0.1565989581f), new Double3(-0.3194922995f, 0.2453752201f, -0.200538455f), new Double3(-0.3441586045f, -0.1698856132f, -0.2349334659f), new Double3(0.2703645948f, -0.3574277231f, 0.04060059933f), new Double3(0.2298568861f, 0.3744156221f, 0.0973588921f), new Double3(0.09326603877f, -0.3170108894f, 0.3054595587f), new Double3(-0.1116165319f, -0.2985018719f, 0.3177080142f), new Double3(0.2172907365f, -0.3460005203f, -0.1885958001f), new Double3(0.1991339479f, 0.3820341668f, -0.1299829458f), new Double3(-0.0541918155f, -0.2103145071f, 0.39412061f), new Double3(0.08871336998f, 0.2012117383f, 0.3926114802f), new Double3(0.2787673278f, 0.3505404674f, 0.04370535101f), new Double3(-0.322166438f, 0.3067213525f, 0.06804996813f), new Double3(-0.4277366384f, 0.132066775f, 0.04582286686f), new Double3(0.240131882f, -0.1612516055f, 0.344723946f), new Double3(0.1448607981f, -0.2387819045f, 0.3528435224f), new Double3(-0.3837065682f, -0.2206398454f, 0.08116235683f), new Double3(-0.4382627882f, -0.09082753406f, -0.04664855374f), new Double3(-0.37728353f, 0.05445141085f, 0.2391488697f), new Double3(0.1259579313f, 0.348394558f, 0.2554522098f), new Double3(-0.1406285511f, -0.270877371f, -0.3306796947f), new Double3(-0.1580694418f, 0.4162931958f, -0.06491553533f), new Double3(0.2477612106f, -0.2927867412f, -0.2353514536f), new Double3(0.2916132853f, 0.3312535401f, 0.08793624968f), new Double3(0.07365265219f, -0.1666159848f, 0.411478311f), new Double3(-0.26126526f, -0.2422237692f, 0.2748965434f), new Double3(-0.3721862032f, 0.252790166f, 0.008634938242f), new Double3(-0.3691191571f, -0.255281188f, 0.03290232422f), new Double3(0.2278441737f, -0.3358364886f, 0.1944244981f), new Double3(0.363398169f, -0.2310190248f, 0.1306597909f), new Double3(-0.304231482f, -0.2698452035f, 0.1926830856f), new Double3(-0.3199312232f, 0.316332536f, -0.008816977938f), new Double3(0.2874852279f, 0.1642275508f, -0.304764754f), new Double3(-0.1451096801f, 0.3277541114f, -0.2720669462f), new Double3(0.3220090754f, 0.0511344108f, 0.3101538769f), new Double3(-0.1247400865f, -0.04333605335f, -0.4301882115f), new Double3(-0.2829555867f, -0.3056190617f, -0.1703910946f), new Double3(0.1069384374f, 0.3491024667f, -0.2630430352f), new Double3(-0.1420661144f, -0.3055376754f, -0.2982682484f), new Double3(-0.250548338f, 0.3156466809f, -0.2002316239f), new Double3(0.3265787872f, 0.1871229129f, 0.2466400438f), new Double3(0.07646097258f, -0.3026690852f, 0.324106687f), new Double3(0.3451771584f, 0.2757120714f, -0.0856480183f), new Double3(0.298137964f, 0.2852657134f, 0.179547284f), new Double3(0.2812250376f, 0.3466716415f, 0.05684409612f), new Double3(0.4390345476f, -0.09790429955f, -0.01278335452f), new Double3(0.2148373234f, 0.1850172527f, 0.3494474791f), new Double3(0.2595421179f, -0.07946825393f, 0.3589187731f), new Double3(0.3182823114f, -0.307355516f, -0.08203022006f), new Double3(-0.4089859285f, -0.04647718411f, 0.1818526372f), new Double3(-0.2826749061f, 0.07417482322f, 0.3421885344f), new Double3(0.3483864637f, 0.225442246f, -0.1740766085f), new Double3(-0.3226415069f, -0.1420585388f, -0.2796816575f), new Double3(0.4330734858f, -0.118868561f, -0.02859407492f), new Double3(-0.08717822568f, -0.3909896417f, -0.2050050172f), new Double3(-0.2149678299f, 0.3939973956f, -0.03247898316f), new Double3(-0.2687330705f, 0.322686276f, -0.1617284888f), new Double3(0.2105665099f, -0.1961317136f, -0.3459683451f), new Double3(0.4361845915f, -0.1105517485f, 0.004616608544f), new Double3(0.05333333359f, -0.313639498f, -0.3182543336f), new Double3(-0.05986216652f, 0.1361029153f, -0.4247264031f), new Double3(0.3664988455f, 0.2550543014f, -0.05590974511f), new Double3(-0.2341015558f, -0.182405731f, 0.3382670703f), new Double3(-0.04730947785f, -0.4222150243f, -0.1483114513f), new Double3(-0.2391566239f, -0.2577696514f, -0.2808182972f), new Double3(-0.1242081035f, 0.4256953395f, -0.07652336246f), new Double3(0.2614832715f, -0.3650179274f, 0.02980623099f), new Double3(-0.2728794681f, -0.3499628774f, 0.07458404908f), new Double3(0.007892900508f, -0.1672771315f, 0.4176793787f), new Double3(-0.01730330376f, 0.2978486637f, -0.3368779738f), new Double3(0.2054835762f, -0.3252600376f, -0.2334146693f), new Double3(-0.3231994983f, 0.1564282844f, -0.2712420987f), new Double3(-0.2669545963f, 0.2599343665f, -0.2523278991f), new Double3(-0.05554372779f, 0.3170813944f, -0.3144428146f), new Double3(-0.2083935713f, -0.310922837f, -0.2497981362f), new Double3(0.06989323478f, -0.3156141536f, 0.3130537363f), new Double3(0.3847566193f, -0.1605309138f, -0.1693876312f), new Double3(-0.3026215288f, -0.3001537679f, -0.1443188342f), new Double3(0.3450735512f, 0.08611519592f, 0.2756962409f), new Double3(0.1814473292f, -0.2788782453f, -0.3029914042f), new Double3(-0.03855010448f, 0.09795110726f, 0.4375151083f), new Double3(0.3533670318f, 0.2665752752f, 0.08105160988f), new Double3(-0.007945601311f, 0.140359426f, -0.4274764309f), new Double3(0.4063099273f, -0.1491768253f, -0.1231199324f), new Double3(-0.2016773589f, 0.008816271194f, -0.4021797064f), new Double3(-0.07527055435f, -0.425643481f, -0.1251477955f), - }; - private static long fastFloor(double f) { return (f >= 0 ? (long) f : (long) f - 1); } @@ -241,22 +98,6 @@ public class FastNoiseDouble { return t * t * t * p + t * t * ((a - b) - p) + t * (c - a) + b; } - private void calculateFractalBounding() { - double amp = m_gain; - double ampFractal = 1; - for (long i = 1; i < m_octaves; i++) { - ampFractal += amp; - amp *= m_gain; - } - m_fractalBounding = 1 / ampFractal; - } - - // Hashing - private final static long X_PRIME = 1619; - private final static long Y_PRIME = 31337; - private final static long Z_PRIME = 6971; - private final static long W_PRIME = 1013; - private static long hash2D(long seed, long x, long y) { long hash = seed; hash ^= X_PRIME * x; @@ -379,6 +220,106 @@ public class FastNoiseDouble { return ((hash & 4) == 0 ? -a : a) + ((hash & 2) == 0 ? -b : b) + ((hash & 1) == 0 ? -c : c); } + // Returns the seed used by this object + public long getSeed() { + return m_seed; + } + + // Sets seed used for all noise types + // Default: 1337 + public void setSeed(long seed) { + m_seed = seed; + } + + // Sets frequency for all noise types + // Default: 0.01 + public void setFrequency(double frequency) { + m_frequency = frequency; + } + + // Changes the longerpolation method used to smooth between noise values + // Possible longerpolation methods (lowest to highest quality) : + // - Linear + // - Hermite + // - Qulongic + // Used in Value, Gradient Noise and Position Perturbing + // Default: Qulongic + public void setLongerp(Longerp longerp) { + m_longerp = longerp; + } + + // Sets noise return type of GetNoise(...) + // Default: Simplex + public void setNoiseType(NoiseType noiseType) { + m_noiseType = noiseType; + } + + // Sets octave count for all fractal noise types + // Default: 3 + public void setFractalOctaves(long octaves) { + m_octaves = octaves; + calculateFractalBounding(); + } + + // Sets octave lacunarity for all fractal noise types + // Default: 2.0 + public void setFractalLacunarity(double lacunarity) { + m_lacunarity = lacunarity; + } + + // Sets octave gain for all fractal noise types + // Default: 0.5 + public void setFractalGain(double gain) { + m_gain = gain; + calculateFractalBounding(); + } + + // Sets method for combining octaves in all fractal noise types + // Default: FBM + public void setFractalType(FractalType fractalType) { + m_fractalType = fractalType; + } + + // Sets return type from cellular noise calculations + // Note: NoiseLookup requires another FastNoise object be set with + // SetCellularNoiseLookup() to function + // Default: CellValue + public void setCellularDistanceFunction(CellularDistanceFunction cellularDistanceFunction) { + m_cellularDistanceFunction = cellularDistanceFunction; + } + + // Sets distance function used in cellular noise calculations + // Default: Euclidean + public void setCellularReturnType(CellularReturnType cellularReturnType) { + m_cellularReturnType = cellularReturnType; + } + + // Noise used to calculate a cell value if cellular return type is NoiseLookup + // The lookup value is acquired through GetNoise() so ensure you SetNoiseType() + // on the noise lookup, value, gradient or simplex is recommended + public void setCellularNoiseLookup(FastNoiseDouble noise) { + m_cellularNoiseLookup = noise; + } + + // Sets the maximum perturb distance from original location when using + // GradientPerturb{Fractal}(...) + // Default: 1.0 + public void setGradientPerturbAmp(double gradientPerturbAmp) { + m_gradientPerturbAmp = gradientPerturbAmp / 0.45; + } + + // White Noise + + private void calculateFractalBounding() { + double amp = m_gain; + double ampFractal = 1; + for (long i = 1; i < m_octaves; i++) { + ampFractal += amp; + amp *= m_gain; + } + m_fractalBounding = 1 / ampFractal; + } + public double GetNoise(double x, double y, double z) { x *= m_frequency; y *= m_frequency; @@ -478,8 +419,6 @@ public class FastNoiseDouble { } } - // White Noise - private long DoubleCast2Long(double f) { long i = Double.doubleToRawLongBits(f); @@ -995,10 +934,6 @@ public class FastNoiseDouble { return SingleSimplex(m_seed, x * m_frequency, y * m_frequency, z * m_frequency); } - private final static double F3 = 1.0 / 3.0; - private final static double G3 = 1.0 / 6.0; - private final static double G33 = G3 * 3 - 1; - private double SingleSimplex(long seed, double x, double y, double z) { double t = (x + y + z) * F3; long i = fastFloor(x + t); @@ -1174,9 +1109,6 @@ public class FastNoiseDouble { return SingleSimplex(m_seed, x * m_frequency, y * m_frequency); } - private final static double F2 = 1.0 / 2.0; - private final static double G2 = 1.0 / 4.0; - private double SingleSimplex(long seed, double x, double y) { double t = (x + y) * F2; long i = fastFloor(x + t); @@ -1236,12 +1168,6 @@ public class FastNoiseDouble { return SingleSimplex(m_seed, x * m_frequency, y * m_frequency, z * m_frequency, w * m_frequency); } - private static final byte[] SIMPLEX_4D = {0, 1, 2, 3, 0, 1, 3, 2, 0, 0, 0, 0, 0, 2, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 0, 0, 2, 1, 3, 0, 0, 0, 0, 0, 3, 1, 2, 0, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 3, 0, 0, 0, 0, 1, 3, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 1, 2, 3, 1, 0, 1, 0, 2, 3, 1, 0, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 1, 0, 0, 0, 0, 2, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1, 2, 3, 0, 2, 1, 0, 0, 0, 0, 3, 1, 2, 0, 2, 1, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 0, 2, 0, 0, 0, 0, 3, 2, 0, 1, 3, 2, 1, 0 - }; - - private final static double F4 = (2.23606797 - 1.0) / 4.0; - private final static double G4 = (5.0 - 2.23606797) / 20.0; - private double SingleSimplex(long seed, double x, double y, double z, double w) { double n0, n1, n2, n3, n4; double t = (x + y + z + w) * F4; @@ -1407,8 +1333,6 @@ public class FastNoiseDouble { return SingleCubic(m_seed, x * m_frequency, y * m_frequency, z * m_frequency); } - private final static double CUBIC_3D_BOUNDING = 1 / (1.5 * 1.5 * 1.5); - private double SingleCubic(long seed, double x, double y, double z) { long x1 = fastFloor(x); long y1 = fastFloor(y); @@ -1500,8 +1424,6 @@ public class FastNoiseDouble { return SingleCubic(0, x, y); } - private final static double CUBIC_2D_BOUNDING = 1 / (1.5 * 1.5); - private double SingleCubic(long seed, double x, double y) { long x1 = fastFloor(x); long y1 = fastFloor(y); @@ -2001,4 +1923,67 @@ public class FastNoiseDouble { v2.y += lerp(ly0x, ly1x, ys) * perturbAmp; } + public enum NoiseType { + Value, + ValueFractal, + Perlin, + PerlinFractal, + Simplex, + SimplexFractal, + Cellular, + WhiteNoise, + Cubic, + CubicFractal + } + + public enum Longerp { + Linear, + Hermite, + Qulongic + } + + public enum FractalType { + FBM, + Billow, + RigidMulti + } + + public enum CellularDistanceFunction { + Euclidean, + Manhattan, + Natural + } + + public enum CellularReturnType { + CellValue, + NoiseLookup, + Distance, + Distance2, + Distance2Add, + Distance2Sub, + Distance2Mul, + Distance2Div + } + + @SuppressWarnings("ClassCanBeRecord") + private static class Double2 { + public final double x, y; + + public Double2(double x, double y) { + this.x = x; + this.y = y; + } + } + + @SuppressWarnings("ClassCanBeRecord") + private static class Double3 { + public final double x, y, z; + + public Double3(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + } + } + } \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/parallel/MultiBurst.java b/src/main/java/com/volmit/iris/util/parallel/MultiBurst.java index 7eb1de959..17a671eaf 100644 --- a/src/main/java/com/volmit/iris/util/parallel/MultiBurst.java +++ b/src/main/java/com/volmit/iris/util/parallel/MultiBurst.java @@ -25,15 +25,20 @@ import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.math.M; import java.util.List; -import java.util.concurrent.*; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.ForkJoinPool; +import java.util.concurrent.ForkJoinWorkerThread; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; public class MultiBurst { public static final MultiBurst burst = new MultiBurst(); - private ExecutorService service; private final AtomicLong last; private final String name; private final int priority; + private ExecutorService service; public MultiBurst() { this("Iris", Thread.MIN_PRIORITY); diff --git a/src/main/java/com/volmit/iris/util/particle/ParticleType.java b/src/main/java/com/volmit/iris/util/particle/ParticleType.java index ecc16ca1a..6d60040a7 100644 --- a/src/main/java/com/volmit/iris/util/particle/ParticleType.java +++ b/src/main/java/com/volmit/iris/util/particle/ParticleType.java @@ -142,6 +142,24 @@ public enum ParticleType { this.minimumVersion = minimumVersion; } + public static ParticleType getParticle(String particleName) { + try { + return ParticleType.valueOf(particleName.toUpperCase()); + } catch (IllegalArgumentException e) { + Iris.reportError(e); + for (ParticleType particle : values()) { + if (particle.getName().equalsIgnoreCase(particleName)) { + return particle; + } + + if (particle.hasLegacyName() && particle.getLegacyName().equalsIgnoreCase(particleName)) { + return particle; + } + } + } + return null; + } + public boolean hasLegacyName() { return legacyName != null; } @@ -171,22 +189,4 @@ public enum ParticleType { default -> Void.class; }; } - - public static ParticleType getParticle(String particleName) { - try { - return ParticleType.valueOf(particleName.toUpperCase()); - } catch (IllegalArgumentException e) { - Iris.reportError(e); - for (ParticleType particle : values()) { - if (particle.getName().equalsIgnoreCase(particleName)) { - return particle; - } - - if (particle.hasLegacyName() && particle.getLegacyName().equalsIgnoreCase(particleName)) { - return particle; - } - } - } - return null; - } } diff --git a/src/main/java/com/volmit/iris/util/plugin/Command.java b/src/main/java/com/volmit/iris/util/plugin/Command.java index 10cdb95c9..132d57bad 100644 --- a/src/main/java/com/volmit/iris/util/plugin/Command.java +++ b/src/main/java/com/volmit/iris/util/plugin/Command.java @@ -21,8 +21,8 @@ package com.volmit.iris.util.plugin; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; @Retention(RUNTIME) @Target(FIELD) diff --git a/src/main/java/com/volmit/iris/util/plugin/Control.java b/src/main/java/com/volmit/iris/util/plugin/Control.java index bd919f4a2..0efebb5b9 100644 --- a/src/main/java/com/volmit/iris/util/plugin/Control.java +++ b/src/main/java/com/volmit/iris/util/plugin/Control.java @@ -21,8 +21,8 @@ package com.volmit.iris.util.plugin; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; @Retention(RUNTIME) @Target(FIELD) diff --git a/src/main/java/com/volmit/iris/util/plugin/Controller.java b/src/main/java/com/volmit/iris/util/plugin/Controller.java index 5630c59f9..e384c0700 100644 --- a/src/main/java/com/volmit/iris/util/plugin/Controller.java +++ b/src/main/java/com/volmit/iris/util/plugin/Controller.java @@ -21,8 +21,8 @@ package com.volmit.iris.util.plugin; import com.volmit.iris.Iris; public abstract class Controller implements IController { - private int tickRate; private final String name; + private int tickRate; public Controller() { name = getClass().getSimpleName().replaceAll("Controller", "") + " Controller"; diff --git a/src/main/java/com/volmit/iris/util/plugin/Instance.java b/src/main/java/com/volmit/iris/util/plugin/Instance.java index c7ee8b138..0f48f84b0 100644 --- a/src/main/java/com/volmit/iris/util/plugin/Instance.java +++ b/src/main/java/com/volmit/iris/util/plugin/Instance.java @@ -21,8 +21,8 @@ package com.volmit.iris.util.plugin; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; @Retention(RUNTIME) @Target(FIELD) diff --git a/src/main/java/com/volmit/iris/util/plugin/Metrics.java b/src/main/java/com/volmit/iris/util/plugin/Metrics.java index 09ad5b2ea..f2d6eabe3 100644 --- a/src/main/java/com/volmit/iris/util/plugin/Metrics.java +++ b/src/main/java/com/volmit/iris/util/plugin/Metrics.java @@ -31,12 +31,23 @@ import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.ServicePriority; import javax.net.ssl.HttpsURLConnection; -import java.io.*; +import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Timer; +import java.util.TimerTask; +import java.util.UUID; import java.util.concurrent.Callable; import java.util.logging.Level; import java.util.zip.GZIPOutputStream; @@ -49,6 +60,19 @@ import java.util.zip.GZIPOutputStream; @SuppressWarnings({"WeakerAccess", "unused"}) public class Metrics { + // The version of this bStats class + public static final int B_STATS_VERSION = 1; + // The url to which the data is sent + private static final String URL = "https://bStats.org/submitData/bukkit"; + // Should failed requests be logged? + private static boolean logFailedRequests; + // Should the sent data be logged? + private static boolean logSentData; + // Should the response text be logged? + private static boolean logResponseStatusText; + // The uuid of the server + private static String serverUUID; + static { // You can use the property to disable the check in your test environment if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) { @@ -63,27 +87,8 @@ public class Metrics { } } - // The version of this bStats class - public static final int B_STATS_VERSION = 1; - - // The url to which the data is sent - private static final String URL = "https://bStats.org/submitData/bukkit"; - // Is bStats enabled on this server? private final boolean enabled; - - // Should failed requests be logged? - private static boolean logFailedRequests; - - // Should the sent data be logged? - private static boolean logSentData; - - // Should the response text be logged? - private static boolean logResponseStatusText; - - // The uuid of the server - private static String serverUUID; - // The plugin private final Plugin plugin; @@ -169,6 +174,74 @@ public class Metrics { } } + /** + * Sends the data to the bStats server. + * + * @param plugin Any plugin. It's just used to get a logger instance. + * @param data The data to send. + * @throws Exception If the request failed. + */ + private static void sendData(Plugin plugin, JsonObject data) throws Exception { + if (data == null) { + throw new IllegalArgumentException("Data cannot be null!"); + } + if (Bukkit.isPrimaryThread()) { + throw new IllegalAccessException("This method must not be called from the main thread!"); + } + if (logSentData) { + plugin.getLogger().info("Sending data to bStats: " + data); + } + HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection(); + + // Compress the data to save bandwidth + byte[] compressedData = compress(data.toString()); + + // Add headers + connection.setRequestMethod("POST"); + connection.addRequestProperty("Accept", "application/json"); + connection.addRequestProperty("Connection", "close"); + connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request + connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length)); + connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format + connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION); + + // Send data + connection.setDoOutput(true); + try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { + outputStream.write(compressedData); + } + + StringBuilder builder = new StringBuilder(); + try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { + String line; + while ((line = bufferedReader.readLine()) != null) { + builder.append(line); + } + } + + if (logResponseStatusText) { + plugin.getLogger().info("Sent data to bStats and received response: " + builder); + } + } + + /** + * Gzips the given String. + * + * @param str The string to gzip. + * @return The gzipped String. + * @throws IOException If the compression failed. + */ + private static byte[] compress(final String str) throws IOException { + if (str == null) { + return null; + } + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) { + gzip.write(str.getBytes(StandardCharsets.UTF_8)); + } + return outputStream.toByteArray(); + } + /** * Checks if bStats is enabled. * @@ -351,74 +424,6 @@ public class Metrics { }).start(); } - /** - * Sends the data to the bStats server. - * - * @param plugin Any plugin. It's just used to get a logger instance. - * @param data The data to send. - * @throws Exception If the request failed. - */ - private static void sendData(Plugin plugin, JsonObject data) throws Exception { - if (data == null) { - throw new IllegalArgumentException("Data cannot be null!"); - } - if (Bukkit.isPrimaryThread()) { - throw new IllegalAccessException("This method must not be called from the main thread!"); - } - if (logSentData) { - plugin.getLogger().info("Sending data to bStats: " + data); - } - HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection(); - - // Compress the data to save bandwidth - byte[] compressedData = compress(data.toString()); - - // Add headers - connection.setRequestMethod("POST"); - connection.addRequestProperty("Accept", "application/json"); - connection.addRequestProperty("Connection", "close"); - connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request - connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length)); - connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format - connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION); - - // Send data - connection.setDoOutput(true); - try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { - outputStream.write(compressedData); - } - - StringBuilder builder = new StringBuilder(); - try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { - String line; - while ((line = bufferedReader.readLine()) != null) { - builder.append(line); - } - } - - if (logResponseStatusText) { - plugin.getLogger().info("Sent data to bStats and received response: " + builder); - } - } - - /** - * Gzips the given String. - * - * @param str The string to gzip. - * @return The gzipped String. - * @throws IOException If the compression failed. - */ - private static byte[] compress(final String str) throws IOException { - if (str == null) { - return null; - } - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) { - gzip.write(str.getBytes(StandardCharsets.UTF_8)); - } - return outputStream.toByteArray(); - } - /** * Represents a custom chart. */ diff --git a/src/main/java/com/volmit/iris/util/plugin/MetricsLite.java b/src/main/java/com/volmit/iris/util/plugin/MetricsLite.java index 72dcb11bf..cc85a1cb9 100644 --- a/src/main/java/com/volmit/iris/util/plugin/MetricsLite.java +++ b/src/main/java/com/volmit/iris/util/plugin/MetricsLite.java @@ -30,7 +30,12 @@ import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.ServicePriority; import javax.net.ssl.HttpsURLConnection; -import java.io.*; +import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; @@ -49,6 +54,19 @@ import java.util.zip.GZIPOutputStream; */ public class MetricsLite { + // The version of this bStats class + public static final int B_STATS_VERSION = 1; + // The url to which the data is sent + private static final String URL = "https://bStats.org/submitData/bukkit"; + // Should failed requests be logged? + private static boolean logFailedRequests; + // Should the sent data be logged? + private static boolean logSentData; + // Should the response text be logged? + private static boolean logResponseStatusText; + // The uuid of the server + private static String serverUUID; + static { // You can use the property to disable the check in your test environment if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) { @@ -64,27 +82,8 @@ public class MetricsLite { } } - // The version of this bStats class - public static final int B_STATS_VERSION = 1; - - // The url to which the data is sent - private static final String URL = "https://bStats.org/submitData/bukkit"; - // Is bStats enabled on this server? private final boolean enabled; - - // Should failed requests be logged? - private static boolean logFailedRequests; - - // Should the sent data be logged? - private static boolean logSentData; - - // Should the response text be logged? - private static boolean logResponseStatusText; - - // The uuid of the server - private static String serverUUID; - // The plugin private final Plugin plugin; @@ -165,6 +164,74 @@ public class MetricsLite { } } + /** + * Sends the data to the bStats server. + * + * @param plugin Any plugin. It's just used to get a logger instance. + * @param data The data to send. + * @throws Exception If the request failed. + */ + private static void sendData(Plugin plugin, JsonObject data) throws Exception { + if (data == null) { + throw new IllegalArgumentException("Data cannot be null!"); + } + if (Bukkit.isPrimaryThread()) { + throw new IllegalAccessException("This method must not be called from the main thread!"); + } + if (logSentData) { + plugin.getLogger().info("Sending data to bStats: " + data); + } + HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection(); + + // Compress the data to save bandwidth + byte[] compressedData = compress(data.toString()); + + // Add headers + connection.setRequestMethod("POST"); + connection.addRequestProperty("Accept", "application/json"); + connection.addRequestProperty("Connection", "close"); + connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request + connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length)); + connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format + connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION); + + // Send data + connection.setDoOutput(true); + try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { + outputStream.write(compressedData); + } + + StringBuilder builder = new StringBuilder(); + try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { + String line; + while ((line = bufferedReader.readLine()) != null) { + builder.append(line); + } + } + + if (logResponseStatusText) { + plugin.getLogger().info("Sent data to bStats and received response: " + builder); + } + } + + /** + * Gzips the given String. + * + * @param str The string to gzip. + * @return The gzipped String. + * @throws IOException If the compression failed. + */ + private static byte[] compress(final String str) throws IOException { + if (str == null) { + return null; + } + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) { + gzip.write(str.getBytes(StandardCharsets.UTF_8)); + } + return outputStream.toByteArray(); + } + /** * Checks if bStats is enabled. * @@ -328,72 +395,4 @@ public class MetricsLite { }).start(); } - /** - * Sends the data to the bStats server. - * - * @param plugin Any plugin. It's just used to get a logger instance. - * @param data The data to send. - * @throws Exception If the request failed. - */ - private static void sendData(Plugin plugin, JsonObject data) throws Exception { - if (data == null) { - throw new IllegalArgumentException("Data cannot be null!"); - } - if (Bukkit.isPrimaryThread()) { - throw new IllegalAccessException("This method must not be called from the main thread!"); - } - if (logSentData) { - plugin.getLogger().info("Sending data to bStats: " + data); - } - HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection(); - - // Compress the data to save bandwidth - byte[] compressedData = compress(data.toString()); - - // Add headers - connection.setRequestMethod("POST"); - connection.addRequestProperty("Accept", "application/json"); - connection.addRequestProperty("Connection", "close"); - connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request - connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length)); - connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format - connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION); - - // Send data - connection.setDoOutput(true); - try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { - outputStream.write(compressedData); - } - - StringBuilder builder = new StringBuilder(); - try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { - String line; - while ((line = bufferedReader.readLine()) != null) { - builder.append(line); - } - } - - if (logResponseStatusText) { - plugin.getLogger().info("Sent data to bStats and received response: " + builder); - } - } - - /** - * Gzips the given String. - * - * @param str The string to gzip. - * @return The gzipped String. - * @throws IOException If the compression failed. - */ - private static byte[] compress(final String str) throws IOException { - if (str == null) { - return null; - } - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) { - gzip.write(str.getBytes(StandardCharsets.UTF_8)); - } - return outputStream.toByteArray(); - } - } \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/plugin/Permission.java b/src/main/java/com/volmit/iris/util/plugin/Permission.java index 309b36f6a..e9480e822 100644 --- a/src/main/java/com/volmit/iris/util/plugin/Permission.java +++ b/src/main/java/com/volmit/iris/util/plugin/Permission.java @@ -21,8 +21,8 @@ package com.volmit.iris.util.plugin; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.*; @Retention(RUNTIME) @Target(FIELD) diff --git a/src/main/java/com/volmit/iris/util/plugin/VolmitPlugin.java b/src/main/java/com/volmit/iris/util/plugin/VolmitPlugin.java index 04a45dd3d..adb5293fc 100644 --- a/src/main/java/com/volmit/iris/util/plugin/VolmitPlugin.java +++ b/src/main/java/com/volmit/iris/util/plugin/VolmitPlugin.java @@ -27,7 +27,10 @@ import com.volmit.iris.util.reflect.V; import com.volmit.iris.util.scheduling.J; import org.bukkit.Bukkit; import org.bukkit.command.Command; -import org.bukkit.command.*; +import org.bukkit.command.CommandMap; +import org.bukkit.command.CommandSender; +import org.bukkit.command.PluginCommand; +import org.bukkit.command.SimpleCommandMap; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.event.HandlerList; diff --git a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java index bb731cbbe..aa1bf26a0 100644 --- a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java +++ b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java @@ -37,7 +37,6 @@ import net.kyori.adventure.title.Title; import org.bukkit.Server; import org.bukkit.Sound; import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionAttachment; @@ -59,9 +58,10 @@ import java.util.concurrent.atomic.AtomicReference; * @author cyberpwn */ public class VolmitSender implements CommandSender { + @Getter + private static final KMap helpCache = new KMap<>(); private final CommandSender s; private String tag; - @Getter @Setter private String command; @@ -81,13 +81,33 @@ public class VolmitSender implements CommandSender { this.s = s; } - /** - * Set a command tag (prefix for sendMessage) - * - * @param tag the tag - */ - public void setTag(String tag) { - this.tag = tag; + public static long getTick() { + return M.ms() / 16; + } + + public static String pulse(String colorA, String colorB, double speed) { + return ""; + } + + public static String pulse(double speed) { + return Form.f(invertSpread((((getTick() * 15D * speed) % 1000D) / 1000D)), 3).replaceAll("\\Q,\\E", ".").replaceAll("\\Q?\\E", "-"); + } + + public static double invertSpread(double v) { + return ((1D - v) * 2D) - 1D; + } + + public static KList paginate(KList all, int linesPerPage, int page, AtomicBoolean hasNext) { + int totalPages = (int) Math.ceil((double) all.size() / linesPerPage); + page = page < 0 ? 0 : page >= totalPages ? totalPages - 1 : page; + hasNext.set(page < totalPages - 1); + KList d = new KList<>(); + + for (int i = linesPerPage * page; i < Math.min(all.size(), linesPerPage * (page + 1)); i++) { + d.add(all.get(i)); + } + + return d; } /** @@ -99,6 +119,15 @@ public class VolmitSender implements CommandSender { return tag; } + /** + * Set a command tag (prefix for sendMessage) + * + * @param tag the tag + */ + public void setTag(String tag) { + this.tag = tag; + } + /** * Is this sender a player? * @@ -146,13 +175,11 @@ public class VolmitSender implements CommandSender { return s.hasPermission(perm); } - @Override public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) { return s.addAttachment(plugin, name, value); } - @Override public PermissionAttachment addAttachment(Plugin plugin) { return s.addAttachment(plugin); @@ -178,7 +205,6 @@ public class VolmitSender implements CommandSender { s.recalculatePermissions(); } - @Override public Set getEffectivePermissions() { return s.getEffectivePermissions(); @@ -205,10 +231,6 @@ public class VolmitSender implements CommandSender { Title.Times.of(Duration.ofMillis(i), Duration.ofMillis(s), Duration.ofMillis(o)))); } - public static long getTick() { - return M.ms() / 16; - } - public void sendProgress(double percent, String thing) { if (percent < 0) { int l = 44; @@ -223,18 +245,6 @@ public class VolmitSender implements CommandSender { } } - public static String pulse(String colorA, String colorB, double speed) { - return ""; - } - - public static String pulse(double speed) { - return Form.f(invertSpread((((getTick() * 15D * speed) % 1000D) / 1000D)), 3).replaceAll("\\Q,\\E", ".").replaceAll("\\Q?\\E", "-"); - } - - public static double invertSpread(double v) { - return ((1D - v) * 2D) - 1D; - } - public void sendAction(String action) { Iris.audiences.player(player()).sendActionBar(createNoPrefixComponent(action)); } @@ -316,8 +326,7 @@ public class VolmitSender implements CommandSender { return; } - if((!IrisSettings.get().getGeneral().isUseCustomColorsIngame() && s instanceof Player) || !IrisSettings.get().getGeneral().isUseConsoleCustomColors()) - { + if ((!IrisSettings.get().getGeneral().isUseCustomColorsIngame() && s instanceof Player) || !IrisSettings.get().getGeneral().isUseConsoleCustomColors()) { s.sendMessage(C.translateAlternateColorCodes('&', getTag() + message)); return; } @@ -347,8 +356,7 @@ public class VolmitSender implements CommandSender { return; } - if((!IrisSettings.get().getGeneral().isUseCustomColorsIngame() && s instanceof Player) || !IrisSettings.get().getGeneral().isUseConsoleCustomColors()) - { + if ((!IrisSettings.get().getGeneral().isUseCustomColorsIngame() && s instanceof Player) || !IrisSettings.get().getGeneral().isUseConsoleCustomColors()) { s.sendMessage(C.translateAlternateColorCodes('&', message)); return; } @@ -385,19 +393,16 @@ public class VolmitSender implements CommandSender { sendMessage(messages); } - @Override public Server getServer() { return s.getServer(); } - @Override public String getName() { return s.getName(); } - @Override public Spigot spigot() { return s.spigot(); @@ -425,7 +430,6 @@ public class VolmitSender implements CommandSender { return m.removeDuplicates().convert((iff) -> iff.replaceAll("\\Q \\E", " ")).toString("\n"); } - public void sendHeader(String name, int overrideLength) { int len = overrideLength; int h = name.length() + 2; @@ -446,25 +450,10 @@ public class VolmitSender implements CommandSender { sendHeader(name, 44); } - public void sendDecreeHelp(VirtualDecreeCommand v) { sendDecreeHelp(v, 0); } - - public static KList paginate(KList all, int linesPerPage, int page, AtomicBoolean hasNext) { - int totalPages = (int) Math.ceil((double) all.size() / linesPerPage); - page = page < 0 ? 0 : page >= totalPages ? totalPages - 1 : page; - hasNext.set(page < totalPages - 1); - KList d = new KList<>(); - - for (int i = linesPerPage * page; i < Math.min(all.size(), linesPerPage * (page + 1)); i++) { - d.add(all.get(i)); - } - - return d; - } - public void sendDecreeHelp(VirtualDecreeCommand v, int page) { if (!isPlayer()) { for (VirtualDecreeCommand i : v.getNodes()) { @@ -508,9 +497,6 @@ public class VolmitSender implements CommandSender { } } - @Getter - private static final KMap helpCache = new KMap<>(); - public void sendDecreeHelpNode(VirtualDecreeCommand i) { if (isPlayer() || s instanceof CommandDummy) { sendMessageRaw(helpCache.compute(i.getPath(), (k, v) -> { diff --git a/src/main/java/com/volmit/iris/util/scheduling/GroupedExecutor.java b/src/main/java/com/volmit/iris/util/scheduling/GroupedExecutor.java index 59de9ccd7..b0aad1f29 100644 --- a/src/main/java/com/volmit/iris/util/scheduling/GroupedExecutor.java +++ b/src/main/java/com/volmit/iris/util/scheduling/GroupedExecutor.java @@ -29,9 +29,9 @@ import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory; import java.util.concurrent.ForkJoinWorkerThread; public class GroupedExecutor { - private int xc; private final ExecutorService service; private final KMap mirror; + private int xc; public GroupedExecutor(int threadLimit, int priority, String name) { xc = 1; diff --git a/src/main/java/com/volmit/iris/util/scheduling/J.java b/src/main/java/com/volmit/iris/util/scheduling/J.java index de0fc28fc..597c7d4b2 100644 --- a/src/main/java/com/volmit/iris/util/scheduling/J.java +++ b/src/main/java/com/volmit/iris/util/scheduling/J.java @@ -38,6 +38,9 @@ import java.util.function.Supplier; @SuppressWarnings("ALL") public class J { private static int tid = 0; + private static KList afterStartup = new KList<>(); + private static KList afterStartupAsync = new KList<>(); + private static boolean started = false; public static void dofor(int a, Function c, int ch, Consumer d) { for (int i = a; c.apply(i); i += ch) { @@ -153,10 +156,6 @@ public class J { } } - private static KList afterStartup = new KList<>(); - private static KList afterStartupAsync = new KList<>(); - private static boolean started = false; - /** * Dont call this unless you know what you are doing! */ diff --git a/src/main/java/com/volmit/iris/util/scheduling/PrecisionStopwatch.java b/src/main/java/com/volmit/iris/util/scheduling/PrecisionStopwatch.java index e90b2159b..aa8e3f811 100644 --- a/src/main/java/com/volmit/iris/util/scheduling/PrecisionStopwatch.java +++ b/src/main/java/com/volmit/iris/util/scheduling/PrecisionStopwatch.java @@ -26,6 +26,11 @@ public class PrecisionStopwatch { private double time; private boolean profiling; + public PrecisionStopwatch() { + reset(); + profiling = false; + } + public static PrecisionStopwatch start() { PrecisionStopwatch p = new PrecisionStopwatch(); p.begin(); @@ -33,11 +38,6 @@ public class PrecisionStopwatch { return p; } - public PrecisionStopwatch() { - reset(); - profiling = false; - } - public void begin() { profiling = true; startNano = System.nanoTime(); diff --git a/src/main/java/com/volmit/iris/util/scheduling/Queue.java b/src/main/java/com/volmit/iris/util/scheduling/Queue.java index e473594ca..ba144e713 100644 --- a/src/main/java/com/volmit/iris/util/scheduling/Queue.java +++ b/src/main/java/com/volmit/iris/util/scheduling/Queue.java @@ -22,6 +22,15 @@ import com.volmit.iris.util.collection.KList; @SuppressWarnings("ALL") public interface Queue { + static Queue create(KList t) { + return new ShurikenQueue().queue(t); + } + + @SuppressWarnings("unchecked") + static Queue create(T... t) { + return new ShurikenQueue().queue(new KList().add(t)); + } + Queue queue(T t); Queue queue(KList t); @@ -38,14 +47,5 @@ public interface Queue { int size(); - static Queue create(KList t) { - return new ShurikenQueue().queue(t); - } - - @SuppressWarnings("unchecked") - static Queue create(T... t) { - return new ShurikenQueue().queue(new KList().add(t)); - } - boolean contains(T p); } diff --git a/src/main/java/com/volmit/iris/util/scheduling/TaskExecutor.java b/src/main/java/com/volmit/iris/util/scheduling/TaskExecutor.java index e7b57da78..1d9a2088e 100644 --- a/src/main/java/com/volmit/iris/util/scheduling/TaskExecutor.java +++ b/src/main/java/com/volmit/iris/util/scheduling/TaskExecutor.java @@ -33,8 +33,8 @@ import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory; import java.util.concurrent.ForkJoinWorkerThread; public class TaskExecutor { - private int xc; private final ExecutorService service; + private int xc; public TaskExecutor(int threadLimit, int priority, String name) { xc = 1; @@ -85,6 +85,13 @@ public class TaskExecutor { service.shutdown(); } + public enum TaskState { + QUEUED, + RUNNING, + COMPLETED, + FAILED + } + public static class TaskGroup { private final KList tasks; private final TaskExecutor e; @@ -155,34 +162,25 @@ public class TaskExecutor { @SuppressWarnings("ClassCanBeRecord") @ToString public static class TaskResult { + public final double timeElapsed; + public final int tasksExecuted; + public final int tasksFailed; + public final int tasksCompleted; public TaskResult(double timeElapsed, int tasksExecuted, int tasksFailed, int tasksCompleted) { this.timeElapsed = timeElapsed; this.tasksExecuted = tasksExecuted; this.tasksFailed = tasksFailed; this.tasksCompleted = tasksCompleted; } - - public final double timeElapsed; - public final int tasksExecuted; - public final int tasksFailed; - public final int tasksCompleted; - } - - public enum TaskState { - QUEUED, - RUNNING, - COMPLETED, - FAILED } public static class AssignedTask { + @Getter + private final NastyRunnable task; @Getter @Setter private TaskState state; - @Getter - private final NastyRunnable task; - public AssignedTask(NastyRunnable task) { this.task = task; state = TaskState.QUEUED; diff --git a/src/main/java/com/volmit/iris/util/scheduling/ThreadMonitor.java b/src/main/java/com/volmit/iris/util/scheduling/ThreadMonitor.java index 740204a8a..096c0784d 100644 --- a/src/main/java/com/volmit/iris/util/scheduling/ThreadMonitor.java +++ b/src/main/java/com/volmit/iris/util/scheduling/ThreadMonitor.java @@ -30,12 +30,12 @@ import com.volmit.iris.util.math.RollingSequence; */ public class ThreadMonitor extends Thread { private final Thread monitor; + private final ChronoLatch cl; + private final RollingSequence sq = new RollingSequence(3); + int cycles = 0; private boolean running; private State lastState; - private final ChronoLatch cl; private PrecisionStopwatch st; - int cycles = 0; - private final RollingSequence sq = new RollingSequence(3); private ThreadMonitor(Thread monitor) { running = true; @@ -46,6 +46,10 @@ public class ThreadMonitor extends Thread { start(); } + public static ThreadMonitor bind(Thread monitor) { + return new ThreadMonitor(monitor); + } + public void run() { while (running) { try { @@ -84,8 +88,4 @@ public class ThreadMonitor extends Thread { public void unbind() { running = false; } - - public static ThreadMonitor bind(Thread monitor) { - return new ThreadMonitor(monitor); - } } diff --git a/src/main/java/com/volmit/iris/util/scheduling/jobs/JobCollection.java b/src/main/java/com/volmit/iris/util/scheduling/jobs/JobCollection.java index 9c5a44f1f..1c3babaf5 100644 --- a/src/main/java/com/volmit/iris/util/scheduling/jobs/JobCollection.java +++ b/src/main/java/com/volmit/iris/util/scheduling/jobs/JobCollection.java @@ -22,8 +22,8 @@ import com.volmit.iris.util.collection.KList; public class JobCollection implements Job { private final String name; - private String status; private final KList jobs; + private String status; public JobCollection(String name, Job... jobs) { this(name, new KList<>(jobs)); diff --git a/src/main/java/com/volmit/iris/util/scheduling/jobs/QueueJob.java b/src/main/java/com/volmit/iris/util/scheduling/jobs/QueueJob.java index be809ca90..37c57741a 100644 --- a/src/main/java/com/volmit/iris/util/scheduling/jobs/QueueJob.java +++ b/src/main/java/com/volmit/iris/util/scheduling/jobs/QueueJob.java @@ -24,8 +24,8 @@ import java.util.concurrent.atomic.AtomicInteger; public abstract class QueueJob implements Job { final KList queue; - protected int totalWork; private final AtomicInteger completed; + protected int totalWork; public QueueJob() { totalWork = 0; diff --git a/src/main/java/com/volmit/iris/util/scheduling/jobs/SingleJob.java b/src/main/java/com/volmit/iris/util/scheduling/jobs/SingleJob.java index 549a940df..e2a98817b 100644 --- a/src/main/java/com/volmit/iris/util/scheduling/jobs/SingleJob.java +++ b/src/main/java/com/volmit/iris/util/scheduling/jobs/SingleJob.java @@ -19,9 +19,9 @@ package com.volmit.iris.util.scheduling.jobs; public class SingleJob implements Job { - private boolean done; private final String name; private final Runnable runnable; + private boolean done; public SingleJob(String name, Runnable runnable) { this.name = name; diff --git a/src/main/java/com/volmit/iris/util/stream/ProceduralStream.java b/src/main/java/com/volmit/iris/util/stream/ProceduralStream.java index ac082a688..b7ffa53f8 100644 --- a/src/main/java/com/volmit/iris/util/stream/ProceduralStream.java +++ b/src/main/java/com/volmit/iris/util/stream/ProceduralStream.java @@ -28,11 +28,39 @@ import com.volmit.iris.util.function.Function3; import com.volmit.iris.util.function.Function4; import com.volmit.iris.util.hunk.Hunk; import com.volmit.iris.util.math.RNG; -import com.volmit.iris.util.stream.arithmetic.*; -import com.volmit.iris.util.stream.convert.*; +import com.volmit.iris.util.stream.arithmetic.AddingStream; +import com.volmit.iris.util.stream.arithmetic.ClampedStream; +import com.volmit.iris.util.stream.arithmetic.CoordinateBitShiftLeftStream; +import com.volmit.iris.util.stream.arithmetic.CoordinateBitShiftRightStream; +import com.volmit.iris.util.stream.arithmetic.DividingStream; +import com.volmit.iris.util.stream.arithmetic.FittedStream; +import com.volmit.iris.util.stream.arithmetic.MaxingStream; +import com.volmit.iris.util.stream.arithmetic.MinningStream; +import com.volmit.iris.util.stream.arithmetic.ModuloStream; +import com.volmit.iris.util.stream.arithmetic.MultiplyingStream; +import com.volmit.iris.util.stream.arithmetic.OffsetStream; +import com.volmit.iris.util.stream.arithmetic.RadialStream; +import com.volmit.iris.util.stream.arithmetic.RoundingDoubleStream; +import com.volmit.iris.util.stream.arithmetic.SlopeStream; +import com.volmit.iris.util.stream.arithmetic.SubtractingStream; +import com.volmit.iris.util.stream.arithmetic.ZoomStream; +import com.volmit.iris.util.stream.convert.AwareConversionStream2D; +import com.volmit.iris.util.stream.convert.AwareConversionStream3D; +import com.volmit.iris.util.stream.convert.CachedConversionStream; +import com.volmit.iris.util.stream.convert.ConversionStream; +import com.volmit.iris.util.stream.convert.ForceDoubleStream; +import com.volmit.iris.util.stream.convert.RoundingStream; +import com.volmit.iris.util.stream.convert.SelectionStream; +import com.volmit.iris.util.stream.convert.SignificanceStream; +import com.volmit.iris.util.stream.convert.To3DStream; import com.volmit.iris.util.stream.interpolation.Interpolated; import com.volmit.iris.util.stream.sources.FunctionStream; -import com.volmit.iris.util.stream.utility.*; +import com.volmit.iris.util.stream.utility.CachedStream2D; +import com.volmit.iris.util.stream.utility.CachedStream3D; +import com.volmit.iris.util.stream.utility.NullSafeStream; +import com.volmit.iris.util.stream.utility.ProfiledStream; +import com.volmit.iris.util.stream.utility.SemaphoreStream; +import com.volmit.iris.util.stream.utility.SynchronizedStream; import java.util.List; import java.util.function.Function; diff --git a/src/main/java/com/volmit/iris/util/stream/interpolation/Interpolated.java b/src/main/java/com/volmit/iris/util/stream/interpolation/Interpolated.java index 98926a51a..ddcf59083 100644 --- a/src/main/java/com/volmit/iris/util/stream/interpolation/Interpolated.java +++ b/src/main/java/com/volmit/iris/util/stream/interpolation/Interpolated.java @@ -38,18 +38,6 @@ public interface Interpolated { Interpolated LONG = of(Double::valueOf, Double::longValue); Interpolated UUID = of((i) -> Double.longBitsToDouble(i.getMostSignificantBits()), (i) -> new UUID(Double.doubleToLongBits(i), i.longValue())); - double toDouble(T t); - - T fromDouble(double d); - - default InterpolatorFactory interpolate() { - if (this instanceof ProceduralStream) { - return new InterpolatorFactory<>((ProceduralStream) this); - } - - return null; - } - static Interpolated of(Function a, Function b) { return new Interpolated<>() { @Override @@ -63,4 +51,16 @@ public interface Interpolated { } }; } + + double toDouble(T t); + + T fromDouble(double d); + + default InterpolatorFactory interpolate() { + if (this instanceof ProceduralStream) { + return new InterpolatorFactory<>((ProceduralStream) this); + } + + return null; + } } diff --git a/src/main/java/com/volmit/iris/util/stream/utility/ProfiledStream.java b/src/main/java/com/volmit/iris/util/stream/utility/ProfiledStream.java index b62969dfe..ef900bc23 100644 --- a/src/main/java/com/volmit/iris/util/stream/utility/ProfiledStream.java +++ b/src/main/java/com/volmit/iris/util/stream/utility/ProfiledStream.java @@ -41,50 +41,6 @@ public class ProfiledStream extends BasicStream { this.id = ids.getAndAdd(1); } - public int getId() { - return id; - } - - @Override - public double toDouble(T t) { - return getTypedSource().toDouble(t); - } - - @Override - public T fromDouble(double d) { - return getTypedSource().fromDouble(d); - } - - @Override - public T get(double x, double z) { - PrecisionStopwatch p = PrecisionStopwatch.start(); - T t = getTypedSource().get(x, z); - try { - metrics.put(p.getMilliseconds()); - } catch (Throwable e) { - Iris.reportError(e); - } - - return t; - } - - @Override - public T get(double x, double y, double z) { - PrecisionStopwatch p = PrecisionStopwatch.start(); - T t = getTypedSource().get(x, y, z); - try { - metrics.put(p.getMilliseconds()); - } catch (Throwable e) { - Iris.reportError(e); - } - - return t; - } - - public RollingSequence getMetrics() { - return metrics; - } - public static void print(Consumer printer, ProceduralStream stream) { KList tails = getTails(stream); int ind = tails.size(); @@ -154,12 +110,56 @@ public class ProfiledStream extends BasicStream { return tailx; } + public int getId() { + return id; + } + + @Override + public double toDouble(T t) { + return getTypedSource().toDouble(t); + } + + @Override + public T fromDouble(double d) { + return getTypedSource().fromDouble(d); + } + + @Override + public T get(double x, double z) { + PrecisionStopwatch p = PrecisionStopwatch.start(); + T t = getTypedSource().get(x, z); + try { + metrics.put(p.getMilliseconds()); + } catch (Throwable e) { + Iris.reportError(e); + } + + return t; + } + + @Override + public T get(double x, double y, double z) { + PrecisionStopwatch p = PrecisionStopwatch.start(); + T t = getTypedSource().get(x, y, z); + try { + metrics.put(p.getMilliseconds()); + } catch (Throwable e) { + Iris.reportError(e); + } + + return t; + } + + public RollingSequence getMetrics() { + return metrics; + } + @Data private static class ProfiledTail { private final int id; private final RollingSequence metrics; - private ProfiledTail child; private final String name; + private ProfiledTail child; public ProfiledTail(int id, RollingSequence metrics, String name) { this.id = id; From 986de265fe61edcc4b151611be0fe70798c114f7 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 8 Sep 2021 08:49:34 -0400 Subject: [PATCH 15/15] V+ --- build.gradle | 2 +- .../iris/engine/mantle/components/MantleJigsawComponent.java | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 61aa39d6a..9b648883d 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ plugins { } group 'com.volmit.iris' -version '1.8.6' +version '1.8.7' def apiVersion = '1.17' def name = getRootProject().getName() // Defined in settings.gradle def main = 'com.volmit.iris.Iris' diff --git a/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java b/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java index d8dfcafc4..7478c668f 100644 --- a/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java +++ b/src/main/java/com/volmit/iris/engine/mantle/components/MantleJigsawComponent.java @@ -117,10 +117,6 @@ public class MantleJigsawComponent extends IrisMantleComponent { } writer.setData(position.getX(), 0, position.getZ(), new IrisFeaturePositional(position.getX(), position.getZ(), structure.getFeature())); - - if (structure.getFeature().getEntitySpawners().isNotEmpty()) { - Iris.info("Placed Structure MAIN SPAWN " + structure.getFeature().getEntitySpawners().get(0) + " @R " + structure.getFeature().getBlockRadius()); - } } new PlannedStructure(structure, position, rng).place(writer, getMantle(), post);