From 59f29eb6b4d8a3b0f0fe51e1a4268424f0f60d69 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 16 Mar 2020 11:55:17 -0400 Subject: [PATCH] RV --- pom.xml | 18 +- src/main/java/ninja/bytecode/iris/Iris.java | 197 +- .../ninja/bytecode/iris/IrisGenerator.java | 84 + .../java/ninja/bytecode/iris/Settings.java | 87 - .../bytecode/iris/command/CommandFind.java | 33 - .../iris/command/CommandFindBiome.java | 93 - .../iris/command/CommandFindObject.java | 64 - .../bytecode/iris/command/CommandIris.java | 44 - .../bytecode/iris/command/CommandObject.java | 36 - .../iris/command/CommandObjectLoad.java | 166 -- .../iris/command/CommandObjectSave.java | 67 - .../iris/command/CommandObjectWand.java | 32 - .../bytecode/iris/command/CommandReload.java | 36 - .../iris/command/CommandReloadChunks.java | 38 - .../iris/command/CommandReloadIris.java | 23 - .../iris/command/CommandReloadPack.java | 142 -- .../iris/command/CommandSelection.java | 42 - .../iris/command/CommandSelectionExpand.java | 60 - .../iris/command/CommandSelectionShift.java | 61 - .../iris/command/CommandSelectionShrink.java | 57 - .../iris/command/CommandSelectionXUp.java | 72 - .../iris/command/CommandSelectionXVert.java | 83 - .../bytecode/iris/command/CommandTimings.java | 57 - .../bytecode/iris/command/CommandWhat.java | 36 - .../iris/command/CommandWhatBiome.java | 66 - .../iris/command/CommandWhatBlock.java | 33 - .../iris/command/CommandWhatObject.java | 165 -- .../iris/controller/ExecutionController.java | 64 - .../iris/controller/PackController.java | 358 --- .../iris/controller/WandController.java | 323 --- .../iris/generator/IrisGenerator.java | 728 ------ .../bytecode/iris/generator/IrisSample.java | 81 - .../bytecode/iris/generator/WorldReactor.java | 105 - .../generator/atomics/AtomicCharArray.java | 83 - .../generator/atomics/AtomicChunkData.java | 456 ---- .../generator/atomics/AtomicRegionData.java | 80 - .../generator/atomics/AtomicWorldData.java | 158 -- .../iris/generator/genobject/GenObject.java | 1110 --------- .../genobject/GenObjectDecorator.java | 463 ---- .../generator/genobject/GenObjectGroup.java | 387 --- .../generator/genobject/PlacedObject.java | 95 - .../generator/layer/BiomeNoiseGenerator.java | 34 - .../iris/generator/layer/GenLayerBiome.java | 217 -- .../iris/generator/layer/GenLayerCarving.java | 64 - .../iris/generator/layer/GenLayerCaves.java | 120 - .../iris/generator/layer/GenLayerCliffs.java | 67 - .../generator/layer/GenLayerLayeredNoise.java | 44 - .../iris/generator/layer/GenLayerOres.java | 145 -- .../iris/generator/layer/GenLayerSnow.java | 42 - .../generator/parallax/ParallaxAnchor.java | 45 - .../generator/parallax/ParallaxCache.java | 102 - .../parallax/ParallaxWorldGenerator.java | 194 -- .../parallax/ParallelChunkGenerator.java | 191 -- .../placer/AtomicParallaxPlacer.java | 47 - .../iris/generator/placer/BukkitPlacer.java | 63 - .../iris/generator/placer/NMSPlacer.java | 92 - .../ninja/bytecode/iris/pack/BiomeType.java | 8 - .../bytecode/iris/pack/CompiledDimension.java | 244 -- .../ninja/bytecode/iris/pack/IrisBiome.java | 1113 --------- .../bytecode/iris/pack/IrisDimension.java | 109 - .../ninja/bytecode/iris/pack/IrisPack.java | 86 - .../ninja/bytecode/iris/pack/IrisRegion.java | 123 - .../java/ninja/bytecode/iris/util/Axis.java | 31 - .../iris/util/BasePerlinNoiseGenerator.java | 219 ++ .../ninja/bytecode/iris/util/BiomeLayer.java | 219 -- .../ninja/bytecode/iris/util/BorderCheck.java | 7 - .../ninja/bytecode/iris/util/Borders.java | 44 - .../java/ninja/bytecode/iris/util/CDou.java | 49 - .../ninja/bytecode/iris/util/Catalyst12.java | 52 - .../bytecode/iris/util/ChancedPopulator.java | 74 - .../ninja/bytecode/iris/util/ChronoQueue.java | 71 - .../ninja/bytecode/iris/util/ChunkPlan.java | 138 -- .../iris/util/ChunkSpliceListener.java | 14 - .../bytecode/iris/util/ColoredEffect.java | 10 - .../java/ninja/bytecode/iris/util/Cuboid.java | 921 -------- .../bytecode/iris/util/CuboidException.java | 16 - .../java/ninja/bytecode/iris/util/DOP.java | 20 - .../ninja/bytecode/iris/util/Dimension.java | 86 - .../bytecode/iris/util/DimensionFace.java | 24 - .../ninja/bytecode/iris/util/Direction.java | 534 ----- .../java/ninja/bytecode/iris/util/GBiset.java | 77 - .../bytecode/iris/util/GListAdapter.java | 51 - .../java/ninja/bytecode/iris/util/GRT.java | 10 - .../ninja/bytecode/iris/util/GenLayer.java | 32 - .../ninja/bytecode/iris/util/GlossGlower.java | 106 - .../ninja/bytecode/iris/util/GlowManager.java | 14 - .../java/ninja/bytecode/iris/util/Glower.java | 20 - .../bytecode/iris/util/GlowingBlock.java | 178 -- .../bytecode/iris/util/HotswapGenerator.java | 74 - .../ninja/bytecode/iris/util/IGenLayer.java | 6 - .../java/ninja/bytecode/iris/util/ING.java | 38 + .../ninja/bytecode/iris/util/IPlacer.java | 19 - .../bytecode/iris/util/InterpolationMode.java | 9 - .../bytecode/iris/util/InterpolationType.java | 10 - .../bytecode/iris/util/IrisController.java | 10 - .../bytecode/iris/util/IrisControllerSet.java | 73 - .../bytecode/iris/util/IrisInterpolation.java | 221 -- .../ninja/bytecode/iris/util/IrisMetrics.java | 233 -- .../bytecode/iris/util/IrisWorldData.java | 274 --- .../java/ninja/bytecode/iris/util/MB.java | 102 - .../java/ninja/bytecode/iris/util/MCAPos.java | 102 - .../ninja/bytecode/iris/util/MCAState.java | 80 - .../bytecode/iris/util/NoiseGenerator.java | 231 ++ .../bytecode/iris/util/NoiseProvider.java | 7 - .../ninja/bytecode/iris/util/ObjectMode.java | 33 - .../bytecode/iris/util/PacketCategory.java | 9 - .../ninja/bytecode/iris/util/PacketGate.java | 129 - .../bytecode/iris/util/ParticleBase.java | 30 - .../bytecode/iris/util/ParticleEffect.java | 2101 ----------------- .../bytecode/iris/util/ParticleRedstone.java | 56 - .../bytecode/iris/util/PerformanceMode.java | 11 - .../ninja/bytecode/iris/util/PerlinNoise.java | 175 ++ .../java/ninja/bytecode/iris/util/Placer.java | 24 - .../bytecode/iris/util/PolygonGenerator.java | 219 -- .../bytecode/iris/util/PrepackagedChunk.java | 37 - .../java/ninja/bytecode/iris/util/RNG.java | 176 ++ .../ninja/bytecode/iris/util/RealBiome.java | 44 - .../bytecode/iris/util/ReflectionUtils.java | 822 ------- .../bytecode/iris/util/SBlockVector.java | 169 -- .../bytecode/iris/util/SChunkVector.java | 76 - .../bytecode/iris/util/SChunkVectorShort.java | 72 - .../ninja/bytecode/iris/util/SMCAVector.java | 61 - .../java/ninja/bytecode/iris/util/SNG.java | 378 +++ .../ninja/bytecode/iris/util/VectorMath.java | 754 ------ .../bytecode/iris/util/VisualEffect.java | 17 - .../ninja/bytecode/iris/util/WorldState.java | 132 -- src/main/java/org/jnbt/ByteArrayTag.java | 82 - src/main/java/org/jnbt/ByteTag.java | 74 - src/main/java/org/jnbt/CompoundTag.java | 83 - src/main/java/org/jnbt/DoubleTag.java | 74 - src/main/java/org/jnbt/EndTag.java | 60 - src/main/java/org/jnbt/FloatTag.java | 74 - src/main/java/org/jnbt/IntArrayTag.java | 76 - src/main/java/org/jnbt/IntTag.java | 74 - src/main/java/org/jnbt/ListTag.java | 99 - src/main/java/org/jnbt/LongTag.java | 74 - src/main/java/org/jnbt/NBTConstants.java | 77 - src/main/java/org/jnbt/NBTInputStream.java | 205 -- src/main/java/org/jnbt/NBTOutputStream.java | 301 --- src/main/java/org/jnbt/NBTUtils.java | 165 -- src/main/java/org/jnbt/ShortTag.java | 74 - src/main/java/org/jnbt/StringTag.java | 74 - src/main/java/org/jnbt/Tag.java | 73 - src/main/resources/plugin.yml | 2 +- 144 files changed, 1335 insertions(+), 19970 deletions(-) create mode 100644 src/main/java/ninja/bytecode/iris/IrisGenerator.java delete mode 100644 src/main/java/ninja/bytecode/iris/Settings.java delete mode 100644 src/main/java/ninja/bytecode/iris/command/CommandFind.java delete mode 100644 src/main/java/ninja/bytecode/iris/command/CommandFindBiome.java delete mode 100644 src/main/java/ninja/bytecode/iris/command/CommandFindObject.java delete mode 100644 src/main/java/ninja/bytecode/iris/command/CommandIris.java delete mode 100644 src/main/java/ninja/bytecode/iris/command/CommandObject.java delete mode 100644 src/main/java/ninja/bytecode/iris/command/CommandObjectLoad.java delete mode 100644 src/main/java/ninja/bytecode/iris/command/CommandObjectSave.java delete mode 100644 src/main/java/ninja/bytecode/iris/command/CommandObjectWand.java delete mode 100644 src/main/java/ninja/bytecode/iris/command/CommandReload.java delete mode 100644 src/main/java/ninja/bytecode/iris/command/CommandReloadChunks.java delete mode 100644 src/main/java/ninja/bytecode/iris/command/CommandReloadIris.java delete mode 100644 src/main/java/ninja/bytecode/iris/command/CommandReloadPack.java delete mode 100644 src/main/java/ninja/bytecode/iris/command/CommandSelection.java delete mode 100644 src/main/java/ninja/bytecode/iris/command/CommandSelectionExpand.java delete mode 100644 src/main/java/ninja/bytecode/iris/command/CommandSelectionShift.java delete mode 100644 src/main/java/ninja/bytecode/iris/command/CommandSelectionShrink.java delete mode 100644 src/main/java/ninja/bytecode/iris/command/CommandSelectionXUp.java delete mode 100644 src/main/java/ninja/bytecode/iris/command/CommandSelectionXVert.java delete mode 100644 src/main/java/ninja/bytecode/iris/command/CommandTimings.java delete mode 100644 src/main/java/ninja/bytecode/iris/command/CommandWhat.java delete mode 100644 src/main/java/ninja/bytecode/iris/command/CommandWhatBiome.java delete mode 100644 src/main/java/ninja/bytecode/iris/command/CommandWhatBlock.java delete mode 100644 src/main/java/ninja/bytecode/iris/command/CommandWhatObject.java delete mode 100644 src/main/java/ninja/bytecode/iris/controller/ExecutionController.java delete mode 100644 src/main/java/ninja/bytecode/iris/controller/PackController.java delete mode 100644 src/main/java/ninja/bytecode/iris/controller/WandController.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/IrisGenerator.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/IrisSample.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/WorldReactor.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/atomics/AtomicCharArray.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/atomics/AtomicChunkData.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/atomics/AtomicRegionData.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/atomics/AtomicWorldData.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/genobject/GenObject.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectDecorator.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectGroup.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/genobject/PlacedObject.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/layer/BiomeNoiseGenerator.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/layer/GenLayerBiome.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCarving.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCaves.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCliffs.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/layer/GenLayerLayeredNoise.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/layer/GenLayerOres.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/layer/GenLayerSnow.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/parallax/ParallaxAnchor.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/parallax/ParallaxCache.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/parallax/ParallaxWorldGenerator.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/parallax/ParallelChunkGenerator.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/placer/AtomicParallaxPlacer.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/placer/BukkitPlacer.java delete mode 100644 src/main/java/ninja/bytecode/iris/generator/placer/NMSPlacer.java delete mode 100644 src/main/java/ninja/bytecode/iris/pack/BiomeType.java delete mode 100644 src/main/java/ninja/bytecode/iris/pack/CompiledDimension.java delete mode 100644 src/main/java/ninja/bytecode/iris/pack/IrisBiome.java delete mode 100644 src/main/java/ninja/bytecode/iris/pack/IrisDimension.java delete mode 100644 src/main/java/ninja/bytecode/iris/pack/IrisPack.java delete mode 100644 src/main/java/ninja/bytecode/iris/pack/IrisRegion.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/Axis.java create mode 100644 src/main/java/ninja/bytecode/iris/util/BasePerlinNoiseGenerator.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/BiomeLayer.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/BorderCheck.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/Borders.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/CDou.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/Catalyst12.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/ChancedPopulator.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/ChronoQueue.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/ChunkPlan.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/ChunkSpliceListener.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/ColoredEffect.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/Cuboid.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/CuboidException.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/DOP.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/Dimension.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/DimensionFace.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/Direction.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/GBiset.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/GListAdapter.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/GRT.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/GenLayer.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/GlossGlower.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/GlowManager.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/Glower.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/GlowingBlock.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/HotswapGenerator.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/IGenLayer.java create mode 100644 src/main/java/ninja/bytecode/iris/util/ING.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/IPlacer.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/InterpolationMode.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/InterpolationType.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/IrisController.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/IrisControllerSet.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/IrisInterpolation.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/IrisMetrics.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/IrisWorldData.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/MB.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/MCAPos.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/MCAState.java create mode 100644 src/main/java/ninja/bytecode/iris/util/NoiseGenerator.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/NoiseProvider.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/ObjectMode.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/PacketCategory.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/PacketGate.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/ParticleBase.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/ParticleEffect.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/ParticleRedstone.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/PerformanceMode.java create mode 100644 src/main/java/ninja/bytecode/iris/util/PerlinNoise.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/Placer.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/PolygonGenerator.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/PrepackagedChunk.java create mode 100644 src/main/java/ninja/bytecode/iris/util/RNG.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/RealBiome.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/ReflectionUtils.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/SBlockVector.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/SChunkVector.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/SChunkVectorShort.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/SMCAVector.java create mode 100644 src/main/java/ninja/bytecode/iris/util/SNG.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/VectorMath.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/VisualEffect.java delete mode 100644 src/main/java/ninja/bytecode/iris/util/WorldState.java delete mode 100644 src/main/java/org/jnbt/ByteArrayTag.java delete mode 100644 src/main/java/org/jnbt/ByteTag.java delete mode 100644 src/main/java/org/jnbt/CompoundTag.java delete mode 100644 src/main/java/org/jnbt/DoubleTag.java delete mode 100644 src/main/java/org/jnbt/EndTag.java delete mode 100644 src/main/java/org/jnbt/FloatTag.java delete mode 100644 src/main/java/org/jnbt/IntArrayTag.java delete mode 100644 src/main/java/org/jnbt/IntTag.java delete mode 100644 src/main/java/org/jnbt/ListTag.java delete mode 100644 src/main/java/org/jnbt/LongTag.java delete mode 100644 src/main/java/org/jnbt/NBTConstants.java delete mode 100644 src/main/java/org/jnbt/NBTInputStream.java delete mode 100644 src/main/java/org/jnbt/NBTOutputStream.java delete mode 100644 src/main/java/org/jnbt/NBTUtils.java delete mode 100644 src/main/java/org/jnbt/ShortTag.java delete mode 100644 src/main/java/org/jnbt/StringTag.java delete mode 100644 src/main/java/org/jnbt/Tag.java diff --git a/pom.xml b/pom.xml index 52035c6d0..ad53524d0 100644 --- a/pom.xml +++ b/pom.xml @@ -144,26 +144,16 @@ - - ninja.bytecode - Shuriken - 1.1.14 - - - com.volmit - Mortar - 1.0.76 - org.spigotmc spigot-api - 1.12.2-R0.1-SNAPSHOT + 1.15.1-R0.1-SNAPSHOT provided - org.bukkit.craftbukkit - cb-1.12.2 - 1.12.2 + org.bukkit + bukkit + 1.15.1-R0.1-SNAPSHOT provided diff --git a/src/main/java/ninja/bytecode/iris/Iris.java b/src/main/java/ninja/bytecode/iris/Iris.java index e31c4f619..f241a0f33 100644 --- a/src/main/java/ninja/bytecode/iris/Iris.java +++ b/src/main/java/ninja/bytecode/iris/Iris.java @@ -1,200 +1,61 @@ package ninja.bytecode.iris; -import java.io.File; import java.util.UUID; import org.bukkit.Bukkit; -import org.bukkit.Difficulty; +import org.bukkit.GameMode; +import org.bukkit.Location; import org.bukkit.World; -import org.bukkit.World.Environment; +import org.bukkit.WorldCreator; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.generator.ChunkGenerator; -import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; -import mortar.api.rift.PhantomRift; -import mortar.api.rift.Rift; -import mortar.api.rift.RiftException; -import mortar.bukkit.command.Command; -import mortar.bukkit.plugin.Control; -import mortar.bukkit.plugin.MortarPlugin; -import mortar.util.text.C; -import ninja.bytecode.iris.command.CommandIris; -import ninja.bytecode.iris.controller.ExecutionController; -import ninja.bytecode.iris.controller.PackController; -import ninja.bytecode.iris.controller.WandController; -import ninja.bytecode.iris.generator.IrisGenerator; -import ninja.bytecode.iris.util.Direction; -import ninja.bytecode.iris.util.HotswapGenerator; -import ninja.bytecode.iris.util.IrisMetrics; -import ninja.bytecode.shuriken.logging.L; - -public class Iris extends MortarPlugin +public class Iris extends JavaPlugin { - public static Thread primaryThread; - public static Settings settings; - public static IrisMetrics metrics; - private static ExecutionController executionController; - - public static Iris instance; - - @Control - private PackController packController; - - @Control - private WandController wandController; - - @Command - private CommandIris commandIris; - - private Rift r; - - @Override public void onEnable() { - instance = this; - executionController = new ExecutionController(); - executionController.start(); - primaryThread = Thread.currentThread(); - L.consoleConsumer = (s) -> Bukkit.getConsoleSender().sendMessage(s); - Direction.calculatePermutations(); - settings = new Settings(); - getServer().getPluginManager().registerEvents((Listener) this, this); - super.onEnable(); - } - public File getObjectCacheFolder() - { - return getDataFolder("cache", "object"); - } - - public static boolean isGen(World world) - { - IrisGenerator g = getGen(world); - return g != null; - } - - public static IrisGenerator getGen(World world) - { - try + Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> { - return (IrisGenerator) ((HotswapGenerator) world.getGenerator()).getGenerator(); - } - - catch(Throwable e) - { - - } - - return null; - } - - @Override - public void start() - { - instance = this; - packController.compile(); - - if(Iris.settings.performance.debugMode) - { - try + for(World i : Bukkit.getWorlds()) { - //@builder - r = new PhantomRift("Iris-Debug/" + UUID.randomUUID().toString()) - .setTileTickLimit(0.1) - .setEntityTickLimit(0.1) - .setAllowBosses(false) - .setEnvironment(Environment.NORMAL) - .setDifficulty(Difficulty.PEACEFUL) - .setRandomLightUpdates(false) - .setViewDistance(32) - .setHangingTickRate(2000) - .setGenerator(IrisGenerator.class) - .load(); - - for(Player i : Bukkit.getOnlinePlayers()) + if(i.getName().startsWith("iris/")) { - r.send(i); + Bukkit.unloadWorld(i, false); } - //@done } - catch(RiftException e) + World world = Bukkit.createWorld(new WorldCreator("iris/" + UUID.randomUUID()).generator(new IrisGenerator())); + + for(Player i : Bukkit.getOnlinePlayers()) { - e.printStackTrace(); + i.teleport(new Location(world, 0, 100, 0)); + + Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> + { + i.setGameMode(GameMode.SPECTATOR); + }, 5); } - } + }); + } + + public void onDisable() + { + } @Override - public void stop() + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if(settings.performance.debugMode && r != null) - { - r.colapse(); - } - - HandlerList.unregisterAll((Plugin) this); - Bukkit.getScheduler().cancelTasks(this); - executionController.stop(); - } - - @EventHandler - public void on(PlayerJoinEvent e) - { - if(settings.performance.debugMode && r != null) - { - e.getPlayer().teleport(r.getSpawn()); - } - } - - public void reload() - { - Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> - { - onDisable(); - onEnable(); - }); + return false; } @Override public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) { - return new HotswapGenerator(new IrisGenerator()); - } - - @Override - public String getTag(String arg0) - { - return makeTag(C.GREEN, C.DARK_GRAY, C.GRAY, C.BOLD + "Iris" + C.RESET); - } - - public static String makeTag(C brace, C tag, C text, String tagName) - { - return brace + "\u3008" + tag + tagName + brace + "\u3009" + " " + text; - } - - public static PackController pack() - { - return instance.packController; - } - - public static ExecutionController exec() - { - if(executionController == null) - { - executionController = new ExecutionController(); - executionController.start(); - } - - return executionController; - } - - public static WandController wand() - { - return instance.wandController; + return new IrisGenerator(); } } diff --git a/src/main/java/ninja/bytecode/iris/IrisGenerator.java b/src/main/java/ninja/bytecode/iris/IrisGenerator.java new file mode 100644 index 000000000..d3a74a5e7 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/IrisGenerator.java @@ -0,0 +1,84 @@ +package ninja.bytecode.iris; + +import java.util.List; +import java.util.Random; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.generator.BlockPopulator; +import org.bukkit.generator.ChunkGenerator; + +import ninja.bytecode.iris.util.ING; +import ninja.bytecode.iris.util.RNG; + +public class IrisGenerator extends ChunkGenerator +{ + private boolean initialized = false; + private ING sng; + + public void onInit() + { + if(initialized) + { + return; + } + + initialized = true; + + sng = new ING(new RNG(), 2); + } + + @Override + public boolean canSpawn(World world, int x, int z) + { + return super.canSpawn(world, x, z); + } + + @Override + public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) + { + onInit(); + ChunkData data = Bukkit.createChunkData(world); + + for(int i = 0; i < 16; i++) + { + for(int j = 0; j < 16; j++) + { + double wx = (x * 16) + i; + double wz = (z * 16) + j; + int y = (int) Math.round(sng.noise(wx / 30D, wz / 30D) * 20); + for(int k = 0; k < 4; k++) + { + if(k < 0) + { + continue; + } + + data.setBlock(i, k + y, j, Material.STONE.createBlockData()); + } + } + } + + return data; + } + + @Override + public List getDefaultPopulators(World world) + { + return super.getDefaultPopulators(world); + } + + @Override + public Location getFixedSpawnLocation(World world, Random random) + { + return super.getFixedSpawnLocation(world, random); + } + + @Override + public boolean isParallelCapable() + { + return true; + } +} diff --git a/src/main/java/ninja/bytecode/iris/Settings.java b/src/main/java/ninja/bytecode/iris/Settings.java deleted file mode 100644 index 893034845..000000000 --- a/src/main/java/ninja/bytecode/iris/Settings.java +++ /dev/null @@ -1,87 +0,0 @@ -package ninja.bytecode.iris; - -import ninja.bytecode.iris.util.InterpolationMode; -import ninja.bytecode.iris.util.ObjectMode; -import ninja.bytecode.iris.util.PerformanceMode; - -public class Settings -{ - public PerformanceSettings performance = new PerformanceSettings(); - public GeneratorSettings gen = new GeneratorSettings(); - public OreSettings ore = new OreSettings(); - - public static class PerformanceSettings - { - public PerformanceMode performanceMode = PerformanceMode.EXPLICIT; - public ObjectMode objectMode = ObjectMode.PARALLAX; - public int threadPriority = Thread.MAX_PRIORITY; - public int threadCount = 32; - public boolean debugMode = true; - public int decorationAccuracy = 1; - public boolean noObjectFail = false; - public boolean verbose = false; - public int placeHistoryLimit = 8192; - } - - public static class GeneratorSettings - { - public InterpolationMode interpolationMode = InterpolationMode.BILINEAR; - public int interpolationRadius = 53; - public int blockSmoothing = 1; - public double objectDensity = 1D; - public double horizontalZoom = 2; - public double heightFracture = 155; - public double landScale = 0.44; - public double landChance = 0.56; - public double roughness = 1.25; - public double biomeEdgeFuzzScale = 1.75; - public double biomeEdgeScrambleScale = 0.2; - public double biomeEdgeScrambleRange = 2.5; - public double heightMultiplier = 0.806; - public double heightExponentBase = 1; - public double heightExponentMultiplier = 1.41; - public double heightScale = 0.56; - public double baseHeight = 0.065; - public int seaLevel = 63; - public double biomeScale = 0.8; - public boolean flatBedrock = false; - } - - public static class OreSettings - { - public int ironMinHeight = 5; - public int ironMaxHeight = 65; - public double ironMaxDispersion = 0.02; - public double ironMinDispersion = 0.26; - - public int coalMinHeight = 5; - public int coalMaxHeight = 100; - public double coalMaxDispersion = 0.02; - public double coalMinDispersion = 0.29; - - public int goldMinHeight = 5; - public int goldMaxHeight = 34; - public double goldMaxDispersion = 0.01; - public double goldMinDispersion = 0.13; - - public int redstoneMinHeight = 5; - public int redstoneMaxHeight = 15; - public double redstoneMaxDispersion = 0.05; - public double redstoneMinDispersion = 0.17; - - public int lapisMinHeight = 13; - public int lapisMaxHeight = 33; - public double lapisMaxDispersion = 0.05; - public double lapisMinDispersion = 0.12; - - public int diamondMinHeight = 5; - public int diamondMaxHeight = 16; - public double diamondMaxDispersion = 0.05; - public double diamondMinDispersion = 0.1; - - public int emeraldMinHeight = 5; - public int emeraldMaxHeight = 16; - public double emeraldMaxDispersion = 0.005; - public double emeraldMinDispersion = 0.07; - } -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandFind.java b/src/main/java/ninja/bytecode/iris/command/CommandFind.java deleted file mode 100644 index 7a47f0f61..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandFind.java +++ /dev/null @@ -1,33 +0,0 @@ -package ninja.bytecode.iris.command; - -import mortar.bukkit.command.Command; -import mortar.bukkit.command.MortarCommand; -import mortar.bukkit.command.MortarSender; -import mortar.util.text.C; - -public class CommandFind extends MortarCommand -{ - @Command - private CommandFindBiome fBiome; - - @Command - private CommandFindObject fObject; - - public CommandFind() - { - super("find", "f"); - setDescription("Teleport to a specific biome / object"); - } - - @Override - public boolean handle(MortarSender sender, String[] args) - { - for(MortarCommand i : getChildren()) - { - sender.sendMessage("/iris find " + C.WHITE + i.getNode() + C.GRAY + (!i.getNodes().isEmpty() ? "," : "") + i.getNodes().toString(",") + " - " + C.DARK_GREEN + i.getDescription()); - } - - return true; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandFindBiome.java b/src/main/java/ninja/bytecode/iris/command/CommandFindBiome.java deleted file mode 100644 index c158ce1bd..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandFindBiome.java +++ /dev/null @@ -1,93 +0,0 @@ -package ninja.bytecode.iris.command; - -import org.bukkit.World; -import org.bukkit.entity.Player; - -import mortar.bukkit.command.MortarCommand; -import mortar.bukkit.command.MortarSender; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.generator.IrisGenerator; -import ninja.bytecode.iris.pack.IrisBiome; - -public class CommandFindBiome extends MortarCommand -{ - public CommandFindBiome() - { - super("biome", "b"); - setDescription("Teleport to a biome by name"); - } - - @Override - public boolean handle(MortarSender sender, String[] args) - { - World w = null; - - if(sender.isPlayer() && Iris.isGen(sender.player().getWorld())) - { - w = sender.player().getWorld(); - } - - else - { - if(sender.isPlayer()) - { - sender.sendMessage(sender.player().getWorld().getGenerator().getClass().getCanonicalName()); - } - - sender.sendMessage("Console / Non-Iris World."); - return true; - } - - Player p = sender.player(); - IrisGenerator g = Iris.getGen(p.getWorld()); - if(args.length > 0) - { - IrisBiome b = null; - for(IrisBiome i : g.getDimension().getBiomes()) - { - if(args[0].toLowerCase().equals(i.getName().toLowerCase().replaceAll("\\Q \\E", "_"))) - { - b = i; - break; - } - } - - if(b == null) - { - sender.sendMessage("Couldn't find any biomes containing '" + args[0] + "'."); - } - - else - { - sender.sendMessage("Looking for Biome " + b.getName() + "..."); - boolean f = false; - - for(int i = 0; i < 10000; i++) - { - int x = (int) ((int) (29999983 / 1.2) * Math.random()); - int z = (int) ((int) (29999983 / 1.2) * Math.random()); - - if(g.getBiome((int) g.getOffsetX(x, z), (int) g.getOffsetZ(x, z)).equals(b)) - { - f = true; - p.teleport(w.getHighestBlockAt(x, z).getLocation()); - break; - } - } - - if(!f) - { - sender.sendMessage("Couldn't for " + b.getName() + " in 10,000 different locations and could not find it. Try again!"); - } - } - } - - else - { - sender.sendMessage("/iris find biome "); - } - - return true; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandFindObject.java b/src/main/java/ninja/bytecode/iris/command/CommandFindObject.java deleted file mode 100644 index 387f964f2..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandFindObject.java +++ /dev/null @@ -1,64 +0,0 @@ -package ninja.bytecode.iris.command; - -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.Player; - -import mortar.bukkit.command.MortarCommand; -import mortar.bukkit.command.MortarSender; -import mortar.util.text.C; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.generator.genobject.PlacedObject; - -public class CommandFindObject extends MortarCommand -{ - public CommandFindObject() - { - super("object", "o"); - setDescription("Teleport to an object by name"); - } - - @Override - public boolean handle(MortarSender sender, String[] args) - { - World w = null; - - if(sender.isPlayer() && Iris.isGen(sender.player().getWorld())) - { - w = sender.player().getWorld(); - } - - else - { - sender.sendMessage("Console / Non-Iris World."); - return true; - } - - Player p = sender.player(); - - if(args.length > 0) - { - PlacedObject o = Iris.getGen(w).randomObject(args[0]); - - if(o != null) - { - Location l = new Location(w, o.getX(), o.getY(), o.getZ()); - p.teleport(l); - sender.sendMessage("Found Object " + C.DARK_GREEN + o.getF().replace(":", "/" + C.WHITE)); - } - - else - { - sender.sendMessage("Couldn't find any objects containing '" + args[0] + "' Either"); - } - } - - else - { - sender.sendMessage("/iris find object "); - } - - return true; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandIris.java b/src/main/java/ninja/bytecode/iris/command/CommandIris.java deleted file mode 100644 index a7907abb8..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandIris.java +++ /dev/null @@ -1,44 +0,0 @@ -package ninja.bytecode.iris.command; - -import mortar.bukkit.command.Command; -import mortar.bukkit.command.MortarCommand; -import mortar.bukkit.command.MortarSender; -import mortar.util.text.C; - -public class CommandIris extends MortarCommand -{ - @Command - private CommandTimings timings; - - @Command - private CommandWhat what; - - @Command - private CommandFind find; - - @Command - private CommandObject object; - - @Command - private CommandSelection selection; - - @Command - private CommandReload reload; - - public CommandIris() - { - super("iris", "irs", "ir"); - } - - @Override - public boolean handle(MortarSender sender, String[] args) - { - for(MortarCommand i : getChildren()) - { - sender.sendMessage("/iris " + C.WHITE + i.getNode() + C.GRAY + (!i.getNodes().isEmpty() ? "," : "") + i.getNodes().toString(",") + " - " + C.DARK_GREEN + i.getDescription()); - } - - return true; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandObject.java b/src/main/java/ninja/bytecode/iris/command/CommandObject.java deleted file mode 100644 index 1c44cabfe..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandObject.java +++ /dev/null @@ -1,36 +0,0 @@ -package ninja.bytecode.iris.command; - -import mortar.bukkit.command.Command; -import mortar.bukkit.command.MortarCommand; -import mortar.bukkit.command.MortarSender; -import mortar.util.text.C; - -public class CommandObject extends MortarCommand -{ - @Command - private CommandObjectWand oWand; - - @Command - private CommandObjectLoad oLoad; - - @Command - private CommandObjectSave oSave; - - public CommandObject() - { - super("object", "o"); - setDescription("Object Subcommands"); - } - - @Override - public boolean handle(MortarSender sender, String[] args) - { - for(MortarCommand i : getChildren()) - { - sender.sendMessage("/iris object " + C.WHITE + i.getNode() + C.GRAY + (!i.getNodes().isEmpty() ? "," : "") + i.getNodes().toString(",") + " - " + C.DARK_GREEN + i.getDescription()); - } - - return true; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandObjectLoad.java b/src/main/java/ninja/bytecode/iris/command/CommandObjectLoad.java deleted file mode 100644 index db4ddcb18..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandObjectLoad.java +++ /dev/null @@ -1,166 +0,0 @@ -package ninja.bytecode.iris.command; - -import java.io.File; -import java.io.FileInputStream; - -import org.bukkit.Location; -import org.bukkit.Sound; -import org.bukkit.entity.Player; - -import mortar.bukkit.command.MortarCommand; -import mortar.bukkit.command.MortarSender; -import mortar.util.text.C; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.controller.WandController; -import ninja.bytecode.iris.generator.genobject.GenObject; -import ninja.bytecode.iris.util.Direction; -import ninja.bytecode.shuriken.format.Form; - -public class CommandObjectLoad extends MortarCommand -{ - public CommandObjectLoad() - { - super("load", "l"); - setDescription("Load & Paste an object"); - } - - @Override - public boolean handle(MortarSender sender, String[] args) - { - if(!sender.isPlayer()) - { - sender.sendMessage("Players Only"); - return true; - } - - if(args.length < 1) - { - sender.sendMessage("/iris object load "); - sender.sendMessage("Use -c to place at cursor"); - sender.sendMessage("Use -g to place with gravity"); - sender.sendMessage("Use -w to set hydrophilic"); - sender.sendMessage("Use -u to set submerged"); - sender.sendMessage("Use -h: to shift vertically"); - sender.sendMessage("Use -m: to set max slope"); - sender.sendMessage("Use -b: to set base slope"); - sender.sendMessage("Use -f:N -t:S to rotate north to south (180 deg)"); - return true; - } - - Player p = sender.player(); - - GenObject s = new GenObject(1, 1, 1); - File f = new File(Iris.instance.getDataFolder(), "schematics/" + args[0] + ".ish"); - - if(!f.exists()) - { - sender.sendMessage("Can't find " + args[0]); - return true; - } - - try - { - FileInputStream fin = new FileInputStream(f); - s.read(fin, true); - - boolean cursor = false; - boolean gravity = false; - Direction df = null; - Direction dt = null; - int shift = 0; - - for(String i : args) - { - if(i.equalsIgnoreCase("-c")) - { - sender.sendMessage("Placing @ Cursor"); - cursor = true; - continue; - } - - if(i.equalsIgnoreCase("-u")) - { - sender.sendMessage("Placing Submerged"); - s.setSubmerged(true); - continue; - } - - if(i.equalsIgnoreCase("-w")) - { - sender.sendMessage("Placing with Hydrophilia"); - s.setHydrophilic(true); - continue; - } - - if(i.equalsIgnoreCase("-g")) - { - sender.sendMessage("Placing with Gravity"); - gravity = true; - continue; - } - - if(i.startsWith("-m:")) - { - shift = Integer.valueOf(i.split("\\Q:\\E")[1]); - sender.sendMessage("Max Slope set to " + shift); - s.setMaxslope(shift); - continue; - } - - if(i.startsWith("-b:")) - { - shift = Integer.valueOf(i.split("\\Q:\\E")[1]); - sender.sendMessage("Base Slope set to " + shift); - s.setBaseslope(shift); - continue; - } - - if(i.startsWith("-h:")) - { - shift = Integer.valueOf(i.split("\\Q:\\E")[1]); - sender.sendMessage("Shifting Placement by 0," + shift + ",0"); - continue; - } - - if(i.startsWith("-f:")) - { - df = Direction.valueOf(i.split("\\Q:\\E")[1].toUpperCase().substring(0, 1)); - continue; - } - - if(i.startsWith("-t:")) - { - dt = Direction.valueOf(i.split("\\Q:\\E")[1].toUpperCase().substring(0, 1)); - continue; - } - } - - if(dt != null && df != null) - { - sender.sendMessage("Rotating " + C.WHITE + df + C.GRAY + " to " + C.WHITE + dt); - s.rotate(df, dt); - } - - Location at = p.getLocation(); - - if(cursor) - { - at = p.getTargetBlock(null, 64).getLocation(); - } - - s.setShift(0, shift, 0); - s.setGravity(gravity); - WandController.pasteSchematic(s, at); - p.playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.25f); - sender.sendMessage("Pasted " + args[0] + " (" + Form.f(s.getSchematic().size()) + " Blocks Modified)"); - } - - catch(Throwable e1) - { - e1.printStackTrace(); - } - - return true; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandObjectSave.java b/src/main/java/ninja/bytecode/iris/command/CommandObjectSave.java deleted file mode 100644 index f0a36430e..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandObjectSave.java +++ /dev/null @@ -1,67 +0,0 @@ -package ninja.bytecode.iris.command; - -import java.io.File; -import java.io.FileOutputStream; - -import org.bukkit.Sound; -import org.bukkit.entity.Player; - -import mortar.bukkit.command.MortarCommand; -import mortar.bukkit.command.MortarSender; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.controller.WandController; -import ninja.bytecode.iris.generator.genobject.GenObject; -import ninja.bytecode.shuriken.format.Form; - -public class CommandObjectSave extends MortarCommand -{ - public CommandObjectSave() - { - super("save", "s"); - setDescription("Save an object"); - } - - @Override - public boolean handle(MortarSender sender, String[] args) - { - if(!sender.isPlayer()) - { - sender.sendMessage("Players Only"); - return true; - } - - if(args.length < 1) - { - sender.sendMessage("/iris object save "); - return true; - } - - Player p = sender.player(); - GenObject s = WandController.createSchematic(p.getInventory().getItemInMainHand(), p.getLocation()); - - if(s == null) - { - sender.sendMessage("Hold your wand while using this command."); - return true; - } - - File f = new File(Iris.instance.getDataFolder(), "schematics/" + args[0] + ".ish"); - f.getParentFile().mkdirs(); - try - { - FileOutputStream fos = new FileOutputStream(f); - s.write(fos, true); - p.sendMessage("Saved " + args[0] + " (" + Form.f(s.getSchematic().size()) + " Entries)"); - p.playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 0.45f); - } - - catch(Throwable e1) - { - p.sendMessage("Failed. Check the console!"); - e1.printStackTrace(); - } - - return true; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandObjectWand.java b/src/main/java/ninja/bytecode/iris/command/CommandObjectWand.java deleted file mode 100644 index b98f2166b..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandObjectWand.java +++ /dev/null @@ -1,32 +0,0 @@ -package ninja.bytecode.iris.command; - -import org.bukkit.Sound; - -import mortar.bukkit.command.MortarCommand; -import mortar.bukkit.command.MortarSender; -import ninja.bytecode.iris.controller.WandController; - -public class CommandObjectWand extends MortarCommand -{ - public CommandObjectWand() - { - super("wand", "w"); - setDescription("Obtain Iris Wand"); - } - - @Override - public boolean handle(MortarSender sender, String[] args) - { - if(!sender.isPlayer()) - { - sender.sendMessage("Players Only"); - return true; - } - - sender.player().getInventory().addItem(WandController.createWand()); - sender.player().playSound(sender.player().getLocation(), Sound.ITEM_ARMOR_EQUIP_DIAMOND, 1f, 1.55f); - - return true; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandReload.java b/src/main/java/ninja/bytecode/iris/command/CommandReload.java deleted file mode 100644 index 45d2a2afc..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandReload.java +++ /dev/null @@ -1,36 +0,0 @@ -package ninja.bytecode.iris.command; - -import mortar.bukkit.command.Command; -import mortar.bukkit.command.MortarCommand; -import mortar.bukkit.command.MortarSender; -import mortar.util.text.C; - -public class CommandReload extends MortarCommand -{ - @Command - private CommandReloadPack rThis; - - @Command - private CommandReloadChunks rChunks; - - @Command - private CommandReloadIris rIris; - - public CommandReload() - { - super("reload", "r"); - setDescription("Reload Chunks / Pack / Iris"); - } - - @Override - public boolean handle(MortarSender sender, String[] args) - { - for(MortarCommand i : getChildren()) - { - sender.sendMessage("/iris reload " + C.WHITE + i.getNode() + C.GRAY + (!i.getNodes().isEmpty() ? "," : "") + i.getNodes().toString(",") + " - " + C.DARK_GREEN + i.getDescription()); - } - - return true; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandReloadChunks.java b/src/main/java/ninja/bytecode/iris/command/CommandReloadChunks.java deleted file mode 100644 index 2bfc5e9c0..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandReloadChunks.java +++ /dev/null @@ -1,38 +0,0 @@ -package ninja.bytecode.iris.command; - -import org.bukkit.Chunk; -import org.bukkit.entity.Player; - -import mortar.api.nms.NMP; -import mortar.bukkit.command.MortarCommand; -import mortar.bukkit.command.MortarSender; - -public class CommandReloadChunks extends MortarCommand -{ - public CommandReloadChunks() - { - super("chunks", "c"); - setDescription("Resends chunk packets."); - } - - @Override - public boolean handle(MortarSender sender, String[] args) - { - - if(!sender.isPlayer()) - { - sender.sendMessage("Again, You don't have a position. Stop it."); - } - - sender.sendMessage("Resending Chunks in your view distance."); - Player p = sender.player(); - - for(Chunk i : p.getWorld().getLoadedChunks()) - { - NMP.CHUNK.refreshIgnorePosition(p, i); - } - - return true; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandReloadIris.java b/src/main/java/ninja/bytecode/iris/command/CommandReloadIris.java deleted file mode 100644 index 892c06388..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandReloadIris.java +++ /dev/null @@ -1,23 +0,0 @@ -package ninja.bytecode.iris.command; - -import mortar.bukkit.command.MortarCommand; -import mortar.bukkit.command.MortarSender; -import ninja.bytecode.iris.Iris; - -public class CommandReloadIris extends MortarCommand -{ - public CommandReloadIris() - { - super("iris", "i"); - setDescription("Reloads Iris"); - } - - @Override - public boolean handle(MortarSender sender, String[] args) - { - Iris.instance.reload(); - - return true; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandReloadPack.java b/src/main/java/ninja/bytecode/iris/command/CommandReloadPack.java deleted file mode 100644 index 63bc8c350..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandReloadPack.java +++ /dev/null @@ -1,142 +0,0 @@ -package ninja.bytecode.iris.command; - -import java.util.function.Consumer; - -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.entity.Player; - -import mortar.api.sched.J; -import mortar.bukkit.command.MortarCommand; -import mortar.bukkit.command.MortarSender; -import mortar.logic.queue.ChronoLatch; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.controller.PackController; -import ninja.bytecode.iris.generator.IrisGenerator; -import ninja.bytecode.iris.generator.WorldReactor; -import ninja.bytecode.iris.pack.CompiledDimension; -import ninja.bytecode.shuriken.collections.KList; -import ninja.bytecode.shuriken.collections.KMap; -import ninja.bytecode.shuriken.format.Form; -import ninja.bytecode.shuriken.logging.L; - -public class CommandReloadPack extends MortarCommand -{ - public CommandReloadPack() - { - super("pack", "p"); - setDescription("Reloads the pack + regen"); - } - - @Override - public boolean handle(MortarSender sender, String[] args) - { - sender.sendMessage("=== Hotloading Pack ==="); - PackController c = Iris.pack(); - KMap f = new KMap<>(); - - for(World i : Bukkit.getWorlds()) - { - if(i.getGenerator() instanceof IrisGenerator) - { - String n = ((IrisGenerator) i.getGenerator()).getDimension().getName(); - sender.sendMessage("Preparing " + n); - f.put(i.getName(), n); - } - } - - if(f.isEmpty()) - { - sender.sendMessage("No Worlds to inject!"); - return true; - } - - J.a(() -> - { - try - { - Consumer m = (msg) -> - { - J.s(() -> - { - String mm = msg; - - if(msg.contains("|")) - { - KList fx = new KList<>(); - fx.add(msg.split("\\Q|\\E")); - fx.remove(0); - fx.remove(0); - mm = fx.toString(""); - } - - sender.sendMessage(mm.replaceAll("\\Q \\E", "")); - }); - }; - - L.addLogConsumer(m); - c.compile(); - L.logConsumers.remove(m); - - J.s(() -> - { - if(sender.isPlayer()) - { - ChronoLatch cl = new ChronoLatch(3000); - Player p = sender.player(); - World ww = sender.player().getWorld(); - - sender.sendMessage("Regenerating View Distance"); - - WorldReactor r = new WorldReactor(ww); - r.generateRegionNormal(p, true, 200, (pct) -> - { - if(cl.flip()) - { - sender.sendMessage("Regenerating " + Form.pc(pct)); - } - }, () -> - { - sender.sendMessage("Done! Use F3 + A"); - }); - } - }, 5); - - for(String fi : f.k()) - { - J.s(() -> - { - World i = Bukkit.getWorld(fi); - CompiledDimension dim = c.getDimension(f.get(fi)); - - for(String k : c.getDimensions().k()) - { - if(c.getDimension(k).getName().equals(f.get(fi))) - { - dim = c.getDimension(k); - break; - } - } - - if(dim == null) - { - J.s(() -> sender.sendMessage("Cannot find dimnension: " + f.get(fi))); - return; - } - sender.sendMessage("Hotloaded " + i.getName()); - IrisGenerator g = ((IrisGenerator) i.getGenerator()); - g.inject(dim); - }); - } - } - - catch(Throwable e) - { - e.printStackTrace(); - } - }); - - return true; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandSelection.java b/src/main/java/ninja/bytecode/iris/command/CommandSelection.java deleted file mode 100644 index 041da0bd2..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandSelection.java +++ /dev/null @@ -1,42 +0,0 @@ -package ninja.bytecode.iris.command; - -import mortar.bukkit.command.Command; -import mortar.bukkit.command.MortarCommand; -import mortar.bukkit.command.MortarSender; -import mortar.util.text.C; - -public class CommandSelection extends MortarCommand -{ - @Command - private CommandSelectionExpand expand; - - @Command - private CommandSelectionShift shift; - - @Command - private CommandSelectionShrink shr; - - @Command - private CommandSelectionXUp xip; - - @Command - private CommandSelectionXVert xvc; - - public CommandSelection() - { - super("selection", "sel", "s"); - setDescription("Wand Selection Subcommands"); - } - - @Override - public boolean handle(MortarSender sender, String[] args) - { - for(MortarCommand i : getChildren()) - { - sender.sendMessage("/iris sel " + C.WHITE + i.getNode() + C.GRAY + (!i.getNodes().isEmpty() ? "," : "") + i.getNodes().toString(",") + " - " + C.DARK_GREEN + i.getDescription()); - } - - return true; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandSelectionExpand.java b/src/main/java/ninja/bytecode/iris/command/CommandSelectionExpand.java deleted file mode 100644 index d5345dc22..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandSelectionExpand.java +++ /dev/null @@ -1,60 +0,0 @@ -package ninja.bytecode.iris.command; - -import org.bukkit.Location; -import org.bukkit.Sound; -import org.bukkit.entity.Player; - -import mortar.bukkit.command.MortarCommand; -import mortar.bukkit.command.MortarSender; -import ninja.bytecode.iris.controller.WandController; -import ninja.bytecode.iris.util.Cuboid; -import ninja.bytecode.iris.util.Direction; - -public class CommandSelectionExpand extends MortarCommand -{ - public CommandSelectionExpand() - { - super("expand", "+"); - setDescription("Expand in looking direction"); - } - - @Override - public boolean handle(MortarSender sender, String[] args) - { - if(!sender.isPlayer()) - { - sender.sendMessage("Players Only"); - return true; - } - - Player p = sender.player(); - - if(!WandController.isWand(p)) - { - sender.sendMessage("Ready your Wand."); - return true; - } - - if(args.length == 0) - { - sender.sendMessage("/iris selection expand "); - return true; - } - - int amt = Integer.valueOf(args[0]); - Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); - Location a1 = b[0].clone(); - Location a2 = b[1].clone(); - Cuboid cursor = new Cuboid(a1, a2); - Direction d = Direction.closest(p.getLocation().getDirection()).reverse(); - cursor = cursor.expand(d, amt); - b[0] = cursor.getLowerNE(); - b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); - p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f); - - return true; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandSelectionShift.java b/src/main/java/ninja/bytecode/iris/command/CommandSelectionShift.java deleted file mode 100644 index d0e60ba4b..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandSelectionShift.java +++ /dev/null @@ -1,61 +0,0 @@ -package ninja.bytecode.iris.command; - -import org.bukkit.Location; -import org.bukkit.Sound; -import org.bukkit.entity.Player; - -import mortar.bukkit.command.MortarCommand; -import mortar.bukkit.command.MortarSender; -import ninja.bytecode.iris.controller.WandController; -import ninja.bytecode.iris.util.Cuboid; -import ninja.bytecode.iris.util.Direction; - -public class CommandSelectionShift extends MortarCommand -{ - public CommandSelectionShift() - { - super("shift", ">"); - setDescription("Shift looking direction"); - } - - @Override - public boolean handle(MortarSender sender, String[] args) - { - if(!sender.isPlayer()) - { - sender.sendMessage("Players Only"); - return true; - } - - Player p = sender.player(); - - if(!WandController.isWand(p)) - { - sender.sendMessage("Ready your Wand."); - return true; - } - - if(args.length == 0) - { - sender.sendMessage("/iris selection shift "); - return true; - } - - int amt = Integer.valueOf(args[0]); - Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); - Location a1 = b[0].clone(); - Location a2 = b[1].clone(); - Direction d = Direction.closest(p.getLocation().getDirection()).reverse(); - a1.add(d.toVector().multiply(amt)); - a2.add(d.toVector().multiply(amt)); - Cuboid cursor = new Cuboid(a1, a2); - b[0] = cursor.getLowerNE(); - b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); - p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f); - - return true; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandSelectionShrink.java b/src/main/java/ninja/bytecode/iris/command/CommandSelectionShrink.java deleted file mode 100644 index 762939d4c..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandSelectionShrink.java +++ /dev/null @@ -1,57 +0,0 @@ -package ninja.bytecode.iris.command; - -import org.bukkit.Location; -import org.bukkit.Sound; -import org.bukkit.entity.Player; - -import mortar.bukkit.command.MortarCommand; -import mortar.bukkit.command.MortarSender; -import ninja.bytecode.iris.controller.WandController; -import ninja.bytecode.iris.util.Cuboid; -import ninja.bytecode.iris.util.Cuboid.CuboidDirection; - -public class CommandSelectionShrink extends MortarCommand -{ - public CommandSelectionShrink() - { - super("shrinkwrap", "shrink"); - setDescription("Match blocks boundary"); - } - - @Override - public boolean handle(MortarSender sender, String[] args) - { - if(!sender.isPlayer()) - { - sender.sendMessage("Players Only"); - return true; - } - - Player p = sender.player(); - - if(!WandController.isWand(p)) - { - sender.sendMessage("Ready your Wand."); - return true; - } - - Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); - Location a1 = b[0].clone(); - Location a2 = b[1].clone(); - Cuboid cursor = new Cuboid(a1, a2); - cursor = cursor.contract(CuboidDirection.North); - cursor = cursor.contract(CuboidDirection.South); - cursor = cursor.contract(CuboidDirection.East); - cursor = cursor.contract(CuboidDirection.West); - cursor = cursor.contract(CuboidDirection.Up); - cursor = cursor.contract(CuboidDirection.Down); - b[0] = cursor.getLowerNE(); - b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); - p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f); - - return true; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandSelectionXUp.java b/src/main/java/ninja/bytecode/iris/command/CommandSelectionXUp.java deleted file mode 100644 index 62d500a69..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandSelectionXUp.java +++ /dev/null @@ -1,72 +0,0 @@ -package ninja.bytecode.iris.command; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -import mortar.bukkit.command.MortarCommand; -import mortar.bukkit.command.MortarSender; -import ninja.bytecode.iris.controller.WandController; -import ninja.bytecode.iris.util.Cuboid; -import ninja.bytecode.iris.util.Cuboid.CuboidDirection; - -public class CommandSelectionXUp extends MortarCommand -{ - public CommandSelectionXUp() - { - super("expandup", "xup"); - setDescription("Expand Up & Trim In"); - } - - @Override - public boolean handle(MortarSender sender, String[] args) - { - if(!sender.isPlayer()) - { - sender.sendMessage("Players Only"); - return true; - } - - Player p = sender.player(); - - if(!WandController.isWand(p)) - { - sender.sendMessage("Ready your Wand."); - return true; - } - - Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); - b[0].add(new Vector(0, 1, 0)); - b[1].add(new Vector(0, 1, 0)); - Location a1 = b[0].clone(); - Location a2 = b[1].clone(); - Cuboid cursor = new Cuboid(a1, a2); - - while(!cursor.containsOnly(Material.AIR)) - { - a1.add(new Vector(0, 1, 0)); - a2.add(new Vector(0, 1, 0)); - cursor = new Cuboid(a1, a2); - } - - a1.add(new Vector(0, -1, 0)); - a2.add(new Vector(0, -1, 0)); - b[0] = a1; - a2 = b[1]; - cursor = new Cuboid(a1, a2); - cursor = cursor.contract(CuboidDirection.North); - cursor = cursor.contract(CuboidDirection.South); - cursor = cursor.contract(CuboidDirection.East); - cursor = cursor.contract(CuboidDirection.West); - b[0] = cursor.getLowerNE(); - b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); - p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f); - - return true; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandSelectionXVert.java b/src/main/java/ninja/bytecode/iris/command/CommandSelectionXVert.java deleted file mode 100644 index 9d97047b9..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandSelectionXVert.java +++ /dev/null @@ -1,83 +0,0 @@ -package ninja.bytecode.iris.command; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -import mortar.bukkit.command.MortarCommand; -import mortar.bukkit.command.MortarSender; -import ninja.bytecode.iris.controller.WandController; -import ninja.bytecode.iris.util.Cuboid; -import ninja.bytecode.iris.util.Cuboid.CuboidDirection; - -public class CommandSelectionXVert extends MortarCommand -{ - public CommandSelectionXVert() - { - super("expandvertical", "xvert"); - setDescription("Expand Up + Down & Trim In"); - } - - @Override - public boolean handle(MortarSender sender, String[] args) - { - if(!sender.isPlayer()) - { - sender.sendMessage("Players Only"); - return true; - } - - Player p = sender.player(); - - if(!WandController.isWand(p)) - { - sender.sendMessage("Ready your Wand."); - return true; - } - - Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); - Location a1 = b[0].clone(); - Location a2 = b[1].clone(); - Location a1x = b[0].clone(); - Location a2x = b[1].clone(); - Cuboid cursor = new Cuboid(a1, a2); - Cuboid cursorx = new Cuboid(a1, a2); - - while(!cursor.containsOnly(Material.AIR)) - { - a1.add(new Vector(0, 1, 0)); - a2.add(new Vector(0, 1, 0)); - cursor = new Cuboid(a1, a2); - } - - a1.add(new Vector(0, -1, 0)); - a2.add(new Vector(0, -1, 0)); - - while(!cursorx.containsOnly(Material.AIR)) - { - a1x.add(new Vector(0, -1, 0)); - a2x.add(new Vector(0, -1, 0)); - cursorx = new Cuboid(a1x, a2x); - } - - a1x.add(new Vector(0, 1, 0)); - a2x.add(new Vector(0, 1, 0)); - b[0] = a1; - b[1] = a2x; - cursor = new Cuboid(b[0], b[1]); - cursor = cursor.contract(CuboidDirection.North); - cursor = cursor.contract(CuboidDirection.South); - cursor = cursor.contract(CuboidDirection.East); - cursor = cursor.contract(CuboidDirection.West); - b[0] = cursor.getLowerNE(); - b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); - p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEMFRAME_ROTATE_ITEM, 1f, 0.55f); - - return true; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandTimings.java b/src/main/java/ninja/bytecode/iris/command/CommandTimings.java deleted file mode 100644 index 901cdded0..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandTimings.java +++ /dev/null @@ -1,57 +0,0 @@ -package ninja.bytecode.iris.command; - -import org.bukkit.Bukkit; -import org.bukkit.World; - -import mortar.bukkit.command.MortarCommand; -import mortar.bukkit.command.MortarSender; -import mortar.util.text.C; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.generator.IrisGenerator; - -public class CommandTimings extends MortarCommand -{ - public CommandTimings() - { - super("timings", "t"); - setDescription("Tick use on a per chunk basis"); - } - - @Override - public boolean handle(MortarSender sender, String[] args) - { - World world = null; - - if(sender.isPlayer() && Iris.isGen(sender.player().getWorld())) - { - world = sender.player().getWorld(); - } - - else if(args.length >= 1) - { - World t = Bukkit.getWorld(args[0]); - - if(t == null) - { - sender.sendMessage("Unknown world " + args[0]); - return true; - } - - else if(t.getGenerator() instanceof IrisGenerator) - { - world = t; - } - } - - else - { - sender.sendMessage("Console / Non-Iris World. " + C.WHITE + "Use /iris timings "); - return true; - } - - Iris.getGen(world).getMetrics().send(sender, (m) -> sender.sendMessage(m)); - - return true; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandWhat.java b/src/main/java/ninja/bytecode/iris/command/CommandWhat.java deleted file mode 100644 index a6ff4f350..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandWhat.java +++ /dev/null @@ -1,36 +0,0 @@ -package ninja.bytecode.iris.command; - -import mortar.bukkit.command.Command; -import mortar.bukkit.command.MortarCommand; -import mortar.bukkit.command.MortarSender; -import mortar.util.text.C; - -public class CommandWhat extends MortarCommand -{ - @Command - private CommandWhatBiome wBiome; - - @Command - private CommandWhatObject wObject; - - @Command - private CommandWhatBlock wBlock; - - public CommandWhat() - { - super("what", "w"); - setDescription("Identify what you are looking at."); - } - - @Override - public boolean handle(MortarSender sender, String[] args) - { - for(MortarCommand i : getChildren()) - { - sender.sendMessage("/iris what " + C.WHITE + i.getNode() + C.GRAY + (!i.getNodes().isEmpty() ? "," : "") + i.getNodes().toString(",") + " - " + C.DARK_GREEN + i.getDescription()); - } - - return true; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandWhatBiome.java b/src/main/java/ninja/bytecode/iris/command/CommandWhatBiome.java deleted file mode 100644 index c40c71e19..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandWhatBiome.java +++ /dev/null @@ -1,66 +0,0 @@ -package ninja.bytecode.iris.command; - -import org.bukkit.World; -import org.bukkit.entity.Player; - -import mortar.bukkit.command.MortarCommand; -import mortar.bukkit.command.MortarSender; -import mortar.util.text.C; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.generator.IrisGenerator; -import ninja.bytecode.iris.pack.IrisBiome; -import ninja.bytecode.iris.util.BiomeLayer; -import ninja.bytecode.shuriken.format.Form; - -public class CommandWhatBiome extends MortarCommand -{ - public CommandWhatBiome() - { - super("biome", "b"); - setDescription("Identify Current Biome"); - } - - @Override - public boolean handle(MortarSender sender, String[] args) - { - World world = null; - - if(sender.isPlayer() && Iris.isGen(sender.player().getWorld())) - { - world = sender.player().getWorld(); - } - - else - { - sender.sendMessage("Console / Non-Iris World."); - return true; - } - - Player p = sender.player(); - IrisGenerator g = Iris.getGen(world); - IrisBiome biome = g.getBiome((int) g.getOffsetX(p.getLocation().getX(), p.getLocation().getZ()), (int) g.getOffsetZ(p.getLocation().getX(), p.getLocation().getZ())); - BiomeLayer l = new BiomeLayer(g, biome); - sender.sendMessage("Biome: " + C.BOLD + C.WHITE + biome.getName() + C.RESET + C.GRAY + " (" + C.GOLD + l.getBiome().getRarityString() + C.GRAY + ")"); - - for(String i : biome.getSchematicGroups().k()) - { - String f = ""; - double percent = biome.getSchematicGroups().get(i); - - if(percent > 1D) - { - f = (int) percent + " + " + Form.pc(percent - (int) percent, percent - (int) percent >= 0.01 ? 0 : 3); - } - - else - { - f = Form.pc(percent, percent >= 0.01 ? 0 : 3); - } - - sender.sendMessage("* " + C.DARK_GREEN + i + ": " + C.BOLD + C.WHITE + f + C.RESET + C.GRAY + " (" + Form.f(g.getDimension().getObjectGroup(i).size()) + " variants)"); - } - - return true; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandWhatBlock.java b/src/main/java/ninja/bytecode/iris/command/CommandWhatBlock.java deleted file mode 100644 index 28bba5856..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandWhatBlock.java +++ /dev/null @@ -1,33 +0,0 @@ -package ninja.bytecode.iris.command; - -import org.bukkit.block.Block; -import org.bukkit.entity.Player; - -import mortar.bukkit.command.MortarCommand; -import mortar.bukkit.command.MortarSender; - -public class CommandWhatBlock extends MortarCommand -{ - public CommandWhatBlock() - { - super("block", "id", "i"); - setDescription("Identify Current Block Looking at"); - } - - @SuppressWarnings("deprecation") - @Override - public boolean handle(MortarSender sender, String[] args) - { - if(!sender.isPlayer()) - { - sender.sendMessage("Not sure where you are looking."); - } - - Player p = sender.player(); - Block b = p.getTargetBlock(null, 64); - sender.sendMessage(b.getType().getId() + ":" + b.getData() + " (" + b.getType().toString() + ":" + b.getData() + ")"); - - return true; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/command/CommandWhatObject.java b/src/main/java/ninja/bytecode/iris/command/CommandWhatObject.java deleted file mode 100644 index d847c6658..000000000 --- a/src/main/java/ninja/bytecode/iris/command/CommandWhatObject.java +++ /dev/null @@ -1,165 +0,0 @@ -package ninja.bytecode.iris.command; - -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.Player; - -import mortar.api.sched.SR; -import mortar.bukkit.command.MortarCommand; -import mortar.bukkit.command.MortarSender; -import mortar.lang.collection.FinalInteger; -import mortar.util.text.C; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.generator.IrisGenerator; -import ninja.bytecode.iris.generator.genobject.GenObject; -import ninja.bytecode.iris.generator.genobject.GenObjectGroup; -import ninja.bytecode.iris.generator.genobject.PlacedObject; -import ninja.bytecode.iris.pack.IrisBiome; -import ninja.bytecode.shuriken.collections.KMap; -import ninja.bytecode.shuriken.format.Form; - -public class CommandWhatObject extends MortarCommand -{ - private KMap goc; - private KMap gog; - - public CommandWhatObject() - { - super("object", "o"); - setDescription("WAYLA For Objects"); - goc = new KMap<>(); - gog = new KMap<>(); - } - - @Override - public boolean handle(MortarSender sender, String[] args) - { - World world = null; - - if(sender.isPlayer() && Iris.isGen(sender.player().getWorld())) - { - world = sender.player().getWorld(); - } - - else - { - sender.sendMessage("Console / Non-Iris World."); - return true; - } - - Player p = sender.player(); - IrisGenerator generator = Iris.getGen(world); - Location l = p.getTargetBlock(null, 32).getLocation(); - PlacedObject po = generator.nearest(l, 12); - - if(po != null) - { - if(!goc.containsKey(po.getF())) - { - String root = po.getF().split("\\Q:\\E")[0]; - String n = po.getF().split("\\Q:\\E")[1]; - GenObjectGroup gg = generator.getDimension().getObjectGroup(root); - gog.put(root, gg); - - for(GenObject i : gg.getSchematics()) - { - if(i.getName().equals(n)) - { - goc.put(po.getF(), i); - break; - } - } - - if(!goc.containsKey(po.getF())) - { - goc.put(po.getF(), new GenObject(0, 0, 0)); - } - } - - GenObjectGroup ggg = gog.get(po.getF().split("\\Q:\\E")[0]); - GenObject g = goc.get(po.getF()); - - if(g != null) - { - Location point = new Location(l.getWorld(), po.getX(), po.getY(), po.getZ()); - IrisBiome biome = generator.getBiome((int) generator.getOffsetX(po.getX(), po.getZ()), (int) generator.getOffsetZ(po.getX(), po.getZ())); - String gg = po.getF().split("\\Q:\\E")[0]; - - p.sendMessage(C.DARK_GREEN + C.BOLD.toString() + gg + C.GRAY + "/" + C.RESET + C.ITALIC + C.GRAY + g.getName() + C.RESET + C.WHITE + " (1 of " + Form.f(generator.getDimension().getObjectGroup(gg).size()) + " variants)"); - - if(biome.getSchematicGroups().containsKey(gg)) - { - String f = ""; - double percent = biome.getSchematicGroups().get(gg); - - if(percent > 1D) - { - f = (int) percent + " + " + Form.pc(percent - (int) percent, percent - (int) percent >= 0.01 ? 0 : 3); - } - - else - { - f = Form.pc(percent, percent >= 0.01 ? 0 : 3); - } - - p.sendMessage(C.GOLD + "Spawn Chance in " + C.YELLOW + biome.getName() + C.RESET + ": " + C.BOLD + C.WHITE + f); - } - - try - { - int a = 0; - int b = 0; - double c = 0; - - for(GenObject i : ggg.getSchematics()) - { - a += i.getSuccesses(); - b += i.getPlaces(); - } - - c = ((double) a / (double) b); - p.sendMessage(C.GRAY + "Grp: " + C.DARK_AQUA + Form.f(a) + C.GRAY + " of " + C.AQUA + Form.f(b) + C.GRAY + " placements (" + C.DARK_AQUA + Form.pc(c, 0) + C.GRAY + ")"); - } - - catch(Throwable e) - { - e.printStackTrace(); - } - - p.sendMessage(C.GRAY + "Var: " + C.DARK_AQUA + Form.f(g.getSuccesses()) + C.GRAY + " of " + C.AQUA + Form.f(g.getPlaces()) + C.GRAY + " placements (" + C.DARK_AQUA + Form.pc(g.getSuccess(), 0) + C.GRAY + ")"); - - for(String i : ggg.getFlags()) - { - p.sendMessage(C.GRAY + "- " + C.DARK_PURPLE + i); - } - - FinalInteger fi = new FinalInteger(125); - - new SR() - { - @Override - public void run() - { - if(point.distanceSquared(p.getLocation()) > 64 * 64) - { - cancel(); - } - - fi.sub(1); - Iris.wand().draw(new Location[] {point.clone().add(g.getW() / 2, g.getH() / 2, g.getD() / 2), point.clone().subtract(g.getW() / 2, g.getH() / 2, g.getD() / 2) - }, p); - - if(fi.get() <= 0) - { - cancel(); - } - } - }; - - } - } - - return true; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/controller/ExecutionController.java b/src/main/java/ninja/bytecode/iris/controller/ExecutionController.java deleted file mode 100644 index da8e95f33..000000000 --- a/src/main/java/ninja/bytecode/iris/controller/ExecutionController.java +++ /dev/null @@ -1,64 +0,0 @@ -package ninja.bytecode.iris.controller; - -import org.bukkit.World; - -import ninja.bytecode.iris.Iris; -import ninja.bytecode.shuriken.collections.KMap; -import ninja.bytecode.shuriken.execution.TaskExecutor; - -public class ExecutionController -{ - KMap executors; - - public void start() - { - executors = new KMap<>(); - } - - public void stop() - { - for(TaskExecutor i : executors.v()) - { - i.close(); - } - - executors.clear(); - } - - public TaskExecutor getExecutor(World world, String f) - { - String k = world.getWorldFolder().getAbsolutePath() + " (" + world + ") " + f; - - if(executors.containsKey(k)) - { - return executors.get(k); - } - - TaskExecutor x = new TaskExecutor(getTC(), Iris.settings.performance.threadPriority, "Iris " + f); - executors.put(k, x); - return x; - } - - public int getTC() - { - switch(Iris.settings.performance.performanceMode) - { - case HALF_CPU: - return Math.max(Runtime.getRuntime().availableProcessors() / 2, 1); - case MATCH_CPU: - return Runtime.getRuntime().availableProcessors(); - case SINGLE_THREADED: - return 1; - case DOUBLE_CPU: - return Runtime.getRuntime().availableProcessors() * 2; - case UNLIMITED: - return -1; - case EXPLICIT: - return Iris.settings.performance.threadCount; - default: - break; - } - - return Math.max(Runtime.getRuntime().availableProcessors() / 2, 1); - } -} diff --git a/src/main/java/ninja/bytecode/iris/controller/PackController.java b/src/main/java/ninja/bytecode/iris/controller/PackController.java deleted file mode 100644 index 68401f1bb..000000000 --- a/src/main/java/ninja/bytecode/iris/controller/PackController.java +++ /dev/null @@ -1,358 +0,0 @@ -package ninja.bytecode.iris.controller; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; - -import mortar.bukkit.plugin.Controller; -import net.md_5.bungee.api.ChatColor; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.generator.genobject.GenObject; -import ninja.bytecode.iris.generator.genobject.GenObjectGroup; -import ninja.bytecode.iris.pack.CompiledDimension; -import ninja.bytecode.iris.pack.IrisBiome; -import ninja.bytecode.iris.pack.IrisDimension; -import ninja.bytecode.iris.pack.IrisPack; -import ninja.bytecode.shuriken.bench.PrecisionStopwatch; -import ninja.bytecode.shuriken.collections.KList; -import ninja.bytecode.shuriken.collections.KMap; -import ninja.bytecode.shuriken.execution.J; -import ninja.bytecode.shuriken.format.Form; -import ninja.bytecode.shuriken.io.IO; -import ninja.bytecode.shuriken.json.JSONException; -import ninja.bytecode.shuriken.json.JSONObject; -import ninja.bytecode.shuriken.logging.L; - -public class PackController extends Controller -{ - private KMap compiledDimensions; - private KMap dimensions; - private KMap biomes; - private KMap genObjectGroups; - private boolean ready; - - @Override - public void start() - { - compiledDimensions = new KMap<>(); - dimensions = new KMap<>(); - biomes = new KMap<>(); - genObjectGroups = new KMap<>(); - ready = false; - } - - @Override - public void stop() - { - - } - - @Override - public void tick() - { - - } - - public boolean isReady() - { - return ready; - } - - public KList getFiles(File folder) - { - KList buf = new KList(); - - if(!folder.exists()) - { - return buf; - } - - if(folder.isDirectory()) - { - for(File i : folder.listFiles()) - { - if(i.isFile()) - { - buf.add(i); - } - - else if(i.isDirectory()) - { - buf.addAll(getFiles(folder)); - } - } - } - - return buf; - } - - public void compile() - { - dimensions = new KMap<>(); - biomes = new KMap<>(); - genObjectGroups = new KMap<>(); - ready = false; - PrecisionStopwatch p = PrecisionStopwatch.start(); - File dims = new File(Iris.instance.getDataFolder(), "dimensions"); - dims.mkdirs(); - - try - { - IrisPack master = new IrisPack(loadJSON("pack/manifest.json")); - master.load(); - } - - catch(Throwable e) - { - e.printStackTrace(); - } - - L.v(ChatColor.LIGHT_PURPLE + "Processing Content"); - - for(GenObjectGroup i : genObjectGroups.v()) - { - i.processVariants(); - } - - for(String i : dimensions.k()) - { - IrisDimension id = dimensions.get(i); - CompiledDimension d = new CompiledDimension(id); - - for(IrisBiome j : id.getBiomes()) - { - d.registerBiome(j); - KList g = j.getSchematicGroups().k(); - g.sort(); - - for(String k : g) - { - d.registerObject(genObjectGroups.get(k)); - - if(j.isLush()) - { - try - { - GenObjectGroup ggx = genObjectGroups.get(k).copy("-lush-" + j.getLush()); - ggx.applyLushFilter(j.getLush()); - d.registerObject(ggx); - j.getSchematicGroups().put(ggx.getName(), j.getSchematicGroups().get(k)); - j.getSchematicGroups().remove(k); - } - - catch(Throwable e) - { - e.printStackTrace(); - } - } - - if(j.isSnowy()) - { - try - { - GenObjectGroup ggx = genObjectGroups.get(k).copy("-snow-" + j.getSnow()); - ggx.applySnowFilter((int) (j.getSnow() * 4)); - d.registerObject(ggx); - j.getSchematicGroups().put(ggx.getName(), j.getSchematicGroups().get(k)); - j.getSchematicGroups().remove(k); - } - - catch(Throwable e) - { - e.printStackTrace(); - } - } - } - } - - d.sort(); - compiledDimensions.put(i, d); - } - - for(String i : compiledDimensions.k()) - { - CompiledDimension d = compiledDimensions.get(i); - d.computeObjectSize(); - L.i(ChatColor.GREEN + i + ChatColor.WHITE + " (" + d.getEnvironment().toString().toLowerCase() + ")"); - L.i(ChatColor.DARK_GREEN + " Biomes: " + ChatColor.GRAY + Form.f(d.getBiomes().size())); - L.i(ChatColor.DARK_GREEN + " Objects: " + ChatColor.GRAY + Form.f(d.countObjects())); - L.flush(); - } - - L.i(""); - L.i(ChatColor.LIGHT_PURPLE + "Compilation Time: " + ChatColor.WHITE + Form.duration(p.getMilliseconds(), 2)); - L.i(ChatColor.GREEN + "Iris Dimensions Successfully Compiled!"); - L.i(""); - L.flush(); - - ready = true; - } - - public KMap getCompiledDimensions() - { - return compiledDimensions; - } - - public KMap getDimensions() - { - return dimensions; - } - - public KMap getBiomes() - { - return biomes; - } - - public KMap getGenObjectGroups() - { - return genObjectGroups; - } - - public CompiledDimension getDimension(String name) - { - return compiledDimensions.get(name); - } - - public IrisDimension loadDimension(String s) throws JSONException, IOException - { - L.v(ChatColor.GOLD + "Loading Dimension: " + ChatColor.GRAY + "pack/dimensions/" + s + ".json"); - return new IrisDimension(loadJSON("pack/dimensions/" + s + ".json")); - } - - public IrisBiome loadBiome(String s) throws JSONException, IOException - { - L.v(ChatColor.DARK_GREEN + "Loading Biome: " + ChatColor.GRAY + "pack/biomes/" + s + ".json"); - return new IrisBiome(loadJSON("pack/biomes/" + s + ".json")); - } - - public GenObjectGroup loadSchematicGroup(String s) - { - GenObjectGroup g = GenObjectGroup.load("pack/objects/" + s); - L.v(ChatColor.DARK_AQUA + "Loading Objects: " + ChatColor.GRAY + "pack/objects/" + s + ".ish"); - - if(g != null) - { - genObjectGroups.put(s, g); - return g; - } - - L.i("Cannot load Object Group: " + s); - - return null; - } - - public GenObject loadSchematic(String s) throws IOException - { - return GenObject.load(loadResource("pack/objects/" + s + ".ish")); - } - - public JSONObject loadJSON(String s) throws JSONException, IOException - { - return new JSONObject(IO.readAll(loadResource(s))); - } - - public File loadFolder(String string) - { - File internal = internalResource(string); - - if(internal.exists()) - { - return internal; - } - - L.f(ChatColor.RED + "Cannot find folder: " + internal.getAbsolutePath()); - return null; - } - - public InputStream loadResource(String string) throws IOException - { - File internal = internalResource(string); - - if(internal.exists()) - { - L.flush(); - return new FileInputStream(internal); - } - - else - { - L.f(ChatColor.RED + "Cannot find Resource: " + ChatColor.YELLOW + internal.getAbsolutePath()); - - if(internal.getName().equals("manifest.json")) - { - L.f(ChatColor.RED + "Reloading Iris to fix manifest jar issues"); - Iris.instance.reload(); - } - - return null; - } - } - - private static File internalResource(String resource) - { - if(new File(Iris.instance.getDataFolder(), "pack").exists()) - { - return new File(Iris.instance.getDataFolder(), resource); - } - - return new File(System.getProperty("java.io.tmpdir") + "/Iris/" + resource); - } - - public void registerBiome(String name, IrisBiome biome) - { - biomes.put(name, biome); - } - - public void registerDimension(String i, IrisDimension d) - { - dimensions.put(i, d); - } - - public void invalidate() - { - J.attempt(() -> new File(Iris.instance.getDataFolder(), "dimensions").delete()); - compiledDimensions.clear(); - } - - public IrisBiome getBiomeById(String id) - { - if(!biomes.containsKey(id)) - { - try - { - biomes.put(id, ((PackController) Iris.instance.getController(PackController.class)).loadBiome(id)); - } - - catch(JSONException | IOException e) - { - e.printStackTrace(); - } - } - - return biomes.get(id); - } - - public void dispose() - { - for(GenObjectGroup i : genObjectGroups.values()) - { - i.dispose(); - } - - for(IrisDimension i : dimensions.values()) - { - i.dispose(); - } - - for(CompiledDimension i : compiledDimensions.values()) - { - i.dispose(); - } - - compiledDimensions.clear(); - dimensions.clear(); - biomes.clear(); - genObjectGroups.clear(); - } -} diff --git a/src/main/java/ninja/bytecode/iris/controller/WandController.java b/src/main/java/ninja/bytecode/iris/controller/WandController.java deleted file mode 100644 index 7bad52843..000000000 --- a/src/main/java/ninja/bytecode/iris/controller/WandController.java +++ /dev/null @@ -1,323 +0,0 @@ -package ninja.bytecode.iris.controller; - -import java.awt.Color; -import java.util.Iterator; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.block.Block; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.block.Action; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.util.BlockVector; -import org.bukkit.util.Vector; - -import mortar.bukkit.plugin.Controller; -import mortar.compute.math.M; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.generator.genobject.GenObject; -import ninja.bytecode.iris.util.Cuboid; -import ninja.bytecode.iris.util.MB; -import ninja.bytecode.iris.util.ParticleEffect; -import ninja.bytecode.iris.util.ParticleRedstone; -import ninja.bytecode.shuriken.collections.KList; - -public class WandController extends Controller -{ - @Override - public void start() - { - // TODO: Optimize - Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, () -> - { - for(Player i : Bukkit.getOnlinePlayers()) - { - tick(i); - } - }, 0, 0); - } - - @Override - public void stop() - { - - } - - @Override - public void tick() - { - - } - - @EventHandler - public void tick(Player p) - { - try - { - if(isWand(p.getInventory().getItemInMainHand())) - { - Location[] d = getCuboid(p.getInventory().getItemInMainHand()); - draw(d, p); - } - } - - catch(Throwable e) - { - - } - } - - public void draw(Location[] d, Player p) - { - ParticleEffect.CRIT_MAGIC.display(0.1f, 1, d[0].clone().add(0.5, 0.5, 0.5).clone().add(Vector.getRandom().subtract(Vector.getRandom()).normalize().clone().multiply(0.65)), p); - ParticleEffect.CRIT.display(0.1f, 1, d[1].clone().add(0.5, 0.5, 0.5).clone().add(Vector.getRandom().subtract(Vector.getRandom()).normalize().clone().multiply(0.65)), p); - - if(!d[0].getWorld().equals(d[1].getWorld())) - { - return; - } - - if(d[0].distanceSquared(d[1]) > 64 * 64) - { - return; - } - - int minx = Math.min(d[0].getBlockX(), d[1].getBlockX()); - int miny = Math.min(d[0].getBlockY(), d[1].getBlockY()); - int minz = Math.min(d[0].getBlockZ(), d[1].getBlockZ()); - int maxx = Math.max(d[0].getBlockX(), d[1].getBlockX()); - int maxy = Math.max(d[0].getBlockY(), d[1].getBlockY()); - int maxz = Math.max(d[0].getBlockZ(), d[1].getBlockZ()); - - for(double j = minx - 1; j < maxx + 1; j += 0.25) - { - for(double k = miny - 1; k < maxy + 1; k += 0.25) - { - for(double l = minz - 1; l < maxz + 1; l += 0.25) - { - if(M.r(0.25)) - { - boolean jj = j == minx || j == maxx; - boolean kk = k == miny || k == maxy; - boolean ll = l == minz || l == maxz; - double aa = j; - double bb = k; - double cc = l; - - if((jj && kk) || (jj && ll) || (ll && kk)) - { - Vector push = new Vector(0, 0, 0); - - if(j == minx) - { - push.add(new Vector(-0.55, 0, 0)); - } - - if(k == miny) - { - push.add(new Vector(0, -0.55, 0)); - } - - if(l == minz) - { - push.add(new Vector(0, 0, -0.55)); - } - - if(j == maxx) - { - push.add(new Vector(0.55, 0, 0)); - } - - if(k == maxy) - { - push.add(new Vector(0, 0.55, 0)); - } - - if(l == maxz) - { - push.add(new Vector(0, 0, 0.55)); - } - - Location lv = new Location(d[0].getWorld(), aa, bb, cc).clone().add(0.5, 0.5, 0.5).clone().add(push); - int color = Color.getHSBColor((float) (0.5f + (Math.sin((aa + bb + cc + (p.getTicksLived() / 2)) / 20f) / 2)), 1, 1).getRGB(); - new ParticleRedstone().setColor(new Color(color)).play(lv, p); - } - } - } - } - } - } - - @EventHandler - public void on(PlayerInteractEvent e) - { - if(e.getHand().equals(EquipmentSlot.HAND) && isWand(e.getPlayer().getInventory().getItemInMainHand())) - { - if(e.getAction().equals(Action.LEFT_CLICK_BLOCK)) - { - e.setCancelled(true); - e.getPlayer().getInventory().setItemInMainHand(update(true, e.getClickedBlock().getLocation(), e.getPlayer().getInventory().getItemInMainHand())); - e.getPlayer().playSound(e.getClickedBlock().getLocation(), Sound.BLOCK_END_PORTAL_FRAME_FILL, 1f, 0.67f); - e.getPlayer().updateInventory(); - } - - else if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) - { - e.setCancelled(true); - e.getPlayer().getInventory().setItemInMainHand(update(false, e.getClickedBlock().getLocation(), e.getPlayer().getInventory().getItemInMainHand())); - e.getPlayer().playSound(e.getClickedBlock().getLocation(), Sound.BLOCK_END_PORTAL_FRAME_FILL, 1f, 1.17f); - e.getPlayer().updateInventory(); - } - } - } - - public static void pasteSchematic(GenObject s, Location at) - { - s.place(at); - } - - @SuppressWarnings("deprecation") - public static GenObject createSchematic(ItemStack wand, Location at) - { - if(!isWand(wand)) - { - return null; - } - - try - { - Location[] f = getCuboid(wand); - Cuboid c = new Cuboid(f[0], f[1]); - GenObject s = new GenObject(c.getSizeX(), c.getSizeY(), c.getSizeZ()); - Iterator bb = c.iterator(); - while(bb.hasNext()) - { - Block b = bb.next(); - - if(b.getType().equals(Material.AIR)) - { - continue; - } - - byte data = b.getData(); - - BlockVector bv = b.getLocation().subtract(c.getCenter()).toVector().toBlockVector(); - s.put(bv.getBlockX(), bv.getBlockY(), bv.getBlockZ(), - - new MB(b.getType(), data)); - } - - return s; - } - - catch(Throwable e) - { - e.printStackTrace(); - } - - return null; - } - - 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.valueOf(g[0]), Integer.valueOf(g[1]), Integer.valueOf(g[2])); - } - - catch(Throwable e) - { - return null; - } - } - - public static String locationToString(Location s) - { - if(s == null) - { - return "<#>"; - } - - return s.getBlockX() + "," + s.getBlockY() + "," + s.getBlockZ() + " in " + s.getWorld().getName(); - } - - public static ItemStack createWand() - { - return createWand(null, null); - } - - public static ItemStack update(boolean left, Location a, ItemStack item) - { - if(!isWand(item)) - { - return item; - } - - Location[] f = getCuboid(item); - Location other = left ? f[1] : f[0]; - - if(other != null && !other.getWorld().getName().equals(a.getWorld().getName())) - { - other = null; - } - - return createWand(left ? a : other, left ? other : a); - } - - 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(ChatColor.BOLD + "" + ChatColor.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; - } - - public static boolean isWand(Player p) - { - ItemStack is = p.getInventory().getItemInMainHand(); - return !(is == null || !isWand(is)); - } - - public static Location[] getCuboid(ItemStack is) - { - ItemMeta im = is.getItemMeta(); - return new Location[] {stringToLocation(im.getLore().get(0)), stringToLocation(im.getLore().get(1))}; - } - - public static boolean isWand(ItemStack item) - { - if(!item.getType().equals(createWand().getType())) - { - return false; - } - - if(!item.getItemMeta().getEnchants().equals(createWand().getItemMeta().getEnchants())) - { - return false; - } - - if(!item.getItemMeta().getDisplayName().equals(createWand().getItemMeta().getDisplayName())) - { - return false; - } - - return true; - } -} diff --git a/src/main/java/ninja/bytecode/iris/generator/IrisGenerator.java b/src/main/java/ninja/bytecode/iris/generator/IrisGenerator.java deleted file mode 100644 index 299f89101..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/IrisGenerator.java +++ /dev/null @@ -1,728 +0,0 @@ -package ninja.bytecode.iris.generator; - -import java.util.List; -import java.util.Random; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.TreeSpecies; -import org.bukkit.World; -import org.bukkit.block.Biome; -import org.bukkit.generator.BlockPopulator; -import org.bukkit.material.Leaves; -import org.bukkit.util.NumberConversions; - -import mortar.util.text.C; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.generator.atomics.AtomicChunkData; -import ninja.bytecode.iris.generator.genobject.GenObjectDecorator; -import ninja.bytecode.iris.generator.genobject.PlacedObject; -import ninja.bytecode.iris.generator.layer.GenLayerBiome; -import ninja.bytecode.iris.generator.layer.GenLayerCarving; -import ninja.bytecode.iris.generator.layer.GenLayerCaves; -import ninja.bytecode.iris.generator.layer.GenLayerCliffs; -import ninja.bytecode.iris.generator.layer.GenLayerLayeredNoise; -import ninja.bytecode.iris.generator.layer.GenLayerOres; -import ninja.bytecode.iris.generator.layer.GenLayerSnow; -import ninja.bytecode.iris.generator.parallax.ParallaxWorldGenerator; -import ninja.bytecode.iris.pack.BiomeType; -import ninja.bytecode.iris.pack.CompiledDimension; -import ninja.bytecode.iris.pack.IrisBiome; -import ninja.bytecode.iris.pack.IrisRegion; -import ninja.bytecode.iris.util.ChunkPlan; -import ninja.bytecode.iris.util.InterpolationMode; -import ninja.bytecode.iris.util.IrisInterpolation; -import ninja.bytecode.iris.util.IrisMetrics; -import ninja.bytecode.iris.util.MB; -import ninja.bytecode.iris.util.NoiseProvider; -import ninja.bytecode.iris.util.ObjectMode; -import ninja.bytecode.iris.util.SChunkVector; -import ninja.bytecode.shuriken.bench.PrecisionStopwatch; -import ninja.bytecode.shuriken.collections.KList; -import ninja.bytecode.shuriken.logging.L; -import ninja.bytecode.shuriken.math.CNG; -import ninja.bytecode.shuriken.math.M; -import ninja.bytecode.shuriken.math.RNG; - -public class IrisGenerator extends ParallaxWorldGenerator -{ - //@builder - public static final KList ROCK = new KList().add(new MB[] { - MB.of(Material.STONE), - MB.of(Material.STONE), - MB.of(Material.STONE), - MB.of(Material.STONE), - MB.of(Material.STONE), - MB.of(Material.STONE), - MB.of(Material.STONE), - MB.of(Material.STONE), - MB.of(Material.STONE), - MB.of(Material.STONE, 5), - MB.of(Material.STONE, 5), - MB.of(Material.STONE, 5), - MB.of(Material.STONE, 5), - MB.of(Material.STONE, 5), - MB.of(Material.STONE, 5) - }); - //@done - private boolean disposed; - private CNG scatter; - private CNG beach; - private CNG swirl; - private MB BEDROCK = new MB(Material.BEDROCK); - private GenObjectDecorator god; - private GenLayerLayeredNoise glLNoise; - private GenLayerBiome glBiome; - private GenLayerSnow glSnow; - private GenLayerCliffs glCliffs; - private GenLayerCaves glCaves; - private GenLayerCarving glCarving; - private GenLayerOres glOres; - private RNG rTerrain; - private CompiledDimension dim; - private IrisMetrics metrics = new IrisMetrics(0, 512); - private int objectHits; - - public IrisGenerator() - { - this(Iris.pack().getDimension("overworld")); - } - - public void hitObject() - { - objectHits++; - } - - public IrisGenerator(CompiledDimension dim) - { - objectHits = 0; - CNG.hits = 0; - CNG.creates = 0; - this.dim = dim; - disposed = false; - L.i("Preparing Dimension: " + dim.getName() + " With " + dim.getBiomes().size() + " Biomes..."); - } - - public int scatterInt(int x, int y, int z, int bound) - { - return (int) (scatter(x, y, z) * (double) (bound - 1)); - } - - public double scatter(int x, int y, int z) - { - return scatter.noise(x, y, z); - } - - public boolean scatterChance(int x, int y, int z, double chance) - { - return scatter(x, y, z) > chance; - } - - @Override - public void onInit(World world, Random random) - { - if(disposed) - { - return; - } - - random = new Random(world.getSeed()); - rTerrain = new RNG(world.getSeed()); - swirl = new CNG(rTerrain.nextParallelRNG(0), 40, 1).scale(0.007); - beach = new CNG(rTerrain.nextParallelRNG(0), 3, 1).scale(0.15); - glLNoise = new GenLayerLayeredNoise(this, world, random, rTerrain.nextParallelRNG(2)); - glBiome = new GenLayerBiome(this, world, random, rTerrain.nextParallelRNG(4), dim.getBiomes()); - glSnow = new GenLayerSnow(this, world, random, rTerrain.nextParallelRNG(5)); - glCliffs = new GenLayerCliffs(this, world, random, rTerrain.nextParallelRNG(9)); - glCaves = new GenLayerCaves(this, world, random, rTerrain.nextParallelRNG(10)); - glCarving = new GenLayerCarving(this, world, random, rTerrain.nextParallelRNG(11)); - glOres = new GenLayerOres(this, world, random, rTerrain.nextParallelRNG(12)); - scatter = new CNG(rTerrain.nextParallelRNG(52), 1, 1).scale(10); - - if(Iris.settings.performance.objectMode.equals(ObjectMode.PARALLAX)) - { - god = new GenObjectDecorator(this); - } - } - - @Override - public ChunkPlan onInitChunk(World world, int x, int z, Random random) - { - return new ChunkPlan(); - } - - public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) - { - random = new Random(world.getSeed()); - PrecisionStopwatch s = getMetrics().start(); - ChunkData d = super.generateChunkData(world, random, x, z, biome); - getMetrics().stop("chunk:ms", s); - getMetrics().put("noise-hits", CNG.hits); - metrics.setGenerators((int) CNG.creates); - CNG.hits = 0; - return d; - } - - public IrisBiome biome(String name) - { - return getDimension().getBiomeByName(name); - } - - public double getOffsetX(double x, double z) - { - return Math.round((double) x * (Iris.settings.gen.horizontalZoom / 1.90476190476)) + swirl.noise(x, z); - } - - public double getOffsetZ(double x, double z) - { - return Math.round((double) z * (Iris.settings.gen.horizontalZoom / 1.90476190476)) - swirl.noise(z, x); - } - - public IrisMetrics getMetrics() - { - return metrics; - } - - public IrisBiome getBeach(IrisBiome biome) - { - IrisBiome beach = null; - IrisRegion region = glBiome.getRegion(biome.getRegionID()); - - if(region != null) - { - beach = region.getBeach(); - } - - if(beach == null) - { - beach = biome("Beach"); - } - - return beach; - } - - public int computeHeight(int x, int z, ChunkPlan plan, IrisBiome biome) - { - return (int) Math.round(M.clip(getANoise((int) x, (int) z, plan, biome), 0D, 1D) * 253); - } - - public double getInterpolation(int x, int z, double opacity, ChunkPlan plan) - { - PrecisionStopwatch s = getMetrics().start(); - NoiseProvider n = (xf, zf) -> getBiomedHeight((int) Math.round(xf), (int) Math.round(zf), plan); - double d = 0; - double rad = Iris.settings.gen.interpolationRadius; - - InterpolationMode m = Iris.settings.gen.interpolationMode; - - if(m.equals(InterpolationMode.BILINEAR)) - { - d = IrisInterpolation.getBilinearNoise(x, z, rad, n); - } - - else if(m.equals(InterpolationMode.BICUBIC)) - { - d = IrisInterpolation.getBicubicNoise(x, z, rad, n); - } - - else if(m.equals(InterpolationMode.HERMITE_BICUBIC)) - { - d = IrisInterpolation.getHermiteNoise(x, z, rad, n); - } - - else - { - d = n.noise(x, z); - } - - getMetrics().stop("interpolation:ms:x256:/biome:.", s); - - return d; - } - - public double getANoise(int x, int z, ChunkPlan plan, IrisBiome biome) - { - double hv = getInterpolation((int) x, (int) z, 1D, plan); - hv += glLNoise.generateLayer(hv * Iris.settings.gen.roughness * 215, (double) x * Iris.settings.gen.roughness * 0.82, (double) z * Iris.settings.gen.roughness * 0.82) * (1.6918 * (hv * 2.35)); - - if(biome.hasCliffs()) - { - hv = glCliffs.generateLayer(hv, x, z, biome.getCliffScale(), biome.getCliffChance()); - } - - return hv; - } - - public IrisRegion getRegion(IrisBiome biome) - { - return glBiome.getRegion(biome.getRegionID()); - } - - @Override - public List getDefaultPopulators(World world) - { - KList p = new KList<>(); - - if(Iris.settings.performance.objectMode.equals(ObjectMode.QUICK_N_DIRTY) || Iris.settings.performance.objectMode.equals(ObjectMode.LIGHTING)) - { - p.add(god = new GenObjectDecorator(this)); - } - - return p; - } - - @Override - public void onGenParallax(int x, int z, Random random) - { - try - { - PrecisionStopwatch s = getMetrics().start(); - god.populateParallax(x, z, random); - String xx = "x" + getParallaxSize().getX() * getParallaxSize().getZ(); - getMetrics().stop("object:" + xx + ":.:ms:/parallax", s); - } - - catch(Throwable e) - { - e.printStackTrace(); - } - } - - private double getObjectHits() - { - int hits = objectHits; - objectHits = 0; - return hits; - } - - public IrisBiome getBiome(int x, int z) - { - IrisBiome biome = glBiome.getBiome(x, z); - int height = computeHeight((int) x, (int) z, new ChunkPlan(), biome); - biome = getBiome((int) x, height, (int) z); - - return biome; - } - - private IrisBiome getBiome(int x, int y, int z) - { - int seaLevel = Iris.settings.gen.seaLevel; - boolean land = y >= seaLevel; - int beachHeight = land ? 1 + (int) Math.round(seaLevel + beach.noise(x, z) + 1) : seaLevel; - boolean beach = y <= beachHeight && land; - IrisBiome biome = glBiome.getBiome(x, z); - IrisBiome realBiome = glBiome.getBiome(x, z, true); - boolean nearAquatic = glBiome.isNearAquatic(x, z); - IrisRegion region = getRegion(realBiome); - - // Remove Oceans from biomes above sea level - if(land && biome.getType().equals(BiomeType.FLUID)) - { - biome = realBiome; - } - - // Add Beaches & Shores - if(beach && biome.getType().equals(BiomeType.LAND)) - { - biome = nearAquatic ? region.getBeach() : region.getShore(); - } - - // // Replace biomes under sea level with lakes - if(!land && biome.getType().equals(BiomeType.LAND)) - { - biome = region.getLake(); - } - - return biome; - } - - @Override - public Biome onGenColumn(int wxxf, int wzxf, int x, int z, ChunkPlan plan, AtomicChunkData data, boolean surfaceOnly) - { - PrecisionStopwatch s = getMetrics().start(); - if(disposed) - { - data.setBlock(x, 0, z, Material.MAGENTA_GLAZED_TERRACOTTA); - return Biome.VOID; - } - - double wx = getOffsetX(wxxf, wzxf); - double wz = getOffsetZ(wxxf, wzxf); - int wxx = (int) wx; - int wzx = (int) wz; - int highest = 0; - int seaLevel = Iris.settings.gen.seaLevel; - IrisBiome biome = glBiome.getBiome(wxx, wzx); - int height = computeHeight(wxx, wzx, plan, biome); - int max = Math.max(height, seaLevel); - biome = getBiome(wxx, height, wzx); - MB FLUID = biome.getFluid(); - - for(int i = surfaceOnly ? max > seaLevel ? max - 2 : height - 2 : 0; i < max; i++) - { - MB mb = ROCK.get(scatterInt(wzx, i, wxx, ROCK.size())); - boolean carved = surfaceOnly ? false : glCarving.isCarved(wzx, wxx, x, z, i, data, plan); - boolean underwater = i >= height && i < seaLevel; - boolean underground = i < height; - int dheight = biome.getDirtDepth(); - int rheight = biome.getRockDepth(); - boolean dirt = (height - 1) - i < (dheight > 0 ? scatterInt(x, i, z, 4) : 0) + dheight; - boolean rocky = i > height - rheight && !dirt; - boolean bedrock = i == 0 || !Iris.settings.gen.flatBedrock ? i <= 2 : i < scatterInt(x, i, z, 3); - - if(!carved) - { - mb = underwater ? FLUID : mb; - mb = underground && dirt ? biome.getSubSurface(wxx, i, wzx, rTerrain) : mb; - mb = underground && rocky ? biome.getRock(wxx, i, wzx, rTerrain) : mb; - mb = bedrock ? BEDROCK : mb; - - if(i == height - 1) - { - mb = biome.getSurface(wx, wz, rTerrain); - } - - highest = i > highest ? i : highest; - } - - else - { - mb = MB.of(Material.AIR); - } - data.setBlock(x, i, z, mb.material, mb.data); - } - - getMetrics().stop("terrain:ms:x256:/chunk:..", s); - - int hw = 0; - int hl = 0; - - for(int i = highest; i > 0; i--) - { - Material t = data.getType(x, i, z); - hw = i > seaLevel && hw == 0 && (t.equals(Material.WATER) || t.equals(Material.STATIONARY_WATER)) ? i : hw; - hl = hl == 0 && !t.equals(Material.AIR) ? i : hl; - } - - plan.setRealHeight(x, z, hl); - plan.setRealWaterHeight(x, z, hw == 0 ? seaLevel : hw); - plan.setBiome(x, z, biome); - - if(!surfaceOnly) - { - glCaves.genCaves(wxxf, wzxf, x, z, data, plan); - glOres.genOres(wxxf, wzxf, x, z, hl, data, plan); - } - - for(int i = highest; i > 0; i--) - { - Material t = data.getType(x, i, z); - hw = i > seaLevel && hw == 0 && (t.equals(Material.WATER) || t.equals(Material.STATIONARY_WATER)) ? i : hw; - hl = hl == 0 && !t.equals(Material.AIR) ? i : hl; - } - - plan.setRealHeight(x, z, hl); - plan.setRealWaterHeight(x, z, hw == 0 ? seaLevel : hw); - plan.setBiome(x, z, biome); - double time = s.getMilliseconds() * 256D; - double atime = getMetrics().get("chunk:ms").getAverage(); - getMetrics().setParScale(time / atime); - getMetrics().put("objects:,:/parallax", getObjectHits()); - - return biome.getRealBiome(); - } - - @Override - protected void onDecorateChunk(World world, int cx, int cz, AtomicChunkData data, ChunkPlan plan) - { - PrecisionStopwatch p = PrecisionStopwatch.start(); - int x = 0; - int z = 0; - int hhx = 0; - int v = 0; - int borderh = 0; - int above = 0; - int below = 0; - - for(int f = 0; f < Iris.settings.gen.blockSmoothing; f++) - { - for(x = 0; x < 16; x++) - { - for(z = 0; z < 16; z++) - { - hhx = plan.getRealHeight(x, z); - borderh = 0; - - if(x == 0 || x == 15) - { - borderh++; - } - - if(z == 0 || z == 15) - { - borderh++; - } - - if(hhx > Iris.settings.gen.seaLevel - 2) - { - above = 0; - below = 0; - - if(x + 1 <= 15) - { - v = plan.getRealHeight(x + 1, z); - - if(v > hhx) - { - above++; - } - - else if(v < hhx) - { - below++; - } - } - - if(x - 1 >= 0) - { - v = plan.getRealHeight(x - 1, z); - - if(v > hhx) - { - above++; - } - - else if(v < hhx) - { - below++; - } - } - - if(z + 1 <= 15) - { - v = plan.getRealHeight(x, z + 1); - - if(v > hhx) - { - above++; - } - - else if(v < hhx) - { - below++; - } - } - - if(z - 1 >= 0) - { - v = plan.getRealHeight(x, z - 1); - - if(v > hhx) - { - above++; - } - - else if(v < hhx) - { - below++; - } - } - - // Patch Hole - if(above >= 4 - borderh) - { - data.setBlock(x, hhx + 1, z, data.getMB(x, hhx, z)); - plan.setRealHeight(x, z, hhx + 1); - } - - // Remove Nipple - else if(below >= 4 - borderh) - { - data.setBlock(x, hhx - 1, z, data.getMB(x, hhx, z)); - data.setBlock(x, hhx, z, Material.AIR); - plan.setRealHeight(x, z, hhx - 1); - } - } - } - } - } - - getMetrics().stop("decoration:ms:/chunk:..", p); - } - - @SuppressWarnings("deprecation") - @Override - protected void onDecorateColumn(World world, int x, int z, int wx, int wz, AtomicChunkData data, ChunkPlan plan) - { - PrecisionStopwatch p = PrecisionStopwatch.start(); - int h = plan.getRealHeight(x, z); - - if(h < 63) - { - return; - } - - IrisBiome biome = plan.getBiome(x, z); - - if(biome == null) - { - return; - } - - if(biome.getSnow() > 0) - { - double level = glSnow.getHeight(wx, wz) * biome.getSnow(); - int blocks = (int) level; - level -= blocks; - int layers = (int) (level * 7D); - int snowHeight = blocks + (layers > 0 ? 1 : 0); - - for(int j = 0; j < snowHeight; j++) - { - data.setBlock(x, h + j + 1, z, j == snowHeight - 1 ? Material.SNOW : Material.SNOW_BLOCK, j == snowHeight - 1 ? (byte) layers : (byte) 0); - } - } - - else - { - MB mbx = biome.getScatterChanceSingle(scatter(wx, h, wz), scatter(wz, h, wx)); - - if(!mbx.material.equals(Material.AIR)) - { - data.setBlock(x, h + 1, z, mbx.material, mbx.data); - - if(mbx.material.equals(Material.DOUBLE_PLANT)) - { - data.setBlock(x, h + 2, z, mbx.material, (byte) 10); - } - } - } - - if(biome.getLush() > 0.33) - { - double lx = (biome.getLush() > 1 ? 1 : biome.getLush()) - 0.33; - double g = glSnow.getHeight(wz, wx); - - if(lx / 1.18D > g) - { - double gx = glSnow.getHeight(wx * 2.25, wz * 2.25); - double gf = glSnow.getHeight(wx * 6.25, wz * 6.25); - - if(gf > gx) - { - Leaves l = new Leaves(TreeSpecies.values()[(int) (gx * (TreeSpecies.values().length - 1))]); - l.setDecaying(false); - l.setDecayable(false); - data.setBlock(x, h - 1, z, data.getMB(x, h, z)); - data.setBlock(x, h, z, l.getItemType(), l.getData()); - - if(gf - gx > 0.2) - { - l = new Leaves(TreeSpecies.values()[(int) (gf * (TreeSpecies.values().length - 1))]); - l.setDecaying(false); - l.setDecayable(false); - data.setBlock(x, h + 1, z, l.getItemType(), l.getData()); - } - } - } - } - - getMetrics().stop("pardecoration:ms:x256:/chunk:..", p); - } - - @Override - public void onPostChunk(World world, int cx, int cz, Random random, AtomicChunkData data, ChunkPlan plan) - { - - } - - private double getBiomedHeight(int x, int z, ChunkPlan plan) - { - double xh = plan.getHeight(x, z); - - if(xh == -1) - { - IrisBiome biome = glBiome.getBiome(x, z); - double h = Iris.settings.gen.baseHeight + biome.getHeight(); - h += biome.getGenerator().getHeight(x, z) / 2D; - plan.setHeight(x, z, h); - return h; - } - - return xh; - } - - public RNG getRTerrain() - { - return rTerrain; - } - - public CompiledDimension getDimension() - { - return dim; - } - - public void dispose() - { - if(disposed) - { - return; - } - L.w(C.YELLOW + "Disposed Iris World " + C.RED + getWorld().getName()); - disposed = true; - dim = null; - glLNoise = null; - glSnow = null; - glCliffs = null; - god.dispose(); - } - - public boolean isDisposed() - { - return disposed; - } - - public PlacedObject nearest(Location o, int i) - { - PlacedObject f = null; - double d = Integer.MAX_VALUE; - if(god != null) - { - for(PlacedObject j : god.getHistory()) - { - double dx = Math.abs(NumberConversions.square(j.getX() - o.getX()) + NumberConversions.square(j.getY() - o.getY()) + NumberConversions.square(j.getZ() - o.getZ())); - - if(dx < d) - { - d = dx; - f = j; - } - } - } - - return f; - } - - public PlacedObject randomObject(String string) - { - return god.randomObject(string); - } - - @Override - protected SChunkVector getParallaxSize() - { - return dim.getMaxChunkSize(); - } - - @Override - protected void onUnload() - { - dispose(); - } - - public void inject(CompiledDimension dimension) - { - this.dim = dimension; - onInit(getWorld(), rTerrain); - } -} \ No newline at end of file diff --git a/src/main/java/ninja/bytecode/iris/generator/IrisSample.java b/src/main/java/ninja/bytecode/iris/generator/IrisSample.java deleted file mode 100644 index 40afbc7bb..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/IrisSample.java +++ /dev/null @@ -1,81 +0,0 @@ -package ninja.bytecode.iris.generator; - -import ninja.bytecode.iris.pack.IrisBiome; -import ninja.bytecode.iris.util.MB; - -public class IrisSample -{ - public MB surface; - public int height; - public IrisBiome biome; - - public MB getSurface() - { - return surface; - } - - public void setSurface(MB surface) - { - this.surface = surface; - } - - public int getHeight() - { - return height; - } - - public void setHeight(int height) - { - this.height = height; - } - - public IrisBiome getBiome() - { - return biome; - } - - public void setBiome(IrisBiome biome) - { - this.biome = biome; - } - - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = prime * result + ((biome == null) ? 0 : biome.hashCode()); - result = prime * result + height; - result = prime * result + ((surface == null) ? 0 : surface.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) - { - if(this == obj) - return true; - if(obj == null) - return false; - if(getClass() != obj.getClass()) - return false; - IrisSample other = (IrisSample) obj; - if(biome == null) - { - if(other.biome != null) - return false; - } - else if(!biome.equals(other.biome)) - return false; - if(height != other.height) - return false; - if(surface == null) - { - if(other.surface != null) - return false; - } - else if(!surface.equals(other.surface)) - return false; - return true; - } -} diff --git a/src/main/java/ninja/bytecode/iris/generator/WorldReactor.java b/src/main/java/ninja/bytecode/iris/generator/WorldReactor.java deleted file mode 100644 index a1acca8fa..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/WorldReactor.java +++ /dev/null @@ -1,105 +0,0 @@ -package ninja.bytecode.iris.generator; - -import java.util.Collections; -import java.util.function.Consumer; - -import org.bukkit.Chunk; -import org.bukkit.World; -import org.bukkit.entity.Player; - -import mortar.api.nms.NMP; -import mortar.api.sched.J; -import mortar.compute.math.M; -import mortar.lang.collection.FinalDouble; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.util.ChronoQueue; -import ninja.bytecode.iris.util.ObjectMode; -import ninja.bytecode.iris.util.SMCAVector; -import ninja.bytecode.shuriken.collections.KList; -import ninja.bytecode.shuriken.collections.KMap; - -public class WorldReactor -{ - private static KList q = new KList<>(); - private final World world; - - public WorldReactor(World world) - { - this.world = world; - } - - public void generateRegionNormal(Player p, boolean force, double mst, Consumer progress, Runnable done) - { - for(ChronoQueue i : WorldReactor.q) - { - i.close(); - } - - WorldReactor.q.clear(); - - ChronoQueue q = new ChronoQueue(mst, 10240); - WorldReactor.q.add(q); - FinalDouble of = new FinalDouble(0D); - FinalDouble max = new FinalDouble(0D); - KMap d = new KMap<>(); - int mx = p.getLocation().getChunk().getX(); - int mz = p.getLocation().getChunk().getZ(); - for(int xx = p.getLocation().getChunk().getX() - 32; xx < p.getLocation().getChunk().getX() + 32; xx++) - { - int x = xx; - - for(int zz = p.getLocation().getChunk().getZ() - 32; zz < p.getLocation().getChunk().getZ() + 32; zz++) - { - int z = zz; - - if(world.isChunkLoaded(x, z) || world.loadChunk(x, z, false)) - { - d.put(new SMCAVector(x, z), Math.sqrt(Math.pow(x - mx, 2) + Math.pow(z - mz, 2))); - } - } - } - - KList v = d.k(); - Collections.sort(v, (a, b) -> (int) (10000 * (d.get(a) - d.get(b)))); - - for(SMCAVector i : v) - { - int x = i.getX(); - int z = i.getZ(); - - if(Iris.settings.performance.objectMode.equals(ObjectMode.PARALLAX) && world.getGenerator() instanceof IrisGenerator) - { - IrisGenerator gg = ((IrisGenerator) world.getGenerator()); - gg.getWorldData().deleteChunk(x, z); - } - - max.add(1); - q.queue(() -> - { - world.regenerateChunk(x, z); - - Chunk cc = world.getChunkAt(x, z); - NMP.host.relight(cc); - of.add(1); - - if(of.get() == max.get()) - { - progress.accept(1D); - q.dieSlowly(); - done.run(); - } - - else - { - progress.accept(M.clip(of.get() / max.get(), 0D, 1D)); - } - - }); - } - - J.s(() -> - { - q.dieSlowly(); - }, 20); - } -} diff --git a/src/main/java/ninja/bytecode/iris/generator/atomics/AtomicCharArray.java b/src/main/java/ninja/bytecode/iris/generator/atomics/AtomicCharArray.java deleted file mode 100644 index 7f032167e..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/atomics/AtomicCharArray.java +++ /dev/null @@ -1,83 +0,0 @@ -package ninja.bytecode.iris.generator.atomics; - -import java.io.Serializable; -import java.lang.reflect.Field; - -import sun.misc.Unsafe; - -@SuppressWarnings("restriction") -public class AtomicCharArray implements Serializable -{ - private static final long serialVersionUID = 2862133569453604235L; - private static final Unsafe unsafe; - private static final int base; - private static final int shift; - volatile char[] array; - - public AtomicCharArray(int var1) - { - this.array = new char[var1]; - } - - private long checkedByteOffset(int var1) - { - if(var1 >= 0 && var1 < this.array.length) - { - return byteOffset(var1); - } - else - { - throw new IndexOutOfBoundsException("index " + var1); - } - } - - public final char get(int var1) - { - return this.getRaw(this.checkedByteOffset(var1)); - } - - private char getRaw(long var1) - { - return unsafe.getCharVolatile(this.array, var1); - } - - public final void set(int var1, char var2) - { - unsafe.putCharVolatile(this.array, this.checkedByteOffset(var1), var2); - } - - private static long byteOffset(int var0) - { - return ((long) var0 << shift) + (long) base; - } - - static - { - Field f; - Unsafe o = null; - - try - { - f = Unsafe.class.getDeclaredField("theUnsafe"); - f.setAccessible(true); - o = (Unsafe) f.get(null); - } - - catch(Throwable e) - { - e.printStackTrace(); - } - - unsafe = o; - base = unsafe.arrayBaseOffset(int[].class); - int var0 = unsafe.arrayIndexScale(int[].class); - if((var0 & var0 - 1) != 0) - { - throw new Error("data type scale not a power of two"); - } - else - { - shift = 31 - Integer.numberOfLeadingZeros(var0); - } - } -} \ No newline at end of file diff --git a/src/main/java/ninja/bytecode/iris/generator/atomics/AtomicChunkData.java b/src/main/java/ninja/bytecode/iris/generator/atomics/AtomicChunkData.java deleted file mode 100644 index e6af21880..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/atomics/AtomicChunkData.java +++ /dev/null @@ -1,456 +0,0 @@ -package ninja.bytecode.iris.generator.atomics; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.lang.reflect.Field; -import java.util.concurrent.locks.ReentrantLock; - -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_12_R1.generator.CraftChunkData; -import org.bukkit.generator.ChunkGenerator; -import org.bukkit.generator.ChunkGenerator.ChunkData; -import org.bukkit.material.MaterialData; - -import mortar.compute.math.M; -import ninja.bytecode.iris.util.MB; - -public final class AtomicChunkData implements ChunkGenerator.ChunkData -{ - private static final Field t; - private static final Field[] sections; - private static final int h = 0x1000; - private final int maxHeight; - private static ReentrantLock[] locks; - private char[] s0; - private char[] s1; - private char[] s2; - private char[] s3; - private char[] s4; - private char[] s5; - private char[] s6; - private char[] s7; - private char[] s8; - private char[] s9; - private char[] s10; - private char[] s11; - private char[] s12; - private char[] s13; - private char[] s14; - private char[] s15; - private char[][] m; - private World w; - private long lastUse; - private int bits; - - public AtomicChunkData(World world) - { - this.maxHeight = world.getMaxHeight(); - this.w = world; - bits = 0; - lastUse = M.ms(); - } - - public long getTimeSinceLastUse() - { - return M.ms() - lastUse; - } - - public void read(InputStream in) throws IOException - { - read(in, true); - } - - public void read(InputStream in, boolean ignoreAir) throws IOException - { - DataInputStream din = new DataInputStream(in); - int bits = din.readInt(); - - for(int i = 0; i < 16; i++) - { - int bit = getBit(i); - if((bits & bit) == bit) - { - char[] section = getChunkSection(i << 4, true); - - for(int j = 0; j < section.length; j++) - { - char c = din.readChar(); - - if(c == 0 && ignoreAir) - { - continue; - } - - section[j] = c; - } - } - } - - din.close(); - } - - public void write(OutputStream out) throws IOException - { - DataOutputStream dos = new DataOutputStream(out); - dos.writeInt(getDataBits()); - - for(int i = 0; i < 16; i++) - { - if(hasDataBit(i)) - { - char[] section = getChunkSection(i << 4, false); - for(int j = 0; j < section.length; j++) - { - dos.writeChar(section[j]); - } - } - } - - dos.close(); - } - - public boolean hasDataBit(int section) - { - int b = getBit(section); - return (bits & b) == b; - } - - public void clearDataBits() - { - bits = 0; - } - - public void addDataBit(int section) - { - bits |= getBit(section); - } - - public void removeDataBit(int section) - { - bits ^= getBit(section); - } - - public int getDataBits() - { - return bits; - } - - public int getBit(int index) - { - return (int) (index < 0 ? -1 : Math.pow(2, index)); - } - - public int computeDataBits() - { - int bits = 0; - - for(int i = 0; i < 16; i++) - { - try - { - bits |= sections[i].get(this) != null ? getBit(i) : 0; - } - - catch(Throwable e) - { - - } - } - - return bits; - } - - @Override - public int getMaxHeight() - { - return maxHeight; - } - - @SuppressWarnings("deprecation") - @Override - public void setBlock(int x, int y, int z, Material material) - { - setBlock(x, y, z, material.getId()); - } - - @SuppressWarnings("deprecation") - @Override - public void setBlock(int x, int y, int z, MaterialData material) - { - setBlock(x, y, z, material.getItemTypeId(), material.getData()); - } - - @SuppressWarnings("deprecation") - @Override - public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, Material material) - { - setRegion(xMin, yMin, zMin, xMax, yMax, zMax, material.getId()); - } - - @SuppressWarnings("deprecation") - @Override - public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, MaterialData material) - { - setRegion(xMin, yMin, zMin, xMax, yMax, zMax, material.getItemTypeId(), material.getData()); - } - - @SuppressWarnings("deprecation") - @Override - public Material getType(int x, int y, int z) - { - lastUse = M.ms(); - return Material.getMaterial(getTypeId(x, y, z)); - } - - @SuppressWarnings("deprecation") - @Override - public MaterialData getTypeAndData(int x, int y, int z) - { - lastUse = M.ms(); - return getType(x, y, z).getNewData(getData(x, y, z)); - } - - @SuppressWarnings("deprecation") - public void setBlock(int x, int y, int z, Material blockId, byte data) - { - setBlock(x, y, z, blockId.getId(), data); - } - - @Override - public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, int blockId) - { - lastUse = M.ms(); - setRegion(xMin, yMin, zMin, xMax, yMax, zMax, blockId, (byte) 0); - } - - @Override - public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, int blockId, int data) - { - lastUse = M.ms(); - throw new UnsupportedOperationException("AtomicChunkData does not support setting regions"); - } - - @Override - public void setBlock(int x, int y, int z, int blockId) - { - setBlock(x, y, z, blockId, (byte) 0); - } - - @Override - public void setBlock(int x, int y, int z, int blockId, byte data) - { - setBlock(x, y, z, (char) (blockId << 4 | data)); - } - - @SuppressWarnings("deprecation") - public MB getMB(int x, int y, int z) - { - if(x != (x & 0xf) || y < 0 || y >= maxHeight || z != (z & 0xf)) - { - lastUse = M.ms(); - return MB.of(Material.AIR); - } - - char[] section = getChunkSection(y, false); - - if(section == null) - { - lastUse = M.ms(); - return MB.of(Material.AIR); - } - - else - { - lastUse = M.ms(); - char xf = section[(y & 0xf) << 8 | z << 4 | x]; - return MB.of(Material.getMaterial(xf >> 4), xf & 0xf); - } - } - - @Override - public int getTypeId(int x, int y, int z) - { - if(x != (x & 0xf) || y < 0 || y >= maxHeight || z != (z & 0xf)) - { - return 0; - } - - char[] section = getChunkSection(y, false); - - if(section == null) - { - return 0; - } - - else - { - lastUse = M.ms(); - return section[(y & 0xf) << 8 | z << 4 | x] >> 4; - } - } - - @Override - public byte getData(int x, int y, int z) - { - if(x != (x & 0xf) || y < 0 || y >= maxHeight || z != (z & 0xf)) - { - lastUse = M.ms(); - return (byte) 0; - } - - char[] section = getChunkSection(y, false); - - if(section == null) - { - lastUse = M.ms(); - return (byte) 0; - } - - else - { - lastUse = M.ms(); - return (byte) (section[(y & 0xf) << 8 | z << 4 | x] & 0xf); - } - } - - private void setBlock(int x, int y, int z, char type) - { - if(x != (x & 0xf) || y < 0 || y >= maxHeight || z != (z & 0xf)) - { - return; - } - - lastUse = M.ms(); - ReentrantLock l = locks[y >> 4]; - l.lock(); - getChunkSection(y, true)[(y & 0xf) << 8 | z << 4 | x] = type; - l.unlock(); - } - - private char[] getChunkSection(int y, boolean c) - { - try - { - int s = y >> 4; - Field sf = sections[s]; - char[] section = (char[]) sf.get(this); - - if(section == null && c) - { - sf.set(this, new char[h]); - section = (char[]) sf.get(this); - addDataBit(s); - } - - return section; - } - - catch(Throwable e) - { - e.printStackTrace(); - } - - return null; - } - - public ChunkData toChunkData() - { - ChunkData c = new CraftChunkData(w); - - try - { - m = (char[][]) t.get(c); - m[0] = s0; - m[1] = s1; - m[2] = s2; - m[3] = s3; - m[4] = s4; - m[5] = s5; - m[6] = s6; - m[7] = s7; - m[8] = s8; - m[9] = s9; - m[10] = s10; - m[11] = s11; - m[12] = s12; - m[13] = s13; - m[14] = s14; - m[15] = s15; - } - - catch(IllegalArgumentException | IllegalAccessException e) - { - e.printStackTrace(); - } - - return c; - } - - static - { - locks = new ReentrantLock[16]; - Field[] s = new Field[16]; - - for(int i = 0; i < 16; i++) - { - try - { - s[i] = AtomicChunkData.class.getDeclaredField("s" + i); - locks[i] = new ReentrantLock(); - } - - catch(Throwable e) - { - e.printStackTrace(); - } - } - - sections = s; - - Field x = null; - - try - { - x = CraftChunkData.class.getDeclaredField("sections"); - x.setAccessible(true); - } - - catch(Throwable e) - { - e.printStackTrace(); - } - - t = x; - } - - public void inject(AtomicChunkData data) - { - for(int i = 0; i < 16; i++) - { - if(hasDataBit(i)) - { - char[] fromSection = getChunkSection(i << 4, false); - char[] toSection = data.getChunkSection(i << 4, true); - - for(int j = 0; j < fromSection.length; j++) - { - char x = fromSection[j]; - - if(x != 0) - { - toSection[j] = x; - } - } - } - } - } - - public void setBlock(int x, int y, int z, MB mb) - { - setBlock(x, y, z, mb.material, mb.data); - } -} \ No newline at end of file diff --git a/src/main/java/ninja/bytecode/iris/generator/atomics/AtomicRegionData.java b/src/main/java/ninja/bytecode/iris/generator/atomics/AtomicRegionData.java deleted file mode 100644 index 444869b50..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/atomics/AtomicRegionData.java +++ /dev/null @@ -1,80 +0,0 @@ -package ninja.bytecode.iris.generator.atomics; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import org.bukkit.World; -import org.jnbt.ByteArrayTag; -import org.jnbt.CompoundTag; -import org.jnbt.NBTInputStream; -import org.jnbt.NBTOutputStream; -import org.jnbt.Tag; - -import ninja.bytecode.shuriken.collections.KMap; - -public class AtomicRegionData -{ - private final World world; - private KMap tag; - - public AtomicRegionData(World world) - { - this.world = world; - tag = new KMap<>(); - } - - public void read(InputStream in) throws IOException - { - NBTInputStream nin = new NBTInputStream(in); - tag = new KMap<>(); - tag.putAll(((CompoundTag) nin.readTag()).getValue()); - nin.close(); - } - - public void write(OutputStream out) throws IOException - { - NBTOutputStream nos = new NBTOutputStream(out); - nos.writeTag(new CompoundTag("imca", tag)); - nos.close(); - } - - public boolean contains(int rx, int rz) - { - return tag.containsKey(rx + "." + rz); - } - - public void delete(int rx, int rz) - { - tag.remove(rx + "." + rz); - } - - public void set(int rx, int rz, AtomicChunkData data) throws IOException - { - ByteArrayOutputStream boas = new ByteArrayOutputStream(); - data.write(boas); - tag.put(rx + "." + rz, new ByteArrayTag(rx + "." + rz, boas.toByteArray())); - } - - public AtomicChunkData get(int rx, int rz) throws IOException - { - if(!contains(rx, rz)) - { - return null; - } - - AtomicChunkData data = new AtomicChunkData(world); - ByteArrayTag btag = (ByteArrayTag) tag.get(rx + "." + rz); - ByteArrayInputStream in = new ByteArrayInputStream(btag.getValue()); - data.read(in); - - return data; - } - - public World getWorld() - { - return world; - } -} diff --git a/src/main/java/ninja/bytecode/iris/generator/atomics/AtomicWorldData.java b/src/main/java/ninja/bytecode/iris/generator/atomics/AtomicWorldData.java deleted file mode 100644 index d6e7e3e0e..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/atomics/AtomicWorldData.java +++ /dev/null @@ -1,158 +0,0 @@ -package ninja.bytecode.iris.generator.atomics; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; - -import org.bukkit.World; - -import ninja.bytecode.iris.util.SMCAVector; -import ninja.bytecode.shuriken.collections.KList; -import ninja.bytecode.shuriken.collections.KMap; - -public class AtomicWorldData -{ - private World world; - private KMap loadedSections; - - public AtomicWorldData(World world) - { - this.world = world; - loadedSections = new KMap<>(); - getSubregionFolder().mkdirs(); - } - - public KList getLoadedRegions() - { - return loadedSections.k(); - } - - public AtomicRegionData getSubregion(int x, int z) throws IOException - { - if(!isSectionLoaded(x, z)) - { - loadedSections.put(new SMCAVector(x, z), loadSection(x, z)); - } - - AtomicRegionData f = loadedSections.get(new SMCAVector(x, z)); - - return f; - } - - public void saveAll() throws IOException - { - for(SMCAVector i : loadedSections.keySet()) - { - saveSection(i); - } - } - - public void unloadAll(boolean save) throws IOException - { - for(SMCAVector i : loadedSections.keySet()) - { - unloadSection(i, save); - } - } - - public void deleteSection(int x, int z) throws IOException - { - unloadSection(x, z, false); - getSubregionFile(x, z).delete(); - } - - public boolean isSectionLoaded(int x, int z) - { - return isSectionLoaded(new SMCAVector(x, z)); - } - - public boolean isSectionLoaded(SMCAVector s) - { - return loadedSections.containsKey(s); - } - - public boolean unloadSection(int x, int z, boolean save) throws IOException - { - return unloadSection(new SMCAVector(x, z), save); - } - - public boolean unloadSection(SMCAVector s, boolean save) throws IOException - { - if(!isSectionLoaded(s)) - { - return false; - } - - if(save) - { - saveSection(s); - } - - loadedSections.remove(s); - return true; - } - - public boolean saveSection(int x, int z) throws IOException - { - return saveSection(new SMCAVector(x, z)); - } - - public boolean saveSection(SMCAVector s) throws IOException - { - if(!isSectionLoaded(s.getX(), s.getZ())) - { - return false; - } - - AtomicRegionData data = loadedSections.get(s); - FileOutputStream fos = new FileOutputStream(getSubregionFile(s.getX(), s.getZ())); - data.write(fos); - fos.close(); - return true; - } - - public AtomicRegionData loadSection(int x, int z) throws IOException - { - if(isSectionLoaded(x, z)) - { - return loadedSections.get(new SMCAVector(x, z)); - } - - File file = getSubregionFile(x, z); - - if(!file.exists()) - { - return createSection(x, z); - } - - FileInputStream fin = new FileInputStream(file); - AtomicRegionData data = new AtomicRegionData(world); - data.read(fin); - fin.close(); - return data; - } - - public AtomicRegionData createSection(int x, int z) - { - if(isSectionLoaded(x, z)) - { - return loadedSections.get(new SMCAVector(x, z)); - } - - AtomicRegionData data = new AtomicRegionData(world); - loadedSections.put(new SMCAVector(x, z), data); - - return data; - } - - public File getSubregionFile(int x, int z) - { - return new File(getSubregionFolder(), "sr." + x + "." + z + ".smca"); - } - - public File getSubregionFolder() - { - return new File(world.getWorldFolder(), "subregion"); - } -} diff --git a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObject.java b/src/main/java/ninja/bytecode/iris/generator/genobject/GenObject.java deleted file mode 100644 index a884a7658..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObject.java +++ /dev/null @@ -1,1110 +0,0 @@ -package ninja.bytecode.iris.generator.genobject; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.function.Consumer; -import java.util.function.Supplier; -import java.util.zip.GZIPInputStream; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.BlockFace; -import org.bukkit.material.Directional; -import org.bukkit.material.Ladder; -import org.bukkit.material.Leaves; -import org.bukkit.material.MaterialData; -import org.bukkit.material.Stairs; -import org.bukkit.material.Vine; -import org.bukkit.util.BlockVector; -import org.bukkit.util.Vector; - -import mortar.compute.math.M; -import mortar.logic.format.F; -import mortar.util.text.C; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.generator.placer.NMSPlacer; -import ninja.bytecode.iris.util.Direction; -import ninja.bytecode.iris.util.IPlacer; -import ninja.bytecode.iris.util.MB; -import ninja.bytecode.iris.util.SBlockVector; -import ninja.bytecode.iris.util.SChunkVectorShort; -import ninja.bytecode.iris.util.VectorMath; -import ninja.bytecode.shuriken.collections.KList; -import ninja.bytecode.shuriken.collections.KMap; -import ninja.bytecode.shuriken.io.CustomOutputStream; -import ninja.bytecode.shuriken.logging.L; -import ninja.bytecode.shuriken.math.RNG; - -public class GenObject -{ - private boolean centeredHeight; - private int w; - private int h; - private int d; - private int failures; - private int successes; - private boolean gravity; - private boolean oversized; - private String name = "?"; - private KMap s; - private KMap slopeCache; - private KMap gravityCache; - private BlockVector mount; - private int maxslope; - private int baseslope; - private boolean hydrophilic; - private boolean submerged; - private int mountHeight; - private BlockVector shift; - - public GenObject(int w, int h, int d) - { - this.w = w; - oversized = false; - this.h = h; - this.d = d; - shift = new BlockVector(); - s = new KMap<>(); - centeredHeight = false; - gravity = false; - maxslope = -1; - baseslope = 0; - hydrophilic = false; - submerged = false; - } - - public void recalculateMountShift() - { - int ly = Integer.MAX_VALUE; - - for(SBlockVector i : s.keySet()) - { - if(i.getY() < ly) - { - ly = (int) i.getY(); - } - } - - KList fmount = new KList<>(); - - for(SBlockVector i : s.keySet()) - { - if(i.getY() == ly) - { - fmount.add(i); - } - } - - double avx[] = new double[fmount.size()]; - double avy[] = new double[fmount.size()]; - double avz[] = new double[fmount.size()]; - int c = 0; - - for(SBlockVector i : fmount) - { - avx[c] = i.getX(); - avy[c] = i.getY(); - avz[c] = i.getZ(); - c++; - } - - mountHeight = avg(avy); - mount = new BlockVector(0, 0, 0); - } - - private KMap getSlopeCache() - { - if(slopeCache == null) - { - computeSlopeCache(); - } - - return slopeCache; - } - - private KMap getGravityCache() - { - if(gravityCache == null) - { - computeGravityCache(); - } - - return gravityCache; - } - - private void computeGravityCache() - { - gravityCache = new KMap<>(); - - for(SBlockVector i : s.keySet()) - { - SChunkVectorShort v = new SChunkVectorShort(i.getX(), i.getZ()); - - if(!gravityCache.containsKey(v) || gravityCache.get(v).getY() > i.getY()) - { - gravityCache.put(v, i); - } - } - } - - private void computeSlopeCache() - { - slopeCache = new KMap<>(); - int low = Integer.MAX_VALUE; - - for(SBlockVector i : s.keySet()) - { - SChunkVectorShort v = new SChunkVectorShort(i.getX(), i.getZ()); - - if(!slopeCache.containsKey(v) || slopeCache.get(v).getY() > i.getY()) - { - slopeCache.put(v, i); - } - } - - for(SChunkVectorShort i : slopeCache.keySet()) - { - int f = (int) slopeCache.get(i).getY(); - - if(f < low) - { - low = f; - } - } - - for(SChunkVectorShort i : slopeCache.k()) - { - int f = (int) slopeCache.get(i).getY(); - - if(f > low - baseslope) - { - slopeCache.remove(i); - } - } - } - - private int avg(double[] v) - { - double g = 0; - - for(int i = 0; i < v.length; i++) - { - g += v[i]; - } - - return (int) Math.round(g / (double) v.length); - } - - public void setCenteredHeight() - { - this.centeredHeight = true; - } - - public int getW() - { - return w; - } - - public int getH() - { - return h; - } - - public int getD() - { - return d; - } - - public KMap getSchematic() - { - return s; - } - - public int getWidth() - { - return w; - } - - public int getDepth() - { - return d; - } - - public void read(InputStream in, boolean gzip) throws IOException - { - @SuppressWarnings("resource") - GZIPInputStream gzi = gzip ? new GZIPInputStream(in) : null; - DataInputStream din = new DataInputStream(gzip ? gzi : in); - readDirect(din); - din.close(); - } - - @SuppressWarnings("deprecation") - public void readDirect(DataInputStream din) throws IOException - { - w = din.readInt(); - h = din.readInt(); - d = din.readInt(); - int l = din.readInt(); - clear(); - - for(int i = 0; i < l; i++) - { - s.put(new SBlockVector(din.readInt(), din.readInt(), din.readInt()), new MB(Material.getMaterial((int) din.readInt()), din.readInt())); - } - } - - @SuppressWarnings("deprecation") - public void writeDirect(DataOutputStream dos) throws IOException - { - dos.writeInt(w); - dos.writeInt(h); - dos.writeInt(d); - dos.writeInt(s.size()); - - for(SBlockVector i : s.keySet()) - { - dos.writeInt((int) i.getX()); - dos.writeInt((int) i.getY()); - dos.writeInt((int) i.getZ()); - dos.writeInt(s.get(i).material.getId()); - dos.writeInt(s.get(i).data); - } - } - - public void write(OutputStream out, boolean gzip) throws IOException - { - CustomOutputStream cos = gzip ? new CustomOutputStream(out, 9) : null; - DataOutputStream dos = new DataOutputStream(gzip ? cos : out); - writeDirect(dos); - dos.close(); - } - - public MB get(int x, int y, int z) - { - return s.get(new SBlockVector(x, y, z)); - } - - public boolean has(int x, int y, int z) - { - return s.containsKey(new SBlockVector(x, y, z)); - } - - public void put(int x, int y, int z, MB mb) - { - s.put(new SBlockVector(x, y, z), mb); - } - - public GenObject copy() - { - GenObject s = new GenObject(w, h, d); - s.fill(this.s); - s.centeredHeight = centeredHeight; - s.name = name; - s.oversized = oversized; - return s; - } - - public void clear() - { - s.clear(); - } - - public void fill(KMap b) - { - clear(); - s.putAll(b); - } - - public int sh(int g) - { - int m = (g / 2); - return g % 2 == 0 ? m : m + 1; - } - - public Location place(Location l) - { - NMSPlacer p; - Location ll = place(l, p = new NMSPlacer(l.getWorld())); - p.flush(); - - return ll; - } - - public Location place(Location l, IPlacer placer) - { - return place(l.getBlockX(), l.getBlockY(), l.getBlockZ(), placer); - } - - @SuppressWarnings("deprecation") - public Location place(int wx, int wy, int wz, IPlacer placer) - { - Location start = new Location(placer.getWorld(), wx, wy, wz).clone().add(0, sh(h) + 1, 0); - - if(mount == null) - { - recalculateMountShift(); - } - - start.subtract(mount); - - int highestY = submerged ? placer.getHighestYUnderwater(start) : placer.getHighestY(start); - - if(start.getBlockY() + mountHeight > highestY) - { - start.subtract(0, start.getBlockY() + mountHeight - highestY, 0); - } - - start.add(shift); - KMap undo = new KMap<>(); - - for(SBlockVector i : s.keySet()) - { - MB b = getSchematic().get(i); - - if(b.material.equals(Material.LEAVES) || b.material.equals(Material.LEAVES_2)) - { - Leaves l = new Leaves(b.material, b.data); - l.setDecayable(false); - l.setDecaying(false); - b = new MB(l.getItemType(), l.getData()); - } - - Location f = start.clone().add(i.toBlockVector()); - - if(gravity) - { - SChunkVectorShort v = new SChunkVectorShort(i.getX(), i.getZ()); - int offset = (int) i.getY() - (int) getGravityCache().get(v).getY(); - f.setY(f.getBlockY() - ((f.getBlockY() - offset) - (submerged ? placer.getHighestYUnderwater(f) : placer.getHighestY(f)))); - } - - else if(maxslope >= 0) - { - SChunkVectorShort v = new SChunkVectorShort(i.getX(), i.getZ()); - SBlockVector m = getSlopeCache().get(v); - - if(m == null) - { - continue; - } - - int offset = (int) i.getY() - (int) m.getY(); - int shift = ((f.getBlockY() - offset) - (submerged ? placer.getHighestYUnderwater(f) : placer.getHighestY(f))); - - if(Math.abs(shift) > maxslope) - { - for(Location j : undo.k()) - { - placer.set(j, undo.get(j)); - } - - if(Iris.settings.performance.verbose) - { - L.w(C.WHITE + "Object " + C.YELLOW + getName() + C.WHITE + " failed to place on slope " + C.YELLOW + Math.abs(shift) + C.WHITE + " at " + C.YELLOW + F.f(f.getBlockX()) + " " + F.f(f.getBlockY()) + " " + F.f(f.getBlockZ())); - } - - failures++; - return null; - } - } - - if(!hydrophilic && !Iris.settings.performance.noObjectFail) - { - if(f.getBlockY() == 63 && i.getY() == mountHeight) - { - Material m = placer.get(f.clone().subtract(0, 1, 0)).material; - - if(m.equals(Material.WATER) || m.equals(Material.STATIONARY_WATER) || m.equals(Material.LAVA) || m.equals(Material.STATIONARY_LAVA)) - { - for(Location j : undo.k()) - { - placer.set(j, undo.get(j)); - } - - if(Iris.settings.performance.verbose) - { - L.w(C.WHITE + "Object " + C.YELLOW + getName() + C.WHITE + " (hydrophobic) failed to place in " + C.YELLOW + m.toString().toLowerCase() + C.WHITE + " at " + C.YELLOW + F.f(f.getBlockX()) + " " + F.f(f.getBlockY()) + " " + F.f(f.getBlockZ())); - } - - failures++; - return null; - } - } - } - - try - { - undo.put(f, placer.get(f)); - placer.set(f, b); - } - - catch(Throwable e) - { - e.printStackTrace(); - } - } - - successes++; - return start; - } - - public static GenObject load(InputStream in) throws IOException - { - GenObject s = new GenObject(1, 1, 1); - s.read(in, true); - - return s; - } - - public static GenObject load(File f) throws IOException - { - GenObject s = new GenObject(1, 1, 1); - s.name = f.getName().replaceAll("\\Q.ish\\E", ""); - FileInputStream fin = new FileInputStream(f); - s.read(fin, true); - - return s; - } - - public String getName() - { - return name; - } - - public void setName(String name) - { - this.name = name; - } - - public void rotate(Direction from, Direction to) - { - KMap g = new KMap<>(); - g.putAll(s); - s.clear(); - - for(SBlockVector i : g.keySet()) - { - MB mb = rotate(from, to, g.get(i)); - s.put(new SBlockVector(VectorMath.rotate(from, to, i.toBlockVector()).toBlockVector()), mb); - } - - name = name + "-rt" + to.name(); - } - - @SuppressWarnings("deprecation") - private MB rotate(Direction from, Direction to, MB mb) - { - try - { - Material t = mb.material; - int i = t.getId(); - byte d = mb.data; - MaterialData data = t.getData().getConstructor(int.class, byte.class).newInstance(i, d); - - if(data instanceof Directional) - { - Directional dir = (Directional) data; - Supplier get = dir::getFacing; - Consumer set = dir::setFacingDirection; - - if(dir instanceof Ladder) - { - get = ((Ladder) dir)::getAttachedFace; - set = ((Ladder) dir)::setFacingDirection; - } - - if(dir instanceof Stairs) - { - get = ((Stairs) dir)::getAscendingDirection; - set = ((Stairs) dir)::setFacingDirection; - } - - BlockFace fac = get.get(); - set.accept(rotate(from, to, fac)); - d = data.getData(); - t = data.getItemType(); - return MB.of(t, d); - } - - else if(data instanceof Vine) - { - Vine vin = (Vine) data; - Vine vif = new Vine(); - - for(Direction j : Direction.news()) - { - if(vin.isOnFace(j.getFace())) - { - vif.putOnFace(rotate(from, to, j.getFace())); - } - } - - d = vif.getData(); - t = vif.getItemType(); - return MB.of(t, d); - } - - else if(i >= 235 && i <= 250) - { - BlockFace fac = getGlazedTCDir(d); - d = toGlazedTCDir(Direction.getDirection(rotate(from, to, fac)).getFace()); - t = data.getItemType(); - return MB.of(t, d); - } - } - - catch(Throwable e) - { - e.printStackTrace(); - } - - return mb; - } - - private byte toGlazedTCDir(BlockFace b) - { - switch(b) - { - case NORTH: - return 0; - case EAST: - return 1; - case SOUTH: - return 2; - case WEST: - return 3; - default: - break; - } - - return 0; - } - - private BlockFace getGlazedTCDir(byte d2) - { - switch(d2) - { - case 0: - return BlockFace.NORTH; - case 1: - return BlockFace.EAST; - case 2: - return BlockFace.SOUTH; - case 3: - return BlockFace.WEST; - } - - return BlockFace.NORTH; - } - - private BlockFace rotate(Direction from, Direction to, BlockFace face) - { - return Direction.getDirection(from.angle(Direction.getDirection(face).toVector(), to)).getFace(); - } - - public void computeFlag(String j) - { - try - { - if(j.equals("gravity")) - { - gravity = true; - } - - if(j.equals("hydrophilic")) - { - hydrophilic = true; - } - - if(j.equals("submerged")) - { - submerged = true; - hydrophilic = true; - } - - if(j.startsWith("maxslope ")) - { - maxslope = Integer.valueOf(j.split("\\Q \\E")[1]); - } - - if(j.startsWith("baseslope ")) - { - baseslope = Integer.valueOf(j.split("\\Q \\E")[1]); - } - - if(j.startsWith("replace ")) - { - String[] g = j.split("\\Q \\E"); - MB a = MB.of(g[1]); - boolean specific = g[1].contains(":"); - MB b = MB.of(g[2]); - - for(SBlockVector i : s.k()) - { - MB c = s.get(i); - - if((specific && c.equals(a)) || c.material.equals(a.material)) - { - s.put(i, b); - } - } - } - - if(j.startsWith("sink ")) - { - int downshift = Integer.valueOf(j.split("\\Q \\E")[1]); - shift.subtract(new Vector(0, downshift, 0)); - } - - if(j.startsWith("raise ")) - { - int downshift = Integer.valueOf(j.split("\\Q \\E")[1]); - shift.add(new Vector(0, downshift, 0)); - } - } - - catch(Throwable e) - { - L.f("Failed to compute flag '" + j + "'"); - L.ex(e); - } - } - - public void applySnowFilter(int factor) - { - int minX = 0; - int maxX = 0; - int minY = 0; - int maxY = 0; - int minZ = 0; - int maxZ = 0; - boolean added = false; - - for(SBlockVector i : getSchematic().keySet()) - { - if(i.getX() > maxX) - { - maxX = (int) i.getX(); - } - - if(i.getY() > maxY) - { - maxY = (int) i.getY(); - } - - if(i.getZ() > maxZ) - { - maxZ = (int) i.getZ(); - } - - if(i.getX() < minX) - { - minX = (int) i.getX(); - } - - if(i.getY() < minY) - { - minY = (int) i.getY(); - } - - if(i.getZ() < minZ) - { - minZ = (int) i.getZ(); - } - } - - for(int i = minX; i <= maxX; i++) - { - for(int j = minZ; j <= maxZ; j++) - { - SBlockVector highest = null; - - for(SBlockVector k : getSchematic().keySet()) - { - if(k.getX() == i && k.getZ() == j) - { - if(highest == null) - { - highest = k; - } - - else if(highest.getY() < k.getY()) - { - highest = k; - } - } - } - - if(highest != null) - { - BlockVector mbv = highest.toBlockVector().add(new Vector(0, 1, 0)).toBlockVector(); - added = true; - getSchematic().put(new SBlockVector(mbv), MB.of(Material.SNOW, RNG.r.nextInt((int) M.clip(factor, 1, 8)))); - } - } - } - - if(added) - { - h++; - recalculateMountShift(); - } - } - - @SuppressWarnings("deprecation") - public void applyLushFilter(double factor) - { - int minX = 0; - int maxX = 0; - int minY = 0; - int maxY = 0; - int minZ = 0; - int maxZ = 0; - boolean added = false; - - for(SBlockVector i : getSchematic().keySet()) - { - if(i.getX() > maxX) - { - maxX = (int) i.getX(); - } - - if(i.getY() > maxY) - { - maxY = (int) i.getY(); - } - - if(i.getZ() > maxZ) - { - maxZ = (int) i.getZ(); - } - - if(i.getX() < minX) - { - minX = (int) i.getX(); - } - - if(i.getY() < minY) - { - minY = (int) i.getY(); - } - - if(i.getZ() < minZ) - { - minZ = (int) i.getZ(); - } - } - - for(int i = minX; i <= maxX; i++) - { - for(int j = minY; j <= maxY; j++) - { - for(int k = minZ; k <= maxZ; k++) - { - SBlockVector at = new SBlockVector(i, j, k); - - if(M.r(factor / 25D) && getSchematic().containsKey(at) && !getSchematic().get(at).material.equals(Material.VINE)) - { - SBlockVector a = new SBlockVector(i + 1, j, k); - SBlockVector b = new SBlockVector(i - 1, j, k); - SBlockVector c = new SBlockVector(i, j, k + 1); - SBlockVector d = new SBlockVector(i, j, k - 1); - Vine v = null; - KMap e = new KMap<>(); - - if(!getSchematic().containsKey(a)) - { - v = new Vine(BlockFace.WEST); - SBlockVector ma = new SBlockVector(a.getX(), a.getY(), a.getZ() + 1); - SBlockVector mb = new SBlockVector(a.getX(), a.getY(), a.getZ() - 1); - - if(getSchematic().containsKey(ma) && !getSchematic().get(ma).material.equals(Material.VINE)) - { - v = new Vine(BlockFace.SOUTH, BlockFace.WEST); - } - - else if(getSchematic().containsKey(mb) && !getSchematic().get(mb).material.equals(Material.VINE)) - { - v = new Vine(BlockFace.NORTH, BlockFace.WEST); - } - - e.put(a, MB.of(Material.VINE, v.getData())); - } - - if(!getSchematic().containsKey(b)) - { - v = new Vine(BlockFace.EAST); - SBlockVector ma = new SBlockVector(b.getX(), b.getY(), b.getZ() + 1); - SBlockVector mb = new SBlockVector(b.getX(), b.getY(), b.getZ() - 1); - - if(getSchematic().containsKey(ma) && !getSchematic().get(ma).material.equals(Material.VINE)) - { - v = new Vine(BlockFace.SOUTH, BlockFace.EAST); - } - - else if(getSchematic().containsKey(mb) && !getSchematic().get(mb).material.equals(Material.VINE)) - { - v = new Vine(BlockFace.NORTH, BlockFace.EAST); - } - - e.put(b, MB.of(Material.VINE, v.getData())); - } - - if(!getSchematic().containsKey(c)) - { - v = new Vine(BlockFace.NORTH); - SBlockVector ma = new SBlockVector(c.getX() + 1, c.getY(), c.getZ()); - SBlockVector mb = new SBlockVector(c.getX() - 1, c.getY(), c.getZ()); - - if(getSchematic().containsKey(ma) && !getSchematic().get(ma).material.equals(Material.VINE)) - { - v = new Vine(BlockFace.NORTH, BlockFace.EAST); - } - - else if(getSchematic().containsKey(mb) && !getSchematic().get(mb).material.equals(Material.VINE)) - { - v = new Vine(BlockFace.NORTH, BlockFace.WEST); - } - - e.put(c, MB.of(Material.VINE, v.getData())); - } - - if(!getSchematic().containsKey(d)) - { - v = new Vine(BlockFace.SOUTH); - SBlockVector ma = new SBlockVector(d.getX() + 1, d.getY(), d.getZ()); - SBlockVector mb = new SBlockVector(d.getX() - 1, d.getY(), d.getZ()); - - if(getSchematic().containsKey(ma) && !getSchematic().get(ma).material.equals(Material.VINE)) - { - v = new Vine(BlockFace.SOUTH, BlockFace.EAST); - } - - else if(getSchematic().containsKey(mb) && !getSchematic().get(mb).material.equals(Material.VINE)) - { - v = new Vine(BlockFace.SOUTH, BlockFace.WEST); - } - - e.put(d, MB.of(Material.VINE, v.getData())); - } - - if(!e.isEmpty()) - { - added = true; - } - - for(SBlockVector n : e.k()) - { - for(int g = 0; g < (factor * 2) * RNG.r.nextDouble(); g++) - { - if(n.getY() - (g + 1) < minY) - { - break; - } - - SBlockVector p = new SBlockVector(n.getX(), n.getY() - g, n.getZ()); - - if(e.containsKey(p) || getSchematic().containsKey(p)) - { - break; - } - - e.put(p, e.get(n)); - } - } - - getSchematic().putAll(e); - } - } - } - } - - if(added) - { - w++; - d++; - recalculateMountShift(); - } - } - - public double getSuccess() - { - return (double) successes / ((double) successes + (double) failures); - } - - public int getFailures() - { - return failures; - } - - public int getSuccesses() - { - return successes; - } - - public int getPlaces() - { - return successes + failures; - } - - public void dispose() - { - s.clear(); - } - - public void setGravity(boolean gravity) - { - this.gravity = gravity; - } - - public void setShift(int x, int y, int z) - { - shift = new BlockVector(x, y, z); - } - - public boolean isCenteredHeight() - { - return centeredHeight; - } - - public boolean isGravity() - { - return gravity; - } - - public KMap getS() - { - return s; - } - - public BlockVector getMount() - { - return mount; - } - - public int getMaxslope() - { - return maxslope; - } - - public int getBaseslope() - { - return baseslope; - } - - public boolean isHydrophilic() - { - return hydrophilic; - } - - public boolean isSubmerged() - { - return submerged; - } - - public int getMountHeight() - { - return mountHeight; - } - - public BlockVector getShift() - { - return shift; - } - - public void setCenteredHeight(boolean centeredHeight) - { - this.centeredHeight = centeredHeight; - } - - public void setW(int w) - { - this.w = w; - } - - public void setH(int h) - { - this.h = h; - } - - public void setD(int d) - { - this.d = d; - } - - public void setFailures(int failures) - { - this.failures = failures; - } - - public void setSuccesses(int successes) - { - this.successes = successes; - } - - public void setS(KMap s) - { - this.s = s; - } - - public void setSlopeCache(KMap slopeCache) - { - this.slopeCache = slopeCache; - } - - public void setGravityCache(KMap gravityCache) - { - this.gravityCache = gravityCache; - } - - public void setMount(BlockVector mount) - { - this.mount = mount; - } - - public void setMaxslope(int maxslope) - { - this.maxslope = maxslope; - } - - public void setBaseslope(int baseslope) - { - this.baseslope = baseslope; - } - - public void setHydrophilic(boolean hydrophilic) - { - this.hydrophilic = hydrophilic; - } - - public void setSubmerged(boolean submerged) - { - this.submerged = submerged; - } - - public void setMountHeight(int mountHeight) - { - this.mountHeight = mountHeight; - } - - public void setShift(BlockVector shift) - { - this.shift = shift; - } - - public boolean isOversized() - { - return oversized; - } - - public void setOversized(boolean oversized) - { - this.oversized = oversized; - } -} diff --git a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectDecorator.java b/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectDecorator.java deleted file mode 100644 index b65309260..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectDecorator.java +++ /dev/null @@ -1,463 +0,0 @@ -package ninja.bytecode.iris.generator.genobject; - -import java.util.Collections; -import java.util.Random; - -import org.bukkit.Chunk; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.generator.BlockPopulator; - -import mortar.api.sched.S; -import mortar.logic.format.F; -import mortar.util.text.C; -import net.md_5.bungee.api.ChatColor; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.generator.IrisGenerator; -import ninja.bytecode.iris.generator.parallax.ParallaxCache; -import ninja.bytecode.iris.generator.placer.AtomicParallaxPlacer; -import ninja.bytecode.iris.generator.placer.BukkitPlacer; -import ninja.bytecode.iris.generator.placer.NMSPlacer; -import ninja.bytecode.iris.pack.IrisBiome; -import ninja.bytecode.iris.util.IPlacer; -import ninja.bytecode.iris.util.MB; -import ninja.bytecode.iris.util.ObjectMode; -import ninja.bytecode.iris.util.SMCAVector; -import ninja.bytecode.shuriken.collections.KList; -import ninja.bytecode.shuriken.collections.KMap; -import ninja.bytecode.shuriken.collections.KSet; -import ninja.bytecode.shuriken.execution.ChronoLatch; -import ninja.bytecode.shuriken.execution.J; -import ninja.bytecode.shuriken.logging.L; -import ninja.bytecode.shuriken.math.M; -import ninja.bytecode.shuriken.math.RNG; - -public class GenObjectDecorator extends BlockPopulator -{ - private KList placeHistory; - private KMap> orderCache; - private KMap> populationCache; - private IPlacer placer; - private IrisGenerator g; - private ChronoLatch cl = new ChronoLatch(250); - - public GenObjectDecorator(IrisGenerator generator) - { - this.g = generator; - placeHistory = new KList<>(); - populationCache = new KMap<>(); - orderCache = new KMap<>(); - - for(IrisBiome i : generator.getDimension().getBiomes()) - { - KMap gc = new KMap<>(); - KMap> or = new KMap<>(); - int ff = 0; - for(String j : i.getSchematicGroups().k()) - { - double c = i.getSchematicGroups().get(j); - - try - { - GenObjectGroup g = generator.getDimension().getObjectGroup(j); - ff += g.size(); - gc.put(g, c); - - if(!or.containsKey(g.getPiority())) - { - or.put(g.getPiority(), new KList<>()); - } - - or.get(g.getPiority()).add(g); - } - - catch(Throwable e) - { - L.f(ChatColor.RED + "Failed to inject " + j + " into GenObjectDecorator"); - L.ex(e); - } - } - - if(!gc.isEmpty()) - { - KList g = new KList<>(); - for(KList j : or.v()) - { - g.addAll(j); - } - - Collections.sort(g, (a, b) -> a.getPiority() - b.getPiority()); - orderCache.put(i, g); - populationCache.put(i, gc); - - if(Iris.settings.performance.verbose) - { - L.v(C.DARK_GREEN + i.getName() + ": " + C.DARK_AQUA + F.f(ff) + " Objects"); - } - } - } - - L.i("Population Cache is " + populationCache.size()); - } - - @Override - public void populate(World world, Random random, Chunk source) - { - Runnable m = () -> - { - try - { - if(g.isDisposed()) - { - placeHistory.clear(); - return; - } - - KSet hits = new KSet<>(); - int cx = source.getX(); - int cz = source.getZ(); - - for(int i = 0; i < Iris.settings.performance.decorationAccuracy; i++) - { - int x = (cx << 4) + random.nextInt(16); - int z = (cz << 4) + random.nextInt(16); - IrisBiome biome = g.getBiome((int) g.getOffsetX(x, z), (int) g.getOffsetZ(x, z)); - - if(hits.contains(biome)) - { - continue; - } - - KMap objects = populationCache.get(biome); - - if(objects == null) - { - continue; - } - - hits.add(biome); - populate(world, cx, cz, random, biome); - } - } - - catch(Throwable e) - { - e.printStackTrace(); - } - }; - - if(Iris.settings.performance.objectMode.equals(ObjectMode.QUICK_N_DIRTY)) - { - J.a(m); - } - - else - { - m.run(); - } - } - - @SuppressWarnings("deprecation") - private void populate(World world, int cx, int cz, Random random, IrisBiome biome) - { - for(GenObjectGroup i : orderCache.get(biome)) - { - if(biome.getSchematicGroups().get(i.getName()) == null) - { - L.w(C.YELLOW + "Cannot find chance for " + C.RED + i.getName() + C.YELLOW + " in Biome " + C.RED + biome.getName()); - continue; - } - - for(int j = 0; j < getTries(biome.getSchematicGroups().get(i.getName())); j++) - { - if(M.r(Iris.settings.gen.objectDensity)) - { - GenObject go = i.getSchematics().get(random.nextInt(i.getSchematics().size())); - int x = (cx << 4) + random.nextInt(16); - int z = (cz << 4) + random.nextInt(16); - - if(i.getWorldChance() >= 0D) - { - int rngx = (int) Math.floor(x / (double) (i.getWorldRadius() == 0 ? 32 : i.getWorldRadius())); - int rngz = (int) Math.floor(z / (double) (i.getWorldRadius() == 0 ? 32 : i.getWorldRadius())); - - if(new RNG(new SMCAVector(rngx, rngz).hashCode()).nextDouble() < i.getWorldChance()) - { - if(Iris.settings.performance.verbose) - { - L.w(C.WHITE + "Object " + C.YELLOW + i.getName() + "/*" + C.WHITE + " failed to place due to a world chance."); - } - - break; - } - } - - int by = world.getHighestBlockYAt(x, z); - Block b = world.getBlockAt(x, by - 1, z); - MB mb = MB.of(b.getType(), b.getData()); - - if(!Iris.settings.performance.noObjectFail) - { - if(!mb.material.isSolid() || !biome.isSurface(mb.material)) - { - if(Iris.settings.performance.verbose) - { - L.w(C.WHITE + "Object " + C.YELLOW + i.getName() + "/*" + C.WHITE + " failed to place in " + C.YELLOW + mb.material.toString().toLowerCase() + C.WHITE + " at " + C.YELLOW + F.f(x) + " " + F.f(by) + " " + F.f(z)); - } - - return; - } - } - - if(Iris.settings.performance.objectMode.equals(ObjectMode.QUICK_N_DIRTY)) - { - placer = new NMSPlacer(world); - } - - else if(Iris.settings.performance.objectMode.equals(ObjectMode.LIGHTING_PHYSICS)) - { - placer = new BukkitPlacer(world, true); - } - - else if(Iris.settings.performance.objectMode.equals(ObjectMode.LIGHTING)) - { - placer = new BukkitPlacer(world, false); - } - - Runnable rx = () -> - { - Location start = go.place(x, by, z, placer); - - if(start != null) - { - g.hitObject(); - if(Iris.settings.performance.verbose) - { - L.v(C.GRAY + "Placed " + C.DARK_GREEN + i.getName() + C.WHITE + "/" + C.DARK_GREEN + go.getName() + C.GRAY + " at " + C.DARK_GREEN + F.f(start.getBlockX()) + " " + F.f(start.getBlockY()) + " " + F.f(start.getBlockZ())); - } - - if(Iris.settings.performance.debugMode) - { - placeHistory.add(new PlacedObject(start.getBlockX(), start.getBlockY(), start.getBlockZ(), i.getName() + ":" + go.getName())); - - if(placeHistory.size() > Iris.settings.performance.placeHistoryLimit) - { - while(placeHistory.size() > Iris.settings.performance.placeHistoryLimit) - { - placeHistory.remove(0); - } - } - } - } - }; - - if(Iris.settings.performance.objectMode.equals(ObjectMode.QUICK_N_DIRTY)) - { - new S(20) - { - @Override - public void run() - { - rx.run(); - } - }; - } - - else - { - rx.run(); - } - } - } - } - - if(placer != null && cl.flip()) - { - placer.flush(); - } - } - - public void populateParallax(int cx, int cz, Random random) - { - try - { - if(g.isDisposed()) - { - placeHistory.clear(); - return; - } - - ParallaxCache cache = new ParallaxCache(g); - KSet hits = new KSet<>(); - - for(int i = 0; i < Iris.settings.performance.decorationAccuracy; i++) - { - int x = (cx << 4) + random.nextInt(16); - int z = (cz << 4) + random.nextInt(16); - IrisBiome biome = cache.getBiome(x, z); - - if(hits.contains(biome)) - { - continue; - } - - KMap objects = populationCache.get(biome); - - if(objects == null) - { - continue; - } - - hits.add(biome); - populateParallax(cx, cz, random, biome, cache); - } - } - - catch(Throwable e) - { - e.printStackTrace(); - } - } - - private void populateParallax(int cx, int cz, Random random, IrisBiome biome, ParallaxCache cache) - { - for(GenObjectGroup i : orderCache.get(biome)) - { - if(biome.getSchematicGroups().get(i.getName()) == null) - { - L.w(C.YELLOW + "Cannot find chance for " + C.RED + i.getName() + C.YELLOW + " in Biome " + C.RED + biome.getName()); - continue; - } - - for(int j = 0; j < getTries(biome.getSchematicGroups().get(i.getName())); j++) - { - if(M.r(Iris.settings.gen.objectDensity)) - { - if(i.getSchematics().isEmpty()) - { - continue; - } - - GenObject go = i.getSchematics().get(random.nextInt(i.getSchematics().size())); - int x = (cx << 4) + random.nextInt(16); - int z = (cz << 4) + random.nextInt(16); - - if(i.getWorldChance() >= 0D) - { - int rngx = (int) Math.floor(x / (double) (i.getWorldRadius() == 0 ? 32 : i.getWorldRadius())); - int rngz = (int) Math.floor(z / (double) (i.getWorldRadius() == 0 ? 32 : i.getWorldRadius())); - - if(new RNG(new SMCAVector(rngx, rngz).hashCode()).nextDouble() < i.getWorldChance()) - { - if(Iris.settings.performance.verbose) - { - L.w(C.WHITE + "Object " + C.YELLOW + i.getName() + "/*" + C.WHITE + " failed to place due to a world chance."); - } - - break; - } - } - - int by = cache.getHeight(x, z); - MB mb = cache.get(x, by, z); - - if(!Iris.settings.performance.noObjectFail) - { - if(!mb.material.isSolid() || !biome.isSurface(mb.material)) - { - if(Iris.settings.performance.verbose) - { - L.w(C.WHITE + "Object " + C.YELLOW + i.getName() + "/*" + C.WHITE + " failed to place in " + C.YELLOW + mb.material.toString().toLowerCase() + C.WHITE + " at " + C.YELLOW + F.f(x) + " " + F.f(by) + " " + F.f(z)); - } - - return; - } - } - - placer = new AtomicParallaxPlacer(g, cache); - Location start = go.place(x, by, z, placer); - - if(start != null) - { - g.hitObject(); - if(Iris.settings.performance.verbose) - { - L.v(C.GRAY + "Placed " + C.DARK_GREEN + i.getName() + C.WHITE + "/" + C.DARK_GREEN + go.getName() + C.GRAY + " at " + C.DARK_GREEN + F.f(start.getBlockX()) + " " + F.f(start.getBlockY()) + " " + F.f(start.getBlockZ())); - } - - if(Iris.settings.performance.debugMode) - { - placeHistory.add(new PlacedObject(start.getBlockX(), start.getBlockY(), start.getBlockZ(), i.getName() + ":" + go.getName())); - - if(placeHistory.size() > Iris.settings.performance.placeHistoryLimit) - { - while(placeHistory.size() > Iris.settings.performance.placeHistoryLimit) - { - placeHistory.remove(0); - } - } - } - } - } - } - } - - if(placer != null && cl.flip()) - { - placer.flush(); - } - } - - public int getTries(double chance) - { - if(chance <= 0) - { - return 0; - } - - if(Math.floor(chance) == chance) - { - return (int) chance; - } - - int floor = (int) Math.floor(chance); - - if(chance - floor > 0 && M.r(chance - floor)) - { - floor++; - } - - return floor; - } - - public KList getHistory() - { - return placeHistory; - } - - public void dispose() - { - - } - - public PlacedObject randomObject(String string) - { - KList v = new KList<>(); - - for(PlacedObject i : placeHistory) - { - if(i.getF().toLowerCase().replaceAll("\\Q:\\E", "/").startsWith(string.toLowerCase())) - { - v.add(i); - } - } - - if(v.isEmpty()) - { - return null; - } - - return v.getRandom(); - } -} diff --git a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectGroup.java b/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectGroup.java deleted file mode 100644 index f2b1dc40a..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectGroup.java +++ /dev/null @@ -1,387 +0,0 @@ -package ninja.bytecode.iris.generator.genobject; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.IOException; -import java.util.function.Consumer; - -import net.md_5.bungee.api.ChatColor; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.util.Direction; -import ninja.bytecode.shuriken.collections.KList; -import ninja.bytecode.shuriken.format.Form; -import ninja.bytecode.shuriken.io.IO; -import ninja.bytecode.shuriken.logging.L; - -public class GenObjectGroup -{ - private KList schematics; - private KList osSchematics; - private KList pxSchematics; - private KList flags; - private String name; - private int priority; - private double worldChance; - private int worldRad; - - public GenObjectGroup(String name) - { - this.schematics = new KList<>(); - this.flags = new KList<>(); - this.name = name; - priority = Integer.MIN_VALUE; - worldChance = Integer.MIN_VALUE; - worldRad = 32; - } - - public void read(DataInputStream din) throws IOException - { - flags.clear(); - schematics.clear(); - name = din.readUTF(); - int fl = din.readInt(); - int sc = din.readInt(); - - for(int i = 0; i < fl; i++) - { - flags.add(din.readUTF()); - } - - for(int i = 0; i < sc; i++) - { - GenObject g = new GenObject(0, 0, 0); - g.readDirect(din); - schematics.add(g); - } - } - - public void write(DataOutputStream dos, Consumer progress) throws IOException - { - dos.writeUTF(name); - dos.writeInt(flags.size()); - dos.writeInt(schematics.size()); - - for(String i : flags) - { - dos.writeUTF(i); - } - - int of = 0; - - if(progress != null) - { - progress.accept((double) of / (double) schematics.size()); - } - - for(GenObject i : schematics) - { - i.writeDirect(dos); - of++; - - if(progress != null) - { - progress.accept((double) of / (double) schematics.size()); - } - } - } - - public void applyLushFilter(double factor) - { - if(flags.contains("no lush")) - { - L.i(ChatColor.DARK_GREEN + "Skipping Lush Filter for " + ChatColor.GRAY + getName()); - return; - } - - L.i(ChatColor.GREEN + "Applying Lush Filter to " + ChatColor.WHITE + getName()); - - for(GenObject i : schematics) - { - i.applyLushFilter(factor); - } - } - - public void applySnowFilter(int factor) - { - if(flags.contains("no snow")) - { - L.i(ChatColor.DARK_AQUA + "Skipping Snow Filter for " + ChatColor.GRAY + getName()); - return; - } - - L.i(ChatColor.AQUA + "Applying Snow Filter to " + ChatColor.WHITE + getName()); - - for(GenObject i : schematics) - { - i.applySnowFilter(factor); - } - } - - public GenObjectGroup copy(String suffix) - { - GenObjectGroup gog = new GenObjectGroup(name + suffix); - gog.schematics = new KList<>(); - gog.flags = flags.copy(); - - for(GenObject i : schematics) - { - GenObject g = i.copy(); - g.setName(i.getName() + suffix); - gog.schematics.add(g); - } - - return gog; - } - - public String getName() - { - return name; - } - - public void setName(String name) - { - this.name = name; - } - - public KList getSchematics() - { - return schematics; - } - - public KList getPXSchematics() - { - if(pxSchematics == null) - { - pxSchematics = new KList<>(); - - for(GenObject i : schematics) - { - if(!i.isOversized()) - { - pxSchematics.add(i); - } - } - } - - return pxSchematics; - } - - public KList getOSSchematics() - { - if(osSchematics == null) - { - osSchematics = new KList<>(); - - for(GenObject i : schematics) - { - if(i.isOversized()) - { - osSchematics.add(i); - } - } - } - - return pxSchematics; - } - - public void setSchematics(KList schematics) - { - this.schematics = schematics; - } - - public KList getFlags() - { - return flags; - } - - public void setFlags(KList flags) - { - this.flags = flags; - } - - public int size() - { - return getSchematics().size(); - } - - public int getPiority() - { - if(priority == Integer.MIN_VALUE) - { - for(String i : flags) - { - if(i.startsWith("priority ")) - { - priority = Integer.valueOf(i.split("\\Q \\E")[1]); - break; - } - } - } - - return priority; - } - - public static GenObjectGroup load(String string) - { - File folder = Iris.pack().loadFolder(string); - - if(folder != null) - { - GenObjectGroup g = new GenObjectGroup(string); - - for(File i : folder.listFiles()) - { - if(i.getName().endsWith(".ifl")) - { - try - { - g.flags.add(IO.readAll(i).split("\\Q\n\\E")); - } - - catch(IOException e) - { - L.ex(e); - } - } - - if(i.getName().endsWith(".ish")) - { - try - { - GenObject s = GenObject.load(i); - g.getSchematics().add(s); - } - - catch(IOException e) - { - L.f("Cannot load Schematic: " + string + "/" + i.getName()); - L.ex(e); - } - } - } - - return g; - } - - return null; - } - - public void processVariants() - { - for(GenObject i : getSchematics()) - { - i.recalculateMountShift(); - - for(String j : flags) - { - i.computeFlag(j); - } - } - - if(!flags.contains("no rotation")) - { - KList inject = new KList<>(); - for(GenObject i : getSchematics()) - { - for(Direction j : new Direction[] {Direction.S, Direction.E, Direction.W}) - { - GenObject cp = i.copy(); - GenObject f = cp; - f.rotate(Direction.N, j); - f.recalculateMountShift(); - inject.add(f); - } - } - - getSchematics().add(inject); - } - - L.i(ChatColor.LIGHT_PURPLE + "Processed " + ChatColor.WHITE + Form.f(schematics.size()) + ChatColor.LIGHT_PURPLE + " Schematics in " + ChatColor.WHITE + name); - } - - public void dispose() - { - for(GenObject i : schematics) - { - i.dispose(); - } - - schematics.clear(); - flags.clear(); - } - - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = prime * result + ((flags == null) ? 0 : flags.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + priority; - return result; - } - - @Override - public boolean equals(Object obj) - { - if(this == obj) - return true; - if(obj == null) - return false; - if(getClass() != obj.getClass()) - return false; - GenObjectGroup other = (GenObjectGroup) obj; - if(flags == null) - { - if(other.flags != null) - return false; - } - else if(!flags.equals(other.flags)) - return false; - if(name == null) - { - if(other.name != null) - return false; - } - else if(!name.equals(other.name)) - return false; - if(priority != other.priority) - return false; - - return true; - } - - public double getWorldChance() - { - if(worldChance == Integer.MIN_VALUE) - { - for(String i : flags) - { - if(i.startsWith("world chance ")) - { - worldChance = Double.valueOf(i.split("\\Q \\E")[2]); - } - } - } - - return worldChance; - } - - public double getWorldRadius() - { - if(worldRad == Integer.MIN_VALUE) - { - for(String i : flags) - { - if(i.startsWith("world radius ")) - { - worldRad = Integer.valueOf(i.split("\\Q \\E")[2]); - } - } - } - - return worldRad; - } - -} diff --git a/src/main/java/ninja/bytecode/iris/generator/genobject/PlacedObject.java b/src/main/java/ninja/bytecode/iris/generator/genobject/PlacedObject.java deleted file mode 100644 index 62cd4b50f..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/genobject/PlacedObject.java +++ /dev/null @@ -1,95 +0,0 @@ -package ninja.bytecode.iris.generator.genobject; - -public class PlacedObject -{ - private int x; - private int y; - private int z; - private String f; - - public PlacedObject(int x, int y, int z, String f) - { - this.x = x; - this.y = y; - this.z = z; - this.f = f; - } - - public int getX() - { - return x; - } - - public void setX(int x) - { - this.x = x; - } - - public int getY() - { - return y; - } - - public void setY(int y) - { - this.y = y; - } - - public int getZ() - { - return z; - } - - public void setZ(int z) - { - this.z = z; - } - - public String getF() - { - return f; - } - - public void setF(String f) - { - this.f = f; - } - - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = prime * result + ((f == null) ? 0 : f.hashCode()); - result = prime * result + x; - result = prime * result + y; - result = prime * result + z; - return result; - } - - @Override - public boolean equals(Object obj) - { - if(this == obj) - return true; - if(obj == null) - return false; - if(getClass() != obj.getClass()) - return false; - PlacedObject other = (PlacedObject) obj; - if(f == null) - { - if(other.f != null) - return false; - } - else if(!f.equals(other.f)) - return false; - if(x != other.x) - return false; - if(y != other.y) - return false; - if(z != other.z) - return false; - return true; - } -} diff --git a/src/main/java/ninja/bytecode/iris/generator/layer/BiomeNoiseGenerator.java b/src/main/java/ninja/bytecode/iris/generator/layer/BiomeNoiseGenerator.java deleted file mode 100644 index 125617acd..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/layer/BiomeNoiseGenerator.java +++ /dev/null @@ -1,34 +0,0 @@ -package ninja.bytecode.iris.generator.layer; - -import ninja.bytecode.iris.pack.IrisBiome; -import ninja.bytecode.shuriken.math.CNG; -import ninja.bytecode.shuriken.math.RNG; - -public class BiomeNoiseGenerator -{ - protected IrisBiome biome; - protected CNG gen; - private double block = 1D / 255D; - - public BiomeNoiseGenerator(RNG rng, IrisBiome biome) - { - this.biome = biome; - //@builder - gen = new CNG(rng.nextParallelRNG(31289 - biome.getName().length() * biome.getRealBiome().ordinal()), 1D, 1) - .scale(0.0025 * biome.getGenScale()) - .fractureWith(new CNG(rng.nextParallelRNG(2922 * biome.getName().length() - biome.getRealBiome().ordinal()), 1D, 1) - .scale(0.0075 * biome.getGenSwirlScale()), 20D * biome.getGenSwirl()); - //@done - } - - public double getHeight(double x, double z) - { - if(biome.getGenAmplifier() == 0) - { - return 0; - } - - double r = block * 52; - return (gen.noise(x, z) * biome.getGenAmplifier() * r); - } -} diff --git a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerBiome.java b/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerBiome.java deleted file mode 100644 index f2952cc0e..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerBiome.java +++ /dev/null @@ -1,217 +0,0 @@ -package ninja.bytecode.iris.generator.layer; - -import java.util.Random; -import java.util.function.Function; - -import org.bukkit.World; - -import mortar.util.text.C; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.generator.IrisGenerator; -import ninja.bytecode.iris.pack.IrisBiome; -import ninja.bytecode.iris.pack.IrisRegion; -import ninja.bytecode.iris.util.BiomeLayer; -import ninja.bytecode.iris.util.Borders; -import ninja.bytecode.iris.util.GenLayer; -import ninja.bytecode.iris.util.PolygonGenerator; -import ninja.bytecode.shuriken.collections.KList; -import ninja.bytecode.shuriken.collections.KMap; -import ninja.bytecode.shuriken.logging.L; -import ninja.bytecode.shuriken.math.CNG; -import ninja.bytecode.shuriken.math.RNG; - -public class GenLayerBiome extends GenLayer -{ - private KMap regions; - private Function factory; - private CNG fracture; - private CNG fuzz; - private PolygonGenerator channel; - private PolygonGenerator ocean; - private BiomeLayer master; - - public GenLayerBiome(IrisGenerator iris, World world, Random random, RNG rng, KList biomes) - { - super(iris, world, random, rng); - //@builder - channel = new PolygonGenerator(rng.nextParallelRNG(-12), 2, 0.0005, 1, (g)->g.fractureWith(new CNG(rng.nextParallelRNG(34), 1D, 2) - .scale(0.01), 30)); - ocean = new PolygonGenerator(rng.nextParallelRNG(-11), 6, 0.005, 1, (g)->g.fractureWith(new CNG(rng.nextParallelRNG(34), 1D, 2) - .scale(0.01), 150)); - fuzz = new CNG(rng.nextParallelRNG(9112), 1D * 12 * Iris.settings.gen.biomeEdgeFuzzScale, 1).scale(6.5); - fracture = new CNG(rng.nextParallelRNG(28), 1D, 4).scale(0.0021 * Iris.settings.gen.biomeEdgeScrambleScale) - .fractureWith(new CNG(rng.nextParallelRNG(34), 1D, 2) - .scale(0.01), 12250); - factory = (g) -> g.fractureWith(new CNG(rng.nextParallelRNG(29), 1D, 3) - .scale(0.005 * Iris.settings.gen.biomeScale), 1024D / Iris.settings.gen.biomeScale) - .fractureWith(new CNG(rng.nextParallelRNG(1212), 1D, 2) - .scale(0.04) - .fractureWith(new CNG(rng.nextParallelRNG(1216), 1D, 3).scale(0.0004), 266), 66); - //@done - regions = new KMap<>(); - - for(IrisBiome i : biomes) - { - if(i.getRegionID().equals("default")) - { - continue; - } - - if(!regions.containsKey(i.getRegionID())) - { - regions.put(i.getRegionID(), new IrisRegion(i.getRegionID())); - } - - regions.get(i.getRegionID()).getBiomes().add(i); - } - - for(IrisRegion i : regions.values()) - { - i.load(); - } - - int m = 0; - - for(IrisBiome i : iris.getDimension().getBiomes()) - { - i.seal(iris.getRTerrain().nextParallelRNG(3922 - m++)); - } - - master = BiomeLayer.compile(iris, 0.082 * Iris.settings.gen.biomeScale * 0.189, 1, factory); - - if(Iris.settings.performance.verbose) - { - master.print(2); - } - } - - public IrisBiome getBiome(double wxx, double wzx) - { - return getBiome(wxx, wzx, false); - } - - public boolean isNearAquatic(int wxx, int wzx) - { - double wx = Math.round((double) wxx * (Iris.settings.gen.horizontalZoom / 1.90476190476)) * Iris.settings.gen.biomeScale; - double wz = Math.round((double) wzx * (Iris.settings.gen.horizontalZoom / 1.90476190476)) * Iris.settings.gen.biomeScale; - double xf = wx + ((fracture.noise(wx, wz) / 2D) * 200D * Iris.settings.gen.biomeEdgeScrambleRange); - double zf = wz - ((fracture.noise(wz, wx) / 2D) * 200D * Iris.settings.gen.biomeEdgeScrambleRange); - double x = xf - fuzz.noise(wx, wz); - double z = zf + fuzz.noise(wz, wx); - - if(ocean.getIndex(x, z) == 0) - { - return true; - } - - if(channel.hasBorder(3, 44, xf, zf)) - { - return true; - } - - if(Borders.isBorderWithin(x, z, 3, 24D, (x + z) / 100D, (xx, zz) -> ocean.getIndex(xx, zz))) - { - return true; - } - - if(ocean.getClosestNeighbor(x, z) > 0.2) - { - return true; - } - - if(channel.getClosestNeighbor(x, z) > 0.2) - { - return true; - } - - if(channel.hasBorder(3, 7, xf, zf) || channel.hasBorder(3, 3, xf, zf)) - { - return true; - } - - return false; - } - - public IrisBiome getBiome(double wxx, double wzx, boolean real) - { - double wx = Math.round((double) wxx * (Iris.settings.gen.horizontalZoom / 1.90476190476)) * Iris.settings.gen.biomeScale; - double wz = Math.round((double) wzx * (Iris.settings.gen.horizontalZoom / 1.90476190476)) * Iris.settings.gen.biomeScale; - double xf = wx + ((fracture.noise(wx, wz) / 2D) * 200D * Iris.settings.gen.biomeEdgeScrambleRange); - double zf = wz - ((fracture.noise(wz, wx) / 2D) * 200D * Iris.settings.gen.biomeEdgeScrambleRange); - double x = xf - fuzz.noise(wx, wz); - double z = zf + fuzz.noise(wz, wx); - IrisBiome biome = master.computeBiome(x, z); - - if(real) - { - return biome; - } - - if(ocean.getIndex(x, z) == 0) - { - IrisRegion region = getRegion(biome.getRegionID()); - - if(region == null) - { - L.f(C.YELLOW + "Cannot find Region " + C.RED + biome.getRegionID()); - return biome; - } - - if(!Borders.isBorderWithin(x, z, 7, 45, (x / 10D) + (z / 10D), (a, b) -> ocean.getIndex(a, b))) - { - if(region.getDeepOcean() == null) - { - L.f(C.YELLOW + "Cannot find Deep Ocean in Region" + C.RED + biome.getRegionID()); - return biome; - } - - return getRegion(biome.getRegionID()).getDeepOcean(); - } - - if(region.getOcean() == null) - { - L.f(C.YELLOW + "Cannot find Ocean in Region" + C.RED + biome.getRegionID()); - return biome; - } - - return getRegion(biome.getRegionID()).getOcean(); - } - - if(channel.hasBorder(3, 44, xf, zf)) - { - IrisRegion region = getRegion(biome.getRegionID()); - - if(region == null) - { - L.f(C.YELLOW + "Cannot find Region " + C.RED + biome.getRegionID()); - return biome; - } - - if(region.getChannel() == null) - { - L.f(C.YELLOW + "Cannot find Channel in Region" + C.RED + biome.getRegionID()); - return biome; - } - - return getRegion(biome.getRegionID()).getChannel(); - } - - return biome; - } - - @Override - public double generateLayer(double noise, double dx, double dz) - { - return noise; - } - - public IrisRegion getRegion(String name) - { - return regions.get(name); - } - - public void compileInfo(BiomeLayer l) - { - l.compileChildren(0.082 * Iris.settings.gen.biomeScale * 0.189, 1, factory, true); - } -} diff --git a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCarving.java b/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCarving.java deleted file mode 100644 index fca30aadc..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCarving.java +++ /dev/null @@ -1,64 +0,0 @@ -package ninja.bytecode.iris.generator.layer; - -import java.util.Random; - -import org.bukkit.World; - -import ninja.bytecode.iris.generator.IrisGenerator; -import ninja.bytecode.iris.generator.atomics.AtomicChunkData; -import ninja.bytecode.iris.util.ChunkPlan; -import ninja.bytecode.iris.util.GenLayer; -import ninja.bytecode.iris.util.IrisInterpolation; -import ninja.bytecode.shuriken.math.CNG; -import ninja.bytecode.shuriken.math.M; -import ninja.bytecode.shuriken.math.RNG; - -public class GenLayerCarving extends GenLayer -{ - private CNG scram; - private CNG cng; - private CNG cngh; - private CNG cngo; - - public GenLayerCarving(IrisGenerator iris, World world, Random random, RNG rng) - { - //@builder - super(iris, world, random, rng); - cng = new CNG(rng.nextParallelRNG(2339234), 1D, 1).scale(0.02); - cngh = new CNG(rng.nextParallelRNG(1939234), 1D, 1).scale(0.027); - cngo = new CNG(rng.nextParallelRNG(8939234), 1D, 1).scale(0.002); - scram = new CNG(rng.nextParallelRNG(2639634), 1D, 1).scale(0.15); - - //@done - } - - @Override - public double generateLayer(double gnoise, double dx, double dz) - { - return gnoise; - } - - public boolean isCarved(double vwxxf, double vwzxf, int x, int z, double hl, AtomicChunkData data, ChunkPlan plan) - { - double a = cngh.noise(vwxxf, vwzxf); - double hmax = 99 + (a * 30); - double hmin = 68 + (a * 30); - - if(hl > hmax || hl < hmin) - { - return false; - } - double wxxf = (scram.noise(vwxxf, vwzxf) * 12) - vwzxf; - double wzxf = (scram.noise(vwzxf, vwxxf) * 12) + vwxxf; - - double downrange = M.lerpInverse(hmin, hmax, hl); - double opacity = IrisInterpolation.sinCenter(downrange); - - if(cng.noise(wxxf, wzxf, hl / 3) < (opacity / 1.4D) * cngo.noise(wxxf, wzxf)) - { - return true; - } - - return false; - } -} diff --git a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCaves.java b/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCaves.java deleted file mode 100644 index ca23f6d36..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCaves.java +++ /dev/null @@ -1,120 +0,0 @@ -package ninja.bytecode.iris.generator.layer; - -import java.util.Random; - -import org.bukkit.Material; -import org.bukkit.World; - -import ninja.bytecode.iris.generator.IrisGenerator; -import ninja.bytecode.iris.generator.atomics.AtomicChunkData; -import ninja.bytecode.iris.util.Borders; -import ninja.bytecode.iris.util.ChunkPlan; -import ninja.bytecode.iris.util.GenLayer; -import ninja.bytecode.iris.util.PolygonGenerator; -import ninja.bytecode.shuriken.bench.PrecisionStopwatch; -import ninja.bytecode.shuriken.math.CNG; -import ninja.bytecode.shuriken.math.RNG; - -public class GenLayerCaves extends GenLayer -{ - private PolygonGenerator g; - private CNG gincline; - private CNG scram; - - public GenLayerCaves(IrisGenerator iris, World world, Random random, RNG rng) - { - //@builder - super(iris, world, random, rng); - g = new PolygonGenerator(rng.nextParallelRNG(1111), 3, 0.024, 8, (c) -> c); - gincline = new CNG(rng.nextParallelRNG(1112), 1D, 3).scale(0.00652); - scram = new CNG(rng.nextParallelRNG(2639634), 1D, 1).scale(0.15); - //@done - } - - @Override - public double generateLayer(double gnoise, double dx, double dz) - { - return gnoise; - } - - public void genCaves(double vwxxf, double vwzxf, int x, int z, AtomicChunkData data, ChunkPlan plan) - { - PrecisionStopwatch s = PrecisionStopwatch.start(); - double itr = 2; - double level = 8; - double incline = 187; - double baseWidth = 11; - double drop = 41; - double wxxf = (scram.noise(vwxxf, vwzxf) * 6) - vwzxf; - double wzxf = (scram.noise(vwzxf, vwxxf) * 6) + vwxxf; - - for(double m = 1; m <= itr; m += 0.45) - { - double w = baseWidth / m; - - if(w < 5) - { - break; - } - - int lowest = 325; - - double n = incline * gincline.noise((wxxf + (m * 10000)), (wzxf - (m * 10000))); - for(double i = 1; i <= w / 3D; i++) - { - if(Borders.isBorderWithin((wxxf + (m * 10000)), (wzxf - (m * 10000)), 5, w / 2D / i, (wxxf / 3D) + (wzxf / 3D), (xx, zz) -> g.getIndex(xx, zz))) - { - int h = (int) ((level + n) - drop); - if(dig(x, (int) (h + i), z, data) && h + i < lowest) - { - lowest = (int) (h + i); - } - - if(dig(x, (int) (h - i), z, data) && h - i < lowest) - { - lowest = (int) (h - i); - } - - if(i == 1) - { - if(dig(x, (int) (h), z, data) && h < lowest) - { - lowest = (int) (h); - } - } - } - } - } - - iris.getMetrics().stop("caves:ms:x256:/chunk:..", s); - } - - public boolean dig(int x, int y, int z, AtomicChunkData data) - { - Material a = data.getType(x, y, z); - Material b = data.getType(x, y, z + 1); - Material c = data.getType(x, y + 1, z); - Material d = data.getType(x + 1, y, z); - Material e = data.getType(x, y, z - 1); - Material f = data.getType(x, y - 1, z); - Material g = data.getType(x - 1, y, z); - - if(can(a) && cann(b) && cann(c) && cann(d) && cann(e) && cann(f) && cann(g)) - { - data.setBlock(x, y, z, Material.AIR); - return true; - } - - return false; - } - - public boolean cann(Material m) - { - return m.isSolid() || m.equals(Material.AIR) && !m.equals(Material.BEDROCK); - } - - public boolean can(Material m) - { - return m.isSolid() && !m.equals(Material.BEDROCK); - } -} diff --git a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCliffs.java b/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCliffs.java deleted file mode 100644 index 1dab5f192..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCliffs.java +++ /dev/null @@ -1,67 +0,0 @@ -package ninja.bytecode.iris.generator.layer; - -import java.util.Random; - -import org.bukkit.World; - -import ninja.bytecode.iris.generator.IrisGenerator; -import ninja.bytecode.iris.util.GenLayer; -import ninja.bytecode.shuriken.math.CNG; -import ninja.bytecode.shuriken.math.RNG; - -public class GenLayerCliffs extends GenLayer -{ - private double block; - private CNG gen; - private CNG sh; - private CNG ch; - - public GenLayerCliffs(IrisGenerator iris, World world, Random random, RNG rng) - { - //@builder - super(iris, world, random, rng); - block = 1D / 255D; - gen = new CNG(rng.nextParallelRNG(128), 1D, 4).scale(0.02); - sh = new CNG(rng.nextParallelRNG(127), 1D, 1).scale(0.00367); - ch = new CNG(rng.nextParallelRNG(127), 1D, 1).scale(0.00413); - //@done - } - - @Override - public double generateLayer(double gnoise, double dx, double dz) - { - return generateLayer(gnoise, dx, dz, 1D, 0.37D); - } - - public double generateLayer(double gnoise, double dx, double dz, double cliffs, double chance) - { - if(gnoise < block * 66) - { - return gnoise; - } - - double shift = 10.25 + (sh.noise(dx, dz) * 2.25) * cliffs; - double hits = 183D / shift; - double n = gnoise; - - for(int i = (int) hits; i > 0; i--) - { - if(ch.noise(dx + (i * -1000), dz + (i * 1000)) >= chance) - { - continue; - } - - double var = 12.2 * block; - double varCombined = 15.45 * block; - double sep = (shift / 1.8D) * block; - double height = (67 + (i * shift)) * block; - double sh = ((gen.noise(dx + dz, dz - dx) - 0.5D) * 2D) * varCombined; - double shv = ((gen.noise(dz + dx, dx - dz) - 0.5D) * 2D) * varCombined; - double lo = (gen.noise(dx + (i * -1000), dz + (i * 1000)) * var) + height + sh; - double hi = (gen.noise(dz + (i * 1000), dx + (i * -1000)) * var) + height + sep + shv; - n = n > lo && n < hi ? lo : n; - } - - return n; - } -} diff --git a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerLayeredNoise.java b/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerLayeredNoise.java deleted file mode 100644 index 089cc5aa1..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerLayeredNoise.java +++ /dev/null @@ -1,44 +0,0 @@ -package ninja.bytecode.iris.generator.layer; - -import java.util.Random; - -import org.bukkit.World; - -import ninja.bytecode.iris.generator.IrisGenerator; -import ninja.bytecode.iris.util.GenLayer; -import ninja.bytecode.shuriken.math.CNG; -import ninja.bytecode.shuriken.math.RNG; - -public class GenLayerLayeredNoise extends GenLayer -{ - private CNG gen; - private CNG fract; - - public GenLayerLayeredNoise(IrisGenerator iris, World world, Random random, RNG rng) - { - //@builder - super(iris, world, random, rng); - fract = new CNG(rng.nextParallelRNG(16), 1D, 9).scale(0.0181); - gen = new CNG(rng.nextParallelRNG(17), 0.19D, 8) - .scale(0.012) - .amp(0.5) - .freq(1.1) - .fractureWith(new CNG(rng.nextParallelRNG(18), 1, 5) - .scale(0.018) - .child(new CNG(rng.nextParallelRNG(19), 0.745, 2) - .scale(0.1)) - .fractureWith(new CNG(rng.nextParallelRNG(20), 1, 3) - .scale(0.15), 24), 44); - } - - public double getHeight(double x, double z) - { - return 0.65* gen.noise(x, z); - } - - @Override - public double generateLayer(double gnoise, double dx, double dz) - { - return 0.65 * gen.noise(gnoise, dx + (fract.noise(gnoise, dx, dz) * 333), dz - (fract.noise(dz, dx, gnoise) * 333)); - } -} diff --git a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerOres.java b/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerOres.java deleted file mode 100644 index 9abb49421..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerOres.java +++ /dev/null @@ -1,145 +0,0 @@ -package ninja.bytecode.iris.generator.layer; - -import java.util.Random; - -import org.bukkit.Material; -import org.bukkit.World; - -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.Settings.OreSettings; -import ninja.bytecode.iris.generator.IrisGenerator; -import ninja.bytecode.iris.generator.atomics.AtomicChunkData; -import ninja.bytecode.iris.util.ChunkPlan; -import ninja.bytecode.iris.util.GenLayer; -import ninja.bytecode.iris.util.IrisInterpolation; -import ninja.bytecode.shuriken.bench.PrecisionStopwatch; -import ninja.bytecode.shuriken.math.CNG; -import ninja.bytecode.shuriken.math.M; -import ninja.bytecode.shuriken.math.RNG; - -public class GenLayerOres extends GenLayer -{ - private CNG ore; - - public GenLayerOres(IrisGenerator iris, World world, Random random, RNG rng) - { - //@builder - super(iris, world, random, rng); - ore = new CNG(rng.nextParallelRNG(12944), 1D, 1).scale(0.1); - //@done - } - - @Override - public double generateLayer(double gnoise, double dx, double dz) - { - return gnoise; - } - - public void genOres(double xxf, double zzf, int x, int z, int h, AtomicChunkData data, ChunkPlan plan) - { - PrecisionStopwatch s = PrecisionStopwatch.start(); - OreSettings o = Iris.settings.ore; - - for(int i = 0; i < h; i++) - { - if(i >= o.ironMinHeight && i <= o.ironMaxHeight && - ore.noise(xxf + 64, i, zzf - 64) < IrisInterpolation.lerpCenterSinBezier( - o.ironMinDispersion, - Iris.settings.ore.ironMaxDispersion, - M.lerpInverse(o.ironMinHeight, o.ironMaxHeight, i))) - { - if(!can(data.getType(x, i, z))) - { - continue; - } - - data.setBlock(x, i, z, Material.IRON_ORE); - } - - if(i >= o.coalMinHeight && i <= o.coalMaxHeight && - ore.noise(xxf + 128, i, zzf - 128) < IrisInterpolation.lerpCenterSinBezier( - o.coalMinDispersion, - Iris.settings.ore.coalMaxDispersion, - M.lerpInverse(o.coalMinHeight, o.coalMaxHeight, i))) - { - if(!can(data.getType(x, i, z))) - { - continue; - } - data.setBlock(x, i, z, Material.COAL_ORE); - } - - if(i >= o.goldMinHeight && i <= o.goldMaxHeight && - ore.noise(xxf + 64, i, zzf - 128) < IrisInterpolation.lerpCenterSinBezier( - o.goldMinDispersion, - Iris.settings.ore.goldMaxDispersion, - M.lerpInverse(o.goldMinHeight, o.goldMaxHeight, i))) - { - if(!can(data.getType(x, i, z))) - { - continue; - } - data.setBlock(x, i, z, Material.GOLD_ORE); - } - - if(i >= o.redstoneMinHeight && i <= o.redstoneMaxHeight && - ore.noise(xxf + 128, i, zzf - 64) < IrisInterpolation.lerpCenterSinBezier( - o.redstoneMinDispersion, - Iris.settings.ore.redstoneMaxDispersion, - M.lerpInverse(o.redstoneMinHeight, o.redstoneMaxHeight, i))) - { - if(!can(data.getType(x, i, z))) - { - continue; - } - data.setBlock(x, i, z, Material.REDSTONE_ORE); - } - - if(i >= o.lapisMinHeight && i <= o.lapisMaxHeight && - ore.noise(xxf + 256, i, zzf - 64) < IrisInterpolation.lerpCenterSinBezier( - o.lapisMinDispersion, - Iris.settings.ore.lapisMaxDispersion, - M.lerpInverse(o.lapisMinHeight, o.lapisMaxHeight, i))) - { - if(!can(data.getType(x, i, z))) - { - continue; - } - data.setBlock(x, i, z, Material.LAPIS_ORE); - } - - if(i >= o.diamondMinHeight && i <= o.diamondMaxHeight && - ore.noise(xxf + 64, i, zzf - 256) < IrisInterpolation.lerpCenterSinBezier( - o.diamondMinDispersion, - Iris.settings.ore.diamondMaxDispersion, - M.lerpInverse(o.diamondMinHeight, o.diamondMaxHeight, i))) - { - if(!can(data.getType(x, i, z))) - { - continue; - } - data.setBlock(x, i, z, Material.DIAMOND_ORE); - } - - if(i >= o.emeraldMinHeight && i <= o.emeraldMaxHeight && - ore.noise(xxf + 128, i, zzf - 256) < IrisInterpolation.lerpCenterSinBezier( - o.emeraldMinDispersion, - Iris.settings.ore.emeraldMaxDispersion, - M.lerpInverse(o.emeraldMinHeight, o.emeraldMaxHeight, i))) - { - if(!can(data.getType(x, i, z))) - { - continue; - } - data.setBlock(x, i, z, Material.EMERALD_ORE); - } - } - - iris.getMetrics().stop("ores:ms:x256:/chunk:..", s); - } - - public boolean can(Material m) - { - return m.equals(Material.STONE) || m.name().endsWith("_ORE"); - } -} diff --git a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerSnow.java b/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerSnow.java deleted file mode 100644 index 10bf2dd9f..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerSnow.java +++ /dev/null @@ -1,42 +0,0 @@ -package ninja.bytecode.iris.generator.layer; - -import java.util.Random; - -import org.bukkit.World; - -import ninja.bytecode.iris.generator.IrisGenerator; -import ninja.bytecode.iris.util.GenLayer; -import ninja.bytecode.shuriken.math.CNG; -import ninja.bytecode.shuriken.math.RNG; - -public class GenLayerSnow extends GenLayer -{ - private CNG gen; - - public GenLayerSnow(IrisGenerator iris, World world, Random random, RNG rng) - { - //@builder - super(iris, world, random, rng); - gen = new CNG(rng.nextParallelRNG(117), 1D, 1) - .scale(0.059) - .amp(0.5) - .freq(1.1) - .fractureWith(new CNG(rng.nextParallelRNG(18), 1, 6) - .scale(0.018) - .child(new CNG(rng.nextParallelRNG(19), 0.745, 2) - .scale(0.1)) - .fractureWith(new CNG(rng.nextParallelRNG(20), 1, 3) - .scale(0.15), 24), 44); - } - - public double getHeight(double x, double z) - { - return gen.noise(x, z); - } - - @Override - public double generateLayer(double gnoise, double dx, double dz) - { - return getHeight(dx, dz); - } -} diff --git a/src/main/java/ninja/bytecode/iris/generator/parallax/ParallaxAnchor.java b/src/main/java/ninja/bytecode/iris/generator/parallax/ParallaxAnchor.java deleted file mode 100644 index b56f51c75..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/parallax/ParallaxAnchor.java +++ /dev/null @@ -1,45 +0,0 @@ -package ninja.bytecode.iris.generator.parallax; - -import ninja.bytecode.iris.generator.atomics.AtomicChunkData; -import ninja.bytecode.iris.pack.IrisBiome; - -public class ParallaxAnchor -{ - private final int height; - private final int water; - private final IrisBiome biome; - private final AtomicChunkData data; - - public ParallaxAnchor(int height, int water, IrisBiome biome, AtomicChunkData data) - { - this.height = height; - this.water = water; - this.biome = biome; - this.data = data; - } - - public AtomicChunkData getData() - { - return data; - } - - public int getWater() - { - return water; - } - - public int getHeight() - { - return height; - } - - public int getWaterHeight() - { - return water; - } - - public IrisBiome getBiome() - { - return biome; - } -} diff --git a/src/main/java/ninja/bytecode/iris/generator/parallax/ParallaxCache.java b/src/main/java/ninja/bytecode/iris/generator/parallax/ParallaxCache.java deleted file mode 100644 index cf9331bfc..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/parallax/ParallaxCache.java +++ /dev/null @@ -1,102 +0,0 @@ -package ninja.bytecode.iris.generator.parallax; - -import ninja.bytecode.iris.generator.IrisGenerator; -import ninja.bytecode.iris.generator.atomics.AtomicChunkData; -import ninja.bytecode.iris.pack.IrisBiome; -import ninja.bytecode.iris.util.ChunkPlan; -import ninja.bytecode.iris.util.MB; -import ninja.bytecode.iris.util.SMCAVector; -import ninja.bytecode.shuriken.collections.KMap; -import ninja.bytecode.shuriken.collections.KSet; - -public class ParallaxCache -{ - private KMap cachePlan; - private KMap cacheData; - private KSet contains; - private IrisGenerator gen; - - public ParallaxCache(IrisGenerator gen) - { - this.gen = gen; - cacheData = new KMap<>(); - cachePlan = new KMap<>(); - contains = new KSet<>(); - } - - public MB get(int x, int y, int z) - { - SMCAVector s = new SMCAVector(x, z); - SMCAVector c = new SMCAVector(x >> 4, z >> 4); - - if(contains.contains(s) && cacheData.containsKey(c) && cachePlan.containsKey(c) ) - { - return cacheData.get(c).getMB(x & 15, y, z & 15); - } - - createData(x, z, s, c); - - return cacheData.get(c).getMB(x & 15, y, z & 15); - } - - public IrisBiome getBiome(int x, int z) - { - SMCAVector s = new SMCAVector(x, z); - SMCAVector c = new SMCAVector(x >> 4, z >> 4); - - if(contains.contains(s) && cacheData.containsKey(c) && cachePlan.containsKey(c) ) - { - return cachePlan.get(c).getBiome(x & 15, z & 15); - } - - createData(x, z, s, c); - - return cachePlan.get(c).getBiome(x & 15, z & 15); - } - - public int getWaterHeight(int x, int z) - { - SMCAVector s = new SMCAVector(x, z); - SMCAVector c = new SMCAVector(x >> 4, z >> 4); - - if(contains.contains(s) && cacheData.containsKey(c) && cachePlan.containsKey(c) ) - { - return cachePlan.get(c).getRealWaterHeight(x & 15, z & 15); - } - - createData(x, z, s, c); - - return cachePlan.get(c).getRealWaterHeight(x & 15, z & 15); - } - - public int getHeight(int x, int z) - { - SMCAVector s = new SMCAVector(x, z); - SMCAVector c = new SMCAVector(x >> 4, z >> 4); - - if(contains.contains(s) && cacheData.containsKey(c) && cachePlan.containsKey(c) ) - { - return cachePlan.get(c).getRealHeight(x & 15, z & 15); - } - - createData(x, z, s, c); - - return cachePlan.get(c).getRealHeight(x & 15, z & 15); - } - - private void createData(int x, int z, SMCAVector s, SMCAVector c) - { - if(!cacheData.containsKey(c)) - { - cacheData.put(c, new AtomicChunkData(gen.getWorld())); - } - - if(!cachePlan.containsKey(c)) - { - cachePlan.put(c, new ChunkPlan()); - } - - gen.computeAnchor(x, z, cachePlan.get(c), cacheData.get(c)); - contains.add(s); - } -} diff --git a/src/main/java/ninja/bytecode/iris/generator/parallax/ParallaxWorldGenerator.java b/src/main/java/ninja/bytecode/iris/generator/parallax/ParallaxWorldGenerator.java deleted file mode 100644 index 8e266b133..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/parallax/ParallaxWorldGenerator.java +++ /dev/null @@ -1,194 +0,0 @@ -package ninja.bytecode.iris.generator.parallax; - -import java.util.Random; - -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.block.Biome; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.world.ChunkLoadEvent; -import org.bukkit.event.world.WorldSaveEvent; -import org.bukkit.event.world.WorldUnloadEvent; - -import mortar.api.nms.NMP; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.generator.IrisGenerator; -import ninja.bytecode.iris.generator.atomics.AtomicChunkData; -import ninja.bytecode.iris.util.ChunkPlan; -import ninja.bytecode.iris.util.IrisWorldData; -import ninja.bytecode.iris.util.ObjectMode; -import ninja.bytecode.iris.util.SChunkVector; -import ninja.bytecode.shuriken.bench.PrecisionStopwatch; -import ninja.bytecode.shuriken.execution.TaskExecutor.TaskGroup; -import ninja.bytecode.shuriken.math.RNG; - -public abstract class ParallaxWorldGenerator extends ParallelChunkGenerator implements Listener -{ - private World world; - private IrisWorldData data; - private RNG rMaster; - private AtomicChunkData buffer; - protected boolean saving; - - @Override - public final void init(World world, Random random) - { - this.world = world; - saving = true; - buffer = new AtomicChunkData(world); - this.data = new IrisWorldData(world); - this.rMaster = new RNG(world.getSeed() + 1); - onInit(world, rMaster.nextParallelRNG(1)); - Bukkit.getPluginManager().registerEvents(this, Iris.instance); - } - - public void disableSaving() - { - saving = false; - data.disableSaving(); - } - - public void enableSaving() - { - saving = true; - data.enableSaving(); - } - - @EventHandler - public void on(ChunkLoadEvent e) - { - if(Iris.settings.performance.objectMode.equals(ObjectMode.PARALLAX) && e.getWorld().equals(world)) - { - NMP.host.relight(e.getChunk()); - } - } - - @EventHandler - public void on(WorldUnloadEvent e) - { - if(e.getWorld().equals(world)) - { - getWorldData().dispose(); - onUnload(); - } - } - - @EventHandler - public void on(WorldSaveEvent e) - { - if(!saving) - { - return; - } - - if(e.getWorld().equals(world)) - { - getWorldData().saveAll(); - } - } - - public ParallaxAnchor computeAnchor(int wx, int wz, ChunkPlan heightBuffer, AtomicChunkData data) - { - onGenColumn(wx, wz, wx & 15, wz & 15, heightBuffer, data, false); - - return new ParallaxAnchor(heightBuffer.getRealHeight(wx & 15, wz & 15), heightBuffer.getRealWaterHeight(wx & 15, wz & 15), heightBuffer.getBiome(wx & 15, wz & 15), data); - } - - public ParallaxAnchor computeAnchor(int wx, int wz) - { - ChunkPlan heightBuffer = new ChunkPlan(); - onGenColumn(wx, wz, wx & 15, wz & 15, heightBuffer, buffer, false); - - return new ParallaxAnchor(heightBuffer.getRealHeight(wx & 15, wz & 15), heightBuffer.getRealWaterHeight(wx & 15, wz & 15), heightBuffer.getBiome(wx & 15, wz & 15), buffer); - } - - public void doGenParallax(int x, int z) - { - onGenParallax(x, z, getRMaster(x, z, -59328)); - getWorldData().getChunk(x, z); - } - - @Override - public final ChunkPlan initChunk(World world, int x, int z, Random random) - { - PrecisionStopwatch ps = PrecisionStopwatch.start(); - TaskGroup g = startWork(); - if(Iris.settings.performance.objectMode.equals(ObjectMode.PARALLAX)) - { - for(int ii = -(getParallaxSize().getX() / 2) - 1; ii < (((getParallaxSize().getX() / 2) + 1)); ii++) - { - int i = ii; - - for(int jj = -(getParallaxSize().getZ() / 2) - 1; jj < (((getParallaxSize().getZ() / 2) + 1)); jj++) - { - int j = jj; - int cx = x + i; - int cz = z + j; - - if(!getWorldData().exists(cx, cz)) - { - g.queue(() -> - { - onGenParallax(cx, cz, getRMaster(cx, cz, -59328)); - getWorldData().getChunk(cx, cz); - }); - } - } - } - - g.execute(); - } - - ((IrisGenerator) this).getMetrics().put("parallax:ms:/chunk", ps.getMillis()); - - return onInitChunk(world, x, z, random); - } - - @Override - public final void postChunk(World world, int x, int z, Random random, AtomicChunkData data, ChunkPlan plan) - { - onPostChunk(world, x, z, random, data, plan); - getWorldData().inject(x, z, data); - } - - @Override - public final Biome genColumn(int wx, int wz, int x, int z, ChunkPlan plan, AtomicChunkData data, boolean surface) - { - return onGenColumn(wx, wz, x, z, plan, data, surface); - } - - public World getWorld() - { - return world; - } - - public IrisWorldData getWorldData() - { - return data; - } - - public RNG getRMaster() - { - return rMaster; - } - - public RNG getRMaster(int x, int z, int signature) - { - return rMaster.nextParallelRNG((int) (signature + x * z + z + x * 2.12)); - } - - protected abstract void onUnload(); - - protected abstract SChunkVector getParallaxSize(); - - public abstract void onGenParallax(int x, int z, Random random); - - public abstract void onInit(World world, Random random); - - public abstract ChunkPlan onInitChunk(World world, int x, int z, Random random); - - public abstract Biome onGenColumn(int wx, int wz, int x, int z, ChunkPlan plan, AtomicChunkData data, boolean surfaceOnly); - - public abstract void onPostChunk(World world, int x, int z, Random random, AtomicChunkData data, ChunkPlan plan); -} diff --git a/src/main/java/ninja/bytecode/iris/generator/parallax/ParallelChunkGenerator.java b/src/main/java/ninja/bytecode/iris/generator/parallax/ParallelChunkGenerator.java deleted file mode 100644 index 27cee34f8..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/parallax/ParallelChunkGenerator.java +++ /dev/null @@ -1,191 +0,0 @@ -package ninja.bytecode.iris.generator.parallax; - -import java.util.Random; - -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Biome; -import org.bukkit.generator.ChunkGenerator; - -import mortar.util.text.C; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.generator.atomics.AtomicChunkData; -import ninja.bytecode.iris.util.ChunkPlan; -import ninja.bytecode.iris.util.ChunkSpliceListener; -import ninja.bytecode.shuriken.execution.TaskExecutor; -import ninja.bytecode.shuriken.execution.TaskExecutor.TaskGroup; -import ninja.bytecode.shuriken.execution.TaskExecutor.TaskResult; -import ninja.bytecode.shuriken.logging.L; -import ninja.bytecode.shuriken.math.RollingSequence; -import ninja.bytecode.shuriken.reaction.O; - -public abstract class ParallelChunkGenerator extends ChunkGenerator -{ - private int i; - private int j; - private int wx; - private int wz; - private TaskExecutor backupService; - private TaskGroup tg; - private boolean ready = false; - int cg = 0; - private RollingSequence rs = new RollingSequence(512); - private World world; - private ChunkSpliceListener splicer; - - public void setSplicer(ChunkSpliceListener splicer) - { - this.splicer = splicer; - } - - public World getWorld() - { - return world; - } - - public Biome generateFullColumn(int a, int b, int c, int d, ChunkPlan p, AtomicChunkData data) - { - return genColumn(a, b, c, d, p, data, false); - } - - private TaskGroup work(String n) - { - if(Iris.instance == null || Iris.exec() == null) - { - if(backupService == null) - { - L.f(C.RED + "Cannot contact ExecutionController!" + C.YELLOW + " Did you reload iris?"); - L.w(C.YELLOW + "Spinning up a temporary backup service until the issue resolves..."); - backupService = new TaskExecutor(4, Thread.MAX_PRIORITY, "Iris Backup Handover"); - Iris.instance.reload(); - } - - return backupService.startWork(); - } - - else if(backupService != null) - { - L.i(C.GREEN + "Reconnected to the execution service. Closing backup service now..."); - backupService.close(); - } - - return Iris.exec().getExecutor(world, n).startWork(); - } - - public TaskGroup startParallaxWork() - { - return work("Parallax"); - } - - public TaskGroup startWork() - { - return work("Generator"); - } - - public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) - { - random = new Random(world.getSeed()); - if(splicer != null) - { - AtomicChunkData d = splicer.onSpliceAvailable(world, random, x, z, biome); - - if(d != null) - { - return d.toChunkData(); - } - } - - AtomicChunkData data = new AtomicChunkData(world); - - try - { - this.world = world; - - if(!ready) - { - init(world, random); - ready = true; - } - - tg = startWork(); - O plan = new O(); - for(i = 0; i < 16; i++) - { - wx = (x << 4) + i; - - for(j = 0; j < 16; j++) - { - wz = (z << 4) + j; - int a = wx; - int b = wz; - int c = i; - int d = j; - tg.queue(() -> - { - Biome f = generateFullColumn(a, b, c, d, plan.get(), data); - biome.setBiome(c, d, f); - }); - } - } - - plan.set(initChunk(world, x, z, random)); - TaskResult r = tg.execute(); - onDecorateChunk(world, x, z, data, plan.get()); - TaskGroup gd = startWork(); - - for(i = 0; i < 16; i++) - { - wx = (x << 4) + i; - - for(j = 0; j < 16; j++) - { - wz = (z << 4) + j; - int a = wx; - int b = wz; - int c = i; - int d = j; - gd.queue(() -> onDecorateColumn(world, c, d, a, b, data, plan.get())); - } - } - - gd.execute(); - postChunk(world, x, z, random, data, plan.get()); - rs.put(r.timeElapsed); - cg++; - } - - catch(Throwable e) - { - try - { - for(int i = 0; i < 16; i++) - { - for(int j = 0; j < 16; j++) - { - data.setBlock(i, 0, j, Material.RED_GLAZED_TERRACOTTA); - } - } - } - - catch(Throwable ex) - { - - } - e.printStackTrace(); - } - - return data.toChunkData(); - } - - protected abstract void onDecorateColumn(World world2, int i2, int j2, int wx2, int wz2, AtomicChunkData data, ChunkPlan chunkPlan); - - protected abstract void onDecorateChunk(World world2, int x, int z, AtomicChunkData data, ChunkPlan chunkPlan); - - public abstract void init(World world, Random random); - - public abstract ChunkPlan initChunk(World world, int x, int z, Random random); - - public abstract void postChunk(World world, int x, int z, Random random, AtomicChunkData data, ChunkPlan plan); - - public abstract Biome genColumn(int wx, int wz, int x, int z, ChunkPlan plan, AtomicChunkData data, boolean surfaceOnly); -} \ No newline at end of file diff --git a/src/main/java/ninja/bytecode/iris/generator/placer/AtomicParallaxPlacer.java b/src/main/java/ninja/bytecode/iris/generator/placer/AtomicParallaxPlacer.java deleted file mode 100644 index 3bd7a7a71..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/placer/AtomicParallaxPlacer.java +++ /dev/null @@ -1,47 +0,0 @@ -package ninja.bytecode.iris.generator.placer; - -import org.bukkit.Location; - -import ninja.bytecode.iris.generator.IrisGenerator; -import ninja.bytecode.iris.generator.parallax.ParallaxCache; -import ninja.bytecode.iris.util.IrisWorldData; -import ninja.bytecode.iris.util.MB; -import ninja.bytecode.iris.util.Placer; - -public class AtomicParallaxPlacer extends Placer -{ - private IrisWorldData data; - private ParallaxCache cache; - - public AtomicParallaxPlacer(IrisGenerator g, ParallaxCache cache) - { - super(g.getWorld()); - this.data = g.getWorldData(); - this.cache = cache; - } - - @Override - public MB get(Location l) - { - return cache.get(l.getBlockX(), l.getBlockY(), l.getBlockZ()); - } - - @SuppressWarnings("deprecation") - @Override - public void set(Location l, MB mb) - { - data.setBlock(l.getBlockX(), l.getBlockY(), l.getBlockZ(), mb.material.getId(), mb.data); - } - - @Override - public int getHighestY(Location l) - { - return cache.getHeight(l.getBlockX(), l.getBlockZ()); - } - - @Override - public int getHighestYUnderwater(Location l) - { - return cache.getWaterHeight(l.getBlockX(), l.getBlockZ()); - } -} diff --git a/src/main/java/ninja/bytecode/iris/generator/placer/BukkitPlacer.java b/src/main/java/ninja/bytecode/iris/generator/placer/BukkitPlacer.java deleted file mode 100644 index ea9368891..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/placer/BukkitPlacer.java +++ /dev/null @@ -1,63 +0,0 @@ -package ninja.bytecode.iris.generator.placer; - -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.block.Block; - -import ninja.bytecode.iris.util.MB; -import ninja.bytecode.iris.util.Placer; - -public class BukkitPlacer extends Placer -{ - private final boolean applyPhysics; - - public BukkitPlacer(World world, boolean applyPhysics) - { - super(world); - this.applyPhysics = applyPhysics; - } - - @SuppressWarnings("deprecation") - @Override - public MB get(Location l) - { - Block b = world.getBlockAt(l); - return MB.of(b.getType(), b.getData()); - } - - @SuppressWarnings("deprecation") - @Override - public void set(Location l, MB mb) - { - l.getBlock().setTypeIdAndData(mb.material.getId(), mb.data, applyPhysics); - } - - @Override - public int getHighestYUnderwater(Location l) - { - int y = getHighestY(l); - - while(y > 0) - { - y--; - Block b = l.getWorld().getBlockAt(l.getBlockX(), y, l.getBlockZ()); - if(!b.isEmpty()) - { - if(b.isLiquid()) - { - continue; - } - - return y + 1; - } - } - - return y; - } - - @Override - public int getHighestY(Location l) - { - return world.getHighestBlockYAt(l); - } -} diff --git a/src/main/java/ninja/bytecode/iris/generator/placer/NMSPlacer.java b/src/main/java/ninja/bytecode/iris/generator/placer/NMSPlacer.java deleted file mode 100644 index 96b6c4ec8..000000000 --- a/src/main/java/ninja/bytecode/iris/generator/placer/NMSPlacer.java +++ /dev/null @@ -1,92 +0,0 @@ -package ninja.bytecode.iris.generator.placer; - -import org.bukkit.Chunk; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; - -import mortar.api.nms.Catalyst; -import mortar.api.nms.NMP; -import mortar.api.world.MaterialBlock; -import ninja.bytecode.iris.util.MB; -import ninja.bytecode.iris.util.Placer; -import ninja.bytecode.shuriken.collections.KSet; -import ninja.bytecode.shuriken.execution.J; - -public class NMSPlacer extends Placer -{ - private KSet c; - - public NMSPlacer(World world) - { - super(world); - c = new KSet<>(); - } - - @SuppressWarnings("deprecation") - @Override - public MB get(Location l) - { - Block b = world.getBlockAt(l); - return MB.of(b.getType(), b.getData()); - } - - @SuppressWarnings("deprecation") - @Override - public void set(Location l, MB mb) - { - Catalyst.host.setBlock(l, new MaterialBlock(mb.material.getId(), mb.data)); - c.add(l.getChunk()); - } - - @Override - public int getHighestY(Location l) - { - return world.getHighestBlockYAt(l); - } - - @Override - public int getHighestYUnderwater(Location l) - { - int y = getHighestY(l); - - while(y > 0) - { - y--; - Block b = l.getWorld().getBlockAt(l.getBlockX(), y, l.getBlockZ()); - if(!b.isEmpty()) - { - if(b.isLiquid()) - { - continue; - } - - return y + 1; - } - } - - return y; - } - - public void flush() - { - J.attempt(() -> - { - for(Chunk i : c) - { - NMP.host.relight(i); - - J.a(() -> - { - for(Player j : i.getWorld().getPlayers()) - { - NMP.CHUNK.refreshIgnorePosition(j, i); - } - }); - } - - c.clear(); - }); - } -} diff --git a/src/main/java/ninja/bytecode/iris/pack/BiomeType.java b/src/main/java/ninja/bytecode/iris/pack/BiomeType.java deleted file mode 100644 index b92610de5..000000000 --- a/src/main/java/ninja/bytecode/iris/pack/BiomeType.java +++ /dev/null @@ -1,8 +0,0 @@ -package ninja.bytecode.iris.pack; - -public enum BiomeType -{ - LAND, - FLUID, - FRONT; -} diff --git a/src/main/java/ninja/bytecode/iris/pack/CompiledDimension.java b/src/main/java/ninja/bytecode/iris/pack/CompiledDimension.java deleted file mode 100644 index e5877f52d..000000000 --- a/src/main/java/ninja/bytecode/iris/pack/CompiledDimension.java +++ /dev/null @@ -1,244 +0,0 @@ -package ninja.bytecode.iris.pack; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.function.Consumer; -import java.util.zip.GZIPInputStream; -import java.util.zip.GZIPOutputStream; - -import org.bukkit.World.Environment; -import org.bukkit.block.Biome; - -import net.md_5.bungee.api.ChatColor; -import ninja.bytecode.iris.generator.genobject.GenObject; -import ninja.bytecode.iris.generator.genobject.GenObjectGroup; -import ninja.bytecode.iris.util.SChunkVector; -import ninja.bytecode.iris.util.SBlockVector; -import ninja.bytecode.shuriken.collections.KList; -import ninja.bytecode.shuriken.collections.KMap; -import ninja.bytecode.shuriken.io.CustomOutputStream; -import ninja.bytecode.shuriken.json.JSONObject; -import ninja.bytecode.shuriken.logging.L; -import ninja.bytecode.shuriken.math.RNG; -import ninja.bytecode.shuriken.reaction.O; - -public class CompiledDimension -{ - public static IrisBiome theVoid = new IrisBiome("Void", Biome.VOID).height(0).seal(RNG.r); - private IrisDimension dimension; - private KList biomes; - private KMap biomeCache; - private KMap objects; - private SBlockVector maxSize; - private SChunkVector maxChunkSize; - - public CompiledDimension(IrisDimension dimension) - { - this.dimension = dimension; - biomes = new KList<>(); - biomeCache = new KMap<>(); - objects = new KMap<>(); - maxSize = new SBlockVector(0, 0, 0); - maxChunkSize = new SChunkVector(0, 0); - } - - public void read(InputStream in) throws IOException - { - GZIPInputStream gin = new GZIPInputStream(in); - DataInputStream din = new DataInputStream(gin); - dimension = new IrisDimension(); - dimension.fromJSON(new JSONObject(din.readUTF()), false); - int bi = din.readInt(); - int ob = din.readInt(); - - for(int i = 0; i < bi; i++) - { - IrisBiome b = new IrisBiome("Loading", Biome.VOID); - b.fromJSON(new JSONObject(din.readUTF()), false); - } - - for(int i = 0; i < ob; i++) - { - GenObjectGroup g = new GenObjectGroup("Loading"); - g.read(din); - } - } - - public void write(OutputStream out, Consumer progress) throws IOException - { - GZIPOutputStream gzo = new CustomOutputStream(out, 1); - DataOutputStream dos = new DataOutputStream(gzo); - dos.writeUTF(dimension.toJSON().toString(0)); - dos.writeInt(biomes.size()); - dos.writeInt(objects.size()); - - for(IrisBiome i : biomes) - { - dos.writeUTF(i.toJSON().toString(0)); - } - - O tc = new O<>(); - O oc = new O<>(); - O cc = new O<>(); - tc.set(0); - oc.set(0); - cc.set(0); - - for(GenObjectGroup i : objects.v()) - { - tc.set(tc.get() + i.size()); - } - - for(GenObjectGroup i : objects.v().shuffle()) - { - i.write(dos, (o) -> - { - cc.set((int) (o * i.size())); - - if(progress != null) - { - progress.accept((double) (oc.get() + cc.get()) / (double) tc.get()); - } - }); - - oc.set(oc.get() + cc.get()); - cc.set(0); - } - - dos.close(); - } - - public void registerBiome(IrisBiome j) - { - biomes.add(j); - biomeCache.put(j.getName(), j); - } - - public void registerObject(GenObjectGroup g) - { - if(g.getName().startsWith("pack/objects/")) - { - g.setName(g.getName().replaceFirst("\\Qpack/objects/\\E", "")); - } - - objects.put(g.getName(), g); - } - - public String getName() - { - return dimension.getName(); - } - - public KList getBiomes() - { - return biomes; - } - - public Environment getEnvironment() - { - return dimension.getEnvironment(); - } - - public GenObjectGroup getObjectGroup(String j) - { - return objects.get(j); - } - - public int countObjects() - { - int m = 0; - - for(GenObjectGroup i : objects.v()) - { - m += i.size(); - } - - return m; - } - - public void sort() - { - biomes.sort(); - } - - public IrisBiome getBiomeByName(String name) - { - IrisBiome b = biomeCache.get(name); - - if(b == null) - { - L.f(ChatColor.RED + "Cannot Find Biome: " + ChatColor.GOLD + name); - return theVoid; - } - - return b; - } - - public void dispose() - { - biomes.clear(); - biomeCache.clear(); - - for(GenObjectGroup i : objects.values()) - { - i.dispose(); - } - - objects.clear(); - } - - public void computeObjectSize() - { - int maxWidth = 0; - int maxHeight = 0; - int maxDepth = 0; - - for(GenObjectGroup i : objects.values()) - { - for(GenObject j : i.getSchematics().copy()) - { - maxWidth = j.getW() > maxWidth ? j.getW() : maxWidth; - maxHeight = j.getH() > maxHeight ? j.getH() : maxHeight; - maxDepth = j.getD() > maxDepth ? j.getD() : maxDepth; - } - } - - maxSize = new SBlockVector(maxWidth, maxHeight, maxDepth); - maxChunkSize = new SChunkVector(Math.ceil((double) (maxWidth) / 16D), Math.ceil((double) (maxDepth) / 16D)); - L.i("Max Object Bound is " + maxWidth + ", " + maxHeight + ", " + maxDepth); - L.i("Max Object Region is " + maxChunkSize.getX() + " by " + maxChunkSize.getZ() + " Chunks"); - } - - public static IrisBiome getTheVoid() - { - return theVoid; - } - - public IrisDimension getDimension() - { - return dimension; - } - - public KMap getBiomeCache() - { - return biomeCache; - } - - public KMap getObjects() - { - return objects; - } - - public SBlockVector getMaxSize() - { - return maxSize; - } - - public SChunkVector getMaxChunkSize() - { - return maxChunkSize; - } -} diff --git a/src/main/java/ninja/bytecode/iris/pack/IrisBiome.java b/src/main/java/ninja/bytecode/iris/pack/IrisBiome.java deleted file mode 100644 index 261e9bb82..000000000 --- a/src/main/java/ninja/bytecode/iris/pack/IrisBiome.java +++ /dev/null @@ -1,1113 +0,0 @@ -package ninja.bytecode.iris.pack; - -import java.lang.reflect.Field; -import java.util.Objects; - -import org.bukkit.Material; -import org.bukkit.block.Biome; - -import mortar.util.text.C; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.generator.layer.BiomeNoiseGenerator; -import ninja.bytecode.iris.util.MB; -import ninja.bytecode.iris.util.ObjectMode; -import ninja.bytecode.iris.util.PolygonGenerator; -import ninja.bytecode.shuriken.collections.KList; -import ninja.bytecode.shuriken.collections.KMap; -import ninja.bytecode.shuriken.execution.J; -import ninja.bytecode.shuriken.json.JSONArray; -import ninja.bytecode.shuriken.json.JSONObject; -import ninja.bytecode.shuriken.logging.L; -import ninja.bytecode.shuriken.math.CNG; -import ninja.bytecode.shuriken.math.M; -import ninja.bytecode.shuriken.math.RNG; - -public class IrisBiome -{ - public static final double MAX_HEIGHT = 0.77768; - public static final double IDEAL_HEIGHT = 0.138; - public static final double MIN_HEIGHT = -0.0218; - private static final KMap map = build(); - private String name; - private String parent; - private Biome realBiome; - private double height; - private KList rock; - private MB fluid; - private int rockDepth; - private KList surface; - private KList dirt; - private KMap scatterChance; - private boolean scatterSurface; - private boolean scatterSurfaceRock; - private boolean scatterSurfaceSub; - private boolean core; - private int dirtDepth; - private double surfaceScale; - private double subSurfaceScale; - private double rockScale; - private boolean simplexScatter; - private boolean simplexScatterRock; - private boolean simplexScatterSub; - private double snow; - private double lush; - private double cliffChance; - private double cliffScale; - private double genScale; - private double genAmplifier; - private double genSwirl; - private double genSwirlScale; - private double rarity; - private boolean cliffs; - private BiomeNoiseGenerator bng; - private BiomeType type; - private String region; - private KMap schematicGroups; - private PolygonGenerator.EnumPolygonGenerator poly; - private PolygonGenerator.EnumPolygonGenerator polySub; - private PolygonGenerator.EnumPolygonGenerator polyRock; - - public static double getMaxHeight() - { - return MAX_HEIGHT; - } - - public static double getIdealHeight() - { - return IDEAL_HEIGHT; - } - - public static double getMinHeight() - { - return MIN_HEIGHT; - } - - public static KMap getMap() - { - return map; - } - - public boolean isScatterSurface() - { - return scatterSurface; - } - - public boolean isCore() - { - return core; - } - - public boolean isSimplexScatter() - { - return simplexScatter; - } - - public PolygonGenerator.EnumPolygonGenerator getPoly() - { - return poly; - } - - public IrisBiome(JSONObject json) - { - this("Loading", Biome.OCEAN); - fromJSON(json); - } - - public IrisBiome(String name, Biome realBiome) - { - this.region = "default"; - this.core = false; - this.name = name; - lush = 0; - type = BiomeType.LAND; - cliffs = false; - fluid = MB.of(Material.STATIONARY_WATER); - genScale = 1; - rarity = 1; - genAmplifier = 0.35; - genSwirl = 1; - genSwirlScale = 1; - cliffScale = 1; - cliffChance = 0.37; - parent = ""; - dirtDepth = 19; - this.realBiome = realBiome; - this.height = IDEAL_HEIGHT; - rockDepth = 23; - surfaceScale = 1; - subSurfaceScale = 1; - rockScale = 1; - simplexScatterRock = false; - scatterSurfaceRock = true; - simplexScatterSub = false; - scatterSurfaceSub = true; - scatterChance = new KMap<>(); - schematicGroups = new KMap<>(); - //@builder - surface(new MB(Material.GRASS)) - .dirt(new MB(Material.DIRT), new MB(Material.DIRT, 1)) - .rock(MB.of(Material.STONE), - MB.of(Material.STONE), - MB.of(Material.STONE), - MB.of(Material.STONE), - MB.of(Material.STONE), - MB.of(Material.STONE), - MB.of(Material.STONE), - MB.of(Material.STONE), - MB.of(Material.STONE), - MB.of(Material.STONE), - MB.of(Material.STONE, 5), - MB.of(Material.STONE, 5), - MB.of(Material.STONE, 5), - MB.of(Material.STONE, 5), - MB.of(Material.STONE, 5), - MB.of(Material.STONE, 5)); - //@done - } - - public void fromJSON(JSONObject o) - { - fromJSON(o, true); - } - - public IrisBiome seal(RNG rng) - { - if(simplexScatter) - { - poly = new PolygonGenerator.EnumPolygonGenerator(rng, 0.125, 2, getSurface().toArray(new MB[getSurface().size()]), (g) -> - { - return g.scale(0.09 * surfaceScale).fractureWith(new CNG(rng.nextParallelRNG(56), 1D, 2).scale(0.0955), 55); - }); - } - - else - { - poly = new PolygonGenerator.EnumPolygonGenerator(rng, 15.05, 2, getSurface().toArray(new MB[getSurface().size()]), (g) -> - { - return g.scale(surfaceScale).fractureWith(new CNG(rng.nextParallelRNG(55), 1D, 2).scale(0.0155), 224); - }); - } - - if(simplexScatterSub) - { - polySub = new PolygonGenerator.EnumPolygonGenerator(rng, 0.125, 2, getDirt().toArray(new MB[getDirt().size()]), (g) -> - { - return g.scale(0.06 * subSurfaceScale).fractureWith(new CNG(rng.nextParallelRNG(526), 1D, 2).scale(0.0955), 55); - }); - } - - else - { - polySub = new PolygonGenerator.EnumPolygonGenerator(rng, 15.05, 2, getDirt().toArray(new MB[getDirt().size()]), (g) -> - { - return g.scale(subSurfaceScale).fractureWith(new CNG(rng.nextParallelRNG(515), 1D, 2).scale(0.0155), 224); - }); - } - - if(simplexScatterRock) - { - polyRock = new PolygonGenerator.EnumPolygonGenerator(rng, 0.125, 2, getRock().toArray(new MB[getRock().size()]), (g) -> - { - return g.scale(0.08 * rockScale).fractureWith(new CNG(rng.nextParallelRNG(562), 1D, 2).scale(0.0955), 55); - }); - } - - else - { - polyRock = new PolygonGenerator.EnumPolygonGenerator(rng, 15.05, 2, getRock().toArray(new MB[getRock().size()]), (g) -> - { - return g.scale(rockScale).fractureWith(new CNG(rng.nextParallelRNG(551), 1D, 2).scale(0.0155), 224); - }); - } - - bng = new BiomeNoiseGenerator(rng.nextParallelRNG(2077), this); - - return this; - } - - public BiomeNoiseGenerator getGenerator() - { - if(polySub == null) - { - L.w(getName() + " is not sealed!"); - } - - return bng; - } - - public void fromJSON(JSONObject o, boolean chain) - { - name = o.getString("name"); - realBiome = Biome.valueOf(o.getString("derivative").toUpperCase().replaceAll(" ", "_")); - type = BiomeType.valueOf(o.getString("type").toUpperCase().replaceAll(" ", "_")); - J.attempt(() -> region = o.getString("region")); - J.attempt(() -> parent = o.getString("parent")); - J.attempt(() -> height(o.getDouble("height"))); - J.attempt(() -> height(o.getDouble("genHeight"))); - J.attempt(() -> genAmplifier = o.getDouble("genAmplifier")); - J.attempt(() -> genSwirl = o.getDouble("genSwirl")); - J.attempt(() -> genSwirlScale = o.getDouble("genSwirlScale")); - J.attempt(() -> genScale = o.getDouble("genScale")); - J.attempt(() -> snow = o.getDouble("snow")); - J.attempt(() -> lush = o.getDouble("lush")); - J.attempt(() -> rarity = o.getDouble("rarity")); - J.attempt(() -> fluid = MB.of(o.getString("fluid"))); - J.attempt(() -> dirtDepth = o.getInt("subSurfaceDepth")); - J.attempt(() -> dirtDepth = o.getInt("dirtDepth")); - J.attempt(() -> rockDepth = o.getInt("rockDepth")); - J.attempt(() -> cliffScale = o.getDouble("cliffScale")); - J.attempt(() -> rockScale = o.getDouble("rockScale")); - J.attempt(() -> surfaceScale = o.getDouble("surfaceScale")); - J.attempt(() -> subSurfaceScale = o.getDouble("subSurfaceScale")); - J.attempt(() -> cliffChance = o.getDouble("cliffChance")); - J.attempt(() -> cliffs = o.getBoolean("cliffs")); - J.attempt(() -> surface = mbListFromJSON(o.getJSONArray("surface"))); - J.attempt(() -> rock = mbListFromJSON(o.getJSONArray("rock"))); - J.attempt(() -> dirt = mbListFromJSON(o.getJSONArray("subSurface"))); - J.attempt(() -> dirt = mbListFromJSON(o.getJSONArray("dirt"))); - J.attempt(() -> scatterChance = scatterFromJSON(o.getJSONArray("scatter"))); - J.attempt(() -> simplexScatter = o.getString("surfaceType").equalsIgnoreCase("simplex")); - J.attempt(() -> scatterSurface = o.getString("surfaceType").equalsIgnoreCase("scatter")); - J.attempt(() -> simplexScatterRock = o.getString("rockType").equalsIgnoreCase("simplex")); - J.attempt(() -> scatterSurfaceRock = o.getString("rockType").equalsIgnoreCase("scatter")); - J.attempt(() -> simplexScatterSub = o.getString("subSurfaceType").equalsIgnoreCase("simplex")); - J.attempt(() -> scatterSurfaceSub = o.getString("subSurfaceType").equalsIgnoreCase("scatter")); - J.attempt(() -> - { - if(!Iris.settings.performance.objectMode.equals(ObjectMode.NONE)) - { - schematicGroups = strFromJSON(o.getJSONArray("objects")); - } - - else - { - schematicGroups = new KMap<>(); - } - - if(chain) - { - if(!Iris.settings.performance.objectMode.equals(ObjectMode.NONE)) - { - for(String i : schematicGroups.k()) - { - Iris.pack().loadSchematicGroup(i); - } - } - } - }); - } - - public JSONObject toJSON() - { - JSONObject j = new JSONObject(); - j.put("name", name); - J.attempt(() -> j.put("parent", parent)); - J.attempt(() -> j.put("region", region)); - J.attempt(() -> j.put("derivative", realBiome.name().toLowerCase().replaceAll("_", " "))); - J.attempt(() -> j.put("type", type.name().toLowerCase().replaceAll("_", " "))); - J.attempt(() -> j.put("rarity", rarity)); - J.attempt(() -> j.put("fluid", fluid.toString())); - J.attempt(() -> j.put("genHeight", height)); - J.attempt(() -> j.put("genScale", genScale)); - J.attempt(() -> j.put("genSwirl", genSwirl)); - J.attempt(() -> j.put("genSwirlScale", genSwirlScale)); - J.attempt(() -> j.put("genAmplifier", genAmplifier)); - J.attempt(() -> j.put("snow", snow)); - J.attempt(() -> j.put("lush", lush)); - J.attempt(() -> j.put("cliffs", cliffs)); - J.attempt(() -> j.put("cliffScale", cliffScale)); - J.attempt(() -> j.put("rockScale", rockScale)); - J.attempt(() -> j.put("subSurfaceScale", subSurfaceScale)); - J.attempt(() -> j.put("surfaceScale", surfaceScale)); - J.attempt(() -> j.put("cliffChance", cliffChance)); - J.attempt(() -> j.put("surface", mbListToJSON(surface))); - J.attempt(() -> j.put("rock", mbListToJSON(rock))); - J.attempt(() -> j.put("subSurfaceDepth", dirtDepth)); - J.attempt(() -> j.put("rockDepth", rockDepth)); - J.attempt(() -> j.put("subSurface", mbListToJSON(dirt))); - J.attempt(() -> j.put("scatter", scatterToJson(scatterChance))); - J.attempt(() -> j.put("surfaceType", simplexScatter ? "simplex" : scatterSurface ? "scatter" : "na")); - J.attempt(() -> j.put("subSurfaceType", simplexScatterSub ? "simplex" : scatterSurfaceSub ? "scatter" : "na")); - J.attempt(() -> j.put("rockType", simplexScatterRock ? "simplex" : scatterSurfaceRock ? "scatter" : "na")); - J.attempt(() -> j.put("objects", strToJson(schematicGroups))); - - return j; - } - - private KList mbListFromJSON(JSONArray ja) - { - KList mb = new KList<>(); - - for(int i = 0; i < ja.length(); i++) - { - mb.add(MB.of(ja.getString(i))); - } - - return mb; - } - - private JSONArray mbListToJSON(KList mbs) - { - JSONArray ja = new JSONArray(); - - for(MB i : mbs) - { - ja.put(i.toString()); - } - - return ja; - } - - public IrisBiome coreBiome() - { - this.core = true; - return this; - } - - private KMap scatterFromJSON(JSONArray ja) - { - KMap mb = new KMap(); - - for(int i = 0; i < ja.length(); i++) - { - String s = ja.getString(i); - mb.put(MB.of(s.split("\\Q=\\E")[0]), Double.valueOf(s.split("\\Q=\\E")[1])); - } - - return mb; - } - - private JSONArray scatterToJson(KMap mbs) - { - JSONArray ja = new JSONArray(); - - for(MB i : mbs.k()) - { - ja.put(i.toString() + "=" + mbs.get(i)); - } - - return ja; - } - - private KMap strFromJSON(JSONArray ja) - { - KMap mb = new KMap(); - - for(int i = 0; i < ja.length(); i++) - { - String s = ja.getString(i); - mb.put(s.split("\\Q=\\E")[0], Double.valueOf(s.split("\\Q=\\E")[1])); - } - - return mb; - } - - private JSONArray strToJson(KMap mbs) - { - JSONArray ja = new JSONArray(); - - for(String i : mbs.k()) - { - ja.put(i.toString() + "=" + mbs.get(i)); - } - - return ja; - } - - private static KMap build() - { - KMap g = new KMap(); - - for(Field i : IrisBiome.class.getDeclaredFields()) - { - J.attempt(() -> - { - i.setAccessible(true); - - IrisBiome bb = (IrisBiome) i.get(null); - - if(!g.containsKey(bb.realBiome)) - { - g.put(bb.realBiome, bb); - } - }); - } - - return g; - } - - public IrisBiome scatter(MB mb, Double chance) - { - scatterChance.put(mb, chance); - - return this; - } - - public IrisBiome schematic(String t, double chance) - { - schematicGroups.put(t, chance); - - return this; - } - - public IrisBiome simplexSurface() - { - simplexScatter = true; - return this; - } - - public IrisBiome scatterSurface() - { - scatterSurface = true; - return this; - } - - public IrisBiome surface(MB... mbs) - { - surface = new KList<>(mbs); - return this; - } - - public IrisBiome dirt(MB... mbs) - { - dirt = new KList<>(mbs); - return this; - } - - public IrisBiome rock(MB... mbs) - { - rock = new KList<>(mbs); - return this; - } - - public IrisBiome height(double height) - { - if(height >= 0) - { - this.height = M.lerp(IDEAL_HEIGHT, MAX_HEIGHT, M.clip(height, 0D, 1D)); - } - - else - { - this.height = M.lerp(MIN_HEIGHT, IDEAL_HEIGHT, 1d - Math.abs(M.clip(height, -1D, 0D))); - } - - return this; - } - - public String getName() - { - return name; - } - - public Biome getRealBiome() - { - return realBiome; - } - - public double getHeight() - { - return height; - } - - public KList getSurface() - { - return surface; - } - - public KList getRock() - { - return rock; - } - - public KList getDirt() - { - return dirt; - } - - public MB getSurface(double x, double z, RNG rng) - { - double wx = x + 1000D; - double wz = z + 1000D; - - if(polySub == null) - { - L.w(getName() + " is not sealed!"); - } - - if(simplexScatter) - { - return poly.getChoice(wx / 3, wz / 3); - } - - if(scatterSurface) - { - return poly.getChoice(wx * 0.2D, wz * 0.2D); - } - - return getSurface().getRandom(); - } - - public MB getSubSurface(double x, double i, double z, RNG rng) - { - double wx = x + 1000D; - double wz = z + 1000D; - - if(polySub == null) - { - L.w(getName() + " is not sealed!"); - } - - if(simplexScatterSub) - { - return polySub.getChoice(wx / 3, i / 3, wz / 3); - } - - if(scatterSurfaceSub) - { - return polySub.getChoice(wx * 0.2D, i / 3, wz * 0.2D); - } - - return getSurface().getRandom(); - } - - public MB getRock(double x, double i, double z, RNG rng) - { - double wx = x + 1000D; - double wz = z + 1000D; - - if(polySub == null) - { - L.w(getName() + " is not sealed!"); - } - - if(simplexScatterRock) - { - return polyRock.getChoice(wx / 3, i / 3, wz / 3); - } - - if(scatterSurfaceRock) - { - return polyRock.getChoice(wx * 0.2D, i * 0.2D, wz * 0.2D); - } - - return getSurface().getRandom(); - } - - public KMap getScatterChance() - { - return scatterChance; - } - - public MB getScatterChanceSingle(double d, double aux) - { - KList a = new KList<>(); - - for(MB i : getScatterChance().keySet()) - { - if(d < getScatterChance().get(i)) - { - a.add(i); - } - } - - if(a.isEmpty()) - { - return MB.of(Material.AIR); - } - - if(a.size() == 1) - { - return a.get(0); - } - - return a.get((int) (aux * (a.size() - 1))); - } - - public static KList getBiomes() - { - return map.v(); - } - - public static IrisBiome findByBiome(Biome biome) - { - if(map.containsKey(biome)) - { - return map.get(biome); - } - - return null; - } - - public KMap getSchematicGroups() - { - return schematicGroups; - } - - public boolean isSurface(Material t) - { - for(MB i : surface) - { - if(i.material.equals(t)) - { - return true; - } - } - - return false; - } - - public String getRegionID() - { - return region; - } - - public boolean isSnowy() - { - return getSnow() > 0; - } - - public double getSnow() - { - return snow; - } - - public double getCliffScale() - { - return cliffScale; - } - - public boolean hasCliffs() - { - return cliffs; - } - - public int getDirtDepth() - { - return dirtDepth; - } - - public int getRockDepth() - { - return rockDepth; - } - - public boolean isCliffs() - { - return cliffs; - } - - public double getCliffChance() - { - return cliffChance; - } - - public String getParent() - { - return parent; - } - - public KList getParents() - { - KList f = new KList<>(); - - if(getParent().trim().isEmpty()) - { - return f; - } - - if(getParent().contains("&")) - { - for(String i : getParent().split("\\Q&\\E")) - { - f.add(i.trim()); - } - } - - else - { - f.add(getParent().trim()); - } - - return f; - } - - public boolean isScatterSurfaceRock() - { - return scatterSurfaceRock; - } - - public boolean isScatterSurfaceSub() - { - return scatterSurfaceSub; - } - - public double getSurfaceScale() - { - return surfaceScale; - } - - public double getSubSurfaceScale() - { - return subSurfaceScale; - } - - public double getRockScale() - { - return rockScale; - } - - public boolean isSimplexScatterRock() - { - return simplexScatterRock; - } - - public boolean isSimplexScatterSub() - { - return simplexScatterSub; - } - - public BiomeType getType() - { - return type; - } - - public PolygonGenerator.EnumPolygonGenerator getPolySub() - { - return polySub; - } - - public PolygonGenerator.EnumPolygonGenerator getPolyRock() - { - return polyRock; - } - - public double getGenScale() - { - return genScale; - } - - public void setGenScale(double genScale) - { - this.genScale = genScale; - } - - public double getGenAmplifier() - { - return genAmplifier; - } - - public void setGenAmplifier(double genAmplifier) - { - this.genAmplifier = genAmplifier; - } - - public double getGenSwirl() - { - return genSwirl; - } - - public void setGenSwirl(double genSwirl) - { - this.genSwirl = genSwirl; - } - - public void setName(String name) - { - this.name = name; - } - - public void setParent(String parent) - { - this.parent = parent; - } - - public void setRealBiome(Biome realBiome) - { - this.realBiome = realBiome; - } - - public void setHeight(double height) - { - this.height = height; - } - - public void setRock(KList rock) - { - this.rock = rock; - } - - public void setRockDepth(int rockDepth) - { - this.rockDepth = rockDepth; - } - - public void setSurface(KList surface) - { - this.surface = surface; - } - - public void setDirt(KList dirt) - { - this.dirt = dirt; - } - - public void setScatterChance(KMap scatterChance) - { - this.scatterChance = scatterChance; - } - - public void setScatterSurface(boolean scatterSurface) - { - this.scatterSurface = scatterSurface; - } - - public void setScatterSurfaceRock(boolean scatterSurfaceRock) - { - this.scatterSurfaceRock = scatterSurfaceRock; - } - - public void setScatterSurfaceSub(boolean scatterSurfaceSub) - { - this.scatterSurfaceSub = scatterSurfaceSub; - } - - public void setCore(boolean core) - { - this.core = core; - } - - public void setDirtDepth(int dirtDepth) - { - this.dirtDepth = dirtDepth; - } - - public void setSurfaceScale(double surfaceScale) - { - this.surfaceScale = surfaceScale; - } - - public void setSubSurfaceScale(double subSurfaceScale) - { - this.subSurfaceScale = subSurfaceScale; - } - - public void setRockScale(double rockScale) - { - this.rockScale = rockScale; - } - - public void setSimplexScatter(boolean simplexScatter) - { - this.simplexScatter = simplexScatter; - } - - public void setSimplexScatterRock(boolean simplexScatterRock) - { - this.simplexScatterRock = simplexScatterRock; - } - - public void setSimplexScatterSub(boolean simplexScatterSub) - { - this.simplexScatterSub = simplexScatterSub; - } - - public void setSnow(double snow) - { - this.snow = snow; - } - - public void setCliffChance(double cliffChance) - { - this.cliffChance = cliffChance; - } - - public void setCliffScale(double cliffScale) - { - this.cliffScale = cliffScale; - } - - public void setCliffs(boolean cliffs) - { - this.cliffs = cliffs; - } - - public void setType(BiomeType type) - { - this.type = type; - } - - public void setRegion(String region) - { - this.region = region; - } - - public void setSchematicGroups(KMap schematicGroups) - { - this.schematicGroups = schematicGroups; - } - - public void setPoly(PolygonGenerator.EnumPolygonGenerator poly) - { - this.poly = poly; - } - - public void setPolySub(PolygonGenerator.EnumPolygonGenerator polySub) - { - this.polySub = polySub; - } - - public void setPolyRock(PolygonGenerator.EnumPolygonGenerator polyRock) - { - this.polyRock = polyRock; - } - - public double getGenSwirlScale() - { - return genSwirlScale; - } - - public void setGenSwirlScale(double genSwirlScale) - { - this.genSwirlScale = genSwirlScale; - } - - public BiomeNoiseGenerator getBng() - { - return bng; - } - - public void setBng(BiomeNoiseGenerator bng) - { - this.bng = bng; - } - - public double getRarity() - { - return rarity; - } - - public String getRarityString() - { - if(getRarity() <= 0.1) - { - return C.RED + "Literally Everywhere"; - } - - else if(getRarity() < 0.25) - { - return "Overly Abundant"; - } - - else if(getRarity() < 0.4) - { - return "Very Abundant"; - } - - else if(getRarity() < 0.6) - { - return "Abundant"; - } - - else if(getRarity() < 0.75) - { - return "Very Common"; - } - - else if(getRarity() <= 1) - { - return "Common"; - } - - else if(getRarity() <= 2) - { - return "Often"; - } - - else if(getRarity() <= 3) - { - return "Uncommon"; - } - - else if(getRarity() <= 6) - { - return "Rare"; - } - - else if(getRarity() <= 16) - { - return "Very Rare"; - } - - else if(getRarity() <= 50) - { - return "Exceedingly Rare"; - } - - else if(getRarity() <= 100) - { - return "Marvelously Rare"; - } - - else if(getRarity() <= 200) - { - return "Extraordinarily Rare"; - } - - else - { - return "Start Praying"; - } - } - - public MB getFluid() - { - return fluid; - } - - public void setFluid(MB fluid) - { - this.fluid = fluid; - } - - public void setRarity(double rarity) - { - this.rarity = rarity; - } - - public double getLush() - { - return lush; - } - - public String getRegion() - { - return region; - } - - @Override - public int hashCode() - { - return Objects.hash(bng, cliffChance, cliffScale, cliffs, core, dirt, dirtDepth, fluid, genAmplifier, genScale, genSwirl, genSwirlScale, height, lush, name, parent, poly, polyRock, polySub, rarity, realBiome, region, rock, rockDepth, rockScale, scatterChance, scatterSurface, scatterSurfaceRock, scatterSurfaceSub, schematicGroups, simplexScatter, simplexScatterRock, simplexScatterSub, snow, subSurfaceScale, surface, surfaceScale, type); - } - - @Override - public boolean equals(Object obj) - { - if(this == obj) - { - return true; - } - if(!(obj instanceof IrisBiome)) - { - return false; - } - IrisBiome other = (IrisBiome) obj; - return Objects.equals(bng, other.bng) && Double.doubleToLongBits(cliffChance) == Double.doubleToLongBits(other.cliffChance) && Double.doubleToLongBits(cliffScale) == Double.doubleToLongBits(other.cliffScale) && cliffs == other.cliffs && core == other.core && Objects.equals(dirt, other.dirt) && dirtDepth == other.dirtDepth && Objects.equals(fluid, other.fluid) && Double.doubleToLongBits(genAmplifier) == Double.doubleToLongBits(other.genAmplifier) && Double.doubleToLongBits(genScale) == Double.doubleToLongBits(other.genScale) && Double.doubleToLongBits(genSwirl) == Double.doubleToLongBits(other.genSwirl) && Double.doubleToLongBits(genSwirlScale) == Double.doubleToLongBits(other.genSwirlScale) && Double.doubleToLongBits(height) == Double.doubleToLongBits(other.height) && Double.doubleToLongBits(lush) == Double.doubleToLongBits(other.lush) && Objects.equals(name, other.name) && Objects.equals(parent, other.parent) && Objects.equals(poly, other.poly) && Objects.equals(polyRock, other.polyRock) && Objects.equals(polySub, other.polySub) && Double.doubleToLongBits(rarity) == Double.doubleToLongBits(other.rarity) && realBiome == other.realBiome && Objects.equals(region, other.region) && Objects.equals(rock, other.rock) && rockDepth == other.rockDepth && Double.doubleToLongBits(rockScale) == Double.doubleToLongBits(other.rockScale) && Objects.equals(scatterChance, other.scatterChance) && scatterSurface == other.scatterSurface && scatterSurfaceRock == other.scatterSurfaceRock && scatterSurfaceSub == other.scatterSurfaceSub && Objects.equals(schematicGroups, other.schematicGroups) && simplexScatter == other.simplexScatter && simplexScatterRock == other.simplexScatterRock && simplexScatterSub == other.simplexScatterSub && Double.doubleToLongBits(snow) == Double.doubleToLongBits(other.snow) && Double.doubleToLongBits(subSurfaceScale) == Double.doubleToLongBits(other.subSurfaceScale) && Objects.equals(surface, other.surface) && Double.doubleToLongBits(surfaceScale) == Double.doubleToLongBits(other.surfaceScale) && type == other.type; - } - - public boolean isLush() - { - return lush > 0; - } -} diff --git a/src/main/java/ninja/bytecode/iris/pack/IrisDimension.java b/src/main/java/ninja/bytecode/iris/pack/IrisDimension.java deleted file mode 100644 index f01cfe739..000000000 --- a/src/main/java/ninja/bytecode/iris/pack/IrisDimension.java +++ /dev/null @@ -1,109 +0,0 @@ -package ninja.bytecode.iris.pack; - -import java.io.IOException; - -import org.bukkit.World.Environment; - -import ninja.bytecode.iris.Iris; -import ninja.bytecode.shuriken.collections.KList; -import ninja.bytecode.shuriken.execution.J; -import ninja.bytecode.shuriken.json.JSONArray; -import ninja.bytecode.shuriken.json.JSONException; -import ninja.bytecode.shuriken.json.JSONObject; - -public class IrisDimension -{ - private String name; - private Environment environment; - KList biomes; - - public IrisDimension(JSONObject o) throws JSONException, IOException - { - this(); - fromJSON(o); - } - - public IrisDimension() - { - biomes = new KList(); - environment = Environment.NORMAL; - } - - public void fromJSON(JSONObject o) throws JSONException, IOException - { - fromJSON(o, true); - } - - public void fromJSON(JSONObject o, boolean chain) throws JSONException, IOException - { - name = o.getString("name"); - J.attempt(() -> environment = Environment.valueOf(o.getString("environment").toUpperCase().replaceAll(" ", "_"))); - - try - { - biomes = chain ? biomesFromArray(o.getJSONArray("biomes")) : new KList<>(); - } - - catch(Throwable e) - { - e.printStackTrace(); - } - } - - public JSONObject toJSON() - { - JSONObject o = new JSONObject(); - - o.put("name", name); - o.put("environment", environment.name().toLowerCase().replaceAll("_", " ")); - o.put("biomes", biomesToArray(biomes)); - - return o; - } - - private KList biomesFromArray(JSONArray a) throws JSONException, IOException - { - KList b = new KList<>(); - for(int i = 0; i < a.length(); i++) - { - int ii = i; - - IrisBiome bb = Iris.pack().loadBiome(a.getString(ii)); - Iris.pack().registerBiome(a.getString(ii), bb); - b.add(bb); - } - return b; - } - - private JSONArray biomesToArray(KList b) - { - JSONArray a = new JSONArray(); - - for(IrisBiome i : b) - { - a.put(i.getName().toLowerCase().replaceAll(" ", "_")); - } - - return a; - } - - public KList getBiomes() - { - return biomes; - } - - public String getName() - { - return name; - } - - public Environment getEnvironment() - { - return environment; - } - - public void dispose() - { - biomes.clear(); - } -} diff --git a/src/main/java/ninja/bytecode/iris/pack/IrisPack.java b/src/main/java/ninja/bytecode/iris/pack/IrisPack.java deleted file mode 100644 index 783e25a72..000000000 --- a/src/main/java/ninja/bytecode/iris/pack/IrisPack.java +++ /dev/null @@ -1,86 +0,0 @@ -package ninja.bytecode.iris.pack; - -import java.io.IOException; - -import ninja.bytecode.iris.Iris; -import ninja.bytecode.shuriken.collections.KList; -import ninja.bytecode.shuriken.execution.J; -import ninja.bytecode.shuriken.json.JSONArray; -import ninja.bytecode.shuriken.json.JSONException; -import ninja.bytecode.shuriken.json.JSONObject; - -public class IrisPack -{ - private KList dimensions; - private KList biomes; - private KList objects; - - public IrisPack() - { - this.dimensions = new KList<>(); - this.biomes = new KList<>(); - this.objects = new KList<>(); - } - - public IrisPack(JSONObject o) - { - this(); - fromJSON(o); - } - - public void fromJSON(JSONObject o) - { - J.attempt(() -> dimensions = fromArray(o.getJSONArray("dimensions"))); - J.attempt(() -> biomes = fromArray(o.getJSONArray("biomes"))); - J.attempt(() -> objects = fromArray(o.getJSONArray("objects"))); - } - - public JSONObject toJSON() - { - JSONObject o = new JSONObject(); - o.put("dimensions", toArray(dimensions)); - o.put("biomes", toArray(biomes)); - o.put("objects", toArray(objects)); - - return o; - } - - public KList fromArray(JSONArray ja) - { - KList g = new KList<>(); - - for(int i = 0; i < ja.length(); i++) - { - g.add(ja.getString(i)); - } - - return g; - } - - public JSONArray toArray(KList s) - { - JSONArray ja = new JSONArray(); - - for(String i : s) - { - ja.put(i); - } - - return ja; - } - - public void load() throws JSONException, IOException - { - for(String i : dimensions) - { - IrisDimension d = Iris.pack().loadDimension(i); - Iris.pack().registerDimension(i, d); - } - } - - public void loadBiome(String s) throws JSONException, IOException - { - IrisBiome b = Iris.pack().loadBiome(s); - Iris.pack().registerBiome(s, b); - } -} diff --git a/src/main/java/ninja/bytecode/iris/pack/IrisRegion.java b/src/main/java/ninja/bytecode/iris/pack/IrisRegion.java deleted file mode 100644 index c3ab94851..000000000 --- a/src/main/java/ninja/bytecode/iris/pack/IrisRegion.java +++ /dev/null @@ -1,123 +0,0 @@ -package ninja.bytecode.iris.pack; - -import java.util.Objects; - -import ninja.bytecode.iris.Iris; -import ninja.bytecode.shuriken.collections.KList; -import ninja.bytecode.shuriken.execution.J; -import ninja.bytecode.shuriken.json.JSONObject; - -public class IrisRegion -{ - private String name; - private KList biomes; - private IrisBiome ocean; - private IrisBiome deepOcean; - private IrisBiome lake; - private IrisBiome lakeBeach; - private IrisBiome channel; - private IrisBiome beach; - - public IrisRegion(String name) - { - this.name = name; - this.biomes = new KList<>(); - beach = null; - ocean = null; - deepOcean = null; - lake = null; - lakeBeach = null; - channel = null; - } - - public void load() - { - J.attempt(() -> - { - JSONObject o = Iris.pack().loadJSON("pack/regions/" + name + ".json"); - J.attempt(() -> name = o.getString("name")); - J.attempt(() -> ocean = Iris.pack().getBiomeById(o.getString("ocean"))); - J.attempt(() -> deepOcean = Iris.pack().getBiomeById(o.getString("deepOcean"))); - J.attempt(() -> beach = Iris.pack().getBiomeById(o.getString("beach"))); - J.attempt(() -> lake = Iris.pack().getBiomeById(o.getString("lake"))); - J.attempt(() -> lakeBeach = Iris.pack().getBiomeById(o.getString("shore"))); - J.attempt(() -> channel = Iris.pack().getBiomeById(o.getString("channel"))); - }); - } - - public String getName() - { - return name; - } - - public void setName(String name) - { - this.name = name; - } - - public KList getBiomes() - { - return biomes; - } - - public void setBiomes(KList biomes) - { - this.biomes = biomes; - } - - public IrisBiome getBeach() - { - return beach; - } - - public void setBeach(IrisBiome beach) - { - this.beach = beach; - } - - public IrisBiome getOcean() - { - return ocean; - } - - public IrisBiome getDeepOcean() - { - return deepOcean; - } - - public IrisBiome getLake() - { - return lake; - } - - public IrisBiome getShore() - { - return lakeBeach; - } - - public IrisBiome getChannel() - { - return channel; - } - - @Override - public int hashCode() - { - return Objects.hash(beach, biomes, channel, lake, lakeBeach, name, ocean); - } - - @Override - public boolean equals(Object obj) - { - if(this == obj) - { - return true; - } - if(!(obj instanceof IrisRegion)) - { - return false; - } - IrisRegion other = (IrisRegion) obj; - return Objects.equals(beach, other.beach) && Objects.equals(biomes, other.biomes) && Objects.equals(channel, other.channel) && Objects.equals(lake, other.lake) && Objects.equals(lakeBeach, other.lakeBeach) && Objects.equals(name, other.name) && Objects.equals(ocean, other.ocean); - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/Axis.java b/src/main/java/ninja/bytecode/iris/util/Axis.java deleted file mode 100644 index 1e7e7291f..000000000 --- a/src/main/java/ninja/bytecode/iris/util/Axis.java +++ /dev/null @@ -1,31 +0,0 @@ -package ninja.bytecode.iris.util; - -import org.bukkit.util.Vector; - -public enum Axis -{ - X(1, 0, 0), - Y(0, 1, 0), - Z(0, 0, 1); - - private int x; - private int y; - private int z; - - private Axis(int x, int y, int z) - { - this.x = x; - this.y = y; - this.z = z; - } - - public Vector positive() - { - return new Vector(x, y, z); - } - - public Vector negative() - { - return VectorMath.reverse(positive()); - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/BasePerlinNoiseGenerator.java b/src/main/java/ninja/bytecode/iris/util/BasePerlinNoiseGenerator.java new file mode 100644 index 000000000..f353284ad --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/util/BasePerlinNoiseGenerator.java @@ -0,0 +1,219 @@ +package ninja.bytecode.iris.util; + +import java.util.Random; + +/** + * Generates noise using the "classic" perlin generator + * + * @see SimplexNoiseC "Improved" and faster version with slighly + * different results + */ +public class BasePerlinNoiseGenerator extends NoiseGenerator +{ + protected static final int grad3[][] = {{1, 1, 0}, {-1, 1, 0}, {1, -1, 0}, {-1, -1, 0}, {1, 0, 1}, {-1, 0, 1}, {1, 0, -1}, {-1, 0, -1}, {0, 1, 1}, {0, -1, 1}, {0, 1, -1}, {0, -1, -1}}; + private static final BasePerlinNoiseGenerator instance = new BasePerlinNoiseGenerator(); + + protected BasePerlinNoiseGenerator() + { + int p[] = {151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180}; + + for(int i = 0; i < 512; i++) + { + perm[i] = p[i & 255]; + } + } + + /** + * Creates a seeded perlin noise generator for the given seed + * + * @param seed + * Seed to construct this generator for + */ + public BasePerlinNoiseGenerator(long seed) + { + this(new Random(seed)); + } + + /** + * Creates a seeded perlin noise generator with the given Random + * + * @param rand + * Random to construct with + */ + public BasePerlinNoiseGenerator(Random rand) + { + offsetX = rand.nextDouble() * 256; + offsetY = rand.nextDouble() * 256; + offsetZ = rand.nextDouble() * 256; + + for(int i = 0; i < 256; i++) + { + perm[i] = rand.nextInt(256); + } + + for(int i = 0; i < 256; i++) + { + int pos = rand.nextInt(256 - i) + i; + int old = perm[i]; + + perm[i] = perm[pos]; + perm[pos] = old; + perm[i + 256] = perm[i]; + } + } + + /** + * Computes and returns the 1D unseeded perlin noise for the given coordinates + * in 1D space + * + * @param x + * X coordinate + * @return Noise at given location, from range -1 to 1 + */ + public static double getNoise(double x) + { + return instance.noise(x); + } + + /** + * Computes and returns the 2D unseeded perlin noise for the given coordinates + * in 2D space + * + * @param x + * X coordinate + * @param y + * Y coordinate + * @return Noise at given location, from range -1 to 1 + */ + public static double getNoise(double x, double y) + { + return instance.noise(x, y); + } + + /** + * Computes and returns the 3D unseeded perlin noise for the given coordinates + * in 3D space + * + * @param x + * X coordinate + * @param y + * Y coordinate + * @param z + * Z coordinate + * @return Noise at given location, from range -1 to 1 + */ + public static double getNoise(double x, double y, double z) + { + return instance.noise(x, y, z); + } + + /** + * Gets the singleton unseeded instance of this generator + * + * @return Singleton + */ + public static BasePerlinNoiseGenerator getInstance() + { + return instance; + } + + @Override + public double noise(double x, double y, double z) + { + x += offsetX; + y += offsetY; + z += offsetZ; + + int floorX = floor(x); + int floorY = floor(y); + int floorZ = floor(z); + + // Find unit cube containing the point + int X = floorX & 255; + int Y = floorY & 255; + int Z = floorZ & 255; + + // Get relative xyz coordinates of the point within the cube + x -= floorX; + y -= floorY; + z -= floorZ; + + // Compute fade curves for xyz + double fX = fade(x); + double fY = fade(y); + double fZ = fade(z); + + // Hash coordinates of the cube corners + int A = perm[X] + Y; + int AA = perm[A] + Z; + int AB = perm[A + 1] + Z; + int B = perm[X + 1] + Y; + int BA = perm[B] + Z; + int BB = perm[B + 1] + Z; + + return lerp(fZ, lerp(fY, lerp(fX, grad(perm[AA], x, y, z), grad(perm[BA], x - 1, y, z)), lerp(fX, grad(perm[AB], x, y - 1, z), grad(perm[BB], x - 1, y - 1, z))), lerp(fY, lerp(fX, grad(perm[AA + 1], x, y, z - 1), grad(perm[BA + 1], x - 1, y, z - 1)), lerp(fX, grad(perm[AB + 1], x, y - 1, z - 1), grad(perm[BB + 1], x - 1, y - 1, z - 1)))); + } + + /** + * Generates noise for the 1D coordinates using the specified number of octaves + * and parameters + * + * @param x + * X-coordinate + * @param octaves + * Number of octaves to use + * @param frequency + * How much to alter the frequency by each octave + * @param amplitude + * How much to alter the amplitude by each octave + * @return Resulting noise + */ + public static double getNoise(double x, int octaves, double frequency, double amplitude) + { + return instance.noise(x, octaves, frequency, amplitude); + } + + /** + * Generates noise for the 2D coordinates using the specified number of octaves + * and parameters + * + * @param x + * X-coordinate + * @param y + * Y-coordinate + * @param octaves + * Number of octaves to use + * @param frequency + * How much to alter the frequency by each octave + * @param amplitude + * How much to alter the amplitude by each octave + * @return Resulting noise + */ + public static double getNoise(double x, double y, int octaves, double frequency, double amplitude) + { + return instance.noise(x, y, octaves, frequency, amplitude); + } + + /** + * Generates noise for the 3D coordinates using the specified number of octaves + * and parameters + * + * @param x + * X-coordinate + * @param y + * Y-coordinate + * @param z + * Z-coordinate + * @param octaves + * Number of octaves to use + * @param frequency + * How much to alter the frequency by each octave + * @param amplitude + * How much to alter the amplitude by each octave + * @return Resulting noise + */ + public static double getNoise(double x, double y, double z, int octaves, double frequency, double amplitude) + { + return instance.noise(x, y, z, octaves, frequency, amplitude); + } +} diff --git a/src/main/java/ninja/bytecode/iris/util/BiomeLayer.java b/src/main/java/ninja/bytecode/iris/util/BiomeLayer.java deleted file mode 100644 index a2c4754be..000000000 --- a/src/main/java/ninja/bytecode/iris/util/BiomeLayer.java +++ /dev/null @@ -1,219 +0,0 @@ -package ninja.bytecode.iris.util; - -import java.util.function.Function; - -import org.bukkit.Material; -import org.bukkit.block.Biome; - -import mortar.lang.collection.GList; -import mortar.lang.collection.GMap; -import mortar.logic.format.F; -import mortar.util.text.C; -import ninja.bytecode.iris.generator.IrisGenerator; -import ninja.bytecode.iris.pack.BiomeType; -import ninja.bytecode.iris.pack.IrisBiome; -import ninja.bytecode.iris.util.PolygonGenerator.EnumPolygonGenerator; -import ninja.bytecode.shuriken.collections.KSet; -import ninja.bytecode.shuriken.logging.L; -import ninja.bytecode.shuriken.math.CNG; -import ninja.bytecode.shuriken.math.RNG; - -public class BiomeLayer -{ - public static final IrisBiome VOID = new IrisBiome("Master", Biome.VOID).height(-1).dirt(MB.of(Material.END_BRICKS)).seal(RNG.r); - private GList children; - private EnumPolygonGenerator gen; - private IrisBiome biome; - private IrisGenerator iris; - - public BiomeLayer(IrisGenerator iris, IrisBiome biome) - { - this.biome = biome == null ? VOID : biome; - this.iris = iris; - this.children = new GList<>(); - } - - public void compileChildren(double scale, int octaves, Function factory, boolean inf) - { - if(gen != null) - { - return; - } - - if(children.isEmpty()) - { - gen = null; - return; - } - - GList b = new GList<>(); - GMap rarities = new GMap<>(); - for(BiomeLayer i : getChildren()) - { - b.add(i); - rarities.put(i, i.getBiome().getRarity()); - } - - if(!getBiome().equals(VOID)) - { - b.add(this); - rarities.put(this, getBiome().getRarity()); - } - - gen = new EnumPolygonGenerator<>(iris.getRTerrain().nextParallelRNG(1022 + getBiome().getRealBiome().ordinal()), scale, octaves, b, rarities, factory).useRarity(); - - for(BiomeLayer i : getChildren()) - { - i.compileChildren(scale, octaves, factory, inf); - } - } - - private IrisBiome computeBiome(double x, double z, GList f) - { - if(gen != null) - { - BiomeLayer b = gen.getChoice(x, z); - - if(b.biome.equals(biome)) - { - return biome; - } - - if(f.contains(b.getBiome().getName())) - { - f.add("..."); - f.add(b.getBiome().getName()); - L.w(C.YELLOW + "Cyclic Biome Heiarchy Detected! " + C.RED + f.toString(C.GRAY + " -> " + C.RED)); - return b.biome; - } - - f.add(b.getBiome().getName()); - - return b.computeBiome(x, z, f); - } - - return getBiome(); - } - - public IrisBiome computeBiome(double x, double z) - { - return computeBiome(x, z, new GList()); - } - - public void addLayer(IrisBiome biome) - { - addLayer(new BiomeLayer(iris, biome)); - } - - public void addLayer(BiomeLayer layer) - { - getChildren().add(layer); - } - - public IrisBiome getBiome() - { - return biome; - } - - public GList getChildren() - { - return children; - } - - public void setChildren(GList children) - { - this.children = children; - } - - public void print(int indent) - { - print(0, F.repeat(" ", indent)); - } - - private void print(int index, String indent) - { - L.i(C.GRAY + F.repeat(indent, index) + "Layer " + C.DARK_GREEN + getBiome().getName() + C.GRAY + "(" + C.GOLD + getBiome().getRarityString() + C.GRAY + ")" + (getBiome().getGenAmplifier() != 0.35 ? C.DARK_AQUA + " A: " + getBiome().getGenAmplifier() : "") + (getBiome().getHeight() != 0.0 ? C.DARK_RED + " H: " + getBiome().getHeight() : "") + (getBiome().hasCliffs() ? C.DARK_PURPLE + " C: " + getBiome().getCliffChance() + " x " + getBiome().getCliffScale() : "")); - L.flush(); - if(!getBiome().getSchematicGroups().isEmpty()) - { - for(String i : getBiome().getSchematicGroups().k()) - { - String f = ""; - double percent = getBiome().getSchematicGroups().get(i); - - if(percent > 1D) - { - f = (int) percent + " + " + F.pc(percent - (int) percent, percent - (int) percent >= 0.01 ? 0 : 3); - } - - else - { - f = F.pc(percent, percent >= 0.01 ? 0 : 3); - } - - L.i(C.GRAY + F.repeat(indent, index + 1) + "Object " + C.GOLD + i + C.GRAY + " at " + C.GOLD + f + C.GRAY + " (" + F.f(iris.getDimension().getObjectGroup(i).size()) + " variants)"); - } - } - - L.flush(); - for(BiomeLayer i : children) - { - i.print(index + 1, indent); - } - } - - public static BiomeLayer compile(IrisGenerator g, double scale, int octaves, Function factory) - { - return compile(g, scale, octaves, factory, false); - } - - public static BiomeLayer compile(IrisGenerator g, double scale, int octaves, Function factory, boolean inf) - { - GMap components = new GMap<>(); - - for(IrisBiome i : g.getDimension().getBiomes()) - { - if(i.getType().equals(BiomeType.LAND)) - { - components.put(i.getName(), new BiomeLayer(g, i)); - } - } - - KSet deject = new KSet<>(); - - for(String i : components.keySet()) - { - BiomeLayer b = components.get(i); - - for(String j : b.getBiome().getParents()) - { - try - { - components.get(j).addLayer(b); - deject.add(i); - } - - catch(Throwable e) - { - L.w(C.YELLOW + "Cannot find Biome " + C.RED + j + C.YELLOW + " (" + C.WHITE + b.getBiome().getName() + C.YELLOW + "'s so-called 'parent'.)"); - } - } - } - - BiomeLayer master = new BiomeLayer(g, null); - - for(String i : components.k()) - { - if(deject.contains(i)) - { - continue; - } - - master.addLayer(components.get(i)); - } - - master.compileChildren(scale, octaves, factory, inf); - - return master; - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/BorderCheck.java b/src/main/java/ninja/bytecode/iris/util/BorderCheck.java deleted file mode 100644 index 28758325e..000000000 --- a/src/main/java/ninja/bytecode/iris/util/BorderCheck.java +++ /dev/null @@ -1,7 +0,0 @@ -package ninja.bytecode.iris.util; - -@FunctionalInterface -public interface BorderCheck -{ - public T get(double x, double z); -} diff --git a/src/main/java/ninja/bytecode/iris/util/Borders.java b/src/main/java/ninja/bytecode/iris/util/Borders.java deleted file mode 100644 index adfe50a03..000000000 --- a/src/main/java/ninja/bytecode/iris/util/Borders.java +++ /dev/null @@ -1,44 +0,0 @@ -package ninja.bytecode.iris.util; - -import ninja.bytecode.shuriken.math.M; - -public class Borders -{ - public static double getDistanceToBorder(double x, double z, int samples, double minRadius, double maxRadius, double jump, BorderCheck check) - { - double offset = 0; - double fract = 1; - - for(double i = minRadius; i < maxRadius; i += jump * fract) - { - offset += jump / 3D; - fract += 0.333; - - if(isBorderWithin(x, z, samples, maxRadius, offset, check)) - { - return minRadius; - } - } - - return maxRadius; - } - - public static boolean isBorderWithin(double x, double z, int samples, double radius, double offset, BorderCheck check) - { - T center = check.get(x, z); - double ajump = Math.toRadians(360D / (double) samples) + offset; - - for(int i = 0; i < samples; i++) - { - double dx = M.sin((float) ajump * i) * radius; - double dz = M.cos((float) ajump * i) * radius; - - if(!center.equals(check.get(x + dx, z + dz))) - { - return true; - } - } - - return false; - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/CDou.java b/src/main/java/ninja/bytecode/iris/util/CDou.java deleted file mode 100644 index c4c099d0f..000000000 --- a/src/main/java/ninja/bytecode/iris/util/CDou.java +++ /dev/null @@ -1,49 +0,0 @@ -package ninja.bytecode.iris.util; - -public class CDou -{ - private double number; - private double max; - - public CDou(double max) - { - number = 0; - this.max = max; - } - - public CDou set(double n) - { - number = n; - circ(); - return this; - } - - public CDou add(double a) - { - number += a; - circ(); - return this; - } - - public CDou sub(double a) - { - number -= a; - circ(); - return this; - } - - public double get() - { - return number; - } - - public void circ() - { - if(number < 0) - { - number = max - (Math.abs(number) > max ? max : Math.abs(number)); - } - - number = number % (max); - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/Catalyst12.java b/src/main/java/ninja/bytecode/iris/util/Catalyst12.java deleted file mode 100644 index 7d3e3b49a..000000000 --- a/src/main/java/ninja/bytecode/iris/util/Catalyst12.java +++ /dev/null @@ -1,52 +0,0 @@ -package ninja.bytecode.iris.util; - -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; - -import net.minecraft.server.v1_12_R1.IBlockData; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.shuriken.execution.J; - -public class Catalyst12 -{ - public static void waitForChunk(World w, int x, int z) - { - if(!w.isChunkLoaded(x, z)) - { - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> w.loadChunk(x, z, true)); - } - - int i = 0; - while(!w.isChunkLoaded(x, z) && i < 20) - { - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> w.loadChunk(x, z, true)); - J.sleep(50); - i++; - } - } - - @SuppressWarnings("deprecation") - public static void setBlock(World wo, int x, int y, int z, MB m) - { - if(y > wo.getMaxHeight()) - { - return; - } - - net.minecraft.server.v1_12_R1.World w = ((CraftWorld) wo).getHandle(); - net.minecraft.server.v1_12_R1.Chunk chunk = w.getChunkAt(x >> 4, z >> 4); - int combined = m.material.getId() + (m.data << 12); - IBlockData ibd = net.minecraft.server.v1_12_R1.Block.getByCombinedId(combined); - - if(chunk.getSections()[y >> 4] == null) - { - chunk.getSections()[y >> 4] = new net.minecraft.server.v1_12_R1.ChunkSection(y >> 4 << 4, chunk.world.worldProvider.m()); - } - - net.minecraft.server.v1_12_R1.ChunkSection sec = chunk.getSections()[y >> 4]; - sec.setType(x & 15, y & 15, z & 15, ibd); - } - - -} \ No newline at end of file diff --git a/src/main/java/ninja/bytecode/iris/util/ChancedPopulator.java b/src/main/java/ninja/bytecode/iris/util/ChancedPopulator.java deleted file mode 100644 index 0f48586be..000000000 --- a/src/main/java/ninja/bytecode/iris/util/ChancedPopulator.java +++ /dev/null @@ -1,74 +0,0 @@ -package ninja.bytecode.iris.util; - -import java.util.Random; - -import org.bukkit.Chunk; -import org.bukkit.World; -import org.bukkit.generator.BlockPopulator; - -import ninja.bytecode.shuriken.math.M; - -public abstract class ChancedPopulator extends BlockPopulator -{ - private final double chance; - - public ChancedPopulator(double chance) - { - this.chance = chance; - } - - @Override - public void populate(World world, Random random, Chunk source) - { - if(chance == 0) - { - return; - } - - if(chance > 0 && chance < 1 && M.r(chance)) - { - doPopulate(world, random, source, (source.getX() << 4) + random.nextInt(16), (source.getZ() << 4) + random.nextInt(16)); - } - - if(chance > 1) - { - for(int i = 0; i < (int) chance; i++) - { - doPopulate(world, random, source, (source.getX() << 4) + random.nextInt(16), (source.getZ() << 4) + random.nextInt(16)); - } - - if(M.r(chance - ((int) chance))) - { - doPopulate(world, random, source, (source.getX() << 4) + random.nextInt(16), (source.getZ() << 4) + random.nextInt(16)); - } - } - } - - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - long temp; - temp = Double.doubleToLongBits(chance); - result = prime * result + (int) (temp ^ (temp >>> 32)); - return result; - } - - @Override - public boolean equals(Object obj) - { - if(this == obj) - return true; - if(obj == null) - return false; - if(getClass() != obj.getClass()) - return false; - ChancedPopulator other = (ChancedPopulator) obj; - if(Double.doubleToLongBits(chance) != Double.doubleToLongBits(other.chance)) - return false; - return true; - } - - public abstract void doPopulate(World world, Random random, Chunk source, int x, int z); -} diff --git a/src/main/java/ninja/bytecode/iris/util/ChronoQueue.java b/src/main/java/ninja/bytecode/iris/util/ChronoQueue.java deleted file mode 100644 index 4f07b3025..000000000 --- a/src/main/java/ninja/bytecode/iris/util/ChronoQueue.java +++ /dev/null @@ -1,71 +0,0 @@ -package ninja.bytecode.iris.util; - -import org.bukkit.Bukkit; - -import ninja.bytecode.iris.Iris; -import ninja.bytecode.shuriken.bench.PrecisionStopwatch; -import ninja.bytecode.shuriken.execution.J; -import ninja.bytecode.shuriken.execution.Queue; -import ninja.bytecode.shuriken.execution.ShurikenQueue; -import ninja.bytecode.shuriken.logging.L; - -public class ChronoQueue -{ - private PrecisionStopwatch s; - private Queue q; - private double limit; - private int jobLimit; - private boolean die; - private int j; - - public ChronoQueue(double limit, int jobLimit) - { - die = false; - this.limit = limit; - this.jobLimit = jobLimit; - s = new PrecisionStopwatch(); - j = Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, this::tick, 0, 0); - q = new ShurikenQueue<>(); - } - - public void close() - { - J.attempt(() -> Bukkit.getScheduler().cancelTask(j)); - } - - public void dieSlowly() - { - die = true; - } - - public void queue(Runnable r) - { - q.queue(r); - } - - private void tick() - { - s.reset(); - s.begin(); - - while(q.hasNext() && (s.getMilliseconds() < limit || q.size() > jobLimit)) - { - try - { - q.next().run(); - } - - catch(Throwable e) - { - L.ex(e); - } - } - - s.end(); - - if(q.size() == 0 && die) - { - close(); - } - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/ChunkPlan.java b/src/main/java/ninja/bytecode/iris/util/ChunkPlan.java deleted file mode 100644 index cf59e0ba2..000000000 --- a/src/main/java/ninja/bytecode/iris/util/ChunkPlan.java +++ /dev/null @@ -1,138 +0,0 @@ -package ninja.bytecode.iris.util; - -import ninja.bytecode.iris.pack.IrisBiome; -import ninja.bytecode.shuriken.collections.KList; -import ninja.bytecode.shuriken.collections.KMap; - -public class ChunkPlan -{ - private final KMap realHeightCache; - private final KMap> caveHeightCache; - private final KMap realWaterHeightCache; - private final KMap heightCache; - private final KMap biomeCache; - - public ChunkPlan() - { - this.caveHeightCache = new KMap<>(); - this.realHeightCache = new KMap<>(); - this.realWaterHeightCache = new KMap<>(); - this.heightCache = new KMap<>(); - this.biomeCache = new KMap<>(); - } - - public IrisBiome getBiome(int x, int z) - { - return biomeCache.get(new SChunkVector(x, z)); - } - - public void setBiome(int x, int z, IrisBiome cng) - { - biomeCache.put(new SChunkVector(x, z), cng); - } - - public double getHeight(int x, int z) - { - SChunkVector c = new SChunkVector(x, z); - if(hasHeight(c)) - { - return heightCache.get(c); - } - - return -1; - } - - public int getRealHeight(int x, int z) - { - SChunkVector c = new SChunkVector(x, z); - if(realHeightCache.containsKey(c)) - { - return realHeightCache.get(c); - } - - return 0; - } - - public KList getCaveHeights(int x, int z) - { - SChunkVector c = new SChunkVector(x, z); - if(caveHeightCache.containsKey(c)) - { - return caveHeightCache.get(c); - } - - return null; - } - - public int getRealWaterHeight(int x, int z) - { - SChunkVector c = new SChunkVector(x, z); - - if(realWaterHeightCache.containsKey(c)) - { - return realWaterHeightCache.get(c); - } - - return 0; - } - - public boolean hasHeight(SChunkVector c) - { - return heightCache.containsKey(c); - } - - public boolean hasHeight(int x, int z) - { - return hasHeight(new SChunkVector(x, z)); - } - - public void setHeight(SChunkVector c, double h) - { - heightCache.put(c, h); - } - - public void setCaveHeight(SChunkVector c, int h) - { - if(!caveHeightCache.containsKey(c)) - { - caveHeightCache.put(c, new KList<>()); - } - - caveHeightCache.get(c).add(h); - } - - public void setRealHeight(SChunkVector c, int h) - { - realHeightCache.put(c, h); - } - - public void setRealHeight(int x, int z, int h) - { - setRealHeight(new SChunkVector(x, z), h); - } - - public void setCaveHeight(int x, int z, int h) - { - setCaveHeight(new SChunkVector(x, z), h); - } - - public void setRealWaterHeight(SChunkVector c, int h) - { - realWaterHeightCache.put(c, h); - } - - public void setRealWaterHeight(int x, int z, int h) - { - setRealWaterHeight(new SChunkVector(x, z), h); - } - - public void setHeight(int x, int z, double h) - { - setHeight(new SChunkVector(x, z), h); - } - - public int biomeCacheSize() - { - return biomeCache.size(); - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/ChunkSpliceListener.java b/src/main/java/ninja/bytecode/iris/util/ChunkSpliceListener.java deleted file mode 100644 index 381288cd4..000000000 --- a/src/main/java/ninja/bytecode/iris/util/ChunkSpliceListener.java +++ /dev/null @@ -1,14 +0,0 @@ -package ninja.bytecode.iris.util; - -import java.util.Random; - -import org.bukkit.World; -import org.bukkit.generator.ChunkGenerator.BiomeGrid; - -import ninja.bytecode.iris.generator.atomics.AtomicChunkData; - -@FunctionalInterface -public interface ChunkSpliceListener -{ - public AtomicChunkData onSpliceAvailable(World world, Random random, int x, int z, BiomeGrid biome); -} diff --git a/src/main/java/ninja/bytecode/iris/util/ColoredEffect.java b/src/main/java/ninja/bytecode/iris/util/ColoredEffect.java deleted file mode 100644 index 03005f5f8..000000000 --- a/src/main/java/ninja/bytecode/iris/util/ColoredEffect.java +++ /dev/null @@ -1,10 +0,0 @@ -package ninja.bytecode.iris.util; - -import java.awt.Color; - -public interface ColoredEffect -{ - public ColoredEffect setColor(Color color); - - public Color getColor(); -} diff --git a/src/main/java/ninja/bytecode/iris/util/Cuboid.java b/src/main/java/ninja/bytecode/iris/util/Cuboid.java deleted file mode 100644 index a65b13aff..000000000 --- a/src/main/java/ninja/bytecode/iris/util/Cuboid.java +++ /dev/null @@ -1,921 +0,0 @@ -package ninja.bytecode.iris.util; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -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 org.bukkit.entity.LivingEntity; -import org.bukkit.material.MaterialData; - -import ninja.bytecode.shuriken.collections.KList; - -/** - * Cuboids - * - * @author cyberpwn - */ -public class Cuboid implements Iterable, Cloneable, ConfigurationSerializable -{ - protected final String worldName; - protected int x1, y1, z1; - protected int x2, y2, z2; - - /** - * Construct a Cuboid given two Location objects which represent any two corners - * of the Cuboid. - * - * @param l1 - * one of the corners - * @param l2 - * the other corner - */ - public Cuboid(Location l1, Location l2) - { - if(!l1.getWorld().equals(l2.getWorld())) - { - throw new IllegalArgumentException("locations must be on the same world"); - } - - worldName = l1.getWorld().getName(); - 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()); - } - - public KList getLivingEntities() - { - return new KList(new GListAdapter() - { - @Override - public LivingEntity onAdapt(Entity from) - { - if(from instanceof LivingEntity) - { - return (LivingEntity) from; - } - - return null; - } - }.adapt(getEntities())); - } - - 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. - * - * @param l1 - * location of the Cuboid - */ - public Cuboid(Location l1) - { - this(l1, l1); - } - - /** - * Copy constructor. - * - * @param other - * the Cuboid to copy - */ - public Cuboid(Cuboid other) - { - this(other.getWorld().getName(), other.x1, other.y1, other.z1, other.x2, other.y2, other.z2); - } - - /** - * Construct a Cuboid in the given World and xyz co-ordinates - * - * @param world - * the Cuboid's world - * @param x1 - * X co-ordinate of corner 1 - * @param y1 - * Y co-ordinate of corner 1 - * @param z1 - * Z co-ordinate of corner 1 - * @param x2 - * X co-ordinate of corner 2 - * @param y2 - * Y co-ordinate of corner 2 - * @param z2 - * Z co-ordinate of corner 2 - */ - public Cuboid(World world, int x1, int y1, int z1, int x2, int y2, int z2) - { - this.worldName = world.getName(); - this.x1 = Math.min(x1, x2); - this.x2 = Math.max(x1, x2); - this.y1 = Math.min(y1, y2); - this.y2 = Math.max(y1, y2); - this.z1 = Math.min(z1, z2); - this.z2 = Math.max(z1, z2); - } - - /** - * Construct a Cuboid in the given world name and xyz co-ordinates. - * - * @param worldName - * the Cuboid's world name - * @param x1 - * X co-ordinate of corner 1 - * @param y1 - * Y co-ordinate of corner 1 - * @param z1 - * Z co-ordinate of corner 1 - * @param x2 - * X co-ordinate of corner 2 - * @param y2 - * Y co-ordinate of corner 2 - * @param z2 - * Z co-ordinate of corner 2 - */ - private Cuboid(String worldName, int x1, int y1, int z1, int x2, int y2, int z2) - { - this.worldName = worldName; - this.x1 = Math.min(x1, x2); - this.x2 = Math.max(x1, x2); - this.y1 = Math.min(y1, y2); - this.y2 = Math.max(y1, y2); - this.z1 = Math.min(z1, z2); - this.z2 = Math.max(z1, z2); - } - - public Cuboid(Map map) - { - worldName = (String) map.get("worldName"); - x1 = (Integer) map.get("x1"); - x2 = (Integer) map.get("x2"); - y1 = (Integer) map.get("y1"); - y2 = (Integer) map.get("y2"); - z1 = (Integer) map.get("z1"); - z2 = (Integer) map.get("z2"); - } - - @Override - public Map serialize() - { - Map map = new HashMap(); - map.put("worldName", worldName); - map.put("x1", x1); - map.put("y1", y1); - map.put("z1", z1); - map.put("x2", x2); - map.put("y2", y2); - map.put("z2", z2); - return map; - } - - public Cuboid flatten(int level) - { - return new Cuboid(getWorld(), x1, level, z1, x2, level, z2); - } - - /** - * Get the Location of the lower northeast corner of the Cuboid (minimum XYZ - * co-ordinates). - * - * @return Location of the lower northeast corner - */ - public Location getLowerNE() - { - return new Location(getWorld(), x1, y1, z1); - } - - /** - * Get the Location of the upper southwest corner of the Cuboid (maximum XYZ - * co-ordinates). - * - * @return Location of the upper southwest corner - */ - public Location getUpperSW() - { - return new Location(getWorld(), x2, y2, z2); - } - - /** - * Get the the centre of the Cuboid - * - * @return Location at the centre of the Cuboid - */ - public Location getCenter() - { - int x1 = getUpperX() + 1; - int y1 = getUpperY() + 1; - int z1 = getUpperZ() + 1; - return new Location(getWorld(), getLowerX() + (x1 - getLowerX()) / 2.0, getLowerY() + (y1 - getLowerY()) / 2.0, getLowerZ() + (z1 - getLowerZ()) / 2.0); - } - - /** - * Get the Cuboid's world. - * - * @return the World object representing this Cuboid's world - * @throws IllegalStateException - * if the world is not loaded - */ - public World getWorld() - { - World world = Bukkit.getWorld(worldName); - if(world == null) - { - throw new IllegalStateException("world '" + worldName + "' is not loaded"); - } - return world; - } - - /** - * Get the size of this Cuboid along the X axis - * - * @return Size of Cuboid along the X axis - */ - public int getSizeX() - { - return (x2 - x1) + 1; - } - - /** - * Get the size of this Cuboid along the Y axis - * - * @return Size of Cuboid along the Y axis - */ - public int getSizeY() - { - return (y2 - y1) + 1; - } - - /** - * Get the size of this Cuboid along the Z axis - * - * @return Size of Cuboid along the Z axis - */ - public int getSizeZ() - { - return (z2 - z1) + 1; - } - - /** - * Get the cuboid dimensions - * - * @return the dimensions - */ - public Dimension getDimension() - { - return new Dimension(getSizeX(), getSizeY(), getSizeZ()); - } - - /** - * Get the minimum X co-ordinate of this Cuboid - * - * @return the minimum X co-ordinate - */ - public int getLowerX() - { - return x1; - } - - /** - * Get the minimum Y co-ordinate of this Cuboid - * - * @return the minimum Y co-ordinate - */ - public int getLowerY() - { - return y1; - } - - /** - * Get the minimum Z co-ordinate of this Cuboid - * - * @return the minimum Z co-ordinate - */ - public int getLowerZ() - { - return z1; - } - - /** - * Get the maximum X co-ordinate of this Cuboid - * - * @return the maximum X co-ordinate - */ - public int getUpperX() - { - return x2; - } - - /** - * Get the maximum Y co-ordinate of this Cuboid - * - * @return the maximum Y co-ordinate - */ - public int getUpperY() - { - return y2; - } - - /** - * Get the maximum Z co-ordinate of this Cuboid - * - * @return the maximum Z co-ordinate - */ - public int getUpperZ() - { - return z2; - } - - /** - * Get the Blocks at the eight corners of the Cuboid. - * - * @return array of Block objects representing the Cuboid corners - */ - public Block[] corners() - { - Block[] res = new Block[8]; - World w = getWorld(); - res[0] = w.getBlockAt(x1, y1, z1); - res[1] = w.getBlockAt(x1, y1, z2); - res[2] = w.getBlockAt(x1, y2, z1); - res[3] = w.getBlockAt(x1, y2, z2); - res[4] = w.getBlockAt(x2, y1, z1); - res[5] = w.getBlockAt(x2, y1, z2); - res[6] = w.getBlockAt(x2, y2, z1); - res[7] = w.getBlockAt(x2, y2, z2); - return res; - } - - /** - * Expand the Cuboid in the given direction by the given amount. Negative - * amounts will shrink the Cuboid in the given direction. Shrinking a cuboid's - * face past the opposite face is not an error and will return a valid Cuboid. - * - * @param dir - * the direction in which to expand - * @param amount - * the number of blocks by which to expand - * @return a new Cuboid expanded by the given direction and amount - */ - public Cuboid expand(CuboidDirection dir, int amount) - { - switch(dir) - { - case North: - return new Cuboid(worldName, x1 - amount, y1, z1, x2, y2, z2); - case South: - return new Cuboid(worldName, x1, y1, z1, x2 + amount, y2, z2); - case East: - return new Cuboid(worldName, x1, y1, z1 - amount, x2, y2, z2); - case West: - return new Cuboid(worldName, x1, y1, z1, x2, y2, z2 + amount); - case Down: - return new Cuboid(worldName, x1, y1 - amount, z1, x2, y2, z2); - case Up: - return new Cuboid(worldName, x1, y1, z1, x2, y2 + amount, z2); - default: - throw new IllegalArgumentException("invalid direction " + dir); - } - } - - public Cuboid expand(Direction dir, int amount) - { - int ax = dir.toVector().getBlockX() == 1 ? amount : 0; - int sx = dir.toVector().getBlockX() == -1 ? -amount : 0; - int ay = dir.toVector().getBlockY() == 1 ? amount : 0; - int sy = dir.toVector().getBlockY() == -1 ? -amount : 0; - int az = dir.toVector().getBlockZ() == 1 ? amount : 0; - int sz = dir.toVector().getBlockZ() == -1 ? -amount : 0; - return new Cuboid(worldName, x1 + sx, y1 + sy, z1 + sz, x2 + ax, y2 + ay, z2 + az); - } - - /** - * Shift the Cuboid in the given direction by the given amount. - * - * @param dir - * the direction in which to shift - * @param amount - * the number of blocks by which to shift - * @return a new Cuboid shifted by the given direction and amount - */ - public Cuboid shift(CuboidDirection dir, int amount) - { - return expand(dir, amount).expand(dir.opposite(), -amount); - } - - /** - * Outset (grow) the Cuboid in the given direction by the given amount. - * - * @param dir - * the direction in which to outset (must be Horizontal, Vertical, or - * Both) - * @param amount - * the number of blocks by which to outset - * @return a new Cuboid outset by the given direction and amount - */ - public Cuboid outset(CuboidDirection dir, int amount) - { - Cuboid c; - switch(dir) - { - case Horizontal: - c = expand(CuboidDirection.North, amount).expand(CuboidDirection.South, amount).expand(CuboidDirection.East, amount).expand(CuboidDirection.West, amount); - break; - case Vertical: - c = expand(CuboidDirection.Down, amount).expand(CuboidDirection.Up, amount); - break; - case Both: - c = outset(CuboidDirection.Horizontal, amount).outset(CuboidDirection.Vertical, amount); - break; - default: - throw new IllegalArgumentException("invalid direction " + dir); - } - return c; - } - - /** - * Inset (shrink) the Cuboid in the given direction by the given amount. - * Equivalent to calling outset() with a negative amount. - * - * @param dir - * the direction in which to inset (must be Horizontal, Vertical, or - * Both) - * @param amount - * the number of blocks by which to inset - * @return a new Cuboid inset by the given direction and amount - */ - public Cuboid inset(CuboidDirection dir, int amount) - { - return outset(dir, -amount); - } - - /** - * Return true if the point at (x,y,z) is contained within this Cuboid. - * - * @param x - * the X co-ordinate - * @param y - * the Y co-ordinate - * @param z - * the Z co-ordinate - * @return true if the given point is within this Cuboid, false otherwise - */ - public boolean contains(int x, int y, int z) - { - return x >= x1 && x <= x2 && y >= y1 && y <= y2 && z >= z1 && z <= z2; - } - - /** - * Check if the given Block is contained within this Cuboid. - * - * @param b - * the Block to check for - * @return true if the Block is within this Cuboid, false otherwise - */ - public boolean contains(Block b) - { - return contains(b.getLocation()); - } - - /** - * Check if the given Location is contained within this Cuboid. - * - * @param l - * the Location to check for - * @return true if the Location is within this Cuboid, false otherwise - */ - public boolean contains(Location l) - { - return worldName.equals(l.getWorld().getName()) && contains(l.getBlockX(), l.getBlockY(), l.getBlockZ()); - } - - /** - * Get the volume of this Cuboid. - * - * @return the Cuboid volume, in blocks - */ - public int volume() - { - return getSizeX() * getSizeY() * getSizeZ(); - } - - /** - * Get the average light level of all empty (air) blocks in the Cuboid. Returns - * 0 if there are no empty blocks. - * - * @return the average light level of this Cuboid - */ - public byte averageLightLevel() - { - long total = 0; - int n = 0; - for(Block b : this) - { - if(b.isEmpty()) - { - total += b.getLightLevel(); - ++n; - } - } - return n > 0 ? (byte) (total / n) : 0; - } - - /** - * Contract the Cuboid, returning a Cuboid with any air around the edges - * removed, just large enough to include all non-air blocks. - * - * @return a new Cuboid with no external air blocks - */ - public Cuboid contract() - { - return this.contract(CuboidDirection.Down).contract(CuboidDirection.South).contract(CuboidDirection.East).contract(CuboidDirection.Up).contract(CuboidDirection.North).contract(CuboidDirection.West); - } - - /** - * Contract the Cuboid in the given direction, returning a new Cuboid which has - * no exterior empty space. E.g. a direction of Down will push the top face - * downwards as much as possible. - * - * @param dir - * the direction in which to contract - * @return a new Cuboid contracted in the given direction - */ - public Cuboid contract(CuboidDirection dir) - { - Cuboid face = getFace(dir.opposite()); - switch(dir) - { - case Down: - while(face.containsOnly(Material.AIR) && face.getLowerY() > this.getLowerY()) - { - face = face.shift(CuboidDirection.Down, 1); - } - return new Cuboid(worldName, x1, y1, z1, x2, face.getUpperY(), z2); - case Up: - while(face.containsOnly(Material.AIR) && face.getUpperY() < this.getUpperY()) - { - face = face.shift(CuboidDirection.Up, 1); - } - return new Cuboid(worldName, x1, face.getLowerY(), z1, x2, y2, z2); - case North: - while(face.containsOnly(Material.AIR) && face.getLowerX() > this.getLowerX()) - { - face = face.shift(CuboidDirection.North, 1); - } - return new Cuboid(worldName, x1, y1, z1, face.getUpperX(), y2, z2); - case South: - while(face.containsOnly(Material.AIR) && face.getUpperX() < this.getUpperX()) - { - face = face.shift(CuboidDirection.South, 1); - } - return new Cuboid(worldName, face.getLowerX(), y1, z1, x2, y2, z2); - case East: - while(face.containsOnly(Material.AIR) && face.getLowerZ() > this.getLowerZ()) - { - face = face.shift(CuboidDirection.East, 1); - } - return new Cuboid(worldName, x1, y1, z1, x2, y2, face.getUpperZ()); - case West: - while(face.containsOnly(Material.AIR) && face.getUpperZ() < this.getUpperZ()) - { - face = face.shift(CuboidDirection.West, 1); - } - return new Cuboid(worldName, x1, y1, face.getLowerZ(), x2, y2, z2); - default: - throw new IllegalArgumentException("Invalid direction " + dir); - } - } - - /** - * Get the Cuboid representing the face of this Cuboid. The resulting Cuboid - * will be one block thick in the axis perpendicular to the requested face. - * - * @param dir - * which face of the Cuboid to get - * @return the Cuboid representing this Cuboid's requested face - */ - public Cuboid getFace(CuboidDirection dir) - { - switch(dir) - { - case Down: - return new Cuboid(worldName, x1, y1, z1, x2, y1, z2); - case Up: - return new Cuboid(worldName, x1, y2, z1, x2, y2, z2); - case North: - return new Cuboid(worldName, x1, y1, z1, x1, y2, z2); - case South: - return new Cuboid(worldName, x2, y1, z1, x2, y2, z2); - case East: - return new Cuboid(worldName, x1, y1, z1, x2, y2, z1); - case West: - return new Cuboid(worldName, x1, y1, z2, x2, y2, z2); - default: - throw new IllegalArgumentException("Invalid direction " + dir); - } - } - - /** - * Check if the Cuboid contains only blocks of the given type - * - * @param material - * the material to check for - * @return true if this Cuboid contains only blocks of the given type - */ - public boolean containsOnly(Material material) - { - for(Block b : this) - { - if(b.getType() != material) - { - return false; - } - } - return true; - } - - /** - * Get the Cuboid big enough to hold both this Cuboid and the given one. - * - * @param other - * the other Cuboid to include - * @return a new Cuboid large enough to hold this Cuboid and the given Cuboid - */ - public Cuboid getBoundingCuboid(Cuboid other) - { - if(other == null) - { - return this; - } - - int xMin = Math.min(getLowerX(), other.getLowerX()); - int yMin = Math.min(getLowerY(), other.getLowerY()); - int zMin = Math.min(getLowerZ(), other.getLowerZ()); - int xMax = Math.max(getUpperX(), other.getUpperX()); - int yMax = Math.max(getUpperY(), other.getUpperY()); - int zMax = Math.max(getUpperZ(), other.getUpperZ()); - - return new Cuboid(worldName, xMin, yMin, zMin, xMax, yMax, zMax); - } - - /** - * Get a block relative to the lower NE point of the Cuboid. - * - * @param x - * the X co-ordinate - * @param y - * the Y co-ordinate - * @param z - * the Z co-ordinate - * @return the block at the given position - */ - public Block getRelativeBlock(int x, int y, int z) - { - return getWorld().getBlockAt(x1 + x, y1 + y, z1 + z); - } - - /** - * Get a block relative to the lower NE point of the Cuboid in the given World. - * This version of getRelativeBlock() should be used if being called many times, - * to avoid excessive calls to getWorld(). - * - * @param w - * the World - * @param x - * the X co-ordinate - * @param y - * the Y co-ordinate - * @param z - * the Z co-ordinate - * @return the block at the given position - */ - public Block getRelativeBlock(World w, int x, int y, int z) - { - return w.getBlockAt(x1 + x, y1 + y, z1 + z); - } - - /** - * Get a list of the chunks which are fully or partially contained in this - * cuboid. - * - * @return a list of Chunk objects - */ - public List getChunks() - { - List res = new ArrayList(); - - World w = getWorld(); - int x1 = getLowerX() & ~0xf; - int x2 = getUpperX() & ~0xf; - int z1 = getLowerZ() & ~0xf; - int z2 = getUpperZ() & ~0xf; - for(int x = x1; x <= x2; x += 16) - { - for(int z = z1; z <= z2; z += 16) - { - res.add(w.getChunkAt(x >> 4, z >> 4)); - } - } - return res; - } - - /** - * Set all the blocks within the Cuboid to the given block ID and data byte. - * - * @param blockId - * the block ID - * @param data - * the block data - * @deprecated use {@link #fill(MaterialData, MassBlockUpdate)} - */ - @Deprecated - public void fill(int blockId, byte data) - { - for(Block b : this) - { - b.setTypeIdAndData(blockId, data, false); - } - } - - /** - * Set all the blocks within the Cuboid to the given MaterialData, using a - * MassBlockUpdate object for fast updates. - * - * @param mat - * the MaterialData to set - * @param mbu - * the MassBlockUpdate object - */ - - /** - * Reset the light level of all blocks within this Cuboid. - */ - - /* - * (non-Javadoc) - * - * @see java.lang.Iterable#iterator() - */ - @Override - public Iterator iterator() - { - return new CuboidIterator(getWorld(), x1, y1, z1, x2, y2, z2); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#clone() - */ - @Override - public Cuboid clone() throws CloneNotSupportedException - { - return new Cuboid(this); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - @Override - public String toString() - { - return "Cuboid: " + worldName + "," + x1 + "," + y1 + "," + z1 + "=>" + x2 + "," + y2 + "," + z2; - } - - public class CuboidIterator implements Iterator - { - private World w; - private int baseX, baseY, baseZ; - private int x, y, z; - private int sizeX, sizeY, sizeZ; - - public CuboidIterator(World w, int x1, int y1, int z1, int x2, int y2, int z2) - { - this.w = w; - baseX = x1; - baseY = y1; - baseZ = z1; - sizeX = Math.abs(x2 - x1) + 1; - sizeY = Math.abs(y2 - y1) + 1; - sizeZ = Math.abs(z2 - z1) + 1; - x = y = z = 0; - } - - @Override - public boolean hasNext() - { - return x < sizeX && y < sizeY && z < sizeZ; - } - - @Override - public Block next() - { - Block b = w.getBlockAt(baseX + x, baseY + y, baseZ + z); - if(++x >= sizeX) - { - x = 0; - if(++y >= sizeY) - { - y = 0; - ++z; - } - } - return b; - } - - @Override - public void remove() - { - // nop - } - } - - public enum CuboidDirection - { - - North, - East, - South, - West, - Up, - Down, - Horizontal, - Vertical, - Both, - Unknown; - - public CuboidDirection opposite() - { - switch(this) - { - case North: - return South; - case East: - return West; - case South: - return North; - case West: - return East; - case Horizontal: - return Vertical; - case Vertical: - return Horizontal; - case Up: - return Down; - case Down: - return Up; - case Both: - return Both; - default: - return Unknown; - } - } - } - -} \ No newline at end of file diff --git a/src/main/java/ninja/bytecode/iris/util/CuboidException.java b/src/main/java/ninja/bytecode/iris/util/CuboidException.java deleted file mode 100644 index 212f9f79c..000000000 --- a/src/main/java/ninja/bytecode/iris/util/CuboidException.java +++ /dev/null @@ -1,16 +0,0 @@ -package ninja.bytecode.iris.util; - -/** - * Represents a cuboid exception - * - * @author cyberpwn - */ -public class CuboidException extends Exception -{ - public CuboidException(String string) - { - super(string); - } - - private static final long serialVersionUID = 1L; -} \ No newline at end of file diff --git a/src/main/java/ninja/bytecode/iris/util/DOP.java b/src/main/java/ninja/bytecode/iris/util/DOP.java deleted file mode 100644 index b36611738..000000000 --- a/src/main/java/ninja/bytecode/iris/util/DOP.java +++ /dev/null @@ -1,20 +0,0 @@ -package ninja.bytecode.iris.util; - -import org.bukkit.util.Vector; - -public abstract class DOP -{ - private String type; - - public DOP(String type) - { - this.type = type; - } - - public abstract Vector op(Vector v); - - public String getType() - { - return type; - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/Dimension.java b/src/main/java/ninja/bytecode/iris/util/Dimension.java deleted file mode 100644 index c9b8a0db6..000000000 --- a/src/main/java/ninja/bytecode/iris/util/Dimension.java +++ /dev/null @@ -1,86 +0,0 @@ -package ninja.bytecode.iris.util; - -/** - * Dimensions - * - * @author cyberpwn - */ -public class Dimension -{ - private final int width; - private final int height; - private final int depth; - - /** - * Make a dimension - * - * @param width - * width of this (X) - * @param height - * the height (Y) - * @param depth - * the depth (Z) - */ - public Dimension(int width, int height, int depth) - { - this.width = width; - this.height = height; - this.depth = depth; - } - - /** - * Make a dimension - * - * @param width - * width of this (X) - * @param height - * the height (Y) - */ - public Dimension(int width, int height) - { - this.width = width; - this.height = height; - this.depth = 0; - } - - /** - * Get the direction of the flat part of this dimension (null if no thin - * face) - * - * @return the direction of the flat pane or null - */ - public DimensionFace getPane() - { - if(width == 1) - { - return DimensionFace.X; - } - - if(height == 1) - { - return DimensionFace.Y; - } - - if(depth == 1) - { - return DimensionFace.Z; - } - - return null; - } - - public int getWidth() - { - return width; - } - - public int getHeight() - { - return height; - } - - public int getDepth() - { - return depth; - } -} \ No newline at end of file diff --git a/src/main/java/ninja/bytecode/iris/util/DimensionFace.java b/src/main/java/ninja/bytecode/iris/util/DimensionFace.java deleted file mode 100644 index 0db5b6b07..000000000 --- a/src/main/java/ninja/bytecode/iris/util/DimensionFace.java +++ /dev/null @@ -1,24 +0,0 @@ -package ninja.bytecode.iris.util; - -/** - * Represents a dimension (coordinates not worlds) - * - * @author cyberpwn - */ -public enum DimensionFace -{ - /** - * The X dimension (width) - */ - X, - - /** - * The Y dimension (height) - */ - Y, - - /** - * The Z dimension (depth) - */ - Z -} \ No newline at end of file diff --git a/src/main/java/ninja/bytecode/iris/util/Direction.java b/src/main/java/ninja/bytecode/iris/util/Direction.java deleted file mode 100644 index 23ee8287d..000000000 --- a/src/main/java/ninja/bytecode/iris/util/Direction.java +++ /dev/null @@ -1,534 +0,0 @@ - -package ninja.bytecode.iris.util; - -import org.bukkit.block.BlockFace; -import org.bukkit.util.Vector; - -import ninja.bytecode.iris.util.Cuboid.CuboidDirection; -import ninja.bytecode.shuriken.collections.KList; -import ninja.bytecode.shuriken.collections.KMap; - -/** - * Directions - * - * @author cyberpwn - */ -public enum Direction -{ - U(0, 1, 0, CuboidDirection.Up), - D(0, -1, 0, CuboidDirection.Down), - N(0, 0, -1, CuboidDirection.North), - S(0, 0, 1, CuboidDirection.South), - E(1, 0, 0, CuboidDirection.East), - W(-1, 0, 0, CuboidDirection.West); - - private static KMap, DOP> permute = null; - - private int x; - private int y; - private int z; - private CuboidDirection f; - - public static Direction getDirection(BlockFace f) - { - switch(f) - { - case DOWN: - return D; - case EAST: - return E; - case EAST_NORTH_EAST: - return E; - case EAST_SOUTH_EAST: - return E; - case NORTH: - return N; - case NORTH_EAST: - return N; - case NORTH_NORTH_EAST: - return N; - case NORTH_NORTH_WEST: - return N; - case NORTH_WEST: - return N; - case SELF: - return U; - case SOUTH: - return S; - case SOUTH_EAST: - return S; - case SOUTH_SOUTH_EAST: - return S; - case SOUTH_SOUTH_WEST: - return S; - case SOUTH_WEST: - return S; - case UP: - return U; - case WEST: - return W; - case WEST_NORTH_WEST: - return W; - case WEST_SOUTH_WEST: - return W; - } - - return D; - } - - @Override - public String toString() - { - switch(this) - { - case D: - return "Down"; - case E: - return "East"; - case N: - return "North"; - case S: - return "South"; - case U: - return "Up"; - case W: - return "West"; - } - - return "?"; - } - - public boolean isVertical() - { - return equals(D) || equals(U); - } - - public static Direction closest(Vector v) - { - double m = Double.MAX_VALUE; - Direction s = null; - - for(Direction i : values()) - { - Vector x = i.toVector(); - double g = x.dot(v); - - if(g < m) - { - m = g; - s = i; - } - } - - return s; - } - - public static Direction closest(Vector v, Direction... d) - { - double m = Double.MAX_VALUE; - Direction s = null; - - for(Direction i : d) - { - Vector x = i.toVector(); - double g = x.distance(v); - - if(g < m) - { - m = g; - s = i; - } - } - - return s; - } - - public static Direction closest(Vector v, KList d) - { - double m = Double.MAX_VALUE; - Direction s = null; - - for(Direction i : d) - { - Vector x = i.toVector(); - double g = x.distance(v); - - if(g < m) - { - m = g; - s = i; - } - } - - return s; - } - - public Vector toVector() - { - return new Vector(x, y, z); - } - - public boolean isCrooked(Direction to) - { - if(equals(to.reverse())) - { - return false; - } - - if(equals(to)) - { - return false; - } - - return true; - } - - private 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(GBiset i : permute.keySet()) - { - if(i.getA().equals(this) && i.getB().equals(d)) - { - return permute.get(i).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); - } - - public static Direction getDirection(Vector v) - { - Vector k = VectorMath.triNormalize(v.clone().normalize()); - - for(Direction i : udnews()) - { - if(i.x == k.getBlockX() && i.y == k.getBlockY() && i.z == k.getBlockZ()) - { - return i; - } - } - - return Direction.N; - } - - public static KList udnews() - { - return new KList().add(U, D, N, E, W, S); - } - - /** - * Get the directional value from the given byte from common directional blocks - * (MUST BE BETWEEN 0 and 5 INCLUSIVE) - * - * @param b - * the byte - * @return the direction or null if the byte is outside of the inclusive range - * 0-5 - */ - public static Direction fromByte(byte b) - { - if(b > 5 || b < 0) - { - return null; - } - - if(b == 0) - { - return D; - } - - else if(b == 1) - { - return U; - } - - else if(b == 2) - { - return N; - } - - else if(b == 3) - { - return S; - } - - else if(b == 4) - { - return W; - } - - else - { - return E; - } - } - - /** - * 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; - } - - permute = new KMap, DOP>(); - - for(Direction i : udnews()) - { - for(Direction j : udnews()) - { - GBiset b = new GBiset(i, j); - - if(i.equals(j)) - { - permute.put(b, new DOP("DIRECT") - { - @Override - public Vector op(Vector v) - { - return v; - } - }); - } - - else if(i.reverse().equals(j)) - { - if(i.isVertical()) - { - permute.put(b, new DOP("R180CCZ") - { - @Override - public Vector op(Vector v) - { - return VectorMath.rotate90CCZ(VectorMath.rotate90CCZ(v)); - } - }); - } - - else - { - permute.put(b, new DOP("R180CCY") - { - @Override - public Vector op(Vector v) - { - return VectorMath.rotate90CCY(VectorMath.rotate90CCY(v)); - } - }); - } - } - - else if(getDirection(VectorMath.rotate90CX(i.toVector())).equals(j)) - { - permute.put(b, new DOP("R90CX") - { - @Override - public Vector op(Vector v) - { - return VectorMath.rotate90CX(v); - } - }); - } - - else if(getDirection(VectorMath.rotate90CCX(i.toVector())).equals(j)) - { - permute.put(b, new DOP("R90CCX") - { - @Override - public Vector op(Vector v) - { - return VectorMath.rotate90CCX(v); - } - }); - } - - else if(getDirection(VectorMath.rotate90CY(i.toVector())).equals(j)) - { - permute.put(b, new DOP("R90CY") - { - @Override - public Vector op(Vector v) - { - return VectorMath.rotate90CY(v); - } - }); - } - - else if(getDirection(VectorMath.rotate90CCY(i.toVector())).equals(j)) - { - permute.put(b, new DOP("R90CCY") - { - @Override - public Vector op(Vector v) - { - return VectorMath.rotate90CCY(v); - } - }); - } - - else if(getDirection(VectorMath.rotate90CZ(i.toVector())).equals(j)) - { - permute.put(b, new DOP("R90CZ") - { - @Override - public Vector op(Vector v) - { - return VectorMath.rotate90CZ(v); - } - }); - } - - else if(getDirection(VectorMath.rotate90CCZ(i.toVector())).equals(j)) - { - permute.put(b, new DOP("R90CCZ") - { - @Override - public Vector op(Vector v) - { - return VectorMath.rotate90CCZ(v); - } - }); - } - - else - { - permute.put(b, new DOP("FAIL") - { - @Override - public Vector op(Vector v) - { - return v; - } - }); - } - } - } - } - - public BlockFace getFace() - { - switch(this) - { - case D: - return BlockFace.DOWN; - case E: - return BlockFace.EAST; - case N: - return BlockFace.NORTH; - case S: - return BlockFace.SOUTH; - case U: - return BlockFace.UP; - case W: - return BlockFace.WEST; - } - - return null; - } - - public Axis getAxis() - { - switch(this) - { - case D: - return Axis.Y; - case E: - return Axis.X; - case N: - return Axis.Z; - case S: - return Axis.Z; - case U: - return Axis.Y; - case W: - return Axis.X; - } - - return null; - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/GBiset.java b/src/main/java/ninja/bytecode/iris/util/GBiset.java deleted file mode 100644 index 901384c1a..000000000 --- a/src/main/java/ninja/bytecode/iris/util/GBiset.java +++ /dev/null @@ -1,77 +0,0 @@ -package ninja.bytecode.iris.util; - - -import java.io.Serializable; - -/** - * A Biset - * - * @author cyberpwn - * - * @param - * the first object type - * @param - * the second object type - */ -@SuppressWarnings("hiding") -public class GBiset implements Serializable -{ - private static final long serialVersionUID = 1L; - private A a; - private B b; - - /** - * Create a new Biset - * - * @param a - * the first object - * @param b - * the second object - */ - public GBiset(A a, B b) - { - this.a = a; - this.b = b; - } - - /** - * Get the object of the type A - * - * @return the first object - */ - public A getA() - { - return a; - } - - /** - * Set the first object - * - * @param a - * the first object A - */ - public void setA(A a) - { - this.a = a; - } - - /** - * Get the second object - * - * @return the second object - */ - public B getB() - { - return b; - } - - /** - * Set the second object - * - * @param b - */ - public void setB(B b) - { - this.b = b; - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/GListAdapter.java b/src/main/java/ninja/bytecode/iris/util/GListAdapter.java deleted file mode 100644 index d6c0d702b..000000000 --- a/src/main/java/ninja/bytecode/iris/util/GListAdapter.java +++ /dev/null @@ -1,51 +0,0 @@ -package ninja.bytecode.iris.util; - - -import java.util.List; - -import ninja.bytecode.shuriken.collections.KList; - -/** - * Adapts a list of objects into a list of other objects - * - * @author cyberpwn - * @param - * the from object in lists (the item INSIDE the list) - * @param - * the to object in lists (the item INSIDE the list) - */ -public abstract class GListAdapter -{ - /** - * Adapts a list of FROM to a list of TO - * - * @param from - * the from list - * @return the to list - */ - public List adapt(List from) - { - List adapted = new KList(); - - for(FROM i : from) - { - TO t = onAdapt(i); - - if(t != null) - { - adapted.add(onAdapt(i)); - } - } - - return adapted; - } - - /** - * Adapts a list object FROM to TO for use with the adapt method - * - * @param from - * the from object - * @return the to object - */ - public abstract TO onAdapt(FROM from); -} diff --git a/src/main/java/ninja/bytecode/iris/util/GRT.java b/src/main/java/ninja/bytecode/iris/util/GRT.java deleted file mode 100644 index 9285a4d9f..000000000 --- a/src/main/java/ninja/bytecode/iris/util/GRT.java +++ /dev/null @@ -1,10 +0,0 @@ -package ninja.bytecode.iris.util; - -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; - -@FunctionalInterface -public interface GRT -{ - public Glower getGlower(Entity entity, Player observer); -} diff --git a/src/main/java/ninja/bytecode/iris/util/GenLayer.java b/src/main/java/ninja/bytecode/iris/util/GenLayer.java deleted file mode 100644 index c71e88b19..000000000 --- a/src/main/java/ninja/bytecode/iris/util/GenLayer.java +++ /dev/null @@ -1,32 +0,0 @@ -package ninja.bytecode.iris.util; - -import java.util.Random; - -import org.bukkit.World; -import org.bukkit.block.Biome; - -import ninja.bytecode.iris.generator.IrisGenerator; -import ninja.bytecode.shuriken.math.RNG; - -public class GenLayer implements IGenLayer -{ - protected RNG rng; - protected World world; - protected Random random; - protected IrisGenerator iris; - protected Biome biome = Biome.OCEAN; - - public GenLayer(IrisGenerator iris, World world, Random random, RNG rng) - { - this.world = world; - this.random = random; - this.rng = rng; - this.iris = iris; - } - - @Override - public double generateLayer(double noise, double dx, double dz) - { - return 0; - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/GlossGlower.java b/src/main/java/ninja/bytecode/iris/util/GlossGlower.java deleted file mode 100644 index 0d1006e5b..000000000 --- a/src/main/java/ninja/bytecode/iris/util/GlossGlower.java +++ /dev/null @@ -1,106 +0,0 @@ -package ninja.bytecode.iris.util; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; - -import mortar.api.nms.NMP; -import mortar.util.text.C; - -public class GlossGlower implements Glower -{ - private final Player observer; - private final Entity entity; - private ChatColor color; - private boolean sentTeam; - - public GlossGlower(Entity entity, Player observer) - { - sentTeam = false; - this.entity = entity; - this.observer = observer; - this.color = ChatColor.WHITE; - } - - @Override - public Entity getEntity() - { - return entity; - } - - @Override - public ChatColor getColor() - { - return color; - } - - @Override - public void setColor(ChatColor color) - { - if(color.isFormat()) - { - throw new UnsupportedOperationException("You cannot use format codes for glow colors"); - } - - this.color = color; - - if(observer == null) - { - for(Player i : entity.getWorld().getPlayers()) - { - NMP.host.sendGlowingColorMeta(i, getEntity(), C.values()[color.ordinal()]); - } - } - - else - { - NMP.host.sendGlowingColorMeta(getObserver(), getEntity(), C.values()[color.ordinal()]); - } - } - - @Override - public void setGlowing(boolean glowing) - { - if(observer == null) - { - for(Player i : entity.getWorld().getPlayers()) - { - NMP.host.sendEntityMetadata(i, getEntity().getEntityId(), NMP.host.getMetaEntityProperties(false, false, false, false, false, glowing, false)); - } - } - - else - { - NMP.host.sendEntityMetadata(observer, getEntity().getEntityId(), NMP.host.getMetaEntityProperties(false, false, false, false, false, glowing, false)); - } - } - - @Override - public void destroy() - { - setGlowing(false); - - if(sentTeam) - { - if(observer == null) - { - for(Player i : entity.getWorld().getPlayers()) - { - NMP.host.sendRemoveGlowingColorMeta(i, getEntity()); - } - } - - else - { - NMP.host.sendRemoveGlowingColorMeta(getObserver(), getEntity()); - } - - } - } - - @Override - public Player getObserver() - { - return observer; - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/GlowManager.java b/src/main/java/ninja/bytecode/iris/util/GlowManager.java deleted file mode 100644 index 2933abe26..000000000 --- a/src/main/java/ninja/bytecode/iris/util/GlowManager.java +++ /dev/null @@ -1,14 +0,0 @@ -package ninja.bytecode.iris.util; - -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; - -public class GlowManager -{ - public static GRT f = null; - - public static Glower create(Entity e, Player observer) - { - return f.getGlower(e, observer); - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/Glower.java b/src/main/java/ninja/bytecode/iris/util/Glower.java deleted file mode 100644 index c99fd420a..000000000 --- a/src/main/java/ninja/bytecode/iris/util/Glower.java +++ /dev/null @@ -1,20 +0,0 @@ -package ninja.bytecode.iris.util; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; - -public interface Glower -{ - public Player getObserver(); - - public Entity getEntity(); - - public ChatColor getColor(); - - public void setColor(ChatColor color); - - public void setGlowing(boolean glowing); - - public void destroy(); -} diff --git a/src/main/java/ninja/bytecode/iris/util/GlowingBlock.java b/src/main/java/ninja/bytecode/iris/util/GlowingBlock.java deleted file mode 100644 index 1f00bb7cb..000000000 --- a/src/main/java/ninja/bytecode/iris/util/GlowingBlock.java +++ /dev/null @@ -1,178 +0,0 @@ -package ninja.bytecode.iris.util; - -import java.util.UUID; - -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -import mortar.api.nms.NMP; -import mortar.api.world.MaterialBlock; -import mortar.compute.math.M; - -public class GlowingBlock -{ - private static int idd = 123456789; - private int id; - private UUID uid; - private Location location; - private Location current; - private Player player; - private double factor; - private Vector velocity; - private boolean active; - private long mv = M.ms(); - private MaterialBlock mb; - private ChatColor c; - - public GlowingBlock(Player player, Location init, MaterialBlock mb, ChatColor c) - { - this.mb = mb; - this.uid = UUID.randomUUID(); - this.id = idd--; - location = init; - current = init.clone(); - this.player = player; - factor = Math.PI; - active = false; - velocity = new Vector(); - this.c = c; - } - - public int getId() - { - return id; - } - - public void sendMetadata(boolean glowing) - { - PacketGate.mark(PacketCategory.EFFECT); - NMP.host.sendEntityMetadata(player, id, NMP.host.getMetaEntityProperties(false, false, false, false, false, glowing, false)); - } - - public void sendMetadata(ChatColor c) - { - PacketGate.mark(PacketCategory.EFFECT); - //NMP.host.sendGlowingColorMetaEntity(getPlayer(), uid, C.values()[c.ordinal()]); - } - - public void update() - { - if(M.ms() - mv < 50) - { - return; - } - - if(location.getX() == current.getX() && location.getY() == current.getY() && location.getZ() == current.getZ()) - { - return; - } - - mv = M.ms(); - - if(location.distanceSquared(current) > 16) - { - if(PacketGate.can(PacketCategory.EFFECT)) - { - sendTeleport(location); - current = location; - } - } - - else - { - if(PacketGate.can(PacketCategory.EFFECT)) - { - double dx = location.getX() - current.getX(); - double dy = location.getY() - current.getY(); - double dz = location.getZ() - current.getZ(); - dx += velocity.getX(); - dy += velocity.getY(); - dz += velocity.getZ(); - dx = M.clip(dx, -8, 8); - dy = M.clip(dy, -8, 8); - dz = M.clip(dz, -8, 8); - sendMove(dx / factor, dy / factor, dz / factor); - current.add(dx / factor, dy / factor, dz / factor); - current.setX(Math.abs(location.getX() - current.getX()) < 0.00001 ? location.getX() : current.getX()); - current.setY(Math.abs(location.getY() - current.getY()) < 0.00001 ? location.getY() : current.getY()); - current.setZ(Math.abs(location.getZ() - current.getZ()) < 0.00001 ? location.getZ() : current.getZ()); - - if(location.getX() == current.getX() && location.getY() == current.getY() && location.getZ() == current.getZ()) - { - if(PacketGate.can(PacketCategory.EFFECT)) - { - sendTeleport(location); - current = location; - } - } - } - } - } - - public Location getPosition() - { - return location.clone(); - } - - public void setPosition(Location l) - { - location = l; - } - - public Player getPlayer() - { - return player; - } - - public void destroy() - { - sendDestroy(); - } - - public void create() - { - sendSpawn(); - } - - public boolean isActive() - { - return active; - } - - public void setFactor(int i) - { - factor = i; - } - - private void sendTeleport(Location l) - { - NMP.host.teleportEntity(id, player, l, false); - } - - private void sendMove(double x, double y, double z) - { - NMP.host.moveEntityRelative(id, player, x, y, z, false); - } - - public void sendDestroy() - { - active = false; - NMP.host.removeEntity(id, player); - NMP.host.sendRemoveGlowingColorMetaEntity(getPlayer(), uid); - sendMetadata(false); - PacketGate.mark(PacketCategory.EFFECT); - PacketGate.mark(PacketCategory.EFFECT); - } - - public void sendSpawn() - { - NMP.host.spawnFallingBlock(id, uid, location, player, mb); - sendMetadata(c); - sendMetadata(true); - active = true; - PacketGate.mark(PacketCategory.EFFECT); - PacketGate.mark(PacketCategory.EFFECT); - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/HotswapGenerator.java b/src/main/java/ninja/bytecode/iris/util/HotswapGenerator.java deleted file mode 100644 index 85abc67b8..000000000 --- a/src/main/java/ninja/bytecode/iris/util/HotswapGenerator.java +++ /dev/null @@ -1,74 +0,0 @@ -package ninja.bytecode.iris.util; - -import java.util.List; -import java.util.Random; - -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.generator.BlockPopulator; -import org.bukkit.generator.ChunkGenerator; - -import ninja.bytecode.iris.generator.IrisGenerator; - -@SuppressWarnings("deprecation") -public class HotswapGenerator extends ChunkGenerator -{ - private IrisGenerator gen; - - public HotswapGenerator(IrisGenerator gen) - { - setGenerator(gen); - } - - public void setGenerator(IrisGenerator gen) - { - this.gen = gen; - } - - public IrisGenerator getGenerator() - { - return gen; - } - - @Override - public byte[] generate(World world, Random random, int x, int z) - { - return gen.generate(world, random, x, z); - } - - @Override - public short[][] generateExtBlockSections(World world, Random random, int x, int z, BiomeGrid biomes) - { - return gen.generateExtBlockSections(world, random, x, z, biomes); - } - - @Override - public byte[][] generateBlockSections(World world, Random random, int x, int z, BiomeGrid biomes) - { - return gen.generateBlockSections(world, random, x, z, biomes); - } - - @Override - public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) - { - return gen.generateChunkData(world, random, x, z, biome); - } - - @Override - public boolean canSpawn(World world, int x, int z) - { - return gen.canSpawn(world, x, z); - } - - @Override - public List getDefaultPopulators(World world) - { - return gen.getDefaultPopulators(world); - } - - @Override - public Location getFixedSpawnLocation(World world, Random random) - { - return gen.getFixedSpawnLocation(world, random); - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/IGenLayer.java b/src/main/java/ninja/bytecode/iris/util/IGenLayer.java deleted file mode 100644 index 7ef327491..000000000 --- a/src/main/java/ninja/bytecode/iris/util/IGenLayer.java +++ /dev/null @@ -1,6 +0,0 @@ -package ninja.bytecode.iris.util; - -public interface IGenLayer -{ - public double generateLayer(double noise, double dx, double dz); -} diff --git a/src/main/java/ninja/bytecode/iris/util/ING.java b/src/main/java/ninja/bytecode/iris/util/ING.java new file mode 100644 index 000000000..e658a76d4 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/util/ING.java @@ -0,0 +1,38 @@ +package ninja.bytecode.iris.util; + +public class ING +{ + private SNG base; + private SNG[] children; + + public ING(RNG rng, int detail) + { + assert (detail >= 1); + this.children = new SNG[detail]; + + for(int i = 0; i < detail; i++) + { + children[i] = new SNG(rng.nextParallelRNG((i * 368989) % 13345)); + } + base = new SNG(rng.nextParallelRNG(13)); + } + + public double noise(double x, double z) + { + double cx = x; + double cz = z; + int i; + double j; + double k; + + for(i = 0; i < children.length; i++) + { + j = (i + 1) * 2; + k = (i + 1) * 1; + cx = cx + (children[i].noise((cx / j) + i, (cz / j) - i) * k); + cz = cz - (children[i].noise((cz / j) - i, (cx / j) + i) * k); + } + + return (base.noise(cx, cz) / 2D) + 0.5D; + } +} diff --git a/src/main/java/ninja/bytecode/iris/util/IPlacer.java b/src/main/java/ninja/bytecode/iris/util/IPlacer.java deleted file mode 100644 index 81849c291..000000000 --- a/src/main/java/ninja/bytecode/iris/util/IPlacer.java +++ /dev/null @@ -1,19 +0,0 @@ -package ninja.bytecode.iris.util; - -import org.bukkit.Location; -import org.bukkit.World; - -public interface IPlacer -{ - public World getWorld(); - - public MB get(Location l); - - public void set(Location l, MB mb); - - public int getHighestY(Location l); - - public int getHighestYUnderwater(Location l); - - public void flush(); -} diff --git a/src/main/java/ninja/bytecode/iris/util/InterpolationMode.java b/src/main/java/ninja/bytecode/iris/util/InterpolationMode.java deleted file mode 100644 index d9204fd08..000000000 --- a/src/main/java/ninja/bytecode/iris/util/InterpolationMode.java +++ /dev/null @@ -1,9 +0,0 @@ -package ninja.bytecode.iris.util; - -public enum InterpolationMode -{ - NONE, - BILINEAR, - BICUBIC, - HERMITE_BICUBIC -} diff --git a/src/main/java/ninja/bytecode/iris/util/InterpolationType.java b/src/main/java/ninja/bytecode/iris/util/InterpolationType.java deleted file mode 100644 index 2b88c0a38..000000000 --- a/src/main/java/ninja/bytecode/iris/util/InterpolationType.java +++ /dev/null @@ -1,10 +0,0 @@ -package ninja.bytecode.iris.util; - -public enum InterpolationType -{ - LINEAR, - PARAMETRIC_2, - PARAMETRIC_4, - BEZIER, - NONE; -} diff --git a/src/main/java/ninja/bytecode/iris/util/IrisController.java b/src/main/java/ninja/bytecode/iris/util/IrisController.java deleted file mode 100644 index 9d3450a29..000000000 --- a/src/main/java/ninja/bytecode/iris/util/IrisController.java +++ /dev/null @@ -1,10 +0,0 @@ -package ninja.bytecode.iris.util; - -import org.bukkit.event.Listener; - -public interface IrisController extends Listener -{ - public void onStart(); - - public void onStop(); -} diff --git a/src/main/java/ninja/bytecode/iris/util/IrisControllerSet.java b/src/main/java/ninja/bytecode/iris/util/IrisControllerSet.java deleted file mode 100644 index 8fe9b1830..000000000 --- a/src/main/java/ninja/bytecode/iris/util/IrisControllerSet.java +++ /dev/null @@ -1,73 +0,0 @@ -package ninja.bytecode.iris.util; - -import java.io.File; -import java.io.IOException; - -import org.bukkit.Bukkit; -import org.bukkit.event.HandlerList; - -import ninja.bytecode.iris.Iris; -import ninja.bytecode.shuriken.collections.KMap; -import ninja.bytecode.shuriken.logging.L; -import ninja.bytecode.shuriken.tools.JarScanner; - -public class IrisControllerSet -{ - private KMap, IrisController> controllers; - - public IrisControllerSet() - { - controllers = new KMap<>(); - } - - public void startControllers(File jar) throws IOException - { - JarScanner ja = new JarScanner(jar, "ninja.bytecode.iris.controller"); - ja.scan(); - for(Class i : ja.getClasses()) - { - try - { - IrisController c = (IrisController) i.getConstructor().newInstance(); - Bukkit.getPluginManager().registerEvents(c, Iris.instance); - c.onStart(); - controllers.put(i, c); - } - - catch(Throwable e) - { - L.ex(e); - } - } - } - - public void stopControllers() - { - for(Class i : controllers.k()) - { - try - { - IrisController c = controllers.get(i); - HandlerList.unregisterAll(); - c.onStop(); - } - - catch(Throwable e) - { - L.ex(e); - } - } - - controllers.clear(); - } - - public IrisController get(Class c) - { - return controllers.get(c); - } - - public int size() - { - return controllers.size(); - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/IrisInterpolation.java b/src/main/java/ninja/bytecode/iris/util/IrisInterpolation.java deleted file mode 100644 index cd7bf2888..000000000 --- a/src/main/java/ninja/bytecode/iris/util/IrisInterpolation.java +++ /dev/null @@ -1,221 +0,0 @@ -package ninja.bytecode.iris.util; - -import ninja.bytecode.shuriken.math.M; - -public class IrisInterpolation -{ - public static double bezier(double t) - { - return t * t * (3.0d - 2.0d * t); - } - - public static double parametric(double t, double alpha) - { - double sqt = Math.pow(t, alpha); - return sqt / (alpha * (sqt - Math.pow(t, alpha - 1)) + 1.0d); - } - - public static double lerp(double a, double b, double f) - { - return a + (f * (b - a)); - } - - public static double lerpBezier(double a, double b, double f) - { - return a + (bezier(f) * (b - a)); - } - - public static double sinCenter(double f) - { - return Math.sin(f * Math.PI); - } - - public static double lerpCenterSinBezier(double a, double b, double f) - { - return lerpBezier(a, b, sinCenter(f)); - } - - public static double lerpCenterSin(double a, double b, double f) - { - return lerpBezier(a, b, sinCenter(f)); - } - - public static double lerpParametric(double a, double b, double f, double v) - { - return a + (parametric(f, v) * (b - a)); - } - - public static double blerp(double a, double b, double c, double d, double tx, double ty) - { - return lerp(lerp(a, b, tx), lerp(c, d, tx), ty); - } - - public static double blerp(double a, double b, double c, double d, double tx, double ty, InterpolationType type) - { - if(type.equals(InterpolationType.LINEAR)) - { - return blerp(a, b, c, d, tx, ty); - } - - if(type.equals(InterpolationType.BEZIER)) - { - return blerpBezier(a, b, c, d, tx, ty); - } - - if(type.equals(InterpolationType.PARAMETRIC_2)) - { - return blerpParametric(a, b, c, d, tx, ty, 2); - } - - if(type.equals(InterpolationType.PARAMETRIC_4)) - { - return blerpParametric(a, b, c, d, tx, ty, 4); - } - - return 0; - } - - public static double blerpBezier(double a, double b, double c, double d, double tx, double ty) - { - return lerpBezier(lerpBezier(a, b, tx), lerpBezier(c, d, tx), ty); - } - - public static double blerpParametric(double a, double b, double c, double d, double tx, double ty, double v) - { - return lerpParametric(lerpParametric(a, b, tx, v), lerpParametric(c, d, tx, v), ty, v); - } - - public static double hermite(double p0, double p1, double p2, double p3, double mu, double tension, double bias) - { - double m0, m1, mu2, mu3; - double a0, a1, a2, a3; - - mu2 = mu * mu; - mu3 = mu2 * mu; - m0 = (p1 - p0) * (1 + bias) * (1 - tension) / 2; - m0 += (p2 - p1) * (1 - bias) * (1 - tension) / 2; - m1 = (p2 - p1) * (1 + bias) * (1 - tension) / 2; - m1 += (p3 - p2) * (1 - bias) * (1 - tension) / 2; - a0 = 2 * mu3 - 3 * mu2 + 1; - a1 = mu3 - 2 * mu2 + mu; - a2 = mu3 - mu2; - a3 = -2 * mu3 + 3 * mu2; - - return (a0 * p1 + a1 * m0 + a2 * m1 + a3 * p2); - } - - public static double bihermite(double p00, double p01, double p02, double p03, double p10, double p11, double p12, double p13, double p20, double p21, double p22, double p23, double p30, double p31, double p32, double p33, double mux, double muy, double tension, double bias) - { - return hermite(hermite(p00, p01, p02, p03, muy, tension, bias), hermite(p10, p11, p12, p13, muy, tension, bias), hermite(p20, p21, p22, p23, muy, tension, bias), hermite(p30, p31, p32, p33, muy, tension, bias), mux, tension, bias); - } - - public static double cubic(double p0, double p1, double p2, double p3, double mu) - { - double a0, a1, a2, a3, mu2; - - mu2 = mu * mu; - a0 = p3 - p2 - p0 + p1; - a1 = p0 - p1 - a0; - a2 = p2 - p0; - a3 = p1; - - return a0 * mu * mu2 + a1 * mu2 + a2 * mu + a3; - } - - public static double bicubic(double p00, double p01, double p02, double p03, double p10, double p11, double p12, double p13, double p20, double p21, double p22, double p23, double p30, double p31, double p32, double p33, double mux, double muy) - { - return cubic(cubic(p00, p01, p02, p03, muy), cubic(p10, p11, p12, p13, muy), cubic(p20, p21, p22, p23, muy), cubic(p30, p31, p32, p33, muy), mux); - } - - 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); - int x1 = (int) Math.round(fx * rad); - int z1 = (int) Math.round(fz * rad); - int x2 = (int) Math.round((fx + 1) * rad); - int z2 = (int) Math.round((fz + 1) * rad); - double px = M.rangeScale(0, 1, x1, x2, x); - double pz = M.rangeScale(0, 1, z1, z2, z); - //@builder - return blerpBezier( - n.noise(x1, z1), - n.noise(x2, z1), - n.noise(x1, z2), - n.noise(x2, z2), - px, pz); - //@done - } - - public static double getBicubicNoise(int x, int z, double rad, NoiseProvider n) - { - int fx = (int) Math.floor(x / rad); - int fz = (int) Math.floor(z / rad); - int x0 = (int) Math.round((fx - 1) * rad); - int z0 = (int) Math.round((fz - 1) * rad); - int x1 = (int) Math.round(fx * rad); - int z1 = (int) Math.round(fz * rad); - int x2 = (int) Math.round((fx + 1) * rad); - int z2 = (int) Math.round((fz + 1) * rad); - int x3 = (int) Math.round((fx + 2) * rad); - int z3 = (int) Math.round((fz + 2) * rad); - double px = M.rangeScale(0, 1, x1, x2, x); - double pz = M.rangeScale(0, 1, z1, z2, z); - //@builder - return bicubic( - n.noise(x0, z0), - n.noise(x0, z1), - n.noise(x0, z2), - n.noise(x0, z3), - n.noise(x1, z0), - n.noise(x1, z1), - n.noise(x1, z2), - n.noise(x1, z3), - n.noise(x2, z0), - n.noise(x2, z1), - n.noise(x2, z2), - n.noise(x2, z3), - n.noise(x3, z0), - n.noise(x3, z1), - n.noise(x3, z2), - n.noise(x3, z3), - px, pz); - //@done - } - - public static double getHermiteNoise(int x, int z, double rad, NoiseProvider n) - { - int fx = (int) Math.floor(x / rad); - int fz = (int) Math.floor(z / rad); - int x0 = (int) Math.round((fx - 1) * rad); - int z0 = (int) Math.round((fz - 1) * rad); - int x1 = (int) Math.round(fx * rad); - int z1 = (int) Math.round(fz * rad); - int x2 = (int) Math.round((fx + 1) * rad); - int z2 = (int) Math.round((fz + 1) * rad); - int x3 = (int) Math.round((fx + 2) * rad); - int z3 = (int) Math.round((fz + 2) * rad); - double px = M.rangeScale(0, 1, x1, x2, x); - double pz = M.rangeScale(0, 1, z1, z2, z); - //@builder - return bihermite( - n.noise(x0, z0), - n.noise(x0, z1), - n.noise(x0, z2), - n.noise(x0, z3), - n.noise(x1, z0), - n.noise(x1, z1), - n.noise(x1, z2), - n.noise(x1, z3), - n.noise(x2, z0), - n.noise(x2, z1), - n.noise(x2, z2), - n.noise(x2, z3), - n.noise(x3, z0), - n.noise(x3, z1), - n.noise(x3, z2), - n.noise(x3, z3), - px, pz, 0.00001, 0.5); - //@done - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/IrisMetrics.java b/src/main/java/ninja/bytecode/iris/util/IrisMetrics.java deleted file mode 100644 index dabc80a57..000000000 --- a/src/main/java/ninja/bytecode/iris/util/IrisMetrics.java +++ /dev/null @@ -1,233 +0,0 @@ -package ninja.bytecode.iris.util; - -import java.util.function.Consumer; - -import org.bukkit.command.CommandSender; - -import mortar.compute.math.M; -import mortar.util.text.C; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.shuriken.bench.PrecisionStopwatch; -import ninja.bytecode.shuriken.collections.KList; -import ninja.bytecode.shuriken.collections.KMap; -import ninja.bytecode.shuriken.format.Form; -import ninja.bytecode.shuriken.math.RollingSequence; - -public class IrisMetrics -{ - private int size; - private int generators; - private double scale; - private KMap sequences; - - public IrisMetrics(int generators, int size) - { - scale = 1; - this.size = size; - this.generators = generators; - sequences = new KMap<>(); - } - - public String avgMS(String s, int dec) - { - return Form.duration(get(s).getAverage(), dec); - } - - public String avg(String s, int dec) - { - return Form.f(get(s).getAverage(), dec); - } - - public String maxMS(String s, int dec) - { - return Form.duration(get(s).getMax(), dec); - } - - public String max(String s, int dec) - { - return Form.f(get(s).getMax(), dec); - } - - public String minMS(String s, int dec) - { - return Form.duration(get(s).getMin(), dec); - } - - public String min(String s, int dec) - { - return Form.f(get(s).getMin(), dec); - } - - public String medianMS(String s, int dec) - { - return Form.duration(get(s).getMedian(), dec); - } - - public String median(String s, int dec) - { - return Form.f(get(s).getMedian(), dec); - } - - public RollingSequence get(String s) - { - if(!sequences.containsKey(s)) - { - return new RollingSequence(2); - } - - return sequences.get(s); - } - - public PrecisionStopwatch start() - { - return PrecisionStopwatch.start(); - } - - public void stop(String f, PrecisionStopwatch g) - { - put(f, g.getMilliseconds()); - } - - public void put(String f, double t) - { - if(!sequences.containsKey(f)) - { - sequences.put(f, new RollingSequence(size)); - } - - sequences.get(f).put(t); - } - - public int getGenerators() - { - return generators; - } - - public void setGenerators(int generators) - { - this.generators = generators; - } - - public KMap getSequences() - { - return sequences; - } - - public void setSequences(KMap sequences) - { - this.sequences = sequences; - } - - public void send(CommandSender p, Consumer c) - { - send(p, c, null, 0); - } - - public void setParScale(double sf) - { - scale = sf; - } - - public void send(CommandSender p, Consumer c, String parent, int ind) - { - KMap out = new KMap<>(); - - looking: for(String i : getSequences().k()) - { - KList o = new KList<>(); - - if(i.contains(":")) - { - o.add(i.split("\\Q:\\E")); - } - - else - { - o.add(i); - } - - String pf = o.get(0); - o.remove(0); - getSequences().get(i).resetExtremes(); - double vmin = Math.abs(getSequences().get(i).getMin()); - double vmed = Math.abs(getSequences().get(i).getMedian()); - double vavg = Math.abs(getSequences().get(i).getAverage()); - double vmax = Math.abs(getSequences().get(i).getMax()); - - for(String k : o) - { - if(k.startsWith("x")) - { - Double mult = Double.valueOf(k.substring(1)); - vmin *= mult / (scale * 2D); - vmed *= mult / (scale * 2D); - vavg *= mult / (scale * 2D); - vmax *= mult / (scale * 2D); - } - } - - boolean ms = false; - boolean comma = false; - String myparent = null; - int dot = 0; - for(String k : o) - { - if(k.startsWith("/")) - { - myparent = k.substring(1); - } - - if(k.startsWith(".") && k.endsWith(".")) - { - dot = k.length(); - } - - else if(k.equals(",")) - { - comma = true; - } - - if(k.equals("ms")) - { - ms = true; - } - } - - if((parent != null) != (myparent != null)) - { - continue looking; - } - - if(parent != null && !myparent.equals(parent)) - { - continue looking; - } - - if(dot == 0 && vavg >= 1000 && !comma) - { - comma = true; - } - - String af = ms ? Form.duration(vmin, dot) : comma ? Form.f((int) vmin) : Form.f(vmin, dot); - String bf = ms ? Form.duration(vmed, dot) : comma ? Form.f((int) vmed) : Form.f(vmed, dot); - String cf = ms ? Form.duration(vavg, dot) : comma ? Form.f((int) vavg) : Form.f(vavg, dot); - String df = ms ? Form.duration(vmax, dot) : comma ? Form.f((int) vmax) : Form.f(vmax, dot); - - out.put(pf, C.DARK_GREEN.toString() + C.ITALIC + cf + C.RESET + C.GRAY + " (" + C.DARK_AQUA + C.ITALIC + af + C.RESET + C.GRAY + " > " + C.GOLD + C.ITALIC + bf + C.RESET + C.GRAY + " < " + C.DARK_RED + C.ITALIC + df + C.RESET + C.GRAY + ")"); - } - - if(ind == 0) - { - c.accept(C.WHITE.toString() + C.BOLD + "Total Generators: " + C.RESET + C.DARK_AQUA + C.ITALIC + Form.f(generators)); - c.accept(C.WHITE.toString() + C.BOLD + "Parallelism: " + C.RESET + C.DARK_PURPLE + C.ITALIC + Form.pc(scale) + C.WHITE + C.BOLD + " Threads: " + C.RESET + C.BLUE + C.ITALIC + Iris.exec().getTC()); - } - - for(String i : out.k()) - { - String g = Form.capitalizeWords(i.replaceAll("\\Q-\\E", " ").toLowerCase()); - c.accept(Form.repeat(" ", M.iclip(ind, 0, 4)) + C.WHITE + C.BOLD + g + C.RESET + ": " + out.get(i)); - - send(p, c, i, ind + 1); - } - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/IrisWorldData.java b/src/main/java/ninja/bytecode/iris/util/IrisWorldData.java deleted file mode 100644 index 45808e756..000000000 --- a/src/main/java/ninja/bytecode/iris/util/IrisWorldData.java +++ /dev/null @@ -1,274 +0,0 @@ -package ninja.bytecode.iris.util; - -import java.io.IOException; - -import org.bukkit.Bukkit; -import org.bukkit.World; - -import mortar.util.text.C; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.generator.atomics.AtomicChunkData; -import ninja.bytecode.iris.generator.atomics.AtomicRegionData; -import ninja.bytecode.iris.generator.atomics.AtomicWorldData; -import ninja.bytecode.shuriken.collections.KList; -import ninja.bytecode.shuriken.collections.KMap; -import ninja.bytecode.shuriken.logging.L; - -public class IrisWorldData -{ - private final World world; - private final AtomicWorldData data; - private boolean saving; - private final KMap loadedChunks; - - public IrisWorldData(World world) - { - this.world = world; - saving = true; - data = new AtomicWorldData(world); - loadedChunks = new KMap<>(); - Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, this::softUnloadWorld, 200, 20); - } - - public void disableSaving() - { - saving = false; - } - - public void enableSaving() - { - saving = true; - } - - private void softUnloadWorld() - { - if(!saving) - { - return; - } - - for(SMCAVector i : getLoadedChunks()) - { - try - { - AtomicChunkData d = getChunk(i.getX(), i.getZ()); - if(d.getTimeSinceLastUse() > 15000) - { - unloadChunk(i.getX(), i.getZ(), true); - } - } - - catch(Throwable e) - { - e.printStackTrace(); - } - } - - for(SMCAVector i : getLoadedRegions()) - { - softUnloadRegion(i.getX(), i.getZ()); - } - } - - private boolean softUnloadRegion(int rx, int rz) - { - if(!saving) - { - return false; - } - - for(SMCAVector i : loadedChunks.keySet()) - { - if(i.getX() >> 5 == rx && i.getZ() >> 5 == rz) - { - return false; - } - } - - try - { - data.unloadSection(rx, rz, true); - return true; - } - - catch(IOException e) - { - e.printStackTrace(); - L.f(C.RED + "Failed to save Iris Subregion " + C.YELLOW + rx + " " + rz); - } - - return false; - } - - public boolean deleteChunk(int x, int z) - { - if(isChunkLoaded(x, z)) - { - unloadChunk(x, z, false); - } - - try - { - AtomicRegionData region = data.getSubregion(x >> 5, z >> 5); - region.delete(x & 31, z & 31); - return true; - } - - catch(IOException e) - { - L.f(C.RED + "Failed delete chunk " + C.YELLOW + x + " " + z + C.RED.toString() + " -> Failed to get Region " + C.YELLOW + (x >> 5) + " " + (z >> 5)); - e.printStackTrace(); - } - - return false; - } - - public boolean unloadChunk(int x, int z, boolean save) - { - if(!isChunkLoaded(x, z)) - { - return false; - } - - if(save) - { - saveChunk(x, z); - } - - loadedChunks.remove(new SMCAVector(x, z)); - return true; - } - - public boolean saveChunk(int x, int z) - { - if(!isChunkLoaded(x, z)) - { - return false; - } - - try - { - AtomicRegionData region = data.getSubregion(x >> 5, z >> 5); - region.set(x & 31, z & 31, getChunk(x, z)); - return true; - } - - catch(IOException e) - { - L.f(C.RED + "Failed save chunk " + C.YELLOW + x + " " + z + C.RED.toString() + " -> Failed to get Region " + C.YELLOW + (x >> 5) + " " + (z >> 5)); - e.printStackTrace(); - } - - return false; - } - - public AtomicChunkData getOnly(int x, int z) - { - if(!isChunkLoaded(x, z)) - { - return null; - } - - return getChunk(x, z); - } - - public AtomicChunkData getChunk(int x, int z) - { - if(!isChunkLoaded(x, z)) - { - try - { - AtomicRegionData region = data.getSubregion(x >> 5, z >> 5); - - if(region.contains(x & 31, z & 31)) - { - AtomicChunkData chunk = region.get(x & 31, z & 31); - loadedChunks.put(new SMCAVector(x, z), chunk); - } - - else - { - AtomicChunkData data = new AtomicChunkData(world); - loadedChunks.put(new SMCAVector(x, z), data); - } - } - - catch(IOException e) - { - L.f(C.RED + "Failed load chunk " + C.YELLOW + x + " " + z + C.RED.toString() + " -> Failed to get Region " + C.YELLOW + (x >> 5) + " " + (z >> 5)); - e.printStackTrace(); - } - } - - return loadedChunks.get(new SMCAVector(x, z)); - } - - public boolean isChunkLoaded(int x, int z) - { - return loadedChunks.containsKey(new SMCAVector(x, z)); - } - - public void inject(int x, int z, AtomicChunkData data) - { - getChunk(x, z).inject(data); - } - - public boolean exists(int x, int z) - { - try - { - return isChunkLoaded(x, z) || data.getSubregion(x >> 5, z >> 5).contains(x & 31, z & 31); - } - - catch(IOException e) - { - L.f(C.RED + "Failed check chunk " + C.YELLOW + x + " " + z + C.RED.toString() + " -> Failed to get Region " + C.YELLOW + (x >> 5) + " " + (z >> 5)); - e.printStackTrace(); - } - - return false; - } - - public KList getLoadedChunks() - { - return loadedChunks.k(); - } - - public KList getLoadedRegions() - { - return data.getLoadedRegions(); - } - - public void saveAll() - { - for(SMCAVector i : loadedChunks.k()) - { - saveChunk(i.getX(), i.getZ()); - } - - try - { - data.saveAll(); - } - - catch(IOException e) - { - e.printStackTrace(); - } - } - - public void setBlock(int x, int y, int z, int id, byte data) - { - getChunk(x >> 4, z >> 4).setBlock(x & 15, y, z & 15, id, data); - } - - public void dispose() - { - for(SMCAVector i : getLoadedChunks()) - { - unloadChunk(i.getX(), i.getZ(), true); - } - - softUnloadWorld(); - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/MB.java b/src/main/java/ninja/bytecode/iris/util/MB.java deleted file mode 100644 index a5e4254d2..000000000 --- a/src/main/java/ninja/bytecode/iris/util/MB.java +++ /dev/null @@ -1,102 +0,0 @@ -package ninja.bytecode.iris.util; - -import org.bukkit.Material; - -public class MB -{ - public final Material material; - public final byte data; - - @SuppressWarnings("deprecation") - public static MB of(String dat) - { - String material = dat; - byte data = 0; - - if(dat.contains(":")) - { - material = dat.split("\\Q:\\E")[0]; - data = Integer.valueOf(dat.split("\\Q:\\E")[1]).byteValue(); - } - - try - { - return new MB(Material.getMaterial(Integer.valueOf(material)), data); - } - - catch(Throwable e) - { - - } - - try - { - return new MB(Material.getMaterial(material), data); - } - - catch(Throwable e) - { - - } - - return MB.of(Material.AIR); - } - - public String toString() - { - if(data == 0) - { - return material.name(); - } - - return material.name() + ":" + data; - } - - public MB(Material material, int data) - { - this.material = material; - this.data = (byte) data; - } - - public MB(Material material) - { - this(material, 0); - } - - public static MB of(Material f) - { - return new MB(f); - } - - public static MB of(Material f, int a) - { - return new MB(f, a); - } - - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = prime * result + data; - result = prime * result + ((material == null) ? 0 : material.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) - { - if(this == obj) - return true; - if(obj == null) - return false; - if(getClass() != obj.getClass()) - return false; - MB other = (MB) obj; - if(data != other.data) - return false; - if(material != other.material) - return false; - return true; - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/MCAPos.java b/src/main/java/ninja/bytecode/iris/util/MCAPos.java deleted file mode 100644 index 60a1d18d9..000000000 --- a/src/main/java/ninja/bytecode/iris/util/MCAPos.java +++ /dev/null @@ -1,102 +0,0 @@ -package ninja.bytecode.iris.util; - -public class MCAPos -{ - private int x; - private int z; - - public static MCAPos fromChunk(int x, int z) - { - return new MCAPos(x >> 5, z >> 5); - } - - public MCAPos(String name) - { - fromFileName(name); - } - - public MCAPos(int x, int z) - { - this.x = x; - this.z = z; - } - - public void fromFileName(String n) - { - String[] f = n.split("\\Q.\\E"); - x = Integer.valueOf(f[0]); - z = Integer.valueOf(f[1]); - } - - public String toFileName() - { - return x + "." + z + ".imc"; - } - - public int getX() - { - return x; - } - - public void setX(int x) - { - this.x = x; - } - - public int getZ() - { - return z; - } - - public void setZ(int z) - { - this.z = z; - } - - public int getMinChunkX() - { - return x << 5; - } - - public int getMinChunkZ() - { - return z << 5; - } - - public int getMaxChunkX() - { - return getMinChunkX() + 32; - } - - public int getMaxChunkZ() - { - return getMinChunkZ() + 32; - } - - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = prime * result + x; - result = prime * result + z; - return result; - } - - @Override - public boolean equals(Object obj) - { - if(this == obj) - return true; - if(obj == null) - return false; - if(getClass() != obj.getClass()) - return false; - MCAPos other = (MCAPos) obj; - if(x != other.x) - return false; - if(z != other.z) - return false; - return true; - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/MCAState.java b/src/main/java/ninja/bytecode/iris/util/MCAState.java deleted file mode 100644 index d089bf987..000000000 --- a/src/main/java/ninja/bytecode/iris/util/MCAState.java +++ /dev/null @@ -1,80 +0,0 @@ -package ninja.bytecode.iris.util; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import ninja.bytecode.shuriken.math.M; - -public class MCAState -{ - private boolean[] decorated; - private boolean dirty; - private long lastUsed; - - public MCAState() - { - lastUsed = M.ms(); - this.decorated = new boolean[1024]; - } - - public boolean isInUse() - { - return M.ms() - lastUsed < 30000; - } - - public void setDirty() - { - lastUsed = M.ms(); - this.dirty = true; - } - - public void saved() - { - lastUsed = M.ms(); - this.dirty = false; - } - - public boolean isDirty() - { - return dirty; - } - - public boolean isDecorated(int rcx, int rcz) - { - lastUsed = M.ms(); - return decorated[rcx + (32 * rcz)]; - } - - public void setDecorated(int rcx, int rcz, boolean decorated) - { - lastUsed = M.ms(); - this.decorated[rcx + (32 * rcz)] = decorated; - } - - public void read(InputStream in) throws IOException - { - DataInputStream din = new DataInputStream(in); - - for(int i = 0; i < 1024; i++) - { - decorated[i] = din.readBoolean(); - } - - din.close(); - } - - public void write(OutputStream out) throws IOException - { - DataOutputStream dos = new DataOutputStream(out); - - for(int i = 0; i < 1024; i++) - { - dos.writeBoolean(decorated[i]); - } - - dos.close(); - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/NoiseGenerator.java b/src/main/java/ninja/bytecode/iris/util/NoiseGenerator.java new file mode 100644 index 000000000..9ec5b32d0 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/util/NoiseGenerator.java @@ -0,0 +1,231 @@ +package ninja.bytecode.iris.util; + +/** + * Base class for all noise generators + */ +public abstract class NoiseGenerator +{ + protected final int perm[] = new int[512]; + protected double offsetX; + protected double offsetY; + protected double offsetZ; + + /** + * Speedy floor, faster than (int)Math.floor(x) + * + * @param x + * Value to floor + * @return Floored value + */ + public static int floor(double x) + { + return x >= 0 ? (int) x : (int) x - 1; + } + + protected static double fade(double x) + { + return x * x * x * (x * (x * 6 - 15) + 10); + } + + protected static double lerp(double x, double y, double z) + { + return y + x * (z - y); + } + + protected static double grad(int hash, double x, double y, double z) + { + hash &= 15; + double u = hash < 8 ? x : y; + double v = hash < 4 ? y : hash == 12 || hash == 14 ? x : z; + return ((hash & 1) == 0 ? u : -u) + ((hash & 2) == 0 ? v : -v); + } + + /** + * Computes and returns the 1D noise for the given coordinate in 1D space + * + * @param x + * X coordinate + * @return Noise at given location, from range -1 to 1 + */ + public double noise(double x) + { + return noise(x, 0, 0); + } + + /** + * Computes and returns the 2D noise for the given coordinates in 2D space + * + * @param x + * X coordinate + * @param y + * Y coordinate + * @return Noise at given location, from range -1 to 1 + */ + public double noise(double x, double y) + { + return noise(x, y, 0); + } + + /** + * Computes and returns the 3D noise for the given coordinates in 3D space + * + * @param x + * X coordinate + * @param y + * Y coordinate + * @param z + * Z coordinate + * @return Noise at given location, from range -1 to 1 + */ + public abstract double noise(double x, double y, double z); + + /** + * Generates noise for the 1D coordinates using the specified number of octaves + * and parameters + * + * @param x + * X-coordinate + * @param octaves + * Number of octaves to use + * @param frequency + * How much to alter the frequency by each octave + * @param amplitude + * How much to alter the amplitude by each octave + * @return Resulting noise + */ + public double noise(double x, int octaves, double frequency, double amplitude) + { + return noise(x, 0, 0, octaves, frequency, amplitude); + } + + /** + * Generates noise for the 1D coordinates using the specified number of octaves + * and parameters + * + * @param x + * X-coordinate + * @param octaves + * Number of octaves to use + * @param frequency + * How much to alter the frequency by each octave + * @param amplitude + * How much to alter the amplitude by each octave + * @param normalized + * If true, normalize the value to [-1, 1] + * @return Resulting noise + */ + public double noise(double x, int octaves, double frequency, double amplitude, boolean normalized) + { + return noise(x, 0, 0, octaves, frequency, amplitude, normalized); + } + + /** + * Generates noise for the 2D coordinates using the specified number of octaves + * and parameters + * + * @param x + * X-coordinate + * @param y + * Y-coordinate + * @param octaves + * Number of octaves to use + * @param frequency + * How much to alter the frequency by each octave + * @param amplitude + * How much to alter the amplitude by each octave + * @return Resulting noise + */ + public double noise(double x, double y, int octaves, double frequency, double amplitude) + { + return noise(x, y, 0, octaves, frequency, amplitude); + } + + /** + * Generates noise for the 2D coordinates using the specified number of octaves + * and parameters + * + * @param x + * X-coordinate + * @param y + * Y-coordinate + * @param octaves + * Number of octaves to use + * @param frequency + * How much to alter the frequency by each octave + * @param amplitude + * How much to alter the amplitude by each octave + * @param normalized + * If true, normalize the value to [-1, 1] + * @return Resulting noise + */ + public double noise(double x, double y, int octaves, double frequency, double amplitude, boolean normalized) + { + return noise(x, y, 0, octaves, frequency, amplitude, normalized); + } + + /** + * Generates noise for the 3D coordinates using the specified number of octaves + * and parameters + * + * @param x + * X-coordinate + * @param y + * Y-coordinate + * @param z + * Z-coordinate + * @param octaves + * Number of octaves to use + * @param frequency + * How much to alter the frequency by each octave + * @param amplitude + * How much to alter the amplitude by each octave + * @return Resulting noise + */ + public double noise(double x, double y, double z, int octaves, double frequency, double amplitude) + { + return noise(x, y, z, octaves, frequency, amplitude, false); + } + + /** + * Generates noise for the 3D coordinates using the specified number of octaves + * and parameters + * + * @param x + * X-coordinate + * @param y + * Y-coordinate + * @param z + * Z-coordinate + * @param octaves + * Number of octaves to use + * @param frequency + * How much to alter the frequency by each octave + * @param amplitude + * How much to alter the amplitude by each octave + * @param normalized + * If true, normalize the value to [-1, 1] + * @return Resulting noise + */ + public double noise(double x, double y, double z, int octaves, double frequency, double amplitude, boolean normalized) + { + double result = 0; + double amp = 1; + double freq = 1; + double max = 0; + + for(int i = 0; i < octaves; i++) + { + result += noise(x * freq, y * freq, z * freq) * amp; + max += amp; + freq *= frequency; + amp *= amplitude; + } + + if(normalized) + { + result /= max; + } + + return result; + } +} diff --git a/src/main/java/ninja/bytecode/iris/util/NoiseProvider.java b/src/main/java/ninja/bytecode/iris/util/NoiseProvider.java deleted file mode 100644 index 33b45b11f..000000000 --- a/src/main/java/ninja/bytecode/iris/util/NoiseProvider.java +++ /dev/null @@ -1,7 +0,0 @@ -package ninja.bytecode.iris.util; - -@FunctionalInterface -public interface NoiseProvider -{ - public double noise(double x, double z); -} diff --git a/src/main/java/ninja/bytecode/iris/util/ObjectMode.java b/src/main/java/ninja/bytecode/iris/util/ObjectMode.java deleted file mode 100644 index 1162711ba..000000000 --- a/src/main/java/ninja/bytecode/iris/util/ObjectMode.java +++ /dev/null @@ -1,33 +0,0 @@ -package ninja.bytecode.iris.util; - -public enum ObjectMode -{ - /** - * Technically the fasted mode. I.e. Do nothing - */ - NONE, - - /** - * The fastest placer. Places without updating lighting or physics - * - * Lighting is applied later with packets - */ - QUICK_N_DIRTY, - - /** - * Somewhat slow but produces near-perfect results. Updates lighting. - */ - LIGHTING, - - /** - * Somewhat slow but produces near-perfect results. Updates lighting & physics - */ - LIGHTING_PHYSICS, - - /** - * Somewhat slow but never cascades and is instantly placed with terrain - * - * Lighting is applied later with packets - */ - PARALLAX; -} diff --git a/src/main/java/ninja/bytecode/iris/util/PacketCategory.java b/src/main/java/ninja/bytecode/iris/util/PacketCategory.java deleted file mode 100644 index cc5be7905..000000000 --- a/src/main/java/ninja/bytecode/iris/util/PacketCategory.java +++ /dev/null @@ -1,9 +0,0 @@ -package ninja.bytecode.iris.util; - -public enum PacketCategory -{ - BOARD, - HOLOGRAM, - EFFECT, - TABLIST; -} diff --git a/src/main/java/ninja/bytecode/iris/util/PacketGate.java b/src/main/java/ninja/bytecode/iris/util/PacketGate.java deleted file mode 100644 index a03026a34..000000000 --- a/src/main/java/ninja/bytecode/iris/util/PacketGate.java +++ /dev/null @@ -1,129 +0,0 @@ -package ninja.bytecode.iris.util; - -import mortar.compute.math.RollingAverage; -import mortar.lang.collection.GMap; - -public class PacketGate -{ - private static final GMap gates = new GMap<>(); - private final RollingAverage average; - private final int pps; - private int sent; - - private PacketGate(int pps) - { - sent = 0; - this.pps = pps; - average = new RollingAverage(100); - } - - public void tick() - { - average.put(sent * 20D); - sent = 0; - } - - public boolean can() - { - if(should()) - { - mark(); - return true; - } - - return false; - } - - public boolean should() - { - if(average.get() < pps) - { - return true; - } - - return false; - } - - public void mark() - { - sent++; - } - - private double getAveragePPS() - { - return average.get(); - } - - public static int getTotalPPS() - { - double m = 0; - - for(PacketCategory i : PacketCategory.values()) - { - m += getAveragePPS(i); - } - - return (int) m; - } - - public static void tickAll() - { - if(gates.isEmpty()) - { - reset(); - } - - for(PacketCategory i : PacketCategory.values()) - { - gates.get(i).tick(); - } - } - - public static double getAveragePPS(PacketCategory cat) - { - if(!gates.containsKey(cat)) - { - reset(); - } - - return gates.get(cat).getAveragePPS(); - } - - public static boolean can(PacketCategory cat) - { - if(!gates.containsKey(cat)) - { - reset(); - } - - return gates.get(cat).can(); - } - - public static void mark(PacketCategory cat) - { - if(!gates.containsKey(cat)) - { - reset(); - } - - gates.get(cat).mark(); - } - - public static boolean should(PacketCategory cat) - { - if(!gates.containsKey(cat)) - { - reset(); - } - - return gates.get(cat).should(); - } - - public static void reset() - { - gates.put(PacketCategory.BOARD, new PacketGate(100)); - gates.put(PacketCategory.EFFECT, new PacketGate(100)); - gates.put(PacketCategory.HOLOGRAM, new PacketGate(100)); - gates.put(PacketCategory.TABLIST, new PacketGate(100)); - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/ParticleBase.java b/src/main/java/ninja/bytecode/iris/util/ParticleBase.java deleted file mode 100644 index e1c50a9ae..000000000 --- a/src/main/java/ninja/bytecode/iris/util/ParticleBase.java +++ /dev/null @@ -1,30 +0,0 @@ -package ninja.bytecode.iris.util; - -import org.bukkit.Location; -import org.bukkit.entity.Player; - -import ninja.bytecode.shuriken.collections.KList; - -public abstract class ParticleBase implements VisualEffect -{ - @Override - public abstract void play(Location l, double range); - - @Override - public abstract void play(Location l, Player p); - - @Override - public void play(Location l) - { - play(l, 64); - } - - @Override - public void play(Location l, KList p) - { - for(Player i : p) - { - play(l, i); - } - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/ParticleEffect.java b/src/main/java/ninja/bytecode/iris/util/ParticleEffect.java deleted file mode 100644 index ba2f68f5a..000000000 --- a/src/main/java/ninja/bytecode/iris/util/ParticleEffect.java +++ /dev/null @@ -1,2101 +0,0 @@ -package ninja.bytecode.iris.util; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.bukkit.Bukkit; -import org.bukkit.Color; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -import ninja.bytecode.iris.util.ParticleEffect.ParticleData; -import ninja.bytecode.iris.util.ReflectionUtils.PackageType; - -/** - * ParticleEffect Library - *

- * This library was created by @DarkBlade12 and allows you to display all - * Minecraft particle effects on a Bukkit server - *

- * You are welcome to use it, modify it and redistribute it under the following - * conditions: - *

    - *
  • Don't claim this class as your own - *
  • Don't remove this disclaimer - *
- *

- * Special thanks: - *

    - *
  • @microgeek (original idea, names and packet parameters) - *
  • @ShadyPotato (1.8 names, ids and packet parameters) - *
  • @RingOfStorms (particle behavior) - *
  • @Cybermaxke (particle behavior) - *
  • @JamieSinn (hosting a jenkins server and documentation for - * particleeffect) - *
- *

- * It would be nice if you provide credit to me if you use this class in a - * published project - * - * @author DarkBlade12 - * @version 1.7 - */ -@SuppressWarnings("unused") -public enum ParticleEffect -{ - /** - * A particle effect which is displayed by exploding tnt and creepers: - *

    - *
  • It looks like a white cloud - *
  • The speed value influences the velocity at which the particle flies off - *
- */ - EXPLOSION_NORMAL("explode", 0, -1, ParticleProperty.DIRECTIONAL), - /** - * A particle effect which is displayed by exploding ghast fireballs and wither - * skulls: - *
    - *
  • It looks like a gray ball which is fading away - *
  • The speed value slightly influences the size of this particle effect - *
- */ - EXPLOSION_LARGE("largeexplode", 1, -1), - /** - * A particle effect which is displayed by exploding tnt and creepers: - *
    - *
  • It looks like a crowd of gray balls which are fading away - *
  • The speed value has no influence on this particle effect - *
- */ - EXPLOSION_HUGE("hugeexplosion", 2, -1), - /** - * A particle effect which is displayed by launching fireworks: - *
    - *
  • It looks like a white star which is sparkling - *
  • The speed value influences the velocity at which the particle flies off - *
- */ - FIREWORKS_SPARK("fireworksSpark", 3, -1, ParticleProperty.DIRECTIONAL), - /** - * A particle effect which is displayed by swimming entities and arrows in - * water: - *
    - *
  • It looks like a bubble - *
  • The speed value influences the velocity at which the particle flies off - *
- */ - WATER_BUBBLE("bubble", 4, -1, ParticleProperty.DIRECTIONAL, ParticleProperty.REQUIRES_WATER), - /** - * A particle effect which is displayed by swimming entities and shaking wolves: - *
    - *
  • It looks like a blue drop - *
  • The speed value has no influence on this particle effect - *
- */ - WATER_SPLASH("splash", 5, -1, ParticleProperty.DIRECTIONAL), - /** - * A particle effect which is displayed on water when fishing: - *
    - *
  • It looks like a blue droplet - *
  • The speed value influences the velocity at which the particle flies off - *
- */ - WATER_WAKE("wake", 6, 7, ParticleProperty.DIRECTIONAL), - /** - * A particle effect which is displayed by water: - *
    - *
  • It looks like a tiny blue square - *
  • The speed value has no influence on this particle effect - *
- */ - SUSPENDED("suspended", 7, -1, ParticleProperty.REQUIRES_WATER), - /** - * A particle effect which is displayed by air when close to bedrock and the in - * the void: - *
    - *
  • It looks like a tiny gray square - *
  • The speed value has no influence on this particle effect - *
- */ - SUSPENDED_DEPTH("depthSuspend", 8, -1, ParticleProperty.DIRECTIONAL), - /** - * A particle effect which is displayed when landing a critical hit and by - * arrows: - *
    - *
  • It looks like a light brown cross - *
  • The speed value influences the velocity at which the particle flies off - *
- */ - CRIT("crit", 9, -1, ParticleProperty.DIRECTIONAL), - /** - * A particle effect which is displayed when landing a hit with an enchanted - * weapon: - *
    - *
  • It looks like a cyan star - *
  • The speed value influences the velocity at which the particle flies off - *
- */ - CRIT_MAGIC("magicCrit", 10, -1, ParticleProperty.DIRECTIONAL), - /** - * A particle effect which is displayed by primed tnt, torches, droppers, - * dispensers, end portals, brewing stands and monster spawners: - *
    - *
  • It looks like a little gray cloud - *
  • The speed value influences the velocity at which the particle flies off - *
- */ - SMOKE_NORMAL("smoke", 11, -1, ParticleProperty.DIRECTIONAL), - /** - * A particle effect which is displayed by fire, minecarts with furnace and - * blazes: - *
    - *
  • It looks like a large gray cloud - *
  • The speed value influences the velocity at which the particle flies off - *
- */ - SMOKE_LARGE("largesmoke", 12, -1, ParticleProperty.DIRECTIONAL), - /** - * A particle effect which is displayed when splash potions or bottles o' - * enchanting hit something: - *
    - *
  • It looks like a white swirl - *
  • The speed value causes the particle to only move upwards when set to 0 - *
  • Only the motion on the y-axis can be controlled, the motion on the x- and - * z-axis are multiplied by 0.1 when setting the values to 0 - *
- */ - SPELL("spell", 13, -1), - /** - * A particle effect which is displayed when instant splash potions hit - * something: - *
    - *
  • It looks like a white cross - *
  • The speed value causes the particle to only move upwards when set to 0 - *
  • Only the motion on the y-axis can be controlled, the motion on the x- and - * z-axis are multiplied by 0.1 when setting the values to 0 - *
- */ - SPELL_INSTANT("instantSpell", 14, -1), - /** - * A particle effect which is displayed by entities with active potion effects: - *
    - *
  • It looks like a colored swirl - *
  • The speed value causes the particle to be colored black when set to 0 - *
  • The particle color gets lighter when increasing the speed and darker when - * decreasing the speed - *
- */ - SPELL_MOB("mobSpell", 15, -1, ParticleProperty.COLORABLE), - /** - * A particle effect which is displayed by entities with active potion effects - * applied through a beacon: - *
    - *
  • It looks like a transparent colored swirl - *
  • The speed value causes the particle to be always colored black when set - * to 0 - *
  • The particle color gets lighter when increasing the speed and darker when - * decreasing the speed - *
- */ - SPELL_MOB_AMBIENT("mobSpellAmbient", 16, -1, ParticleProperty.COLORABLE), - /** - * A particle effect which is displayed by witches: - *
    - *
  • It looks like a purple cross - *
  • The speed value causes the particle to only move upwards when set to 0 - *
  • Only the motion on the y-axis can be controlled, the motion on the x- and - * z-axis are multiplied by 0.1 when setting the values to 0 - *
- */ - SPELL_WITCH("witchMagic", 17, -1), - /** - * A particle effect which is displayed by blocks beneath a water source: - *
    - *
  • It looks like a blue drip - *
  • The speed value has no influence on this particle effect - *
- */ - DRIP_WATER("dripWater", 18, -1), - /** - * A particle effect which is displayed by blocks beneath a lava source: - *
    - *
  • It looks like an orange drip - *
  • The speed value has no influence on this particle effect - *
- */ - DRIP_LAVA("dripLava", 19, -1), - /** - * A particle effect which is displayed when attacking a villager in a village: - *
    - *
  • It looks like a cracked gray heart - *
  • The speed value has no influence on this particle effect - *
- */ - VILLAGER_ANGRY("angryVillager", 20, -1), - /** - * A particle effect which is displayed when using bone meal and trading with a - * villager in a village: - *
    - *
  • It looks like a green star - *
  • The speed value has no influence on this particle effect - *
- */ - VILLAGER_HAPPY("happyVillager", 21, -1, ParticleProperty.DIRECTIONAL), - /** - * A particle effect which is displayed by mycelium: - *
    - *
  • It looks like a tiny gray square - *
  • The speed value has no influence on this particle effect - *
- */ - TOWN_AURA("townaura", 22, -1, ParticleProperty.DIRECTIONAL), - /** - * A particle effect which is displayed by note blocks: - *
    - *
  • It looks like a colored note - *
  • The speed value causes the particle to be colored green when set to 0 - *
- */ - NOTE("note", 23, -1, ParticleProperty.COLORABLE), - /** - * A particle effect which is displayed by nether portals, endermen, ender - * pearls, eyes of ender, ender chests and dragon eggs: - *
    - *
  • It looks like a purple cloud - *
  • The speed value influences the spread of this particle effect - *
- */ - PORTAL("portal", 24, -1, ParticleProperty.DIRECTIONAL), - /** - * A particle effect which is displayed by enchantment tables which are nearby - * bookshelves: - *
    - *
  • It looks like a cryptic white letter - *
  • The speed value influences the spread of this particle effect - *
- */ - ENCHANTMENT_TABLE("enchantmenttable", 25, -1, ParticleProperty.DIRECTIONAL), - /** - * A particle effect which is displayed by torches, active furnaces, magma cubes - * and monster spawners: - *
    - *
  • It looks like a tiny flame - *
  • The speed value influences the velocity at which the particle flies off - *
- */ - FLAME("flame", 26, -1, ParticleProperty.DIRECTIONAL), - /** - * A particle effect which is displayed by lava: - *
    - *
  • It looks like a spark - *
  • The speed value has no influence on this particle effect - *
- */ - LAVA("lava", 27, -1), - /** - * A particle effect which is currently unused: - *
    - *
  • It looks like a transparent gray square - *
  • The speed value has no influence on this particle effect - *
- */ - FOOTSTEP("footstep", 28, -1), - /** - * A particle effect which is displayed when a mob dies: - *
    - *
  • It looks like a large white cloud - *
  • The speed value influences the velocity at which the particle flies off - *
- */ - CLOUD("cloud", 29, -1, ParticleProperty.DIRECTIONAL), - /** - * A particle effect which is displayed by redstone ore, powered redstone, - * redstone torches and redstone repeaters: - *
    - *
  • It looks like a tiny colored cloud - *
  • The speed value causes the particle to be colored red when set to 0 - *
- */ - REDSTONE("reddust", 30, -1, ParticleProperty.COLORABLE), - /** - * A particle effect which is displayed when snowballs hit a block: - *
    - *
  • It looks like a little piece with the snowball texture - *
  • The speed value has no influence on this particle effect - *
- */ - SNOWBALL("snowballpoof", 31, -1), - /** - * A particle effect which is currently unused: - *
    - *
  • It looks like a tiny white cloud - *
  • The speed value influences the velocity at which the particle flies off - *
- */ - SNOW_SHOVEL("snowshovel", 32, -1, ParticleProperty.DIRECTIONAL), - /** - * A particle effect which is displayed by slimes: - *
    - *
  • It looks like a tiny part of the slimeball icon - *
  • The speed value has no influence on this particle effect - *
- */ - SLIME("slime", 33, -1), - /** - * A particle effect which is displayed when breeding and taming animals: - *
    - *
  • It looks like a red heart - *
  • The speed value has no influence on this particle effect - *
- */ - HEART("heart", 34, -1), - /** - * A particle effect which is displayed by barriers: - *
    - *
  • It looks like a red box with a slash through it - *
  • The speed value has no influence on this particle effect - *
- */ - BARRIER("barrier", 35, 8), - /** - * A particle effect which is displayed when breaking a tool or eggs hit a - * block: - *
    - *
  • It looks like a little piece with an item texture - *
- */ - ITEM_CRACK("iconcrack", 36, -1, ParticleProperty.DIRECTIONAL, ParticleProperty.REQUIRES_DATA), - /** - * A particle effect which is displayed when breaking blocks or sprinting: - *
    - *
  • It looks like a little piece with a block texture - *
  • The speed value has no influence on this particle effect - *
- */ - BLOCK_CRACK("blockcrack", 37, -1, ParticleProperty.REQUIRES_DATA), - /** - * A particle effect which is displayed when falling: - *
    - *
  • It looks like a little piece with a block texture - *
- */ - BLOCK_DUST("blockdust", 38, 7, ParticleProperty.DIRECTIONAL, ParticleProperty.REQUIRES_DATA), - /** - * A particle effect which is displayed when rain hits the ground: - *
    - *
  • It looks like a blue droplet - *
  • The speed value has no influence on this particle effect - *
- */ - WATER_DROP("droplet", 39, 8), - /** - * A particle effect which is currently unused: - *
    - *
  • It has no visual effect - *
- */ - ITEM_TAKE("take", 40, 8), - - /** - * A particle effect which is displayed by elder guardians: - *
    - *
  • It looks like the shape of the elder guardian - *
  • The speed value has no influence on this particle effect - *
  • The offset values have no influence on this particle effect - *
- */ - MOB_APPEARANCE("mobappearance", 41, 8), - - /** - * A particle effect which is displayed by enderdragons - */ - DRAGON_BREATH("dragonbreath", 42, 9), - - /** - * The end rod particle effect from end rods - */ - END_ROD("endrod", 43, 9), - - /** - * A damage indicator particle effect - */ - DAMAGE_INDICATOR("damageindicator", 44, 9), - - /** - * A swipe sword effect - */ - SWEEP_ATTACK("sweepttack", 45, 9); - - private static final Map NAME_MAP = new HashMap(); - private static final Map ID_MAP = new HashMap(); - private final String name; - private final int id; - private final int requiredVersion; - private final List properties; - - // Initialize map for quick name and id lookup - static - { - for(ParticleEffect effect : values()) - { - NAME_MAP.put(effect.name, effect); - ID_MAP.put(effect.id, effect); - } - } - - /** - * Construct a new particle effect - * - * @param name - * Name of this particle effect - * @param id - * Id of this particle effect - * @param requiredVersion - * Version which is required (1.x) - * @param properties - * Properties of this particle effect - */ - private ParticleEffect(String name, int id, int requiredVersion, ParticleProperty... properties) - { - this.name = name; - this.id = id; - this.requiredVersion = requiredVersion; - this.properties = Arrays.asList(properties); - } - - /** - * Returns the name of this particle effect - * - * @return The name - */ - public String getName() - { - return name; - } - - /** - * Returns the id of this particle effect - * - * @return The id - */ - public int getId() - { - return id; - } - - /** - * Returns the required version for this particle effect (1.x) - * - * @return The required version - */ - public int getRequiredVersion() - { - return requiredVersion; - } - - /** - * Determine if this particle effect has a specific property - * - * @return Whether it has the property or not - */ - public boolean hasProperty(ParticleProperty property) - { - return properties.contains(property); - } - - /** - * Determine if this particle effect is supported by your current server version - * - * @return Whether the particle effect is supported or not - */ - public boolean isSupported() - { - return true; - } - - /** - * Returns the particle effect with the given name - * - * @param name - * Name of the particle effect - * @return The particle effect - */ - public static ParticleEffect fromName(String name) - { - for(Entry entry : NAME_MAP.entrySet()) - { - if(!entry.getKey().equalsIgnoreCase(name)) - { - continue; - } - return entry.getValue(); - } - return null; - } - - /** - * Returns the particle effect with the given id - * - * @param id - * Id of the particle effect - * @return The particle effect - */ - public static ParticleEffect fromId(int id) - { - for(Entry entry : ID_MAP.entrySet()) - { - if(entry.getKey() != id) - { - continue; - } - return entry.getValue(); - } - return null; - } - - /** - * Determine if water is at a certain location - * - * @param location - * Location to check - * @return Whether water is at this location or not - */ - private static boolean isWater(Location location) - { - Material material = location.getBlock().getType(); - return false; - } - - /** - * Determine if the distance between @param location and one of the players - * exceeds 256 - * - * @param location - * Location to check - * @return Whether the distance exceeds 256 or not - */ - private static boolean isLongDistance(Location location, List players) - { - String world = location.getWorld().getName(); - for(Player player : players) - { - Location playerLocation = player.getLocation(); - if(!world.equals(playerLocation.getWorld().getName()) || playerLocation.distanceSquared(location) < 65536) - { - continue; - } - return true; - } - return false; - } - - /** - * Determine if the data type for a particle effect is correct - * - * @param effect - * Particle effect - * @param data - * Particle data - * @return Whether the data type is correct or not - */ - private static boolean isDataCorrect(ParticleEffect effect, ParticleData data) - { - return ((effect == BLOCK_CRACK || effect == BLOCK_DUST) && data instanceof BlockData) || (effect == ITEM_CRACK && data instanceof ItemData); - } - - /** - * Determine if the color type for a particle effect is correct - * - * @param effect - * Particle effect - * @param color - * Particle color - * @return Whether the color type is correct or not - */ - private static boolean isColorCorrect(ParticleEffect effect, ParticleColor color) - { - return ((effect == SPELL_MOB || effect == SPELL_MOB_AMBIENT || effect == REDSTONE) && color instanceof OrdinaryColor) || (effect == NOTE && color instanceof NoteColor); - } - - /** - * Displays a particle effect which is only visible for all players within a - * certain range in the world of @param center - * - * @param offsetX - * Maximum distance particles can fly away from the center on the - * x-axis - * @param offsetY - * Maximum distance particles can fly away from the center on the - * y-axis - * @param offsetZ - * Maximum distance particles can fly away from the center on the - * z-axis - * @param speed - * Display speed of the particles - * @param amount - * Amount of particles - * @param center - * Center location of the effect - * @param range - * Range of the visibility - * @throws ParticleVersionException - * If the particle effect is not supported by the server version - * @throws ParticleDataException - * If the particle effect requires additional data - * @throws IllegalArgumentException - * If the particle effect requires water and none is at the center - * location - * @see ParticlePacket - * @see ParticlePacket#sendTo(Location, double) - */ - public void display(float speed, int amount, Location center, double range) throws ParticleVersionException, ParticleDataException, IllegalArgumentException - { - if(!isSupported()) - { - return; - } - - if(hasProperty(ParticleProperty.REQUIRES_DATA)) - { - throw new ParticleDataException("This particle effect requires additional data"); - } - - if(hasProperty(ParticleProperty.REQUIRES_WATER) && !isWater(center)) - { - throw new IllegalArgumentException("There is no water at the center location"); - } - - new ParticlePacket(this, 0, 0, 0, speed, amount, range > 256, null).sendTo(center, range); - } - - /** - * Displays a particle effect which is only visible for the specified players - * - * @param offsetX - * Maximum distance particles can fly away from the center on the - * x-axis - * @param offsetY - * Maximum distance particles can fly away from the center on the - * y-axis - * @param offsetZ - * Maximum distance particles can fly away from the center on the - * z-axis - * @param speed - * Display speed of the particles - * @param amount - * Amount of particles - * @param center - * Center location of the effect - * @param players - * Receivers of the effect - * @throws ParticleVersionException - * If the particle effect is not supported by the server version - * @throws ParticleDataException - * If the particle effect requires additional data - * @throws IllegalArgumentException - * If the particle effect requires water and none is at the center - * location - * @see ParticlePacket - * @see ParticlePacket#sendTo(Location, List) - */ - public void display(float speed, int amount, Location center, List players) throws ParticleVersionException, ParticleDataException, IllegalArgumentException - { - if(!isSupported()) - { - throw new ParticleVersionException("This particle effect is not supported by your server version"); - } - if(hasProperty(ParticleProperty.REQUIRES_DATA)) - { - throw new ParticleDataException("This particle effect requires additional data"); - } - if(hasProperty(ParticleProperty.REQUIRES_WATER) && !isWater(center)) - { - throw new IllegalArgumentException("There is no water at the center location"); - } - new ParticlePacket(this, 0, 0, 0, speed, amount, isLongDistance(center, players), null).sendTo(center, players); - } - - /** - * Displays a particle effect which is only visible for the specified players - * - * @param offsetX - * Maximum distance particles can fly away from the center on the - * x-axis - * @param offsetY - * Maximum distance particles can fly away from the center on the - * y-axis - * @param offsetZ - * Maximum distance particles can fly away from the center on the - * z-axis - * @param speed - * Display speed of the particles - * @param amount - * Amount of particles - * @param center - * Center location of the effect - * @param players - * Receivers of the effect - * @throws ParticleVersionException - * If the particle effect is not supported by the server version - * @throws ParticleDataException - * If the particle effect requires additional data - * @throws IllegalArgumentException - * If the particle effect requires water and none is at the center - * location - * @see #display(float, float, float, float, int, Location, List) - */ - public void display(float speed, int amount, Location center, Player... players) throws ParticleVersionException, ParticleDataException, IllegalArgumentException - { - display(speed, amount, center, Arrays.asList(players)); - } - - /** - * Displays a single particle which flies into a determined direction and is - * only visible for all players within a certain range in the world of @param - * center - * - * @param direction - * Direction of the particle - * @param speed - * Display speed of the particle - * @param center - * Center location of the effect - * @param range - * Range of the visibility - * @throws ParticleVersionException - * If the particle effect is not supported by the server version - * @throws ParticleDataException - * If the particle effect requires additional data - * @throws IllegalArgumentException - * If the particle effect is not directional or if it requires water - * and none is at the center location - * @see ParticlePacket#ParticlePacket(ParticleEffect, Vector, float, boolean, - * ParticleData) - * @see ParticlePacket#sendTo(Location, double) - */ - public void display(Vector direction, float speed, Location center, double range) throws ParticleVersionException, ParticleDataException, IllegalArgumentException - { - if(!isSupported()) - { - throw new ParticleVersionException("This particle effect is not supported by your server version"); - } - if(hasProperty(ParticleProperty.REQUIRES_DATA)) - { - throw new ParticleDataException("This particle effect requires additional data"); - } - if(!hasProperty(ParticleProperty.DIRECTIONAL)) - { - throw new IllegalArgumentException("This particle effect is not directional"); - } - if(hasProperty(ParticleProperty.REQUIRES_WATER) && !isWater(center)) - { - throw new IllegalArgumentException("There is no water at the center location"); - } - new ParticlePacket(this, direction, speed, range > 256, null).sendTo(center, range); - } - - /** - * Displays a single particle which flies into a determined direction and is - * only visible for the specified players - * - * @param direction - * Direction of the particle - * @param speed - * Display speed of the particle - * @param center - * Center location of the effect - * @param players - * Receivers of the effect - * @throws ParticleVersionException - * If the particle effect is not supported by the server version - * @throws ParticleDataException - * If the particle effect requires additional data - * @throws IllegalArgumentException - * If the particle effect is not directional or if it requires water - * and none is at the center location - * @see ParticlePacket#ParticlePacket(ParticleEffect, Vector, float, boolean, - * ParticleData) - * @see ParticlePacket#sendTo(Location, List) - */ - public void display(Vector direction, float speed, Location center, List players) throws ParticleVersionException, ParticleDataException, IllegalArgumentException - { - if(!isSupported()) - { - throw new ParticleVersionException("This particle effect is not supported by your server version"); - } - if(hasProperty(ParticleProperty.REQUIRES_DATA)) - { - throw new ParticleDataException("This particle effect requires additional data"); - } - if(!hasProperty(ParticleProperty.DIRECTIONAL)) - { - throw new IllegalArgumentException("This particle effect is not directional"); - } - if(hasProperty(ParticleProperty.REQUIRES_WATER) && !isWater(center)) - { - throw new IllegalArgumentException("There is no water at the center location"); - } - new ParticlePacket(this, direction, speed, isLongDistance(center, players), null).sendTo(center, players); - } - - /** - * Displays a single particle which flies into a determined direction and is - * only visible for the specified players - * - * @param direction - * Direction of the particle - * @param speed - * Display speed of the particle - * @param center - * Center location of the effect - * @param players - * Receivers of the effect - * @throws ParticleVersionException - * If the particle effect is not supported by the server version - * @throws ParticleDataException - * If the particle effect requires additional data - * @throws IllegalArgumentException - * If the particle effect is not directional or if it requires water - * and none is at the center location - * @see #display(Vector, float, Location, List) - */ - public void display(Vector direction, float speed, Location center, Player... players) throws ParticleVersionException, ParticleDataException, IllegalArgumentException - { - display(direction, speed, center, Arrays.asList(players)); - } - - /** - * Displays a single particle which is colored and only visible for all players - * within a certain range in the world of @param center - * - * @param color - * Color of the particle - * @param center - * Center location of the effect - * @param range - * Range of the visibility - * @throws ParticleVersionException - * If the particle effect is not supported by the server version - * @throws ParticleColorException - * If the particle effect is not colorable or the color type is - * incorrect - * @see ParticlePacket#ParticlePacket(ParticleEffect, ParticleColor, boolean) - * @see ParticlePacket#sendTo(Location, double) - */ - public void display(ParticleColor color, Location center, double range) throws ParticleVersionException, ParticleColorException - { - if(!isSupported()) - { - throw new ParticleVersionException("This particle effect is not supported by your server version"); - } - if(!hasProperty(ParticleProperty.COLORABLE)) - { - throw new ParticleColorException("This particle effect is not colorable"); - } - if(!isColorCorrect(this, color)) - { - throw new ParticleColorException("The particle color type is incorrect"); - } - new ParticlePacket(this, color, range > 256).sendTo(center, range); - } - - /** - * Displays a single particle which is colored and only visible for the - * specified players - * - * @param color - * Color of the particle - * @param center - * Center location of the effect - * @param players - * Receivers of the effect - * @throws ParticleVersionException - * If the particle effect is not supported by the server version - * @throws ParticleColorException - * If the particle effect is not colorable or the color type is - * incorrect - * @see ParticlePacket#ParticlePacket(ParticleEffect, ParticleColor, boolean) - * @see ParticlePacket#sendTo(Location, List) - */ - public void display(ParticleColor color, Location center, List players) throws ParticleVersionException, ParticleColorException - { - if(!isSupported()) - { - throw new ParticleVersionException("This particle effect is not supported by your server version"); - } - if(!hasProperty(ParticleProperty.COLORABLE)) - { - throw new ParticleColorException("This particle effect is not colorable"); - } - if(!isColorCorrect(this, color)) - { - throw new ParticleColorException("The particle color type is incorrect"); - } - new ParticlePacket(this, color, isLongDistance(center, players)).sendTo(center, players); - } - - /** - * Displays a single particle which is colored and only visible for the - * specified players - * - * @param color - * Color of the particle - * @param center - * Center location of the effect - * @param players - * Receivers of the effect - * @throws ParticleVersionException - * If the particle effect is not supported by the server version - * @throws ParticleColorException - * If the particle effect is not colorable or the color type is - * incorrect - * @see #display(ParticleColor, Location, List) - */ - public void display(ParticleColor color, Location center, Player... players) throws ParticleVersionException, ParticleColorException - { - display(color, center, Arrays.asList(players)); - } - - /** - * Displays a particle effect which requires additional data and is only visible - * for all players within a certain range in the world of @param center - * - * @param data - * Data of the effect - * @param offsetX - * Maximum distance particles can fly away from the center on the - * x-axis - * @param offsetY - * Maximum distance particles can fly away from the center on the - * y-axis - * @param offsetZ - * Maximum distance particles can fly away from the center on the - * z-axis - * @param speed - * Display speed of the particles - * @param amount - * Amount of particles - * @param center - * Center location of the effect - * @param range - * Range of the visibility - * @throws ParticleVersionException - * If the particle effect is not supported by the server version - * @throws ParticleDataException - * If the particle effect does not require additional data or if the - * data type is incorrect - * @see ParticlePacket - * @see ParticlePacket#sendTo(Location, double) - */ - public void display(ParticleData data, float speed, int amount, Location center, double range) throws ParticleVersionException, ParticleDataException - { - if(!isSupported()) - { - throw new ParticleVersionException("This particle effect is not supported by your server version"); - } - - if(!hasProperty(ParticleProperty.REQUIRES_DATA)) - { - throw new ParticleDataException("This particle effect does not require additional data"); - } - - if(!isDataCorrect(this, data)) - { - throw new ParticleDataException("The particle data type is incorrect"); - } - - new ParticlePacket(this, 0, 0, 0, speed, amount, range > 256, data).sendTo(center, range); - } - - /** - * Displays a particle effect which requires additional data and is only visible - * for the specified players - * - * @param data - * Data of the effect - * @param offsetX - * Maximum distance particles can fly away from the center on the - * x-axis - * @param offsetY - * Maximum distance particles can fly away from the center on the - * y-axis - * @param offsetZ - * Maximum distance particles can fly away from the center on the - * z-axis - * @param speed - * Display speed of the particles - * @param amount - * Amount of particles - * @param center - * Center location of the effect - * @param players - * Receivers of the effect - * @throws ParticleVersionException - * If the particle effect is not supported by the server version - * @throws ParticleDataException - * If the particle effect does not require additional data or if the - * data type is incorrect - * @see ParticlePacket - * @see ParticlePacket#sendTo(Location, List) - */ - public void display(ParticleData data, float speed, int amount, Location center, List players) throws ParticleVersionException, ParticleDataException - { - if(!isSupported()) - { - throw new ParticleVersionException("This particle effect is not supported by your server version"); - } - if(!hasProperty(ParticleProperty.REQUIRES_DATA)) - { - throw new ParticleDataException("This particle effect does not require additional data"); - } - if(!isDataCorrect(this, data)) - { - throw new ParticleDataException("The particle data type is incorrect"); - } - new ParticlePacket(this, 0, 0, 0, speed, amount, isLongDistance(center, players), data).sendTo(center, players); - } - - /** - * Displays a particle effect which requires additional data and is only visible - * for the specified players - * - * @param data - * Data of the effect - * @param offsetX - * Maximum distance particles can fly away from the center on the - * x-axis - * @param offsetY - * Maximum distance particles can fly away from the center on the - * y-axis - * @param offsetZ - * Maximum distance particles can fly away from the center on the - * z-axis - * @param speed - * Display speed of the particles - * @param amount - * Amount of particles - * @param center - * Center location of the effect - * @param players - * Receivers of the effect - * @throws ParticleVersionException - * If the particle effect is not supported by the server version - * @throws ParticleDataException - * If the particle effect does not require additional data or if the - * data type is incorrect - * @see #display(ParticleData, float, float, float, float, int, Location, List) - */ - public void display(ParticleData data, float speed, int amount, Location center, Player... players) throws ParticleVersionException, ParticleDataException - { - display(data, speed, amount, center, Arrays.asList(players)); - } - - /** - * Displays a single particle which requires additional data that flies into a - * determined direction and is only visible for all players within a certain - * range in the world of @param center - * - * @param data - * Data of the effect - * @param direction - * Direction of the particle - * @param speed - * Display speed of the particles - * @param center - * Center location of the effect - * @param range - * Range of the visibility - * @throws ParticleVersionException - * If the particle effect is not supported by the server version - * @throws ParticleDataException - * If the particle effect does not require additional data or if the - * data type is incorrect - * @see ParticlePacket - * @see ParticlePacket#sendTo(Location, double) - */ - public void display(ParticleData data, Vector direction, float speed, Location center, double range) throws ParticleVersionException, ParticleDataException - { - if(!isSupported()) - { - throw new ParticleVersionException("This particle effect is not supported by your server version"); - } - if(!hasProperty(ParticleProperty.REQUIRES_DATA)) - { - throw new ParticleDataException("This particle effect does not require additional data"); - } - if(!isDataCorrect(this, data)) - { - throw new ParticleDataException("The particle data type is incorrect"); - } - new ParticlePacket(this, direction, speed, range > 256, data).sendTo(center, range); - } - - /** - * Displays a single particle which requires additional data that flies into a - * determined direction and is only visible for the specified players - * - * @param data - * Data of the effect - * @param direction - * Direction of the particle - * @param speed - * Display speed of the particles - * @param center - * Center location of the effect - * @param players - * Receivers of the effect - * @throws ParticleVersionException - * If the particle effect is not supported by the server version - * @throws ParticleDataException - * If the particle effect does not require additional data or if the - * data type is incorrect - * @see ParticlePacket - * @see ParticlePacket#sendTo(Location, List) - */ - public void display(ParticleData data, Vector direction, float speed, Location center, List players) throws ParticleVersionException, ParticleDataException - { - if(!isSupported()) - { - throw new ParticleVersionException("This particle effect is not supported by your server version"); - } - if(!hasProperty(ParticleProperty.REQUIRES_DATA)) - { - throw new ParticleDataException("This particle effect does not require additional data"); - } - if(!isDataCorrect(this, data)) - { - throw new ParticleDataException("The particle data type is incorrect"); - } - new ParticlePacket(this, direction, speed, isLongDistance(center, players), data).sendTo(center, players); - } - - /** - * Displays a single particle which requires additional data that flies into a - * determined direction and is only visible for the specified players - * - * @param data - * Data of the effect - * @param direction - * Direction of the particle - * @param speed - * Display speed of the particles - * @param center - * Center location of the effect - * @param players - * Receivers of the effect - * @throws ParticleVersionException - * If the particle effect is not supported by the server version - * @throws ParticleDataException - * If the particle effect does not require additional data or if the - * data type is incorrect - * @see #display(ParticleData, Vector, float, Location, List) - */ - public void display(ParticleData data, Vector direction, float speed, Location center, Player... players) throws ParticleVersionException, ParticleDataException - { - display(data, direction, speed, center, Arrays.asList(players)); - } - - /** - * Represents the property of a particle effect - *

- * This class is part of the ParticleEffect Library and follows the same - * usage conditions - * - * @author DarkBlade12 - * @since 1.7 - */ - public static enum ParticleProperty - { - /** - * The particle effect requires water to be displayed - */ - REQUIRES_WATER, - /** - * The particle effect requires block or item data to be displayed - */ - REQUIRES_DATA, - /** - * The particle effect uses the offsets as direction values - */ - DIRECTIONAL, - /** - * The particle effect uses the offsets as color values - */ - COLORABLE; - } - - /** - * Represents the particle data for effects like - * {@link ParticleEffect#ITEM_CRACK}, {@link ParticleEffect#BLOCK_CRACK} and - * {@link ParticleEffect#BLOCK_DUST} - *

- * This class is part of the ParticleEffect Library and follows the same - * usage conditions - * - * @author DarkBlade12 - * @since 1.6 - */ - public static abstract class ParticleData - { - private final Material material; - private final byte data; - private final int[] packetData; - - /** - * Construct a new particle data - * - * @param material - * Material of the item/block - * @param data - * Data value of the item/block - */ - @SuppressWarnings("deprecation") - public ParticleData(Material material, byte data) - { - this.material = material; - this.data = data; - this.packetData = new int[] {material.getId(), data}; - } - - /** - * Returns the material of this data - * - * @return The material - */ - public Material getMaterial() - { - return material; - } - - /** - * Returns the data value of this data - * - * @return The data value - */ - public byte getData() - { - return data; - } - - /** - * Returns the data as an int array for packet construction - * - * @return The data for the packet - */ - public int[] getPacketData() - { - return packetData; - } - - /** - * Returns the data as a string for pre 1.8 versions - * - * @return The data string for the packet - */ - public String getPacketDataString() - { - return "_" + packetData[0] + "_" + packetData[1]; - } - } - - /** - * Represents the item data for the {@link ParticleEffect#ITEM_CRACK} effect - *

- * This class is part of the ParticleEffect Library and follows the same - * usage conditions - * - * @author DarkBlade12 - * @since 1.6 - */ - public static final class ItemData extends ParticleData - { - /** - * Construct a new item data - * - * @param material - * Material of the item - * @param data - * Data value of the item - * @see ParticleData#ParticleData(Material, byte) - */ - public ItemData(Material material, byte data) - { - super(material, data); - } - } - - /** - * Represents the block data for the {@link ParticleEffect#BLOCK_CRACK} and - * {@link ParticleEffect#BLOCK_DUST} effects - *

- * This class is part of the ParticleEffect Library and follows the same - * usage conditions - * - * @author DarkBlade12 - * @since 1.6 - */ - public static final class BlockData extends ParticleData - { - /** - * Construct a new block data - * - * @param material - * Material of the block - * @param data - * Data value of the block - * @throws IllegalArgumentException - * If the material is not a block - * @see ParticleData#ParticleData(Material, byte) - */ - public BlockData(Material material, byte data) throws IllegalArgumentException - { - super(material, data); - if(!material.isBlock()) - { - throw new IllegalArgumentException("The material is not a block"); - } - } - } - - /** - * Represents the color for effects like {@link ParticleEffect#SPELL_MOB}, - * {@link ParticleEffect#SPELL_MOB_AMBIENT}, {@link ParticleEffect#REDSTONE} and - * {@link ParticleEffect#NOTE} - *

- * This class is part of the ParticleEffect Library and follows the same - * usage conditions - * - * @author DarkBlade12 - * @since 1.7 - */ - public static abstract class ParticleColor - { - /** - * Returns the value for the offsetX field - * - * @return The offsetX value - */ - public abstract float getValueX(); - - /** - * Returns the value for the offsetY field - * - * @return The offsetY value - */ - public abstract float getValueY(); - - /** - * Returns the value for the offsetZ field - * - * @return The offsetZ value - */ - public abstract float getValueZ(); - } - - /** - * Represents the color for effects like {@link ParticleEffect#SPELL_MOB}, - * {@link ParticleEffect#SPELL_MOB_AMBIENT} and {@link ParticleEffect#NOTE} - *

- * This class is part of the ParticleEffect Library and follows the same - * usage conditions - * - * @author DarkBlade12 - * @since 1.7 - */ - public static final class OrdinaryColor extends ParticleColor - { - private final int red; - private final int green; - private final int blue; - - /** - * Construct a new ordinary color - * - * @param red - * Red value of the RGB format - * @param green - * Green value of the RGB format - * @param blue - * Blue value of the RGB format - * @throws IllegalArgumentException - * If one of the values is lower than 0 or higher than 255 - */ - public OrdinaryColor(int red, int green, int blue) throws IllegalArgumentException - { - if(red < 0) - { - throw new IllegalArgumentException("The red value is lower than 0"); - } - if(red > 255) - { - throw new IllegalArgumentException("The red value is higher than 255"); - } - this.red = red; - if(green < 0) - { - throw new IllegalArgumentException("The green value is lower than 0"); - } - if(green > 255) - { - throw new IllegalArgumentException("The green value is higher than 255"); - } - this.green = green; - if(blue < 0) - { - throw new IllegalArgumentException("The blue value is lower than 0"); - } - if(blue > 255) - { - throw new IllegalArgumentException("The blue value is higher than 255"); - } - this.blue = blue; - } - - /** - * Construct a new ordinary color - * - * @param color - * Bukkit color - */ - public OrdinaryColor(Color color) - { - this(color.getRed(), color.getGreen(), color.getBlue()); - } - - /** - * Returns the red value of the RGB format - * - * @return The red value - */ - public int getRed() - { - return red; - } - - /** - * Returns the green value of the RGB format - * - * @return The green value - */ - public int getGreen() - { - return green; - } - - /** - * Returns the blue value of the RGB format - * - * @return The blue value - */ - public int getBlue() - { - return blue; - } - - /** - * Returns the red value divided by 255 - * - * @return The offsetX value - */ - @Override - public float getValueX() - { - return (float) red / 255F; - } - - /** - * Returns the green value divided by 255 - * - * @return The offsetY value - */ - @Override - public float getValueY() - { - return (float) green / 255F; - } - - /** - * Returns the blue value divided by 255 - * - * @return The offsetZ value - */ - @Override - public float getValueZ() - { - return (float) blue / 255F; - } - } - - /** - * Represents the color for the {@link ParticleEffect#NOTE} effect - *

- * This class is part of the ParticleEffect Library and follows the same - * usage conditions - * - * @author DarkBlade12 - * @since 1.7 - */ - public static final class NoteColor extends ParticleColor - { - private final int note; - - /** - * Construct a new note color - * - * @param note - * Note id which determines color - * @throws IllegalArgumentException - * If the note value is lower than 0 or higher than 24 - */ - public NoteColor(int note) throws IllegalArgumentException - { - if(note < 0) - { - throw new IllegalArgumentException("The note value is lower than 0"); - } - if(note > 24) - { - throw new IllegalArgumentException("The note value is higher than 24"); - } - this.note = note; - } - - /** - * Returns the note value divided by 24 - * - * @return The offsetX value - */ - @Override - public float getValueX() - { - return (float) note / 24F; - } - - /** - * Returns zero because the offsetY value is unused - * - * @return zero - */ - @Override - public float getValueY() - { - return 0; - } - - /** - * Returns zero because the offsetZ value is unused - * - * @return zero - */ - @Override - public float getValueZ() - { - return 0; - } - - } - - /** - * Represents a runtime exception that is thrown either if the displayed - * particle effect requires data and has none or vice-versa or if the data type - * is incorrect - *

- * This class is part of the ParticleEffect Library and follows the same - * usage conditions - * - * @author DarkBlade12 - * @since 1.6 - */ - private static final class ParticleDataException extends RuntimeException - { - private static final long serialVersionUID = 3203085387160737484L; - - /** - * Construct a new particle data exception - * - * @param message - * Message that will be logged - */ - public ParticleDataException(String message) - { - super(message); - } - } - - /** - * Represents a runtime exception that is thrown either if the displayed - * particle effect is not colorable or if the particle color type is incorrect - *

- * This class is part of the ParticleEffect Library and follows the same - * usage conditions - * - * @author DarkBlade12 - * @since 1.7 - */ - private static final class ParticleColorException extends RuntimeException - { - private static final long serialVersionUID = 3203085387160737484L; - - /** - * Construct a new particle color exception - * - * @param message - * Message that will be logged - */ - public ParticleColorException(String message) - { - super(message); - } - } - - /** - * Represents a runtime exception that is thrown if the displayed particle - * effect requires a newer version - *

- * This class is part of the ParticleEffect Library and follows the same - * usage conditions - * - * @author DarkBlade12 - * @since 1.6 - */ - private static final class ParticleVersionException extends RuntimeException - { - private static final long serialVersionUID = 3203085387160737484L; - - /** - * Construct a new particle version exception - * - * @param message - * Message that will be logged - */ - public ParticleVersionException(String message) - { - super(message); - } - } - - /** - * Represents a particle effect packet with all attributes which is used for - * sending packets to the players - *

- * This class is part of the ParticleEffect Library and follows the same - * usage conditions - * - * @author DarkBlade12 - * @since 1.5 - */ - public static final class ParticlePacket - { - private static int version; - private static Class enumParticle; - private static Constructor packetConstructor; - private static Method getHandle; - private static Field playerConnection; - private static Method sendPacket; - private static boolean initialized; - private final ParticleEffect effect; - private float offsetX; - private final float offsetY; - private final float offsetZ; - private final float speed; - private final int amount; - private final boolean longDistance; - private final ParticleData data; - private Object packet; - - /** - * Construct a new particle packet - * - * @param effect - * Particle effect - * @param offsetX - * Maximum distance particles can fly away from the center on the - * x-axis - * @param offsetY - * Maximum distance particles can fly away from the center on the - * y-axis - * @param offsetZ - * Maximum distance particles can fly away from the center on the - * z-axis - * @param speed - * Display speed of the particles - * @param amount - * Amount of particles - * @param longDistance - * Indicates whether the maximum distance is increased from 256 to - * 65536 - * @param data - * Data of the effect - * @throws IllegalArgumentException - * If the speed or amount is lower than 0 - * @see #initialize() - */ - public ParticlePacket(ParticleEffect effect, float offsetX, float offsetY, float offsetZ, float speed, int amount, boolean longDistance, ParticleData data) throws IllegalArgumentException - { - initialize(); - if(speed < 0) - { - throw new IllegalArgumentException("The speed is lower than 0"); - } - if(amount < 0) - { - throw new IllegalArgumentException("The amount is lower than 0"); - } - this.effect = effect; - this.offsetX = offsetX; - this.offsetY = offsetY; - this.offsetZ = offsetZ; - this.speed = speed; - this.amount = amount; - this.longDistance = longDistance; - this.data = data; - } - - /** - * Construct a new particle packet of a single particle flying into a determined - * direction - * - * @param effect - * Particle effect - * @param direction - * Direction of the particle - * @param speed - * Display speed of the particle - * @param longDistance - * Indicates whether the maximum distance is increased from 256 to - * 65536 - * @param data - * Data of the effect - * @throws IllegalArgumentException - * If the speed is lower than 0 - * @see #ParticleEffect(ParticleEffect, float, float, float, float, int, - * boolean, ParticleData) - */ - public ParticlePacket(ParticleEffect effect, Vector direction, float speed, boolean longDistance, ParticleData data) throws IllegalArgumentException - { - this(effect, (float) direction.getX(), (float) direction.getY(), (float) direction.getZ(), speed, 0, longDistance, data); - } - - /** - * Construct a new particle packet of a single colored particle - * - * @param effect - * Particle effect - * @param color - * Color of the particle - * @param longDistance - * Indicates whether the maximum distance is increased from 256 to - * 65536 - * @see #ParticleEffect(ParticleEffect, float, float, float, float, int, - * boolean, ParticleData) - */ - public ParticlePacket(ParticleEffect effect, ParticleColor color, boolean longDistance) - { - this(effect, color.getValueX(), color.getValueY(), color.getValueZ(), 1, 0, longDistance, null); - if(effect == ParticleEffect.REDSTONE && color instanceof OrdinaryColor && ((OrdinaryColor) color).getRed() == 0) - { - offsetX = Float.MIN_NORMAL; - } - } - - /** - * Initializes {@link #packetConstructor}, {@link #getHandle}, - * {@link #playerConnection} and {@link #sendPacket} and sets - * {@link #initialized} to true if it succeeds - *

- * Note: These fields only have to be initialized once, so it will return - * if {@link #initialized} is already set to true - * - * @throws VersionIncompatibleException - * if your bukkit version is not supported by this library - */ - public static void initialize() throws VersionIncompatibleException - { - if(initialized) - { - return; - } - - try - { - String ver = PackageType.getServerVersion(); - int un1 = ver.indexOf("_") + 1; - int un2 = ver.lastIndexOf("_"); - - version = Integer.parseInt(ver.substring(un1, un2)); - - if(version > 7) - { - enumParticle = PackageType.MINECRAFT_SERVER.getClass("EnumParticle"); - } - - Class packetClass = PackageType.MINECRAFT_SERVER.getClass(version < 7 ? "Packet63WorldParticles" : "PacketPlayOutWorldParticles"); - - packetConstructor = ReflectionUtils.getConstructor(packetClass); - getHandle = ReflectionUtils.getMethod("CraftPlayer", PackageType.CRAFTBUKKIT_ENTITY, "getHandle"); - playerConnection = ReflectionUtils.getField("EntityPlayer", PackageType.MINECRAFT_SERVER, false, "playerConnection"); - sendPacket = ReflectionUtils.getMethod(playerConnection.getType(), "sendPacket", PackageType.MINECRAFT_SERVER.getClass("Packet")); - } - - catch(Exception exception) - { - - } - - initialized = true; - - if(initialized) - { - return; - } - } - - /** - * Returns the version of your server (1.x) - * - * @return The version number - */ - public static int getVersion() - { - if(!initialized) - { - initialize(); - } - return version; - } - - /** - * Determine if {@link #packetConstructor}, {@link #getHandle}, - * {@link #playerConnection} and {@link #sendPacket} are initialized - * - * @return Whether these fields are initialized or not - * @see #initialize() - */ - public static boolean isInitialized() - { - return initialized; - } - - /** - * Initializes {@link #packet} with all set values - * - * @param center - * Center location of the effect - * @throws PacketInstantiationException - * If instantion fails due to an unknown error - */ - private void initializePacket(Location center) throws PacketInstantiationException - { - if(packet != null) - { - return; - } - try - { - packet = packetConstructor.newInstance(); - - if(version < 8) - { - String name = effect.getName(); - if(data != null) - { - name += data.getPacketDataString(); - } - ReflectionUtils.setValue(packet, true, "a", name); - } - else - { - ReflectionUtils.setValue(packet, true, "a", enumParticle.getEnumConstants()[effect.getId()]); - ReflectionUtils.setValue(packet, true, "j", longDistance); - if(data != null) - { - int[] packetData = data.getPacketData(); - ReflectionUtils.setValue(packet, true, "k", effect == ParticleEffect.ITEM_CRACK ? packetData : new int[] {packetData[0] | (packetData[1] << 12)}); - } - } - ReflectionUtils.setValue(packet, true, "b", (float) center.getX()); - ReflectionUtils.setValue(packet, true, "c", (float) center.getY()); - ReflectionUtils.setValue(packet, true, "d", (float) center.getZ()); - ReflectionUtils.setValue(packet, true, "e", offsetX); - ReflectionUtils.setValue(packet, true, "f", offsetY); - ReflectionUtils.setValue(packet, true, "g", offsetZ); - ReflectionUtils.setValue(packet, true, "h", speed); - ReflectionUtils.setValue(packet, true, "i", amount); - } - - catch(Exception exception) - { - - } - } - - /** - * Sends the packet to a single player and caches it - * - * @param center - * Center location of the effect - * @param player - * Receiver of the packet - * @throws PacketInstantiationException - * If instantion fails due to an unknown error - * @throws PacketSendingException - * If sending fails due to an unknown error - * @see #initializePacket(Location) - */ - public void sendTo(Location center, Player player) throws PacketInstantiationException, PacketSendingException - { - initializePacket(center); - try - { - sendPacket.invoke(playerConnection.get(getHandle.invoke(player)), packet); - } - - catch(Exception exception) - { - } - } - - /** - * Sends the packet to all players in the list - * - * @param center - * Center location of the effect - * @param players - * Receivers of the packet - * @throws IllegalArgumentException - * If the player list is empty - * @see #sendTo(Location center, Player player) - */ - public void sendTo(Location center, List players) throws IllegalArgumentException - { - if(players.isEmpty()) - { - throw new IllegalArgumentException("The player list is empty"); - } - for(Player player : players) - { - sendTo(center, player); - } - } - - /** - * Sends the packet to all players in a certain range - * - * @param center - * Center location of the effect - * @param range - * Range in which players will receive the packet (Maximum range for - * particles is usually 16, but it can differ for some types) - * @throws IllegalArgumentException - * If the range is lower than 1 - * @see #sendTo(Location center, Player player) - */ - public void sendTo(Location center, double range) throws IllegalArgumentException - { - if(range < 1) - { - throw new IllegalArgumentException("The range is lower than 1"); - } - String worldName = center.getWorld().getName(); - double squared = range * range; - for(Player player : Bukkit.getOnlinePlayers()) - { - if(!player.getWorld().getName().equals(worldName) || player.getLocation().distanceSquared(center) > squared) - { - continue; - } - sendTo(center, player); - } - } - - /** - * Represents a runtime exception that is thrown if a bukkit version is not - * compatible with this library - *

- * This class is part of the ParticleEffect Library and follows the same - * usage conditions - * - * @author DarkBlade12 - * @since 1.5 - */ - private static final class VersionIncompatibleException extends RuntimeException - { - private static final long serialVersionUID = 3203085387160737484L; - - /** - * Construct a new version incompatible exception - * - * @param message - * Message that will be logged - * @param cause - * Cause of the exception - */ - public VersionIncompatibleException(String message, Throwable cause) - { - super(message, cause); - } - } - - /** - * Represents a runtime exception that is thrown if packet instantiation fails - *

- * This class is part of the ParticleEffect Library and follows the same - * usage conditions - * - * @author DarkBlade12 - * @since 1.4 - */ - private static final class PacketInstantiationException extends RuntimeException - { - private static final long serialVersionUID = 3203085387160737484L; - - /** - * Construct a new packet instantiation exception - * - * @param message - * Message that will be logged - * @param cause - * Cause of the exception - */ - public PacketInstantiationException(String message, Throwable cause) - { - super(message, cause); - } - } - - /** - * Represents a runtime exception that is thrown if packet sending fails - *

- * This class is part of the ParticleEffect Library and follows the same - * usage conditions - * - * @author DarkBlade12 - * @since 1.4 - */ - private static final class PacketSendingException extends RuntimeException - { - private static final long serialVersionUID = 3203085387160737484L; - - /** - * Construct a new packet sending exception - * - * @param message - * Message that will be logged - * @param cause - * Cause of the exception - */ - public PacketSendingException(String message, Throwable cause) - { - super(message, cause); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/ninja/bytecode/iris/util/ParticleRedstone.java b/src/main/java/ninja/bytecode/iris/util/ParticleRedstone.java deleted file mode 100644 index 369b0fb7c..000000000 --- a/src/main/java/ninja/bytecode/iris/util/ParticleRedstone.java +++ /dev/null @@ -1,56 +0,0 @@ -package ninja.bytecode.iris.util; - -import java.awt.Color; - -import org.bukkit.Location; -import org.bukkit.entity.Player; - -import ninja.bytecode.iris.util.ParticleEffect.OrdinaryColor; - -public class ParticleRedstone extends ParticleBase implements ColoredEffect -{ - private Color color; - private float size; - - public ParticleRedstone() - { - this.color = Color.WHITE; - size = 1f; - } - - @Override - public void play(Location l, double range) - { - ParticleEffect.REDSTONE.display(new OrdinaryColor(getColor().getRed(), getColor().getGreen(), getColor().getBlue()), l , range); - } - - @Override - public void play(Location l, Player p) - { - ParticleEffect.REDSTONE.display(new OrdinaryColor(getColor().getRed(), getColor().getGreen(), getColor().getBlue()), l , p); - } - - @Override - public ParticleRedstone setColor(Color color) - { - this.color = color; - return this; - } - - @Override - public Color getColor() - { - return color; - } - - public ParticleRedstone setSize(float size) - { - this.size = size; - return this; - } - - public float getSize() - { - return size; - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/PerformanceMode.java b/src/main/java/ninja/bytecode/iris/util/PerformanceMode.java deleted file mode 100644 index 3dfc3279f..000000000 --- a/src/main/java/ninja/bytecode/iris/util/PerformanceMode.java +++ /dev/null @@ -1,11 +0,0 @@ -package ninja.bytecode.iris.util; - -public enum PerformanceMode -{ - SINGLE_THREADED, - UNLIMITED, - MATCH_CPU, - DOUBLE_CPU, - HALF_CPU, - EXPLICIT, -} diff --git a/src/main/java/ninja/bytecode/iris/util/PerlinNoise.java b/src/main/java/ninja/bytecode/iris/util/PerlinNoise.java new file mode 100644 index 000000000..6b74faf34 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/util/PerlinNoise.java @@ -0,0 +1,175 @@ +package ninja.bytecode.iris.util; + +import java.util.Random; + +public class PerlinNoise extends BasePerlinNoiseGenerator +{ + + /** + * Creates an instance using the given PRNG. + * + * @param rand + * the PRNG used to generate the seed permutation + */ + public PerlinNoise(Random rand) + { + offsetX = rand.nextDouble() * 256; + offsetY = rand.nextDouble() * 256; + offsetZ = rand.nextDouble() * 256; + // The only reason why I'm re-implementing the constructor code is that I've + // read + // on at least 3 different sources that the permutation table should initially + // be + // populated with indices. + // "The permutation table is his answer to the issue of random numbers. + // First take an array of decent length, usually 256 values. Fill it + // sequentially with each + // number in that range: so index 1 gets 1, index 8 gets 8, index 251 gets 251, + // etc... + // Then randomly shuffle the values so you have a table of 256 random values, + // but only + // contains the values between 0 and 255." + // source: https://code.google.com/p/fractalterraingeneration/wiki/Perlin_Noise + for(int i = 0; i < 256; i++) + { + perm[i] = i; + } + for(int i = 0; i < 256; i++) + { + int pos = rand.nextInt(256 - i) + i; + int old = perm[i]; + perm[i] = perm[pos]; + perm[pos] = old; + perm[i + 256] = perm[i]; + } + } + + public static int floor(double x) + { + int floored = (int) x; + return x < floored ? floored - 1 : floored; + } + + /** + * Generates a rectangular section of this generator's noise. + * + * @param noise + * the output of the previous noise layer + * @param x + * the X offset + * @param y + * the Y offset + * @param z + * the Z offset + * @param sizeX + * the size on the X axis + * @param sizeY + * the size on the Y axis + * @param sizeZ + * the size on the Z axis + * @param scaleX + * the X scale parameter + * @param scaleY + * the Y scale parameter + * @param scaleZ + * the Z scale parameter + * @param amplitude + * the amplitude parameter + * @return {@code noise} with this layer of noise added + */ + public double[] getNoise(double[] noise, double x, double y, double z, int sizeX, int sizeY, int sizeZ, double scaleX, double scaleY, double scaleZ, double amplitude) + { + if(sizeY == 1) + { + return get2dNoise(noise, x, z, sizeX, sizeZ, scaleX, scaleZ, amplitude); + } + else + { + return get3dNoise(noise, x, y, z, sizeX, sizeY, sizeZ, scaleX, scaleY, scaleZ, amplitude); + } + } + + protected double[] get2dNoise(double[] noise, double x, double z, int sizeX, int sizeZ, double scaleX, double scaleZ, double amplitude) + { + int index = 0; + for(int i = 0; i < sizeX; i++) + { + double dx = x + offsetX + i * scaleX; + int floorX = floor(dx); + int ix = floorX & 255; + dx -= floorX; + double fx = fade(dx); + for(int j = 0; j < sizeZ; j++) + { + double dz = z + offsetZ + j * scaleZ; + int floorZ = floor(dz); + int iz = floorZ & 255; + dz -= floorZ; + double fz = fade(dz); + // Hash coordinates of the square corners + int a = perm[ix]; + int aa = perm[a] + iz; + int b = perm[ix + 1]; + int ba = perm[b] + iz; + double x1 = lerp(fx, grad(perm[aa], dx, 0, dz), grad(perm[ba], dx - 1, 0, dz)); + double x2 = lerp(fx, grad(perm[aa + 1], dx, 0, dz - 1), grad(perm[ba + 1], dx - 1, 0, dz - 1)); + noise[index++] += lerp(fz, x1, x2) * amplitude; + } + } + return noise; + } + + protected double[] get3dNoise(double[] noise, double x, double y, double z, int sizeX, int sizeY, int sizeZ, double scaleX, double scaleY, double scaleZ, double amplitude) + { + int n = -1; + double x1 = 0; + double x2 = 0; + double x3 = 0; + double x4 = 0; + int index = 0; + for(int i = 0; i < sizeX; i++) + { + double dx = x + offsetX + i * scaleX; + int floorX = floor(dx); + int ix = floorX & 255; + dx -= floorX; + double fx = fade(dx); + for(int j = 0; j < sizeZ; j++) + { + double dz = z + offsetZ + j * scaleZ; + int floorZ = floor(dz); + int iz = floorZ & 255; + dz -= floorZ; + double fz = fade(dz); + for(int k = 0; k < sizeY; k++) + { + double dy = y + offsetY + k * scaleY; + int floorY = floor(dy); + int iy = floorY & 255; + dy -= floorY; + double fy = fade(dy); + if(k == 0 || iy != n) + { + n = iy; + // Hash coordinates of the cube corners + int a = perm[ix] + iy; + int aa = perm[a] + iz; + int ab = perm[a + 1] + iz; + int b = perm[ix + 1] + iy; + int ba = perm[b] + iz; + int bb = perm[b + 1] + iz; + x1 = lerp(fx, grad(perm[aa], dx, dy, dz), grad(perm[ba], dx - 1, dy, dz)); + x2 = lerp(fx, grad(perm[ab], dx, dy - 1, dz), grad(perm[bb], dx - 1, dy - 1, dz)); + x3 = lerp(fx, grad(perm[aa + 1], dx, dy, dz - 1), grad(perm[ba + 1], dx - 1, dy, dz - 1)); + x4 = lerp(fx, grad(perm[ab + 1], dx, dy - 1, dz - 1), grad(perm[bb + 1], dx - 1, dy - 1, dz - 1)); + } + double y1 = lerp(fy, x1, x2); + double y2 = lerp(fy, x3, x4); + + noise[index++] += lerp(fz, y1, y2) * amplitude; + } + } + } + return noise; + } +} \ No newline at end of file diff --git a/src/main/java/ninja/bytecode/iris/util/Placer.java b/src/main/java/ninja/bytecode/iris/util/Placer.java deleted file mode 100644 index d0450fb3e..000000000 --- a/src/main/java/ninja/bytecode/iris/util/Placer.java +++ /dev/null @@ -1,24 +0,0 @@ -package ninja.bytecode.iris.util; - -import org.bukkit.World; - -public abstract class Placer implements IPlacer -{ - protected final World world; - - public Placer(World world) - { - this.world = world; - } - - @Override - public World getWorld() - { - return world; - } - - public void flush() - { - - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/PolygonGenerator.java b/src/main/java/ninja/bytecode/iris/util/PolygonGenerator.java deleted file mode 100644 index 3f8795e76..000000000 --- a/src/main/java/ninja/bytecode/iris/util/PolygonGenerator.java +++ /dev/null @@ -1,219 +0,0 @@ -package ninja.bytecode.iris.util; - -import java.util.function.Function; - -import mortar.lang.collection.GList; -import mortar.lang.collection.GMap; -import ninja.bytecode.shuriken.math.CNG; -import ninja.bytecode.shuriken.math.M; -import ninja.bytecode.shuriken.math.RNG; - -public class PolygonGenerator -{ - private double[] rarity; - private CNG[] gen; - private int bits; - private int possibilities; - private boolean useRarity; - - public PolygonGenerator(RNG rng, int possibilities, double scale, int octaves, Function factory) - { - useRarity = false; - bits = 1; - this.possibilities = possibilities; - - while(Math.pow(2, bits) <= possibilities) - { - bits++; - } - - bits++; - bits = bits > 32 ? 32 : bits; - rarity = new double[possibilities]; - gen = new CNG[bits]; - - for(int i = 0; i < bits; i++) - { - gen[i] = new CNG(rng.nextParallelRNG(2118 + (i * 3305)), 1D, 1).scale(scale / possibilities); - gen[i] = factory.apply(gen[i]); - } - } - - public PolygonGenerator useRarity() - { - useRarity = true; - return this; - } - - public void setRarity(int index, double r) - { - rarity[index] = 1D - Math.pow(0.5, r); - } - - public boolean hasBorder(int checks, double distance, double... dims) - { - int current = getIndex(dims); - double ajump = 360D / (double) checks; - - if(dims.length == 2) - { - for(int i = 0; i < checks; i++) - { - double dx = M.sin((float) Math.toRadians(ajump * i)); - double dz = M.cos((float) Math.toRadians(ajump * i)); - if(current != getIndex((dx * distance) + dims[0], (dz * distance) + dims[1])) - { - return true; - } - } - } - - if(dims.length == 3) - { - for(int i = 0; i < checks; i++) - { - double dx = M.sin((float) Math.toRadians(ajump * i)); - double dz = M.cos((float) Math.toRadians(ajump * i)); - double dy = Math.tan(Math.toRadians(ajump * i)); - if(current != getIndex((dx * distance) + dims[0], (dz * distance) + dims[1], (dy * distance) + dims[2])) - { - return true; - } - } - } - - return false; - } - - public boolean hasBorder3D(int checks, double distance, double... dims) - { - int current = getIndex(dims); - double ajump = 360D / (double) checks; - int hit = -1; - - if(dims.length == 3) - { - for(int i = 0; i < checks; i++) - { - double dx = M.sin((float) Math.toRadians(ajump * i)); - double dz = M.cos((float) Math.toRadians(ajump * i)); - double dy = Math.tan(Math.toRadians(ajump * i)); - int d = getIndex((dx * distance) + dims[0], (dz * distance) + dims[1], (dy * distance) + dims[2]); - if(current != d) - { - if(hit >= 0 && hit != current && hit != d) - { - return true; - } - - if(hit < 0) - { - hit = d; - } - } - } - } - - return false; - } - - /** - * Returns 0.0 to 1.0 where 0.0 is directly on the border of another region and - * 1.0 is perfectly in the center of a region - * - * @param x - * the x - * @param z - * the z - * @return the closest neighbor threshold. - */ - public double getClosestNeighbor(double... dim) - { - double closest = 0.5; - - for(int i = 0; i < gen.length; i++) - { - double distance = Math.abs(gen[i].noise(dim) - 0.5); - - if(distance < closest) - { - closest = distance; - } - } - - return (closest * 2); - } - - public int getIndex(double... dim) - { - int data = 0; - int adjusted = 0; - double[] noise = new double[gen.length]; - - for(int i = 0; i < gen.length; i++) - { - data |= (noise[i] = gen[i].noise(dim)) > 0.5 ? i == 0 ? 1 : 1 << i : 0; - } - - if(!useRarity) - { - return data % possibilities; - } - - double r = rarity[data % possibilities]; - - for(int i = 0; i < gen.length; i++) - { - adjusted |= noise[i] > r ? i == 0 ? 1 : 1 << i : 0; - } - - return adjusted % possibilities; - } - - public static class EnumPolygonGenerator extends PolygonGenerator - { - private T[] choices; - - public EnumPolygonGenerator(RNG rng, double scale, int octaves, T[] choices, Function factory) - { - super(rng, choices.length, scale / (double) choices.length, octaves, factory); - this.choices = choices; - } - - public EnumPolygonGenerator useRarity() - { - super.useRarity(); - return this; - } - - @SuppressWarnings("unchecked") - public EnumPolygonGenerator(RNG rng, double scale, int octaves, GList c, GMap choiceRarities, Function factory) - { - super(rng, choiceRarities.size(), scale / (double) choiceRarities.size(), octaves, factory); - this.choices = (T[]) c.toArray(); - int m = 0; - - for(T i : c) - { - setRarity(m++, choiceRarities.get(i)); - } - } - - public void setRarity(T t, double rarity) - { - for(int i = 0; i < choices.length; i++) - { - if(choices[i].equals(t)) - { - setRarity(i, rarity); - return; - } - } - } - - public T getChoice(double... dim) - { - return choices[getIndex(dim)]; - } - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/PrepackagedChunk.java b/src/main/java/ninja/bytecode/iris/util/PrepackagedChunk.java deleted file mode 100644 index da6344608..000000000 --- a/src/main/java/ninja/bytecode/iris/util/PrepackagedChunk.java +++ /dev/null @@ -1,37 +0,0 @@ -package ninja.bytecode.iris.util; - -import org.bukkit.block.Biome; - -import ninja.bytecode.iris.generator.atomics.AtomicChunkData; - -public class PrepackagedChunk -{ - private AtomicChunkData data; - private Biome[] biome; - - public PrepackagedChunk(AtomicChunkData data, Biome[] biome) - { - this.data = data; - this.biome = biome; - } - - public AtomicChunkData getData() - { - return data; - } - - public void setData(AtomicChunkData data) - { - this.data = data; - } - - public Biome[] getBiome() - { - return biome; - } - - public void setBiome(Biome[] biome) - { - this.biome = biome; - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/RNG.java b/src/main/java/ninja/bytecode/iris/util/RNG.java new file mode 100644 index 000000000..f14330f1f --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/util/RNG.java @@ -0,0 +1,176 @@ +package ninja.bytecode.iris.util; + +import java.nio.charset.StandardCharsets; +import java.util.Random; +import java.util.UUID; + +public class RNG extends Random +{ + 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() + { + super(); + sx = 0; + } + + public RNG(long seed) + { + super(seed); + this.sx = seed; + } + + /** + * Creates a seed (long) from the hash of the seed string + * + * @param seed + * the seed (string) + */ + public RNG(String seed) + { + this(UUID.nameUUIDFromBytes(seed.getBytes(StandardCharsets.UTF_8)).getLeastSignificantBits() + UUID.nameUUIDFromBytes(seed.getBytes(StandardCharsets.UTF_8)).getMostSignificantBits() + (seed.length() * 32564)); + } + + public RNG nextParallelRNG(int signature) + { + return new RNG(sx + signature); + } + + @Deprecated + public RNG nextRNG() + { + return new RNG(nextLong()); + } + + public String s(int length) + { + StringBuilder sb = new StringBuilder(); + + for(int i = 0; i < length; i++) + { + sb.append(c()); + } + + return sb.toString(); + } + + public char c() + { + return CHARGEN[i(CHARGEN.length - 1)]; + } + + /** + * Pick a random enum + * + * @param t + * the enum class + * @return the enum + */ + public T e(Class t) + { + T[] c = t.getEnumConstants(); + return c[i(c.length)]; + } + + public boolean b() + { + return nextBoolean(); + } + + public boolean b(double percent) + { + return d() > percent; + } + + public short si(int lowerBound, int upperBound) + { + return (short) (lowerBound + (nextFloat() * ((upperBound - lowerBound) + 1))); + } + + public short si(int upperBound) + { + return si(0, upperBound); + } + + public short si() + { + return si(1); + } + + public float f(float lowerBound, float upperBound) + { + return lowerBound + (nextFloat() * ((upperBound - lowerBound))); + } + + public float f(float upperBound) + { + return f(0, upperBound); + } + + public float f() + { + return f(1); + } + + public double d(double lowerBound, double upperBound) + { + return lowerBound + (nextDouble() * ((upperBound - lowerBound))); + } + + public double d(double upperBound) + { + return d(0, upperBound); + } + + public double d() + { + return d(1); + } + + public int i(int lowerBound, int upperBound) + { + return (int) Math.round(d(lowerBound, upperBound)); + } + + public int i(int upperBound) + { + return i(0, upperBound); + } + + public long l(long lowerBound, long upperBound) + { + return Math.round(d(lowerBound, upperBound)); + } + + public long l(long upperBound) + { + return l(0, upperBound); + } + + public int imax() + { + return i(Integer.MIN_VALUE, Integer.MAX_VALUE); + } + + public long lmax() + { + return l(Long.MIN_VALUE, Long.MAX_VALUE); + } + + public float fmax() + { + return f(Float.MIN_VALUE, Float.MAX_VALUE); + } + + public double dmax() + { + return d(Double.MIN_VALUE, Double.MAX_VALUE); + } + + public short simax() + { + return si(Short.MIN_VALUE, Short.MAX_VALUE); + } +} diff --git a/src/main/java/ninja/bytecode/iris/util/RealBiome.java b/src/main/java/ninja/bytecode/iris/util/RealBiome.java deleted file mode 100644 index 18aa2c97a..000000000 --- a/src/main/java/ninja/bytecode/iris/util/RealBiome.java +++ /dev/null @@ -1,44 +0,0 @@ -package ninja.bytecode.iris.util; - -import org.bukkit.Material; -import org.bukkit.block.Biome; - -import net.minecraft.server.v1_12_R1.BiomeBase; -import net.minecraft.server.v1_12_R1.Block; -import net.minecraft.server.v1_12_R1.IBlockData; -import ninja.bytecode.shuriken.format.Form; - -public class RealBiome -{ - private Biome b; - private double temperature; - private double height; - private double humidity; - private MB surface; - private MB dirt; - - public RealBiome(Biome b) - { - this.b = b; - BiomeBase base = BiomeBase.a(b.ordinal()); - surface = toMB(base.q); - dirt = toMB(base.r); - temperature = base.getTemperature(); - humidity = base.getHumidity(); - height = base.j(); - } - - public String toString() - { - return Form.capitalizeWords(b.toString().toLowerCase().replaceAll("\\Q_\\E", " ")) + " Temp: " + temperature + " Humidity: " + humidity + " Height: " + height + " Surf: " + Form.capitalizeWords(surface.material.toString().replaceAll("_", " ").toLowerCase())+ " Dirt: " + Form.capitalizeWords(dirt.material.toString().replaceAll("_", " ").toLowerCase()); - } - - @SuppressWarnings("deprecation") - public MB toMB(IBlockData d) - { - int i = Block.getCombinedId(d); - int j = i & 4095; - int k = i >> 12 & 15; - return new MB(Material.getMaterial(j), k); - } -} \ No newline at end of file diff --git a/src/main/java/ninja/bytecode/iris/util/ReflectionUtils.java b/src/main/java/ninja/bytecode/iris/util/ReflectionUtils.java deleted file mode 100644 index 8df919aea..000000000 --- a/src/main/java/ninja/bytecode/iris/util/ReflectionUtils.java +++ /dev/null @@ -1,822 +0,0 @@ -package ninja.bytecode.iris.util; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; - -import org.bukkit.Bukkit; - -/** - * ReflectionUtils - *

- * This class provides useful methods which makes dealing with reflection much - * easier, especially when working with Bukkit - *

- * You are welcome to use it, modify it and redistribute it under the following - * conditions: - *

    - *
  • Don't claim this class as your own - *
  • Don't remove this disclaimer - *
- *

- * It would be nice if you provide credit to me if you use this class in a - * published project - * - * @author DarkBlade12 - * @version 1.1 - */ -public final class ReflectionUtils -{ - // Prevent accidental construction - private ReflectionUtils() - { - - } - - /** - * Returns the constructor of a given class with the given parameter types - * - * @param clazz - * Target class - * @param parameterTypes - * Parameter types of the desired constructor - * @return The constructor of the target class with the specified parameter - * types - * @throws NoSuchMethodException - * If the desired constructor with the specified parameter types - * cannot be found - * @see DataType - * @see DataType#getPrimitive(Class[]) - * @see DataType#compare(Class[], Class[]) - */ - public static Constructor getConstructor(Class clazz, Class... parameterTypes) throws NoSuchMethodException - { - Class[] primitiveTypes = DataType.getPrimitive(parameterTypes); - for(Constructor constructor : clazz.getConstructors()) - { - if(!DataType.compare(DataType.getPrimitive(constructor.getParameterTypes()), primitiveTypes)) - { - continue; - } - return constructor; - } - throw new NoSuchMethodException("There is no such constructor in this class with the specified parameter types"); - } - - /** - * Returns the constructor of a desired class with the given parameter types - * - * @param className - * Name of the desired target class - * @param packageType - * Package where the desired target class is located - * @param parameterTypes - * Parameter types of the desired constructor - * @return The constructor of the desired target class with the specified - * parameter types - * @throws NoSuchMethodException - * If the desired constructor with the specified parameter types - * cannot be found - * @throws ClassNotFoundException - * ClassNotFoundException If the desired target class with the - * specified name and package cannot be found - * @see #getConstructor(Class, Class...) - */ - public static Constructor getConstructor(String className, PackageType packageType, Class... parameterTypes) throws NoSuchMethodException, ClassNotFoundException - { - return getConstructor(packageType.getClass(className), parameterTypes); - } - - /** - * Returns an instance of a class with the given arguments - * - * @param clazz - * Target class - * @param arguments - * Arguments which are used to construct an object of the target - * class - * @return The instance of the target class with the specified arguments - * @throws InstantiationException - * If you cannot create an instance of the target class due to - * certain circumstances - * @throws IllegalAccessException - * If the desired constructor cannot be accessed due to certain - * circumstances - * @throws IllegalArgumentException - * If the types of the arguments do not match the parameter - * types of the constructor (this should not occur since it - * searches for a constructor with the types of the arguments) - * @throws InvocationTargetException - * If the desired constructor cannot be invoked - * @throws NoSuchMethodException - * If the desired constructor with the specified arguments - * cannot be found - */ - public static Object instantiateObject(Class clazz, Object... arguments) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException - { - return getConstructor(clazz, DataType.getPrimitive(arguments)).newInstance(arguments); - } - - /** - * Returns an instance of a desired class with the given arguments - * - * @param className - * Name of the desired target class - * @param packageType - * Package where the desired target class is located - * @param arguments - * Arguments which are used to construct an object of the desired - * target class - * @return The instance of the desired target class with the specified - * arguments - * @throws InstantiationException - * If you cannot create an instance of the desired target class - * due to certain circumstances - * @throws IllegalAccessException - * If the desired constructor cannot be accessed due to certain - * circumstances - * @throws IllegalArgumentException - * If the types of the arguments do not match the parameter - * types of the constructor (this should not occur since it - * searches for a constructor with the types of the arguments) - * @throws InvocationTargetException - * If the desired constructor cannot be invoked - * @throws NoSuchMethodException - * If the desired constructor with the specified arguments - * cannot be found - * @throws ClassNotFoundException - * If the desired target class with the specified name and - * package cannot be found - * @see #instantiateObject(Class, Object...) - */ - public static Object instantiateObject(String className, PackageType packageType, Object... arguments) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException - { - return instantiateObject(packageType.getClass(className), arguments); - } - - /** - * Returns a method of a class with the given parameter types - * - * @param clazz - * Target class - * @param methodName - * Name of the desired method - * @param parameterTypes - * Parameter types of the desired method - * @return The method of the target class with the specified name and - * parameter types - * @throws NoSuchMethodException - * If the desired method of the target class with the specified - * name and parameter types cannot be found - * @see DataType#getPrimitive(Class[]) - * @see DataType#compare(Class[], Class[]) - */ - public static Method getMethod(Class clazz, String methodName, Class... parameterTypes) throws NoSuchMethodException - { - Class[] primitiveTypes = DataType.getPrimitive(parameterTypes); - for(Method method : clazz.getMethods()) - { - if(!method.getName().equals(methodName) || !DataType.compare(DataType.getPrimitive(method.getParameterTypes()), primitiveTypes)) - { - continue; - } - return method; - } - throw new NoSuchMethodException("There is no such method in this class with the specified name and parameter types"); - } - - /** - * Returns a method of a desired class with the given parameter types - * - * @param className - * Name of the desired target class - * @param packageType - * Package where the desired target class is located - * @param methodName - * Name of the desired method - * @param parameterTypes - * Parameter types of the desired method - * @return The method of the desired target class with the specified name - * and parameter types - * @throws NoSuchMethodException - * If the desired method of the desired target class with the - * specified name and parameter types cannot be found - * @throws ClassNotFoundException - * If the desired target class with the specified name and - * package cannot be found - * @see #getMethod(Class, String, Class...) - */ - public static Method getMethod(String className, PackageType packageType, String methodName, Class... parameterTypes) throws NoSuchMethodException, ClassNotFoundException - { - return getMethod(packageType.getClass(className), methodName, parameterTypes); - } - - /** - * Invokes a method on an object with the given arguments - * - * @param instance - * Target object - * @param methodName - * Name of the desired method - * @param arguments - * Arguments which are used to invoke the desired method - * @return The result of invoking the desired method on the target object - * @throws IllegalAccessException - * If the desired method cannot be accessed due to certain - * circumstances - * @throws IllegalArgumentException - * If the types of the arguments do not match the parameter - * types of the method (this should not occur since it searches - * for a method with the types of the arguments) - * @throws InvocationTargetException - * If the desired method cannot be invoked on the target object - * @throws NoSuchMethodException - * If the desired method of the class of the target object with - * the specified name and arguments cannot be found - * @see #getMethod(Class, String, Class...) - * @see DataType#getPrimitive(Object[]) - */ - public static Object invokeMethod(Object instance, String methodName, Object... arguments) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException - { - return getMethod(instance.getClass(), methodName, DataType.getPrimitive(arguments)).invoke(instance, arguments); - } - - /** - * Invokes a method of the target class on an object with the given - * arguments - * - * @param instance - * Target object - * @param clazz - * Target class - * @param methodName - * Name of the desired method - * @param arguments - * Arguments which are used to invoke the desired method - * @return The result of invoking the desired method on the target object - * @throws IllegalAccessException - * If the desired method cannot be accessed due to certain - * circumstances - * @throws IllegalArgumentException - * If the types of the arguments do not match the parameter - * types of the method (this should not occur since it searches - * for a method with the types of the arguments) - * @throws InvocationTargetException - * If the desired method cannot be invoked on the target object - * @throws NoSuchMethodException - * If the desired method of the target class with the specified - * name and arguments cannot be found - * @see #getMethod(Class, String, Class...) - * @see DataType#getPrimitive(Object[]) - */ - public static Object invokeMethod(Object instance, Class clazz, String methodName, Object... arguments) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException - { - return getMethod(clazz, methodName, DataType.getPrimitive(arguments)).invoke(instance, arguments); - } - - /** - * Invokes a method of a desired class on an object with the given arguments - * - * @param instance - * Target object - * @param className - * Name of the desired target class - * @param packageType - * Package where the desired target class is located - * @param methodName - * Name of the desired method - * @param arguments - * Arguments which are used to invoke the desired method - * @return The result of invoking the desired method on the target object - * @throws IllegalAccessException - * If the desired method cannot be accessed due to certain - * circumstances - * @throws IllegalArgumentException - * If the types of the arguments do not match the parameter - * types of the method (this should not occur since it searches - * for a method with the types of the arguments) - * @throws InvocationTargetException - * If the desired method cannot be invoked on the target object - * @throws NoSuchMethodException - * If the desired method of the desired target class with the - * specified name and arguments cannot be found - * @throws ClassNotFoundException - * If the desired target class with the specified name and - * package cannot be found - * @see #invokeMethod(Object, Class, String, Object...) - */ - public static Object invokeMethod(Object instance, String className, PackageType packageType, String methodName, Object... arguments) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException - { - return invokeMethod(instance, packageType.getClass(className), methodName, arguments); - } - - /** - * Returns a field of the target class with the given name - * - * @param clazz - * Target class - * @param declared - * Whether the desired field is declared or not - * @param fieldName - * Name of the desired field - * @return The field of the target class with the specified name - * @throws NoSuchFieldException - * If the desired field of the given class cannot be found - * @throws SecurityException - * If the desired field cannot be made accessible - */ - public static Field getField(Class clazz, boolean declared, String fieldName) throws NoSuchFieldException, SecurityException - { - Field field = declared ? clazz.getDeclaredField(fieldName) : clazz.getField(fieldName); - field.setAccessible(true); - return field; - } - - /** - * Returns a field of a desired class with the given name - * - * @param className - * Name of the desired target class - * @param packageType - * Package where the desired target class is located - * @param declared - * Whether the desired field is declared or not - * @param fieldName - * Name of the desired field - * @return The field of the desired target class with the specified name - * @throws NoSuchFieldException - * If the desired field of the desired class cannot be found - * @throws SecurityException - * If the desired field cannot be made accessible - * @throws ClassNotFoundException - * If the desired target class with the specified name and - * package cannot be found - * @see #getField(Class, boolean, String) - */ - public static Field getField(String className, PackageType packageType, boolean declared, String fieldName) throws NoSuchFieldException, SecurityException, ClassNotFoundException - { - return getField(packageType.getClass(className), declared, fieldName); - } - - /** - * Returns the value of a field of the given class of an object - * - * @param instance - * Target object - * @param clazz - * Target class - * @param declared - * Whether the desired field is declared or not - * @param fieldName - * Name of the desired field - * @return The value of field of the target object - * @throws IllegalArgumentException - * If the target object does not feature the desired field - * @throws IllegalAccessException - * If the desired field cannot be accessed - * @throws NoSuchFieldException - * If the desired field of the target class cannot be found - * @throws SecurityException - * If the desired field cannot be made accessible - * @see #getField(Class, boolean, String) - */ - public static Object getValue(Object instance, Class clazz, boolean declared, String fieldName) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException - { - return getField(clazz, declared, fieldName).get(instance); - } - - /** - * Returns the value of a field of a desired class of an object - * - * @param instance - * Target object - * @param className - * Name of the desired target class - * @param packageType - * Package where the desired target class is located - * @param declared - * Whether the desired field is declared or not - * @param fieldName - * Name of the desired field - * @return The value of field of the target object - * @throws IllegalArgumentException - * If the target object does not feature the desired field - * @throws IllegalAccessException - * If the desired field cannot be accessed - * @throws NoSuchFieldException - * If the desired field of the desired class cannot be found - * @throws SecurityException - * If the desired field cannot be made accessible - * @throws ClassNotFoundException - * If the desired target class with the specified name and - * package cannot be found - * @see #getValue(Object, Class, boolean, String) - */ - public static Object getValue(Object instance, String className, PackageType packageType, boolean declared, String fieldName) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException, ClassNotFoundException - { - return getValue(instance, packageType.getClass(className), declared, fieldName); - } - - /** - * Returns the value of a field with the given name of an object - * - * @param instance - * Target object - * @param declared - * Whether the desired field is declared or not - * @param fieldName - * Name of the desired field - * @return The value of field of the target object - * @throws IllegalArgumentException - * If the target object does not feature the desired field - * (should not occur since it searches for a field with the - * given name in the class of the object) - * @throws IllegalAccessException - * If the desired field cannot be accessed - * @throws NoSuchFieldException - * If the desired field of the target object cannot be found - * @throws SecurityException - * If the desired field cannot be made accessible - * @see #getValue(Object, Class, boolean, String) - */ - public static Object getValue(Object instance, boolean declared, String fieldName) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException - { - return getValue(instance, instance.getClass(), declared, fieldName); - } - - /** - * Sets the value of a field of the given class of an object - * - * @param instance - * Target object - * @param clazz - * Target class - * @param declared - * Whether the desired field is declared or not - * @param fieldName - * Name of the desired field - * @param value - * New value - * @throws IllegalArgumentException - * If the type of the value does not match the type of the - * desired field - * @throws IllegalAccessException - * If the desired field cannot be accessed - * @throws NoSuchFieldException - * If the desired field of the target class cannot be found - * @throws SecurityException - * If the desired field cannot be made accessible - * @see #getField(Class, boolean, String) - */ - public static void setValue(Object instance, Class clazz, boolean declared, String fieldName, Object value) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException - { - getField(clazz, declared, fieldName).set(instance, value); - } - - /** - * Sets the value of a field of a desired class of an object - * - * @param instance - * Target object - * @param className - * Name of the desired target class - * @param packageType - * Package where the desired target class is located - * @param declared - * Whether the desired field is declared or not - * @param fieldName - * Name of the desired field - * @param value - * New value - * @throws IllegalArgumentException - * If the type of the value does not match the type of the - * desired field - * @throws IllegalAccessException - * If the desired field cannot be accessed - * @throws NoSuchFieldException - * If the desired field of the desired class cannot be found - * @throws SecurityException - * If the desired field cannot be made accessible - * @throws ClassNotFoundException - * If the desired target class with the specified name and - * package cannot be found - * @see #setValue(Object, Class, boolean, String, Object) - */ - public static void setValue(Object instance, String className, PackageType packageType, boolean declared, String fieldName, Object value) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException, ClassNotFoundException - { - setValue(instance, packageType.getClass(className), declared, fieldName, value); - } - - /** - * Sets the value of a field with the given name of an object - * - * @param instance - * Target object - * @param declared - * Whether the desired field is declared or not - * @param fieldName - * Name of the desired field - * @param value - * New value - * @throws IllegalArgumentException - * If the type of the value does not match the type of the - * desired field - * @throws IllegalAccessException - * If the desired field cannot be accessed - * @throws NoSuchFieldException - * If the desired field of the target object cannot be found - * @throws SecurityException - * If the desired field cannot be made accessible - * @see #setValue(Object, Class, boolean, String, Object) - */ - public static void setValue(Object instance, boolean declared, String fieldName, Object value) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException - { - setValue(instance, instance.getClass(), declared, fieldName, value); - } - - /** - * Represents an enumeration of dynamic packages of NMS and CraftBukkit - *

- * This class is part of the ReflectionUtils and follows the same - * usage conditions - * - * @author DarkBlade12 - * @since 1.0 - */ - public enum PackageType - { - MINECRAFT_SERVER("net.minecraft.server." + getServerVersion()), CRAFTBUKKIT("org.bukkit.craftbukkit." + getServerVersion()), CRAFTBUKKIT_BLOCK(CRAFTBUKKIT, "block"), CRAFTBUKKIT_CHUNKIO(CRAFTBUKKIT, "chunkio"), CRAFTBUKKIT_COMMAND(CRAFTBUKKIT, "command"), CRAFTBUKKIT_CONVERSATIONS(CRAFTBUKKIT, "conversations"), CRAFTBUKKIT_ENCHANTMENS(CRAFTBUKKIT, "enchantments"), CRAFTBUKKIT_ENTITY(CRAFTBUKKIT, "entity"), CRAFTBUKKIT_EVENT(CRAFTBUKKIT, "event"), CRAFTBUKKIT_GENERATOR(CRAFTBUKKIT, "generator"), CRAFTBUKKIT_HELP(CRAFTBUKKIT, "help"), CRAFTBUKKIT_INVENTORY(CRAFTBUKKIT, "inventory"), CRAFTBUKKIT_MAP(CRAFTBUKKIT, "map"), CRAFTBUKKIT_METADATA(CRAFTBUKKIT, "metadata"), CRAFTBUKKIT_POTION(CRAFTBUKKIT, "potion"), CRAFTBUKKIT_PROJECTILES(CRAFTBUKKIT, "projectiles"), CRAFTBUKKIT_SCHEDULER(CRAFTBUKKIT, "scheduler"), CRAFTBUKKIT_SCOREBOARD(CRAFTBUKKIT, "scoreboard"), CRAFTBUKKIT_UPDATER(CRAFTBUKKIT, "updater"), CRAFTBUKKIT_UTIL(CRAFTBUKKIT, "util"); - - private final String path; - - /** - * Construct a new package type - * - * @param path - * Path of the package - */ - private PackageType(String path) - { - this.path = path; - } - - /** - * Construct a new package type - * - * @param parent - * Parent package of the package - * @param path - * Path of the package - */ - private PackageType(PackageType parent, String path) - { - this(parent + "." + path); - } - - /** - * Returns the path of this package type - * - * @return The path - */ - public String getPath() - { - return path; - } - - /** - * Returns the class with the given name - * - * @param className - * Name of the desired class - * @return The class with the specified name - * @throws ClassNotFoundException - * If the desired class with the specified name and package - * cannot be found - */ - public Class getClass(String className) throws ClassNotFoundException - { - return Class.forName(this + "." + className); - } - - // Override for convenience - @Override - public String toString() - { - return path; - } - - /** - * Returns the version of your server - * - * @return The server version - */ - public static String getServerVersion() - { - return Bukkit.getServer().getClass().getPackage().getName().substring(23); - } - } - - /** - * Represents an enumeration of Java data types with corresponding classes - *

- * This class is part of the ReflectionUtils and follows the same - * usage conditions - * - * @author DarkBlade12 - * @since 1.0 - */ - public enum DataType - { - BYTE(byte.class, Byte.class), SHORT(short.class, Short.class), INTEGER(int.class, Integer.class), LONG(long.class, Long.class), CHARACTER(char.class, Character.class), FLOAT(float.class, Float.class), DOUBLE(double.class, Double.class), BOOLEAN(boolean.class, Boolean.class); - - private static final Map, DataType> CLASS_MAP = new HashMap, DataType>(); - private final Class primitive; - private final Class reference; - - // Initialize map for quick class lookup - static - { - for(DataType type : values()) - { - CLASS_MAP.put(type.primitive, type); - CLASS_MAP.put(type.reference, type); - } - } - - /** - * Construct a new data type - * - * @param primitive - * Primitive class of this data type - * @param reference - * Reference class of this data type - */ - private DataType(Class primitive, Class reference) - { - this.primitive = primitive; - this.reference = reference; - } - - /** - * Returns the primitive class of this data type - * - * @return The primitive class - */ - public Class getPrimitive() - { - return primitive; - } - - /** - * Returns the reference class of this data type - * - * @return The reference class - */ - public Class getReference() - { - return reference; - } - - /** - * Returns the data type with the given primitive/reference class - * - * @param clazz - * Primitive/Reference class of the data type - * @return The data type - */ - public static DataType fromClass(Class clazz) - { - return CLASS_MAP.get(clazz); - } - - /** - * Returns the primitive class of the data type with the given reference - * class - * - * @param clazz - * Reference class of the data type - * @return The primitive class - */ - public static Class getPrimitive(Class clazz) - { - DataType type = fromClass(clazz); - return type == null ? clazz : type.getPrimitive(); - } - - /** - * Returns the reference class of the data type with the given primitive - * class - * - * @param clazz - * Primitive class of the data type - * @return The reference class - */ - public static Class getReference(Class clazz) - { - DataType type = fromClass(clazz); - return type == null ? clazz : type.getReference(); - } - - /** - * Returns the primitive class array of the given class array - * - * @param classes - * Given class array - * @return The primitive class array - */ - public static Class[] getPrimitive(Class[] classes) - { - int length = classes == null ? 0 : classes.length; - Class[] types = new Class[length]; - for(int index = 0; index < length; index++) - { - types[index] = getPrimitive(classes[index]); - } - return types; - } - - /** - * Returns the reference class array of the given class array - * - * @param classes - * Given class array - * @return The reference class array - */ - public static Class[] getReference(Class[] classes) - { - int length = classes == null ? 0 : classes.length; - Class[] types = new Class[length]; - for(int index = 0; index < length; index++) - { - types[index] = getReference(classes[index]); - } - return types; - } - - /** - * Returns the primitive class array of the given object array - * - * @param objects - * Given object array - * @return The primitive class array - */ - public static Class[] getPrimitive(Object[] objects) - { - int length = objects == null ? 0 : objects.length; - Class[] types = new Class[length]; - for(int index = 0; index < length; index++) - { - types[index] = getPrimitive(objects[index].getClass()); - } - return types; - } - - /** - * Returns the reference class array of the given object array - * - * @param objects - * Given object array - * @return The reference class array - */ - public static Class[] getReference(Object[] objects) - { - int length = objects == null ? 0 : objects.length; - Class[] types = new Class[length]; - for(int index = 0; index < length; index++) - { - types[index] = getReference(objects[index].getClass()); - } - return types; - } - - /** - * Compares two class arrays on equivalence - * - * @param primary - * Primary class array - * @param secondary - * Class array which is compared to the primary array - * @return Whether these arrays are equal or not - */ - public static boolean compare(Class[] primary, Class[] secondary) - { - if(primary == null || secondary == null || primary.length != secondary.length) - { - return false; - } - for(int index = 0; index < primary.length; index++) - { - Class primaryClass = primary[index]; - Class secondaryClass = secondary[index]; - if(primaryClass.equals(secondaryClass) || primaryClass.isAssignableFrom(secondaryClass)) - { - continue; - } - return false; - } - return true; - } - } -} \ No newline at end of file diff --git a/src/main/java/ninja/bytecode/iris/util/SBlockVector.java b/src/main/java/ninja/bytecode/iris/util/SBlockVector.java deleted file mode 100644 index f9cd1e181..000000000 --- a/src/main/java/ninja/bytecode/iris/util/SBlockVector.java +++ /dev/null @@ -1,169 +0,0 @@ -package ninja.bytecode.iris.util; - -import org.bukkit.configuration.serialization.SerializableAs; -import org.bukkit.util.BlockVector; -import org.bukkit.util.Vector; - -/** - * A vector with a hash function that floors the X, Y, Z components, a la - * BlockVector in WorldEdit. BlockVectors can be used in hash sets and hash - * maps. Be aware that BlockVectors are mutable, but it is important that - * BlockVectors are never changed once put into a hash set or hash map. - */ -@SerializableAs("BlockVector") -public class SBlockVector -{ - private short x; - private short y; - private short z; - - /** - * Construct the vector with all components as 0. - */ - public SBlockVector() - { - this.x = 0; - this.y = 0; - this.z = 0; - } - - /** - * Construct the vector with another vector. - * - * @param vec - * The other vector. - */ - public SBlockVector(Vector vec) - { - this.x = (short) vec.getX(); - this.y = (short) vec.getY(); - this.z = (short) vec.getZ(); - } - - /** - * Construct the vector with provided integer components. - * - * @param x - * X component - * @param y - * Y component - * @param z - * Z component - */ - public SBlockVector(int x, int y, int z) - { - this.x = (short) x; - this.y = (short) y; - this.z = (short) z; - } - - /** - * Construct the vector with provided double components. - * - * @param x - * X component - * @param y - * Y component - * @param z - * Z component - */ - public SBlockVector(double x, double y, double z) - { - this.x = (short) x; - this.y = (short) y; - this.z = (short) z; - } - - /** - * Construct the vector with provided float components. - * - * @param x - * X component - * @param y - * Y component - * @param z - * Z component - */ - public SBlockVector(float x, float y, float z) - { - this.x = (short) x; - this.y = (short) y; - this.z = (short) z; - } - - /** - * Get a new block vector. - * - * @return vector - */ - @Override - public SBlockVector clone() - { - return new SBlockVector(x, y, z); - } - - public double getX() - { - return x; - } - - public void setX(double x) - { - this.x = (short) x; - } - - public double getY() - { - return y; - } - - public void setY(double y) - { - this.y = (short) y; - } - - public double getZ() - { - return z; - } - - public void setZ(double z) - { - this.z = (short) z; - } - - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = prime * result + x; - result = prime * result + y; - result = prime * result + z; - return result; - } - - @Override - public boolean equals(Object obj) - { - if(this == obj) - return true; - if(obj == null) - return false; - if(getClass() != obj.getClass()) - return false; - SBlockVector other = (SBlockVector) obj; - if(x != other.x) - return false; - if(y != other.y) - return false; - if(z != other.z) - return false; - return true; - } - - public BlockVector toBlockVector() - { - return new BlockVector(x, y, z); - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/SChunkVector.java b/src/main/java/ninja/bytecode/iris/util/SChunkVector.java deleted file mode 100644 index 31e1c080a..000000000 --- a/src/main/java/ninja/bytecode/iris/util/SChunkVector.java +++ /dev/null @@ -1,76 +0,0 @@ -package ninja.bytecode.iris.util; - -public class SChunkVector -{ - private byte x; - private byte z; - - public SChunkVector(int x, int z) - { - this.x = (byte) (x); - this.z = (byte) (z); - } - - public SChunkVector(byte x, byte z) - { - this.x = x; - this.z = z; - } - - public SChunkVector(double x, double z) - { - this((int) Math.round(x), (int) Math.round(z)); - } - - public SChunkVector() - { - this((byte) 0, (byte) 0); - } - - public int getX() - { - return x; - } - - public void setX(int x) - { - this.x = (byte) x; - } - - public int getZ() - { - return z; - } - - public void setZ(int z) - { - this.z = (byte) z; - } - - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = prime * result + x; - result = prime * result + z; - return result; - } - - @Override - public boolean equals(Object obj) - { - if(this == obj) - return true; - if(obj == null) - return false; - if(getClass() != obj.getClass()) - return false; - SChunkVector other = (SChunkVector) obj; - if(x != other.x) - return false; - if(z != other.z) - return false; - return true; - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/SChunkVectorShort.java b/src/main/java/ninja/bytecode/iris/util/SChunkVectorShort.java deleted file mode 100644 index 57cae1305..000000000 --- a/src/main/java/ninja/bytecode/iris/util/SChunkVectorShort.java +++ /dev/null @@ -1,72 +0,0 @@ -package ninja.bytecode.iris.util; - -import java.util.Objects; - -public class SChunkVectorShort -{ - private short x; - private short z; - - public SChunkVectorShort(int x, int z) - { - this.x = (short) (x); - this.z = (short) (z); - } - - public SChunkVectorShort(short x, short z) - { - this.x = x; - this.z = z; - } - - public SChunkVectorShort(double x, double z) - { - this((int) Math.round(x), (int) Math.round(z)); - } - - public SChunkVectorShort() - { - this((short) 0, (short) 0); - } - - public int getX() - { - return x; - } - - public void setX(int x) - { - this.x = (short) x; - } - - public int getZ() - { - return z; - } - - public void setZ(int z) - { - this.z = (short) z; - } - - @Override - public int hashCode() - { - return Objects.hash(x, z); - } - - @Override - public boolean equals(Object obj) - { - if(this == obj) - { - return true; - } - if(!(obj instanceof SChunkVectorShort)) - { - return false; - } - SChunkVectorShort other = (SChunkVectorShort) obj; - return x == other.x && z == other.z; - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/SMCAVector.java b/src/main/java/ninja/bytecode/iris/util/SMCAVector.java deleted file mode 100644 index 1becfc7d1..000000000 --- a/src/main/java/ninja/bytecode/iris/util/SMCAVector.java +++ /dev/null @@ -1,61 +0,0 @@ -package ninja.bytecode.iris.util; - -import java.util.Objects; - -public class SMCAVector -{ - private int x; - private int z; - - public SMCAVector(int x, int z) - { - this.x = x; - this.z = z; - } - - public SMCAVector() - { - this(0, 0); - } - - public int getX() - { - return x; - } - - public void setX(int x) - { - this.x = x; - } - - public int getZ() - { - return z; - } - - public void setZ(int z) - { - this.z = z; - } - - @Override - public int hashCode() - { - return Objects.hash(x, z); - } - - @Override - public boolean equals(Object obj) - { - if(this == obj) - { - return true; - } - if(!(obj instanceof SMCAVector)) - { - return false; - } - SMCAVector other = (SMCAVector) obj; - return x == other.x && z == other.z; - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/SNG.java b/src/main/java/ninja/bytecode/iris/util/SNG.java new file mode 100644 index 000000000..a177cc48b --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/util/SNG.java @@ -0,0 +1,378 @@ +package ninja.bytecode.iris.util; + +import java.util.Random; + +/** + * A speed-improved simplex noise algorithm. + * + *

+ * Based on example code by Stefan Gustavson (stegu@itn.liu.se). Optimisations + * by Peter Eastman (peastman@drizzle.stanford.edu). Better rank ordering method + * by Stefan Gustavson in 2012. + * + *

+ * This could be sped up even further, but it's useful as is. + */ +public class SNG extends PerlinNoise +{ + + protected static final double SQRT_3 = 1.7320508075688772; // Math.sqrt(3) + protected static final double F2 = 0.5 * (SQRT_3 - 1); + protected static final double G2 = (3 - SQRT_3) / 6; + protected static final double G22 = G2 * 2.0 - 1; + protected static final double F3 = 1.0 / 3.0; + protected static final double G3 = 1.0 / 6.0; + protected static final double G32 = G3 * 2.0; + protected static final double G33 = G3 * 3.0 - 1.0; + private static Grad[] grad3 = {new Grad(1, 1, 0), new Grad(-1, 1, 0), new Grad(1, -1, 0), new Grad(-1, -1, 0), new Grad(1, 0, 1), new Grad(-1, 0, 1), new Grad(1, 0, -1), new Grad(-1, 0, -1), new Grad(0, 1, 1), new Grad(0, -1, 1), new Grad(0, 1, -1), new Grad(0, -1, -1)}; + protected final int[] permMod12 = new int[512]; + + /** + * Creates a simplex noise generator. + * + * @param rand + * the PRNG to use + */ + public SNG(Random rand) + { + super(rand); + for(int i = 0; i < 512; i++) + { + permMod12[i] = perm[i] % 12; + } + } + + public static int floor(double x) + { + return x > 0 ? (int) x : (int) x - 1; + } + + protected static double dot(Grad g, double x, double y) + { + return g.x * x + g.y * y; + } + + protected static double dot(Grad g, double x, double y, double z) + { + return g.x * x + g.y * y + g.z * z; + } + + @Override + protected double[] get2dNoise(double[] noise, double x, double z, int sizeX, int sizeY, double scaleX, double scaleY, double amplitude) + { + int index = 0; + for(int i = 0; i < sizeY; i++) + { + double zin = offsetY + (z + i) * scaleY; + for(int j = 0; j < sizeX; j++) + { + double xin = offsetX + (x + j) * scaleX; + noise[index++] += simplex2D(xin, zin) * amplitude; + } + } + return noise; + } + + @Override + protected double[] get3dNoise(double[] noise, double x, double y, double z, int sizeX, int sizeY, int sizeZ, double scaleX, double scaleY, double scaleZ, double amplitude) + { + int index = 0; + for(int i = 0; i < sizeZ; i++) + { + double zin = offsetZ + (z + i) * scaleZ; + for(int j = 0; j < sizeX; j++) + { + double xin = offsetX + (x + j) * scaleX; + for(int k = 0; k < sizeY; k++) + { + double yin = offsetY + (y + k) * scaleY; + noise[index++] += simplex3D(xin, yin, zin) * amplitude; + } + } + } + return noise; + } + + @Override + public double noise(double xin, double yin) + { + xin += offsetX; + yin += offsetY; + return simplex2D(xin, yin); + } + + @Override + public double noise(double xin, double yin, double zin) + { + xin += offsetX; + yin += offsetY; + zin += offsetZ; + return simplex3D(xin, yin, zin); + } + + private double simplex2D(double xin, double yin) + { + // Skew the input space to determine which simplex cell we're in + double s = (xin + yin) * F2; // Hairy factor for 2D + int i = floor(xin + s); + int j = floor(yin + s); + double t = (i + j) * G2; + double dx0 = i - t; // Unskew the cell origin back to (x,y) space + double dy0 = j - t; + double x0 = xin - dx0; // The x,y distances from the cell origin + double y0 = yin - dy0; + + // For the 2D case, the simplex shape is an equilateral triangle. + + // Determine which simplex we are in. + int i1; // Offsets for second (middle) corner of simplex in (i,j) coords + int j1; + if(x0 > y0) + { + i1 = 1; // lower triangle, XY order: (0,0)->(1,0)->(1,1) + j1 = 0; + } + else + { + i1 = 0; // upper triangle, YX order: (0,0)->(0,1)->(1,1) + j1 = 1; + } + + // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and + // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where + // c = (3-sqrt(3))/6 + + double x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords + double y1 = y0 - j1 + G2; + double x2 = x0 + G22; // Offsets for last corner in (x,y) unskewed coords + double y2 = y0 + G22; + + // Work out the hashed gradient indices of the three simplex corners + int ii = i & 255; + int jj = j & 255; + int gi0 = permMod12[ii + perm[jj]]; + int gi1 = permMod12[ii + i1 + perm[jj + j1]]; + int gi2 = permMod12[ii + 1 + perm[jj + 1]]; + + // Calculate the contribution from the three corners + double t0 = 0.5 - x0 * x0 - y0 * y0; + double n0; + if(t0 < 0) + { + n0 = 0.0; + } + else + { + t0 *= t0; + n0 = t0 * t0 * dot(grad3[gi0], x0, y0); // (x,y) of grad3 used for 2D gradient + } + + double t1 = 0.5 - x1 * x1 - y1 * y1; + double n1; + if(t1 < 0) + { + n1 = 0.0; + } + else + { + t1 *= t1; + n1 = t1 * t1 * dot(grad3[gi1], x1, y1); + } + + double t2 = 0.5 - x2 * x2 - y2 * y2; + double n2; + if(t2 < 0) + { + n2 = 0.0; + } + else + { + t2 *= t2; + n2 = t2 * t2 * dot(grad3[gi2], x2, y2); + } + + // Add contributions from each corner to get the final noise value. + // The result is scaled to return values in the interval [-1,1]. + return 70.0 * (n0 + n1 + n2); + } + + private double simplex3D(double xin, double yin, double zin) + { + // Skew the input space to determine which simplex cell we're in + double s = (xin + yin + zin) * F3; // Very nice and simple skew factor for 3D + int i = floor(xin + s); + int j = floor(yin + s); + int k = floor(zin + s); + double t = (i + j + k) * G3; + double dx0 = i - t; // Unskew the cell origin back to (x,y,z) space + double dy0 = j - t; + double dz0 = k - t; + + // For the 3D case, the simplex shape is a slightly irregular tetrahedron. + + int i1; // Offsets for second corner of simplex in (i,j,k) coords + int j1; + int k1; + int i2; // Offsets for third corner of simplex in (i,j,k) coords + int j2; + int k2; + + double x0 = xin - dx0; // The x,y,z distances from the cell origin + double y0 = yin - dy0; + double z0 = zin - dz0; + // Determine which simplex we are in + if(x0 >= y0) + { + if(y0 >= z0) + { + i1 = 1; // X Y Z order + j1 = 0; + k1 = 0; + i2 = 1; + j2 = 1; + k2 = 0; + } + else if(x0 >= z0) + { + i1 = 1; // X Z Y order + j1 = 0; + k1 = 0; + i2 = 1; + j2 = 0; + k2 = 1; + } + else + { + i1 = 0; // Z X Y order + j1 = 0; + k1 = 1; + i2 = 1; + j2 = 0; + k2 = 1; + } + } + else + { // x0 split(BlockFace f) - { - KList faces = new KList(); - - switch(f) - { - case DOWN: - faces.add(BlockFace.DOWN); - break; - case EAST: - faces.add(BlockFace.EAST); - break; - case EAST_NORTH_EAST: - faces.add(BlockFace.EAST); - faces.add(BlockFace.EAST); - faces.add(BlockFace.NORTH); - break; - case EAST_SOUTH_EAST: - faces.add(BlockFace.EAST); - faces.add(BlockFace.EAST); - faces.add(BlockFace.SOUTH); - break; - case NORTH: - faces.add(BlockFace.NORTH); - break; - case NORTH_EAST: - faces.add(BlockFace.NORTH); - faces.add(BlockFace.EAST); - break; - case NORTH_NORTH_EAST: - faces.add(BlockFace.NORTH); - faces.add(BlockFace.NORTH); - faces.add(BlockFace.EAST); - break; - case NORTH_NORTH_WEST: - faces.add(BlockFace.NORTH); - faces.add(BlockFace.NORTH); - faces.add(BlockFace.WEST); - break; - case NORTH_WEST: - faces.add(BlockFace.NORTH); - faces.add(BlockFace.WEST); - break; - case SELF: - faces.add(BlockFace.SELF); - break; - case SOUTH: - faces.add(BlockFace.SOUTH); - break; - case SOUTH_EAST: - faces.add(BlockFace.SOUTH); - faces.add(BlockFace.EAST); - break; - case SOUTH_SOUTH_EAST: - faces.add(BlockFace.SOUTH); - faces.add(BlockFace.SOUTH); - faces.add(BlockFace.EAST); - break; - case SOUTH_SOUTH_WEST: - faces.add(BlockFace.SOUTH); - faces.add(BlockFace.SOUTH); - faces.add(BlockFace.WEST); - break; - case SOUTH_WEST: - faces.add(BlockFace.SOUTH); - faces.add(BlockFace.WEST); - break; - case UP: - faces.add(BlockFace.UP); - break; - case WEST: - faces.add(BlockFace.WEST); - break; - case WEST_NORTH_WEST: - faces.add(BlockFace.WEST); - faces.add(BlockFace.WEST); - faces.add(BlockFace.NORTH); - break; - case WEST_SOUTH_WEST: - faces.add(BlockFace.WEST); - faces.add(BlockFace.WEST); - faces.add(BlockFace.SOUTH); - break; - default: - break; - } - - return faces; - } - - /** - * Get a normalized vector going from a location to another - * - * @param from - * from here - * @param to - * to here - * @return the normalized vector direction - */ - public static Vector direction(Location from, Location to) - { - return to.clone().subtract(from.clone()).toVector().normalize(); - } - - public static Vector directionNoNormal(Location from, Location to) - { - return to.clone().subtract(from.clone()).toVector(); - } - - /** - * Get the vector direction from the yaw and pitch - * - * @param yaw - * the yaw - * @param pitch - * the pitch - * @return the vector - */ - public static Vector toVector(float yaw, float pitch) - { - return new Vector(Math.cos(pitch) * Math.cos(yaw), Math.sin(pitch), Math.cos(pitch) * Math.sin(-yaw)); - } - - /** - * Add an impulse (force) to an entity - * - * @param e - * the entity - * @param v - * the vector - */ - public static void impulse(Entity e, Vector v) - { - impulse(e, v, 1.0); - } - - /** - * Add an impulse (force) on an entity - * - * @param e - * the entity - * @param v - * the vector - * @param effectiveness - * the effectiveness - */ - public static void impulse(Entity e, Vector v, double effectiveness) - { - Vector vx = e.getVelocity(); - vx.add(v.clone().multiply(effectiveness)); - e.setVelocity(vx); - } - - /** - * Reverse a direction - * - * @param v - * the direction - * @return the reversed direction - */ - public static Vector reverse(Vector v) - { - if(v.getX() != 0) - { - v.setX(-v.getX()); - } - - if(v.getY() != 0) - { - v.setY(-v.getY()); - } - - if(v.getZ() != 0) - { - v.setZ(-v.getZ()); - } - - return v; - } - - /** - * Get a speed value from a vector (velocity) - * - * @param v - * the vector - * @return the speed - */ - public static double getSpeed(Vector v) - { - Vector vi = new Vector(0, 0, 0); - Vector vt = new Vector(0, 0, 0).add(v); - - return vi.distance(vt); - } - - /** - * Shift all vectors based on the given vector - * - * @param vector - * the vector direction to shift the vectors - * @param vectors - * the vectors to be shifted - * @return the shifted vectors - */ - public static KList shift(Vector vector, KList vectors) - { - return new KList(new GListAdapter() - { - @Override - public Vector onAdapt(Vector from) - { - return from.add(vector); - } - }.adapt(vectors)); - } - - /** - * Attempt to get the blockFace for the vector (will be tri-normalized) - * - * @param v - * the vector - * @return the block face or null - */ - public static BlockFace getBlockFace(Vector v) - { - Vector p = triNormalize(v); - - for(BlockFace i : BlockFace.values()) - { - if(p.getX() == i.getModX() && p.getY() == i.getModY() && p.getZ() == i.getModZ()) - { - return i; - } - } - - for(BlockFace i : BlockFace.values()) - { - if(p.getX() == i.getModX() && p.getZ() == i.getModZ()) - { - return i; - } - } - - for(BlockFace i : BlockFace.values()) - { - if(p.getY() == i.getModY() && p.getZ() == i.getModZ()) - { - return i; - } - } - - for(BlockFace i : BlockFace.values()) - { - if(p.getX() == i.getModX() || p.getY() == i.getModY()) - { - return i; - } - } - - for(BlockFace i : BlockFace.values()) - { - if(p.getX() == i.getModX() || p.getY() == i.getModY() || p.getZ() == i.getModZ()) - { - return i; - } - } - - return null; - } - - /** - * Angle the vector in a self relative direction - * - * @param v - * the initial direction - * @param amt - * the amount to shift in the direction - * @return the shifted direction - */ - public static Vector angleLeft(Vector v, float amt) - { - Location l = new Location(Bukkit.getWorlds().get(0), 0, 0, 0); - l.setDirection(v); - float y = l.getYaw(); - float p = l.getPitch(); - CDou cy = new CDou(360); - CDou cp = new CDou(180); - cy.set(y); - cp.set(p); - cy.sub(amt); - l.setYaw((float) cy.get()); - l.setPitch((float) cp.get()); - - return l.getDirection(); - } - - /** - * Angle the vector in a self relative direction - * - * @param v - * the initial direction - * @param amt - * the amount to shift in the direction - * @return the shifted direction - */ - public static Vector angleRight(Vector v, float amt) - { - Location l = new Location(Bukkit.getWorlds().get(0), 0, 0, 0); - l.setDirection(v); - float y = l.getYaw(); - float p = l.getPitch(); - CDou cy = new CDou(360); - CDou cp = new CDou(180); - cy.set(y); - cp.set(p); - cy.add(amt); - l.setYaw((float) cy.get()); - l.setPitch((float) cp.get()); - - return l.getDirection(); - } - - /** - * Angle the vector in a self relative direction - * - * @param v - * the initial direction - * @param amt - * the amount to shift in the direction - * @return the shifted direction - */ - public static Vector angleUp(Vector v, float amt) - { - Location l = new Location(Bukkit.getWorlds().get(0), 0, 0, 0); - l.setDirection(v); - float y = l.getYaw(); - float p = l.getPitch(); - CDou cy = new CDou(360); - cy.set(y); - l.setYaw((float) cy.get()); - l.setPitch((float) Math.max(-90, p - amt)); - - return l.getDirection(); - } - - /** - * Angle the vector in a self relative direction - * - * @param v - * the initial direction - * @param amt - * the amount to shift in the direction - * @return the shifted direction - */ - public static Vector angleDown(Vector v, float amt) - { - Location l = new Location(Bukkit.getWorlds().get(0), 0, 0, 0); - l.setDirection(v); - float y = l.getYaw(); - float p = l.getPitch(); - CDou cy = new CDou(360); - cy.set(y); - l.setYaw((float) cy.get()); - l.setPitch((float) Math.min(90, p + amt)); - - return l.getDirection(); - } - - /** - * (clone) Force normalize the vector into three points, 1, 0, or -1. If the - * value is > 0.333 (1) if the value is less than -0.333 (-1) else 0 - * - * @param direction - * the direction - * @return the vector - */ - public static Vector triNormalize(Vector direction) - { - Vector v = direction.clone(); - v.normalize(); - - if(v.getX() > 0.333) - { - v.setX(1); - } - - else if(v.getX() < -0.333) - { - v.setX(-1); - } - - else - { - v.setX(0); - } - - if(v.getY() > 0.333) - { - v.setY(1); - } - - else if(v.getY() < -0.333) - { - v.setY(-1); - } - - else - { - v.setY(0); - } - - if(v.getZ() > 0.333) - { - v.setZ(1); - } - - else if(v.getZ() < -0.333) - { - v.setZ(-1); - } - - else - { - v.setZ(0); - } - - return v; - } -} diff --git a/src/main/java/ninja/bytecode/iris/util/VisualEffect.java b/src/main/java/ninja/bytecode/iris/util/VisualEffect.java deleted file mode 100644 index 2f619b094..000000000 --- a/src/main/java/ninja/bytecode/iris/util/VisualEffect.java +++ /dev/null @@ -1,17 +0,0 @@ -package ninja.bytecode.iris.util; - -import org.bukkit.Location; -import org.bukkit.entity.Player; - -import ninja.bytecode.shuriken.collections.KList; - -public interface VisualEffect -{ - public void play(Location l); - - public void play(Location l, double r); - - public void play(Location l, Player p); - - public void play(Location l, KList p); -} diff --git a/src/main/java/ninja/bytecode/iris/util/WorldState.java b/src/main/java/ninja/bytecode/iris/util/WorldState.java deleted file mode 100644 index a50485ef3..000000000 --- a/src/main/java/ninja/bytecode/iris/util/WorldState.java +++ /dev/null @@ -1,132 +0,0 @@ -package ninja.bytecode.iris.util; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.zip.GZIPInputStream; - -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; - -import net.md_5.bungee.api.ChatColor; -import ninja.bytecode.iris.Iris; -import ninja.bytecode.shuriken.collections.KMap; -import ninja.bytecode.shuriken.io.CustomOutputStream; -import ninja.bytecode.shuriken.logging.L; - -public class WorldState implements Listener -{ - private int taskId; - private KMap stateCache; - private World world; - - @SuppressWarnings("deprecation") - public WorldState(World world) - { - this.world = world; - taskId = Bukkit.getScheduler().scheduleAsyncRepeatingTask(Iris.instance, this::tick, 20, 20 * 18); - Bukkit.getPluginManager().registerEvents(this, Iris.instance); - } - - public void tick() - { - for(MCAPos i : stateCache.k()) - { - MCAState state = stateCache.get(i); - - if(state.isDirty()) - { - try - { - saveMCAState(i, state); - } - - catch(IOException e) - { - L.f(ChatColor.RED + "Failed to save MCA State " + i.toFileName()); - L.ex(e); - } - } - } - } - - public void close() - { - HandlerList.unregisterAll(this); - Bukkit.getScheduler().cancelTask(taskId); - - for(MCAPos i : stateCache.k()) - { - try - { - saveMCAState(i, stateCache.get(i)); - } - - catch(IOException e) - { - e.printStackTrace(); - } - } - } - - public void unloadState(MCAPos pos) - { - stateCache.remove(pos); - L.v(ChatColor.GRAY + "Unloaded MCA State " + pos.toFileName()); - } - - public MCAState getState(MCAPos pos) - { - if(!stateCache.containsKey(pos)) - { - try - { - stateCache.put(pos, loadMCAState(pos)); - } - - catch(IOException e) - { - L.f(ChatColor.RED + "Failed to read MCA State " + pos.toFileName()); - L.ex(e); - L.w(ChatColor.YELLOW + "Created Fallback MCA State " + pos.toString()); - stateCache.put(pos, new MCAState()); - } - } - - return stateCache.get(pos); - } - - private void saveMCAState(MCAPos pos, MCAState state) throws IOException - { - File file = new File(world.getWorldFolder(), "iris/state/" + pos.toFileName()); - file.getParentFile().mkdirs(); - FileOutputStream fos = new FileOutputStream(file); - CustomOutputStream cos = new CustomOutputStream(fos, 9); - state.write(cos); - state.saved(); - L.v(ChatColor.GRAY + "Saved MCA State " + pos.toString()); - } - - private MCAState loadMCAState(MCAPos pos) throws IOException - { - MCAState state = new MCAState(); - File file = new File(world.getWorldFolder(), "iris/state/" + pos.toFileName()); - - if(!file.exists()) - { - file.getParentFile().mkdirs(); - state.setDirty(); - L.v(ChatColor.GRAY + "Created MCA State " + pos.toString()); - return state; - } - - FileInputStream fin = new FileInputStream(file); - GZIPInputStream gzi = new GZIPInputStream(fin); - state.read(gzi); - L.v(ChatColor.GRAY + "Loaded MCA State " + pos.toString()); - return state; - } -} diff --git a/src/main/java/org/jnbt/ByteArrayTag.java b/src/main/java/org/jnbt/ByteArrayTag.java deleted file mode 100644 index 9b88ae90e..000000000 --- a/src/main/java/org/jnbt/ByteArrayTag.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.jnbt; - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -/** - * The TAG_Byte_Array tag. - * - * @author Graham Edgecombe - * - */ -public final class ByteArrayTag extends Tag { - - /** - * The value. - */ - private final byte[] value; - - /** - * Creates the tag. - * - * @param name The name. - * @param value The value. - */ - public ByteArrayTag(String name, byte[] value) { - super(name); - this.value = value; - } - - @Override - public byte[] getValue() { - return value; - } - - @Override - public String toString() { - StringBuilder hex = new StringBuilder(); - for (byte b : value) { - String hexDigits = Integer.toHexString(b).toUpperCase(); - if (hexDigits.length() == 1) { - hex.append("0"); - } - hex.append(hexDigits).append(" "); - } - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Byte_Array" + append + ": " + hex.toString(); - } - -} diff --git a/src/main/java/org/jnbt/ByteTag.java b/src/main/java/org/jnbt/ByteTag.java deleted file mode 100644 index f259f9b2a..000000000 --- a/src/main/java/org/jnbt/ByteTag.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.jnbt; - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -/** - * The TAG_Byte tag. - * - * @author Graham Edgecombe - * - */ -public final class ByteTag extends Tag { - - /** - * The value. - */ - private final byte value; - - /** - * Creates the tag. - * - * @param name The name. - * @param value The value. - */ - public ByteTag(String name, byte value) { - super(name); - this.value = value; - } - - @Override - public Byte getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Byte" + append + ": " + value; - } - -} diff --git a/src/main/java/org/jnbt/CompoundTag.java b/src/main/java/org/jnbt/CompoundTag.java deleted file mode 100644 index 30225f8dd..000000000 --- a/src/main/java/org/jnbt/CompoundTag.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.jnbt; - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -import java.util.Collections; -import java.util.Map; - -/** - * The TAG_Compound tag. - * - * @author Graham Edgecombe - * - */ -public final class CompoundTag extends Tag { - - /** - * The value. - */ - private final Map value; - - /** - * Creates the tag. - * - * @param name The name. - * @param value The value. - */ - public CompoundTag(String name, Map value) { - super(name); - this.value = Collections.unmodifiableMap(value); - } - - @Override - public Map getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - StringBuilder bldr = new StringBuilder(); - bldr.append("TAG_Compound" + append + ": " + value.size() + " entries\r\n{\r\n"); - for (Map.Entry entry : value.entrySet()) { - bldr.append(" " + entry.getValue().toString().replaceAll("\r\n", "\r\n ") + "\r\n"); - } - bldr.append("}"); - return bldr.toString(); - } - -} diff --git a/src/main/java/org/jnbt/DoubleTag.java b/src/main/java/org/jnbt/DoubleTag.java deleted file mode 100644 index 31327f0c7..000000000 --- a/src/main/java/org/jnbt/DoubleTag.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.jnbt; - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -/** - * The TAG_Double tag. - * - * @author Graham Edgecombe - * - */ -public final class DoubleTag extends Tag { - - /** - * The value. - */ - private final double value; - - /** - * Creates the tag. - * - * @param name The name. - * @param value The value. - */ - public DoubleTag(String name, double value) { - super(name); - this.value = value; - } - - @Override - public Double getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Double" + append + ": " + value; - } - -} diff --git a/src/main/java/org/jnbt/EndTag.java b/src/main/java/org/jnbt/EndTag.java deleted file mode 100644 index 0420ccf83..000000000 --- a/src/main/java/org/jnbt/EndTag.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.jnbt; - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -/** - * The TAG_End tag. - * - * @author Graham Edgecombe - * - */ -public final class EndTag extends Tag { - - /** - * Creates the tag. - */ - public EndTag() { - super(""); - } - - @Override - public Object getValue() { - return null; - } - - @Override - public String toString() { - return "TAG_End"; - } - -} diff --git a/src/main/java/org/jnbt/FloatTag.java b/src/main/java/org/jnbt/FloatTag.java deleted file mode 100644 index fc7e4cb2a..000000000 --- a/src/main/java/org/jnbt/FloatTag.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.jnbt; - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -/** - * The TAG_Float tag. - * - * @author Graham Edgecombe - * - */ -public final class FloatTag extends Tag { - - /** - * The value. - */ - private final float value; - - /** - * Creates the tag. - * - * @param name The name. - * @param value The value. - */ - public FloatTag(String name, float value) { - super(name); - this.value = value; - } - - @Override - public Float getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Float" + append + ": " + value; - } - -} diff --git a/src/main/java/org/jnbt/IntArrayTag.java b/src/main/java/org/jnbt/IntArrayTag.java deleted file mode 100644 index d5ef03ebd..000000000 --- a/src/main/java/org/jnbt/IntArrayTag.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.jnbt; - -import java.util.Arrays; - -/* - * JNBT License - * - * Copyright (c) 2015 Neil Wightman - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -/** - * The TAG_Int_Array tag. - * - * @author Neil Wightman - * - */ -public final class IntArrayTag extends Tag { - - /** - * The value. - */ - private final int[] value; - - /** - * Creates the tag. - * - * @param name The name. - * @param value The value. - */ - public IntArrayTag(String name, int[] value) { - super(name); - this.value = value; - } - - @Override - public int[] getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Int_Array" + append + ": " + Arrays.toString(value); - } - -} diff --git a/src/main/java/org/jnbt/IntTag.java b/src/main/java/org/jnbt/IntTag.java deleted file mode 100644 index 798f8e0e2..000000000 --- a/src/main/java/org/jnbt/IntTag.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.jnbt; - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -/** - * The TAG_Int tag. - * - * @author Graham Edgecombe - * - */ -public final class IntTag extends Tag { - - /** - * The value. - */ - private final int value; - - /** - * Creates the tag. - * - * @param name The name. - * @param value The value. - */ - public IntTag(String name, int value) { - super(name); - this.value = value; - } - - @Override - public Integer getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Int" + append + ": " + value; - } - -} diff --git a/src/main/java/org/jnbt/ListTag.java b/src/main/java/org/jnbt/ListTag.java deleted file mode 100644 index e12eb54c4..000000000 --- a/src/main/java/org/jnbt/ListTag.java +++ /dev/null @@ -1,99 +0,0 @@ -package org.jnbt; - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -import java.util.Collections; -import java.util.List; - -/** - * The TAG_List tag. - * - * @author Graham Edgecombe - * - */ -public final class ListTag extends Tag { - - /** - * The type. - */ - private final Class type; - - /** - * The value. - */ - private final List value; - - /** - * Creates the tag. - * - * @param name The name. - * @param type The type of item in the list. - * @param value The value. - */ - public ListTag(String name, Class type, List value) { - super(name); - this.type = type; - this.value = Collections.unmodifiableList(value); - } - - /** - * Gets the type of item in this list. - * - * @return The type of item in this list. - */ - public Class getType() { - return type; - } - - @Override - public List getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - StringBuilder bldr = new StringBuilder(); - bldr.append("TAG_List" + append + ": " + value.size() + " entries of type " + NBTUtils.getTypeName(type) + "\r\n{\r\n"); - for (Tag t : value) { - bldr.append(" " + t.toString().replaceAll("\r\n", "\r\n ") + "\r\n"); - } - bldr.append("}"); - return bldr.toString(); - } - -} diff --git a/src/main/java/org/jnbt/LongTag.java b/src/main/java/org/jnbt/LongTag.java deleted file mode 100644 index a7d4d7939..000000000 --- a/src/main/java/org/jnbt/LongTag.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.jnbt; - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -/** - * The TAG_Long tag. - * - * @author Graham Edgecombe - * - */ -public final class LongTag extends Tag { - - /** - * The value. - */ - private final long value; - - /** - * Creates the tag. - * - * @param name The name. - * @param value The value. - */ - public LongTag(String name, long value) { - super(name); - this.value = value; - } - - @Override - public Long getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Long" + append + ": " + value; - } - -} diff --git a/src/main/java/org/jnbt/NBTConstants.java b/src/main/java/org/jnbt/NBTConstants.java deleted file mode 100644 index 4696afcc5..000000000 --- a/src/main/java/org/jnbt/NBTConstants.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.jnbt; - -/* - * JNBT License - * - * Copyright (c) 2015 Neil Wightman - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -import java.nio.charset.Charset; - -/** - * Changes : Neil Wightman - Support 19133 Tag_Int_Array tag - */ -/** - * A class which holds constant values. - * - * @author Graham Edgecombe - * - */ -public final class NBTConstants { - - /** - * The character set used by NBT (UTF-8). - */ - public static final Charset CHARSET = Charset.forName("UTF-8"); - - /** - * Tag type constants. - */ - public static final int TYPE_END = 0, - TYPE_BYTE = 1, - TYPE_SHORT = 2, - TYPE_INT = 3, - TYPE_LONG = 4, - TYPE_FLOAT = 5, - TYPE_DOUBLE = 6, - TYPE_BYTE_ARRAY = 7, - TYPE_STRING = 8, - TYPE_LIST = 9, - TYPE_COMPOUND = 10, - TYPE_INT_ARRAY = 11; - - /** - * Default private constructor. - */ - private NBTConstants() { - - } - -} diff --git a/src/main/java/org/jnbt/NBTInputStream.java b/src/main/java/org/jnbt/NBTInputStream.java deleted file mode 100644 index 676666bd4..000000000 --- a/src/main/java/org/jnbt/NBTInputStream.java +++ /dev/null @@ -1,205 +0,0 @@ -package org.jnbt; - -/* - * JNBT License - * - * Copyright (c) 2015 Neil Wightman - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -import java.io.Closeable; -import java.io.DataInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.zip.GZIPInputStream; - -/** - * Changes : - * Neil Wightman - Support 19133 Tag_Int_Array tag - */ - -/** - *

- * This class reads NBT, or - * Named Binary Tag streams, and produces an object graph of subclasses of the Tag object.

- * - *
- * - * @author Graham Edgecombe - * - */ -public final class NBTInputStream implements Closeable { - - /** - * The data input stream. - */ - private final DataInputStream is; - - /** - * Create a new NBTInputStream, which will source its data from the specified input stream. - * @param is The output stream - */ - public NBTInputStream(DataInputStream is) { - this.is = is; - } - - /** - * Creates a new NBTInputStream, which will source its data from the specified input stream. - * The stream will be decompressed using GZIP. - * - * @param is The input stream. - * @throws IOException if an I/O error occurs. - */ - public NBTInputStream(InputStream is) throws IOException { - this.is = new DataInputStream(new GZIPInputStream(is)); - } - - /** - * Reads an NBT tag from the stream. - * - * @return The tag that was read. - * @throws IOException if an I/O error occurs. - */ - public Tag readTag() throws IOException { - return readTag(0); - } - - /** - * Reads an NBT from the stream. - * - * @param depth The depth of this tag. - * @return The tag that was read. - * @throws IOException if an I/O error occurs. - */ - private Tag readTag(int depth) throws IOException { - int type = is.readByte() & 0xFF; - - String name; - if (type != NBTConstants.TYPE_END) { - int nameLength = is.readShort() & 0xFFFF; - byte[] nameBytes = new byte[nameLength]; - is.readFully(nameBytes); - name = new String(nameBytes, NBTConstants.CHARSET); - } else { - name = ""; - } - - return readTagPayload(type, name, depth); - } - - /** - * Reads the payload of a tag, given the name and type. - * - * @param type The type. - * @param name The name. - * @param depth The depth. - * @return The tag. - * @throws IOException if an I/O error occurs. - */ - private Tag readTagPayload(int type, String name, int depth) throws IOException { - switch (type) { - case NBTConstants.TYPE_END: - if (depth == 0) { - throw new IOException("TAG_End found without a TAG_Compound/TAG_List tag preceding it."); - } else { - return new EndTag(); - } - case NBTConstants.TYPE_BYTE: - return new ByteTag(name, is.readByte()); - case NBTConstants.TYPE_SHORT: - return new ShortTag(name, is.readShort()); - case NBTConstants.TYPE_INT: - return new IntTag(name, is.readInt()); - case NBTConstants.TYPE_LONG: - return new LongTag(name, is.readLong()); - case NBTConstants.TYPE_FLOAT: - return new FloatTag(name, is.readFloat()); - case NBTConstants.TYPE_DOUBLE: - return new DoubleTag(name, is.readDouble()); - case NBTConstants.TYPE_BYTE_ARRAY: - int length = is.readInt(); - byte[] bytes = new byte[length]; - is.readFully(bytes); - return new ByteArrayTag(name, bytes); - case NBTConstants.TYPE_STRING: - length = is.readShort(); - bytes = new byte[length]; - is.readFully(bytes); - return new StringTag(name, new String(bytes, NBTConstants.CHARSET)); - case NBTConstants.TYPE_LIST: - int childType = is.readByte(); - length = is.readInt(); - - List tagList = new ArrayList(); - for (int i = 0; i < length; i++) { - Tag tag = readTagPayload(childType, "", depth + 1); - if (tag instanceof EndTag) { - throw new IOException("TAG_End not permitted in a list."); - } - tagList.add(tag); - } - - return new ListTag(name, NBTUtils.getTypeClass(childType), tagList); - case NBTConstants.TYPE_COMPOUND: - Map tagMap = new HashMap(); - while (true) { - Tag tag = readTag(depth + 1); - if (tag instanceof EndTag) { - break; - } else { - tagMap.put(tag.getName(), tag); - } - } - - return new CompoundTag(name, tagMap); - case NBTConstants.TYPE_INT_ARRAY: - length = is.readInt(); - int[] value = new int[length]; - for (int i = 0; i < length; i++) { - value[i] = is.readInt(); - } - return new IntArrayTag(name, value); - default: - throw new IOException("Invalid tag type: " + type + "."); - } - } - - @Override - public void close() throws IOException { - is.close(); - } - -} diff --git a/src/main/java/org/jnbt/NBTOutputStream.java b/src/main/java/org/jnbt/NBTOutputStream.java deleted file mode 100644 index b7db3f745..000000000 --- a/src/main/java/org/jnbt/NBTOutputStream.java +++ /dev/null @@ -1,301 +0,0 @@ -package org.jnbt; - -/* - * JNBT License - * - * Copyright (c) 2015 Neil Wightman - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -import java.io.Closeable; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.List; -import java.util.zip.GZIPOutputStream; -/** - * Changes : Neil Wightman - Support 19133 Tag_Int_Array tag - */ - -/** - *

- * This class writes NBT, or - * Named Binary Tag Tag objects to an underlying OutputStream.

- * - *

- * The NBT format was created by Markus Persson, and the specification may be found at - * http://www.minecraft.net/docs/NBT.txt.

- * - * @author Graham Edgecombe - * - */ -public final class NBTOutputStream implements Closeable { - - /** - * The output stream. - */ - private final DataOutputStream os; - - /** - * Create a new NBTOutputStream, which will write data to the specified underlying output stream. - * @param os The output stream - */ - public NBTOutputStream(DataOutputStream os) { - this.os = os; - } - - /** - * Creates a new NBTOutputStream, which will write data to the specified underlying output stream. - * the stream will be compressed using GZIP. - * - * @param os The output stream. - * @throws IOException if an I/O error occurs. - */ - public NBTOutputStream(OutputStream os) throws IOException { - this.os = new DataOutputStream(new GZIPOutputStream(os)); - } - - /** - * Writes a tag. - * - * @param tag The tag to write. - * @throws IOException if an I/O error occurs. - */ - public void writeTag(Tag tag) throws IOException { - int type = NBTUtils.getTypeCode(tag.getClass()); - String name = tag.getName(); - byte[] nameBytes = name.getBytes(NBTConstants.CHARSET); - - os.writeByte(type); - os.writeShort(nameBytes.length); - os.write(nameBytes); - - if (type == NBTConstants.TYPE_END) { - throw new IOException("Named TAG_End not permitted."); - } - - writeTagPayload(tag); - } - - /** - * Writes tag payload. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeTagPayload(Tag tag) throws IOException { - int type = NBTUtils.getTypeCode(tag.getClass()); - switch (type) { - case NBTConstants.TYPE_END: - writeEndTagPayload((EndTag) tag); - break; - case NBTConstants.TYPE_BYTE: - writeByteTagPayload((ByteTag) tag); - break; - case NBTConstants.TYPE_SHORT: - writeShortTagPayload((ShortTag) tag); - break; - case NBTConstants.TYPE_INT: - writeIntTagPayload((IntTag) tag); - break; - case NBTConstants.TYPE_LONG: - writeLongTagPayload((LongTag) tag); - break; - case NBTConstants.TYPE_FLOAT: - writeFloatTagPayload((FloatTag) tag); - break; - case NBTConstants.TYPE_DOUBLE: - writeDoubleTagPayload((DoubleTag) tag); - break; - case NBTConstants.TYPE_BYTE_ARRAY: - writeByteArrayTagPayload((ByteArrayTag) tag); - break; - case NBTConstants.TYPE_STRING: - writeStringTagPayload((StringTag) tag); - break; - case NBTConstants.TYPE_LIST: - writeListTagPayload((ListTag) tag); - break; - case NBTConstants.TYPE_COMPOUND: - writeCompoundTagPayload((CompoundTag) tag); - break; - case NBTConstants.TYPE_INT_ARRAY: - writeIntArrayTagPayload((IntArrayTag) tag); - break; - default: - throw new IOException("Invalid tag type: " + type + "."); - } - } - - /** - * Writes a TAG_Byte tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeByteTagPayload(ByteTag tag) throws IOException { - os.writeByte(tag.getValue()); - } - - /** - * Writes a TAG_Byte_Array tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeByteArrayTagPayload(ByteArrayTag tag) throws IOException { - byte[] bytes = tag.getValue(); - os.writeInt(bytes.length); - os.write(bytes); - } - - - /** - * Writes a TAG_Compound tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeCompoundTagPayload(CompoundTag tag) throws IOException { - for (Tag childTag : tag.getValue().values()) { - writeTag(childTag); - } - os.writeByte((byte) 0); // end tag - better way? - } - - /** - * Writes a TAG_List tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeListTagPayload(ListTag tag) throws IOException { - Class clazz = tag.getType(); - List tags = tag.getValue(); - int size = tags.size(); - - os.writeByte(NBTUtils.getTypeCode(clazz)); - os.writeInt(size); - for (int i = 0; i < size; i++) { - writeTagPayload(tags.get(i)); - } - } - - /** - * Writes a TAG_String tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeStringTagPayload(StringTag tag) throws IOException { - byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET); - os.writeShort(bytes.length); - os.write(bytes); - } - - /** - * Writes a TAG_Double tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeDoubleTagPayload(DoubleTag tag) throws IOException { - os.writeDouble(tag.getValue()); - } - - /** - * Writes a TAG_Float tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeFloatTagPayload(FloatTag tag) throws IOException { - os.writeFloat(tag.getValue()); - } - - /** - * Writes a TAG_Long tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeLongTagPayload(LongTag tag) throws IOException { - os.writeLong(tag.getValue()); - } - - /** - * Writes a TAG_Int tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeIntTagPayload(IntTag tag) throws IOException { - os.writeInt(tag.getValue()); - } - - /** - * Writes a TAG_Short tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeShortTagPayload(ShortTag tag) throws IOException { - os.writeShort(tag.getValue()); - } - - /** - * Writes a TAG_Empty tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeEndTagPayload(EndTag tag) { - /* empty */ - } - - /** - * Writes a TAG_Int_Array tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeIntArrayTagPayload(IntArrayTag tag) throws IOException { - final int[] values = tag.getValue(); - os.writeInt(values.length); - for(final int value : values) { - os.writeInt(value); - } - } - - @Override - public void close() throws IOException { - os.close(); - } - -} diff --git a/src/main/java/org/jnbt/NBTUtils.java b/src/main/java/org/jnbt/NBTUtils.java deleted file mode 100644 index c4879af10..000000000 --- a/src/main/java/org/jnbt/NBTUtils.java +++ /dev/null @@ -1,165 +0,0 @@ -package org.jnbt; - -/* - * JNBT License - * - * Copyright (c) 2015 Neil Wightman - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -/** - * Changes : Neil Wightman - Support 19133 Tag_Int_Array tag - */ -/** - * A class which contains NBT-related utility methods. This currently supports reading 19133 but only writing 19132. - * - * @author Graham Edgecombe - * - */ -public final class NBTUtils { - - /** - * Gets the type name of a tag. - * - * @param clazz The tag class. - * @return The type name. - */ - public static String getTypeName(Class clazz) { - if (clazz.equals(ByteArrayTag.class)) { - return "TAG_Byte_Array"; - } else if (clazz.equals(ByteTag.class)) { - return "TAG_Byte"; - } else if (clazz.equals(CompoundTag.class)) { - return "TAG_Compound"; - } else if (clazz.equals(DoubleTag.class)) { - return "TAG_Double"; - } else if (clazz.equals(EndTag.class)) { - return "TAG_End"; - } else if (clazz.equals(FloatTag.class)) { - return "TAG_Float"; - } else if (clazz.equals(IntTag.class)) { - return "TAG_Int"; - } else if (clazz.equals(ListTag.class)) { - return "TAG_List"; - } else if (clazz.equals(LongTag.class)) { - return "TAG_Long"; - } else if (clazz.equals(ShortTag.class)) { - return "TAG_Short"; - } else if (clazz.equals(StringTag.class)) { - return "TAG_String"; - } else if (clazz.equals(IntArrayTag.class)) { - return "TAG_Int_Array"; - } else { - throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ")."); - } - } - - /** - * Gets the type code of a tag class. - * - * @param clazz The tag class. - * @return The type code. - * @throws IllegalArgumentException if the tag class is invalid. - */ - public static int getTypeCode(Class clazz) { - if (clazz.equals(ByteArrayTag.class)) { - return NBTConstants.TYPE_BYTE_ARRAY; - } else if (clazz.equals(ByteTag.class)) { - return NBTConstants.TYPE_BYTE; - } else if (clazz.equals(CompoundTag.class)) { - return NBTConstants.TYPE_COMPOUND; - } else if (clazz.equals(DoubleTag.class)) { - return NBTConstants.TYPE_DOUBLE; - } else if (clazz.equals(EndTag.class)) { - return NBTConstants.TYPE_END; - } else if (clazz.equals(FloatTag.class)) { - return NBTConstants.TYPE_FLOAT; - } else if (clazz.equals(IntTag.class)) { - return NBTConstants.TYPE_INT; - } else if (clazz.equals(ListTag.class)) { - return NBTConstants.TYPE_LIST; - } else if (clazz.equals(LongTag.class)) { - return NBTConstants.TYPE_LONG; - } else if (clazz.equals(ShortTag.class)) { - return NBTConstants.TYPE_SHORT; - } else if (clazz.equals(StringTag.class)) { - return NBTConstants.TYPE_STRING; - } else if (clazz.equals(IntArrayTag.class)) { - return NBTConstants.TYPE_INT_ARRAY; - } else { - throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ")."); - } - } - - /** - * Gets the class of a type of tag. - * - * @param type The type. - * @return The class. - * @throws IllegalArgumentException if the tag type is invalid. - */ - public static Class getTypeClass(int type) { - switch (type) { - case NBTConstants.TYPE_END: - return EndTag.class; - case NBTConstants.TYPE_BYTE: - return ByteTag.class; - case NBTConstants.TYPE_SHORT: - return ShortTag.class; - case NBTConstants.TYPE_INT: - return IntTag.class; - case NBTConstants.TYPE_LONG: - return LongTag.class; - case NBTConstants.TYPE_FLOAT: - return FloatTag.class; - case NBTConstants.TYPE_DOUBLE: - return DoubleTag.class; - case NBTConstants.TYPE_BYTE_ARRAY: - return ByteArrayTag.class; - case NBTConstants.TYPE_STRING: - return StringTag.class; - case NBTConstants.TYPE_LIST: - return ListTag.class; - case NBTConstants.TYPE_COMPOUND: - return CompoundTag.class; - case NBTConstants.TYPE_INT_ARRAY: - return IntArrayTag.class; - default: - throw new IllegalArgumentException("Invalid tag type : " + type + "."); - } - } - - /** - * Default private constructor. - */ - private NBTUtils() { - - } - -} diff --git a/src/main/java/org/jnbt/ShortTag.java b/src/main/java/org/jnbt/ShortTag.java deleted file mode 100644 index cf5448114..000000000 --- a/src/main/java/org/jnbt/ShortTag.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.jnbt; - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -/** - * The TAG_Short tag. - * - * @author Graham Edgecombe - * - */ -public final class ShortTag extends Tag { - - /** - * The value. - */ - private final short value; - - /** - * Creates the tag. - * - * @param name The name. - * @param value The value. - */ - public ShortTag(String name, short value) { - super(name); - this.value = value; - } - - @Override - public Short getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Short" + append + ": " + value; - } - -} diff --git a/src/main/java/org/jnbt/StringTag.java b/src/main/java/org/jnbt/StringTag.java deleted file mode 100644 index 80e8ba1d6..000000000 --- a/src/main/java/org/jnbt/StringTag.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.jnbt; - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -/** - * The TAG_String tag. - * - * @author Graham Edgecombe - * - */ -public final class StringTag extends Tag { - - /** - * The value. - */ - private final String value; - - /** - * Creates the tag. - * - * @param name The name. - * @param value The value. - */ - public StringTag(String name, String value) { - super(name); - this.value = value; - } - - @Override - public String getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_String" + append + ": " + value; - } - -} diff --git a/src/main/java/org/jnbt/Tag.java b/src/main/java/org/jnbt/Tag.java deleted file mode 100644 index 80c7ff6f9..000000000 --- a/src/main/java/org/jnbt/Tag.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.jnbt; - -/* - * JNBT License - * - * Copyright (c) 2010 Graham Edgecombe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of the JNBT team nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -/** - * Represents a single NBT tag. - * - * @author Graham Edgecombe - * - */ -public abstract class Tag { - - /** - * The name of this tag. - */ - private final String name; - - /** - * Creates the tag with the specified name. - * - * @param name The name. - */ - public Tag(String name) { - this.name = name; - } - - /** - * Gets the name of this tag. - * - * @return The name of this tag. - */ - public final String getName() { - return name; - } - - /** - * Gets the value of this tag. - * - * @return The value of this tag. - */ - public abstract Object getValue(); - -} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index cf9f2607f..29268c6cb 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -2,5 +2,5 @@ name: ${project.name} version: ${project.version} main: ninja.bytecode.iris.Iris load: STARTUP -depend: [Mortar] +api-version: 1.15 hotload-dependencies: false \ No newline at end of file

- * The NBT format was created by Markus Persson, and the specification may be found at - * http://www.minecraft.net/docs/NBT.txt.