From 5e761c3e299fdb33b5187c6601caa404e7abe1e2 Mon Sep 17 00:00:00 2001 From: dfsek Date: Fri, 19 Feb 2021 20:36:35 -0700 Subject: [PATCH 01/95] basic addon loading --- .../dfsek/terra/addons/addon/TerraAddon.java | 30 ++++++++++ .../dfsek/terra/addons/annotations/Addon.java | 12 ++++ .../terra/addons/annotations/Author.java | 12 ++++ .../terra/addons/annotations/Depends.java | 12 ++++ .../terra/addons/annotations/Version.java | 12 ++++ .../addons/annotations/inject/Inject.java | 11 ++++ .../addons/loading/AddonClassLoader.java | 60 +++++++++++++++++++ .../addons/loading/AddonLoadException.java | 11 ++++ .../com/dfsek/terra/api/core/TerraPlugin.java | 4 +- .../api/core/event/annotations/Global.java | 7 +++ .../math/paralithic/noise/NoiseFunction2.java | 2 +- .../script/functions/BiomeFunction.java | 4 +- .../script/functions/CheckFunction.java | 4 +- .../{ => api}/util/hash/HashIntrinsic.java | 2 +- .../util/hash/HashMapDoubleDouble.java | 2 +- .../terra/api/util/seeded/SourceSeeded.java | 2 +- .../terra/api/util/seeded/StageSeeded.java | 2 +- .../{util => api/util/world}/MaterialSet.java | 2 +- .../{util => api/util/world}/PaletteUtil.java | 2 +- .../util/world}/PopulationUtil.java | 2 +- .../{ => api/world}/biome/TerraBiome.java | 3 +- .../world}/biome/UserDefinedBiome.java | 3 +- .../api/world/biome/pipeline/BiomeHolder.java | 18 ++++++ .../world}/biome/pipeline/BiomePipeline.java | 6 +- .../biome/pipeline/TerraBiomeHolder.java | 10 ++-- .../biome/pipeline/expand/BiomeExpander.java | 7 +++ .../pipeline/expand/FractalExpander.java | 4 +- .../biome/pipeline/mutator/BiomeMutator.java | 6 +- .../pipeline/mutator/BorderListMutator.java | 4 +- .../biome/pipeline/mutator/BorderMutator.java | 4 +- .../pipeline/mutator/ReplaceListMutator.java | 4 +- .../pipeline/mutator/ReplaceMutator.java | 4 +- .../biome/pipeline/mutator/SmoothMutator.java | 4 +- .../biome/pipeline/source/BiomeSource.java | 7 +++ .../biome/pipeline/source/RandomSource.java | 4 +- .../biome/pipeline/stages/ExpanderStage.java | 6 +- .../biome/pipeline/stages/MutatorStage.java | 6 +- .../world/biome/pipeline/stages/Stage.java | 10 ++++ .../world}/biome/provider/BiomeProvider.java | 4 +- .../biome/provider/ImageBiomeProvider.java | 4 +- .../biome/provider/SingleBiomeProvider.java | 4 +- .../biome/provider/StandardBiomeProvider.java | 8 +-- .../api/world/tree/fractal/FractalTree.java | 2 +- .../api/world/tree/fractal/trees/Cactus.java | 2 +- .../world/tree/fractal/trees/IceSpike.java | 2 +- .../api/world/tree/fractal/trees/OakTree.java | 2 +- .../tree/fractal/trees/ShatteredPillar.java | 2 +- .../tree/fractal/trees/ShatteredTree.java | 2 +- .../fractal/trees/SmallShatteredPillar.java | 2 +- .../fractal/trees/SmallShatteredTree.java | 2 +- .../world/tree/fractal/trees/SpruceTree.java | 2 +- .../dfsek/terra/async/AsyncBiomeFinder.java | 4 +- .../dfsek/terra/async/AsyncFeatureFinder.java | 2 +- .../terra/async/AsyncStructureFinder.java | 4 +- .../terra/biome/pipeline/BiomeHolder.java | 18 ------ .../biome/pipeline/expand/BiomeExpander.java | 7 --- .../biome/pipeline/source/BiomeSource.java | 7 --- .../terra/biome/pipeline/stages/Stage.java | 10 ---- .../com/dfsek/terra/carving/CarverCache.java | 6 +- .../dfsek/terra/carving/CarverPalette.java | 2 +- .../terra/carving/UserDefinedCarver.java | 2 +- .../dfsek/terra/config/GenericLoaders.java | 10 ++-- .../terra/config/factories/BiomeFactory.java | 4 +- .../config/loaders/MaterialSetLoader.java | 2 +- .../com/dfsek/terra/config/loaders/Types.java | 2 +- .../biome/BiomeProviderBuilderLoader.java | 2 +- .../config/biome/SourceBuilderLoader.java | 4 +- .../config/biome/StageBuilderLoader.java | 4 +- .../source/BiomePipelineTemplate.java | 6 +- .../source/BiomeProviderTemplate.java | 2 +- .../source/ImageProviderTemplate.java | 4 +- .../source/SingleBiomeProviderTemplate.java | 6 +- .../biome/templates/stage/StageTemplate.java | 2 +- .../stage/expander/ExpanderStageTemplate.java | 6 +- .../mutator/BorderListMutatorTemplate.java | 6 +- .../stage/mutator/BorderMutatorTemplate.java | 6 +- .../stage/mutator/MutatorStageTemplate.java | 6 +- .../mutator/ReplaceListMutatorTemplate.java | 6 +- .../stage/mutator/ReplaceMutatorTemplate.java | 6 +- .../stage/mutator/SmoothMutatorTemplate.java | 4 +- .../loaders/palette/CarverPaletteLoader.java | 2 +- .../dfsek/terra/config/pack/ConfigPack.java | 4 +- .../config/pack/ConfigPackPostTemplate.java | 2 +- .../config/templates/CarverTemplate.java | 2 +- .../terra/config/templates/FloraTemplate.java | 2 +- .../terra/config/templates/OreTemplate.java | 2 +- .../terra/config/templates/TreeTemplate.java | 2 +- .../dfsek/terra/registry/AddonRegistry.java | 56 +++++++++++++++++ .../dfsek/terra/registry/ConfigRegistry.java | 2 +- .../dfsek/terra/registry/TerraRegistry.java | 5 ++ .../terra/registry/config/BiomeRegistry.java | 2 +- .../terra/registry/config/FloraRegistry.java | 2 +- .../com/dfsek/terra/world/TerraWorld.java | 4 +- .../generation/MasterChunkGenerator.java | 8 +-- .../terra/world/generation/math/Sampler.java | 2 +- .../interpolation/BiomeChunkInterpolator.java | 2 +- .../interpolation/ElevationInterpolator.java | 2 +- .../{ => world}/population/CavePopulator.java | 4 +- .../world/population/FloraPopulator.java | 6 +- .../terra/world/population/OrePopulator.java | 4 +- .../world/population/StructurePopulator.java | 4 +- .../terra/world/population/TreePopulator.java | 6 +- .../population/items/flora/ConstantFlora.java | 2 +- .../population/items/flora/TerraFlora.java | 2 +- .../items/ores/DeformedSphereOre.java | 2 +- .../world/population/items/ores/Ore.java | 2 +- .../population/items/ores/VanillaOre.java | 2 +- .../population/items/tree/TerraTree.java | 2 +- .../population/items/tree/TreeLayer.java | 2 +- .../src/test/java/biome/DistributionTest.java | 10 +++- common/src/test/java/biome/ImageTest.java | 6 +- common/src/test/java/event/EventTest.java | 10 +++- .../dfsek/terra/bukkit/TerraBukkitPlugin.java | 8 +++ .../command/command/biome/BiomeCommand.java | 4 +- .../command/biome/BiomeInfoCommand.java | 2 +- .../command/biome/BiomeLocateCommand.java | 2 +- .../structure/load/LoadFullCommand.java | 2 +- .../BukkitChunkGeneratorWrapper.java | 2 +- .../dfsek/terra/bukkit/world/BukkitTree.java | 2 +- .../bukkit/src}/main/resources/lang/da.yml | 0 .../dfsek/terra/fabric/TerraFabricPlugin.java | 10 +++- .../dfsek/terra/fabric/world/FabricTree.java | 2 +- .../terra/fabric/world/TerraBiomeSource.java | 4 +- .../com/dfsek/terra/StandalonePlugin.java | 7 +++ 124 files changed, 483 insertions(+), 220 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/addons/addon/TerraAddon.java create mode 100644 common/src/main/java/com/dfsek/terra/addons/annotations/Addon.java create mode 100644 common/src/main/java/com/dfsek/terra/addons/annotations/Author.java create mode 100644 common/src/main/java/com/dfsek/terra/addons/annotations/Depends.java create mode 100644 common/src/main/java/com/dfsek/terra/addons/annotations/Version.java create mode 100644 common/src/main/java/com/dfsek/terra/addons/annotations/inject/Inject.java create mode 100644 common/src/main/java/com/dfsek/terra/addons/loading/AddonClassLoader.java create mode 100644 common/src/main/java/com/dfsek/terra/addons/loading/AddonLoadException.java create mode 100644 common/src/main/java/com/dfsek/terra/api/core/event/annotations/Global.java rename common/src/main/java/com/dfsek/terra/{ => api}/util/hash/HashIntrinsic.java (99%) rename common/src/main/java/com/dfsek/terra/{ => api}/util/hash/HashMapDoubleDouble.java (99%) rename common/src/main/java/com/dfsek/terra/{util => api/util/world}/MaterialSet.java (94%) rename common/src/main/java/com/dfsek/terra/{util => api/util/world}/PaletteUtil.java (94%) rename common/src/main/java/com/dfsek/terra/{util => api/util/world}/PopulationUtil.java (91%) rename common/src/main/java/com/dfsek/terra/{ => api/world}/biome/TerraBiome.java (89%) rename common/src/main/java/com/dfsek/terra/{ => api/world}/biome/UserDefinedBiome.java (95%) create mode 100644 common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/BiomeHolder.java rename common/src/main/java/com/dfsek/terra/{ => api/world}/biome/pipeline/BiomePipeline.java (91%) rename common/src/main/java/com/dfsek/terra/{ => api/world}/biome/pipeline/TerraBiomeHolder.java (89%) create mode 100644 common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/expand/BiomeExpander.java rename common/src/main/java/com/dfsek/terra/{ => api/world}/biome/pipeline/expand/FractalExpander.java (81%) rename common/src/main/java/com/dfsek/terra/{ => api/world}/biome/pipeline/mutator/BiomeMutator.java (75%) rename common/src/main/java/com/dfsek/terra/{ => api/world}/biome/pipeline/mutator/BorderListMutator.java (94%) rename common/src/main/java/com/dfsek/terra/{ => api/world}/biome/pipeline/mutator/BorderMutator.java (92%) rename common/src/main/java/com/dfsek/terra/{ => api/world}/biome/pipeline/mutator/ReplaceListMutator.java (92%) rename common/src/main/java/com/dfsek/terra/{ => api/world}/biome/pipeline/mutator/ReplaceMutator.java (88%) rename common/src/main/java/com/dfsek/terra/{ => api/world}/biome/pipeline/mutator/SmoothMutator.java (90%) create mode 100644 common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/source/BiomeSource.java rename common/src/main/java/com/dfsek/terra/{ => api/world}/biome/pipeline/source/RandomSource.java (83%) rename common/src/main/java/com/dfsek/terra/{ => api/world}/biome/pipeline/stages/ExpanderStage.java (68%) rename common/src/main/java/com/dfsek/terra/{ => api/world}/biome/pipeline/stages/MutatorStage.java (70%) create mode 100644 common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/stages/Stage.java rename common/src/main/java/com/dfsek/terra/{ => api/world}/biome/provider/BiomeProvider.java (87%) rename common/src/main/java/com/dfsek/terra/{ => api/world}/biome/provider/ImageBiomeProvider.java (95%) rename common/src/main/java/com/dfsek/terra/{ => api/world}/biome/provider/SingleBiomeProvider.java (79%) rename common/src/main/java/com/dfsek/terra/{ => api/world}/biome/provider/StandardBiomeProvider.java (90%) delete mode 100644 common/src/main/java/com/dfsek/terra/biome/pipeline/BiomeHolder.java delete mode 100644 common/src/main/java/com/dfsek/terra/biome/pipeline/expand/BiomeExpander.java delete mode 100644 common/src/main/java/com/dfsek/terra/biome/pipeline/source/BiomeSource.java delete mode 100644 common/src/main/java/com/dfsek/terra/biome/pipeline/stages/Stage.java create mode 100644 common/src/main/java/com/dfsek/terra/registry/AddonRegistry.java rename common/src/main/java/com/dfsek/terra/{ => world}/population/CavePopulator.java (98%) rename {src => platforms/bukkit/src}/main/resources/lang/da.yml (100%) diff --git a/common/src/main/java/com/dfsek/terra/addons/addon/TerraAddon.java b/common/src/main/java/com/dfsek/terra/addons/addon/TerraAddon.java new file mode 100644 index 000000000..15a503b77 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/addons/addon/TerraAddon.java @@ -0,0 +1,30 @@ +package com.dfsek.terra.addons.addon; + + +import com.dfsek.terra.addons.annotations.Addon; +import com.dfsek.terra.addons.annotations.Author; +import com.dfsek.terra.addons.annotations.Version; +import org.jetbrains.annotations.NotNull; + +public abstract class TerraAddon { + public final @NotNull String getVersion() { + Version version = getClass().getAnnotation(Version.class); + return version == null ? "0.1.0" : version.value(); + } + + public final @NotNull String getAuthor() { + Author author = getClass().getAnnotation(Author.class); + return author == null ? "Anon Y. Mous" : author.value(); + } + + public final @NotNull String getName() { + Addon addon = getClass().getAnnotation(Addon.class); + if(addon == null) throw new IllegalStateException("Addon annotation not present"); // This should never happen; the presence of this annotation is checked by the addon loader. + return addon.value(); + } + + /** + * Invoked immediately after an addon is loaded. + */ + public abstract void initialize(); +} diff --git a/common/src/main/java/com/dfsek/terra/addons/annotations/Addon.java b/common/src/main/java/com/dfsek/terra/addons/annotations/Addon.java new file mode 100644 index 000000000..aa0c3e2c1 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/addons/annotations/Addon.java @@ -0,0 +1,12 @@ +package com.dfsek.terra.addons.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface Addon { + String value(); +} diff --git a/common/src/main/java/com/dfsek/terra/addons/annotations/Author.java b/common/src/main/java/com/dfsek/terra/addons/annotations/Author.java new file mode 100644 index 000000000..4967706fa --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/addons/annotations/Author.java @@ -0,0 +1,12 @@ +package com.dfsek.terra.addons.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface Author { + String value(); +} diff --git a/common/src/main/java/com/dfsek/terra/addons/annotations/Depends.java b/common/src/main/java/com/dfsek/terra/addons/annotations/Depends.java new file mode 100644 index 000000000..4e4e755f5 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/addons/annotations/Depends.java @@ -0,0 +1,12 @@ +package com.dfsek.terra.addons.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface Depends { + String[] value(); +} diff --git a/common/src/main/java/com/dfsek/terra/addons/annotations/Version.java b/common/src/main/java/com/dfsek/terra/addons/annotations/Version.java new file mode 100644 index 000000000..f4c08b936 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/addons/annotations/Version.java @@ -0,0 +1,12 @@ +package com.dfsek.terra.addons.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface Version { + String value(); +} diff --git a/common/src/main/java/com/dfsek/terra/addons/annotations/inject/Inject.java b/common/src/main/java/com/dfsek/terra/addons/annotations/inject/Inject.java new file mode 100644 index 000000000..83552f4cc --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/addons/annotations/inject/Inject.java @@ -0,0 +1,11 @@ +package com.dfsek.terra.addons.annotations.inject; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Inject { +} diff --git a/common/src/main/java/com/dfsek/terra/addons/loading/AddonClassLoader.java b/common/src/main/java/com/dfsek/terra/addons/loading/AddonClassLoader.java new file mode 100644 index 000000000..5cd20fd75 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/addons/loading/AddonClassLoader.java @@ -0,0 +1,60 @@ +package com.dfsek.terra.addons.loading; + +import com.dfsek.terra.addons.addon.TerraAddon; +import com.dfsek.terra.addons.annotations.Addon; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Set; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +public class AddonClassLoader extends URLClassLoader { + static { + ClassLoader.registerAsParallelCapable(); + } + + public AddonClassLoader(URL[] urls, ClassLoader parent) { + super(urls, parent); + } + + public AddonClassLoader(URL[] urls) { + super(urls); + } + + @SuppressWarnings("unchecked") + public static Set> fetchAddonClasses(File file) throws IOException { + JarFile jarFile = new JarFile(file); + Enumeration entries = jarFile.entries(); + + AddonClassLoader loader = new AddonClassLoader(new URL[] {file.toURI().toURL()}, AddonClassLoader.class.getClassLoader()); + + Set> set = new HashSet<>(); + while(entries.hasMoreElements()) { + JarEntry entry = entries.nextElement(); + + if(entry.isDirectory() || !entry.getName().endsWith(".class")) continue; + String className = entry.getName().substring(0, entry.getName().length() - 6).replace('/', '.'); + + try { + Class clazz = loader.loadClass(className); + + Addon addon = clazz.getAnnotation(Addon.class); + + if(addon == null) continue; + + if(!TerraAddon.class.isAssignableFrom(clazz)) throw new IllegalArgumentException("Addon class must extend TerraAddon."); + + set.add((Class) clazz); + } catch(ClassNotFoundException e) { + e.printStackTrace(); + } + } + + return set; + } +} diff --git a/common/src/main/java/com/dfsek/terra/addons/loading/AddonLoadException.java b/common/src/main/java/com/dfsek/terra/addons/loading/AddonLoadException.java new file mode 100644 index 000000000..45e8aa1b2 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/addons/loading/AddonLoadException.java @@ -0,0 +1,11 @@ +package com.dfsek.terra.addons.loading; + +public class AddonLoadException extends Exception { + public AddonLoadException(String message) { + super(message); + } + + public AddonLoadException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/common/src/main/java/com/dfsek/terra/api/core/TerraPlugin.java b/common/src/main/java/com/dfsek/terra/api/core/TerraPlugin.java index 7fee3132f..7076afc2c 100644 --- a/common/src/main/java/com/dfsek/terra/api/core/TerraPlugin.java +++ b/common/src/main/java/com/dfsek/terra/api/core/TerraPlugin.java @@ -8,6 +8,7 @@ import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.config.PluginConfig; import com.dfsek.terra.config.lang.Language; import com.dfsek.terra.debug.DebugLogger; +import com.dfsek.terra.registry.AddonRegistry; import com.dfsek.terra.registry.ConfigRegistry; import com.dfsek.terra.world.TerraWorld; @@ -33,6 +34,8 @@ public interface TerraPlugin extends LoaderRegistrar { ConfigRegistry getRegistry(); + AddonRegistry getAddons(); + void reload(); ItemHandle getItemHandle(); @@ -41,7 +44,6 @@ public interface TerraPlugin extends LoaderRegistrar { String platformName(); - DebugLogger getDebugLogger(); EventManager getEventManager(); diff --git a/common/src/main/java/com/dfsek/terra/api/core/event/annotations/Global.java b/common/src/main/java/com/dfsek/terra/api/core/event/annotations/Global.java new file mode 100644 index 000000000..afb523515 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/core/event/annotations/Global.java @@ -0,0 +1,7 @@ +package com.dfsek.terra.api.core.event.annotations; + +/** + * Specifies that an event handler is to handle all events. + */ +public @interface Global { +} diff --git a/common/src/main/java/com/dfsek/terra/api/math/paralithic/noise/NoiseFunction2.java b/common/src/main/java/com/dfsek/terra/api/math/paralithic/noise/NoiseFunction2.java index 3b51cdd48..f4a516375 100644 --- a/common/src/main/java/com/dfsek/terra/api/math/paralithic/noise/NoiseFunction2.java +++ b/common/src/main/java/com/dfsek/terra/api/math/paralithic/noise/NoiseFunction2.java @@ -1,7 +1,7 @@ package com.dfsek.terra.api.math.paralithic.noise; import com.dfsek.terra.api.math.noise.NoiseSampler; -import com.dfsek.terra.util.hash.HashMapDoubleDouble; +import com.dfsek.terra.api.util.hash.HashMapDoubleDouble; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/BiomeFunction.java b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/BiomeFunction.java index dd6a5bc0b..8e8640e98 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/BiomeFunction.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/BiomeFunction.java @@ -10,8 +10,8 @@ import com.dfsek.terra.api.structures.parser.lang.variables.Variable; import com.dfsek.terra.api.structures.script.TerraImplementationArguments; import com.dfsek.terra.api.structures.structure.RotationUtil; import com.dfsek.terra.api.structures.tokenizer.Position; -import com.dfsek.terra.biome.UserDefinedBiome; -import com.dfsek.terra.biome.provider.BiomeProvider; +import com.dfsek.terra.api.world.biome.UserDefinedBiome; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import net.jafama.FastMath; import java.util.Map; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/CheckFunction.java b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/CheckFunction.java index e82053b84..bc01fcd23 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/CheckFunction.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/CheckFunction.java @@ -12,8 +12,8 @@ import com.dfsek.terra.api.structures.parser.lang.variables.Variable; import com.dfsek.terra.api.structures.script.TerraImplementationArguments; import com.dfsek.terra.api.structures.structure.RotationUtil; import com.dfsek.terra.api.structures.tokenizer.Position; -import com.dfsek.terra.biome.UserDefinedBiome; -import com.dfsek.terra.biome.provider.BiomeProvider; +import com.dfsek.terra.api.world.biome.UserDefinedBiome; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.config.templates.BiomeTemplate; import com.dfsek.terra.world.TerraWorld; import com.dfsek.terra.world.generation.math.SamplerCache; diff --git a/common/src/main/java/com/dfsek/terra/util/hash/HashIntrinsic.java b/common/src/main/java/com/dfsek/terra/api/util/hash/HashIntrinsic.java similarity index 99% rename from common/src/main/java/com/dfsek/terra/util/hash/HashIntrinsic.java rename to common/src/main/java/com/dfsek/terra/api/util/hash/HashIntrinsic.java index 74166a7a8..638d8a66c 100644 --- a/common/src/main/java/com/dfsek/terra/util/hash/HashIntrinsic.java +++ b/common/src/main/java/com/dfsek/terra/api/util/hash/HashIntrinsic.java @@ -31,7 +31,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.dfsek.terra.util.hash; +package com.dfsek.terra.api.util.hash; import java.io.Serializable; diff --git a/common/src/main/java/com/dfsek/terra/util/hash/HashMapDoubleDouble.java b/common/src/main/java/com/dfsek/terra/api/util/hash/HashMapDoubleDouble.java similarity index 99% rename from common/src/main/java/com/dfsek/terra/util/hash/HashMapDoubleDouble.java rename to common/src/main/java/com/dfsek/terra/api/util/hash/HashMapDoubleDouble.java index 7ea6f735a..edad7aa32 100644 --- a/common/src/main/java/com/dfsek/terra/util/hash/HashMapDoubleDouble.java +++ b/common/src/main/java/com/dfsek/terra/api/util/hash/HashMapDoubleDouble.java @@ -31,7 +31,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package com.dfsek.terra.util.hash; +package com.dfsek.terra.api.util.hash; import java.io.Serializable; import java.util.NoSuchElementException; diff --git a/common/src/main/java/com/dfsek/terra/api/util/seeded/SourceSeeded.java b/common/src/main/java/com/dfsek/terra/api/util/seeded/SourceSeeded.java index e2a9e0e3c..c64e4d17e 100644 --- a/common/src/main/java/com/dfsek/terra/api/util/seeded/SourceSeeded.java +++ b/common/src/main/java/com/dfsek/terra/api/util/seeded/SourceSeeded.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.util.seeded; -import com.dfsek.terra.biome.pipeline.source.BiomeSource; +import com.dfsek.terra.api.world.biome.pipeline.source.BiomeSource; public interface SourceSeeded extends SeededBuilder { } diff --git a/common/src/main/java/com/dfsek/terra/api/util/seeded/StageSeeded.java b/common/src/main/java/com/dfsek/terra/api/util/seeded/StageSeeded.java index c9754c22f..093e54207 100644 --- a/common/src/main/java/com/dfsek/terra/api/util/seeded/StageSeeded.java +++ b/common/src/main/java/com/dfsek/terra/api/util/seeded/StageSeeded.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.util.seeded; -import com.dfsek.terra.biome.pipeline.stages.Stage; +import com.dfsek.terra.api.world.biome.pipeline.stages.Stage; public interface StageSeeded extends SeededBuilder { } diff --git a/common/src/main/java/com/dfsek/terra/util/MaterialSet.java b/common/src/main/java/com/dfsek/terra/api/util/world/MaterialSet.java similarity index 94% rename from common/src/main/java/com/dfsek/terra/util/MaterialSet.java rename to common/src/main/java/com/dfsek/terra/api/util/world/MaterialSet.java index 455051d97..0e43ea827 100644 --- a/common/src/main/java/com/dfsek/terra/util/MaterialSet.java +++ b/common/src/main/java/com/dfsek/terra/api/util/world/MaterialSet.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.util; +package com.dfsek.terra.api.util.world; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.MaterialData; diff --git a/common/src/main/java/com/dfsek/terra/util/PaletteUtil.java b/common/src/main/java/com/dfsek/terra/api/util/world/PaletteUtil.java similarity index 94% rename from common/src/main/java/com/dfsek/terra/util/PaletteUtil.java rename to common/src/main/java/com/dfsek/terra/api/util/world/PaletteUtil.java index 77478effd..92e81aa57 100644 --- a/common/src/main/java/com/dfsek/terra/util/PaletteUtil.java +++ b/common/src/main/java/com/dfsek/terra/api/util/world/PaletteUtil.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.util; +package com.dfsek.terra.api.util.world; import com.dfsek.terra.api.math.MathUtil; import com.dfsek.terra.api.platform.block.BlockData; diff --git a/common/src/main/java/com/dfsek/terra/util/PopulationUtil.java b/common/src/main/java/com/dfsek/terra/api/util/world/PopulationUtil.java similarity index 91% rename from common/src/main/java/com/dfsek/terra/util/PopulationUtil.java rename to common/src/main/java/com/dfsek/terra/api/util/world/PopulationUtil.java index b260ae451..a1805d437 100644 --- a/common/src/main/java/com/dfsek/terra/util/PopulationUtil.java +++ b/common/src/main/java/com/dfsek/terra/api/util/world/PopulationUtil.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.util; +package com.dfsek.terra.api.util.world; import com.dfsek.terra.api.math.MathUtil; import com.dfsek.terra.api.platform.world.Chunk; diff --git a/common/src/main/java/com/dfsek/terra/biome/TerraBiome.java b/common/src/main/java/com/dfsek/terra/api/world/biome/TerraBiome.java similarity index 89% rename from common/src/main/java/com/dfsek/terra/biome/TerraBiome.java rename to common/src/main/java/com/dfsek/terra/api/world/biome/TerraBiome.java index 7bcb917de..1dcd5fdc7 100644 --- a/common/src/main/java/com/dfsek/terra/biome/TerraBiome.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/TerraBiome.java @@ -1,10 +1,9 @@ -package com.dfsek.terra.biome; +package com.dfsek.terra.api.world.biome; import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.platform.world.Biome; import com.dfsek.terra.api.platform.world.World; -import com.dfsek.terra.api.world.biome.Generator; import java.util.Set; diff --git a/common/src/main/java/com/dfsek/terra/biome/UserDefinedBiome.java b/common/src/main/java/com/dfsek/terra/api/world/biome/UserDefinedBiome.java similarity index 95% rename from common/src/main/java/com/dfsek/terra/biome/UserDefinedBiome.java rename to common/src/main/java/com/dfsek/terra/api/world/biome/UserDefinedBiome.java index 99d768482..5f51ff5a7 100644 --- a/common/src/main/java/com/dfsek/terra/biome/UserDefinedBiome.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/UserDefinedBiome.java @@ -1,9 +1,8 @@ -package com.dfsek.terra.biome; +package com.dfsek.terra.api.world.biome; import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.platform.world.Biome; import com.dfsek.terra.api.platform.world.World; -import com.dfsek.terra.api.world.biome.Generator; import com.dfsek.terra.config.builder.GeneratorBuilder; import com.dfsek.terra.config.templates.BiomeTemplate; diff --git a/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/BiomeHolder.java b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/BiomeHolder.java new file mode 100644 index 000000000..46edff4c4 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/BiomeHolder.java @@ -0,0 +1,18 @@ +package com.dfsek.terra.api.world.biome.pipeline; + +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.pipeline.expand.BiomeExpander; +import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator; +import com.dfsek.terra.api.world.biome.pipeline.source.BiomeSource; + +public interface BiomeHolder { + BiomeHolder expand(BiomeExpander expander); + + void mutate(BiomeMutator mutator); + + void fill(BiomeSource source); + + TerraBiome getBiome(int x, int z); + + TerraBiome getBiomeRaw(int x, int z); +} diff --git a/common/src/main/java/com/dfsek/terra/biome/pipeline/BiomePipeline.java b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/BiomePipeline.java similarity index 91% rename from common/src/main/java/com/dfsek/terra/biome/pipeline/BiomePipeline.java rename to common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/BiomePipeline.java index a2bcb5df5..ed4211892 100644 --- a/common/src/main/java/com/dfsek/terra/biome/pipeline/BiomePipeline.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/BiomePipeline.java @@ -1,10 +1,10 @@ -package com.dfsek.terra.biome.pipeline; +package com.dfsek.terra.api.world.biome.pipeline; import com.dfsek.terra.api.math.vector.Vector2; import com.dfsek.terra.api.util.GlueList; import com.dfsek.terra.api.util.seeded.StageSeeded; -import com.dfsek.terra.biome.pipeline.source.BiomeSource; -import com.dfsek.terra.biome.pipeline.stages.Stage; +import com.dfsek.terra.api.world.biome.pipeline.source.BiomeSource; +import com.dfsek.terra.api.world.biome.pipeline.stages.Stage; import java.util.List; import java.util.stream.Collectors; diff --git a/common/src/main/java/com/dfsek/terra/biome/pipeline/TerraBiomeHolder.java b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/TerraBiomeHolder.java similarity index 89% rename from common/src/main/java/com/dfsek/terra/biome/pipeline/TerraBiomeHolder.java rename to common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/TerraBiomeHolder.java index 9a44a8935..df07577c0 100644 --- a/common/src/main/java/com/dfsek/terra/biome/pipeline/TerraBiomeHolder.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/TerraBiomeHolder.java @@ -1,10 +1,10 @@ -package com.dfsek.terra.biome.pipeline; +package com.dfsek.terra.api.world.biome.pipeline; import com.dfsek.terra.api.math.vector.Vector2; -import com.dfsek.terra.biome.TerraBiome; -import com.dfsek.terra.biome.pipeline.expand.BiomeExpander; -import com.dfsek.terra.biome.pipeline.mutator.BiomeMutator; -import com.dfsek.terra.biome.pipeline.source.BiomeSource; +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.pipeline.expand.BiomeExpander; +import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator; +import com.dfsek.terra.api.world.biome.pipeline.source.BiomeSource; public class TerraBiomeHolder implements BiomeHolder { private final Vector2 origin; diff --git a/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/expand/BiomeExpander.java b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/expand/BiomeExpander.java new file mode 100644 index 000000000..15082a0fe --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/expand/BiomeExpander.java @@ -0,0 +1,7 @@ +package com.dfsek.terra.api.world.biome.pipeline.expand; + +import com.dfsek.terra.api.world.biome.TerraBiome; + +public interface BiomeExpander { + TerraBiome getBetween(double x, double z, TerraBiome... others); +} diff --git a/common/src/main/java/com/dfsek/terra/biome/pipeline/expand/FractalExpander.java b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/expand/FractalExpander.java similarity index 81% rename from common/src/main/java/com/dfsek/terra/biome/pipeline/expand/FractalExpander.java rename to common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/expand/FractalExpander.java index bba7b7931..a7d44be84 100644 --- a/common/src/main/java/com/dfsek/terra/biome/pipeline/expand/FractalExpander.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/expand/FractalExpander.java @@ -1,8 +1,8 @@ -package com.dfsek.terra.biome.pipeline.expand; +package com.dfsek.terra.api.world.biome.pipeline.expand; import com.dfsek.terra.api.math.MathUtil; import com.dfsek.terra.api.math.noise.NoiseSampler; -import com.dfsek.terra.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.TerraBiome; public class FractalExpander implements BiomeExpander { private final NoiseSampler sampler; diff --git a/common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/BiomeMutator.java b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/BiomeMutator.java similarity index 75% rename from common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/BiomeMutator.java rename to common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/BiomeMutator.java index 83cf9aa11..da70c3d9e 100644 --- a/common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/BiomeMutator.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/BiomeMutator.java @@ -1,7 +1,7 @@ -package com.dfsek.terra.biome.pipeline.mutator; +package com.dfsek.terra.api.world.biome.pipeline.mutator; -import com.dfsek.terra.biome.TerraBiome; -import com.dfsek.terra.biome.pipeline.BiomeHolder; +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.pipeline.BiomeHolder; public interface BiomeMutator { TerraBiome mutate(ViewPoint viewPoint, double x, double z); diff --git a/common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/BorderListMutator.java b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/BorderListMutator.java similarity index 94% rename from common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/BorderListMutator.java rename to common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/BorderListMutator.java index cc5fdac47..5fcfc2e1a 100644 --- a/common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/BorderListMutator.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/BorderListMutator.java @@ -1,8 +1,8 @@ -package com.dfsek.terra.biome.pipeline.mutator; +package com.dfsek.terra.api.world.biome.pipeline.mutator; import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.noise.NoiseSampler; -import com.dfsek.terra.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.TerraBiome; import java.util.Map; diff --git a/common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/BorderMutator.java b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/BorderMutator.java similarity index 92% rename from common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/BorderMutator.java rename to common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/BorderMutator.java index c5add13f0..15e7edcc9 100644 --- a/common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/BorderMutator.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/BorderMutator.java @@ -1,8 +1,8 @@ -package com.dfsek.terra.biome.pipeline.mutator; +package com.dfsek.terra.api.world.biome.pipeline.mutator; import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.noise.NoiseSampler; -import com.dfsek.terra.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.TerraBiome; public class BorderMutator implements BiomeMutator { private final String border; diff --git a/common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/ReplaceListMutator.java b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/ReplaceListMutator.java similarity index 92% rename from common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/ReplaceListMutator.java rename to common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/ReplaceListMutator.java index 9a4e8de1e..ebd3ec5f2 100644 --- a/common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/ReplaceListMutator.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/ReplaceListMutator.java @@ -1,8 +1,8 @@ -package com.dfsek.terra.biome.pipeline.mutator; +package com.dfsek.terra.api.world.biome.pipeline.mutator; import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.noise.NoiseSampler; -import com.dfsek.terra.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.TerraBiome; import java.util.Map; diff --git a/common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/ReplaceMutator.java b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/ReplaceMutator.java similarity index 88% rename from common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/ReplaceMutator.java rename to common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/ReplaceMutator.java index 8cad6a777..b37657654 100644 --- a/common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/ReplaceMutator.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/ReplaceMutator.java @@ -1,8 +1,8 @@ -package com.dfsek.terra.biome.pipeline.mutator; +package com.dfsek.terra.api.world.biome.pipeline.mutator; import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.noise.NoiseSampler; -import com.dfsek.terra.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.TerraBiome; public class ReplaceMutator implements BiomeMutator { private final String replaceableTag; diff --git a/common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/SmoothMutator.java b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/SmoothMutator.java similarity index 90% rename from common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/SmoothMutator.java rename to common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/SmoothMutator.java index 490f791d0..a3c679ea1 100644 --- a/common/src/main/java/com/dfsek/terra/biome/pipeline/mutator/SmoothMutator.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/SmoothMutator.java @@ -1,8 +1,8 @@ -package com.dfsek.terra.biome.pipeline.mutator; +package com.dfsek.terra.api.world.biome.pipeline.mutator; import com.dfsek.terra.api.math.MathUtil; import com.dfsek.terra.api.math.noise.NoiseSampler; -import com.dfsek.terra.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.TerraBiome; import java.util.Objects; diff --git a/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/source/BiomeSource.java b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/source/BiomeSource.java new file mode 100644 index 000000000..81ab9c858 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/source/BiomeSource.java @@ -0,0 +1,7 @@ +package com.dfsek.terra.api.world.biome.pipeline.source; + +import com.dfsek.terra.api.world.biome.TerraBiome; + +public interface BiomeSource { + TerraBiome getBiome(double x, double z); +} diff --git a/common/src/main/java/com/dfsek/terra/biome/pipeline/source/RandomSource.java b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/source/RandomSource.java similarity index 83% rename from common/src/main/java/com/dfsek/terra/biome/pipeline/source/RandomSource.java rename to common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/source/RandomSource.java index e1a487e32..fa7b9fe01 100644 --- a/common/src/main/java/com/dfsek/terra/biome/pipeline/source/RandomSource.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/source/RandomSource.java @@ -1,8 +1,8 @@ -package com.dfsek.terra.biome.pipeline.source; +package com.dfsek.terra.api.world.biome.pipeline.source; import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.noise.NoiseSampler; -import com.dfsek.terra.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.TerraBiome; public class RandomSource implements BiomeSource { private final ProbabilityCollection biomes; diff --git a/common/src/main/java/com/dfsek/terra/biome/pipeline/stages/ExpanderStage.java b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/stages/ExpanderStage.java similarity index 68% rename from common/src/main/java/com/dfsek/terra/biome/pipeline/stages/ExpanderStage.java rename to common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/stages/ExpanderStage.java index b8f26bf6c..fc0555e19 100644 --- a/common/src/main/java/com/dfsek/terra/biome/pipeline/stages/ExpanderStage.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/stages/ExpanderStage.java @@ -1,7 +1,7 @@ -package com.dfsek.terra.biome.pipeline.stages; +package com.dfsek.terra.api.world.biome.pipeline.stages; -import com.dfsek.terra.biome.pipeline.BiomeHolder; -import com.dfsek.terra.biome.pipeline.expand.BiomeExpander; +import com.dfsek.terra.api.world.biome.pipeline.BiomeHolder; +import com.dfsek.terra.api.world.biome.pipeline.expand.BiomeExpander; public class ExpanderStage implements Stage { private final BiomeExpander expander; diff --git a/common/src/main/java/com/dfsek/terra/biome/pipeline/stages/MutatorStage.java b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/stages/MutatorStage.java similarity index 70% rename from common/src/main/java/com/dfsek/terra/biome/pipeline/stages/MutatorStage.java rename to common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/stages/MutatorStage.java index dab5b5f12..a9b060fd1 100644 --- a/common/src/main/java/com/dfsek/terra/biome/pipeline/stages/MutatorStage.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/stages/MutatorStage.java @@ -1,7 +1,7 @@ -package com.dfsek.terra.biome.pipeline.stages; +package com.dfsek.terra.api.world.biome.pipeline.stages; -import com.dfsek.terra.biome.pipeline.BiomeHolder; -import com.dfsek.terra.biome.pipeline.mutator.BiomeMutator; +import com.dfsek.terra.api.world.biome.pipeline.BiomeHolder; +import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator; public class MutatorStage implements Stage { private final BiomeMutator mutator; diff --git a/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/stages/Stage.java b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/stages/Stage.java new file mode 100644 index 000000000..a179da2eb --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/stages/Stage.java @@ -0,0 +1,10 @@ +package com.dfsek.terra.api.world.biome.pipeline.stages; + +import com.dfsek.terra.api.world.biome.pipeline.BiomeHolder; + +public interface Stage { + boolean isExpansion(); + + BiomeHolder apply(BiomeHolder in); + +} diff --git a/common/src/main/java/com/dfsek/terra/biome/provider/BiomeProvider.java b/common/src/main/java/com/dfsek/terra/api/world/biome/provider/BiomeProvider.java similarity index 87% rename from common/src/main/java/com/dfsek/terra/biome/provider/BiomeProvider.java rename to common/src/main/java/com/dfsek/terra/api/world/biome/provider/BiomeProvider.java index 9041edd85..c1f664314 100644 --- a/common/src/main/java/com/dfsek/terra/biome/provider/BiomeProvider.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/provider/BiomeProvider.java @@ -1,9 +1,9 @@ -package com.dfsek.terra.biome.provider; +package com.dfsek.terra.api.world.biome.provider; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.math.vector.Vector2; import com.dfsek.terra.api.math.vector.Vector3; -import com.dfsek.terra.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.TerraBiome; public interface BiomeProvider { TerraBiome getBiome(int x, int z); diff --git a/common/src/main/java/com/dfsek/terra/biome/provider/ImageBiomeProvider.java b/common/src/main/java/com/dfsek/terra/api/world/biome/provider/ImageBiomeProvider.java similarity index 95% rename from common/src/main/java/com/dfsek/terra/biome/provider/ImageBiomeProvider.java rename to common/src/main/java/com/dfsek/terra/api/world/biome/provider/ImageBiomeProvider.java index 2f2a6467e..5225d1432 100644 --- a/common/src/main/java/com/dfsek/terra/biome/provider/ImageBiomeProvider.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/provider/ImageBiomeProvider.java @@ -1,6 +1,6 @@ -package com.dfsek.terra.biome.provider; +package com.dfsek.terra.api.world.biome.provider; -import com.dfsek.terra.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.registry.TerraRegistry; import net.jafama.FastMath; diff --git a/common/src/main/java/com/dfsek/terra/biome/provider/SingleBiomeProvider.java b/common/src/main/java/com/dfsek/terra/api/world/biome/provider/SingleBiomeProvider.java similarity index 79% rename from common/src/main/java/com/dfsek/terra/biome/provider/SingleBiomeProvider.java rename to common/src/main/java/com/dfsek/terra/api/world/biome/provider/SingleBiomeProvider.java index 1119788f6..6dc103cd6 100644 --- a/common/src/main/java/com/dfsek/terra/biome/provider/SingleBiomeProvider.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/provider/SingleBiomeProvider.java @@ -1,6 +1,6 @@ -package com.dfsek.terra.biome.provider; +package com.dfsek.terra.api.world.biome.provider; -import com.dfsek.terra.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.TerraBiome; public class SingleBiomeProvider implements BiomeProvider, BiomeProvider.BiomeProviderBuilder { private final TerraBiome biome; diff --git a/common/src/main/java/com/dfsek/terra/biome/provider/StandardBiomeProvider.java b/common/src/main/java/com/dfsek/terra/api/world/biome/provider/StandardBiomeProvider.java similarity index 90% rename from common/src/main/java/com/dfsek/terra/biome/provider/StandardBiomeProvider.java rename to common/src/main/java/com/dfsek/terra/api/world/biome/provider/StandardBiomeProvider.java index f54c3c287..e53bd4749 100644 --- a/common/src/main/java/com/dfsek/terra/biome/provider/StandardBiomeProvider.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/provider/StandardBiomeProvider.java @@ -1,11 +1,11 @@ -package com.dfsek.terra.biome.provider; +package com.dfsek.terra.api.world.biome.provider; import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.math.noise.NoiseSampler; import com.dfsek.terra.api.math.vector.Vector2; -import com.dfsek.terra.biome.TerraBiome; -import com.dfsek.terra.biome.pipeline.BiomeHolder; -import com.dfsek.terra.biome.pipeline.BiomePipeline; +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.pipeline.BiomeHolder; +import com.dfsek.terra.api.world.biome.pipeline.BiomePipeline; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/FractalTree.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/FractalTree.java index 639fd7774..869ed9183 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/FractalTree.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/FractalTree.java @@ -5,7 +5,7 @@ import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.entity.Entity; import com.dfsek.terra.api.platform.entity.EntityType; -import com.dfsek.terra.util.MaterialSet; +import com.dfsek.terra.api.util.world.MaterialSet; import java.util.Random; import java.util.function.Consumer; diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/Cactus.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/Cactus.java index d3b5fd463..359d59f1d 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/Cactus.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/Cactus.java @@ -3,8 +3,8 @@ package com.dfsek.terra.api.world.tree.fractal.trees; import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.BlockData; +import com.dfsek.terra.api.util.world.MaterialSet; import com.dfsek.terra.api.world.tree.fractal.FractalTree; -import com.dfsek.terra.util.MaterialSet; import java.util.Random; diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/IceSpike.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/IceSpike.java index 5dbe76690..abbeb0f2b 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/IceSpike.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/IceSpike.java @@ -6,9 +6,9 @@ import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.handle.WorldHandle; +import com.dfsek.terra.api.util.world.MaterialSet; import com.dfsek.terra.api.world.tree.fractal.FractalTree; import com.dfsek.terra.api.world.tree.fractal.TreeGeometry; -import com.dfsek.terra.util.MaterialSet; import java.util.Random; diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/OakTree.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/OakTree.java index de8ad123b..a5502ee6a 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/OakTree.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/OakTree.java @@ -4,9 +4,9 @@ import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockData; +import com.dfsek.terra.api.util.world.MaterialSet; import com.dfsek.terra.api.world.tree.fractal.FractalTree; import com.dfsek.terra.api.world.tree.fractal.TreeGeometry; -import com.dfsek.terra.util.MaterialSet; import net.jafama.FastMath; import java.util.Random; diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredPillar.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredPillar.java index ed66b3d68..0bb915cd5 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredPillar.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredPillar.java @@ -3,8 +3,8 @@ package com.dfsek.terra.api.world.tree.fractal.trees; import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.BlockData; +import com.dfsek.terra.api.util.world.MaterialSet; import com.dfsek.terra.api.world.tree.fractal.FractalTree; -import com.dfsek.terra.util.MaterialSet; import java.util.Random; diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredTree.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredTree.java index 0841d5e2f..2175df3c1 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredTree.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredTree.java @@ -6,9 +6,9 @@ import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.handle.WorldHandle; +import com.dfsek.terra.api.util.world.MaterialSet; import com.dfsek.terra.api.world.tree.fractal.FractalTree; import com.dfsek.terra.api.world.tree.fractal.TreeGeometry; -import com.dfsek.terra.util.MaterialSet; import net.jafama.FastMath; import java.util.Random; diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredPillar.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredPillar.java index a06634e6d..a73c5dce9 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredPillar.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredPillar.java @@ -3,8 +3,8 @@ package com.dfsek.terra.api.world.tree.fractal.trees; import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.BlockData; +import com.dfsek.terra.api.util.world.MaterialSet; import com.dfsek.terra.api.world.tree.fractal.FractalTree; -import com.dfsek.terra.util.MaterialSet; import java.util.Random; diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredTree.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredTree.java index c5094c61a..ce9fa2abf 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredTree.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredTree.java @@ -6,9 +6,9 @@ import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.handle.WorldHandle; +import com.dfsek.terra.api.util.world.MaterialSet; import com.dfsek.terra.api.world.tree.fractal.FractalTree; import com.dfsek.terra.api.world.tree.fractal.TreeGeometry; -import com.dfsek.terra.util.MaterialSet; import net.jafama.FastMath; import java.util.Random; diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SpruceTree.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SpruceTree.java index 327c52706..eb51add0c 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SpruceTree.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SpruceTree.java @@ -4,9 +4,9 @@ import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockData; +import com.dfsek.terra.api.util.world.MaterialSet; import com.dfsek.terra.api.world.tree.fractal.FractalTree; import com.dfsek.terra.api.world.tree.fractal.TreeGeometry; -import com.dfsek.terra.util.MaterialSet; import net.jafama.FastMath; import java.util.Random; diff --git a/common/src/main/java/com/dfsek/terra/async/AsyncBiomeFinder.java b/common/src/main/java/com/dfsek/terra/async/AsyncBiomeFinder.java index 3fd723abb..38b6662a3 100644 --- a/common/src/main/java/com/dfsek/terra/async/AsyncBiomeFinder.java +++ b/common/src/main/java/com/dfsek/terra/async/AsyncBiomeFinder.java @@ -3,8 +3,8 @@ package com.dfsek.terra.async; import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.math.vector.Vector3; -import com.dfsek.terra.biome.TerraBiome; -import com.dfsek.terra.biome.provider.BiomeProvider; +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import org.jetbrains.annotations.NotNull; import java.util.function.Consumer; diff --git a/common/src/main/java/com/dfsek/terra/async/AsyncFeatureFinder.java b/common/src/main/java/com/dfsek/terra/async/AsyncFeatureFinder.java index 69869a861..b44afc711 100644 --- a/common/src/main/java/com/dfsek/terra/async/AsyncFeatureFinder.java +++ b/common/src/main/java/com/dfsek/terra/async/AsyncFeatureFinder.java @@ -4,7 +4,7 @@ import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.world.World; -import com.dfsek.terra.biome.provider.BiomeProvider; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import org.jetbrains.annotations.NotNull; import java.util.function.Consumer; diff --git a/common/src/main/java/com/dfsek/terra/async/AsyncStructureFinder.java b/common/src/main/java/com/dfsek/terra/async/AsyncStructureFinder.java index 89aa90344..4680da9fd 100644 --- a/common/src/main/java/com/dfsek/terra/async/AsyncStructureFinder.java +++ b/common/src/main/java/com/dfsek/terra/async/AsyncStructureFinder.java @@ -6,8 +6,8 @@ import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.structures.structure.Rotation; import com.dfsek.terra.api.util.FastRandom; -import com.dfsek.terra.biome.UserDefinedBiome; -import com.dfsek.terra.biome.provider.BiomeProvider; +import com.dfsek.terra.api.world.biome.UserDefinedBiome; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.world.population.items.TerraStructure; import net.jafama.FastMath; import org.jetbrains.annotations.NotNull; diff --git a/common/src/main/java/com/dfsek/terra/biome/pipeline/BiomeHolder.java b/common/src/main/java/com/dfsek/terra/biome/pipeline/BiomeHolder.java deleted file mode 100644 index 7e2fb6bfb..000000000 --- a/common/src/main/java/com/dfsek/terra/biome/pipeline/BiomeHolder.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.dfsek.terra.biome.pipeline; - -import com.dfsek.terra.biome.TerraBiome; -import com.dfsek.terra.biome.pipeline.expand.BiomeExpander; -import com.dfsek.terra.biome.pipeline.mutator.BiomeMutator; -import com.dfsek.terra.biome.pipeline.source.BiomeSource; - -public interface BiomeHolder { - BiomeHolder expand(BiomeExpander expander); - - void mutate(BiomeMutator mutator); - - void fill(BiomeSource source); - - TerraBiome getBiome(int x, int z); - - TerraBiome getBiomeRaw(int x, int z); -} diff --git a/common/src/main/java/com/dfsek/terra/biome/pipeline/expand/BiomeExpander.java b/common/src/main/java/com/dfsek/terra/biome/pipeline/expand/BiomeExpander.java deleted file mode 100644 index a3530ca70..000000000 --- a/common/src/main/java/com/dfsek/terra/biome/pipeline/expand/BiomeExpander.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.dfsek.terra.biome.pipeline.expand; - -import com.dfsek.terra.biome.TerraBiome; - -public interface BiomeExpander { - TerraBiome getBetween(double x, double z, TerraBiome... others); -} diff --git a/common/src/main/java/com/dfsek/terra/biome/pipeline/source/BiomeSource.java b/common/src/main/java/com/dfsek/terra/biome/pipeline/source/BiomeSource.java deleted file mode 100644 index 80b0961c6..000000000 --- a/common/src/main/java/com/dfsek/terra/biome/pipeline/source/BiomeSource.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.dfsek.terra.biome.pipeline.source; - -import com.dfsek.terra.biome.TerraBiome; - -public interface BiomeSource { - TerraBiome getBiome(double x, double z); -} diff --git a/common/src/main/java/com/dfsek/terra/biome/pipeline/stages/Stage.java b/common/src/main/java/com/dfsek/terra/biome/pipeline/stages/Stage.java deleted file mode 100644 index 531313363..000000000 --- a/common/src/main/java/com/dfsek/terra/biome/pipeline/stages/Stage.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.dfsek.terra.biome.pipeline.stages; - -import com.dfsek.terra.biome.pipeline.BiomeHolder; - -public interface Stage { - boolean isExpansion(); - - BiomeHolder apply(BiomeHolder in); - -} diff --git a/common/src/main/java/com/dfsek/terra/carving/CarverCache.java b/common/src/main/java/com/dfsek/terra/carving/CarverCache.java index 75a645aa0..fe379c53c 100644 --- a/common/src/main/java/com/dfsek/terra/carving/CarverCache.java +++ b/common/src/main/java/com/dfsek/terra/carving/CarverCache.java @@ -6,10 +6,10 @@ import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.util.FastRandom; import com.dfsek.terra.api.util.GlueList; +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.UserDefinedBiome; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.api.world.carving.Worm; -import com.dfsek.terra.biome.TerraBiome; -import com.dfsek.terra.biome.UserDefinedBiome; -import com.dfsek.terra.biome.provider.BiomeProvider; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; diff --git a/common/src/main/java/com/dfsek/terra/carving/CarverPalette.java b/common/src/main/java/com/dfsek/terra/carving/CarverPalette.java index 249c36957..937994d1d 100644 --- a/common/src/main/java/com/dfsek/terra/carving/CarverPalette.java +++ b/common/src/main/java/com/dfsek/terra/carving/CarverPalette.java @@ -3,7 +3,7 @@ package com.dfsek.terra.carving; import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.MaterialData; -import com.dfsek.terra.util.MaterialSet; +import com.dfsek.terra.api.util.world.MaterialSet; import java.util.Map; import java.util.TreeMap; diff --git a/common/src/main/java/com/dfsek/terra/carving/UserDefinedCarver.java b/common/src/main/java/com/dfsek/terra/carving/UserDefinedCarver.java index 4c9a9a80a..e5fd230ab 100644 --- a/common/src/main/java/com/dfsek/terra/carving/UserDefinedCarver.java +++ b/common/src/main/java/com/dfsek/terra/carving/UserDefinedCarver.java @@ -13,9 +13,9 @@ import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.util.FastRandom; import com.dfsek.terra.api.util.seeded.NoiseSeeded; +import com.dfsek.terra.api.world.biome.UserDefinedBiome; import com.dfsek.terra.api.world.carving.Carver; import com.dfsek.terra.api.world.carving.Worm; -import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.config.loaders.config.function.FunctionTemplate; import com.dfsek.terra.config.templates.BiomeTemplate; import com.dfsek.terra.config.templates.CarverTemplate; diff --git a/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java b/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java index 52cdf965c..20549a829 100644 --- a/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java +++ b/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java @@ -10,12 +10,13 @@ import com.dfsek.terra.api.math.noise.samplers.ImageSampler; import com.dfsek.terra.api.math.noise.samplers.noise.CellularSampler; import com.dfsek.terra.api.util.seeded.SourceSeeded; import com.dfsek.terra.api.util.seeded.StageSeeded; +import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.world.biome.pipeline.stages.ExpanderStage; +import com.dfsek.terra.api.world.biome.pipeline.stages.MutatorStage; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; +import com.dfsek.terra.api.world.biome.provider.ImageBiomeProvider; import com.dfsek.terra.api.world.palette.holder.PaletteHolder; import com.dfsek.terra.api.world.palette.holder.PaletteLayerHolder; -import com.dfsek.terra.biome.pipeline.stages.ExpanderStage; -import com.dfsek.terra.biome.pipeline.stages.MutatorStage; -import com.dfsek.terra.biome.provider.BiomeProvider; -import com.dfsek.terra.biome.provider.ImageBiomeProvider; import com.dfsek.terra.carving.CarverPalette; import com.dfsek.terra.config.loaders.LinkedHashMapLoader; import com.dfsek.terra.config.loaders.MaterialSetLoader; @@ -44,7 +45,6 @@ import com.dfsek.terra.config.loaders.config.sampler.templates.normalizer.Normal import com.dfsek.terra.config.loaders.palette.CarverPaletteLoader; import com.dfsek.terra.config.loaders.palette.PaletteHolderLoader; import com.dfsek.terra.config.loaders.palette.PaletteLayerLoader; -import com.dfsek.terra.util.MaterialSet; import com.dfsek.terra.world.population.items.flora.FloraLayer; import com.dfsek.terra.world.population.items.flora.TerraFlora; import com.dfsek.terra.world.population.items.ores.Ore; diff --git a/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java b/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java index b4f09aa8c..f3e987b93 100644 --- a/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java +++ b/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java @@ -2,8 +2,8 @@ package com.dfsek.terra.config.factories; import com.dfsek.paralithic.eval.parser.Scope; import com.dfsek.terra.api.core.TerraPlugin; -import com.dfsek.terra.biome.TerraBiome; -import com.dfsek.terra.biome.UserDefinedBiome; +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.UserDefinedBiome; import com.dfsek.terra.config.builder.GeneratorBuilder; import com.dfsek.terra.config.loaders.config.function.FunctionTemplate; import com.dfsek.terra.config.pack.ConfigPack; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/MaterialSetLoader.java b/common/src/main/java/com/dfsek/terra/config/loaders/MaterialSetLoader.java index c06333917..4001a8589 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/MaterialSetLoader.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/MaterialSetLoader.java @@ -4,7 +4,7 @@ import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; import com.dfsek.tectonic.loading.TypeLoader; import com.dfsek.terra.api.platform.block.MaterialData; -import com.dfsek.terra.util.MaterialSet; +import com.dfsek.terra.api.util.world.MaterialSet; import java.lang.reflect.Type; import java.util.List; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/Types.java b/common/src/main/java/com/dfsek/terra/config/loaders/Types.java index bb58ce950..206c6226a 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/Types.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/Types.java @@ -3,10 +3,10 @@ package com.dfsek.terra.config.loaders; import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.flora.Flora; import com.dfsek.terra.api.world.palette.Palette; import com.dfsek.terra.api.world.tree.Tree; -import com.dfsek.terra.biome.TerraBiome; import java.lang.reflect.Type; import java.util.Map; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/BiomeProviderBuilderLoader.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/BiomeProviderBuilderLoader.java index d7f4d045f..1e45c5536 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/BiomeProviderBuilderLoader.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/BiomeProviderBuilderLoader.java @@ -3,7 +3,7 @@ package com.dfsek.terra.config.loaders.config.biome; import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; import com.dfsek.tectonic.loading.TypeLoader; -import com.dfsek.terra.biome.provider.BiomeProvider; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.config.loaders.config.biome.templates.source.BiomePipelineTemplate; import com.dfsek.terra.config.loaders.config.biome.templates.source.ImageProviderTemplate; import com.dfsek.terra.config.loaders.config.biome.templates.source.SingleBiomeProviderTemplate; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/SourceBuilderLoader.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/SourceBuilderLoader.java index 03a8d5527..a7d2d61ed 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/SourceBuilderLoader.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/SourceBuilderLoader.java @@ -6,8 +6,8 @@ import com.dfsek.tectonic.loading.TypeLoader; import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.util.seeded.NoiseSeeded; import com.dfsek.terra.api.util.seeded.SourceSeeded; -import com.dfsek.terra.biome.TerraBiome; -import com.dfsek.terra.biome.pipeline.source.RandomSource; +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.pipeline.source.RandomSource; import com.dfsek.terra.config.loaders.Types; import java.lang.reflect.Type; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/StageBuilderLoader.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/StageBuilderLoader.java index f173c1364..58c464fde 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/StageBuilderLoader.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/StageBuilderLoader.java @@ -4,8 +4,8 @@ import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; import com.dfsek.tectonic.loading.TypeLoader; import com.dfsek.terra.api.util.seeded.StageSeeded; -import com.dfsek.terra.biome.pipeline.stages.ExpanderStage; -import com.dfsek.terra.biome.pipeline.stages.MutatorStage; +import com.dfsek.terra.api.world.biome.pipeline.stages.ExpanderStage; +import com.dfsek.terra.api.world.biome.pipeline.stages.MutatorStage; import com.dfsek.terra.config.loaders.config.biome.templates.stage.expander.ExpanderStageTemplate; import com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator.BorderListMutatorTemplate; import com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator.BorderMutatorTemplate; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/BiomePipelineTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/BiomePipelineTemplate.java index 46d810866..0e3195efb 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/BiomePipelineTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/BiomePipelineTemplate.java @@ -5,9 +5,9 @@ import com.dfsek.tectonic.annotations.Value; import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.util.seeded.SourceSeeded; import com.dfsek.terra.api.util.seeded.StageSeeded; -import com.dfsek.terra.biome.pipeline.BiomePipeline; -import com.dfsek.terra.biome.provider.BiomeProvider; -import com.dfsek.terra.biome.provider.StandardBiomeProvider; +import com.dfsek.terra.api.world.biome.pipeline.BiomePipeline; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; +import com.dfsek.terra.api.world.biome.provider.StandardBiomeProvider; import com.dfsek.terra.registry.config.BiomeRegistry; import java.util.List; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/BiomeProviderTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/BiomeProviderTemplate.java index b0a65d85e..89b6d2b6c 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/BiomeProviderTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/BiomeProviderTemplate.java @@ -6,7 +6,7 @@ import com.dfsek.tectonic.loading.object.ObjectTemplate; import com.dfsek.terra.api.math.noise.NoiseSampler; import com.dfsek.terra.api.math.noise.samplers.noise.ConstantSampler; import com.dfsek.terra.api.util.seeded.NoiseSeeded; -import com.dfsek.terra.biome.provider.BiomeProvider; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.registry.config.BiomeRegistry; public abstract class BiomeProviderTemplate implements ObjectTemplate, BiomeProvider.BiomeProviderBuilder { diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/ImageProviderTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/ImageProviderTemplate.java index e92379d7e..d9668b2ca 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/ImageProviderTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/ImageProviderTemplate.java @@ -1,8 +1,8 @@ package com.dfsek.terra.config.loaders.config.biome.templates.source; import com.dfsek.tectonic.annotations.Value; -import com.dfsek.terra.biome.provider.BiomeProvider; -import com.dfsek.terra.biome.provider.ImageBiomeProvider; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; +import com.dfsek.terra.api.world.biome.provider.ImageBiomeProvider; import com.dfsek.terra.registry.config.BiomeRegistry; import java.awt.image.BufferedImage; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/SingleBiomeProviderTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/SingleBiomeProviderTemplate.java index 811656cd4..4c7aa3279 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/SingleBiomeProviderTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/SingleBiomeProviderTemplate.java @@ -1,9 +1,9 @@ package com.dfsek.terra.config.loaders.config.biome.templates.source; import com.dfsek.tectonic.annotations.Value; -import com.dfsek.terra.biome.TerraBiome; -import com.dfsek.terra.biome.provider.BiomeProvider; -import com.dfsek.terra.biome.provider.SingleBiomeProvider; +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; +import com.dfsek.terra.api.world.biome.provider.SingleBiomeProvider; import com.dfsek.terra.registry.config.BiomeRegistry; public class SingleBiomeProviderTemplate extends BiomeProviderTemplate { diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/StageTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/StageTemplate.java index 041185648..151eaedef 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/StageTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/StageTemplate.java @@ -5,7 +5,7 @@ import com.dfsek.tectonic.loading.object.ObjectTemplate; import com.dfsek.terra.api.util.seeded.NoiseSeeded; import com.dfsek.terra.api.util.seeded.SeededBuilder; import com.dfsek.terra.api.util.seeded.StageSeeded; -import com.dfsek.terra.biome.pipeline.stages.Stage; +import com.dfsek.terra.api.world.biome.pipeline.stages.Stage; public abstract class StageTemplate implements ObjectTemplate>, StageSeeded { @Value("noise") diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/expander/ExpanderStageTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/expander/ExpanderStageTemplate.java index 0d25cdbc0..fb396ddbc 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/expander/ExpanderStageTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/expander/ExpanderStageTemplate.java @@ -1,8 +1,8 @@ package com.dfsek.terra.config.loaders.config.biome.templates.stage.expander; -import com.dfsek.terra.biome.pipeline.expand.FractalExpander; -import com.dfsek.terra.biome.pipeline.stages.ExpanderStage; -import com.dfsek.terra.biome.pipeline.stages.Stage; +import com.dfsek.terra.api.world.biome.pipeline.expand.FractalExpander; +import com.dfsek.terra.api.world.biome.pipeline.stages.ExpanderStage; +import com.dfsek.terra.api.world.biome.pipeline.stages.Stage; import com.dfsek.terra.config.loaders.config.biome.templates.stage.StageTemplate; public class ExpanderStageTemplate extends StageTemplate { diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java index 3a10d7b47..b7eb95219 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java @@ -2,9 +2,9 @@ package com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator; import com.dfsek.tectonic.annotations.Value; import com.dfsek.terra.api.math.ProbabilityCollection; -import com.dfsek.terra.biome.TerraBiome; -import com.dfsek.terra.biome.pipeline.mutator.BiomeMutator; -import com.dfsek.terra.biome.pipeline.mutator.BorderListMutator; +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator; +import com.dfsek.terra.api.world.biome.pipeline.mutator.BorderListMutator; import java.util.Map; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderMutatorTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderMutatorTemplate.java index 094c68dd6..6b06e8bcf 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderMutatorTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderMutatorTemplate.java @@ -2,9 +2,9 @@ package com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator; import com.dfsek.tectonic.annotations.Value; import com.dfsek.terra.api.math.ProbabilityCollection; -import com.dfsek.terra.biome.TerraBiome; -import com.dfsek.terra.biome.pipeline.mutator.BiomeMutator; -import com.dfsek.terra.biome.pipeline.mutator.BorderMutator; +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator; +import com.dfsek.terra.api.world.biome.pipeline.mutator.BorderMutator; @SuppressWarnings("unused") public class BorderMutatorTemplate extends MutatorStageTemplate { diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/MutatorStageTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/MutatorStageTemplate.java index 47ea30afd..84283ffcc 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/MutatorStageTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/MutatorStageTemplate.java @@ -1,8 +1,8 @@ package com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator; -import com.dfsek.terra.biome.pipeline.mutator.BiomeMutator; -import com.dfsek.terra.biome.pipeline.stages.MutatorStage; -import com.dfsek.terra.biome.pipeline.stages.Stage; +import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator; +import com.dfsek.terra.api.world.biome.pipeline.stages.MutatorStage; +import com.dfsek.terra.api.world.biome.pipeline.stages.Stage; import com.dfsek.terra.config.loaders.config.biome.templates.stage.StageTemplate; public abstract class MutatorStageTemplate extends StageTemplate { diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceListMutatorTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceListMutatorTemplate.java index 9ac41f078..52bfdf946 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceListMutatorTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceListMutatorTemplate.java @@ -2,9 +2,9 @@ package com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator; import com.dfsek.tectonic.annotations.Value; import com.dfsek.terra.api.math.ProbabilityCollection; -import com.dfsek.terra.biome.TerraBiome; -import com.dfsek.terra.biome.pipeline.mutator.BiomeMutator; -import com.dfsek.terra.biome.pipeline.mutator.ReplaceListMutator; +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator; +import com.dfsek.terra.api.world.biome.pipeline.mutator.ReplaceListMutator; import java.util.Map; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceMutatorTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceMutatorTemplate.java index 9239d4ddd..379b08137 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceMutatorTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceMutatorTemplate.java @@ -2,9 +2,9 @@ package com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator; import com.dfsek.tectonic.annotations.Value; import com.dfsek.terra.api.math.ProbabilityCollection; -import com.dfsek.terra.biome.TerraBiome; -import com.dfsek.terra.biome.pipeline.mutator.BiomeMutator; -import com.dfsek.terra.biome.pipeline.mutator.ReplaceMutator; +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator; +import com.dfsek.terra.api.world.biome.pipeline.mutator.ReplaceMutator; @SuppressWarnings("unused") public class ReplaceMutatorTemplate extends MutatorStageTemplate { diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/SmoothMutatorTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/SmoothMutatorTemplate.java index c01d2dbd1..a5c27c54a 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/SmoothMutatorTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/SmoothMutatorTemplate.java @@ -1,7 +1,7 @@ package com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator; -import com.dfsek.terra.biome.pipeline.mutator.BiomeMutator; -import com.dfsek.terra.biome.pipeline.mutator.SmoothMutator; +import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator; +import com.dfsek.terra.api.world.biome.pipeline.mutator.SmoothMutator; public class SmoothMutatorTemplate extends MutatorStageTemplate { @Override diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/palette/CarverPaletteLoader.java b/common/src/main/java/com/dfsek/terra/config/loaders/palette/CarverPaletteLoader.java index ed5bd12fb..26f12725e 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/palette/CarverPaletteLoader.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/palette/CarverPaletteLoader.java @@ -6,9 +6,9 @@ import com.dfsek.tectonic.loading.ConfigLoader; import com.dfsek.tectonic.loading.TypeLoader; import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.platform.block.BlockData; +import com.dfsek.terra.api.util.world.MaterialSet; import com.dfsek.terra.carving.CarverPalette; import com.dfsek.terra.config.loaders.Types; -import com.dfsek.terra.util.MaterialSet; import java.lang.reflect.Type; import java.util.List; diff --git a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java index d426c6748..7f36e01b6 100644 --- a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java +++ b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java @@ -13,11 +13,11 @@ import com.dfsek.terra.api.core.event.events.config.ConfigPackPreLoadEvent; import com.dfsek.terra.api.structures.loot.LootTable; import com.dfsek.terra.api.structures.script.StructureScript; import com.dfsek.terra.api.util.seeded.NoiseSeeded; +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.api.world.flora.Flora; import com.dfsek.terra.api.world.palette.Palette; import com.dfsek.terra.api.world.tree.Tree; -import com.dfsek.terra.biome.TerraBiome; -import com.dfsek.terra.biome.provider.BiomeProvider; import com.dfsek.terra.carving.UserDefinedCarver; import com.dfsek.terra.config.exception.FileMissingException; import com.dfsek.terra.config.factories.BiomeFactory; diff --git a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPackPostTemplate.java b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPackPostTemplate.java index 985740a1a..dd24def46 100644 --- a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPackPostTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPackPostTemplate.java @@ -2,7 +2,7 @@ package com.dfsek.terra.config.pack; import com.dfsek.tectonic.annotations.Value; import com.dfsek.tectonic.config.ConfigTemplate; -import com.dfsek.terra.biome.provider.BiomeProvider; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; public class ConfigPackPostTemplate implements ConfigTemplate { @Value("biomes") diff --git a/common/src/main/java/com/dfsek/terra/config/templates/CarverTemplate.java b/common/src/main/java/com/dfsek/terra/config/templates/CarverTemplate.java index 4f9bf1b12..b196852a1 100644 --- a/common/src/main/java/com/dfsek/terra/config/templates/CarverTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/templates/CarverTemplate.java @@ -5,8 +5,8 @@ import com.dfsek.tectonic.annotations.Default; import com.dfsek.tectonic.annotations.Value; import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.util.world.MaterialSet; import com.dfsek.terra.carving.CarverPalette; -import com.dfsek.terra.util.MaterialSet; import java.util.HashMap; import java.util.Map; diff --git a/common/src/main/java/com/dfsek/terra/config/templates/FloraTemplate.java b/common/src/main/java/com/dfsek/terra/config/templates/FloraTemplate.java index 4ca624764..3b676bee8 100644 --- a/common/src/main/java/com/dfsek/terra/config/templates/FloraTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/templates/FloraTemplate.java @@ -3,8 +3,8 @@ package com.dfsek.terra.config.templates; import com.dfsek.tectonic.annotations.Abstractable; import com.dfsek.tectonic.annotations.Default; import com.dfsek.tectonic.annotations.Value; +import com.dfsek.terra.api.util.world.MaterialSet; import com.dfsek.terra.api.world.palette.holder.PaletteLayerHolder; -import com.dfsek.terra.util.MaterialSet; import com.dfsek.terra.world.population.items.flora.TerraFlora; import java.util.List; diff --git a/common/src/main/java/com/dfsek/terra/config/templates/OreTemplate.java b/common/src/main/java/com/dfsek/terra/config/templates/OreTemplate.java index 9311baedf..7e56bab83 100644 --- a/common/src/main/java/com/dfsek/terra/config/templates/OreTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/templates/OreTemplate.java @@ -5,7 +5,7 @@ import com.dfsek.tectonic.annotations.Default; import com.dfsek.tectonic.annotations.Value; import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.util.MaterialSet; +import com.dfsek.terra.api.util.world.MaterialSet; import com.dfsek.terra.world.population.items.ores.Ore; @SuppressWarnings({"unused", "FieldMayBeFinal"}) diff --git a/common/src/main/java/com/dfsek/terra/config/templates/TreeTemplate.java b/common/src/main/java/com/dfsek/terra/config/templates/TreeTemplate.java index 33702c5a4..07db47a1c 100644 --- a/common/src/main/java/com/dfsek/terra/config/templates/TreeTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/templates/TreeTemplate.java @@ -5,7 +5,7 @@ import com.dfsek.tectonic.annotations.Default; import com.dfsek.tectonic.annotations.Value; import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.structures.script.StructureScript; -import com.dfsek.terra.util.MaterialSet; +import com.dfsek.terra.api.util.world.MaterialSet; @SuppressWarnings({"unused", "FieldMayBeFinal"}) public class TreeTemplate extends AbstractableTemplate { diff --git a/common/src/main/java/com/dfsek/terra/registry/AddonRegistry.java b/common/src/main/java/com/dfsek/terra/registry/AddonRegistry.java new file mode 100644 index 000000000..4cbb26636 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/registry/AddonRegistry.java @@ -0,0 +1,56 @@ +package com.dfsek.terra.registry; + +import com.dfsek.terra.addons.addon.TerraAddon; +import com.dfsek.terra.addons.loading.AddonClassLoader; +import com.dfsek.terra.addons.loading.AddonLoadException; +import com.dfsek.terra.api.core.TerraPlugin; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.Set; + +public class AddonRegistry extends TerraRegistry { + public boolean loadAll(TerraPlugin main) { + boolean valid = true; + File addonsFolder = new File(main.getDataFolder(), "addons"); + addonsFolder.mkdirs(); + for(File jar : addonsFolder.listFiles(file -> file.getName().endsWith(".jar"))) { + try { + main.getLogger().info("Loading Addon(s) from: " + jar.getName()); + load(jar, main); + } catch(IOException | AddonLoadException e) { + e.printStackTrace(); + valid = false; + } + } + return valid; + } + + public void load(File file, TerraPlugin main) throws AddonLoadException, IOException { + Set> addonClasses = AddonClassLoader.fetchAddonClasses(file); + + for(Class addonClass : addonClasses) { + Constructor constructor; + try { + constructor = addonClass.getConstructor(); + } catch(NoSuchMethodException e) { + throw new AddonLoadException("Addon class has no valid constructor: " + addonClass.getCanonicalName(), e); + } + TerraAddon addon; + try { + addon = constructor.newInstance(); + } catch(InstantiationException | IllegalAccessException | InvocationTargetException e) { + throw new AddonLoadException("Failed to instantiate addon: " + addonClass.getCanonicalName(), e); + } + try { + addChecked(addon.getName(), addon); + } catch(IllegalArgumentException e) { + throw new AddonLoadException("Duplicate addon ID; addon with ID " + addon.getName() + " is already loaded."); + } + main.getLogger().info("Loaded addon " + addon.getName() + " v" + addon.getVersion() + ", by " + addon.getAuthor()); + addon.initialize(); + } + } +} diff --git a/common/src/main/java/com/dfsek/terra/registry/ConfigRegistry.java b/common/src/main/java/com/dfsek/terra/registry/ConfigRegistry.java index 4f2dd1dd9..8532cf535 100644 --- a/common/src/main/java/com/dfsek/terra/registry/ConfigRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/ConfigRegistry.java @@ -29,7 +29,7 @@ public class ConfigRegistry extends TerraRegistry { valid = false; } } - for(File zip : packsFolder.listFiles(file -> file.getName().endsWith(".zip") || file.getName().endsWith(".jar") || file.getName().endsWith(".com.dfsek.terra"))) { + for(File zip : packsFolder.listFiles(file -> file.getName().endsWith(".zip") || file.getName().endsWith(".terra"))) { try { main.getDebugLogger().info("Loading ZIP archive: " + zip.getName()); load(new ZipFile(zip), main); diff --git a/common/src/main/java/com/dfsek/terra/registry/TerraRegistry.java b/common/src/main/java/com/dfsek/terra/registry/TerraRegistry.java index 5b25ca67d..71d9026b0 100644 --- a/common/src/main/java/com/dfsek/terra/registry/TerraRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/TerraRegistry.java @@ -36,6 +36,11 @@ public abstract class TerraRegistry implements TypeLoader { return exists; } + public void addChecked(String name, T value) { + if(objects.containsKey(name)) throw new IllegalArgumentException("Value is already defined in registry."); + objects.put(name, value); + } + /** * Check if the registry contains an object. * diff --git a/common/src/main/java/com/dfsek/terra/registry/config/BiomeRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/BiomeRegistry.java index 06aad4412..42a093961 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/BiomeRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/BiomeRegistry.java @@ -2,7 +2,7 @@ package com.dfsek.terra.registry.config; import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; -import com.dfsek.terra.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.registry.TerraRegistry; import java.lang.reflect.Type; diff --git a/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java index e62f88b08..147e56a26 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java @@ -3,9 +3,9 @@ package com.dfsek.terra.registry.config; import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.util.world.MaterialSet; import com.dfsek.terra.api.world.flora.Flora; import com.dfsek.terra.registry.TerraRegistry; -import com.dfsek.terra.util.MaterialSet; import com.dfsek.terra.world.population.items.flora.ConstantFlora; import java.util.Arrays; diff --git a/common/src/main/java/com/dfsek/terra/world/TerraWorld.java b/common/src/main/java/com/dfsek/terra/world/TerraWorld.java index e9442141a..6a607008d 100644 --- a/common/src/main/java/com/dfsek/terra/world/TerraWorld.java +++ b/common/src/main/java/com/dfsek/terra/world/TerraWorld.java @@ -7,9 +7,9 @@ import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper; +import com.dfsek.terra.api.world.biome.UserDefinedBiome; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.api.world.palette.Palette; -import com.dfsek.terra.biome.UserDefinedBiome; -import com.dfsek.terra.biome.provider.BiomeProvider; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.profiler.WorldProfiler; import com.dfsek.terra.world.generation.math.Sampler; diff --git a/common/src/main/java/com/dfsek/terra/world/generation/MasterChunkGenerator.java b/common/src/main/java/com/dfsek/terra/world/generation/MasterChunkGenerator.java index 4f74ccdb4..e51131e7c 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/MasterChunkGenerator.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/MasterChunkGenerator.java @@ -13,16 +13,16 @@ import com.dfsek.terra.api.platform.block.data.Waterlogged; import com.dfsek.terra.api.platform.world.BiomeGrid; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.platform.world.generator.ChunkGenerator; +import com.dfsek.terra.api.util.world.PaletteUtil; +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.UserDefinedBiome; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.api.world.generation.TerraChunkGenerator; import com.dfsek.terra.api.world.palette.Palette; import com.dfsek.terra.api.world.palette.SinglePalette; -import com.dfsek.terra.biome.TerraBiome; -import com.dfsek.terra.biome.UserDefinedBiome; -import com.dfsek.terra.biome.provider.BiomeProvider; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.config.templates.BiomeTemplate; import com.dfsek.terra.profiler.ProfileFuture; -import com.dfsek.terra.util.PaletteUtil; import com.dfsek.terra.world.Carver; import com.dfsek.terra.world.TerraWorld; import com.dfsek.terra.world.carving.NoiseCarver; diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/Sampler.java b/common/src/main/java/com/dfsek/terra/world/generation/math/Sampler.java index 41de6b12d..2f2beb585 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/math/Sampler.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/Sampler.java @@ -1,7 +1,7 @@ package com.dfsek.terra.world.generation.math; import com.dfsek.terra.api.platform.world.World; -import com.dfsek.terra.biome.provider.BiomeProvider; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.world.generation.math.interpolation.BiomeChunkInterpolator; import com.dfsek.terra.world.generation.math.interpolation.ElevationInterpolator; import net.jafama.FastMath; diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/BiomeChunkInterpolator.java b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/BiomeChunkInterpolator.java index fdb8fe31d..2561d9311 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/BiomeChunkInterpolator.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/BiomeChunkInterpolator.java @@ -4,7 +4,7 @@ import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.util.mutable.MutableInteger; import com.dfsek.terra.api.world.biome.Generator; -import com.dfsek.terra.biome.provider.BiomeProvider; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import net.jafama.FastMath; import java.util.HashMap; diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ElevationInterpolator.java b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ElevationInterpolator.java index 5e2d05910..330cafdc8 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ElevationInterpolator.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ElevationInterpolator.java @@ -2,7 +2,7 @@ package com.dfsek.terra.world.generation.math.interpolation; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.world.biome.Generator; -import com.dfsek.terra.biome.provider.BiomeProvider; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.world.generation.WorldGenerator; public class ElevationInterpolator { diff --git a/common/src/main/java/com/dfsek/terra/population/CavePopulator.java b/common/src/main/java/com/dfsek/terra/world/population/CavePopulator.java similarity index 98% rename from common/src/main/java/com/dfsek/terra/population/CavePopulator.java rename to common/src/main/java/com/dfsek/terra/world/population/CavePopulator.java index 720918abe..929d41626 100644 --- a/common/src/main/java/com/dfsek/terra/population/CavePopulator.java +++ b/common/src/main/java/com/dfsek/terra/world/population/CavePopulator.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.population; +package com.dfsek.terra.world.population; import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; @@ -8,12 +8,12 @@ import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.platform.world.World; +import com.dfsek.terra.api.util.world.PopulationUtil; import com.dfsek.terra.api.world.generation.TerraBlockPopulator; import com.dfsek.terra.carving.UserDefinedCarver; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.config.templates.CarverTemplate; import com.dfsek.terra.profiler.ProfileFuture; -import com.dfsek.terra.util.PopulationUtil; import com.dfsek.terra.world.TerraWorld; import org.jetbrains.annotations.NotNull; diff --git a/common/src/main/java/com/dfsek/terra/world/population/FloraPopulator.java b/common/src/main/java/com/dfsek/terra/world/population/FloraPopulator.java index c1318f92b..4aeca61c2 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/FloraPopulator.java +++ b/common/src/main/java/com/dfsek/terra/world/population/FloraPopulator.java @@ -4,11 +4,11 @@ import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.math.vector.Vector2; import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.platform.world.World; +import com.dfsek.terra.api.util.world.PopulationUtil; +import com.dfsek.terra.api.world.biome.UserDefinedBiome; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.api.world.generation.TerraBlockPopulator; -import com.dfsek.terra.biome.UserDefinedBiome; -import com.dfsek.terra.biome.provider.BiomeProvider; import com.dfsek.terra.profiler.ProfileFuture; -import com.dfsek.terra.util.PopulationUtil; import com.dfsek.terra.world.TerraWorld; import com.dfsek.terra.world.population.items.flora.FloraLayer; import org.jetbrains.annotations.NotNull; diff --git a/common/src/main/java/com/dfsek/terra/world/population/OrePopulator.java b/common/src/main/java/com/dfsek/terra/world/population/OrePopulator.java index f4a60e2fc..1fdc5c961 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/OrePopulator.java +++ b/common/src/main/java/com/dfsek/terra/world/population/OrePopulator.java @@ -6,9 +6,9 @@ import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.util.FastRandom; +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.UserDefinedBiome; import com.dfsek.terra.api.world.generation.TerraBlockPopulator; -import com.dfsek.terra.biome.TerraBiome; -import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.config.templates.BiomeTemplate; import com.dfsek.terra.profiler.ProfileFuture; import com.dfsek.terra.world.TerraWorld; diff --git a/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java b/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java index a266de3dd..d19fc1fa0 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java +++ b/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java @@ -7,9 +7,9 @@ import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.structures.structure.Rotation; import com.dfsek.terra.api.util.FastRandom; +import com.dfsek.terra.api.world.biome.UserDefinedBiome; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.api.world.generation.TerraBlockPopulator; -import com.dfsek.terra.biome.UserDefinedBiome; -import com.dfsek.terra.biome.provider.BiomeProvider; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.profiler.ProfileFuture; import com.dfsek.terra.world.TerraWorld; diff --git a/common/src/main/java/com/dfsek/terra/world/population/TreePopulator.java b/common/src/main/java/com/dfsek/terra/world/population/TreePopulator.java index c88476971..1b14c80bd 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/TreePopulator.java +++ b/common/src/main/java/com/dfsek/terra/world/population/TreePopulator.java @@ -4,11 +4,11 @@ import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.math.vector.Vector2; import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.platform.world.World; +import com.dfsek.terra.api.util.world.PopulationUtil; +import com.dfsek.terra.api.world.biome.UserDefinedBiome; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.api.world.generation.TerraBlockPopulator; -import com.dfsek.terra.biome.UserDefinedBiome; -import com.dfsek.terra.biome.provider.BiomeProvider; import com.dfsek.terra.profiler.ProfileFuture; -import com.dfsek.terra.util.PopulationUtil; import com.dfsek.terra.world.TerraWorld; import com.dfsek.terra.world.population.items.tree.TreeLayer; import net.jafama.FastMath; diff --git a/common/src/main/java/com/dfsek/terra/world/population/items/flora/ConstantFlora.java b/common/src/main/java/com/dfsek/terra/world/population/items/flora/ConstantFlora.java index 45669bc36..0559f61dd 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/items/flora/ConstantFlora.java +++ b/common/src/main/java/com/dfsek/terra/world/population/items/flora/ConstantFlora.java @@ -7,8 +7,8 @@ import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.BlockFace; import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.util.GlueList; +import com.dfsek.terra.api.util.world.MaterialSet; import com.dfsek.terra.api.world.flora.Flora; -import com.dfsek.terra.util.MaterialSet; import java.util.List; diff --git a/common/src/main/java/com/dfsek/terra/world/population/items/flora/TerraFlora.java b/common/src/main/java/com/dfsek/terra/world/population/items/flora/TerraFlora.java index 4bb60eae1..c542e06b4 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/items/flora/TerraFlora.java +++ b/common/src/main/java/com/dfsek/terra/world/population/items/flora/TerraFlora.java @@ -13,9 +13,9 @@ import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.util.FastRandom; import com.dfsek.terra.api.util.GlueList; +import com.dfsek.terra.api.util.world.MaterialSet; import com.dfsek.terra.api.world.flora.Flora; import com.dfsek.terra.api.world.palette.Palette; -import com.dfsek.terra.util.MaterialSet; import net.jafama.FastMath; import java.util.ArrayList; diff --git a/common/src/main/java/com/dfsek/terra/world/population/items/ores/DeformedSphereOre.java b/common/src/main/java/com/dfsek/terra/world/population/items/ores/DeformedSphereOre.java index 4396f8028..22c6bb193 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/items/ores/DeformedSphereOre.java +++ b/common/src/main/java/com/dfsek/terra/world/population/items/ores/DeformedSphereOre.java @@ -8,7 +8,7 @@ import com.dfsek.terra.api.platform.block.Block; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.api.platform.world.Chunk; -import com.dfsek.terra.util.MaterialSet; +import com.dfsek.terra.api.util.world.MaterialSet; import java.util.Random; diff --git a/common/src/main/java/com/dfsek/terra/world/population/items/ores/Ore.java b/common/src/main/java/com/dfsek/terra/world/population/items/ores/Ore.java index 231b625a9..1115ce3c7 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/items/ores/Ore.java +++ b/common/src/main/java/com/dfsek/terra/world/population/items/ores/Ore.java @@ -4,7 +4,7 @@ import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.world.Chunk; -import com.dfsek.terra.util.MaterialSet; +import com.dfsek.terra.api.util.world.MaterialSet; import java.util.Random; diff --git a/common/src/main/java/com/dfsek/terra/world/population/items/ores/VanillaOre.java b/common/src/main/java/com/dfsek/terra/world/population/items/ores/VanillaOre.java index 5c19f5246..a1b9b3b65 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/items/ores/VanillaOre.java +++ b/common/src/main/java/com/dfsek/terra/world/population/items/ores/VanillaOre.java @@ -7,7 +7,7 @@ import com.dfsek.terra.api.platform.block.Block; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.api.platform.world.Chunk; -import com.dfsek.terra.util.MaterialSet; +import com.dfsek.terra.api.util.world.MaterialSet; import net.jafama.FastMath; import java.util.Random; diff --git a/common/src/main/java/com/dfsek/terra/world/population/items/tree/TerraTree.java b/common/src/main/java/com/dfsek/terra/world/population/items/tree/TerraTree.java index 7b24a9eb4..a0abe79aa 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/items/tree/TerraTree.java +++ b/common/src/main/java/com/dfsek/terra/world/population/items/tree/TerraTree.java @@ -4,8 +4,8 @@ import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.structures.script.StructureScript; import com.dfsek.terra.api.structures.structure.Rotation; +import com.dfsek.terra.api.util.world.MaterialSet; import com.dfsek.terra.api.world.tree.Tree; -import com.dfsek.terra.util.MaterialSet; import java.util.Random; diff --git a/common/src/main/java/com/dfsek/terra/world/population/items/tree/TreeLayer.java b/common/src/main/java/com/dfsek/terra/world/population/items/tree/TreeLayer.java index 461b633be..71bb5b077 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/items/tree/TreeLayer.java +++ b/common/src/main/java/com/dfsek/terra/world/population/items/tree/TreeLayer.java @@ -7,8 +7,8 @@ import com.dfsek.terra.api.math.vector.Vector2; import com.dfsek.terra.api.platform.block.Block; import com.dfsek.terra.api.platform.block.BlockFace; import com.dfsek.terra.api.platform.world.Chunk; +import com.dfsek.terra.api.util.world.PopulationUtil; import com.dfsek.terra.api.world.tree.Tree; -import com.dfsek.terra.util.PopulationUtil; import com.dfsek.terra.world.population.items.PlaceableLayer; public class TreeLayer extends PlaceableLayer { diff --git a/common/src/test/java/biome/DistributionTest.java b/common/src/test/java/biome/DistributionTest.java index 6ffe4da82..464c93a33 100644 --- a/common/src/test/java/biome/DistributionTest.java +++ b/common/src/test/java/biome/DistributionTest.java @@ -18,8 +18,8 @@ import com.dfsek.terra.api.platform.world.Biome; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.util.seeded.NoiseSeeded; import com.dfsek.terra.api.world.biome.Generator; -import com.dfsek.terra.biome.TerraBiome; -import com.dfsek.terra.biome.provider.BiomeProvider; +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.config.GenericLoaders; import com.dfsek.terra.config.PluginConfig; import com.dfsek.terra.config.fileloaders.FolderLoader; @@ -34,6 +34,7 @@ import com.dfsek.terra.config.loaders.config.sampler.NoiseSamplerBuilderLoader; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.config.templates.AbstractableTemplate; import com.dfsek.terra.debug.DebugLogger; +import com.dfsek.terra.registry.AddonRegistry; import com.dfsek.terra.registry.ConfigRegistry; import com.dfsek.terra.registry.config.BiomeRegistry; import com.dfsek.terra.registry.config.NoiseRegistry; @@ -102,6 +103,11 @@ public class DistributionTest { return null; } + @Override + public AddonRegistry getAddons() { + return null; + } + @Override public void reload() { diff --git a/common/src/test/java/biome/ImageTest.java b/common/src/test/java/biome/ImageTest.java index 916a68c00..bf6a9460f 100644 --- a/common/src/test/java/biome/ImageTest.java +++ b/common/src/test/java/biome/ImageTest.java @@ -11,9 +11,9 @@ import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.platform.world.Biome; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.world.biome.Generator; -import com.dfsek.terra.biome.TerraBiome; -import com.dfsek.terra.biome.provider.BiomeProvider; -import com.dfsek.terra.biome.provider.ImageBiomeProvider; +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; +import com.dfsek.terra.api.world.biome.provider.ImageBiomeProvider; import com.dfsek.terra.config.fileloaders.FolderLoader; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.config.templates.AbstractableTemplate; diff --git a/common/src/test/java/event/EventTest.java b/common/src/test/java/event/EventTest.java index 00f16f1ad..49299dc1a 100644 --- a/common/src/test/java/event/EventTest.java +++ b/common/src/test/java/event/EventTest.java @@ -2,17 +2,18 @@ package event; import com.dfsek.tectonic.loading.TypeRegistry; import com.dfsek.terra.api.core.TerraPlugin; -import com.dfsek.terra.api.core.event.annotations.Priority; -import com.dfsek.terra.api.core.event.events.Event; import com.dfsek.terra.api.core.event.EventListener; import com.dfsek.terra.api.core.event.EventManager; import com.dfsek.terra.api.core.event.TerraEventManager; +import com.dfsek.terra.api.core.event.annotations.Priority; +import com.dfsek.terra.api.core.event.events.Event; import com.dfsek.terra.api.platform.handle.ItemHandle; import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.config.PluginConfig; import com.dfsek.terra.config.lang.Language; import com.dfsek.terra.debug.DebugLogger; +import com.dfsek.terra.registry.AddonRegistry; import com.dfsek.terra.registry.ConfigRegistry; import com.dfsek.terra.world.TerraWorld; import org.junit.jupiter.api.Test; @@ -70,6 +71,11 @@ public class EventTest { return null; } + @Override + public AddonRegistry getAddons() { + return null; + } + @Override public void reload() { diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java index 5e2a75f4a..02c7af250 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java @@ -27,6 +27,7 @@ import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.Language; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.debug.DebugLogger; +import com.dfsek.terra.registry.AddonRegistry; import com.dfsek.terra.registry.ConfigRegistry; import com.dfsek.terra.world.TerraWorld; import com.dfsek.terra.world.generation.MasterChunkGenerator; @@ -55,6 +56,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { private WorldHandle handle = new BukkitWorldHandle(); private final GenericLoaders genericLoaders = new GenericLoaders(this); private DebugLogger debugLogger; + private final AddonRegistry addonRegistry = new AddonRegistry(); private final EventManager eventManager = new TerraEventManager(this); @@ -136,6 +138,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { LangUtil.load(config.getLanguage(), this); // Load language. debugLogger.setDebug(isDebug()); + addonRegistry.loadAll(this); registry.loadAll(this); // Load all config packs. PluginCommand c = Objects.requireNonNull(getCommand("terra")); @@ -245,6 +248,11 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { genericLoaders.register(registry); } + @Override + public AddonRegistry getAddons() { + return addonRegistry; + } + public enum Version { V1_13(13), diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeCommand.java index 254550157..216897347 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeCommand.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeCommand.java @@ -1,7 +1,7 @@ package com.dfsek.terra.bukkit.command.command.biome; -import com.dfsek.terra.biome.UserDefinedBiome; -import com.dfsek.terra.biome.provider.BiomeProvider; +import com.dfsek.terra.api.world.biome.UserDefinedBiome; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.bukkit.command.WorldCommand; import com.dfsek.terra.bukkit.world.BukkitAdapter; import com.dfsek.terra.config.lang.LangUtil; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeInfoCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeInfoCommand.java index 636907691..c3faf300c 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeInfoCommand.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeInfoCommand.java @@ -1,6 +1,6 @@ package com.dfsek.terra.bukkit.command.command.biome; -import com.dfsek.terra.biome.UserDefinedBiome; +import com.dfsek.terra.api.world.biome.UserDefinedBiome; import com.dfsek.terra.bukkit.BukkitCommandSender; import com.dfsek.terra.bukkit.command.WorldCommand; import com.dfsek.terra.bukkit.world.BukkitAdapter; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeLocateCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeLocateCommand.java index 17d1abf59..07b07e451 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeLocateCommand.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeLocateCommand.java @@ -1,8 +1,8 @@ package com.dfsek.terra.bukkit.command.command.biome; import com.dfsek.terra.api.math.vector.Vector3; +import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.async.AsyncBiomeFinder; -import com.dfsek.terra.biome.TerraBiome; import com.dfsek.terra.bukkit.TerraBukkitPlugin; import com.dfsek.terra.bukkit.command.WorldCommand; import com.dfsek.terra.bukkit.world.BukkitAdapter; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/load/LoadFullCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/load/LoadFullCommand.java index 0bbf7969a..33ab614a6 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/load/LoadFullCommand.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/load/LoadFullCommand.java @@ -4,10 +4,10 @@ import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.structures.script.StructureScript; import com.dfsek.terra.api.structures.structure.Rotation; import com.dfsek.terra.api.util.FastRandom; +import com.dfsek.terra.api.util.world.PopulationUtil; import com.dfsek.terra.bukkit.command.DebugCommand; import com.dfsek.terra.bukkit.world.BukkitAdapter; import com.dfsek.terra.bukkit.world.BukkitChunk; -import com.dfsek.terra.util.PopulationUtil; import com.dfsek.terra.world.TerraWorld; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java index b8bb83839..81e305834 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java @@ -9,10 +9,10 @@ import com.dfsek.terra.bukkit.population.PopulationManager; import com.dfsek.terra.bukkit.world.BukkitAdapter; import com.dfsek.terra.bukkit.world.BukkitBiomeGrid; import com.dfsek.terra.config.lang.LangUtil; -import com.dfsek.terra.population.CavePopulator; import com.dfsek.terra.profiler.DataType; import com.dfsek.terra.profiler.Measurement; import com.dfsek.terra.world.TerraWorld; +import com.dfsek.terra.world.population.CavePopulator; import com.dfsek.terra.world.population.FloraPopulator; import com.dfsek.terra.world.population.OrePopulator; import com.dfsek.terra.world.population.StructurePopulator; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitTree.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitTree.java index db12c9c18..ecf87d1e9 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitTree.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitTree.java @@ -4,8 +4,8 @@ import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.platform.handle.WorldHandle; +import com.dfsek.terra.api.util.world.MaterialSet; import com.dfsek.terra.api.world.tree.Tree; -import com.dfsek.terra.util.MaterialSet; import org.bukkit.TreeType; import java.util.Random; diff --git a/src/main/resources/lang/da.yml b/platforms/bukkit/src/main/resources/lang/da.yml similarity index 100% rename from src/main/resources/lang/da.yml rename to platforms/bukkit/src/main/resources/lang/da.yml diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index 822902e40..0f768541e 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -12,7 +12,7 @@ import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.transform.MapTransform; import com.dfsek.terra.api.transform.NotNullValidator; import com.dfsek.terra.api.transform.Transformer; -import com.dfsek.terra.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.config.GenericLoaders; import com.dfsek.terra.config.PluginConfig; import com.dfsek.terra.config.lang.LangUtil; @@ -26,6 +26,7 @@ import com.dfsek.terra.fabric.world.FabricWorldHandle; import com.dfsek.terra.fabric.world.TerraBiomeSource; import com.dfsek.terra.fabric.world.features.PopulatorFeature; import com.dfsek.terra.fabric.world.generator.FabricChunkGeneratorWrapper; +import com.dfsek.terra.registry.AddonRegistry; import com.dfsek.terra.registry.ConfigRegistry; import com.dfsek.terra.world.TerraWorld; import net.fabricmc.api.EnvType; @@ -85,6 +86,8 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { private final ItemHandle itemHandle = new FabricItemHandle(); private final WorldHandle worldHandle = new FabricWorldHandle(); private final ConfigRegistry registry = new ConfigRegistry(); + + private final AddonRegistry addonRegistry = new AddonRegistry(); private File config; private static final Transformer> TREE_TRANSFORMER = new Transformer.Builder>() .addTransform(TerraFabricPlugin::getFeature) @@ -162,6 +165,11 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { return registry; } + @Override + public AddonRegistry getAddons() { + return addonRegistry; + } + @Override public void reload() { diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricTree.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricTree.java index 603202480..b5bbabccc 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricTree.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricTree.java @@ -2,11 +2,11 @@ package com.dfsek.terra.fabric.world; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.util.world.MaterialSet; import com.dfsek.terra.api.world.tree.Tree; import com.dfsek.terra.fabric.TerraFabricPlugin; import com.dfsek.terra.fabric.world.generator.FabricChunkGenerator; import com.dfsek.terra.fabric.world.handles.world.FabricWorldAccess; -import com.dfsek.terra.util.MaterialSet; import net.minecraft.util.math.BlockPos; import net.minecraft.world.StructureWorldAccess; import net.minecraft.world.gen.chunk.ChunkGenerator; diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/TerraBiomeSource.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/TerraBiomeSource.java index 8cc0dee3d..f73c0f16d 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/TerraBiomeSource.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/TerraBiomeSource.java @@ -1,7 +1,7 @@ package com.dfsek.terra.fabric.world; -import com.dfsek.terra.biome.UserDefinedBiome; -import com.dfsek.terra.biome.provider.BiomeProvider; +import com.dfsek.terra.api.world.biome.UserDefinedBiome; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.fabric.TerraFabricPlugin; import com.mojang.serialization.Codec; diff --git a/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java b/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java index c933025c0..93b46810e 100644 --- a/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java +++ b/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java @@ -17,6 +17,7 @@ import com.dfsek.terra.config.lang.Language; import com.dfsek.terra.debug.DebugLogger; import com.dfsek.terra.platform.RawBiome; import com.dfsek.terra.platform.RawWorldHandle; +import com.dfsek.terra.registry.AddonRegistry; import com.dfsek.terra.registry.ConfigRegistry; import com.dfsek.terra.world.TerraWorld; @@ -26,6 +27,7 @@ import java.util.logging.Logger; public class StandalonePlugin implements TerraPlugin { private final ConfigRegistry registry = new ConfigRegistry(); + private final AddonRegistry addonRegistry = new AddonRegistry(); private final PluginConfig config = new PluginConfig(); private final RawWorldHandle worldHandle = new RawWorldHandle(); private final EventManager eventManager = new TerraEventManager(this); @@ -79,6 +81,11 @@ public class StandalonePlugin implements TerraPlugin { return registry; } + @Override + public AddonRegistry getAddons() { + return addonRegistry; + } + @Override public void reload() { throw new UnsupportedOperationException(); From 76f2a3fbc49b418897312f81f7a399f830285f98 Mon Sep 17 00:00:00 2001 From: dfsek Date: Fri, 19 Feb 2021 22:49:11 -0700 Subject: [PATCH 02/95] fleshed out addon loading --- .../addons/annotations/inject/Inject.java | 11 -- .../terra/api/core/event/EventManager.java | 3 +- .../api/core/event/TerraEventManager.java | 22 ++- .../api/core/event/annotations/Global.java | 7 + .../api/core/event/events/PackEvent.java | 8 + .../events/config/ConfigPackLoadEvent.java | 5 +- .../events/world/TerraWorldLoadEvent.java | 10 +- .../dfsek/terra/config/GenericLoaders.java | 2 + .../terra/config/pack/ConfigPackTemplate.java | 10 ++ .../dfsek/terra/registry/AddonRegistry.java | 108 ++++++++---- .../dfsek/terra/registry/TerraRegistry.java | 2 +- common/src/test/java/event/EventTest.java | 156 ------------------ platforms/bukkit/build.gradle.kts | 2 +- .../dfsek/terra/bukkit/TerraBukkitPlugin.java | 49 ++++-- .../bukkit/command/command/AddonsCommand.java | 41 +++++ .../bukkit/command/command/TerraCommand.java | 3 +- .../terra/bukkit/listeners/TerraListener.java | 2 + .../world/block/data/BukkitBlockData.java | 2 +- .../dfsek/terra/fabric/TerraFabricPlugin.java | 2 +- .../com/dfsek/terra/StandalonePlugin.java | 2 +- 20 files changed, 217 insertions(+), 230 deletions(-) delete mode 100644 common/src/main/java/com/dfsek/terra/addons/annotations/inject/Inject.java create mode 100644 common/src/main/java/com/dfsek/terra/api/core/event/events/PackEvent.java delete mode 100644 common/src/test/java/event/EventTest.java create mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/AddonsCommand.java diff --git a/common/src/main/java/com/dfsek/terra/addons/annotations/inject/Inject.java b/common/src/main/java/com/dfsek/terra/addons/annotations/inject/Inject.java deleted file mode 100644 index 83552f4cc..000000000 --- a/common/src/main/java/com/dfsek/terra/addons/annotations/inject/Inject.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.dfsek.terra.addons.annotations.inject; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface Inject { -} diff --git a/common/src/main/java/com/dfsek/terra/api/core/event/EventManager.java b/common/src/main/java/com/dfsek/terra/api/core/event/EventManager.java index 9f3e7e993..f61f27d06 100644 --- a/common/src/main/java/com/dfsek/terra/api/core/event/EventManager.java +++ b/common/src/main/java/com/dfsek/terra/api/core/event/EventManager.java @@ -1,5 +1,6 @@ package com.dfsek.terra.api.core.event; +import com.dfsek.terra.addons.addon.TerraAddon; import com.dfsek.terra.api.core.event.events.Event; public interface EventManager { @@ -10,5 +11,5 @@ public interface EventManager { */ boolean callEvent(Event event); - void registerListener(EventListener listener); + void registerListener(TerraAddon addon, EventListener listener); } diff --git a/common/src/main/java/com/dfsek/terra/api/core/event/TerraEventManager.java b/common/src/main/java/com/dfsek/terra/api/core/event/TerraEventManager.java index 2bb14ebd6..aafa3f118 100644 --- a/common/src/main/java/com/dfsek/terra/api/core/event/TerraEventManager.java +++ b/common/src/main/java/com/dfsek/terra/api/core/event/TerraEventManager.java @@ -1,9 +1,12 @@ package com.dfsek.terra.api.core.event; +import com.dfsek.terra.addons.addon.TerraAddon; import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.core.event.annotations.Global; import com.dfsek.terra.api.core.event.annotations.Priority; import com.dfsek.terra.api.core.event.events.Cancellable; import com.dfsek.terra.api.core.event.events.Event; +import com.dfsek.terra.api.core.event.events.PackEvent; import com.dfsek.terra.api.util.ReflectionUtil; import java.io.PrintWriter; @@ -29,7 +32,14 @@ public class TerraEventManager implements EventManager { public boolean callEvent(Event event) { listeners.getOrDefault(event.getClass(), Collections.emptyList()).forEach(listenerHolder -> { try { - listenerHolder.method.invoke(listenerHolder.listener, event); + if(event instanceof PackEvent && !listenerHolder.global) { + PackEvent packEvent = (PackEvent) event; + if(packEvent.getPack().getTemplate().getAddons().contains(listenerHolder.addon)) { + listenerHolder.method.invoke(listenerHolder.listener, event); + } + } else { + listenerHolder.method.invoke(listenerHolder.listener, event); + } } catch(InvocationTargetException e) { StringWriter writer = new StringWriter(); e.getTargetException().printStackTrace(new PrintWriter(writer)); @@ -51,7 +61,7 @@ public class TerraEventManager implements EventManager { @SuppressWarnings("unchecked") @Override - public void registerListener(EventListener listener) { + public void registerListener(TerraAddon addon, EventListener listener) { Class listenerClass = listener.getClass(); Method[] methods = ReflectionUtil.getMethods(listenerClass); @@ -68,7 +78,7 @@ public class TerraEventManager implements EventManager { List holders = listeners.computeIfAbsent((Class) eventParam, e -> new ArrayList<>()); - holders.add(new ListenerHolder(method, listener, priority)); + holders.add(new ListenerHolder(method, listener, priority, addon, method.getAnnotation(Global.class) != null)); holders.sort(Comparator.comparingInt(ListenerHolder::getPriority)); // Sort priorities. } @@ -78,11 +88,15 @@ public class TerraEventManager implements EventManager { private final Method method; private final EventListener listener; private final int priority; + private final TerraAddon addon; + private final boolean global; - private ListenerHolder(Method method, EventListener listener, int priority) { + private ListenerHolder(Method method, EventListener listener, int priority, TerraAddon addon, boolean global) { this.method = method; this.listener = listener; this.priority = priority; + this.addon = addon; + this.global = global; } public int getPriority() { diff --git a/common/src/main/java/com/dfsek/terra/api/core/event/annotations/Global.java b/common/src/main/java/com/dfsek/terra/api/core/event/annotations/Global.java index afb523515..345033e46 100644 --- a/common/src/main/java/com/dfsek/terra/api/core/event/annotations/Global.java +++ b/common/src/main/java/com/dfsek/terra/api/core/event/annotations/Global.java @@ -1,7 +1,14 @@ package com.dfsek.terra.api.core.event.annotations; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + /** * Specifies that an event handler is to handle all events. */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) public @interface Global { } diff --git a/common/src/main/java/com/dfsek/terra/api/core/event/events/PackEvent.java b/common/src/main/java/com/dfsek/terra/api/core/event/events/PackEvent.java new file mode 100644 index 000000000..ede861206 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/core/event/events/PackEvent.java @@ -0,0 +1,8 @@ +package com.dfsek.terra.api.core.event.events; + +import com.dfsek.terra.config.pack.ConfigPack; + +@SuppressWarnings("InterfaceMayBeAnnotatedFunctional") +public interface PackEvent extends Event { + ConfigPack getPack(); +} diff --git a/common/src/main/java/com/dfsek/terra/api/core/event/events/config/ConfigPackLoadEvent.java b/common/src/main/java/com/dfsek/terra/api/core/event/events/config/ConfigPackLoadEvent.java index a69eba172..b1a301ed3 100644 --- a/common/src/main/java/com/dfsek/terra/api/core/event/events/config/ConfigPackLoadEvent.java +++ b/common/src/main/java/com/dfsek/terra/api/core/event/events/config/ConfigPackLoadEvent.java @@ -1,15 +1,16 @@ package com.dfsek.terra.api.core.event.events.config; -import com.dfsek.terra.api.core.event.events.Event; +import com.dfsek.terra.api.core.event.events.PackEvent; import com.dfsek.terra.config.pack.ConfigPack; -public abstract class ConfigPackLoadEvent implements Event { +public abstract class ConfigPackLoadEvent implements PackEvent { private final ConfigPack pack; public ConfigPackLoadEvent(ConfigPack pack) { this.pack = pack; } + @Override public ConfigPack getPack() { return pack; } diff --git a/common/src/main/java/com/dfsek/terra/api/core/event/events/world/TerraWorldLoadEvent.java b/common/src/main/java/com/dfsek/terra/api/core/event/events/world/TerraWorldLoadEvent.java index e68d174c3..ec8501316 100644 --- a/common/src/main/java/com/dfsek/terra/api/core/event/events/world/TerraWorldLoadEvent.java +++ b/common/src/main/java/com/dfsek/terra/api/core/event/events/world/TerraWorldLoadEvent.java @@ -1,12 +1,13 @@ package com.dfsek.terra.api.core.event.events.world; -import com.dfsek.terra.api.core.event.events.Event; +import com.dfsek.terra.api.core.event.events.PackEvent; +import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.world.TerraWorld; /** * Called upon initialization of a TerraWorld. */ -public class TerraWorldLoadEvent implements Event { +public class TerraWorldLoadEvent implements PackEvent { private final TerraWorld world; public TerraWorldLoadEvent(TerraWorld world) { @@ -16,4 +17,9 @@ public class TerraWorldLoadEvent implements Event { public TerraWorld getWorld() { return world; } + + @Override + public ConfigPack getPack() { + return world.getConfig(); + } } diff --git a/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java b/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java index 20549a829..82bae3dfb 100644 --- a/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java +++ b/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java @@ -1,6 +1,7 @@ package com.dfsek.terra.config; import com.dfsek.tectonic.loading.TypeRegistry; +import com.dfsek.terra.addons.addon.TerraAddon; import com.dfsek.terra.api.LoaderRegistrar; import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.math.GridSpawn; @@ -90,6 +91,7 @@ public class GenericLoaders implements LoaderRegistrar { .registerLoader(CarverPalette.class, new CarverPaletteLoader()) .registerLoader(SourceSeeded.class, new SourceBuilderLoader()) .registerLoader(StageSeeded.class, new StageBuilderLoader()) + .registerLoader(TerraAddon.class, main.getAddons()) .registerLoader(BiomeProvider.BiomeProviderBuilder.class, new BiomeProviderBuilderLoader()) .registerLoader(ImageSampler.Channel.class, (t, object, cf) -> ImageSampler.Channel.valueOf((String) object)) .registerLoader(BiomeProvider.Type.class, (t, object, cf) -> BiomeProvider.Type.valueOf((String) object)) diff --git a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPackTemplate.java b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPackTemplate.java index 638a6f4e9..13df2f11a 100644 --- a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPackTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPackTemplate.java @@ -3,12 +3,14 @@ package com.dfsek.terra.config.pack; import com.dfsek.tectonic.annotations.Default; import com.dfsek.tectonic.annotations.Value; import com.dfsek.tectonic.config.ConfigTemplate; +import com.dfsek.terra.addons.addon.TerraAddon; import com.dfsek.terra.api.util.seeded.NoiseSeeded; import com.dfsek.terra.config.loaders.config.function.FunctionTemplate; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Set; @SuppressWarnings({"unused", "FieldMayBeFinal"}) public class ConfigPackTemplate implements ConfigTemplate { @@ -18,6 +20,10 @@ public class ConfigPackTemplate implements ConfigTemplate { @Value("noise") private Map noiseBuilderMap; + @Value("addons") + @Default + private Set addons; + @Value("variables") @Default private Map variables = new HashMap<>(); @@ -121,4 +127,8 @@ public class ConfigPackTemplate implements ConfigTemplate { public boolean doBetaCarvers() { return betaCarvers; } + + public Set getAddons() { + return addons; + } } diff --git a/common/src/main/java/com/dfsek/terra/registry/AddonRegistry.java b/common/src/main/java/com/dfsek/terra/registry/AddonRegistry.java index 4cbb26636..17667d75d 100644 --- a/common/src/main/java/com/dfsek/terra/registry/AddonRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/AddonRegistry.java @@ -1,6 +1,8 @@ package com.dfsek.terra.registry; import com.dfsek.terra.addons.addon.TerraAddon; +import com.dfsek.terra.addons.annotations.Addon; +import com.dfsek.terra.addons.annotations.Depends; import com.dfsek.terra.addons.loading.AddonClassLoader; import com.dfsek.terra.addons.loading.AddonLoadException; import com.dfsek.terra.api.core.TerraPlugin; @@ -9,48 +11,88 @@ import java.io.File; import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; import java.util.Set; public class AddonRegistry extends TerraRegistry { - public boolean loadAll(TerraPlugin main) { + private final TerraPlugin main; + + public AddonRegistry(TerraPlugin main) { + + this.main = main; + } + + public AddonRegistry(TerraAddon addon, TerraPlugin main) { + this.main = main; + add(addon.getName(), addon); + } + + @Override + public boolean add(String name, TerraAddon addon) { + addon.initialize(); + main.getLogger().info("Loaded addon " + addon.getName() + " v" + addon.getVersion() + ", by " + addon.getAuthor()); + return super.add(name, addon); + } + + public boolean loadAll() { boolean valid = true; File addonsFolder = new File(main.getDataFolder(), "addons"); addonsFolder.mkdirs(); - for(File jar : addonsFolder.listFiles(file -> file.getName().endsWith(".jar"))) { - try { + + Map> addonIDs = new HashMap<>(); + + try { + for(File jar : addonsFolder.listFiles(file -> file.getName().endsWith(".jar"))) { + main.getLogger().info("Loading Addon(s) from: " + jar.getName()); - load(jar, main); - } catch(IOException | AddonLoadException e) { - e.printStackTrace(); - valid = false; + + Set> addonClasses = AddonClassLoader.fetchAddonClasses(jar); + + for(Class addonClass : addonClasses) { + String id = addonClass.getAnnotation(Addon.class).value(); + if(addonIDs.containsKey(id)) + throw new AddonLoadException("Duplicate addon ID: " + id); + addonIDs.put(id, addonClass); + } } + + for(Map.Entry> entry : addonIDs.entrySet()) { + Class addonClass = entry.getValue(); + + Depends dependencies = addonClass.getAnnotation(Depends.class); + + if(dependencies != null) { + for(String dependency : dependencies.value()) { + if(!addonIDs.containsKey(dependency)) + throw new AddonLoadException("Addon " + entry.getKey() + " specifies dependency " + dependency + ", which is not loaded. Please install " + dependency + " to use " + entry.getKey()); + } + } + + Constructor constructor; + try { + constructor = addonClass.getConstructor(); + } catch(NoSuchMethodException e) { + throw new AddonLoadException("Addon class has no valid constructor: " + addonClass.getCanonicalName(), e); + } + TerraAddon addon; + try { + addon = constructor.newInstance(); + } catch(InstantiationException | IllegalAccessException | InvocationTargetException e) { + throw new AddonLoadException("Failed to instantiate addon: " + addonClass.getCanonicalName(), e); + } + try { + addChecked(addon.getName(), addon); + } catch(IllegalArgumentException e) { + throw new AddonLoadException("Duplicate addon ID; addon with ID " + addon.getName() + " is already loaded."); + } + } + } catch(IOException | AddonLoadException e) { + e.printStackTrace(); + valid = false; + main.getLogger().severe("Addons failed to load. Please ensure all addons are properly installed."); } + return valid; } - - public void load(File file, TerraPlugin main) throws AddonLoadException, IOException { - Set> addonClasses = AddonClassLoader.fetchAddonClasses(file); - - for(Class addonClass : addonClasses) { - Constructor constructor; - try { - constructor = addonClass.getConstructor(); - } catch(NoSuchMethodException e) { - throw new AddonLoadException("Addon class has no valid constructor: " + addonClass.getCanonicalName(), e); - } - TerraAddon addon; - try { - addon = constructor.newInstance(); - } catch(InstantiationException | IllegalAccessException | InvocationTargetException e) { - throw new AddonLoadException("Failed to instantiate addon: " + addonClass.getCanonicalName(), e); - } - try { - addChecked(addon.getName(), addon); - } catch(IllegalArgumentException e) { - throw new AddonLoadException("Duplicate addon ID; addon with ID " + addon.getName() + " is already loaded."); - } - main.getLogger().info("Loaded addon " + addon.getName() + " v" + addon.getVersion() + ", by " + addon.getAuthor()); - addon.initialize(); - } - } } diff --git a/common/src/main/java/com/dfsek/terra/registry/TerraRegistry.java b/common/src/main/java/com/dfsek/terra/registry/TerraRegistry.java index 71d9026b0..eefe13120 100644 --- a/common/src/main/java/com/dfsek/terra/registry/TerraRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/TerraRegistry.java @@ -38,7 +38,7 @@ public abstract class TerraRegistry implements TypeLoader { public void addChecked(String name, T value) { if(objects.containsKey(name)) throw new IllegalArgumentException("Value is already defined in registry."); - objects.put(name, value); + add(name, value); } /** diff --git a/common/src/test/java/event/EventTest.java b/common/src/test/java/event/EventTest.java deleted file mode 100644 index 49299dc1a..000000000 --- a/common/src/test/java/event/EventTest.java +++ /dev/null @@ -1,156 +0,0 @@ -package event; - -import com.dfsek.tectonic.loading.TypeRegistry; -import com.dfsek.terra.api.core.TerraPlugin; -import com.dfsek.terra.api.core.event.EventListener; -import com.dfsek.terra.api.core.event.EventManager; -import com.dfsek.terra.api.core.event.TerraEventManager; -import com.dfsek.terra.api.core.event.annotations.Priority; -import com.dfsek.terra.api.core.event.events.Event; -import com.dfsek.terra.api.platform.handle.ItemHandle; -import com.dfsek.terra.api.platform.handle.WorldHandle; -import com.dfsek.terra.api.platform.world.World; -import com.dfsek.terra.config.PluginConfig; -import com.dfsek.terra.config.lang.Language; -import com.dfsek.terra.debug.DebugLogger; -import com.dfsek.terra.registry.AddonRegistry; -import com.dfsek.terra.registry.ConfigRegistry; -import com.dfsek.terra.world.TerraWorld; -import org.junit.jupiter.api.Test; - -import java.io.File; -import java.util.logging.Logger; - -public class EventTest { - public TerraPlugin main = new TerraPlugin() { - private final Logger logger = Logger.getLogger("Terra"); - private final EventManager eventManager = new TerraEventManager(this); - - @Override - public WorldHandle getWorldHandle() { - return null; - } - - @Override - public boolean isEnabled() { - return false; - } - - @Override - public TerraWorld getWorld(World world) { - return null; - } - - @Override - public Logger getLogger() { - return logger; - } - - @Override - public PluginConfig getTerraConfig() { - return null; - } - - @Override - public File getDataFolder() { - return null; - } - - @Override - public boolean isDebug() { - return false; - } - - @Override - public Language getLanguage() { - return null; - } - - @Override - public ConfigRegistry getRegistry() { - return null; - } - - @Override - public AddonRegistry getAddons() { - return null; - } - - @Override - public void reload() { - - } - - @Override - public ItemHandle getItemHandle() { - return null; - } - - @Override - public void saveDefaultConfig() { - - } - - @Override - public String platformName() { - return null; - } - - @Override - public DebugLogger getDebugLogger() { - return null; - } - - @Override - public void register(TypeRegistry registry) { - - } - - @Override - public EventManager getEventManager() { - return eventManager; - } - }; - - @Test - public void eventTest() { - EventManager eventManager = main.getEventManager(); - eventManager.registerListener(new TestListener()); - eventManager.registerListener(new TestListener2()); - - TestEvent event = new TestEvent(4); - eventManager.callEvent(event); - - eventManager.registerListener(new TestListenerException()); - - TestEvent event2 = new TestEvent(5); - eventManager.callEvent(event2); - } - - static class TestListener implements EventListener { - public void doThing(TestEvent event) { - System.out.println("Event value: " + event.value); - } - } - - static class TestListener2 implements EventListener { - @Priority(Priority.LOWEST) - public void doThing(TestEvent event) { - System.out.println("Event value 2: " + event.value); - } - } - - static class TestListenerException implements EventListener { - public void doThing(TestEvent event) { - throw new RuntimeException("bazinga: " + event.value); - } - } - - static class TestEvent implements Event { - private final int value; - - TestEvent(int value) { - this.value = value; - } - } -} diff --git a/platforms/bukkit/build.gradle.kts b/platforms/bukkit/build.gradle.kts index ebf64f845..09c58492d 100644 --- a/platforms/bukkit/build.gradle.kts +++ b/platforms/bukkit/build.gradle.kts @@ -34,7 +34,7 @@ dependencies { } tasks.withType { - include("**/*.yml") + include("**/*.*") filter( "tokens" to mapOf( "VERSION" to project.version.toString() diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java index 02c7af250..f79e3722f 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java @@ -1,6 +1,10 @@ package com.dfsek.terra.bukkit; import com.dfsek.tectonic.loading.TypeRegistry; +import com.dfsek.terra.addons.addon.TerraAddon; +import com.dfsek.terra.addons.annotations.Addon; +import com.dfsek.terra.addons.annotations.Author; +import com.dfsek.terra.addons.annotations.Version; import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.core.event.EventManager; import com.dfsek.terra.api.core.event.TerraEventManager; @@ -56,21 +60,22 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { private WorldHandle handle = new BukkitWorldHandle(); private final GenericLoaders genericLoaders = new GenericLoaders(this); private DebugLogger debugLogger; - private final AddonRegistry addonRegistry = new AddonRegistry(); + private final EventManager eventManager = new TerraEventManager(this); - - public static final Version BUKKIT_VERSION; + public static final BukkitVersion BUKKIT_VERSION; static { String ver = Bukkit.getServer().getClass().getPackage().getName(); - if(ver.contains("1_16")) BUKKIT_VERSION = Version.V1_16; - else if(ver.contains("1_15")) BUKKIT_VERSION = Version.V1_15; - else if(ver.contains("1_14")) BUKKIT_VERSION = Version.V1_14; - else if(ver.contains("1_13")) BUKKIT_VERSION = Version.V1_13; - else BUKKIT_VERSION = Version.UNKNOWN; + if(ver.contains("1_16")) BUKKIT_VERSION = BukkitVersion.V1_16; + else if(ver.contains("1_15")) BUKKIT_VERSION = BukkitVersion.V1_15; + else if(ver.contains("1_14")) BUKKIT_VERSION = BukkitVersion.V1_14; + else if(ver.contains("1_13")) BUKKIT_VERSION = BukkitVersion.V1_13; + else BUKKIT_VERSION = BukkitVersion.UNKNOWN; } + private final AddonRegistry addonRegistry = new AddonRegistry(new BukkitAddon(this), this); + public void reload() { Map newMap = new HashMap<>(); @@ -122,10 +127,8 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { public void onEnable() { debugLogger = new DebugLogger(getLogger()); - eventManager.registerListener(new TerraListener(this)); // Register tree injection event - getLogger().info("Running on version " + BUKKIT_VERSION); - if(BUKKIT_VERSION.equals(Version.UNKNOWN)) { + if(BUKKIT_VERSION == BukkitVersion.UNKNOWN) { getLogger().warning("Terra is running on an unknown Bukkit version. Proceed with caution."); } @@ -138,7 +141,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { LangUtil.load(config.getLanguage(), this); // Load language. debugLogger.setDebug(isDebug()); - addonRegistry.loadAll(this); + addonRegistry.loadAll(); registry.loadAll(this); // Load all config packs. PluginCommand c = Objects.requireNonNull(getCommand("terra")); @@ -253,7 +256,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { return addonRegistry; } - public enum Version { + public enum BukkitVersion { V1_13(13), V1_14(14), @@ -266,7 +269,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { private final int index; - Version(int index) { + BukkitVersion(int index) { this.index = index; } @@ -276,8 +279,24 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { * @param other Other version * @return Whether this version is equal to or later than other. */ - public boolean above(Version other) { + public boolean above(BukkitVersion other) { return this.index >= other.index; } } + + @Addon("Terra") + @Version("1.0.0") + @Author("Terra") + private static final class BukkitAddon extends TerraAddon { + private final TerraPlugin main; + + private BukkitAddon(TerraPlugin main) { + this.main = main; + } + + @Override + public void initialize() { + main.getEventManager().registerListener(this, new TerraListener(main)); + } + } } diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/AddonsCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/AddonsCommand.java new file mode 100644 index 000000000..c7dba7e80 --- /dev/null +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/AddonsCommand.java @@ -0,0 +1,41 @@ +package com.dfsek.terra.bukkit.command.command; + +import com.dfsek.terra.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; + +public class AddonsCommand extends Command { + public AddonsCommand(Command parent) { + super(parent); + } + + @Override + public String getName() { + return "addons"; + } + + @Override + public List getSubCommands() { + return Collections.emptyList(); + } + + @Override + public boolean execute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) { + sender.sendMessage("Installed Addons:"); + getMain().getAddons().forEach(addon -> sender.sendMessage(" - " + addon.getName() + " v" + addon.getVersion() + " by " + addon.getAuthor())); + return true; + } + + @Override + public int arguments() { + return 0; + } + + @Override + public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { + return Collections.emptyList(); + } +} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/TerraCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/TerraCommand.java index 6a1948cf9..f844b82e3 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/TerraCommand.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/TerraCommand.java @@ -25,7 +25,8 @@ public class TerraCommand extends Command { new FixChunkCommand(this), new VersionCommand(this), new GetBlockCommand(this), - new PacksCommand(this)); + new PacksCommand(this), + new AddonsCommand(this)); public TerraCommand(TerraPlugin main) { super(main); diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/TerraListener.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/TerraListener.java index 1549cefdb..4c98e3cea 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/TerraListener.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/TerraListener.java @@ -2,6 +2,7 @@ package com.dfsek.terra.bukkit.listeners; import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.core.event.EventListener; +import com.dfsek.terra.api.core.event.annotations.Global; import com.dfsek.terra.api.core.event.events.config.ConfigPackPreLoadEvent; import com.dfsek.terra.bukkit.world.BukkitAdapter; import com.dfsek.terra.bukkit.world.BukkitTree; @@ -14,6 +15,7 @@ public class TerraListener implements EventListener { this.main = main; } + @Global public void injectTrees(ConfigPackPreLoadEvent event) { for(TreeType value : TreeType.values()) { event.getPack().getTreeRegistry().add(BukkitAdapter.TREE_TRANSFORMER.translate(value), new BukkitTree(value, main)); diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/data/BukkitBlockData.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/data/BukkitBlockData.java index dc3295f73..6e198a53b 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/data/BukkitBlockData.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/data/BukkitBlockData.java @@ -28,7 +28,7 @@ public class BukkitBlockData implements BlockData { if(bukkitData instanceof Rail) return new BukkitRail((Rail) bukkitData); if(bukkitData instanceof Stairs) return new BukkitStairs((Stairs) bukkitData); if(bukkitData instanceof Slab) return new BukkitSlab((Slab) bukkitData); - if(TerraBukkitPlugin.BUKKIT_VERSION.above(TerraBukkitPlugin.Version.V1_16) && bukkitData instanceof Wall) { // Wall only exists on 1.16 and up. + if(TerraBukkitPlugin.BUKKIT_VERSION.above(TerraBukkitPlugin.BukkitVersion.V1_16) && bukkitData instanceof Wall) { // Wall only exists on 1.16 and up. return new BukkitWall((Wall) bukkitData); } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index 0f768541e..cb6baa70a 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -87,7 +87,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { private final WorldHandle worldHandle = new FabricWorldHandle(); private final ConfigRegistry registry = new ConfigRegistry(); - private final AddonRegistry addonRegistry = new AddonRegistry(); + private final AddonRegistry addonRegistry = new AddonRegistry(this); private File config; private static final Transformer> TREE_TRANSFORMER = new Transformer.Builder>() .addTransform(TerraFabricPlugin::getFeature) diff --git a/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java b/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java index 93b46810e..0f6eb97c2 100644 --- a/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java +++ b/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java @@ -27,7 +27,7 @@ import java.util.logging.Logger; public class StandalonePlugin implements TerraPlugin { private final ConfigRegistry registry = new ConfigRegistry(); - private final AddonRegistry addonRegistry = new AddonRegistry(); + private final AddonRegistry addonRegistry = new AddonRegistry(this); private final PluginConfig config = new PluginConfig(); private final RawWorldHandle worldHandle = new RawWorldHandle(); private final EventManager eventManager = new TerraEventManager(this); From 45dbe45fb4be6a29af0e6d89c7ba4c5f0d403e4a Mon Sep 17 00:00:00 2001 From: dfsek Date: Sat, 20 Feb 2021 22:31:13 -0700 Subject: [PATCH 03/95] set up dependency stuff --- .../addons/loading/AddonClassLoader.java | 2 +- .../addons/loading/AddonLoadException.java | 2 + .../terra/addons/loading/pre/AddonPool.java | 32 +++++++++++ .../pre/CircularDependencyException.java | 15 +++++ .../pre/DependencyMissingException.java | 15 +++++ .../addons/loading/pre/PreLoadAddon.java | 48 ++++++++++++++++ .../dfsek/terra/registry/AddonRegistry.java | 57 ++++++++----------- .../dfsek/terra/bukkit/TerraBukkitPlugin.java | 7 ++- .../bukkit/population/SerializationUtil.java | 2 +- 9 files changed, 144 insertions(+), 36 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/addons/loading/pre/AddonPool.java create mode 100644 common/src/main/java/com/dfsek/terra/addons/loading/pre/CircularDependencyException.java create mode 100644 common/src/main/java/com/dfsek/terra/addons/loading/pre/DependencyMissingException.java create mode 100644 common/src/main/java/com/dfsek/terra/addons/loading/pre/PreLoadAddon.java diff --git a/common/src/main/java/com/dfsek/terra/addons/loading/AddonClassLoader.java b/common/src/main/java/com/dfsek/terra/addons/loading/AddonClassLoader.java index 5cd20fd75..58093e6cf 100644 --- a/common/src/main/java/com/dfsek/terra/addons/loading/AddonClassLoader.java +++ b/common/src/main/java/com/dfsek/terra/addons/loading/AddonClassLoader.java @@ -51,7 +51,7 @@ public class AddonClassLoader extends URLClassLoader { set.add((Class) clazz); } catch(ClassNotFoundException e) { - e.printStackTrace(); + throw new IllegalStateException(e); // this should literally never happen, if it does something is very wrong } } diff --git a/common/src/main/java/com/dfsek/terra/addons/loading/AddonLoadException.java b/common/src/main/java/com/dfsek/terra/addons/loading/AddonLoadException.java index 45e8aa1b2..867987ec2 100644 --- a/common/src/main/java/com/dfsek/terra/addons/loading/AddonLoadException.java +++ b/common/src/main/java/com/dfsek/terra/addons/loading/AddonLoadException.java @@ -1,6 +1,8 @@ package com.dfsek.terra.addons.loading; public class AddonLoadException extends Exception { + private static final long serialVersionUID = -4949084729296580176L; + public AddonLoadException(String message) { super(message); } diff --git a/common/src/main/java/com/dfsek/terra/addons/loading/pre/AddonPool.java b/common/src/main/java/com/dfsek/terra/addons/loading/pre/AddonPool.java new file mode 100644 index 000000000..2264b49d6 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/addons/loading/pre/AddonPool.java @@ -0,0 +1,32 @@ +package com.dfsek.terra.addons.loading.pre; + +import com.dfsek.terra.addons.loading.AddonLoadException; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class AddonPool { + private final Map pool = new HashMap<>(); + + public void add(PreLoadAddon addon) throws AddonLoadException { + if(pool.containsKey(addon.getId())) + throw new AddonLoadException("Duplicate addon ID: " + addon.getId()); + pool.put(addon.getId(), addon); + } + + public PreLoadAddon get(String id) { + return pool.get(id); + } + + public void buildAll() throws AddonLoadException { + for(PreLoadAddon value : pool.values()) { + value.rebuildDependencies(this, value, true); + } + } + + public Set getAddons() { + return new HashSet<>(pool.values()); + } +} diff --git a/common/src/main/java/com/dfsek/terra/addons/loading/pre/CircularDependencyException.java b/common/src/main/java/com/dfsek/terra/addons/loading/pre/CircularDependencyException.java new file mode 100644 index 000000000..f262f7285 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/addons/loading/pre/CircularDependencyException.java @@ -0,0 +1,15 @@ +package com.dfsek.terra.addons.loading.pre; + +import com.dfsek.terra.addons.loading.AddonLoadException; + +public class CircularDependencyException extends AddonLoadException { + private static final long serialVersionUID = 7398510879124125121L; + + public CircularDependencyException(String message) { + super(message); + } + + public CircularDependencyException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/common/src/main/java/com/dfsek/terra/addons/loading/pre/DependencyMissingException.java b/common/src/main/java/com/dfsek/terra/addons/loading/pre/DependencyMissingException.java new file mode 100644 index 000000000..936c6f480 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/addons/loading/pre/DependencyMissingException.java @@ -0,0 +1,15 @@ +package com.dfsek.terra.addons.loading.pre; + +import com.dfsek.terra.addons.loading.AddonLoadException; + +public class DependencyMissingException extends AddonLoadException { + private static final long serialVersionUID = -8419489102208521583L; + + public DependencyMissingException(String message) { + super(message); + } + + public DependencyMissingException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/common/src/main/java/com/dfsek/terra/addons/loading/pre/PreLoadAddon.java b/common/src/main/java/com/dfsek/terra/addons/loading/pre/PreLoadAddon.java new file mode 100644 index 000000000..08e006e21 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/addons/loading/pre/PreLoadAddon.java @@ -0,0 +1,48 @@ +package com.dfsek.terra.addons.loading.pre; + +import com.dfsek.terra.addons.addon.TerraAddon; +import com.dfsek.terra.addons.annotations.Addon; +import com.dfsek.terra.addons.annotations.Depends; +import com.dfsek.terra.addons.loading.AddonLoadException; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class PreLoadAddon { + private final List depends = new ArrayList<>(); + private final Class addonClass; + private final String id; + private final String[] dependencies; + + public PreLoadAddon(Class addonClass) { + this.addonClass = addonClass; + this.id = addonClass.getAnnotation(Addon.class).value(); + Depends depends = addonClass.getAnnotation(Depends.class); + this.dependencies = depends == null ? new String[] {} : depends.value(); + } + + public List getDepends() { + return depends; + } + + public void rebuildDependencies(AddonPool pool, PreLoadAddon origin, boolean levelG1) throws AddonLoadException { + if(this.equals(origin) && !levelG1) + throw new CircularDependencyException("Detected circular dependency in addon \"" + id + "\", dependencies: " + Arrays.toString(dependencies)); + + for(String dependency : dependencies) { + PreLoadAddon preLoadAddon = pool.get(dependency); + if(preLoadAddon == null) throw new DependencyMissingException("Dependency " + dependency + " was not found."); + depends.add(preLoadAddon); + preLoadAddon.rebuildDependencies(pool, origin, false); + } + } + + public String getId() { + return id; + } + + public Class getAddonClass() { + return addonClass; + } +} diff --git a/common/src/main/java/com/dfsek/terra/registry/AddonRegistry.java b/common/src/main/java/com/dfsek/terra/registry/AddonRegistry.java index 17667d75d..892e48d87 100644 --- a/common/src/main/java/com/dfsek/terra/registry/AddonRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/AddonRegistry.java @@ -1,19 +1,16 @@ package com.dfsek.terra.registry; import com.dfsek.terra.addons.addon.TerraAddon; -import com.dfsek.terra.addons.annotations.Addon; -import com.dfsek.terra.addons.annotations.Depends; import com.dfsek.terra.addons.loading.AddonClassLoader; import com.dfsek.terra.addons.loading.AddonLoadException; +import com.dfsek.terra.addons.loading.pre.AddonPool; +import com.dfsek.terra.addons.loading.pre.PreLoadAddon; import com.dfsek.terra.api.core.TerraPlugin; import java.io.File; import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; public class AddonRegistry extends TerraRegistry { private final TerraPlugin main; @@ -30,67 +27,61 @@ public class AddonRegistry extends TerraRegistry { @Override public boolean add(String name, TerraAddon addon) { + if(contains(name)) throw new IllegalArgumentException("Addon " + name + " is already registered."); addon.initialize(); main.getLogger().info("Loaded addon " + addon.getName() + " v" + addon.getVersion() + ", by " + addon.getAuthor()); return super.add(name, addon); } + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + public boolean loadAll() { boolean valid = true; File addonsFolder = new File(main.getDataFolder(), "addons"); addonsFolder.mkdirs(); - Map> addonIDs = new HashMap<>(); + AddonPool pool = new AddonPool(); try { for(File jar : addonsFolder.listFiles(file -> file.getName().endsWith(".jar"))) { - main.getLogger().info("Loading Addon(s) from: " + jar.getName()); - - Set> addonClasses = AddonClassLoader.fetchAddonClasses(jar); - - for(Class addonClass : addonClasses) { - String id = addonClass.getAnnotation(Addon.class).value(); - if(addonIDs.containsKey(id)) - throw new AddonLoadException("Duplicate addon ID: " + id); - addonIDs.put(id, addonClass); + for(Class addonClass : AddonClassLoader.fetchAddonClasses(jar)) { + pool.add(new PreLoadAddon(addonClass)); } } - for(Map.Entry> entry : addonIDs.entrySet()) { - Class addonClass = entry.getValue(); - - Depends dependencies = addonClass.getAnnotation(Depends.class); - - if(dependencies != null) { - for(String dependency : dependencies.value()) { - if(!addonIDs.containsKey(dependency)) - throw new AddonLoadException("Addon " + entry.getKey() + " specifies dependency " + dependency + ", which is not loaded. Please install " + dependency + " to use " + entry.getKey()); - } - } + pool.buildAll(); + for(PreLoadAddon addon : pool.getAddons()) { + Class addonClass = addon.getAddonClass(); Constructor constructor; + try { constructor = addonClass.getConstructor(); } catch(NoSuchMethodException e) { throw new AddonLoadException("Addon class has no valid constructor: " + addonClass.getCanonicalName(), e); } - TerraAddon addon; + TerraAddon loadedAddon; try { - addon = constructor.newInstance(); + loadedAddon = constructor.newInstance(); } catch(InstantiationException | IllegalAccessException | InvocationTargetException e) { - throw new AddonLoadException("Failed to instantiate addon: " + addonClass.getCanonicalName(), e); + throw new AddonLoadException("Failed to load addon \" + " + addon.getId() + "\": ", e); } try { - addChecked(addon.getName(), addon); + addChecked(loadedAddon.getName(), loadedAddon); } catch(IllegalArgumentException e) { - throw new AddonLoadException("Duplicate addon ID; addon with ID " + addon.getName() + " is already loaded."); + valid = false; + main.getLogger().severe("Duplicate addon ID; addon with ID " + loadedAddon.getName() + " is already loaded."); + main.getLogger().severe("Existing addon class: " + get(loadedAddon.getName()).getClass().getCanonicalName()); + main.getLogger().severe("Duplicate addon class: " + addonClass.getCanonicalName()); } } - } catch(IOException | AddonLoadException e) { + } catch(AddonLoadException | IOException e) { e.printStackTrace(); valid = false; - main.getLogger().severe("Addons failed to load. Please ensure all addons are properly installed."); } return valid; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java index f79e3722f..7e62cd637 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java @@ -141,7 +141,12 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { LangUtil.load(config.getLanguage(), this); // Load language. debugLogger.setDebug(isDebug()); - addonRegistry.loadAll(); + if(!addonRegistry.loadAll()) { + getLogger().severe("Failed to load addons. Please correct addon installations to continue."); + Bukkit.getPluginManager().disablePlugin(this); + return; + } + registry.loadAll(this); // Load all config packs. PluginCommand c = Objects.requireNonNull(getCommand("terra")); diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/population/SerializationUtil.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/population/SerializationUtil.java index 0a0267b6a..a297259c5 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/population/SerializationUtil.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/population/SerializationUtil.java @@ -41,7 +41,7 @@ public final class SerializationUtil { try { if(result.getName().contains(oldNameSpace)) { String newClassName = result.getName().replace(oldNameSpace, newNameSpace); - Class localClass = Class.forName(newClassName); + Class localClass = Class.forName(newClassName); Field nameField = ObjectStreamClass.class.getDeclaredField("name"); nameField.setAccessible(true); From 3b719d08806badbc51f87f5651d7ce6a7848bc1b Mon Sep 17 00:00:00 2001 From: dfsek Date: Sat, 20 Feb 2021 23:23:17 -0700 Subject: [PATCH 04/95] add dependency injection API --- .../dfsek/terra/addons/injection/Inject.java | 11 +++++ .../addons/injection/InjectionException.java | 13 +++++ .../terra/addons/injection/Injector.java | 47 +++++++++++++++++++ .../addons/loading/pre/PreLoadAddon.java | 5 +- .../CircularDependencyException.java | 2 +- .../DependencyMissingException.java | 2 +- .../api/core/event/TerraEventManager.java | 6 ++- .../terra/config/pack/ConfigPackTemplate.java | 3 +- .../dfsek/terra/registry/AddonRegistry.java | 21 ++++++++- 9 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/addons/injection/Inject.java create mode 100644 common/src/main/java/com/dfsek/terra/addons/injection/InjectionException.java create mode 100644 common/src/main/java/com/dfsek/terra/addons/injection/Injector.java rename common/src/main/java/com/dfsek/terra/addons/loading/pre/{ => exception}/CircularDependencyException.java (88%) rename common/src/main/java/com/dfsek/terra/addons/loading/pre/{ => exception}/DependencyMissingException.java (88%) diff --git a/common/src/main/java/com/dfsek/terra/addons/injection/Inject.java b/common/src/main/java/com/dfsek/terra/addons/injection/Inject.java new file mode 100644 index 000000000..38b35cd42 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/addons/injection/Inject.java @@ -0,0 +1,11 @@ +package com.dfsek.terra.addons.injection; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface Inject { +} diff --git a/common/src/main/java/com/dfsek/terra/addons/injection/InjectionException.java b/common/src/main/java/com/dfsek/terra/addons/injection/InjectionException.java new file mode 100644 index 000000000..26d3e5be4 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/addons/injection/InjectionException.java @@ -0,0 +1,13 @@ +package com.dfsek.terra.addons.injection; + +public class InjectionException extends Exception { + private static final long serialVersionUID = -6929631447064215387L; + + public InjectionException(String message) { + super(message); + } + + public InjectionException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/common/src/main/java/com/dfsek/terra/addons/injection/Injector.java b/common/src/main/java/com/dfsek/terra/addons/injection/Injector.java new file mode 100644 index 000000000..0ba685a4f --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/addons/injection/Injector.java @@ -0,0 +1,47 @@ +package com.dfsek.terra.addons.injection; + +import com.dfsek.terra.api.util.ReflectionUtil; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.HashSet; +import java.util.Set; + +public class Injector { + private final T value; + private final Set> targets = new HashSet<>(); + + public Injector(T value) { + this.value = value; + } + + public void addExplicitTarget(Class target) { + targets.add(target); + } + + public void inject(Object object) throws InjectionException { + for(Field field : ReflectionUtil.getFields(object.getClass())) { + Inject inject = field.getAnnotation(Inject.class); + if(inject == null) continue; + + System.out.println(field); + System.out.println("attempting to inject " + value.getClass() + " to " + field.getClass()); + if(value.getClass().equals(field.getType()) || targets.contains(field.getType())) { + System.out.println("injecting..."); + int mod = field.getModifiers(); + if(Modifier.isFinal(mod)) { + throw new InjectionException("Attempted to inject final field: " + field); + } + if(Modifier.isStatic(mod)) { + throw new InjectionException("Attempted to inject static field: " + field); + } + field.setAccessible(true); + try { + field.set(object, value); + } catch(IllegalAccessException e) { + throw new InjectionException("Failed to inject field: " + field, e); + } + } + } + } +} diff --git a/common/src/main/java/com/dfsek/terra/addons/loading/pre/PreLoadAddon.java b/common/src/main/java/com/dfsek/terra/addons/loading/pre/PreLoadAddon.java index 08e006e21..5b14b43ad 100644 --- a/common/src/main/java/com/dfsek/terra/addons/loading/pre/PreLoadAddon.java +++ b/common/src/main/java/com/dfsek/terra/addons/loading/pre/PreLoadAddon.java @@ -4,6 +4,8 @@ import com.dfsek.terra.addons.addon.TerraAddon; import com.dfsek.terra.addons.annotations.Addon; import com.dfsek.terra.addons.annotations.Depends; import com.dfsek.terra.addons.loading.AddonLoadException; +import com.dfsek.terra.addons.loading.pre.exception.CircularDependencyException; +import com.dfsek.terra.addons.loading.pre.exception.DependencyMissingException; import java.util.ArrayList; import java.util.Arrays; @@ -32,7 +34,8 @@ public class PreLoadAddon { for(String dependency : dependencies) { PreLoadAddon preLoadAddon = pool.get(dependency); - if(preLoadAddon == null) throw new DependencyMissingException("Dependency " + dependency + " was not found."); + if(preLoadAddon == null) + throw new DependencyMissingException("Dependency " + dependency + " was not found. Please install " + dependency + " to use " + id + "."); depends.add(preLoadAddon); preLoadAddon.rebuildDependencies(pool, origin, false); } diff --git a/common/src/main/java/com/dfsek/terra/addons/loading/pre/CircularDependencyException.java b/common/src/main/java/com/dfsek/terra/addons/loading/pre/exception/CircularDependencyException.java similarity index 88% rename from common/src/main/java/com/dfsek/terra/addons/loading/pre/CircularDependencyException.java rename to common/src/main/java/com/dfsek/terra/addons/loading/pre/exception/CircularDependencyException.java index f262f7285..221e66520 100644 --- a/common/src/main/java/com/dfsek/terra/addons/loading/pre/CircularDependencyException.java +++ b/common/src/main/java/com/dfsek/terra/addons/loading/pre/exception/CircularDependencyException.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.addons.loading.pre; +package com.dfsek.terra.addons.loading.pre.exception; import com.dfsek.terra.addons.loading.AddonLoadException; diff --git a/common/src/main/java/com/dfsek/terra/addons/loading/pre/DependencyMissingException.java b/common/src/main/java/com/dfsek/terra/addons/loading/pre/exception/DependencyMissingException.java similarity index 88% rename from common/src/main/java/com/dfsek/terra/addons/loading/pre/DependencyMissingException.java rename to common/src/main/java/com/dfsek/terra/addons/loading/pre/exception/DependencyMissingException.java index 936c6f480..b6a81d837 100644 --- a/common/src/main/java/com/dfsek/terra/addons/loading/pre/DependencyMissingException.java +++ b/common/src/main/java/com/dfsek/terra/addons/loading/pre/exception/DependencyMissingException.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.addons.loading.pre; +package com.dfsek.terra.addons.loading.pre.exception; import com.dfsek.terra.addons.loading.AddonLoadException; diff --git a/common/src/main/java/com/dfsek/terra/api/core/event/TerraEventManager.java b/common/src/main/java/com/dfsek/terra/api/core/event/TerraEventManager.java index aafa3f118..1bc3e6aa7 100644 --- a/common/src/main/java/com/dfsek/terra/api/core/event/TerraEventManager.java +++ b/common/src/main/java/com/dfsek/terra/api/core/event/TerraEventManager.java @@ -34,7 +34,11 @@ public class TerraEventManager implements EventManager { try { if(event instanceof PackEvent && !listenerHolder.global) { PackEvent packEvent = (PackEvent) event; - if(packEvent.getPack().getTemplate().getAddons().contains(listenerHolder.addon)) { + if(packEvent + .getPack() + .getTemplate() + .getAddons() + .contains(listenerHolder.addon)) { listenerHolder.method.invoke(listenerHolder.listener, event); } } else { diff --git a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPackTemplate.java b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPackTemplate.java index 13df2f11a..d57615148 100644 --- a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPackTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPackTemplate.java @@ -8,6 +8,7 @@ import com.dfsek.terra.api.util.seeded.NoiseSeeded; import com.dfsek.terra.config.loaders.config.function.FunctionTemplate; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; @@ -22,7 +23,7 @@ public class ConfigPackTemplate implements ConfigTemplate { @Value("addons") @Default - private Set addons; + private Set addons = new HashSet<>(); @Value("variables") @Default diff --git a/common/src/main/java/com/dfsek/terra/registry/AddonRegistry.java b/common/src/main/java/com/dfsek/terra/registry/AddonRegistry.java index 892e48d87..d73799b67 100644 --- a/common/src/main/java/com/dfsek/terra/registry/AddonRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/AddonRegistry.java @@ -1,6 +1,8 @@ package com.dfsek.terra.registry; import com.dfsek.terra.addons.addon.TerraAddon; +import com.dfsek.terra.addons.injection.InjectionException; +import com.dfsek.terra.addons.injection.Injector; import com.dfsek.terra.addons.loading.AddonClassLoader; import com.dfsek.terra.addons.loading.AddonLoadException; import com.dfsek.terra.addons.loading.pre.AddonPool; @@ -11,6 +13,8 @@ import java.io.File; import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.util.logging.LogManager; +import java.util.logging.Logger; public class AddonRegistry extends TerraRegistry { private final TerraPlugin main; @@ -39,6 +43,9 @@ public class AddonRegistry extends TerraRegistry { } public boolean loadAll() { + Injector pluginInjector = new Injector<>(main); + pluginInjector.addExplicitTarget(TerraPlugin.class); + boolean valid = true; File addonsFolder = new File(main.getDataFolder(), "addons"); addonsFolder.mkdirs(); @@ -59,6 +66,16 @@ public class AddonRegistry extends TerraRegistry { Class addonClass = addon.getAddonClass(); Constructor constructor; + String logPrefix = "Terra:" + addon.getId(); + Logger addonLogger = Logger.getLogger(logPrefix); + + if(!LogManager.getLogManager().addLogger(addonLogger)) { + addonLogger = LogManager.getLogManager().getLogger(logPrefix); + } + + Injector loggerInjector = new Injector<>(addonLogger); + loggerInjector.addExplicitTarget(Logger.class); + try { constructor = addonClass.getConstructor(); } catch(NoSuchMethodException e) { @@ -67,7 +84,9 @@ public class AddonRegistry extends TerraRegistry { TerraAddon loadedAddon; try { loadedAddon = constructor.newInstance(); - } catch(InstantiationException | IllegalAccessException | InvocationTargetException e) { + pluginInjector.inject(loadedAddon); + loggerInjector.inject(loadedAddon); + } catch(InstantiationException | IllegalAccessException | InvocationTargetException | InjectionException e) { throw new AddonLoadException("Failed to load addon \" + " + addon.getId() + "\": ", e); } try { From fab8c90e92a3e57c4085642fe8590c2206a72ad1 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sat, 20 Feb 2021 23:49:47 -0700 Subject: [PATCH 05/95] clean up ChunkGenerator API --- .../com/dfsek/terra/api/core/TerraPlugin.java | 4 +- .../platform/world/generator/ChunkData.java | 14 +++++ .../world/generator/ChunkGenerator.java | 36 ------------- .../world/generator/GeneratorWrapper.java | 6 --- .../structures/script/StructureScript.java | 4 +- .../world/generation/TerraChunkGenerator.java | 4 +- .../dfsek/terra/config/pack/ConfigPack.java | 2 +- .../dfsek/terra/profiler/WorldProfiler.java | 5 +- .../{ => config}/FunctionRegistry.java | 3 +- .../registry/{ => master}/AddonRegistry.java | 3 +- .../master/ChunkGeneratorRegistry.java | 7 +++ .../registry/{ => master}/ConfigRegistry.java | 3 +- .../com/dfsek/terra/world/TerraWorld.java | 4 +- .../generation/MasterChunkGenerator.java | 10 ++-- .../src/test/java/biome/DistributionTest.java | 4 +- .../dfsek/terra/bukkit/TerraBukkitPlugin.java | 4 +- .../bukkit/command/command/PacksCommand.java | 2 +- .../generator/BukkitChunkGenerator.java | 52 +------------------ .../BukkitChunkGeneratorWrapper.java | 5 +- .../dfsek/terra/fabric/TerraFabricPlugin.java | 8 +-- .../world/generator/FabricChunkData.java | 4 +- .../world/generator/FabricChunkGenerator.java | 50 ------------------ .../FabricChunkGeneratorWrapper.java | 3 +- .../com/dfsek/terra/StandalonePlugin.java | 4 +- .../dfsek/terra/platform/DirectChunkData.java | 4 +- .../com/dfsek/terra/platform/GenWrapper.java | 49 ----------------- 26 files changed, 63 insertions(+), 231 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/api/platform/world/generator/ChunkData.java delete mode 100644 common/src/main/java/com/dfsek/terra/api/platform/world/generator/GeneratorWrapper.java rename common/src/main/java/com/dfsek/terra/registry/{ => config}/FunctionRegistry.java (63%) rename common/src/main/java/com/dfsek/terra/registry/{ => master}/AddonRegistry.java (98%) create mode 100644 common/src/main/java/com/dfsek/terra/registry/master/ChunkGeneratorRegistry.java rename common/src/main/java/com/dfsek/terra/registry/{ => master}/ConfigRegistry.java (94%) diff --git a/common/src/main/java/com/dfsek/terra/api/core/TerraPlugin.java b/common/src/main/java/com/dfsek/terra/api/core/TerraPlugin.java index 7076afc2c..8bd907761 100644 --- a/common/src/main/java/com/dfsek/terra/api/core/TerraPlugin.java +++ b/common/src/main/java/com/dfsek/terra/api/core/TerraPlugin.java @@ -8,8 +8,8 @@ import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.config.PluginConfig; import com.dfsek.terra.config.lang.Language; import com.dfsek.terra.debug.DebugLogger; -import com.dfsek.terra.registry.AddonRegistry; -import com.dfsek.terra.registry.ConfigRegistry; +import com.dfsek.terra.registry.master.AddonRegistry; +import com.dfsek.terra.registry.master.ConfigRegistry; import com.dfsek.terra.world.TerraWorld; import java.io.File; diff --git a/common/src/main/java/com/dfsek/terra/api/platform/world/generator/ChunkData.java b/common/src/main/java/com/dfsek/terra/api/platform/world/generator/ChunkData.java new file mode 100644 index 000000000..bb7f164a4 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/platform/world/generator/ChunkData.java @@ -0,0 +1,14 @@ +package com.dfsek.terra.api.platform.world.generator; + +import com.dfsek.terra.api.platform.world.ChunkAccess; + +public interface ChunkData extends ChunkAccess { + /** + * Get the maximum height for the chunk. + *

+ * Setting blocks at or above this height will do nothing. + * + * @return the maximum height + */ + int getMaxHeight(); +} diff --git a/common/src/main/java/com/dfsek/terra/api/platform/world/generator/ChunkGenerator.java b/common/src/main/java/com/dfsek/terra/api/platform/world/generator/ChunkGenerator.java index 63676d31c..da3594011 100644 --- a/common/src/main/java/com/dfsek/terra/api/platform/world/generator/ChunkGenerator.java +++ b/common/src/main/java/com/dfsek/terra/api/platform/world/generator/ChunkGenerator.java @@ -1,43 +1,7 @@ package com.dfsek.terra.api.platform.world.generator; import com.dfsek.terra.api.platform.Handle; -import com.dfsek.terra.api.platform.world.BiomeGrid; -import com.dfsek.terra.api.platform.world.ChunkAccess; -import com.dfsek.terra.api.platform.world.World; -import com.dfsek.terra.api.world.generation.TerraChunkGenerator; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; -import java.util.Random; public interface ChunkGenerator extends Handle { - boolean isParallelCapable(); - boolean shouldGenerateCaves(); - - boolean shouldGenerateDecorations(); - - boolean shouldGenerateMobs(); - - boolean shouldGenerateStructures(); - - ChunkData generateChunkData(@NotNull World world, @NotNull Random random, int x, int z, @NotNull BiomeGrid biome); - - - List getDefaultPopulators(World world); - - @Nullable - TerraChunkGenerator getTerraGenerator(); - - interface ChunkData extends ChunkAccess { - /** - * Get the maximum height for the chunk. - *

- * Setting blocks at or above this height will do nothing. - * - * @return the maximum height - */ - int getMaxHeight(); - } } diff --git a/common/src/main/java/com/dfsek/terra/api/platform/world/generator/GeneratorWrapper.java b/common/src/main/java/com/dfsek/terra/api/platform/world/generator/GeneratorWrapper.java deleted file mode 100644 index 4de6bdc2b..000000000 --- a/common/src/main/java/com/dfsek/terra/api/platform/world/generator/GeneratorWrapper.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.dfsek.terra.api.platform.world.generator; - -import com.dfsek.terra.api.platform.Handle; - -public interface GeneratorWrapper extends Handle { -} diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java b/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java index c68c7cb07..232a931f6 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java @@ -28,7 +28,7 @@ import com.dfsek.terra.api.structures.structure.Rotation; import com.dfsek.terra.api.structures.structure.buffer.Buffer; import com.dfsek.terra.api.structures.structure.buffer.DirectBuffer; import com.dfsek.terra.api.structures.structure.buffer.StructureBuffer; -import com.dfsek.terra.registry.FunctionRegistry; +import com.dfsek.terra.registry.config.FunctionRegistry; import com.dfsek.terra.registry.config.LootRegistry; import com.dfsek.terra.registry.config.ScriptRegistry; import com.dfsek.terra.world.generation.math.SamplerCache; @@ -47,7 +47,7 @@ public class StructureScript { private final String id; private final Cache cache; private final TerraPlugin main; - String tempID; + private String tempID; public StructureScript(InputStream inputStream, TerraPlugin main, ScriptRegistry registry, LootRegistry lootRegistry, SamplerCache cache, FunctionRegistry functionRegistry) throws ParseException { Parser parser; diff --git a/common/src/main/java/com/dfsek/terra/api/world/generation/TerraChunkGenerator.java b/common/src/main/java/com/dfsek/terra/api/world/generation/TerraChunkGenerator.java index c4b52f2f3..94b89a983 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/generation/TerraChunkGenerator.java +++ b/common/src/main/java/com/dfsek/terra/api/world/generation/TerraChunkGenerator.java @@ -3,14 +3,14 @@ package com.dfsek.terra.api.world.generation; import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.platform.world.BiomeGrid; import com.dfsek.terra.api.platform.world.World; -import com.dfsek.terra.api.platform.world.generator.ChunkGenerator; +import com.dfsek.terra.api.platform.world.generator.ChunkData; import com.dfsek.terra.config.pack.ConfigPack; import org.jetbrains.annotations.NotNull; import java.util.Random; public interface TerraChunkGenerator { - ChunkGenerator.ChunkData generateChunkData(@NotNull World world, Random random, int x, int z, ChunkGenerator.ChunkData original); + ChunkData generateChunkData(@NotNull World world, Random random, int x, int z, ChunkData original); void generateBiomes(@NotNull World world, @NotNull Random random, int x, int z, @NotNull BiomeGrid biome); diff --git a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java index 7f36e01b6..fb9d433e6 100644 --- a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java +++ b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java @@ -46,11 +46,11 @@ import com.dfsek.terra.config.templates.OreTemplate; import com.dfsek.terra.config.templates.PaletteTemplate; import com.dfsek.terra.config.templates.StructureTemplate; import com.dfsek.terra.config.templates.TreeTemplate; -import com.dfsek.terra.registry.FunctionRegistry; import com.dfsek.terra.registry.TerraRegistry; import com.dfsek.terra.registry.config.BiomeRegistry; import com.dfsek.terra.registry.config.CarverRegistry; import com.dfsek.terra.registry.config.FloraRegistry; +import com.dfsek.terra.registry.config.FunctionRegistry; import com.dfsek.terra.registry.config.LootRegistry; import com.dfsek.terra.registry.config.NoiseRegistry; import com.dfsek.terra.registry.config.OreRegistry; diff --git a/common/src/main/java/com/dfsek/terra/profiler/WorldProfiler.java b/common/src/main/java/com/dfsek/terra/profiler/WorldProfiler.java index 7b3e9c12d..a1ea04908 100644 --- a/common/src/main/java/com/dfsek/terra/profiler/WorldProfiler.java +++ b/common/src/main/java/com/dfsek/terra/profiler/WorldProfiler.java @@ -1,6 +1,7 @@ package com.dfsek.terra.profiler; import com.dfsek.terra.api.platform.world.World; +import com.dfsek.terra.world.TerraWorld; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import net.jafama.FastMath; @@ -13,7 +14,7 @@ public class WorldProfiler { private boolean isProfiling; public WorldProfiler(World w) { - if(w.getGenerator().getTerraGenerator() == null) + if(!TerraWorld.isTerraWorld(w)) throw new IllegalArgumentException("Attempted to instantiate profiler on non-Terra managed world!"); this.addMeasurement(new Measurement(2500000, DataType.PERIOD_MILLISECONDS), "TotalChunkGenTime") .addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "FloraTime") @@ -21,7 +22,7 @@ public class WorldProfiler { .addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "OreTime") .addMeasurement(new Measurement(5000000, DataType.PERIOD_MILLISECONDS), "CaveTime") .addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "StructureTime"); - ; + isProfiling = false; this.world = w; } diff --git a/common/src/main/java/com/dfsek/terra/registry/FunctionRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/FunctionRegistry.java similarity index 63% rename from common/src/main/java/com/dfsek/terra/registry/FunctionRegistry.java rename to common/src/main/java/com/dfsek/terra/registry/config/FunctionRegistry.java index dc3689d0a..6e0e465e6 100644 --- a/common/src/main/java/com/dfsek/terra/registry/FunctionRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/FunctionRegistry.java @@ -1,6 +1,7 @@ -package com.dfsek.terra.registry; +package com.dfsek.terra.registry.config; import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder; +import com.dfsek.terra.registry.TerraRegistry; public class FunctionRegistry extends TerraRegistry> { } diff --git a/common/src/main/java/com/dfsek/terra/registry/AddonRegistry.java b/common/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java similarity index 98% rename from common/src/main/java/com/dfsek/terra/registry/AddonRegistry.java rename to common/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java index d73799b67..40db3b7b0 100644 --- a/common/src/main/java/com/dfsek/terra/registry/AddonRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.registry; +package com.dfsek.terra.registry.master; import com.dfsek.terra.addons.addon.TerraAddon; import com.dfsek.terra.addons.injection.InjectionException; @@ -8,6 +8,7 @@ import com.dfsek.terra.addons.loading.AddonLoadException; import com.dfsek.terra.addons.loading.pre.AddonPool; import com.dfsek.terra.addons.loading.pre.PreLoadAddon; import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.registry.TerraRegistry; import java.io.File; import java.io.IOException; diff --git a/common/src/main/java/com/dfsek/terra/registry/master/ChunkGeneratorRegistry.java b/common/src/main/java/com/dfsek/terra/registry/master/ChunkGeneratorRegistry.java new file mode 100644 index 000000000..93ee25e94 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/registry/master/ChunkGeneratorRegistry.java @@ -0,0 +1,7 @@ +package com.dfsek.terra.registry.master; + +import com.dfsek.terra.api.platform.world.generator.ChunkGenerator; +import com.dfsek.terra.registry.TerraRegistry; + +public class ChunkGeneratorRegistry extends TerraRegistry { +} diff --git a/common/src/main/java/com/dfsek/terra/registry/ConfigRegistry.java b/common/src/main/java/com/dfsek/terra/registry/master/ConfigRegistry.java similarity index 94% rename from common/src/main/java/com/dfsek/terra/registry/ConfigRegistry.java rename to common/src/main/java/com/dfsek/terra/registry/master/ConfigRegistry.java index 8532cf535..0cf923850 100644 --- a/common/src/main/java/com/dfsek/terra/registry/ConfigRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/master/ConfigRegistry.java @@ -1,8 +1,9 @@ -package com.dfsek.terra.registry; +package com.dfsek.terra.registry.master; import com.dfsek.tectonic.exception.ConfigException; import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.config.pack.ConfigPack; +import com.dfsek.terra.registry.TerraRegistry; import java.io.File; import java.io.IOException; diff --git a/common/src/main/java/com/dfsek/terra/world/TerraWorld.java b/common/src/main/java/com/dfsek/terra/world/TerraWorld.java index 6a607008d..0dd3d9129 100644 --- a/common/src/main/java/com/dfsek/terra/world/TerraWorld.java +++ b/common/src/main/java/com/dfsek/terra/world/TerraWorld.java @@ -6,7 +6,7 @@ import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.world.World; -import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper; +import com.dfsek.terra.api.platform.world.generator.ChunkGenerator; import com.dfsek.terra.api.world.biome.UserDefinedBiome; import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.api.world.palette.Palette; @@ -40,7 +40,7 @@ public class TerraWorld { } public static boolean isTerraWorld(World w) { - return w.getGenerator().getHandle() instanceof GeneratorWrapper; + return w.getGenerator().getHandle() instanceof ChunkGenerator; } public BiomeProvider getBiomeProvider() { diff --git a/common/src/main/java/com/dfsek/terra/world/generation/MasterChunkGenerator.java b/common/src/main/java/com/dfsek/terra/world/generation/MasterChunkGenerator.java index e51131e7c..ef9415f52 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/MasterChunkGenerator.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/MasterChunkGenerator.java @@ -12,7 +12,7 @@ import com.dfsek.terra.api.platform.block.data.Stairs; import com.dfsek.terra.api.platform.block.data.Waterlogged; import com.dfsek.terra.api.platform.world.BiomeGrid; import com.dfsek.terra.api.platform.world.World; -import com.dfsek.terra.api.platform.world.generator.ChunkGenerator; +import com.dfsek.terra.api.platform.world.generator.ChunkData; import com.dfsek.terra.api.util.world.PaletteUtil; import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.UserDefinedBiome; @@ -92,7 +92,7 @@ public class MasterChunkGenerator implements TerraChunkGenerator { @Override @SuppressWarnings({"try"}) - public ChunkGenerator.ChunkData generateChunkData(@NotNull World world, Random random, int chunkX, int chunkZ, ChunkGenerator.ChunkData chunk) { + public ChunkData generateChunkData(@NotNull World world, Random random, int chunkX, int chunkZ, ChunkData chunk) { TerraWorld tw = main.getWorld(world); BiomeProvider grid = tw.getBiomeProvider(); try(ProfileFuture ignore = tw.getProfiler().measure("TotalChunkGenTime")) { @@ -151,7 +151,7 @@ public class MasterChunkGenerator implements TerraChunkGenerator { } } - private void prepareBlockPartFloor(BlockData down, BlockData orig, ChunkGenerator.ChunkData chunk, Vector3 block, Map> slabs, + private void prepareBlockPartFloor(BlockData down, BlockData orig, ChunkData chunk, Vector3 block, Map> slabs, Map> stairs, double thresh, Sampler sampler) { if(sampler.sample(block.getX(), block.getY() - 0.4, block.getZ()) > thresh) { if(stairs != null) { @@ -172,7 +172,7 @@ public class MasterChunkGenerator implements TerraChunkGenerator { } } - private void prepareBlockPartCeiling(BlockData up, BlockData orig, ChunkGenerator.ChunkData chunk, Vector3 block, Map> slabs, + private void prepareBlockPartCeiling(BlockData up, BlockData orig, ChunkData chunk, Vector3 block, Map> slabs, Map> stairs, double thresh, Sampler sampler) { if(sampler.sample(block.getX(), block.getY() + 0.4, block.getZ()) > thresh) { if(stairs != null) { @@ -196,7 +196,7 @@ public class MasterChunkGenerator implements TerraChunkGenerator { } } - private boolean placeStair(BlockData orig, ChunkGenerator.ChunkData chunk, Vector3 block, double thresh, Sampler sampler, Stairs stairNew) { + private boolean placeStair(BlockData orig, ChunkData chunk, Vector3 block, double thresh, Sampler sampler, Stairs stairNew) { if(sampler.sample(block.getBlockX() - 0.55, block.getY(), block.getZ()) > thresh) { diff --git a/common/src/test/java/biome/DistributionTest.java b/common/src/test/java/biome/DistributionTest.java index 464c93a33..2f91fb2a3 100644 --- a/common/src/test/java/biome/DistributionTest.java +++ b/common/src/test/java/biome/DistributionTest.java @@ -34,10 +34,10 @@ import com.dfsek.terra.config.loaders.config.sampler.NoiseSamplerBuilderLoader; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.config.templates.AbstractableTemplate; import com.dfsek.terra.debug.DebugLogger; -import com.dfsek.terra.registry.AddonRegistry; -import com.dfsek.terra.registry.ConfigRegistry; import com.dfsek.terra.registry.config.BiomeRegistry; import com.dfsek.terra.registry.config.NoiseRegistry; +import com.dfsek.terra.registry.master.AddonRegistry; +import com.dfsek.terra.registry.master.ConfigRegistry; import com.dfsek.terra.world.TerraWorld; import javax.swing.*; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java index 7e62cd637..75d296d81 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java @@ -31,8 +31,8 @@ import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.Language; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.debug.DebugLogger; -import com.dfsek.terra.registry.AddonRegistry; -import com.dfsek.terra.registry.ConfigRegistry; +import com.dfsek.terra.registry.master.AddonRegistry; +import com.dfsek.terra.registry.master.ConfigRegistry; import com.dfsek.terra.world.TerraWorld; import com.dfsek.terra.world.generation.MasterChunkGenerator; import io.papermc.lib.PaperLib; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/PacksCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/PacksCommand.java index ce768d37a..2a36c4986 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/PacksCommand.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/PacksCommand.java @@ -4,7 +4,7 @@ import com.dfsek.terra.bukkit.BukkitCommandSender; import com.dfsek.terra.bukkit.command.Command; import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.pack.ConfigPackTemplate; -import com.dfsek.terra.registry.ConfigRegistry; +import com.dfsek.terra.registry.master.ConfigRegistry; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGenerator.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGenerator.java index b1875f1ff..da186a425 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGenerator.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGenerator.java @@ -1,20 +1,10 @@ package com.dfsek.terra.bukkit.generator; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.platform.world.BiomeGrid; -import com.dfsek.terra.api.platform.world.World; -import com.dfsek.terra.api.platform.world.generator.BlockPopulator; -import com.dfsek.terra.api.world.generation.TerraChunkGenerator; -import com.dfsek.terra.bukkit.world.BukkitBiomeGrid; -import com.dfsek.terra.bukkit.world.BukkitWorld; +import com.dfsek.terra.api.platform.world.generator.ChunkData; import com.dfsek.terra.bukkit.world.block.data.BukkitBlockData; import org.bukkit.generator.ChunkGenerator; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; -import java.util.Random; -import java.util.stream.Collectors; public class BukkitChunkGenerator implements com.dfsek.terra.api.platform.world.generator.ChunkGenerator { private final ChunkGenerator delegate; @@ -28,46 +18,6 @@ public class BukkitChunkGenerator implements com.dfsek.terra.api.platform.world. return delegate; } - @Override - public boolean isParallelCapable() { - return delegate.isParallelCapable(); - } - - @Override - public boolean shouldGenerateCaves() { - return delegate.shouldGenerateCaves(); - } - - @Override - public boolean shouldGenerateDecorations() { - return delegate.shouldGenerateDecorations(); - } - - @Override - public boolean shouldGenerateMobs() { - return delegate.shouldGenerateMobs(); - } - - @Override - public boolean shouldGenerateStructures() { - return delegate.shouldGenerateStructures(); - } - - @Override - public ChunkData generateChunkData(@NotNull World world, @NotNull Random random, int x, int z, @NotNull BiomeGrid biome) { - return new BukkitChunkData(delegate.generateChunkData(((BukkitWorld) world).getHandle(), random, x, z, ((BukkitBiomeGrid) biome).getHandle())); - } - - @Override - public List getDefaultPopulators(World world) { - return delegate.getDefaultPopulators(((BukkitWorld) world).getHandle()).stream().map(BukkitPopulator::new).collect(Collectors.toList()); - } - - @Override - public @Nullable TerraChunkGenerator getTerraGenerator() { - return delegate instanceof BukkitChunkGeneratorWrapper ? ((BukkitChunkGeneratorWrapper) delegate).getHandle() : null; - } - public static class BukkitChunkData implements ChunkData { private final ChunkGenerator.ChunkData delegate; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java index 81e305834..8c0e5bb09 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java @@ -2,7 +2,6 @@ package com.dfsek.terra.bukkit.generator; import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.platform.world.Chunk; -import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper; import com.dfsek.terra.api.world.generation.TerraBlockPopulator; import com.dfsek.terra.api.world.generation.TerraChunkGenerator; import com.dfsek.terra.bukkit.population.PopulationManager; @@ -32,7 +31,7 @@ import java.util.Random; import java.util.logging.Level; import java.util.stream.Collectors; -public class BukkitChunkGeneratorWrapper extends ChunkGenerator implements GeneratorWrapper { +public class BukkitChunkGeneratorWrapper extends ChunkGenerator implements com.dfsek.terra.api.platform.world.generator.ChunkGenerator { private static final Map popMap = new HashMap<>(); @@ -123,7 +122,7 @@ public class BukkitChunkGeneratorWrapper extends ChunkGenerator implements Gener @Override public boolean shouldGenerateStructures() { - return super.shouldGenerateStructures(); + return delegate.shouldGenerateStructures(); } @Override diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index cb6baa70a..c57fb5dc4 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -26,8 +26,8 @@ import com.dfsek.terra.fabric.world.FabricWorldHandle; import com.dfsek.terra.fabric.world.TerraBiomeSource; import com.dfsek.terra.fabric.world.features.PopulatorFeature; import com.dfsek.terra.fabric.world.generator.FabricChunkGeneratorWrapper; -import com.dfsek.terra.registry.AddonRegistry; -import com.dfsek.terra.registry.ConfigRegistry; +import com.dfsek.terra.registry.master.AddonRegistry; +import com.dfsek.terra.registry.master.ConfigRegistry; import com.dfsek.terra.world.TerraWorld; import net.fabricmc.api.EnvType; import net.fabricmc.api.ModInitializer; @@ -200,7 +200,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { return debugLogger; } - Transformer biomeFixer = new Transformer.Builder() + private Transformer biomeFixer = new Transformer.Builder() .addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse(id)), new NotNullValidator<>()) .addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse("minecraft:" + id.toLowerCase())), new NotNullValidator<>()).build(); @@ -286,7 +286,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { Registry.register(Registry.CHUNK_GENERATOR, new Identifier("terra:terra"), FabricChunkGeneratorWrapper.CODEC); Registry.register(Registry.BIOME_SOURCE, new Identifier("terra:terra"), TerraBiomeSource.CODEC); - if(FabricLoader.getInstance().getEnvironmentType().equals(EnvType.CLIENT)) { + if(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { GeneratorTypeAccessor.getValues().add(new GeneratorType("terra") { @Override protected ChunkGenerator getChunkGenerator(Registry biomeRegistry, Registry chunkGeneratorSettingsRegistry, long seed) { diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkData.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkData.java index 9864c472f..24ea33e9b 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkData.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkData.java @@ -1,13 +1,13 @@ package com.dfsek.terra.fabric.world.generator; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.platform.world.generator.ChunkGenerator; +import com.dfsek.terra.api.platform.world.generator.ChunkData; import com.dfsek.terra.fabric.world.block.FabricBlockData; import net.minecraft.util.math.BlockPos; import net.minecraft.world.chunk.Chunk; import org.jetbrains.annotations.NotNull; -public class FabricChunkData implements ChunkGenerator.ChunkData { +public class FabricChunkData implements ChunkData { private final Chunk handle; public FabricChunkData(Chunk handle) { diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGenerator.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGenerator.java index 52b4c0d5f..ae7526326 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGenerator.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGenerator.java @@ -1,15 +1,6 @@ package com.dfsek.terra.fabric.world.generator; -import com.dfsek.terra.api.platform.world.BiomeGrid; -import com.dfsek.terra.api.platform.world.World; -import com.dfsek.terra.api.platform.world.generator.BlockPopulator; import com.dfsek.terra.api.platform.world.generator.ChunkGenerator; -import com.dfsek.terra.api.world.generation.TerraChunkGenerator; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; -import java.util.Random; public class FabricChunkGenerator implements ChunkGenerator { private final net.minecraft.world.gen.chunk.ChunkGenerator delegate; @@ -18,47 +9,6 @@ public class FabricChunkGenerator implements ChunkGenerator { this.delegate = delegate; } - @Override - public boolean isParallelCapable() { - return false; - } - - @Override - public boolean shouldGenerateCaves() { - return false; - } - - @Override - public boolean shouldGenerateDecorations() { - return false; - } - - @Override - public boolean shouldGenerateMobs() { - return false; - } - - @Override - public boolean shouldGenerateStructures() { - return false; - } - - @Override - public ChunkData generateChunkData(@NotNull World world, @NotNull Random random, int x, int z, @NotNull BiomeGrid biome) { - return null; - } - - @Override - public List getDefaultPopulators(World world) { - return null; - } - - @Override - public @Nullable TerraChunkGenerator getTerraGenerator() { - if(delegate instanceof FabricChunkGeneratorWrapper) return ((FabricChunkGeneratorWrapper) delegate).getHandle(); - return null; - } - @Override public net.minecraft.world.gen.chunk.ChunkGenerator getHandle() { return delegate; diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java index 898c230d9..dfc83d37b 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java @@ -1,6 +1,5 @@ package com.dfsek.terra.fabric.world.generator; -import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper; import com.dfsek.terra.api.util.FastRandom; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.fabric.TerraFabricPlugin; @@ -30,7 +29,7 @@ import net.minecraft.world.gen.chunk.ChunkGenerator; import net.minecraft.world.gen.chunk.StructuresConfig; import net.minecraft.world.gen.chunk.VerticalBlockSample; -public class FabricChunkGeneratorWrapper extends ChunkGenerator implements GeneratorWrapper { +public class FabricChunkGeneratorWrapper extends ChunkGenerator implements com.dfsek.terra.api.platform.world.generator.ChunkGenerator { private final long seed; private final MasterChunkGenerator delegate; private final TerraBiomeSource biomeSource; diff --git a/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java b/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java index 0f6eb97c2..aa918951a 100644 --- a/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java +++ b/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java @@ -17,8 +17,8 @@ import com.dfsek.terra.config.lang.Language; import com.dfsek.terra.debug.DebugLogger; import com.dfsek.terra.platform.RawBiome; import com.dfsek.terra.platform.RawWorldHandle; -import com.dfsek.terra.registry.AddonRegistry; -import com.dfsek.terra.registry.ConfigRegistry; +import com.dfsek.terra.registry.master.AddonRegistry; +import com.dfsek.terra.registry.master.ConfigRegistry; import com.dfsek.terra.world.TerraWorld; import java.io.File; diff --git a/platforms/region/src/main/java/com/dfsek/terra/platform/DirectChunkData.java b/platforms/region/src/main/java/com/dfsek/terra/platform/DirectChunkData.java index 2705e70e2..4eac21cce 100644 --- a/platforms/region/src/main/java/com/dfsek/terra/platform/DirectChunkData.java +++ b/platforms/region/src/main/java/com/dfsek/terra/platform/DirectChunkData.java @@ -4,12 +4,12 @@ import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.Block; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.world.World; -import com.dfsek.terra.api.platform.world.generator.ChunkGenerator; +import com.dfsek.terra.api.platform.world.generator.ChunkData; import net.querz.mca.Chunk; import net.querz.nbt.tag.CompoundTag; import org.jetbrains.annotations.NotNull; -public class DirectChunkData implements ChunkGenerator.ChunkData, com.dfsek.terra.api.platform.world.Chunk { +public class DirectChunkData implements ChunkData, com.dfsek.terra.api.platform.world.Chunk { private final Chunk delegate; private final DirectWorld world; private final int x; diff --git a/platforms/region/src/main/java/com/dfsek/terra/platform/GenWrapper.java b/platforms/region/src/main/java/com/dfsek/terra/platform/GenWrapper.java index 25118e8bf..e41fb743f 100644 --- a/platforms/region/src/main/java/com/dfsek/terra/platform/GenWrapper.java +++ b/platforms/region/src/main/java/com/dfsek/terra/platform/GenWrapper.java @@ -1,17 +1,7 @@ package com.dfsek.terra.platform; -import com.dfsek.terra.api.platform.world.BiomeGrid; -import com.dfsek.terra.api.platform.world.World; -import com.dfsek.terra.api.platform.world.generator.BlockPopulator; import com.dfsek.terra.api.platform.world.generator.ChunkGenerator; -import com.dfsek.terra.api.world.generation.TerraChunkGenerator; import com.dfsek.terra.world.generation.MasterChunkGenerator; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collections; -import java.util.List; -import java.util.Random; public class GenWrapper implements ChunkGenerator { private final MasterChunkGenerator generator; @@ -25,43 +15,4 @@ public class GenWrapper implements ChunkGenerator { return generator; } - @Override - public boolean isParallelCapable() { - return true; - } - - @Override - public boolean shouldGenerateCaves() { - return true; - } - - @Override - public boolean shouldGenerateDecorations() { - return true; - } - - @Override - public boolean shouldGenerateMobs() { - return true; - } - - @Override - public boolean shouldGenerateStructures() { - return true; - } - - @Override - public ChunkData generateChunkData(@NotNull World world, @NotNull Random random, int x, int z, @NotNull BiomeGrid biome) { - throw new UnsupportedOperationException(); // gen is directly handled by Generator - } - - @Override - public List getDefaultPopulators(World world) { - return Collections.emptyList(); - } - - @Override - public @Nullable TerraChunkGenerator getTerraGenerator() { - return generator; - } } From 03e9f6b8824bf76b5b5b4ac630b8f9fcbe11dd9d Mon Sep 17 00:00:00 2001 From: dfsek Date: Sat, 20 Feb 2021 23:59:17 -0700 Subject: [PATCH 06/95] more cleanup --- .../api/structures/script/StructureScript.java | 4 ++-- .../world/generation/TerraChunkGenerator.java | 3 +++ .../DefaultChunkGenerator3D.java} | 17 ++++++++--------- .../interpolation/BiomeChunkInterpolator.java | 4 ++-- .../interpolation/NoiseChunkInterpolator.java | 4 ++-- .../dfsek/terra/bukkit/TerraBukkitPlugin.java | 11 ++++++----- .../dfsek/terra/fabric/TerraFabricPlugin.java | 2 +- .../generator/FabricChunkGeneratorWrapper.java | 8 ++++---- .../com/dfsek/terra/platform/GenWrapper.java | 6 +++--- .../java/com/dfsek/terra/region/Generator.java | 6 +++--- 10 files changed, 34 insertions(+), 31 deletions(-) rename common/src/main/java/com/dfsek/terra/world/generation/{MasterChunkGenerator.java => generators/DefaultChunkGenerator3D.java} (95%) diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java b/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java index 232a931f6..219d8092d 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java @@ -57,6 +57,8 @@ public class StructureScript { throw new RuntimeException(e); } + functionRegistry.forEach(parser::registerFunction); // Register registry functions. + parser.registerFunction("block", new BlockFunctionBuilder(main)) .registerFunction("check", new CheckFunctionBuilder(main, cache)) .registerFunction("structure", new StructureFunctionBuilder(registry, main)) @@ -86,8 +88,6 @@ public class StructureScript { .registerFunction("max", new BinaryNumberFunctionBuilder((number, number2) -> FastMath.max(number.doubleValue(), number2.doubleValue()))) .registerFunction("min", new BinaryNumberFunctionBuilder((number, number2) -> FastMath.min(number.doubleValue(), number2.doubleValue()))); - functionRegistry.forEach(parser::registerFunction); // Register registry functions. - block = parser.parse(); this.id = parser.getID(); tempID = id; diff --git a/common/src/main/java/com/dfsek/terra/api/world/generation/TerraChunkGenerator.java b/common/src/main/java/com/dfsek/terra/api/world/generation/TerraChunkGenerator.java index 94b89a983..f5f91e69c 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/generation/TerraChunkGenerator.java +++ b/common/src/main/java/com/dfsek/terra/api/world/generation/TerraChunkGenerator.java @@ -5,6 +5,7 @@ import com.dfsek.terra.api.platform.world.BiomeGrid; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.platform.world.generator.ChunkData; import com.dfsek.terra.config.pack.ConfigPack; +import com.dfsek.terra.world.generation.math.SamplerCache; import org.jetbrains.annotations.NotNull; import java.util.Random; @@ -27,4 +28,6 @@ public interface TerraChunkGenerator { ConfigPack getConfigPack(); TerraPlugin getMain(); + + SamplerCache getCache(); } diff --git a/common/src/main/java/com/dfsek/terra/world/generation/MasterChunkGenerator.java b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java similarity index 95% rename from common/src/main/java/com/dfsek/terra/world/generation/MasterChunkGenerator.java rename to common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java index ef9415f52..693c1db85 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/MasterChunkGenerator.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.world.generation; +package com.dfsek.terra.world.generation.generators; import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.math.Range; @@ -33,9 +33,7 @@ import org.jetbrains.annotations.NotNull; import java.util.Map; import java.util.Random; -public class MasterChunkGenerator implements TerraChunkGenerator { - - +public class DefaultChunkGenerator3D implements TerraChunkGenerator { private final ConfigPack configPack; private final TerraPlugin main; private final MaterialData water; @@ -46,7 +44,7 @@ public class MasterChunkGenerator implements TerraChunkGenerator { private final SamplerCache cache; - public MasterChunkGenerator(ConfigPack c, TerraPlugin main, SamplerCache cache) { + public DefaultChunkGenerator3D(ConfigPack c, TerraPlugin main, SamplerCache cache) { this.configPack = c; this.main = main; carver = new NoiseCarver(new Range(0, 255), main.getWorldHandle().createBlockData("minecraft:air"), main); @@ -102,8 +100,8 @@ public class MasterChunkGenerator implements TerraChunkGenerator { Sampler sampler = cache.getChunk(world, chunkX, chunkZ); - for(byte x = 0; x < 16; x++) { - for(byte z = 0; z < 16; z++) { + for(int x = 0; x < 16; x++) { + for(int z = 0; z < 16; z++) { int paletteLevel = 0; int cx = xOrig + x; @@ -222,16 +220,17 @@ public class MasterChunkGenerator implements TerraChunkGenerator { int zOrig = (chunkZ << 4); BiomeProvider grid = main.getWorld(world).getBiomeProvider(); for(int x = 0; x < 4; x++) { - for(byte z = 0; z < 4; z++) { + for(int z = 0; z < 4; z++) { int cx = xOrig + (x << 2); int cz = zOrig + (z << 2); TerraBiome b = grid.getBiome(cx, cz); - biome.setBiome(x << 2, z << 2, b.getVanillaBiomes().get(b.getGenerator(world).getBiomeNoise(), cx, 0, cz)); + biome.setBiome(cx, cz, b.getVanillaBiomes().get(b.getGenerator(world).getBiomeNoise(), cx, 0, cz)); } } } + @Override public SamplerCache getCache() { return cache; } diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/BiomeChunkInterpolator.java b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/BiomeChunkInterpolator.java index 2561d9311..5f9d4c0d5 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/BiomeChunkInterpolator.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/BiomeChunkInterpolator.java @@ -53,8 +53,8 @@ public class BiomeChunkInterpolator implements ChunkInterpolator { } } - for(byte x = 0; x < 4; x++) { - for(byte z = 0; z < 4; z++) { + for(int x = 0; x < 4; x++) { + for(int z = 0; z < 4; z++) { for(int y = 0; y < 64; y++) { interpGrid[x][y][z] = new Interpolator3( noiseStorage[x][z][y], diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/NoiseChunkInterpolator.java b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/NoiseChunkInterpolator.java index ec845d7ad..0ba964824 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/NoiseChunkInterpolator.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/NoiseChunkInterpolator.java @@ -20,8 +20,8 @@ public class NoiseChunkInterpolator implements ChunkInterpolator { } } - for(byte x = 0; x < 4; x++) { - for(byte z = 0; z < 4; z++) { + for(int x = 0; x < 4; x++) { + for(int z = 0; z < 4; z++) { for(int y = 0; y < 64; y++) { interpGrid[x][y][z] = new Interpolator3( noiseStorage[x][z][y], diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java index 75d296d81..ce150c8e7 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java @@ -14,6 +14,7 @@ import com.dfsek.terra.api.platform.handle.ItemHandle; import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.api.platform.world.Biome; import com.dfsek.terra.api.platform.world.World; +import com.dfsek.terra.api.world.generation.TerraChunkGenerator; import com.dfsek.terra.bukkit.command.command.TerraCommand; import com.dfsek.terra.bukkit.command.command.structure.LocateCommand; import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper; @@ -34,7 +35,7 @@ import com.dfsek.terra.debug.DebugLogger; import com.dfsek.terra.registry.master.AddonRegistry; import com.dfsek.terra.registry.master.ConfigRegistry; import com.dfsek.terra.world.TerraWorld; -import com.dfsek.terra.world.generation.MasterChunkGenerator; +import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D; import io.papermc.lib.PaperLib; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; @@ -51,7 +52,7 @@ import java.util.Objects; public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { - private final Map generatorMap = new HashMap<>(); + private final Map generatorMap = new HashMap<>(); private final Map worldMap = new HashMap<>(); private final Map worlds = new HashMap<>(); private final ConfigRegistry registry = new ConfigRegistry(); @@ -80,7 +81,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { public void reload() { Map newMap = new HashMap<>(); worldMap.forEach((world, tw) -> { - ((MasterChunkGenerator) ((BukkitChunkGeneratorWrapper) world.getGenerator().getHandle()).getHandle()).getCache().clear(); + ((BukkitChunkGeneratorWrapper) world.getGenerator().getHandle()).getHandle().getCache().clear(); String packID = tw.getConfig().getTemplate().getID(); newMap.put(world, new TerraWorld(world, registry.get(packID), this)); }); @@ -205,7 +206,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { if(!registry.contains(id)) throw new IllegalArgumentException("No such config pack \"" + id + "\""); ConfigPack pack = registry.get(id); worlds.put(worldName, pack); - return new MasterChunkGenerator(registry.get(id), this, pack.getSamplerCache()); + return new DefaultChunkGenerator3D(registry.get(id), this, pack.getSamplerCache()); })); } @@ -229,7 +230,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { throw new IllegalArgumentException("Not a Terra world! " + w.getGenerator()); if(!worlds.containsKey(w.getName())) { getLogger().warning("Unexpected world load detected: \"" + w.getName() + "\""); - return new TerraWorld(w, ((MasterChunkGenerator) w.getGenerator().getHandle()).getConfigPack(), this); + return new TerraWorld(w, ((TerraChunkGenerator) w.getGenerator().getHandle()).getConfigPack(), this); } return worldMap.computeIfAbsent(w, world -> new TerraWorld(w, worlds.get(w.getName()), this)); } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index c57fb5dc4..50c9da071 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -200,7 +200,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { return debugLogger; } - private Transformer biomeFixer = new Transformer.Builder() + private final Transformer biomeFixer = new Transformer.Builder() .addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse(id)), new NotNullValidator<>()) .addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse("minecraft:" + id.toLowerCase())), new NotNullValidator<>()).build(); diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java index dfc83d37b..16bc8983d 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java @@ -5,7 +5,7 @@ import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.fabric.TerraFabricPlugin; import com.dfsek.terra.fabric.world.TerraBiomeSource; import com.dfsek.terra.fabric.world.handles.world.FabricSeededWorldAccess; -import com.dfsek.terra.world.generation.MasterChunkGenerator; +import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D; import com.dfsek.terra.world.population.FloraPopulator; import com.dfsek.terra.world.population.OrePopulator; import com.dfsek.terra.world.population.StructurePopulator; @@ -31,7 +31,7 @@ import net.minecraft.world.gen.chunk.VerticalBlockSample; public class FabricChunkGeneratorWrapper extends ChunkGenerator implements com.dfsek.terra.api.platform.world.generator.ChunkGenerator { private final long seed; - private final MasterChunkGenerator delegate; + private final DefaultChunkGenerator3D delegate; private final TerraBiomeSource biomeSource; public static final Codec PACK_CODEC = (RecordCodecBuilder.create(config -> config.group( Codec.STRING.fieldOf("pack").forGetter(pack -> pack.getTemplate().getID()) @@ -69,7 +69,7 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements com.d super(biomeSource, new StructuresConfig(false)); this.pack = configPack; - this.delegate = new MasterChunkGenerator(configPack, TerraFabricPlugin.getInstance(), pack.getSamplerCache()); + this.delegate = new DefaultChunkGenerator3D(configPack, TerraFabricPlugin.getInstance(), pack.getSamplerCache()); delegate.getMain().getLogger().info("Loading world..."); this.biomeSource = biomeSource; @@ -77,7 +77,7 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements com.d } @Override - public MasterChunkGenerator getHandle() { + public DefaultChunkGenerator3D getHandle() { return delegate; } diff --git a/platforms/region/src/main/java/com/dfsek/terra/platform/GenWrapper.java b/platforms/region/src/main/java/com/dfsek/terra/platform/GenWrapper.java index e41fb743f..7de56d5bf 100644 --- a/platforms/region/src/main/java/com/dfsek/terra/platform/GenWrapper.java +++ b/platforms/region/src/main/java/com/dfsek/terra/platform/GenWrapper.java @@ -1,12 +1,12 @@ package com.dfsek.terra.platform; import com.dfsek.terra.api.platform.world.generator.ChunkGenerator; -import com.dfsek.terra.world.generation.MasterChunkGenerator; +import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D; public class GenWrapper implements ChunkGenerator { - private final MasterChunkGenerator generator; + private final DefaultChunkGenerator3D generator; - public GenWrapper(MasterChunkGenerator generator) { + public GenWrapper(DefaultChunkGenerator3D generator) { this.generator = generator; } diff --git a/platforms/region/src/main/java/com/dfsek/terra/region/Generator.java b/platforms/region/src/main/java/com/dfsek/terra/region/Generator.java index 4f425e224..616cc20ec 100644 --- a/platforms/region/src/main/java/com/dfsek/terra/region/Generator.java +++ b/platforms/region/src/main/java/com/dfsek/terra/region/Generator.java @@ -4,7 +4,7 @@ import com.dfsek.terra.StandalonePlugin; import com.dfsek.terra.platform.DirectChunkData; import com.dfsek.terra.platform.DirectWorld; import com.dfsek.terra.platform.GenWrapper; -import com.dfsek.terra.world.generation.MasterChunkGenerator; +import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D; import com.dfsek.terra.world.generation.math.SamplerCache; import com.dfsek.terra.world.population.FloraPopulator; import com.dfsek.terra.world.population.OrePopulator; @@ -23,7 +23,7 @@ public class Generator { StructurePopulator structurePopulator; TreePopulator treePopulator; OrePopulator orePopulator; - MasterChunkGenerator generator; + DefaultChunkGenerator3D generator; public Generator(long seed, StandalonePlugin plugin) { plugin.load(); @@ -31,7 +31,7 @@ public class Generator { structurePopulator = new StructurePopulator(plugin); treePopulator = new TreePopulator(plugin); orePopulator = new OrePopulator(plugin); - generator = new MasterChunkGenerator(plugin.getRegistry().get("DEFAULT"), plugin, new SamplerCache(plugin)); + generator = new DefaultChunkGenerator3D(plugin.getRegistry().get("DEFAULT"), plugin, new SamplerCache(plugin)); this.seed = seed; } From e00209c99ccff2660c1666b1f55ef29145abf0c2 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 21 Feb 2021 14:19:42 -0700 Subject: [PATCH 07/95] rework chunkgenerator API to allow easier extension --- .../com/dfsek/terra/api/math/MathUtil.java | 2 +- .../noise/samplers/ExpressionSampler.java | 2 +- .../noise/samplers/noise/ConstantSampler.java | 2 +- .../terra/api/util/world/PaletteUtil.java | 2 +- .../world/generation/TerraChunkGenerator.java | 4 + .../com/dfsek/terra/world/TerraWorld.java | 8 +- .../terra/world/carving/NoiseCarver.java | 4 +- .../generators/DefaultChunkGenerator2D.java | 139 ++++++++++++++++++ .../generators/DefaultChunkGenerator3D.java | 16 +- .../world/generation/math/SamplerCache.java | 5 +- .../math/interpolation/ChunkInterpolator.java | 21 +++ .../interpolation/ChunkInterpolator2D.java | 84 +++++++++++ ...rpolator.java => ChunkInterpolator3D.java} | 22 +-- .../math/interpolation/Interpolator.java | 1 - .../math/interpolation/Interpolator3.java | 18 +-- .../interpolation/NoiseChunkInterpolator.java | 48 ------ .../generation/math/samplers/Sampler.java | 6 + .../generation/math/samplers/Sampler2D.java | 22 +++ .../{Sampler.java => samplers/Sampler3D.java} | 17 +-- 19 files changed, 322 insertions(+), 101 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator2D.java create mode 100644 common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator2D.java rename common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/{BiomeChunkInterpolator.java => ChunkInterpolator3D.java} (79%) delete mode 100644 common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/NoiseChunkInterpolator.java create mode 100644 common/src/main/java/com/dfsek/terra/world/generation/math/samplers/Sampler.java create mode 100644 common/src/main/java/com/dfsek/terra/world/generation/math/samplers/Sampler2D.java rename common/src/main/java/com/dfsek/terra/world/generation/math/{Sampler.java => samplers/Sampler3D.java} (51%) diff --git a/common/src/main/java/com/dfsek/terra/api/math/MathUtil.java b/common/src/main/java/com/dfsek/terra/api/math/MathUtil.java index 8dd83ee90..77c1a43cf 100644 --- a/common/src/main/java/com/dfsek/terra/api/math/MathUtil.java +++ b/common/src/main/java/com/dfsek/terra/api/math/MathUtil.java @@ -1,7 +1,7 @@ package com.dfsek.terra.api.math; import com.dfsek.terra.api.util.FastRandom; -import com.dfsek.terra.world.generation.math.Sampler; +import com.dfsek.terra.world.generation.math.samplers.Sampler; import net.jafama.FastMath; import java.util.List; diff --git a/common/src/main/java/com/dfsek/terra/api/math/noise/samplers/ExpressionSampler.java b/common/src/main/java/com/dfsek/terra/api/math/noise/samplers/ExpressionSampler.java index 9b1fbbc4c..8ca8f2333 100644 --- a/common/src/main/java/com/dfsek/terra/api/math/noise/samplers/ExpressionSampler.java +++ b/common/src/main/java/com/dfsek/terra/api/math/noise/samplers/ExpressionSampler.java @@ -14,7 +14,7 @@ import com.dfsek.terra.config.loaders.config.function.FunctionTemplate; import java.util.Map; /** - * Sampler implementation using Paralithic expression + * Sampler3D implementation using Paralithic expression */ public class ExpressionSampler implements NoiseSampler { private final Expression expression; diff --git a/common/src/main/java/com/dfsek/terra/api/math/noise/samplers/noise/ConstantSampler.java b/common/src/main/java/com/dfsek/terra/api/math/noise/samplers/noise/ConstantSampler.java index a81756b92..203a1a85f 100644 --- a/common/src/main/java/com/dfsek/terra/api/math/noise/samplers/noise/ConstantSampler.java +++ b/common/src/main/java/com/dfsek/terra/api/math/noise/samplers/noise/ConstantSampler.java @@ -1,7 +1,7 @@ package com.dfsek.terra.api.math.noise.samplers.noise; /** - * Sampler implementation that returns a constant. + * Sampler3D implementation that returns a constant. */ public class ConstantSampler extends NoiseFunction { private final double constant; diff --git a/common/src/main/java/com/dfsek/terra/api/util/world/PaletteUtil.java b/common/src/main/java/com/dfsek/terra/api/util/world/PaletteUtil.java index 92e81aa57..69edf202e 100644 --- a/common/src/main/java/com/dfsek/terra/api/util/world/PaletteUtil.java +++ b/common/src/main/java/com/dfsek/terra/api/util/world/PaletteUtil.java @@ -5,7 +5,7 @@ import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.world.palette.Palette; import com.dfsek.terra.api.world.palette.holder.PaletteHolder; import com.dfsek.terra.config.templates.BiomeTemplate; -import com.dfsek.terra.world.generation.math.Sampler; +import com.dfsek.terra.world.generation.math.samplers.Sampler; public final class PaletteUtil { public static Palette getPalette(int x, int y, int z, BiomeTemplate c, Sampler sampler) { diff --git a/common/src/main/java/com/dfsek/terra/api/world/generation/TerraChunkGenerator.java b/common/src/main/java/com/dfsek/terra/api/world/generation/TerraChunkGenerator.java index f5f91e69c..71b9e8f90 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/generation/TerraChunkGenerator.java +++ b/common/src/main/java/com/dfsek/terra/api/world/generation/TerraChunkGenerator.java @@ -4,8 +4,10 @@ import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.platform.world.BiomeGrid; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.platform.world.generator.ChunkData; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.world.generation.math.SamplerCache; +import com.dfsek.terra.world.generation.math.samplers.Sampler; import org.jetbrains.annotations.NotNull; import java.util.Random; @@ -30,4 +32,6 @@ public interface TerraChunkGenerator { TerraPlugin getMain(); SamplerCache getCache(); + + Sampler createSampler(int chunkX, int chunkZ, BiomeProvider provider, World world, int elevationSmooth); } diff --git a/common/src/main/java/com/dfsek/terra/world/TerraWorld.java b/common/src/main/java/com/dfsek/terra/world/TerraWorld.java index 0dd3d9129..236224aa6 100644 --- a/common/src/main/java/com/dfsek/terra/world/TerraWorld.java +++ b/common/src/main/java/com/dfsek/terra/world/TerraWorld.java @@ -9,10 +9,11 @@ import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.platform.world.generator.ChunkGenerator; import com.dfsek.terra.api.world.biome.UserDefinedBiome; import com.dfsek.terra.api.world.biome.provider.BiomeProvider; +import com.dfsek.terra.api.world.generation.TerraChunkGenerator; import com.dfsek.terra.api.world.palette.Palette; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.profiler.WorldProfiler; -import com.dfsek.terra.world.generation.math.Sampler; +import com.dfsek.terra.world.generation.math.samplers.Sampler; import net.jafama.FastMath; public class TerraWorld { @@ -25,6 +26,7 @@ public class TerraWorld { public TerraWorld(World w, ConfigPack c, TerraPlugin main) { + if(!isTerraWorld(w)) throw new IllegalArgumentException("World " + w + " is not a Terra World!"); c.getBiomeRegistry().forEach(biome -> biome.getGenerator(w)); // Load all gens to cache config = c; profiler = new WorldProfiler(w); @@ -35,6 +37,10 @@ public class TerraWorld { safe = true; } + public TerraChunkGenerator getGenerator() { + return (TerraChunkGenerator) ((ChunkGenerator) world.getGenerator().getHandle()).getHandle(); + } + public World getWorld() { return world; } diff --git a/common/src/main/java/com/dfsek/terra/world/carving/NoiseCarver.java b/common/src/main/java/com/dfsek/terra/world/carving/NoiseCarver.java index 1fdf39c6b..04b961a90 100644 --- a/common/src/main/java/com/dfsek/terra/world/carving/NoiseCarver.java +++ b/common/src/main/java/com/dfsek/terra/world/carving/NoiseCarver.java @@ -6,8 +6,8 @@ import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.world.ChunkAccess; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.world.Carver; -import com.dfsek.terra.world.generation.math.interpolation.BiomeChunkInterpolator; import com.dfsek.terra.world.generation.math.interpolation.ChunkInterpolator; +import com.dfsek.terra.world.generation.math.interpolation.ChunkInterpolator3D; public class NoiseCarver implements Carver { private final Range range; @@ -22,7 +22,7 @@ public class NoiseCarver implements Carver { @Override public void carve(World world, int chunkX, int chunkZ, ChunkAccess chunk) { - ChunkInterpolator interpolator = new BiomeChunkInterpolator(world, chunkX, chunkZ, main.getWorld(world).getBiomeProvider(), (gen, coord) -> gen.getCarver().getNoise(coord.setY(coord.getY()))); + ChunkInterpolator interpolator = new ChunkInterpolator3D(world, chunkX, chunkZ, main.getWorld(world).getBiomeProvider(), (gen, coord) -> gen.getCarver().getNoise(coord.setY(coord.getY()))); for(int y : range) { for(int x = 0; x < 16; x++) { for(int z = 0; z < 16; z++) { diff --git a/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator2D.java b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator2D.java new file mode 100644 index 000000000..b1c468768 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator2D.java @@ -0,0 +1,139 @@ +package com.dfsek.terra.world.generation.generators; + +import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.math.Range; +import com.dfsek.terra.api.platform.block.BlockData; +import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.platform.world.BiomeGrid; +import com.dfsek.terra.api.platform.world.World; +import com.dfsek.terra.api.platform.world.generator.ChunkData; +import com.dfsek.terra.api.util.world.PaletteUtil; +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.UserDefinedBiome; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; +import com.dfsek.terra.api.world.generation.TerraChunkGenerator; +import com.dfsek.terra.api.world.palette.Palette; +import com.dfsek.terra.api.world.palette.SinglePalette; +import com.dfsek.terra.config.pack.ConfigPack; +import com.dfsek.terra.config.templates.BiomeTemplate; +import com.dfsek.terra.profiler.ProfileFuture; +import com.dfsek.terra.world.Carver; +import com.dfsek.terra.world.TerraWorld; +import com.dfsek.terra.world.carving.NoiseCarver; +import com.dfsek.terra.world.generation.math.SamplerCache; +import com.dfsek.terra.world.generation.math.samplers.Sampler; +import com.dfsek.terra.world.generation.math.samplers.Sampler2D; +import net.jafama.FastMath; +import org.jetbrains.annotations.NotNull; + +import java.util.Random; + +public class DefaultChunkGenerator2D implements TerraChunkGenerator { + private final ConfigPack configPack; + private final TerraPlugin main; + private final MaterialData water; + private final SinglePalette blank; + + private final Carver carver; + + private final SamplerCache cache; + + public DefaultChunkGenerator2D(ConfigPack c, TerraPlugin main, SamplerCache cache) { + this.configPack = c; + this.main = main; + carver = new NoiseCarver(new Range(0, 255), main.getWorldHandle().createBlockData("minecraft:air"), main); + water = main.getWorldHandle().createMaterialData("minecraft:water"); + blank = new SinglePalette<>(main.getWorldHandle().createBlockData("minecraft:air")); + this.cache = cache; + } + + @Override + public boolean isParallelCapable() { + return true; + } + + @Override + public boolean shouldGenerateCaves() { + return configPack.getTemplate().vanillaCaves(); + } + + @Override + public boolean shouldGenerateDecorations() { + return configPack.getTemplate().vanillaDecorations(); + } + + @Override + public boolean shouldGenerateMobs() { + return configPack.getTemplate().vanillaMobs(); + } + + @Override + public boolean shouldGenerateStructures() { + return configPack.getTemplate().vanillaStructures(); + } + + @Override + public ConfigPack getConfigPack() { + return configPack; + } + + @Override + public TerraPlugin getMain() { + return main; + } + + @Override + @SuppressWarnings({"try"}) + public ChunkData generateChunkData(@NotNull World world, Random random, int chunkX, int chunkZ, ChunkData chunk) { + TerraWorld tw = main.getWorld(world); + BiomeProvider grid = tw.getBiomeProvider(); + try(ProfileFuture ignore = tw.getProfiler().measure("TotalChunkGenTime")) { + if(!tw.isSafe()) return chunk; + int xOrig = (chunkX << 4); + int zOrig = (chunkZ << 4); + + Sampler sampler = cache.getChunk(world, chunkX, chunkZ); + + for(int x = 0; x < 16; x++) { + for(int z = 0; z < 16; z++) { + int paletteLevel = 0; + int seaPaletteLevel = 0; + + int cx = xOrig + x; + int cz = zOrig + z; + + TerraBiome b = grid.getBiome(xOrig + x, zOrig + z); + BiomeTemplate c = ((UserDefinedBiome) b).getConfig(); + + Palette seaPalette = c.getOceanPalette(); + + int height = FastMath.min((int) sampler.sample(x, 0, z), world.getMaxHeight() - 1); + + for(int y = FastMath.max(height, c.getSeaLevel()); y >= 0; y--) { + BlockData data = y > height ? seaPalette.get(seaPaletteLevel++, cx, y, cz) : PaletteUtil.getPalette(x, y, z, c, sampler).get(paletteLevel++, cx, y, cz); + chunk.setBlock(x, y, z, data); + } + } + } + if(configPack.getTemplate().doBetaCarvers()) { + carver.carve(world, chunkX, chunkZ, chunk); + } + return chunk; + } + } + + @Override + public void generateBiomes(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, @NotNull BiomeGrid biome) { + DefaultChunkGenerator3D.biomes(world, chunkX, chunkZ, biome, main); + } + + @Override + public SamplerCache getCache() { + return cache; + } + + @Override + public Sampler createSampler(int chunkX, int chunkZ, BiomeProvider provider, World world, int elevationSmooth) { + return new Sampler2D(chunkX, chunkZ, provider, world, elevationSmooth); + } +} diff --git a/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java index 693c1db85..734dbfd59 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java @@ -26,8 +26,9 @@ import com.dfsek.terra.profiler.ProfileFuture; import com.dfsek.terra.world.Carver; import com.dfsek.terra.world.TerraWorld; import com.dfsek.terra.world.carving.NoiseCarver; -import com.dfsek.terra.world.generation.math.Sampler; import com.dfsek.terra.world.generation.math.SamplerCache; +import com.dfsek.terra.world.generation.math.samplers.Sampler; +import com.dfsek.terra.world.generation.math.samplers.Sampler3D; import org.jetbrains.annotations.NotNull; import java.util.Map; @@ -214,8 +215,7 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator { return false; } - @Override - public void generateBiomes(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, @NotNull BiomeGrid biome) { + static void biomes(@NotNull World world, int chunkX, int chunkZ, @NotNull BiomeGrid biome, TerraPlugin main) { int xOrig = (chunkX << 4); int zOrig = (chunkZ << 4); BiomeProvider grid = main.getWorld(world).getBiomeProvider(); @@ -230,8 +230,18 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator { } } + @Override + public void generateBiomes(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, @NotNull BiomeGrid biome) { + biomes(world, chunkX, chunkZ, biome, main); + } + @Override public SamplerCache getCache() { return cache; } + + @Override + public Sampler createSampler(int chunkX, int chunkZ, BiomeProvider provider, World world, int elevationSmooth) { + return new Sampler3D(chunkX, chunkZ, provider, world, elevationSmooth); + } } diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/SamplerCache.java b/common/src/main/java/com/dfsek/terra/world/generation/math/SamplerCache.java index 5bb3c58d6..31e7e6c00 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/math/SamplerCache.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/SamplerCache.java @@ -4,6 +4,7 @@ import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.math.MathUtil; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.world.TerraWorld; +import com.dfsek.terra.world.generation.math.samplers.Sampler; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; @@ -39,7 +40,7 @@ public class SamplerCache { containerMap.clear(); } - private class Container { + private final class Container { private final TerraWorld terraWorld; private final LoadingCache cache; @@ -50,7 +51,7 @@ public class SamplerCache { public Sampler load(@NotNull Long key) { int cx = (int) (key >> 32); int cz = (int) key.longValue(); - return new Sampler(cx, cz, terraWorld.getBiomeProvider(), world, terraWorld.getConfig().getTemplate().getElevationBlend()); + return terraWorld.getGenerator().createSampler(cx, cz, terraWorld.getBiomeProvider(), world, terraWorld.getConfig().getTemplate().getElevationBlend()); } }); terraWorld = main.getWorld(world); diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator.java b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator.java index 210d5c503..5d91d43e4 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator.java @@ -1,5 +1,10 @@ package com.dfsek.terra.world.generation.math.interpolation; +import com.dfsek.terra.api.util.mutable.MutableInteger; +import com.dfsek.terra.api.world.biome.Generator; + +import java.util.Map; + public interface ChunkInterpolator { /** * Gets the noise at a pair of internal chunk coordinates. @@ -9,4 +14,20 @@ public interface ChunkInterpolator { * @return double - The interpolated noise at the coordinates. */ double getNoise(double x, double y, double z); + + default double computeNoise(Map gens, double x, double y, double z) { + double n = 0; + double div = 0; + for(Map.Entry entry : gens.entrySet()) { + Generator gen = entry.getKey(); + int weight = entry.getValue().get(); + double noise = computeNoise(gen, x, y, z); + + n += noise * weight; + div += gen.getWeight() * weight; + } + return n / div; + } + + double computeNoise(Generator generator, double x, double y, double z); } diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator2D.java b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator2D.java new file mode 100644 index 000000000..81da092bc --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator2D.java @@ -0,0 +1,84 @@ +package com.dfsek.terra.world.generation.math.interpolation; + +import com.dfsek.terra.api.math.vector.Vector3; +import com.dfsek.terra.api.platform.world.World; +import com.dfsek.terra.api.util.mutable.MutableInteger; +import com.dfsek.terra.api.world.biome.Generator; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; +import net.jafama.FastMath; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.BiFunction; + +/** + * Class to abstract away the Interpolators needed to generate a chunk.
+ * Contains method to get interpolated noise at a coordinate within the chunk. + */ +public class ChunkInterpolator2D implements ChunkInterpolator { + private final Interpolator[][] interpGrid = new Interpolator[4][4]; + private final BiFunction noiseGetter; + + /** + * Instantiates a 3D ChunkInterpolator3D at a pair of chunk coordinates. + * + * @param chunkX X coordinate of the chunk. + * @param chunkZ Z coordinate of the chunk. + * @param provider Biome Provider to use for biome fetching. + */ + public ChunkInterpolator2D(World w, int chunkX, int chunkZ, BiomeProvider provider, BiFunction noiseGetter) { + this.noiseGetter = noiseGetter; + int xOrigin = chunkX << 4; + int zOrigin = chunkZ << 4; + + double[][] noiseStorage = new double[5][5]; + + for(int x = 0; x < 5; x++) { + for(int z = 0; z < 5; z++) { + Generator generator = provider.getBiome(xOrigin + (x << 2), zOrigin + (z << 2)).getGenerator(w); + Map genMap = new HashMap<>(); + + int step = generator.getBlendStep(); + int blend = generator.getBlendDistance(); + + for(int xi = -blend; xi <= blend; xi++) { + for(int zi = -blend; zi <= blend; zi++) { + genMap.computeIfAbsent(provider.getBiome(xOrigin + (x << 2) + (xi * step), zOrigin + (z << 2) + (zi * step)).getGenerator(w), g -> new MutableInteger(0)).increment(); // Increment by 1 + } + } + + noiseStorage[x][z] = computeNoise(genMap, (x << 2) + xOrigin, 0, (z << 2) + zOrigin); + } + } + + for(int x = 0; x < 4; x++) { + for(int z = 0; z < 4; z++) { + interpGrid[x][z] = new Interpolator( + noiseStorage[x][z], + noiseStorage[x + 1][z], + noiseStorage[x][z + 1], + noiseStorage[x + 1][z + 1]); + } + } + } + + private static int reRange(int value, int high) { + return FastMath.max(FastMath.min(value, high), 0); + } + + public double computeNoise(Generator generator, double x, double y, double z) { + return noiseGetter.apply(generator, new Vector3(x, y, z)); + } + + /** + * Gets the noise at a pair of internal chunk coordinates. + * + * @param x The internal X coordinate (0-15). + * @param z The internal Z coordinate (0-15). + * @return double - The interpolated noise at the coordinates. + */ + @Override + public double getNoise(double x, double y, double z) { + return interpGrid[reRange(((int) x) / 4, 3)][reRange(((int) z) / 4, 3)].bilerp((x % 4) / 4, (z % 4) / 4); + } +} diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/BiomeChunkInterpolator.java b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator3D.java similarity index 79% rename from common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/BiomeChunkInterpolator.java rename to common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator3D.java index 5f9d4c0d5..cb077620e 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/BiomeChunkInterpolator.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator3D.java @@ -15,18 +15,18 @@ import java.util.function.BiFunction; * Class to abstract away the Interpolators needed to generate a chunk.
* Contains method to get interpolated noise at a coordinate within the chunk. */ -public class BiomeChunkInterpolator implements ChunkInterpolator { +public class ChunkInterpolator3D implements ChunkInterpolator { private final Interpolator3[][][] interpGrid = new Interpolator3[4][64][4]; private final BiFunction noiseGetter; /** - * Instantiates a 3D BiomeChunkInterpolator at a pair of chunk coordinates. + * Instantiates a 3D ChunkInterpolator3D at a pair of chunk coordinates. * * @param chunkX X coordinate of the chunk. * @param chunkZ Z coordinate of the chunk. * @param provider Biome Provider to use for biome fetching. */ - public BiomeChunkInterpolator(World w, int chunkX, int chunkZ, BiomeProvider provider, BiFunction noiseGetter) { + public ChunkInterpolator3D(World w, int chunkX, int chunkZ, BiomeProvider provider, BiFunction noiseGetter) { this.noiseGetter = noiseGetter; int xOrigin = chunkX << 4; int zOrigin = chunkZ << 4; @@ -70,21 +70,7 @@ public class BiomeChunkInterpolator implements ChunkInterpolator { } } - private double computeNoise(Map gens, double x, double y, double z) { - double n = 0; - double div = 0; - for(Map.Entry entry : gens.entrySet()) { - Generator gen = entry.getKey(); - int weight = entry.getValue().get(); - double noise = computeNoise(gen, x, y, z); - - n += noise * weight; - div += gen.getWeight() * weight; - } - return n / div; - } - - private double computeNoise(Generator generator, double x, double y, double z) { + public double computeNoise(Generator generator, double x, double y, double z) { return noiseGetter.apply(generator, new Vector3(x, y, z)); } diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/Interpolator.java b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/Interpolator.java index cc15c55aa..bf002e8a4 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/Interpolator.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/Interpolator.java @@ -31,7 +31,6 @@ public class Interpolator { */ public static double lerp(double t, double v0, double v1) { return v0 + t * (v1 - v0); - } /** diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/Interpolator3.java b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/Interpolator3.java index 6fd4c69a3..c7a7c0275 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/Interpolator3.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/Interpolator3.java @@ -4,7 +4,8 @@ package com.dfsek.terra.world.generation.math.interpolation; * Class for bilinear interpolation of values arranged on a unit square. */ public class Interpolator3 { - private final double _000, _100, _010, _110, _001, _101, _011, _111; + private final Interpolator bottom; + private final Interpolator top; /** * Constructs an interpolator with given values as vertices of a unit cube. @@ -18,21 +19,14 @@ public class Interpolator3 { * * @param _111 The value at (t, u, v) = (1, 1, 1). */ public Interpolator3(double _000, double _100, - double _010, double _110, double _001, double _101, + double _010, double _110, + double _001, double _101, double _011, double _111) { - this._000 = _000; - this._001 = _001; - this._010 = _010; - this._011 = _011; - this._100 = _100; - this._101 = _101; - this._110 = _110; - this._111 = _111; + this.top = new Interpolator(_000, _010, _001, _011); + this.bottom = new Interpolator(_100, _110, _101, _111); } public double trilerp(double x, double y, double z) { - Interpolator top = new Interpolator(_000, _010, _001, _011); - Interpolator bottom = new Interpolator(_100, _110, _101, _111); return Interpolator.lerp(x, top.bilerp(y, z), bottom.bilerp(y, z)); } } \ No newline at end of file diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/NoiseChunkInterpolator.java b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/NoiseChunkInterpolator.java deleted file mode 100644 index 0ba964824..000000000 --- a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/NoiseChunkInterpolator.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.dfsek.terra.world.generation.math.interpolation; - -import com.dfsek.terra.api.math.noise.NoiseSampler; -import net.jafama.FastMath; - -public class NoiseChunkInterpolator implements ChunkInterpolator { - private final Interpolator3[][][] interpGrid = new Interpolator3[4][64][4]; - - public NoiseChunkInterpolator(int chunkX, int chunkZ, NoiseSampler noise) { - int xOrigin = chunkX << 4; - int zOrigin = chunkZ << 4; - - double[][][] noiseStorage = new double[5][5][65]; - - for(int x = 0; x < 5; x++) { - for(int z = 0; z < 5; z++) { - for(int y = 0; y < 65; y++) { - noiseStorage[x][z][y] = noise.getNoise((x << 2) + xOrigin, y << 2, (z << 2) + zOrigin); - } - } - } - - for(int x = 0; x < 4; x++) { - for(int z = 0; z < 4; z++) { - for(int y = 0; y < 64; y++) { - interpGrid[x][y][z] = new Interpolator3( - noiseStorage[x][z][y], - noiseStorage[x + 1][z][y], - noiseStorage[x][z][y + 1], - noiseStorage[x + 1][z][y + 1], - noiseStorage[x][z + 1][y], - noiseStorage[x + 1][z + 1][y], - noiseStorage[x][z + 1][y + 1], - noiseStorage[x + 1][z + 1][y + 1]); - } - } - } - } - - private static int reRange(int value, int high) { - return FastMath.max(FastMath.min(value, high), 0); - } - - @Override - public double getNoise(double x, double y, double z) { - return interpGrid[reRange(((int) x) / 4, 3)][reRange(((int) y) / 4, 63)][reRange(((int) z) / 4, 3)].trilerp((x % 4) / 4, (y % 4) / 4, (z % 4) / 4); - } -} diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/samplers/Sampler.java b/common/src/main/java/com/dfsek/terra/world/generation/math/samplers/Sampler.java new file mode 100644 index 000000000..7e28c341d --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/samplers/Sampler.java @@ -0,0 +1,6 @@ +package com.dfsek.terra.world.generation.math.samplers; + +@FunctionalInterface +public interface Sampler { + double sample(double x, double y, double z); +} diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/samplers/Sampler2D.java b/common/src/main/java/com/dfsek/terra/world/generation/math/samplers/Sampler2D.java new file mode 100644 index 000000000..9e901e92a --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/samplers/Sampler2D.java @@ -0,0 +1,22 @@ +package com.dfsek.terra.world.generation.math.samplers; + +import com.dfsek.terra.api.platform.world.World; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; +import com.dfsek.terra.world.generation.math.interpolation.ChunkInterpolator2D; +import com.dfsek.terra.world.generation.math.interpolation.ElevationInterpolator; +import net.jafama.FastMath; + +public class Sampler2D implements Sampler { + private final ChunkInterpolator2D interpolator; + private final ElevationInterpolator elevationInterpolator; + + public Sampler2D(int x, int z, BiomeProvider provider, World world, int elevationSmooth) { + this.interpolator = new ChunkInterpolator2D(world, x, z, provider, (generator, coord) -> generator.getBaseSampler().getNoise(coord)); + this.elevationInterpolator = new ElevationInterpolator(world, x, z, provider, elevationSmooth); + } + + @Override + public double sample(double x, double y, double z) { + return interpolator.getNoise(x, 0, z) + elevationInterpolator.getElevation(FastMath.roundToInt(x), FastMath.roundToInt(z)); + } +} diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/Sampler.java b/common/src/main/java/com/dfsek/terra/world/generation/math/samplers/Sampler3D.java similarity index 51% rename from common/src/main/java/com/dfsek/terra/world/generation/math/Sampler.java rename to common/src/main/java/com/dfsek/terra/world/generation/math/samplers/Sampler3D.java index 2f2beb585..bb07140a7 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/math/Sampler.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/samplers/Sampler3D.java @@ -1,25 +1,22 @@ -package com.dfsek.terra.world.generation.math; +package com.dfsek.terra.world.generation.math.samplers; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.world.biome.provider.BiomeProvider; -import com.dfsek.terra.world.generation.math.interpolation.BiomeChunkInterpolator; +import com.dfsek.terra.world.generation.math.interpolation.ChunkInterpolator3D; import com.dfsek.terra.world.generation.math.interpolation.ElevationInterpolator; import net.jafama.FastMath; -public class Sampler { - private final BiomeChunkInterpolator interpolator; +public class Sampler3D implements Sampler { + private final ChunkInterpolator3D interpolator; private final ElevationInterpolator elevationInterpolator; - public Sampler(int x, int z, BiomeProvider provider, World world, int elevationSmooth) { - this.interpolator = new BiomeChunkInterpolator(world, x, z, provider, (generator, coord) -> generator.getBaseSampler().getNoise(coord)); + public Sampler3D(int x, int z, BiomeProvider provider, World world, int elevationSmooth) { + this.interpolator = new ChunkInterpolator3D(world, x, z, provider, (generator, coord) -> generator.getBaseSampler().getNoise(coord)); this.elevationInterpolator = new ElevationInterpolator(world, x, z, provider, elevationSmooth); } + @Override public double sample(double x, double y, double z) { return interpolator.getNoise(x, y, z) + elevationInterpolator.getElevation(FastMath.roundToInt(x), FastMath.roundToInt(z)); } - - public static double noise2dExtrude(double y, double base) { - return ((-FastMath.pow2((y / base))) + 1); - } } From 6025e0f5574701a6b382155934a27c4f79190d18 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 21 Feb 2021 17:49:07 -0700 Subject: [PATCH 08/95] cleanup --- .../java/com/dfsek/terra/api/math/Range.java | 24 +++++++++---------- .../generators/DefaultChunkGenerator2D.java | 6 ----- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/common/src/main/java/com/dfsek/terra/api/math/Range.java b/common/src/main/java/com/dfsek/terra/api/math/Range.java index 6c5d3174a..ce8ae477d 100644 --- a/common/src/main/java/com/dfsek/terra/api/math/Range.java +++ b/common/src/main/java/com/dfsek/terra/api/math/Range.java @@ -24,7 +24,7 @@ public class Range implements Iterable { return max; } - public com.dfsek.terra.api.math.Range setMax(int max) { + public Range setMax(int max) { this.max = max; return this; } @@ -33,7 +33,7 @@ public class Range implements Iterable { return min; } - public com.dfsek.terra.api.math.Range setMin(int min) { + public Range setMin(int min) { this.min = min; return this; } @@ -42,35 +42,35 @@ public class Range implements Iterable { return max - min; } - public com.dfsek.terra.api.math.Range multiply(int mult) { + public Range multiply(int mult) { min *= mult; max *= mult; return this; } - public com.dfsek.terra.api.math.Range reflect(int pt) { - return new com.dfsek.terra.api.math.Range(2 * pt - this.getMax(), 2 * pt - this.getMin()); + public Range reflect(int pt) { + return new Range(2 * pt - this.getMax(), 2 * pt - this.getMin()); } public int get(Random r) { return r.nextInt((max - min) + 1) + min; } - public com.dfsek.terra.api.math.Range intersects(com.dfsek.terra.api.math.Range other) { + public Range intersects(com.dfsek.terra.api.math.Range other) { try { - return new com.dfsek.terra.api.math.Range(FastMath.max(this.getMin(), other.getMin()), FastMath.min(this.getMax(), other.getMax())); + return new Range(FastMath.max(this.getMin(), other.getMin()), FastMath.min(this.getMax(), other.getMax())); } catch(IllegalArgumentException e) { return null; } } - public com.dfsek.terra.api.math.Range add(int add) { + public Range add(int add) { this.min += add; this.max += add; return this; } - public com.dfsek.terra.api.math.Range sub(int sub) { + public Range sub(int sub) { this.min -= sub; this.max -= sub; return this; @@ -89,7 +89,7 @@ public class Range implements Iterable { @Override public boolean equals(Object obj) { if(!(obj instanceof com.dfsek.terra.api.math.Range)) return false; - com.dfsek.terra.api.math.Range other = (com.dfsek.terra.api.math.Range) obj; + Range other = (com.dfsek.terra.api.math.Range) obj; return other.getMin() == this.getMin() && other.getMax() == this.getMax(); } @@ -100,10 +100,10 @@ public class Range implements Iterable { } private static class RangeIterator implements Iterator { - private final com.dfsek.terra.api.math.Range m; + private final Range m; private Integer current; - public RangeIterator(com.dfsek.terra.api.math.Range m) { + public RangeIterator(Range m) { this.m = m; current = m.getMin(); } diff --git a/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator2D.java b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator2D.java index b1c468768..be6857923 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator2D.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator2D.java @@ -3,7 +3,6 @@ package com.dfsek.terra.world.generation.generators; import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.platform.world.BiomeGrid; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.platform.world.generator.ChunkData; @@ -13,7 +12,6 @@ import com.dfsek.terra.api.world.biome.UserDefinedBiome; import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.api.world.generation.TerraChunkGenerator; import com.dfsek.terra.api.world.palette.Palette; -import com.dfsek.terra.api.world.palette.SinglePalette; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.config.templates.BiomeTemplate; import com.dfsek.terra.profiler.ProfileFuture; @@ -31,8 +29,6 @@ import java.util.Random; public class DefaultChunkGenerator2D implements TerraChunkGenerator { private final ConfigPack configPack; private final TerraPlugin main; - private final MaterialData water; - private final SinglePalette blank; private final Carver carver; @@ -42,8 +38,6 @@ public class DefaultChunkGenerator2D implements TerraChunkGenerator { this.configPack = c; this.main = main; carver = new NoiseCarver(new Range(0, 255), main.getWorldHandle().createBlockData("minecraft:air"), main); - water = main.getWorldHandle().createMaterialData("minecraft:water"); - blank = new SinglePalette<>(main.getWorldHandle().createBlockData("minecraft:air")); this.cache = cache; } From 8b196716a4c725a62e8cf834289552796b3aed49 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 21 Feb 2021 22:04:29 -0700 Subject: [PATCH 09/95] CheckedRegistry API --- .../dfsek/terra/config/pack/ConfigPack.java | 61 ++++++----- .../dfsek/terra/registry/CheckedRegistry.java | 102 ++++++++++++++++++ .../exception/DuplicateEntryException.java | 13 +++ .../master/ChunkGeneratorRegistry.java | 7 -- .../bukkit/listeners/CommonListener.java | 4 +- 5 files changed, 149 insertions(+), 38 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/registry/CheckedRegistry.java create mode 100644 common/src/main/java/com/dfsek/terra/registry/exception/DuplicateEntryException.java delete mode 100644 common/src/main/java/com/dfsek/terra/registry/master/ChunkGeneratorRegistry.java diff --git a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java index fb9d433e6..9ad335ecb 100644 --- a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java +++ b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java @@ -6,11 +6,14 @@ import com.dfsek.tectonic.exception.ConfigException; import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; import com.dfsek.tectonic.loading.TypeRegistry; +import com.dfsek.tectonic.loading.object.ObjectTemplate; import com.dfsek.terra.api.LoaderRegistrar; import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.core.event.events.config.ConfigPackPostLoadEvent; import com.dfsek.terra.api.core.event.events.config.ConfigPackPreLoadEvent; +import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.structures.loot.LootTable; +import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder; import com.dfsek.terra.api.structures.script.StructureScript; import com.dfsek.terra.api.util.seeded.NoiseSeeded; import com.dfsek.terra.api.world.biome.TerraBiome; @@ -46,6 +49,7 @@ import com.dfsek.terra.config.templates.OreTemplate; import com.dfsek.terra.config.templates.PaletteTemplate; import com.dfsek.terra.config.templates.StructureTemplate; import com.dfsek.terra.config.templates.TreeTemplate; +import com.dfsek.terra.registry.CheckedRegistry; import com.dfsek.terra.registry.TerraRegistry; import com.dfsek.terra.registry.config.BiomeRegistry; import com.dfsek.terra.registry.config.CarverRegistry; @@ -75,6 +79,7 @@ import java.util.Enumeration; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.function.Supplier; import java.util.logging.Level; import java.util.stream.Collectors; import java.util.zip.ZipEntry; @@ -255,10 +260,6 @@ public class ConfigPack implements LoaderRegistrar { return structureRegistry.entries().stream().map(terraStructure -> terraStructure.getTemplate().getID()).collect(Collectors.toList()); } - public TreeRegistry getTreeRegistry() { - return treeRegistry; - } - public ConfigPackTemplate getTemplate() { return template; } @@ -287,14 +288,6 @@ public class ConfigPack implements LoaderRegistrar { .registerLoader(ImageSamplerTemplate.class, () -> new ImageProviderTemplate(biomeRegistry)); } - public ScriptRegistry getScriptRegistry() { - return scriptRegistry; - } - - public BiomeRegistry getBiomeRegistry() { - return biomeRegistry; - } - public SamplerCache getSamplerCache() { return samplerCache; } @@ -307,35 +300,47 @@ public class ConfigPack implements LoaderRegistrar { return biomeProviderBuilder; } - public FunctionRegistry getFunctionRegistry() { - return functionRegistry; + public CheckedRegistry getScriptRegistry() { + return new CheckedRegistry<>(scriptRegistry); } - public NoiseRegistry getNormalizerRegistry() { - return noiseRegistry; + public CheckedRegistry getBiomeRegistry() { + return new CheckedRegistry<>(biomeRegistry); } - public CarverRegistry getCarverRegistry() { - return carverRegistry; + public CheckedRegistry getTreeRegistry() { + return new CheckedRegistry<>(treeRegistry); } - public FloraRegistry getFloraRegistry() { - return floraRegistry; + public CheckedRegistry> getFunctionRegistry() { + return new CheckedRegistry<>(functionRegistry); } - public LootRegistry getLootRegistry() { - return lootRegistry; + public CheckedRegistry>> getNormalizerRegistry() { + return new CheckedRegistry<>(noiseRegistry); } - public OreRegistry getOreRegistry() { - return oreRegistry; + public CheckedRegistry getCarverRegistry() { + return new CheckedRegistry<>(carverRegistry); } - public PaletteRegistry getPaletteRegistry() { - return paletteRegistry; + public CheckedRegistry getFloraRegistry() { + return new CheckedRegistry<>(floraRegistry); } - public StructureRegistry getStructureRegistry() { - return structureRegistry; + public CheckedRegistry getLootRegistry() { + return new CheckedRegistry<>(lootRegistry); + } + + public CheckedRegistry getOreRegistry() { + return new CheckedRegistry<>(oreRegistry); + } + + public CheckedRegistry> getPaletteRegistry() { + return new CheckedRegistry<>(paletteRegistry); + } + + public CheckedRegistry getStructureRegistry() { + return new CheckedRegistry<>(structureRegistry); } } diff --git a/common/src/main/java/com/dfsek/terra/registry/CheckedRegistry.java b/common/src/main/java/com/dfsek/terra/registry/CheckedRegistry.java new file mode 100644 index 000000000..29cb08708 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/registry/CheckedRegistry.java @@ -0,0 +1,102 @@ +package com.dfsek.terra.registry; + +import com.dfsek.tectonic.exception.LoadException; +import com.dfsek.tectonic.loading.ConfigLoader; +import com.dfsek.tectonic.loading.TypeLoader; +import com.dfsek.terra.registry.exception.DuplicateEntryException; + +import java.lang.reflect.Type; +import java.util.Set; +import java.util.function.BiConsumer; +import java.util.function.Consumer; + +/** + * Wrapper for a registry that ensures checked access. + * + * @param Type in registry + */ +public class CheckedRegistry implements TypeLoader { + private final TerraRegistry registry; + + public CheckedRegistry(TerraRegistry registry) { + this.registry = registry; + } + + /** + * Add a value to this registry, checking whether it is present first. + * + * @param identifier Identifier to assign value. + * @param value Value to add. + * @throws DuplicateEntryException If an entry with the same identifier is already present. + */ + public void add(String identifier, T value) throws DuplicateEntryException { + if(registry.contains(identifier)) throw new DuplicateEntryException("Entry \"" + identifier + "\" is already present in registry."); + registry.addChecked(identifier, value); + } + + /** + * Add a value to the registry, without checking presence beforehand. + *

+ * Use of this method is generally discouraged, as it is bad practice to overwrite registry values. + * + * @param identifier Identifier to assign value. + * @param value Value to add. + * @deprecated Use of {@link #add(String, Object)} is encouraged. + */ + @Deprecated + public void addUnchecked(String identifier, T value) { + registry.add(identifier, value); + } + + /** + * Get a value from the registry. + * + * @param identifier Identifier of value. + * @return Value matching the identifier, {@code null} if no value is present. + */ + public T get(String identifier) { + return registry.get(identifier); + } + + /** + * Check if the registry contains a value. + * + * @param identifier Identifier of value. + * @return Whether the registry contains the value. + */ + public boolean contains(String identifier) { + return registry.contains(identifier); + } + + /** + * Perform the given action for every value in the registry. + * + * @param consumer Action to perform on value. + */ + public void forEach(Consumer consumer) { + registry.forEach(consumer); + } + + /** + * Perform an action for every key-value pair in the registry. + * + * @param consumer Action to perform on pair. + */ + public void forEach(BiConsumer consumer) { + registry.forEach(consumer); + } + + /** + * Get the entries of this registry as a {@link Set}. + * + * @return Set containing all entries. + */ + public Set entries() { + return registry.entries(); + } + + @Override + public T load(Type t, Object c, ConfigLoader loader) throws LoadException { + return registry.load(t, c, loader); + } +} diff --git a/common/src/main/java/com/dfsek/terra/registry/exception/DuplicateEntryException.java b/common/src/main/java/com/dfsek/terra/registry/exception/DuplicateEntryException.java new file mode 100644 index 000000000..df965eabb --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/registry/exception/DuplicateEntryException.java @@ -0,0 +1,13 @@ +package com.dfsek.terra.registry.exception; + +public class DuplicateEntryException extends Exception { + private static final long serialVersionUID = -7199021672428288780L; + + public DuplicateEntryException(String message) { + super(message); + } + + public DuplicateEntryException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/common/src/main/java/com/dfsek/terra/registry/master/ChunkGeneratorRegistry.java b/common/src/main/java/com/dfsek/terra/registry/master/ChunkGeneratorRegistry.java deleted file mode 100644 index 93ee25e94..000000000 --- a/common/src/main/java/com/dfsek/terra/registry/master/ChunkGeneratorRegistry.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.dfsek.terra.registry.master; - -import com.dfsek.terra.api.platform.world.generator.ChunkGenerator; -import com.dfsek.terra.registry.TerraRegistry; - -public class ChunkGeneratorRegistry extends TerraRegistry { -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/CommonListener.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/CommonListener.java index b4ef72b18..753b785c9 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/CommonListener.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/CommonListener.java @@ -9,7 +9,6 @@ import com.dfsek.terra.api.util.FastRandom; import com.dfsek.terra.api.world.tree.Tree; import com.dfsek.terra.bukkit.world.BukkitAdapter; import com.dfsek.terra.config.pack.ConfigPack; -import com.dfsek.terra.registry.config.TreeRegistry; import com.dfsek.terra.world.TerraWorld; import org.bukkit.Material; import org.bukkit.TreeType; @@ -53,8 +52,7 @@ public class CommonListener implements Listener { Block block = e.getLocation().getBlock(); BlockData data = block.getBlockData(); block.setType(Material.AIR); - TreeRegistry registry = c.getTreeRegistry(); - Tree tree = registry.get(TREE_TYPE_STRING_TRANSFORMER.translate(e.getSpecies())); + Tree tree = c.getTreeRegistry().get(TREE_TYPE_STRING_TRANSFORMER.translate(e.getSpecies())); org.bukkit.Location location = e.getLocation(); if(!tree.plant(new Location(bukkit, location.getX(), location.getY(), location.getZ()), new FastRandom())) block.setBlockData(data); } From 5e940187d99e286c8a674af5cea4d9b5412a8019 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 21 Feb 2021 22:14:38 -0700 Subject: [PATCH 10/95] documentation --- .../dfsek/terra/addons/annotations/Addon.java | 6 +++ .../terra/addons/annotations/Author.java | 6 +++ .../terra/addons/annotations/Depends.java | 6 +++ .../terra/addons/annotations/Version.java | 6 +++ .../dfsek/terra/addons/injection/Inject.java | 3 ++ .../api/core/event/annotations/Priority.java | 4 +- .../dfsek/terra/registry/CheckedRegistry.java | 1 - .../dfsek/terra/registry/TerraRegistry.java | 48 +++++++++++-------- .../terra/registry/config/FloraRegistry.java | 4 +- .../registry/config/PaletteRegistry.java | 8 ++-- .../terra/registry/config/TreeRegistry.java | 4 +- .../exception/DuplicateEntryException.java | 3 ++ .../terra/registry/master/AddonRegistry.java | 9 ++-- .../terra/bukkit/listeners/TerraListener.java | 8 +++- 14 files changed, 80 insertions(+), 36 deletions(-) diff --git a/common/src/main/java/com/dfsek/terra/addons/annotations/Addon.java b/common/src/main/java/com/dfsek/terra/addons/annotations/Addon.java index aa0c3e2c1..79db4b24b 100644 --- a/common/src/main/java/com/dfsek/terra/addons/annotations/Addon.java +++ b/common/src/main/java/com/dfsek/terra/addons/annotations/Addon.java @@ -5,8 +5,14 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Specifies that the annotated class is an entry point for a Terra addon. + */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface Addon { + /** + * @return The ID of the addon. + */ String value(); } diff --git a/common/src/main/java/com/dfsek/terra/addons/annotations/Author.java b/common/src/main/java/com/dfsek/terra/addons/annotations/Author.java index 4967706fa..b7bd416e3 100644 --- a/common/src/main/java/com/dfsek/terra/addons/annotations/Author.java +++ b/common/src/main/java/com/dfsek/terra/addons/annotations/Author.java @@ -5,8 +5,14 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Optional annotation that specifies the author of an addon. + */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface Author { + /** + * @return Name of the addon author. + */ String value(); } diff --git a/common/src/main/java/com/dfsek/terra/addons/annotations/Depends.java b/common/src/main/java/com/dfsek/terra/addons/annotations/Depends.java index 4e4e755f5..ded30d6ba 100644 --- a/common/src/main/java/com/dfsek/terra/addons/annotations/Depends.java +++ b/common/src/main/java/com/dfsek/terra/addons/annotations/Depends.java @@ -5,8 +5,14 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Optional annotation that specifies dependencies of an addon. + */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface Depends { + /** + * @return All addons this addon is dependent upon. + */ String[] value(); } diff --git a/common/src/main/java/com/dfsek/terra/addons/annotations/Version.java b/common/src/main/java/com/dfsek/terra/addons/annotations/Version.java index f4c08b936..87ce44984 100644 --- a/common/src/main/java/com/dfsek/terra/addons/annotations/Version.java +++ b/common/src/main/java/com/dfsek/terra/addons/annotations/Version.java @@ -5,8 +5,14 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Optional annotation that specifies the version of an addon. + */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface Version { + /** + * @return Version of the addon. + */ String value(); } diff --git a/common/src/main/java/com/dfsek/terra/addons/injection/Inject.java b/common/src/main/java/com/dfsek/terra/addons/injection/Inject.java index 38b35cd42..2094b14cc 100644 --- a/common/src/main/java/com/dfsek/terra/addons/injection/Inject.java +++ b/common/src/main/java/com/dfsek/terra/addons/injection/Inject.java @@ -5,6 +5,9 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Specifies that a field is a target for dependency injection. + */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Inject { diff --git a/common/src/main/java/com/dfsek/terra/api/core/event/annotations/Priority.java b/common/src/main/java/com/dfsek/terra/api/core/event/annotations/Priority.java index 7ee84aecd..0bcce141a 100644 --- a/common/src/main/java/com/dfsek/terra/api/core/event/annotations/Priority.java +++ b/common/src/main/java/com/dfsek/terra/api/core/event/annotations/Priority.java @@ -12,11 +12,11 @@ import java.lang.annotation.Target; @Target(ElementType.METHOD) public @interface Priority { /** - * Highest possible priority. Listeners with this priority will always be invoked first. + * Highest possible priority. Listeners with this priority will always be invoked last. */ int HIGHEST = Integer.MAX_VALUE; /** - * Lowest possible priority. Listeners with this priority will always be invoked last. + * Lowest possible priority. Listeners with this priority will always be invoked first. */ int LOWEST = Integer.MIN_VALUE; /** diff --git a/common/src/main/java/com/dfsek/terra/registry/CheckedRegistry.java b/common/src/main/java/com/dfsek/terra/registry/CheckedRegistry.java index 29cb08708..99c4047ae 100644 --- a/common/src/main/java/com/dfsek/terra/registry/CheckedRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/CheckedRegistry.java @@ -30,7 +30,6 @@ public class CheckedRegistry implements TypeLoader { * @throws DuplicateEntryException If an entry with the same identifier is already present. */ public void add(String identifier, T value) throws DuplicateEntryException { - if(registry.contains(identifier)) throw new DuplicateEntryException("Entry \"" + identifier + "\" is already present in registry."); registry.addChecked(identifier, value); } diff --git a/common/src/main/java/com/dfsek/terra/registry/TerraRegistry.java b/common/src/main/java/com/dfsek/terra/registry/TerraRegistry.java index eefe13120..1d4b1d1d0 100644 --- a/common/src/main/java/com/dfsek/terra/registry/TerraRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/TerraRegistry.java @@ -3,6 +3,7 @@ package com.dfsek.terra.registry; import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; import com.dfsek.tectonic.loading.TypeLoader; +import com.dfsek.terra.registry.exception.DuplicateEntryException; import java.lang.reflect.Type; import java.util.HashMap; @@ -24,41 +25,48 @@ public abstract class TerraRegistry implements TypeLoader { } /** - * Add an object to the registry with a name. + * Add a value to this registry. * - * @param name Name of the tree. - * @param value Object to increment - * @return True if tree was overwritten. + * @param identifier Identifier to assign value. + * @param value Value to add. */ - public boolean add(String name, T value) { - boolean exists = objects.containsKey(name); - objects.put(name, value); + public boolean add(String identifier, T value) { + boolean exists = objects.containsKey(identifier); + objects.put(identifier, value); return exists; } - public void addChecked(String name, T value) { - if(objects.containsKey(name)) throw new IllegalArgumentException("Value is already defined in registry."); - add(name, value); + /** + * Add a value to this registry, checking whether it is present first. + * + * @param identifier Identifier to assign value. + * @param value Value to add. + * @throws DuplicateEntryException If an entry with the same identifier is already present. + */ + public void addChecked(String identifier, T value) throws DuplicateEntryException { + if(objects.containsKey(identifier)) + throw new DuplicateEntryException("Value with identifier \"" + identifier + "\" is already defined in registry."); + add(identifier, value); } /** - * Check if the registry contains an object. + * Check if the registry contains a value. * - * @param name Name of the object. - * @return Whether the registry contains the object. + * @param identifier Identifier of value. + * @return Whether the registry contains the value. */ - public boolean contains(String name) { - return objects.containsKey(name); + public boolean contains(String identifier) { + return objects.containsKey(identifier); } /** - * Get an object from the registry, + * Get a value from the registry. * - * @param id ID of object to get - * @return Object + * @param identifier Identifier of value. + * @return Value matching the identifier, {@code null} if no value is present. */ - public T get(String id) { - return objects.get(id); + public T get(String identifier) { + return objects.get(identifier); } public void forEach(Consumer consumer) { diff --git a/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java index 147e56a26..05482e816 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java @@ -70,7 +70,7 @@ public class FloraRegistry extends TerraRegistry { @Override - public Flora get(String id) { - return super.get(id); + public Flora get(String identifier) { + return super.get(identifier); } } diff --git a/common/src/main/java/com/dfsek/terra/registry/config/PaletteRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/PaletteRegistry.java index 2a8cb5704..e13cfb6ba 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/PaletteRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/PaletteRegistry.java @@ -14,9 +14,9 @@ public class PaletteRegistry extends TerraRegistry> { @Override - public Palette get(String id) { - if(id.startsWith("BLOCK:")) - return new SinglePalette<>(main.getWorldHandle().createBlockData(id.substring(6))); // Return single palette for BLOCK: shortcut. - return super.get(id); + public Palette get(String identifier) { + if(identifier.startsWith("BLOCK:")) + return new SinglePalette<>(main.getWorldHandle().createBlockData(identifier.substring(6))); // Return single palette for BLOCK: shortcut. + return super.get(identifier); } } diff --git a/common/src/main/java/com/dfsek/terra/registry/config/TreeRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/TreeRegistry.java index 82ac69fc6..b444dbc44 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/TreeRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/TreeRegistry.java @@ -45,8 +45,8 @@ public class TreeRegistry extends TerraRegistry { } @Override - public boolean add(String name, Tree value) { - return super.add(name, value); + public boolean add(String identifier, Tree value) { + return super.add(identifier, value); } private final class FractalTreeHolder implements Tree { diff --git a/common/src/main/java/com/dfsek/terra/registry/exception/DuplicateEntryException.java b/common/src/main/java/com/dfsek/terra/registry/exception/DuplicateEntryException.java index df965eabb..477c93f50 100644 --- a/common/src/main/java/com/dfsek/terra/registry/exception/DuplicateEntryException.java +++ b/common/src/main/java/com/dfsek/terra/registry/exception/DuplicateEntryException.java @@ -1,5 +1,8 @@ package com.dfsek.terra.registry.exception; +/** + * Thrown when a duplicate entry is found in a registry. + */ public class DuplicateEntryException extends Exception { private static final long serialVersionUID = -7199021672428288780L; diff --git a/common/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java b/common/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java index 40db3b7b0..266a8bb0a 100644 --- a/common/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java @@ -9,6 +9,7 @@ import com.dfsek.terra.addons.loading.pre.AddonPool; import com.dfsek.terra.addons.loading.pre.PreLoadAddon; import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.registry.TerraRegistry; +import com.dfsek.terra.registry.exception.DuplicateEntryException; import java.io.File; import java.io.IOException; @@ -31,11 +32,11 @@ public class AddonRegistry extends TerraRegistry { } @Override - public boolean add(String name, TerraAddon addon) { - if(contains(name)) throw new IllegalArgumentException("Addon " + name + " is already registered."); + public boolean add(String identifier, TerraAddon addon) { + if(contains(identifier)) throw new IllegalArgumentException("Addon " + identifier + " is already registered."); addon.initialize(); main.getLogger().info("Loaded addon " + addon.getName() + " v" + addon.getVersion() + ", by " + addon.getAuthor()); - return super.add(name, addon); + return super.add(identifier, addon); } @Override @@ -92,7 +93,7 @@ public class AddonRegistry extends TerraRegistry { } try { addChecked(loadedAddon.getName(), loadedAddon); - } catch(IllegalArgumentException e) { + } catch(DuplicateEntryException e) { valid = false; main.getLogger().severe("Duplicate addon ID; addon with ID " + loadedAddon.getName() + " is already loaded."); main.getLogger().severe("Existing addon class: " + get(loadedAddon.getName()).getClass().getCanonicalName()); diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/TerraListener.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/TerraListener.java index 4c98e3cea..edb09bd22 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/TerraListener.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/TerraListener.java @@ -3,9 +3,11 @@ package com.dfsek.terra.bukkit.listeners; import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.core.event.EventListener; import com.dfsek.terra.api.core.event.annotations.Global; +import com.dfsek.terra.api.core.event.annotations.Priority; import com.dfsek.terra.api.core.event.events.config.ConfigPackPreLoadEvent; import com.dfsek.terra.bukkit.world.BukkitAdapter; import com.dfsek.terra.bukkit.world.BukkitTree; +import com.dfsek.terra.registry.exception.DuplicateEntryException; import org.bukkit.TreeType; public class TerraListener implements EventListener { @@ -16,9 +18,13 @@ public class TerraListener implements EventListener { } @Global + @Priority(Priority.LOWEST) public void injectTrees(ConfigPackPreLoadEvent event) { for(TreeType value : TreeType.values()) { - event.getPack().getTreeRegistry().add(BukkitAdapter.TREE_TRANSFORMER.translate(value), new BukkitTree(value, main)); + try { + event.getPack().getTreeRegistry().add(BukkitAdapter.TREE_TRANSFORMER.translate(value), new BukkitTree(value, main)); + } catch(DuplicateEntryException ignore) { // If another addon has already registered trees, do nothing. + } } } } From 05cd0b625c1c5abd37dddf30946403508f50ae76 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 21 Feb 2021 23:08:51 -0700 Subject: [PATCH 11/95] notnull annotations --- .../main/java/com/dfsek/terra/addons/annotations/Addon.java | 4 +++- .../main/java/com/dfsek/terra/addons/annotations/Author.java | 4 +++- .../main/java/com/dfsek/terra/addons/annotations/Depends.java | 4 +++- .../main/java/com/dfsek/terra/addons/annotations/Version.java | 4 +++- .../main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java | 2 +- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/com/dfsek/terra/addons/annotations/Addon.java b/common/src/main/java/com/dfsek/terra/addons/annotations/Addon.java index 79db4b24b..fc3fd8f23 100644 --- a/common/src/main/java/com/dfsek/terra/addons/annotations/Addon.java +++ b/common/src/main/java/com/dfsek/terra/addons/annotations/Addon.java @@ -1,5 +1,7 @@ package com.dfsek.terra.addons.annotations; +import org.jetbrains.annotations.NotNull; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -14,5 +16,5 @@ public @interface Addon { /** * @return The ID of the addon. */ - String value(); + @NotNull String value(); } diff --git a/common/src/main/java/com/dfsek/terra/addons/annotations/Author.java b/common/src/main/java/com/dfsek/terra/addons/annotations/Author.java index b7bd416e3..5df87c2e8 100644 --- a/common/src/main/java/com/dfsek/terra/addons/annotations/Author.java +++ b/common/src/main/java/com/dfsek/terra/addons/annotations/Author.java @@ -1,5 +1,7 @@ package com.dfsek.terra.addons.annotations; +import org.jetbrains.annotations.NotNull; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -14,5 +16,5 @@ public @interface Author { /** * @return Name of the addon author. */ - String value(); + @NotNull String value(); } diff --git a/common/src/main/java/com/dfsek/terra/addons/annotations/Depends.java b/common/src/main/java/com/dfsek/terra/addons/annotations/Depends.java index ded30d6ba..cf0b05b5a 100644 --- a/common/src/main/java/com/dfsek/terra/addons/annotations/Depends.java +++ b/common/src/main/java/com/dfsek/terra/addons/annotations/Depends.java @@ -1,5 +1,7 @@ package com.dfsek.terra.addons.annotations; +import org.jetbrains.annotations.NotNull; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -14,5 +16,5 @@ public @interface Depends { /** * @return All addons this addon is dependent upon. */ - String[] value(); + @NotNull String[] value(); } diff --git a/common/src/main/java/com/dfsek/terra/addons/annotations/Version.java b/common/src/main/java/com/dfsek/terra/addons/annotations/Version.java index 87ce44984..48f5f44c2 100644 --- a/common/src/main/java/com/dfsek/terra/addons/annotations/Version.java +++ b/common/src/main/java/com/dfsek/terra/addons/annotations/Version.java @@ -1,5 +1,7 @@ package com.dfsek.terra.addons.annotations; +import org.jetbrains.annotations.NotNull; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -14,5 +16,5 @@ public @interface Version { /** * @return Version of the addon. */ - String value(); + @NotNull String value(); } diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java index ce150c8e7..bbc9a004d 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java @@ -290,7 +290,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { } } - @Addon("Terra") + @Addon("Terra-Bukkit") @Version("1.0.0") @Author("Terra") private static final class BukkitAddon extends TerraAddon { From 46a08e49f5641e76382a439b1a7f44af8d27e65a Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 22 Feb 2021 10:32:38 -0700 Subject: [PATCH 12/95] registry stuff --- common/build.gradle.kts | 1 + .../com/dfsek/terra/api/core/TerraPlugin.java | 12 +++-- .../biome/provider/ImageBiomeProvider.java | 4 +- .../dfsek/terra/config/pack/ConfigPack.java | 4 +- .../dfsek/terra/registry/CheckedRegistry.java | 41 ++++----------- .../dfsek/terra/registry/LockedRegistry.java | 52 +++++++++++++++++++ .../{TerraRegistry.java => OpenRegistry.java} | 23 ++++---- .../com/dfsek/terra/registry/Registry.java | 46 ++++++++++++++++ .../terra/registry/config/BiomeRegistry.java | 4 +- .../terra/registry/config/CarverRegistry.java | 4 +- .../terra/registry/config/FloraRegistry.java | 4 +- .../registry/config/FunctionRegistry.java | 4 +- .../terra/registry/config/LootRegistry.java | 4 +- .../terra/registry/config/NoiseRegistry.java | 4 +- .../terra/registry/config/OreRegistry.java | 4 +- .../registry/config/PaletteRegistry.java | 4 +- .../terra/registry/config/ScriptRegistry.java | 4 +- .../registry/config/StructureRegistry.java | 4 +- .../terra/registry/config/TreeRegistry.java | 4 +- .../terra/registry/master/AddonRegistry.java | 4 +- .../terra/registry/master/ConfigRegistry.java | 4 +- .../src/test/java/biome/DistributionTest.java | 13 ++--- common/src/test/java/biome/ImageTest.java | 4 +- .../dfsek/terra/bukkit/TerraBukkitPlugin.java | 21 ++++++-- .../bukkit/command/command/PacksCommand.java | 4 +- .../bukkit/command/command/ReloadCommand.java | 5 +- .../dfsek/terra/fabric/TerraFabricPlugin.java | 21 +++++--- .../terra/fabric/world/TerraBiomeSource.java | 2 +- .../FabricChunkGeneratorWrapper.java | 2 +- .../com/dfsek/terra/StandalonePlugin.java | 17 ++++-- .../com/dfsek/terra/region/Generator.java | 2 +- 31 files changed, 213 insertions(+), 113 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/registry/LockedRegistry.java rename common/src/main/java/com/dfsek/terra/registry/{TerraRegistry.java => OpenRegistry.java} (84%) create mode 100644 common/src/main/java/com/dfsek/terra/registry/Registry.java diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 38d982bca..38a1a4f8e 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -18,6 +18,7 @@ dependencies { "shadedApi"("net.jafama:jafama:2.3.2") "shadedApi"("org.yaml:snakeyaml:1.27") "shadedApi"("org.ow2.asm:asm:9.0") + "shadedApi"("commons-io:commons-io:2.6") "compileOnly"("com.googlecode.json-simple:json-simple:1.1") diff --git a/common/src/main/java/com/dfsek/terra/api/core/TerraPlugin.java b/common/src/main/java/com/dfsek/terra/api/core/TerraPlugin.java index 8bd907761..e5dea5f9a 100644 --- a/common/src/main/java/com/dfsek/terra/api/core/TerraPlugin.java +++ b/common/src/main/java/com/dfsek/terra/api/core/TerraPlugin.java @@ -1,5 +1,6 @@ package com.dfsek.terra.api.core; +import com.dfsek.terra.addons.addon.TerraAddon; import com.dfsek.terra.api.LoaderRegistrar; import com.dfsek.terra.api.core.event.EventManager; import com.dfsek.terra.api.platform.handle.ItemHandle; @@ -7,9 +8,10 @@ import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.config.PluginConfig; import com.dfsek.terra.config.lang.Language; +import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.debug.DebugLogger; -import com.dfsek.terra.registry.master.AddonRegistry; -import com.dfsek.terra.registry.master.ConfigRegistry; +import com.dfsek.terra.registry.CheckedRegistry; +import com.dfsek.terra.registry.LockedRegistry; import com.dfsek.terra.world.TerraWorld; import java.io.File; @@ -32,11 +34,11 @@ public interface TerraPlugin extends LoaderRegistrar { Language getLanguage(); - ConfigRegistry getRegistry(); + CheckedRegistry getConfigRegistry(); - AddonRegistry getAddons(); + LockedRegistry getAddons(); - void reload(); + boolean reload(); ItemHandle getItemHandle(); diff --git a/common/src/main/java/com/dfsek/terra/api/world/biome/provider/ImageBiomeProvider.java b/common/src/main/java/com/dfsek/terra/api/world/biome/provider/ImageBiomeProvider.java index 5225d1432..abf5de855 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/biome/provider/ImageBiomeProvider.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/provider/ImageBiomeProvider.java @@ -1,7 +1,7 @@ package com.dfsek.terra.api.world.biome.provider; import com.dfsek.terra.api.world.biome.TerraBiome; -import com.dfsek.terra.registry.TerraRegistry; +import com.dfsek.terra.registry.OpenRegistry; import net.jafama.FastMath; import java.awt.*; @@ -15,7 +15,7 @@ public class ImageBiomeProvider implements BiomeProvider, BiomeProvider.BiomePro private final int resolution; private final Align align; - public ImageBiomeProvider(TerraRegistry registry, BufferedImage image, int resolution, Align align) { + public ImageBiomeProvider(OpenRegistry registry, BufferedImage image, int resolution, Align align) { this.image = image; this.resolution = resolution; this.align = align; diff --git a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java index 9ad335ecb..d7c32f3c6 100644 --- a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java +++ b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java @@ -50,7 +50,7 @@ import com.dfsek.terra.config.templates.PaletteTemplate; import com.dfsek.terra.config.templates.StructureTemplate; import com.dfsek.terra.config.templates.TreeTemplate; import com.dfsek.terra.registry.CheckedRegistry; -import com.dfsek.terra.registry.TerraRegistry; +import com.dfsek.terra.registry.OpenRegistry; import com.dfsek.terra.registry.config.BiomeRegistry; import com.dfsek.terra.registry.config.CarverRegistry; import com.dfsek.terra.registry.config.FloraRegistry; @@ -197,7 +197,7 @@ public class ConfigPack implements LoaderRegistrar { } } - public static void buildAll(TerraFactory factory, TerraRegistry registry, List configTemplates, TerraPlugin main) throws LoadException { + public static void buildAll(TerraFactory factory, OpenRegistry registry, List configTemplates, TerraPlugin main) throws LoadException { for(C template : configTemplates) registry.add(template.getID(), factory.build(template, main)); } diff --git a/common/src/main/java/com/dfsek/terra/registry/CheckedRegistry.java b/common/src/main/java/com/dfsek/terra/registry/CheckedRegistry.java index 99c4047ae..5d8963f19 100644 --- a/common/src/main/java/com/dfsek/terra/registry/CheckedRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/CheckedRegistry.java @@ -2,7 +2,6 @@ package com.dfsek.terra.registry; import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; -import com.dfsek.tectonic.loading.TypeLoader; import com.dfsek.terra.registry.exception.DuplicateEntryException; import java.lang.reflect.Type; @@ -11,14 +10,14 @@ import java.util.function.BiConsumer; import java.util.function.Consumer; /** - * Wrapper for a registry that ensures checked access. + * Wrapper for a registry that ensures checked additions. * * @param Type in registry */ -public class CheckedRegistry implements TypeLoader { - private final TerraRegistry registry; +public class CheckedRegistry implements Registry { + private final OpenRegistry registry; - public CheckedRegistry(TerraRegistry registry) { + public CheckedRegistry(OpenRegistry registry) { this.registry = registry; } @@ -47,49 +46,27 @@ public class CheckedRegistry implements TypeLoader { registry.add(identifier, value); } - /** - * Get a value from the registry. - * - * @param identifier Identifier of value. - * @return Value matching the identifier, {@code null} if no value is present. - */ + @Override public T get(String identifier) { return registry.get(identifier); } - /** - * Check if the registry contains a value. - * - * @param identifier Identifier of value. - * @return Whether the registry contains the value. - */ + @Override public boolean contains(String identifier) { return registry.contains(identifier); } - /** - * Perform the given action for every value in the registry. - * - * @param consumer Action to perform on value. - */ + @Override public void forEach(Consumer consumer) { registry.forEach(consumer); } - /** - * Perform an action for every key-value pair in the registry. - * - * @param consumer Action to perform on pair. - */ + @Override public void forEach(BiConsumer consumer) { registry.forEach(consumer); } - /** - * Get the entries of this registry as a {@link Set}. - * - * @return Set containing all entries. - */ + @Override public Set entries() { return registry.entries(); } diff --git a/common/src/main/java/com/dfsek/terra/registry/LockedRegistry.java b/common/src/main/java/com/dfsek/terra/registry/LockedRegistry.java new file mode 100644 index 000000000..709088366 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/registry/LockedRegistry.java @@ -0,0 +1,52 @@ +package com.dfsek.terra.registry; + +import com.dfsek.tectonic.exception.LoadException; +import com.dfsek.tectonic.loading.ConfigLoader; + +import java.lang.reflect.Type; +import java.util.Set; +import java.util.function.BiConsumer; +import java.util.function.Consumer; + +/** + * Wrapper for a registry that forbids all write access. + * + * @param Type in registry + */ +public class LockedRegistry implements Registry { + private final OpenRegistry registry; + + public LockedRegistry(OpenRegistry registry) { + this.registry = registry; + } + + @Override + public T get(String identifier) { + return registry.get(identifier); + } + + @Override + public boolean contains(String identifier) { + return registry.contains(identifier); + } + + @Override + public void forEach(Consumer consumer) { + registry.forEach(consumer); + } + + @Override + public void forEach(BiConsumer consumer) { + registry.forEach(consumer); + } + + @Override + public Set entries() { + return registry.entries(); + } + + @Override + public T load(Type t, Object c, ConfigLoader loader) throws LoadException { + return registry.load(t, c, loader); + } +} diff --git a/common/src/main/java/com/dfsek/terra/registry/TerraRegistry.java b/common/src/main/java/com/dfsek/terra/registry/OpenRegistry.java similarity index 84% rename from common/src/main/java/com/dfsek/terra/registry/TerraRegistry.java rename to common/src/main/java/com/dfsek/terra/registry/OpenRegistry.java index 1d4b1d1d0..5d3fbb5bd 100644 --- a/common/src/main/java/com/dfsek/terra/registry/TerraRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/OpenRegistry.java @@ -13,7 +13,11 @@ import java.util.Set; import java.util.function.BiConsumer; import java.util.function.Consumer; -public abstract class TerraRegistry implements TypeLoader { +/** + * Registry implementation with read/write access. For internal use only. + * @param + */ +public abstract class OpenRegistry implements Registry { private final Map objects = new HashMap<>(); @Override @@ -49,34 +53,27 @@ public abstract class TerraRegistry implements TypeLoader { add(identifier, value); } - /** - * Check if the registry contains a value. - * - * @param identifier Identifier of value. - * @return Whether the registry contains the value. - */ + @Override public boolean contains(String identifier) { return objects.containsKey(identifier); } - /** - * Get a value from the registry. - * - * @param identifier Identifier of value. - * @return Value matching the identifier, {@code null} if no value is present. - */ + @Override public T get(String identifier) { return objects.get(identifier); } + @Override public void forEach(Consumer consumer) { objects.forEach((id, obj) -> consumer.accept(obj)); } + @Override public void forEach(BiConsumer consumer) { objects.forEach(consumer); } + @Override public Set entries() { return new HashSet<>(objects.values()); } diff --git a/common/src/main/java/com/dfsek/terra/registry/Registry.java b/common/src/main/java/com/dfsek/terra/registry/Registry.java new file mode 100644 index 000000000..5289cb39a --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/registry/Registry.java @@ -0,0 +1,46 @@ +package com.dfsek.terra.registry; + +import com.dfsek.tectonic.loading.TypeLoader; + +import java.util.Set; +import java.util.function.BiConsumer; +import java.util.function.Consumer; + +public interface Registry extends TypeLoader { + /** + * Get a value from the registry. + * + * @param identifier Identifier of value. + * @return Value matching the identifier, {@code null} if no value is present. + */ + T get(String identifier); + + /** + * Check if the registry contains a value. + * + * @param identifier Identifier of value. + * @return Whether the registry contains the value. + */ + boolean contains(String identifier); + + /** + * Perform the given action for every value in the registry. + * + * @param consumer Action to perform on value. + */ + void forEach(Consumer consumer); + + /** + * Perform an action for every key-value pair in the registry. + * + * @param consumer Action to perform on pair. + */ + void forEach(BiConsumer consumer); + + /** + * Get the entries of this registry as a {@link Set}. + * + * @return Set containing all entries. + */ + Set entries(); +} diff --git a/common/src/main/java/com/dfsek/terra/registry/config/BiomeRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/BiomeRegistry.java index 42a093961..924efc3d6 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/BiomeRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/BiomeRegistry.java @@ -3,11 +3,11 @@ package com.dfsek.terra.registry.config; import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; import com.dfsek.terra.api.world.biome.TerraBiome; -import com.dfsek.terra.registry.TerraRegistry; +import com.dfsek.terra.registry.OpenRegistry; import java.lang.reflect.Type; -public class BiomeRegistry extends TerraRegistry { +public class BiomeRegistry extends OpenRegistry { @Override public TerraBiome load(Type type, Object o, ConfigLoader configLoader) throws LoadException { if(o.equals("SELF")) return null; diff --git a/common/src/main/java/com/dfsek/terra/registry/config/CarverRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/CarverRegistry.java index 46fe3d725..63b80f715 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/CarverRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/CarverRegistry.java @@ -1,7 +1,7 @@ package com.dfsek.terra.registry.config; import com.dfsek.terra.carving.UserDefinedCarver; -import com.dfsek.terra.registry.TerraRegistry; +import com.dfsek.terra.registry.OpenRegistry; -public class CarverRegistry extends TerraRegistry { +public class CarverRegistry extends OpenRegistry { } diff --git a/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java index 05482e816..3a3905330 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java @@ -5,14 +5,14 @@ import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.util.world.MaterialSet; import com.dfsek.terra.api.world.flora.Flora; -import com.dfsek.terra.registry.TerraRegistry; +import com.dfsek.terra.registry.OpenRegistry; import com.dfsek.terra.world.population.items.flora.ConstantFlora; import java.util.Arrays; import java.util.Collections; import java.util.concurrent.Callable; -public class FloraRegistry extends TerraRegistry { +public class FloraRegistry extends OpenRegistry { private final TerraPlugin main; public FloraRegistry(TerraPlugin main) { diff --git a/common/src/main/java/com/dfsek/terra/registry/config/FunctionRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/FunctionRegistry.java index 6e0e465e6..2d140137a 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/FunctionRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/FunctionRegistry.java @@ -1,7 +1,7 @@ package com.dfsek.terra.registry.config; import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder; -import com.dfsek.terra.registry.TerraRegistry; +import com.dfsek.terra.registry.OpenRegistry; -public class FunctionRegistry extends TerraRegistry> { +public class FunctionRegistry extends OpenRegistry> { } diff --git a/common/src/main/java/com/dfsek/terra/registry/config/LootRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/LootRegistry.java index 21358ea41..8c8e987aa 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/LootRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/LootRegistry.java @@ -1,7 +1,7 @@ package com.dfsek.terra.registry.config; import com.dfsek.terra.api.structures.loot.LootTable; -import com.dfsek.terra.registry.TerraRegistry; +import com.dfsek.terra.registry.OpenRegistry; -public class LootRegistry extends TerraRegistry { +public class LootRegistry extends OpenRegistry { } diff --git a/common/src/main/java/com/dfsek/terra/registry/config/NoiseRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/NoiseRegistry.java index e6625b3e9..d84227455 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/NoiseRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/NoiseRegistry.java @@ -22,11 +22,11 @@ import com.dfsek.terra.config.loaders.config.sampler.templates.noise.fractal.Rid import com.dfsek.terra.config.loaders.config.sampler.templates.normalizer.ClampNormalizerTemplate; import com.dfsek.terra.config.loaders.config.sampler.templates.normalizer.LinearNormalizerTemplate; import com.dfsek.terra.config.loaders.config.sampler.templates.normalizer.NormalNormalizerTemplate; -import com.dfsek.terra.registry.TerraRegistry; +import com.dfsek.terra.registry.OpenRegistry; import java.util.function.Supplier; -public class NoiseRegistry extends TerraRegistry>> { +public class NoiseRegistry extends OpenRegistry>> { public NoiseRegistry() { add("LINEAR", LinearNormalizerTemplate::new); add("NORMAL", NormalNormalizerTemplate::new); diff --git a/common/src/main/java/com/dfsek/terra/registry/config/OreRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/OreRegistry.java index 3f8e285df..010a812f2 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/OreRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/OreRegistry.java @@ -1,7 +1,7 @@ package com.dfsek.terra.registry.config; -import com.dfsek.terra.registry.TerraRegistry; +import com.dfsek.terra.registry.OpenRegistry; import com.dfsek.terra.world.population.items.ores.Ore; -public class OreRegistry extends TerraRegistry { +public class OreRegistry extends OpenRegistry { } diff --git a/common/src/main/java/com/dfsek/terra/registry/config/PaletteRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/PaletteRegistry.java index e13cfb6ba..53a857d9e 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/PaletteRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/PaletteRegistry.java @@ -4,9 +4,9 @@ import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.world.palette.Palette; import com.dfsek.terra.api.world.palette.SinglePalette; -import com.dfsek.terra.registry.TerraRegistry; +import com.dfsek.terra.registry.OpenRegistry; -public class PaletteRegistry extends TerraRegistry> { +public class PaletteRegistry extends OpenRegistry> { private final TerraPlugin main; public PaletteRegistry(TerraPlugin main) { this.main = main; diff --git a/common/src/main/java/com/dfsek/terra/registry/config/ScriptRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/ScriptRegistry.java index d4320f854..a715c5ad9 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/ScriptRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/ScriptRegistry.java @@ -1,7 +1,7 @@ package com.dfsek.terra.registry.config; import com.dfsek.terra.api.structures.script.StructureScript; -import com.dfsek.terra.registry.TerraRegistry; +import com.dfsek.terra.registry.OpenRegistry; -public class ScriptRegistry extends TerraRegistry { +public class ScriptRegistry extends OpenRegistry { } diff --git a/common/src/main/java/com/dfsek/terra/registry/config/StructureRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/StructureRegistry.java index 523395fa7..56a24711d 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/StructureRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/StructureRegistry.java @@ -1,7 +1,7 @@ package com.dfsek.terra.registry.config; -import com.dfsek.terra.registry.TerraRegistry; +import com.dfsek.terra.registry.OpenRegistry; import com.dfsek.terra.world.population.items.TerraStructure; -public class StructureRegistry extends TerraRegistry { +public class StructureRegistry extends OpenRegistry { } diff --git a/common/src/main/java/com/dfsek/terra/registry/config/TreeRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/TreeRegistry.java index b444dbc44..bf9fa629f 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/TreeRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/TreeRegistry.java @@ -14,14 +14,14 @@ import com.dfsek.terra.api.world.tree.fractal.trees.ShatteredTree; import com.dfsek.terra.api.world.tree.fractal.trees.SmallShatteredPillar; import com.dfsek.terra.api.world.tree.fractal.trees.SmallShatteredTree; import com.dfsek.terra.api.world.tree.fractal.trees.SpruceTree; -import com.dfsek.terra.registry.TerraRegistry; +import com.dfsek.terra.registry.OpenRegistry; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.Random; import java.util.Set; -public class TreeRegistry extends TerraRegistry { +public class TreeRegistry extends OpenRegistry { private final TerraPlugin main; public TreeRegistry(TerraPlugin main) { diff --git a/common/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java b/common/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java index 266a8bb0a..3483b3091 100644 --- a/common/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java @@ -8,7 +8,7 @@ import com.dfsek.terra.addons.loading.AddonLoadException; import com.dfsek.terra.addons.loading.pre.AddonPool; import com.dfsek.terra.addons.loading.pre.PreLoadAddon; import com.dfsek.terra.api.core.TerraPlugin; -import com.dfsek.terra.registry.TerraRegistry; +import com.dfsek.terra.registry.OpenRegistry; import com.dfsek.terra.registry.exception.DuplicateEntryException; import java.io.File; @@ -18,7 +18,7 @@ import java.lang.reflect.InvocationTargetException; import java.util.logging.LogManager; import java.util.logging.Logger; -public class AddonRegistry extends TerraRegistry { +public class AddonRegistry extends OpenRegistry { private final TerraPlugin main; public AddonRegistry(TerraPlugin main) { diff --git a/common/src/main/java/com/dfsek/terra/registry/master/ConfigRegistry.java b/common/src/main/java/com/dfsek/terra/registry/master/ConfigRegistry.java index 0cf923850..17476237c 100644 --- a/common/src/main/java/com/dfsek/terra/registry/master/ConfigRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/master/ConfigRegistry.java @@ -3,7 +3,7 @@ package com.dfsek.terra.registry.master; import com.dfsek.tectonic.exception.ConfigException; import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.config.pack.ConfigPack; -import com.dfsek.terra.registry.TerraRegistry; +import com.dfsek.terra.registry.OpenRegistry; import java.io.File; import java.io.IOException; @@ -12,7 +12,7 @@ import java.util.zip.ZipFile; /** * Class to hold config packs */ -public class ConfigRegistry extends TerraRegistry { +public class ConfigRegistry extends OpenRegistry { public void load(File folder, TerraPlugin main) throws ConfigException { ConfigPack pack = new ConfigPack(folder, main); add(pack.getTemplate().getID(), pack); diff --git a/common/src/test/java/biome/DistributionTest.java b/common/src/test/java/biome/DistributionTest.java index 2f91fb2a3..abecc1efd 100644 --- a/common/src/test/java/biome/DistributionTest.java +++ b/common/src/test/java/biome/DistributionTest.java @@ -9,6 +9,7 @@ import com.dfsek.tectonic.config.ValidatedConfigTemplate; import com.dfsek.tectonic.exception.ConfigException; import com.dfsek.tectonic.loading.ConfigLoader; import com.dfsek.tectonic.loading.TypeRegistry; +import com.dfsek.terra.addons.addon.TerraAddon; import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.core.event.EventManager; import com.dfsek.terra.api.math.ProbabilityCollection; @@ -34,10 +35,10 @@ import com.dfsek.terra.config.loaders.config.sampler.NoiseSamplerBuilderLoader; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.config.templates.AbstractableTemplate; import com.dfsek.terra.debug.DebugLogger; +import com.dfsek.terra.registry.CheckedRegistry; +import com.dfsek.terra.registry.LockedRegistry; import com.dfsek.terra.registry.config.BiomeRegistry; import com.dfsek.terra.registry.config.NoiseRegistry; -import com.dfsek.terra.registry.master.AddonRegistry; -import com.dfsek.terra.registry.master.ConfigRegistry; import com.dfsek.terra.world.TerraWorld; import javax.swing.*; @@ -99,18 +100,18 @@ public class DistributionTest { } @Override - public ConfigRegistry getRegistry() { + public CheckedRegistry getConfigRegistry() { return null; } @Override - public AddonRegistry getAddons() { + public LockedRegistry getAddons() { return null; } @Override - public void reload() { - + public boolean reload() { + return true; } @Override diff --git a/common/src/test/java/biome/ImageTest.java b/common/src/test/java/biome/ImageTest.java index bf6a9460f..8e52c0ce9 100644 --- a/common/src/test/java/biome/ImageTest.java +++ b/common/src/test/java/biome/ImageTest.java @@ -17,7 +17,7 @@ import com.dfsek.terra.api.world.biome.provider.ImageBiomeProvider; import com.dfsek.terra.config.fileloaders.FolderLoader; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.config.templates.AbstractableTemplate; -import com.dfsek.terra.registry.TerraRegistry; +import com.dfsek.terra.registry.OpenRegistry; import org.junit.jupiter.api.Test; import javax.imageio.ImageIO; @@ -44,7 +44,7 @@ public class ImageTest { AbstractConfigLoader loader = new AbstractConfigLoader(); - TerraRegistry biomeRegistry = new TerraRegistry() { + OpenRegistry biomeRegistry = new OpenRegistry() { }; folderLoader.open("biomes", ".yml").then(inputStreams -> ConfigPack.buildAll((template, main) -> template, biomeRegistry, loader.load(inputStreams, TestBiome::new), null)); diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java index bbc9a004d..1d3b70dcb 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java @@ -32,6 +32,8 @@ import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.Language; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.debug.DebugLogger; +import com.dfsek.terra.registry.CheckedRegistry; +import com.dfsek.terra.registry.LockedRegistry; import com.dfsek.terra.registry.master.AddonRegistry; import com.dfsek.terra.registry.master.ConfigRegistry; import com.dfsek.terra.world.TerraWorld; @@ -55,7 +57,10 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { private final Map generatorMap = new HashMap<>(); private final Map worldMap = new HashMap<>(); private final Map worlds = new HashMap<>(); + private final ConfigRegistry registry = new ConfigRegistry(); + private final CheckedRegistry checkedRegistry = new CheckedRegistry<>(registry); + private final PluginConfig config = new PluginConfig(); private final ItemHandle itemHandle = new BukkitItemHandle(); private WorldHandle handle = new BukkitWorldHandle(); @@ -76,9 +81,14 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { } private final AddonRegistry addonRegistry = new AddonRegistry(new BukkitAddon(this), this); + private final LockedRegistry addonLockedRegistry = new LockedRegistry<>(addonRegistry); - public void reload() { + + public boolean reload() { + config.load(this); + LangUtil.load(config.getLanguage(), this); // Load language. + boolean succeed = registry.loadAll(this); Map newMap = new HashMap<>(); worldMap.forEach((world, tw) -> { ((BukkitChunkGeneratorWrapper) world.getGenerator().getHandle()).getHandle().getCache().clear(); @@ -87,6 +97,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { }); worldMap.clear(); worldMap.putAll(newMap); + return succeed; } @Override @@ -221,8 +232,8 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { return LangUtil.getLanguage(); } - public ConfigRegistry getRegistry() { - return registry; + public CheckedRegistry getConfigRegistry() { + return checkedRegistry; } public TerraWorld getWorld(World w) { @@ -258,8 +269,8 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { } @Override - public AddonRegistry getAddons() { - return addonRegistry; + public LockedRegistry getAddons() { + return addonLockedRegistry; } public enum BukkitVersion { diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/PacksCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/PacksCommand.java index 2a36c4986..0cdea2157 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/PacksCommand.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/PacksCommand.java @@ -3,7 +3,9 @@ package com.dfsek.terra.bukkit.command.command; import com.dfsek.terra.bukkit.BukkitCommandSender; import com.dfsek.terra.bukkit.command.Command; import com.dfsek.terra.config.lang.LangUtil; +import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.config.pack.ConfigPackTemplate; +import com.dfsek.terra.registry.CheckedRegistry; import com.dfsek.terra.registry.master.ConfigRegistry; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; @@ -29,7 +31,7 @@ public class PacksCommand extends Command { @Override public boolean execute(@NotNull CommandSender commandSender, org.bukkit.command.@NotNull Command command, @NotNull String s, @NotNull String[] strings) { - ConfigRegistry registry = getMain().getRegistry(); + CheckedRegistry registry = getMain().getConfigRegistry(); if(registry.entries().size() == 0) { LangUtil.send("command.packs.none", new BukkitCommandSender(commandSender)); diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/ReloadCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/ReloadCommand.java index b6b4093ac..50e6a2cc9 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/ReloadCommand.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/ReloadCommand.java @@ -28,13 +28,10 @@ public class ReloadCommand extends Command implements DebugCommand { @Override public boolean execute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) { - getMain().getTerraConfig().load(getMain()); - LangUtil.load(getMain().getTerraConfig().getLanguage(), getMain()); // Load language. - if(!getMain().getRegistry().loadAll(getMain())) { + if(!getMain().reload()) { LangUtil.send("command.reload-error", new BukkitCommandSender(sender)); return true; } - getMain().reload(); LangUtil.send("command.reload", new BukkitCommandSender(sender)); return true; } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index 50c9da071..b08cad22f 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -1,6 +1,7 @@ package com.dfsek.terra.fabric; import com.dfsek.tectonic.loading.TypeRegistry; +import com.dfsek.terra.addons.addon.TerraAddon; import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.core.event.EventManager; import com.dfsek.terra.api.core.event.TerraEventManager; @@ -26,6 +27,8 @@ import com.dfsek.terra.fabric.world.FabricWorldHandle; import com.dfsek.terra.fabric.world.TerraBiomeSource; import com.dfsek.terra.fabric.world.features.PopulatorFeature; import com.dfsek.terra.fabric.world.generator.FabricChunkGeneratorWrapper; +import com.dfsek.terra.registry.CheckedRegistry; +import com.dfsek.terra.registry.LockedRegistry; import com.dfsek.terra.registry.master.AddonRegistry; import com.dfsek.terra.registry.master.ConfigRegistry; import com.dfsek.terra.world.TerraWorld; @@ -86,8 +89,12 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { private final ItemHandle itemHandle = new FabricItemHandle(); private final WorldHandle worldHandle = new FabricWorldHandle(); private final ConfigRegistry registry = new ConfigRegistry(); + private final CheckedRegistry checkedRegistry = new CheckedRegistry<>(registry); private final AddonRegistry addonRegistry = new AddonRegistry(this); + private final LockedRegistry addonLockedRegistry = new LockedRegistry<>(addonRegistry); + + private File config; private static final Transformer> TREE_TRANSFORMER = new Transformer.Builder>() .addTransform(TerraFabricPlugin::getFeature) @@ -127,7 +134,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { public TerraWorld getWorld(World world) { return worldMap.computeIfAbsent(world.getSeed(), w -> { logger.info("Loading world " + w); - return new TerraWorld(world, getRegistry().get("DEFAULT"), this); + return new TerraWorld(world, getConfigRegistry().get("DEFAULT"), this); }); } @@ -161,18 +168,18 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { } @Override - public ConfigRegistry getRegistry() { - return registry; + public CheckedRegistry getConfigRegistry() { + return checkedRegistry; } @Override - public AddonRegistry getAddons() { - return addonRegistry; + public LockedRegistry getAddons() { + return addonLockedRegistry; } @Override - public void reload() { - + public boolean reload() { + return true; } @Override diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/TerraBiomeSource.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/TerraBiomeSource.java index f73c0f16d..2f0903ab8 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/TerraBiomeSource.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/TerraBiomeSource.java @@ -18,7 +18,7 @@ import java.util.stream.Collectors; public class TerraBiomeSource extends BiomeSource { public static final Codec PACK_CODEC = (RecordCodecBuilder.create(config -> config.group( Codec.STRING.fieldOf("pack").forGetter(pack -> pack.getTemplate().getID()) - ).apply(config, config.stable(TerraFabricPlugin.getInstance().getRegistry()::get)))); + ).apply(config, config.stable(TerraFabricPlugin.getInstance().getConfigRegistry()::get)))); public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( RegistryLookupCodec.of(Registry.BIOME_KEY).forGetter(source -> source.biomeRegistry), Codec.LONG.fieldOf("seed").stable().forGetter(source -> source.seed), diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java index 16bc8983d..1bb87f0e1 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java @@ -35,7 +35,7 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements com.d private final TerraBiomeSource biomeSource; public static final Codec PACK_CODEC = (RecordCodecBuilder.create(config -> config.group( Codec.STRING.fieldOf("pack").forGetter(pack -> pack.getTemplate().getID()) - ).apply(config, config.stable(TerraFabricPlugin.getInstance().getRegistry()::get)))); + ).apply(config, config.stable(TerraFabricPlugin.getInstance().getConfigRegistry()::get)))); public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( TerraBiomeSource.CODEC.fieldOf("biome_source").forGetter(generator -> generator.biomeSource), Codec.LONG.fieldOf("seed").stable().forGetter(generator -> generator.seed), diff --git a/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java b/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java index aa918951a..9257c40ca 100644 --- a/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java +++ b/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java @@ -1,6 +1,7 @@ package com.dfsek.terra; import com.dfsek.tectonic.loading.TypeRegistry; +import com.dfsek.terra.addons.addon.TerraAddon; import com.dfsek.terra.api.core.TerraPlugin; import com.dfsek.terra.api.core.event.EventManager; import com.dfsek.terra.api.core.event.TerraEventManager; @@ -14,9 +15,12 @@ import com.dfsek.terra.config.GenericLoaders; import com.dfsek.terra.config.PluginConfig; import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.Language; +import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.debug.DebugLogger; import com.dfsek.terra.platform.RawBiome; import com.dfsek.terra.platform.RawWorldHandle; +import com.dfsek.terra.registry.CheckedRegistry; +import com.dfsek.terra.registry.LockedRegistry; import com.dfsek.terra.registry.master.AddonRegistry; import com.dfsek.terra.registry.master.ConfigRegistry; import com.dfsek.terra.world.TerraWorld; @@ -28,6 +32,9 @@ import java.util.logging.Logger; public class StandalonePlugin implements TerraPlugin { private final ConfigRegistry registry = new ConfigRegistry(); private final AddonRegistry addonRegistry = new AddonRegistry(this); + + private final LockedRegistry addonLockedRegistry = new LockedRegistry<>(addonRegistry); + private final PluginConfig config = new PluginConfig(); private final RawWorldHandle worldHandle = new RawWorldHandle(); private final EventManager eventManager = new TerraEventManager(this); @@ -77,17 +84,17 @@ public class StandalonePlugin implements TerraPlugin { } @Override - public ConfigRegistry getRegistry() { - return registry; + public CheckedRegistry getConfigRegistry() { + return new CheckedRegistry<>(registry); } @Override - public AddonRegistry getAddons() { - return addonRegistry; + public LockedRegistry getAddons() { + return addonLockedRegistry; } @Override - public void reload() { + public boolean reload() { throw new UnsupportedOperationException(); } diff --git a/platforms/region/src/main/java/com/dfsek/terra/region/Generator.java b/platforms/region/src/main/java/com/dfsek/terra/region/Generator.java index 616cc20ec..d1725b3c5 100644 --- a/platforms/region/src/main/java/com/dfsek/terra/region/Generator.java +++ b/platforms/region/src/main/java/com/dfsek/terra/region/Generator.java @@ -31,7 +31,7 @@ public class Generator { structurePopulator = new StructurePopulator(plugin); treePopulator = new TreePopulator(plugin); orePopulator = new OrePopulator(plugin); - generator = new DefaultChunkGenerator3D(plugin.getRegistry().get("DEFAULT"), plugin, new SamplerCache(plugin)); + generator = new DefaultChunkGenerator3D(plugin.getConfigRegistry().get("DEFAULT"), plugin, new SamplerCache(plugin)); this.seed = seed; } From a328ff2f2ab237604b336f920e9e613763fe65de Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 22 Feb 2021 16:13:53 -0700 Subject: [PATCH 13/95] refactor API --- .../loading => addon}/AddonClassLoader.java | 6 +- .../loading/pre => addon}/AddonPool.java | 4 +- .../loading/pre => addon}/PreLoadAddon.java | 14 ++-- .../exception}/AddonLoadException.java | 2 +- .../CircularDependencyException.java | 4 +- .../exception/DependencyMissingException.java | 4 +- .../terra/api/{core => }/TerraPlugin.java | 16 ++-- .../addon => api/addons}/TerraAddon.java | 8 +- .../{ => api}/addons/annotations/Addon.java | 2 +- .../{ => api}/addons/annotations/Author.java | 2 +- .../{ => api}/addons/annotations/Depends.java | 2 +- .../{ => api}/addons/annotations/Version.java | 2 +- .../terra/api/core/event/EventListener.java | 4 - .../terra/api/core/event/events/Event.java | 4 - .../dfsek/terra/api/event/EventListener.java | 4 + .../api/{core => }/event/EventManager.java | 6 +- .../{core => }/event/TerraEventManager.java | 16 ++-- .../{core => }/event/annotations/Global.java | 2 +- .../event/annotations/Priority.java | 2 +- .../{core => }/event/events/Cancellable.java | 2 +- .../dfsek/terra/api/event/events/Event.java | 4 + .../{core => }/event/events/PackEvent.java | 2 +- .../events/config/ConfigPackLoadEvent.java | 4 +- .../config/ConfigPackPostLoadEvent.java | 2 +- .../events/config/ConfigPackPreLoadEvent.java | 2 +- .../events/world/TerraWorldLoadEvent.java | 4 +- .../{addons => api}/injection/Injector.java | 4 +- .../injection/annotations}/Inject.java | 2 +- .../exception}/InjectionException.java | 2 +- .../com/dfsek/terra/api/platform/Player.java | 6 -- .../terra/api/platform/entity/Player.java | 4 + .../terra/api/platform/package-info.java | 2 + .../{ => api}/registry/CheckedRegistry.java | 3 +- .../{ => api}/registry/LockedRegistry.java | 3 +- .../terra/{ => api}/registry/Registry.java | 2 +- .../terra/api/structures/loot/Entry.java | 2 +- .../terra/api/structures/loot/LootTable.java | 2 +- .../dfsek/terra/api/structures/loot/Pool.java | 4 +- .../loot/functions/EnchantFunction.java | 2 +- .../structures/script/StructureScript.java | 2 +- .../script/builders/BiomeFunctionBuilder.java | 2 +- .../script/builders/BlockFunctionBuilder.java | 2 +- .../script/builders/CheckFunctionBuilder.java | 2 +- .../builders/EntityFunctionBuilder.java | 2 +- .../script/builders/LootFunctionBuilder.java | 2 +- .../script/builders/PullFunctionBuilder.java | 2 +- .../script/builders/StateFunctionBuilder.java | 2 +- .../builders/StructureFunctionBuilder.java | 2 +- .../script/functions/BiomeFunction.java | 2 +- .../script/functions/BlockFunction.java | 2 +- .../script/functions/CheckFunction.java | 2 +- .../script/functions/EntityFunction.java | 2 +- .../script/functions/LootFunction.java | 2 +- .../script/functions/PullFunction.java | 2 +- .../script/functions/StateFunction.java | 2 +- .../script/functions/StructureFunction.java | 2 +- .../buffer/items/BufferedLootApplication.java | 2 +- .../items/BufferedStateManipulator.java | 2 +- .../{debug => api/util}/DebugLogger.java | 2 +- .../{world => collections}/MaterialSet.java | 2 +- .../collections}/ProbabilityCollection.java | 81 ++++++++++++++++++- .../api/util/mutable/MutableBoolean.java | 7 ++ .../terra/api/util/mutable/MutableDouble.java | 7 ++ .../api/util/mutable/MutableInteger.java | 7 ++ .../api/util/mutable/MutablePrimitive.java | 2 +- .../terra/api/util/mutable/package-info.java | 4 + .../terra/api/util/seeded/SeededBuilder.java | 1 + .../terra/api/util/seeded/SourceSeeded.java | 1 + .../terra/api/util/seeded/StageSeeded.java | 1 + .../terra/api/world/biome/TerraBiome.java | 2 +- .../api/world/biome/UserDefinedBiome.java | 2 +- .../pipeline/mutator/BorderListMutator.java | 2 +- .../biome/pipeline/mutator/BorderMutator.java | 2 +- .../pipeline/mutator/ReplaceListMutator.java | 2 +- .../pipeline/mutator/ReplaceMutator.java | 2 +- .../biome/pipeline/source/RandomSource.java | 2 +- .../biome/provider/StandardBiomeProvider.java | 2 +- .../world/generation/TerraChunkGenerator.java | 2 +- .../world/locate}/AsyncBiomeFinder.java | 4 +- .../world/locate}/AsyncFeatureFinder.java | 4 +- .../world/locate}/AsyncStructureFinder.java | 4 +- .../terra/api/world/palette/Palette.java | 2 +- .../palette/holder/PaletteLayerHolder.java | 2 +- .../api/world/tree/fractal/FractalTree.java | 4 +- .../api/world/tree/fractal/TreeGeometry.java | 2 +- .../api/world/tree/fractal/trees/Cactus.java | 4 +- .../world/tree/fractal/trees/IceSpike.java | 6 +- .../api/world/tree/fractal/trees/OakTree.java | 4 +- .../tree/fractal/trees/ShatteredPillar.java | 4 +- .../tree/fractal/trees/ShatteredTree.java | 6 +- .../fractal/trees/SmallShatteredPillar.java | 4 +- .../fractal/trees/SmallShatteredTree.java | 6 +- .../world/tree/fractal/trees/SpruceTree.java | 4 +- .../com/dfsek/terra/carving/CarverCache.java | 2 +- .../dfsek/terra/carving/CarverPalette.java | 4 +- .../terra/carving/UserDefinedCarver.java | 2 +- .../dfsek/terra/config/GenericLoaders.java | 8 +- .../com/dfsek/terra/config/PluginConfig.java | 2 +- .../exception/FileMissingException.java | 15 ---- .../terra/config/factories/BiomeFactory.java | 2 +- .../terra/config/factories/CarverFactory.java | 2 +- .../terra/config/factories/FloraFactory.java | 2 +- .../terra/config/factories/OreFactory.java | 2 +- .../config/factories/PaletteFactory.java | 2 +- .../config/factories/StructureFactory.java | 2 +- .../terra/config/factories/TerraFactory.java | 2 +- .../terra/config/factories/TreeFactory.java | 2 +- .../com/dfsek/terra/config/lang/LangUtil.java | 2 +- .../config/loaders/MaterialSetLoader.java | 2 +- .../loaders/ProbabilityCollectionLoader.java | 2 +- .../com/dfsek/terra/config/loaders/Types.java | 2 +- .../loaders/config/FloraLayerLoader.java | 2 +- .../loaders/config/TreeLayerLoader.java | 2 +- .../config/biome/SourceBuilderLoader.java | 2 +- .../source/BiomePipelineTemplate.java | 2 +- .../mutator/BorderListMutatorTemplate.java | 2 +- .../stage/mutator/BorderMutatorTemplate.java | 2 +- .../mutator/ReplaceListMutatorTemplate.java | 2 +- .../stage/mutator/ReplaceMutatorTemplate.java | 2 +- .../loaders/palette/CarverPaletteLoader.java | 4 +- .../loaders/palette/PaletteLayerLoader.java | 2 +- .../dfsek/terra/config/pack/ConfigPack.java | 13 ++- .../terra/config/pack/ConfigPackTemplate.java | 2 +- .../terra/config/templates/BiomeTemplate.java | 4 +- .../config/templates/CarverTemplate.java | 2 +- .../terra/config/templates/FloraTemplate.java | 2 +- .../terra/config/templates/OreTemplate.java | 2 +- .../config/templates/StructureTemplate.java | 2 +- .../terra/config/templates/TreeTemplate.java | 4 +- .../dfsek/terra/registry/OpenRegistry.java | 2 +- .../terra/registry/config/FloraRegistry.java | 4 +- .../registry/config/PaletteRegistry.java | 2 +- .../terra/registry/config/TreeRegistry.java | 2 +- .../terra/registry/master/AddonRegistry.java | 16 ++-- .../terra/registry/master/ConfigRegistry.java | 2 +- .../com/dfsek/terra/world/TerraWorld.java | 4 +- .../terra/world/carving/NoiseCarver.java | 2 +- .../generators/DefaultChunkGenerator2D.java | 2 +- .../generators/DefaultChunkGenerator3D.java | 2 +- .../world/generation/math/SamplerCache.java | 2 +- .../terra/world/population/CavePopulator.java | 14 ++-- .../world/population/FloraPopulator.java | 2 +- .../terra/world/population/OrePopulator.java | 2 +- .../world/population/StructurePopulator.java | 2 +- .../terra/world/population/TreePopulator.java | 2 +- .../population/items/PlaceableLayer.java | 2 +- .../population/items/TerraStructure.java | 2 +- .../population/items/flora/ConstantFlora.java | 2 +- .../population/items/flora/FloraLayer.java | 2 +- .../population/items/flora/TerraFlora.java | 4 +- .../items/ores/DeformedSphereOre.java | 4 +- .../world/population/items/ores/Ore.java | 4 +- .../population/items/ores/VanillaOre.java | 4 +- .../population/items/tree/TerraTree.java | 4 +- .../population/items/tree/TreeLayer.java | 2 +- .../src/test/java/biome/DistributionTest.java | 14 ++-- common/src/test/java/biome/ImageTest.java | 2 +- .../test/java/noise/ColorConfigTemplate.java | 2 +- common/src/test/java/noise/NoiseTool.java | 2 +- .../com/dfsek/terra/bukkit/BukkitPlayer.java | 2 +- .../dfsek/terra/bukkit/TerraBukkitPlugin.java | 20 ++--- .../dfsek/terra/bukkit/command/Command.java | 2 +- .../bukkit/command/command/PacksCommand.java | 3 +- .../bukkit/command/command/TerraCommand.java | 2 +- .../command/biome/BiomeLocateCommand.java | 2 +- .../command/structure/LocateCommand.java | 2 +- .../BukkitChunkGeneratorWrapper.java | 2 +- .../bukkit/listeners/CommonListener.java | 2 +- .../terra/bukkit/listeners/PaperListener.java | 4 +- .../bukkit/listeners/SpigotListener.java | 4 +- .../terra/bukkit/listeners/TerraListener.java | 10 +-- .../bukkit/population/PopulationManager.java | 2 +- .../terra/bukkit/world/BukkitAdapter.java | 4 +- .../dfsek/terra/bukkit/world/BukkitTree.java | 4 +- .../dfsek/terra/fabric/TerraFabricPlugin.java | 14 ++-- .../dfsek/terra/fabric/world/FabricTree.java | 2 +- .../com/dfsek/terra/StandalonePlugin.java | 14 ++-- 177 files changed, 399 insertions(+), 311 deletions(-) rename common/src/main/java/com/dfsek/terra/{addons/loading => addon}/AddonClassLoader.java (93%) rename common/src/main/java/com/dfsek/terra/{addons/loading/pre => addon}/AddonPool.java (88%) rename common/src/main/java/com/dfsek/terra/{addons/loading/pre => addon}/PreLoadAddon.java (79%) rename common/src/main/java/com/dfsek/terra/{addons/loading => addon/exception}/AddonLoadException.java (88%) rename common/src/main/java/com/dfsek/terra/{addons/loading/pre => addon}/exception/CircularDependencyException.java (75%) rename common/src/main/java/com/dfsek/terra/{addons/loading/pre => addon}/exception/DependencyMissingException.java (75%) rename common/src/main/java/com/dfsek/terra/api/{core => }/TerraPlugin.java (75%) rename common/src/main/java/com/dfsek/terra/{addons/addon => api/addons}/TerraAddon.java (81%) rename common/src/main/java/com/dfsek/terra/{ => api}/addons/annotations/Addon.java (90%) rename common/src/main/java/com/dfsek/terra/{ => api}/addons/annotations/Author.java (90%) rename common/src/main/java/com/dfsek/terra/{ => api}/addons/annotations/Depends.java (90%) rename common/src/main/java/com/dfsek/terra/{ => api}/addons/annotations/Version.java (90%) delete mode 100644 common/src/main/java/com/dfsek/terra/api/core/event/EventListener.java delete mode 100644 common/src/main/java/com/dfsek/terra/api/core/event/events/Event.java create mode 100644 common/src/main/java/com/dfsek/terra/api/event/EventListener.java rename common/src/main/java/com/dfsek/terra/api/{core => }/event/EventManager.java (72%) rename common/src/main/java/com/dfsek/terra/api/{core => }/event/TerraEventManager.java (91%) rename common/src/main/java/com/dfsek/terra/api/{core => }/event/annotations/Global.java (86%) rename common/src/main/java/com/dfsek/terra/api/{core => }/event/annotations/Priority.java (94%) rename common/src/main/java/com/dfsek/terra/api/{core => }/event/events/Cancellable.java (84%) create mode 100644 common/src/main/java/com/dfsek/terra/api/event/events/Event.java rename common/src/main/java/com/dfsek/terra/api/{core => }/event/events/PackEvent.java (78%) rename common/src/main/java/com/dfsek/terra/api/{core => }/event/events/config/ConfigPackLoadEvent.java (73%) rename common/src/main/java/com/dfsek/terra/api/{core => }/event/events/config/ConfigPackPostLoadEvent.java (82%) rename common/src/main/java/com/dfsek/terra/api/{core => }/event/events/config/ConfigPackPreLoadEvent.java (86%) rename common/src/main/java/com/dfsek/terra/api/{core => }/event/events/world/TerraWorldLoadEvent.java (81%) rename common/src/main/java/com/dfsek/terra/{addons => api}/injection/Injector.java (91%) rename common/src/main/java/com/dfsek/terra/{addons/injection => api/injection/annotations}/Inject.java (86%) rename common/src/main/java/com/dfsek/terra/{addons/injection => api/injection/exception}/InjectionException.java (86%) delete mode 100644 common/src/main/java/com/dfsek/terra/api/platform/Player.java create mode 100644 common/src/main/java/com/dfsek/terra/api/platform/entity/Player.java rename common/src/main/java/com/dfsek/terra/{ => api}/registry/CheckedRegistry.java (96%) rename common/src/main/java/com/dfsek/terra/{ => api}/registry/LockedRegistry.java (93%) rename common/src/main/java/com/dfsek/terra/{ => api}/registry/Registry.java (96%) rename common/src/main/java/com/dfsek/terra/{debug => api/util}/DebugLogger.java (95%) rename common/src/main/java/com/dfsek/terra/api/util/{world => collections}/MaterialSet.java (93%) rename common/src/main/java/com/dfsek/terra/api/{math => util/collections}/ProbabilityCollection.java (54%) create mode 100644 common/src/main/java/com/dfsek/terra/api/util/mutable/package-info.java rename common/src/main/java/com/dfsek/terra/{async => api/world/locate}/AsyncBiomeFinder.java (93%) rename common/src/main/java/com/dfsek/terra/{async => api/world/locate}/AsyncFeatureFinder.java (97%) rename common/src/main/java/com/dfsek/terra/{async => api/world/locate}/AsyncStructureFinder.java (95%) delete mode 100644 common/src/main/java/com/dfsek/terra/config/exception/FileMissingException.java diff --git a/common/src/main/java/com/dfsek/terra/addons/loading/AddonClassLoader.java b/common/src/main/java/com/dfsek/terra/addon/AddonClassLoader.java similarity index 93% rename from common/src/main/java/com/dfsek/terra/addons/loading/AddonClassLoader.java rename to common/src/main/java/com/dfsek/terra/addon/AddonClassLoader.java index 58093e6cf..cb749a3ef 100644 --- a/common/src/main/java/com/dfsek/terra/addons/loading/AddonClassLoader.java +++ b/common/src/main/java/com/dfsek/terra/addon/AddonClassLoader.java @@ -1,7 +1,7 @@ -package com.dfsek.terra.addons.loading; +package com.dfsek.terra.addon; -import com.dfsek.terra.addons.addon.TerraAddon; -import com.dfsek.terra.addons.annotations.Addon; +import com.dfsek.terra.api.addons.TerraAddon; +import com.dfsek.terra.api.addons.annotations.Addon; import java.io.File; import java.io.IOException; diff --git a/common/src/main/java/com/dfsek/terra/addons/loading/pre/AddonPool.java b/common/src/main/java/com/dfsek/terra/addon/AddonPool.java similarity index 88% rename from common/src/main/java/com/dfsek/terra/addons/loading/pre/AddonPool.java rename to common/src/main/java/com/dfsek/terra/addon/AddonPool.java index 2264b49d6..1fe0844dd 100644 --- a/common/src/main/java/com/dfsek/terra/addons/loading/pre/AddonPool.java +++ b/common/src/main/java/com/dfsek/terra/addon/AddonPool.java @@ -1,6 +1,6 @@ -package com.dfsek.terra.addons.loading.pre; +package com.dfsek.terra.addon; -import com.dfsek.terra.addons.loading.AddonLoadException; +import com.dfsek.terra.addon.exception.AddonLoadException; import java.util.HashMap; import java.util.HashSet; diff --git a/common/src/main/java/com/dfsek/terra/addons/loading/pre/PreLoadAddon.java b/common/src/main/java/com/dfsek/terra/addon/PreLoadAddon.java similarity index 79% rename from common/src/main/java/com/dfsek/terra/addons/loading/pre/PreLoadAddon.java rename to common/src/main/java/com/dfsek/terra/addon/PreLoadAddon.java index 5b14b43ad..4f54ebf10 100644 --- a/common/src/main/java/com/dfsek/terra/addons/loading/pre/PreLoadAddon.java +++ b/common/src/main/java/com/dfsek/terra/addon/PreLoadAddon.java @@ -1,11 +1,11 @@ -package com.dfsek.terra.addons.loading.pre; +package com.dfsek.terra.addon; -import com.dfsek.terra.addons.addon.TerraAddon; -import com.dfsek.terra.addons.annotations.Addon; -import com.dfsek.terra.addons.annotations.Depends; -import com.dfsek.terra.addons.loading.AddonLoadException; -import com.dfsek.terra.addons.loading.pre.exception.CircularDependencyException; -import com.dfsek.terra.addons.loading.pre.exception.DependencyMissingException; +import com.dfsek.terra.addon.exception.AddonLoadException; +import com.dfsek.terra.addon.exception.CircularDependencyException; +import com.dfsek.terra.addon.exception.DependencyMissingException; +import com.dfsek.terra.api.addons.TerraAddon; +import com.dfsek.terra.api.addons.annotations.Addon; +import com.dfsek.terra.api.addons.annotations.Depends; import java.util.ArrayList; import java.util.Arrays; diff --git a/common/src/main/java/com/dfsek/terra/addons/loading/AddonLoadException.java b/common/src/main/java/com/dfsek/terra/addon/exception/AddonLoadException.java similarity index 88% rename from common/src/main/java/com/dfsek/terra/addons/loading/AddonLoadException.java rename to common/src/main/java/com/dfsek/terra/addon/exception/AddonLoadException.java index 867987ec2..e0ff046d5 100644 --- a/common/src/main/java/com/dfsek/terra/addons/loading/AddonLoadException.java +++ b/common/src/main/java/com/dfsek/terra/addon/exception/AddonLoadException.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.addons.loading; +package com.dfsek.terra.addon.exception; public class AddonLoadException extends Exception { private static final long serialVersionUID = -4949084729296580176L; diff --git a/common/src/main/java/com/dfsek/terra/addons/loading/pre/exception/CircularDependencyException.java b/common/src/main/java/com/dfsek/terra/addon/exception/CircularDependencyException.java similarity index 75% rename from common/src/main/java/com/dfsek/terra/addons/loading/pre/exception/CircularDependencyException.java rename to common/src/main/java/com/dfsek/terra/addon/exception/CircularDependencyException.java index 221e66520..88513f6b1 100644 --- a/common/src/main/java/com/dfsek/terra/addons/loading/pre/exception/CircularDependencyException.java +++ b/common/src/main/java/com/dfsek/terra/addon/exception/CircularDependencyException.java @@ -1,6 +1,4 @@ -package com.dfsek.terra.addons.loading.pre.exception; - -import com.dfsek.terra.addons.loading.AddonLoadException; +package com.dfsek.terra.addon.exception; public class CircularDependencyException extends AddonLoadException { private static final long serialVersionUID = 7398510879124125121L; diff --git a/common/src/main/java/com/dfsek/terra/addons/loading/pre/exception/DependencyMissingException.java b/common/src/main/java/com/dfsek/terra/addon/exception/DependencyMissingException.java similarity index 75% rename from common/src/main/java/com/dfsek/terra/addons/loading/pre/exception/DependencyMissingException.java rename to common/src/main/java/com/dfsek/terra/addon/exception/DependencyMissingException.java index b6a81d837..fec11d10f 100644 --- a/common/src/main/java/com/dfsek/terra/addons/loading/pre/exception/DependencyMissingException.java +++ b/common/src/main/java/com/dfsek/terra/addon/exception/DependencyMissingException.java @@ -1,6 +1,4 @@ -package com.dfsek.terra.addons.loading.pre.exception; - -import com.dfsek.terra.addons.loading.AddonLoadException; +package com.dfsek.terra.addon.exception; public class DependencyMissingException extends AddonLoadException { private static final long serialVersionUID = -8419489102208521583L; diff --git a/common/src/main/java/com/dfsek/terra/api/core/TerraPlugin.java b/common/src/main/java/com/dfsek/terra/api/TerraPlugin.java similarity index 75% rename from common/src/main/java/com/dfsek/terra/api/core/TerraPlugin.java rename to common/src/main/java/com/dfsek/terra/api/TerraPlugin.java index e5dea5f9a..707038f3f 100644 --- a/common/src/main/java/com/dfsek/terra/api/core/TerraPlugin.java +++ b/common/src/main/java/com/dfsek/terra/api/TerraPlugin.java @@ -1,22 +1,24 @@ -package com.dfsek.terra.api.core; +package com.dfsek.terra.api; -import com.dfsek.terra.addons.addon.TerraAddon; -import com.dfsek.terra.api.LoaderRegistrar; -import com.dfsek.terra.api.core.event.EventManager; +import com.dfsek.terra.api.addons.TerraAddon; +import com.dfsek.terra.api.event.EventManager; import com.dfsek.terra.api.platform.handle.ItemHandle; import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.api.platform.world.World; +import com.dfsek.terra.api.registry.CheckedRegistry; +import com.dfsek.terra.api.registry.LockedRegistry; +import com.dfsek.terra.api.util.DebugLogger; import com.dfsek.terra.config.PluginConfig; import com.dfsek.terra.config.lang.Language; import com.dfsek.terra.config.pack.ConfigPack; -import com.dfsek.terra.debug.DebugLogger; -import com.dfsek.terra.registry.CheckedRegistry; -import com.dfsek.terra.registry.LockedRegistry; import com.dfsek.terra.world.TerraWorld; import java.io.File; import java.util.logging.Logger; +/** + * Represents a Terra mod/plugin instance. + */ public interface TerraPlugin extends LoaderRegistrar { WorldHandle getWorldHandle(); diff --git a/common/src/main/java/com/dfsek/terra/addons/addon/TerraAddon.java b/common/src/main/java/com/dfsek/terra/api/addons/TerraAddon.java similarity index 81% rename from common/src/main/java/com/dfsek/terra/addons/addon/TerraAddon.java rename to common/src/main/java/com/dfsek/terra/api/addons/TerraAddon.java index 15a503b77..6fd5e6f82 100644 --- a/common/src/main/java/com/dfsek/terra/addons/addon/TerraAddon.java +++ b/common/src/main/java/com/dfsek/terra/api/addons/TerraAddon.java @@ -1,9 +1,9 @@ -package com.dfsek.terra.addons.addon; +package com.dfsek.terra.api.addons; -import com.dfsek.terra.addons.annotations.Addon; -import com.dfsek.terra.addons.annotations.Author; -import com.dfsek.terra.addons.annotations.Version; +import com.dfsek.terra.api.addons.annotations.Addon; +import com.dfsek.terra.api.addons.annotations.Author; +import com.dfsek.terra.api.addons.annotations.Version; import org.jetbrains.annotations.NotNull; public abstract class TerraAddon { diff --git a/common/src/main/java/com/dfsek/terra/addons/annotations/Addon.java b/common/src/main/java/com/dfsek/terra/api/addons/annotations/Addon.java similarity index 90% rename from common/src/main/java/com/dfsek/terra/addons/annotations/Addon.java rename to common/src/main/java/com/dfsek/terra/api/addons/annotations/Addon.java index fc3fd8f23..cf36cf6cf 100644 --- a/common/src/main/java/com/dfsek/terra/addons/annotations/Addon.java +++ b/common/src/main/java/com/dfsek/terra/api/addons/annotations/Addon.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.addons.annotations; +package com.dfsek.terra.api.addons.annotations; import org.jetbrains.annotations.NotNull; diff --git a/common/src/main/java/com/dfsek/terra/addons/annotations/Author.java b/common/src/main/java/com/dfsek/terra/api/addons/annotations/Author.java similarity index 90% rename from common/src/main/java/com/dfsek/terra/addons/annotations/Author.java rename to common/src/main/java/com/dfsek/terra/api/addons/annotations/Author.java index 5df87c2e8..7a7c70873 100644 --- a/common/src/main/java/com/dfsek/terra/addons/annotations/Author.java +++ b/common/src/main/java/com/dfsek/terra/api/addons/annotations/Author.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.addons.annotations; +package com.dfsek.terra.api.addons.annotations; import org.jetbrains.annotations.NotNull; diff --git a/common/src/main/java/com/dfsek/terra/addons/annotations/Depends.java b/common/src/main/java/com/dfsek/terra/api/addons/annotations/Depends.java similarity index 90% rename from common/src/main/java/com/dfsek/terra/addons/annotations/Depends.java rename to common/src/main/java/com/dfsek/terra/api/addons/annotations/Depends.java index cf0b05b5a..8634335be 100644 --- a/common/src/main/java/com/dfsek/terra/addons/annotations/Depends.java +++ b/common/src/main/java/com/dfsek/terra/api/addons/annotations/Depends.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.addons.annotations; +package com.dfsek.terra.api.addons.annotations; import org.jetbrains.annotations.NotNull; diff --git a/common/src/main/java/com/dfsek/terra/addons/annotations/Version.java b/common/src/main/java/com/dfsek/terra/api/addons/annotations/Version.java similarity index 90% rename from common/src/main/java/com/dfsek/terra/addons/annotations/Version.java rename to common/src/main/java/com/dfsek/terra/api/addons/annotations/Version.java index 48f5f44c2..a2f8c2743 100644 --- a/common/src/main/java/com/dfsek/terra/addons/annotations/Version.java +++ b/common/src/main/java/com/dfsek/terra/api/addons/annotations/Version.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.addons.annotations; +package com.dfsek.terra.api.addons.annotations; import org.jetbrains.annotations.NotNull; diff --git a/common/src/main/java/com/dfsek/terra/api/core/event/EventListener.java b/common/src/main/java/com/dfsek/terra/api/core/event/EventListener.java deleted file mode 100644 index 276097e7d..000000000 --- a/common/src/main/java/com/dfsek/terra/api/core/event/EventListener.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.dfsek.terra.api.core.event; - -public interface EventListener { -} diff --git a/common/src/main/java/com/dfsek/terra/api/core/event/events/Event.java b/common/src/main/java/com/dfsek/terra/api/core/event/events/Event.java deleted file mode 100644 index 62a6e07f2..000000000 --- a/common/src/main/java/com/dfsek/terra/api/core/event/events/Event.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.dfsek.terra.api.core.event.events; - -public interface Event { -} diff --git a/common/src/main/java/com/dfsek/terra/api/event/EventListener.java b/common/src/main/java/com/dfsek/terra/api/event/EventListener.java new file mode 100644 index 000000000..f5d3dcf60 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/event/EventListener.java @@ -0,0 +1,4 @@ +package com.dfsek.terra.api.event; + +public interface EventListener { +} diff --git a/common/src/main/java/com/dfsek/terra/api/core/event/EventManager.java b/common/src/main/java/com/dfsek/terra/api/event/EventManager.java similarity index 72% rename from common/src/main/java/com/dfsek/terra/api/core/event/EventManager.java rename to common/src/main/java/com/dfsek/terra/api/event/EventManager.java index f61f27d06..96378ede4 100644 --- a/common/src/main/java/com/dfsek/terra/api/core/event/EventManager.java +++ b/common/src/main/java/com/dfsek/terra/api/event/EventManager.java @@ -1,7 +1,7 @@ -package com.dfsek.terra.api.core.event; +package com.dfsek.terra.api.event; -import com.dfsek.terra.addons.addon.TerraAddon; -import com.dfsek.terra.api.core.event.events.Event; +import com.dfsek.terra.api.addons.TerraAddon; +import com.dfsek.terra.api.event.events.Event; public interface EventManager { /** diff --git a/common/src/main/java/com/dfsek/terra/api/core/event/TerraEventManager.java b/common/src/main/java/com/dfsek/terra/api/event/TerraEventManager.java similarity index 91% rename from common/src/main/java/com/dfsek/terra/api/core/event/TerraEventManager.java rename to common/src/main/java/com/dfsek/terra/api/event/TerraEventManager.java index 1bc3e6aa7..c25b5c1ee 100644 --- a/common/src/main/java/com/dfsek/terra/api/core/event/TerraEventManager.java +++ b/common/src/main/java/com/dfsek/terra/api/event/TerraEventManager.java @@ -1,12 +1,12 @@ -package com.dfsek.terra.api.core.event; +package com.dfsek.terra.api.event; -import com.dfsek.terra.addons.addon.TerraAddon; -import com.dfsek.terra.api.core.TerraPlugin; -import com.dfsek.terra.api.core.event.annotations.Global; -import com.dfsek.terra.api.core.event.annotations.Priority; -import com.dfsek.terra.api.core.event.events.Cancellable; -import com.dfsek.terra.api.core.event.events.Event; -import com.dfsek.terra.api.core.event.events.PackEvent; +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.addons.TerraAddon; +import com.dfsek.terra.api.event.annotations.Global; +import com.dfsek.terra.api.event.annotations.Priority; +import com.dfsek.terra.api.event.events.Cancellable; +import com.dfsek.terra.api.event.events.Event; +import com.dfsek.terra.api.event.events.PackEvent; import com.dfsek.terra.api.util.ReflectionUtil; import java.io.PrintWriter; diff --git a/common/src/main/java/com/dfsek/terra/api/core/event/annotations/Global.java b/common/src/main/java/com/dfsek/terra/api/event/annotations/Global.java similarity index 86% rename from common/src/main/java/com/dfsek/terra/api/core/event/annotations/Global.java rename to common/src/main/java/com/dfsek/terra/api/event/annotations/Global.java index 345033e46..5084f527a 100644 --- a/common/src/main/java/com/dfsek/terra/api/core/event/annotations/Global.java +++ b/common/src/main/java/com/dfsek/terra/api/event/annotations/Global.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.api.core.event.annotations; +package com.dfsek.terra.api.event.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/common/src/main/java/com/dfsek/terra/api/core/event/annotations/Priority.java b/common/src/main/java/com/dfsek/terra/api/event/annotations/Priority.java similarity index 94% rename from common/src/main/java/com/dfsek/terra/api/core/event/annotations/Priority.java rename to common/src/main/java/com/dfsek/terra/api/event/annotations/Priority.java index 0bcce141a..2d5b7c11f 100644 --- a/common/src/main/java/com/dfsek/terra/api/core/event/annotations/Priority.java +++ b/common/src/main/java/com/dfsek/terra/api/event/annotations/Priority.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.api.core.event.annotations; +package com.dfsek.terra.api.event.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/common/src/main/java/com/dfsek/terra/api/core/event/events/Cancellable.java b/common/src/main/java/com/dfsek/terra/api/event/events/Cancellable.java similarity index 84% rename from common/src/main/java/com/dfsek/terra/api/core/event/events/Cancellable.java rename to common/src/main/java/com/dfsek/terra/api/event/events/Cancellable.java index 0d8a548c0..bfac9adb2 100644 --- a/common/src/main/java/com/dfsek/terra/api/core/event/events/Cancellable.java +++ b/common/src/main/java/com/dfsek/terra/api/event/events/Cancellable.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.api.core.event.events; +package com.dfsek.terra.api.event.events; /** * Events that implement this interface may be cancelled. diff --git a/common/src/main/java/com/dfsek/terra/api/event/events/Event.java b/common/src/main/java/com/dfsek/terra/api/event/events/Event.java new file mode 100644 index 000000000..2a65f4116 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/event/events/Event.java @@ -0,0 +1,4 @@ +package com.dfsek.terra.api.event.events; + +public interface Event { +} diff --git a/common/src/main/java/com/dfsek/terra/api/core/event/events/PackEvent.java b/common/src/main/java/com/dfsek/terra/api/event/events/PackEvent.java similarity index 78% rename from common/src/main/java/com/dfsek/terra/api/core/event/events/PackEvent.java rename to common/src/main/java/com/dfsek/terra/api/event/events/PackEvent.java index ede861206..adddf8b19 100644 --- a/common/src/main/java/com/dfsek/terra/api/core/event/events/PackEvent.java +++ b/common/src/main/java/com/dfsek/terra/api/event/events/PackEvent.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.api.core.event.events; +package com.dfsek.terra.api.event.events; import com.dfsek.terra.config.pack.ConfigPack; diff --git a/common/src/main/java/com/dfsek/terra/api/core/event/events/config/ConfigPackLoadEvent.java b/common/src/main/java/com/dfsek/terra/api/event/events/config/ConfigPackLoadEvent.java similarity index 73% rename from common/src/main/java/com/dfsek/terra/api/core/event/events/config/ConfigPackLoadEvent.java rename to common/src/main/java/com/dfsek/terra/api/event/events/config/ConfigPackLoadEvent.java index b1a301ed3..a6a4c5c12 100644 --- a/common/src/main/java/com/dfsek/terra/api/core/event/events/config/ConfigPackLoadEvent.java +++ b/common/src/main/java/com/dfsek/terra/api/event/events/config/ConfigPackLoadEvent.java @@ -1,6 +1,6 @@ -package com.dfsek.terra.api.core.event.events.config; +package com.dfsek.terra.api.event.events.config; -import com.dfsek.terra.api.core.event.events.PackEvent; +import com.dfsek.terra.api.event.events.PackEvent; import com.dfsek.terra.config.pack.ConfigPack; public abstract class ConfigPackLoadEvent implements PackEvent { diff --git a/common/src/main/java/com/dfsek/terra/api/core/event/events/config/ConfigPackPostLoadEvent.java b/common/src/main/java/com/dfsek/terra/api/event/events/config/ConfigPackPostLoadEvent.java similarity index 82% rename from common/src/main/java/com/dfsek/terra/api/core/event/events/config/ConfigPackPostLoadEvent.java rename to common/src/main/java/com/dfsek/terra/api/event/events/config/ConfigPackPostLoadEvent.java index 838f0e22a..138de647c 100644 --- a/common/src/main/java/com/dfsek/terra/api/core/event/events/config/ConfigPackPostLoadEvent.java +++ b/common/src/main/java/com/dfsek/terra/api/event/events/config/ConfigPackPostLoadEvent.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.api.core.event.events.config; +package com.dfsek.terra.api.event.events.config; import com.dfsek.terra.config.pack.ConfigPack; diff --git a/common/src/main/java/com/dfsek/terra/api/core/event/events/config/ConfigPackPreLoadEvent.java b/common/src/main/java/com/dfsek/terra/api/event/events/config/ConfigPackPreLoadEvent.java similarity index 86% rename from common/src/main/java/com/dfsek/terra/api/core/event/events/config/ConfigPackPreLoadEvent.java rename to common/src/main/java/com/dfsek/terra/api/event/events/config/ConfigPackPreLoadEvent.java index e2d72d17d..317603c9e 100644 --- a/common/src/main/java/com/dfsek/terra/api/core/event/events/config/ConfigPackPreLoadEvent.java +++ b/common/src/main/java/com/dfsek/terra/api/event/events/config/ConfigPackPreLoadEvent.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.api.core.event.events.config; +package com.dfsek.terra.api.event.events.config; import com.dfsek.terra.config.pack.ConfigPack; diff --git a/common/src/main/java/com/dfsek/terra/api/core/event/events/world/TerraWorldLoadEvent.java b/common/src/main/java/com/dfsek/terra/api/event/events/world/TerraWorldLoadEvent.java similarity index 81% rename from common/src/main/java/com/dfsek/terra/api/core/event/events/world/TerraWorldLoadEvent.java rename to common/src/main/java/com/dfsek/terra/api/event/events/world/TerraWorldLoadEvent.java index ec8501316..483f2deef 100644 --- a/common/src/main/java/com/dfsek/terra/api/core/event/events/world/TerraWorldLoadEvent.java +++ b/common/src/main/java/com/dfsek/terra/api/event/events/world/TerraWorldLoadEvent.java @@ -1,6 +1,6 @@ -package com.dfsek.terra.api.core.event.events.world; +package com.dfsek.terra.api.event.events.world; -import com.dfsek.terra.api.core.event.events.PackEvent; +import com.dfsek.terra.api.event.events.PackEvent; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.world.TerraWorld; diff --git a/common/src/main/java/com/dfsek/terra/addons/injection/Injector.java b/common/src/main/java/com/dfsek/terra/api/injection/Injector.java similarity index 91% rename from common/src/main/java/com/dfsek/terra/addons/injection/Injector.java rename to common/src/main/java/com/dfsek/terra/api/injection/Injector.java index 0ba685a4f..d3df1d554 100644 --- a/common/src/main/java/com/dfsek/terra/addons/injection/Injector.java +++ b/common/src/main/java/com/dfsek/terra/api/injection/Injector.java @@ -1,5 +1,7 @@ -package com.dfsek.terra.addons.injection; +package com.dfsek.terra.api.injection; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.injection.exception.InjectionException; import com.dfsek.terra.api.util.ReflectionUtil; import java.lang.reflect.Field; diff --git a/common/src/main/java/com/dfsek/terra/addons/injection/Inject.java b/common/src/main/java/com/dfsek/terra/api/injection/annotations/Inject.java similarity index 86% rename from common/src/main/java/com/dfsek/terra/addons/injection/Inject.java rename to common/src/main/java/com/dfsek/terra/api/injection/annotations/Inject.java index 2094b14cc..b73f05d42 100644 --- a/common/src/main/java/com/dfsek/terra/addons/injection/Inject.java +++ b/common/src/main/java/com/dfsek/terra/api/injection/annotations/Inject.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.addons.injection; +package com.dfsek.terra.api.injection.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/common/src/main/java/com/dfsek/terra/addons/injection/InjectionException.java b/common/src/main/java/com/dfsek/terra/api/injection/exception/InjectionException.java similarity index 86% rename from common/src/main/java/com/dfsek/terra/addons/injection/InjectionException.java rename to common/src/main/java/com/dfsek/terra/api/injection/exception/InjectionException.java index 26d3e5be4..93e0d258c 100644 --- a/common/src/main/java/com/dfsek/terra/addons/injection/InjectionException.java +++ b/common/src/main/java/com/dfsek/terra/api/injection/exception/InjectionException.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.addons.injection; +package com.dfsek.terra.api.injection.exception; public class InjectionException extends Exception { private static final long serialVersionUID = -6929631447064215387L; diff --git a/common/src/main/java/com/dfsek/terra/api/platform/Player.java b/common/src/main/java/com/dfsek/terra/api/platform/Player.java deleted file mode 100644 index 136727749..000000000 --- a/common/src/main/java/com/dfsek/terra/api/platform/Player.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.dfsek.terra.api.platform; - -import com.dfsek.terra.api.platform.entity.Entity; - -public interface Player extends Entity { -} diff --git a/common/src/main/java/com/dfsek/terra/api/platform/entity/Player.java b/common/src/main/java/com/dfsek/terra/api/platform/entity/Player.java new file mode 100644 index 000000000..43a002089 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/platform/entity/Player.java @@ -0,0 +1,4 @@ +package com.dfsek.terra.api.platform.entity; + +public interface Player extends Entity { +} diff --git a/common/src/main/java/com/dfsek/terra/api/platform/package-info.java b/common/src/main/java/com/dfsek/terra/api/platform/package-info.java index f1b97f5ed..44377a381 100644 --- a/common/src/main/java/com/dfsek/terra/api/platform/package-info.java +++ b/common/src/main/java/com/dfsek/terra/api/platform/package-info.java @@ -1,4 +1,6 @@ /** * API for platform implementations. Mostly interfaces to be implemented by platform delegates. + *

+ * Interfaces in this package generally should not be implemented by addons. */ package com.dfsek.terra.api.platform; diff --git a/common/src/main/java/com/dfsek/terra/registry/CheckedRegistry.java b/common/src/main/java/com/dfsek/terra/api/registry/CheckedRegistry.java similarity index 96% rename from common/src/main/java/com/dfsek/terra/registry/CheckedRegistry.java rename to common/src/main/java/com/dfsek/terra/api/registry/CheckedRegistry.java index 5d8963f19..d7900cee7 100644 --- a/common/src/main/java/com/dfsek/terra/registry/CheckedRegistry.java +++ b/common/src/main/java/com/dfsek/terra/api/registry/CheckedRegistry.java @@ -1,7 +1,8 @@ -package com.dfsek.terra.registry; +package com.dfsek.terra.api.registry; import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; +import com.dfsek.terra.registry.OpenRegistry; import com.dfsek.terra.registry.exception.DuplicateEntryException; import java.lang.reflect.Type; diff --git a/common/src/main/java/com/dfsek/terra/registry/LockedRegistry.java b/common/src/main/java/com/dfsek/terra/api/registry/LockedRegistry.java similarity index 93% rename from common/src/main/java/com/dfsek/terra/registry/LockedRegistry.java rename to common/src/main/java/com/dfsek/terra/api/registry/LockedRegistry.java index 709088366..e53e21e08 100644 --- a/common/src/main/java/com/dfsek/terra/registry/LockedRegistry.java +++ b/common/src/main/java/com/dfsek/terra/api/registry/LockedRegistry.java @@ -1,7 +1,8 @@ -package com.dfsek.terra.registry; +package com.dfsek.terra.api.registry; import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; +import com.dfsek.terra.registry.OpenRegistry; import java.lang.reflect.Type; import java.util.Set; diff --git a/common/src/main/java/com/dfsek/terra/registry/Registry.java b/common/src/main/java/com/dfsek/terra/api/registry/Registry.java similarity index 96% rename from common/src/main/java/com/dfsek/terra/registry/Registry.java rename to common/src/main/java/com/dfsek/terra/api/registry/Registry.java index 5289cb39a..41f10379b 100644 --- a/common/src/main/java/com/dfsek/terra/registry/Registry.java +++ b/common/src/main/java/com/dfsek/terra/api/registry/Registry.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.registry; +package com.dfsek.terra.api.registry; import com.dfsek.tectonic.loading.TypeLoader; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/loot/Entry.java b/common/src/main/java/com/dfsek/terra/api/structures/loot/Entry.java index 4da109325..4eb506c1d 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/loot/Entry.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/loot/Entry.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.structures.loot; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.platform.inventory.ItemStack; import com.dfsek.terra.api.structures.loot.functions.AmountFunction; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/loot/LootTable.java b/common/src/main/java/com/dfsek/terra/api/structures/loot/LootTable.java index cdbc80296..f5da89b65 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/loot/LootTable.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/loot/LootTable.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.structures.loot; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.platform.inventory.Inventory; import com.dfsek.terra.api.platform.inventory.ItemStack; import com.dfsek.terra.api.util.GlueList; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/loot/Pool.java b/common/src/main/java/com/dfsek/terra/api/structures/loot/Pool.java index 418d86332..e01a25bdb 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/loot/Pool.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/loot/Pool.java @@ -1,9 +1,9 @@ package com.dfsek.terra.api.structures.loot; -import com.dfsek.terra.api.core.TerraPlugin; -import com.dfsek.terra.api.math.ProbabilityCollection; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.platform.inventory.ItemStack; import com.dfsek.terra.api.util.GlueList; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import net.jafama.FastMath; import org.json.simple.JSONArray; import org.json.simple.JSONObject; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/loot/functions/EnchantFunction.java b/common/src/main/java/com/dfsek/terra/api/structures/loot/functions/EnchantFunction.java index badfe6979..555f0cf21 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/loot/functions/EnchantFunction.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/loot/functions/EnchantFunction.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.structures.loot.functions; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.platform.inventory.ItemStack; import com.dfsek.terra.api.platform.inventory.item.Enchantment; import com.dfsek.terra.api.platform.inventory.item.ItemMeta; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java b/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java index 219d8092d..c3d8a70fc 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.structures.script; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.structures.parser.Parser; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/builders/BiomeFunctionBuilder.java b/common/src/main/java/com/dfsek/terra/api/structures/script/builders/BiomeFunctionBuilder.java index 58c71b589..7c15c70b4 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/builders/BiomeFunctionBuilder.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/builders/BiomeFunctionBuilder.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.structures.script.builders; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.structures.parser.lang.Returnable; import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder; import com.dfsek.terra.api.structures.script.functions.BiomeFunction; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/builders/BlockFunctionBuilder.java b/common/src/main/java/com/dfsek/terra/api/structures/script/builders/BlockFunctionBuilder.java index ac0052165..41c4a0dfe 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/builders/BlockFunctionBuilder.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/builders/BlockFunctionBuilder.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.structures.script.builders; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.structures.parser.exceptions.ParseException; import com.dfsek.terra.api.structures.parser.lang.Returnable; import com.dfsek.terra.api.structures.parser.lang.constants.BooleanConstant; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/builders/CheckFunctionBuilder.java b/common/src/main/java/com/dfsek/terra/api/structures/script/builders/CheckFunctionBuilder.java index af024d8c2..c4e26486a 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/builders/CheckFunctionBuilder.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/builders/CheckFunctionBuilder.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.structures.script.builders; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.structures.parser.exceptions.ParseException; import com.dfsek.terra.api.structures.parser.lang.Returnable; import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/builders/EntityFunctionBuilder.java b/common/src/main/java/com/dfsek/terra/api/structures/script/builders/EntityFunctionBuilder.java index 6582d617e..dd66a3d84 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/builders/EntityFunctionBuilder.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/builders/EntityFunctionBuilder.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.structures.script.builders; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.structures.parser.exceptions.ParseException; import com.dfsek.terra.api.structures.parser.lang.Returnable; import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/builders/LootFunctionBuilder.java b/common/src/main/java/com/dfsek/terra/api/structures/script/builders/LootFunctionBuilder.java index b2a39c92a..fe4634848 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/builders/LootFunctionBuilder.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/builders/LootFunctionBuilder.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.structures.script.builders; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.structures.parser.lang.Returnable; import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder; import com.dfsek.terra.api.structures.script.functions.LootFunction; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/builders/PullFunctionBuilder.java b/common/src/main/java/com/dfsek/terra/api/structures/script/builders/PullFunctionBuilder.java index 54eb8fc27..9b55da244 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/builders/PullFunctionBuilder.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/builders/PullFunctionBuilder.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.structures.script.builders; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.structures.parser.exceptions.ParseException; import com.dfsek.terra.api.structures.parser.lang.Returnable; import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/builders/StateFunctionBuilder.java b/common/src/main/java/com/dfsek/terra/api/structures/script/builders/StateFunctionBuilder.java index cbd37db8f..56c9ab2e3 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/builders/StateFunctionBuilder.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/builders/StateFunctionBuilder.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.structures.script.builders; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.structures.parser.exceptions.ParseException; import com.dfsek.terra.api.structures.parser.lang.Returnable; import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/builders/StructureFunctionBuilder.java b/common/src/main/java/com/dfsek/terra/api/structures/script/builders/StructureFunctionBuilder.java index 311cb4d1b..2b0be8468 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/builders/StructureFunctionBuilder.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/builders/StructureFunctionBuilder.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.structures.script.builders; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.structures.parser.exceptions.ParseException; import com.dfsek.terra.api.structures.parser.lang.Returnable; import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/BiomeFunction.java b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/BiomeFunction.java index 8e8640e98..54eb7e280 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/BiomeFunction.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/BiomeFunction.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.structures.script.functions; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Vector2; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.structures.parser.lang.ImplementationArguments; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/BlockFunction.java b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/BlockFunction.java index 27e10da56..0373fe5fe 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/BlockFunction.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/BlockFunction.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.structures.script.functions; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Vector2; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockData; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/CheckFunction.java b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/CheckFunction.java index bc01fcd23..7e1a1b6c8 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/CheckFunction.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/CheckFunction.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.structures.script.functions; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.math.vector.Vector2; import com.dfsek.terra.api.math.vector.Vector3; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/EntityFunction.java b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/EntityFunction.java index 96ca732ce..547ae7a00 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/EntityFunction.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/EntityFunction.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.structures.script.functions; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Vector2; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.entity.EntityType; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/LootFunction.java b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/LootFunction.java index 5218f86a7..09f1af284 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/LootFunction.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/LootFunction.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.structures.script.functions; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Vector2; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.structures.loot.LootTable; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/PullFunction.java b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/PullFunction.java index de1d56053..059aca0fa 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/PullFunction.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/PullFunction.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.structures.script.functions; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Vector2; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockData; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/StateFunction.java b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/StateFunction.java index 812ca86bb..4e2e2c276 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/StateFunction.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/StateFunction.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.structures.script.functions; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Vector2; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.structures.parser.lang.ImplementationArguments; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/StructureFunction.java b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/StructureFunction.java index cd61d0ae0..6fdefff68 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/StructureFunction.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/StructureFunction.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.structures.script.functions; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Vector2; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.structures.parser.lang.ImplementationArguments; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedLootApplication.java b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedLootApplication.java index 7b0c04234..482b242fd 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedLootApplication.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedLootApplication.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.structures.structure.buffer.items; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.state.BlockState; import com.dfsek.terra.api.platform.block.state.Container; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedStateManipulator.java b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedStateManipulator.java index 6e11ea384..3edf9873d 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedStateManipulator.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedStateManipulator.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.structures.structure.buffer.items; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.state.BlockState; diff --git a/common/src/main/java/com/dfsek/terra/debug/DebugLogger.java b/common/src/main/java/com/dfsek/terra/api/util/DebugLogger.java similarity index 95% rename from common/src/main/java/com/dfsek/terra/debug/DebugLogger.java rename to common/src/main/java/com/dfsek/terra/api/util/DebugLogger.java index c907fab9f..35604d620 100644 --- a/common/src/main/java/com/dfsek/terra/debug/DebugLogger.java +++ b/common/src/main/java/com/dfsek/terra/api/util/DebugLogger.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.debug; +package com.dfsek.terra.api.util; import java.util.logging.Logger; diff --git a/common/src/main/java/com/dfsek/terra/api/util/world/MaterialSet.java b/common/src/main/java/com/dfsek/terra/api/util/collections/MaterialSet.java similarity index 93% rename from common/src/main/java/com/dfsek/terra/api/util/world/MaterialSet.java rename to common/src/main/java/com/dfsek/terra/api/util/collections/MaterialSet.java index 0e43ea827..44b9b16f6 100644 --- a/common/src/main/java/com/dfsek/terra/api/util/world/MaterialSet.java +++ b/common/src/main/java/com/dfsek/terra/api/util/collections/MaterialSet.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.api.util.world; +package com.dfsek.terra.api.util.collections; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.MaterialData; diff --git a/common/src/main/java/com/dfsek/terra/api/math/ProbabilityCollection.java b/common/src/main/java/com/dfsek/terra/api/util/collections/ProbabilityCollection.java similarity index 54% rename from common/src/main/java/com/dfsek/terra/api/math/ProbabilityCollection.java rename to common/src/main/java/com/dfsek/terra/api/util/collections/ProbabilityCollection.java index 6d785e1d7..ecdd520b4 100644 --- a/common/src/main/java/com/dfsek/terra/api/math/ProbabilityCollection.java +++ b/common/src/main/java/com/dfsek/terra/api/util/collections/ProbabilityCollection.java @@ -1,19 +1,23 @@ -package com.dfsek.terra.api.math; +package com.dfsek.terra.api.util.collections; +import com.dfsek.terra.api.math.MathUtil; import com.dfsek.terra.api.math.noise.NoiseSampler; +import org.jetbrains.annotations.NotNull; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; +import java.util.Iterator; import java.util.Random; import java.util.Set; @SuppressWarnings("unchecked") -public class ProbabilityCollection { +public class ProbabilityCollection implements Collection { private final Set cont = new HashSet<>(); private Object[] array = new Object[0]; private int size; - public com.dfsek.terra.api.math.ProbabilityCollection add(E item, int probability) { + public ProbabilityCollection add(E item, int probability) { if(!cont.contains(item)) size++; cont.add(item); int oldLength = array.length; @@ -43,10 +47,81 @@ public class ProbabilityCollection { return array.length; } + @Override public int size() { return size; } + @Override + public boolean isEmpty() { + return array.length == 0; + } + + @Override + public boolean contains(Object o) { + return cont.contains(o); + } + + @NotNull + @Override + public Iterator iterator() { + return cont.iterator(); + } + + @NotNull + @Override + public Object[] toArray() { + return cont.toArray(); + } + + @SuppressWarnings("SuspiciousToArrayCall") + @NotNull + @Override + public T[] toArray(@NotNull T[] a) { + return cont.toArray(a); + } + + /** + * Adds an item with probability of 1. + */ + @Override + public boolean add(E e) { + add(e, 1); + return true; // Since this adds the item with a probability, the collection will always have changed. + } + + @Override + public boolean remove(Object o) { + throw new UnsupportedOperationException("Cannot remove item from ProbabilityCollection!"); + } + + @Override + public boolean containsAll(@NotNull Collection c) { + return cont.containsAll(c); + } + + @Override + public boolean addAll(@NotNull Collection c) { + c.forEach(this::add); + return true; + } + + @Override + public boolean removeAll(@NotNull Collection c) { + throw new UnsupportedOperationException("Cannot remove item from ProbabilityCollection!"); + } + + @Override + public boolean retainAll(@NotNull Collection c) { + throw new UnsupportedOperationException("Cannot remove item from ProbabilityCollection!"); + } + + @Override + public void clear() { + cont.clear(); + array = new Object[0]; + } + public Set getContents() { return new HashSet<>(cont); } diff --git a/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableBoolean.java b/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableBoolean.java index 146bc606a..50abd8feb 100644 --- a/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableBoolean.java +++ b/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableBoolean.java @@ -1,5 +1,7 @@ package com.dfsek.terra.api.util.mutable; +import org.jetbrains.annotations.NotNull; + public class MutableBoolean implements MutablePrimitive { private boolean value; @@ -17,4 +19,9 @@ public class MutableBoolean implements MutablePrimitive { value = !value; return value; } + + @Override + public int compareTo(@NotNull Boolean o) { + return Boolean.compare(value, o); + } } diff --git a/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableDouble.java b/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableDouble.java index 483fa3d3e..be86110b3 100644 --- a/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableDouble.java +++ b/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableDouble.java @@ -1,5 +1,7 @@ package com.dfsek.terra.api.util.mutable; +import org.jetbrains.annotations.NotNull; + public class MutableDouble extends MutableNumber { private static final long serialVersionUID = -2218110876763640053L; @@ -36,4 +38,9 @@ public class MutableDouble extends MutableNumber { public void divide(Double divide) { value /= divide; } + + @Override + public int compareTo(@NotNull Double o) { + return Double.compare(value, o); + } } diff --git a/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableInteger.java b/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableInteger.java index 0774680d5..a2d949d87 100644 --- a/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableInteger.java +++ b/common/src/main/java/com/dfsek/terra/api/util/mutable/MutableInteger.java @@ -1,5 +1,7 @@ package com.dfsek.terra.api.util.mutable; +import org.jetbrains.annotations.NotNull; + public class MutableInteger extends MutableNumber { private static final long serialVersionUID = -4427935901819632745L; @@ -38,4 +40,9 @@ public class MutableInteger extends MutableNumber { public void add(int add) { value += add; } + + @Override + public int compareTo(@NotNull Integer o) { + return Integer.compare(value, o); + } } diff --git a/common/src/main/java/com/dfsek/terra/api/util/mutable/MutablePrimitive.java b/common/src/main/java/com/dfsek/terra/api/util/mutable/MutablePrimitive.java index f1848007d..ab3e17f70 100644 --- a/common/src/main/java/com/dfsek/terra/api/util/mutable/MutablePrimitive.java +++ b/common/src/main/java/com/dfsek/terra/api/util/mutable/MutablePrimitive.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.util.mutable; -public interface MutablePrimitive { +public interface MutablePrimitive extends Comparable{ T get(); void set(T value); diff --git a/common/src/main/java/com/dfsek/terra/api/util/mutable/package-info.java b/common/src/main/java/com/dfsek/terra/api/util/mutable/package-info.java new file mode 100644 index 000000000..02bf8235e --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/util/mutable/package-info.java @@ -0,0 +1,4 @@ +/** + * Mutable objects containing primitive types. + */ +package com.dfsek.terra.api.util.mutable; \ No newline at end of file diff --git a/common/src/main/java/com/dfsek/terra/api/util/seeded/SeededBuilder.java b/common/src/main/java/com/dfsek/terra/api/util/seeded/SeededBuilder.java index ff35cc1f5..1a7d15d39 100644 --- a/common/src/main/java/com/dfsek/terra/api/util/seeded/SeededBuilder.java +++ b/common/src/main/java/com/dfsek/terra/api/util/seeded/SeededBuilder.java @@ -2,6 +2,7 @@ package com.dfsek.terra.api.util.seeded; import java.util.function.Function; +@FunctionalInterface public interface SeededBuilder extends Function { } diff --git a/common/src/main/java/com/dfsek/terra/api/util/seeded/SourceSeeded.java b/common/src/main/java/com/dfsek/terra/api/util/seeded/SourceSeeded.java index c64e4d17e..5ec6f4511 100644 --- a/common/src/main/java/com/dfsek/terra/api/util/seeded/SourceSeeded.java +++ b/common/src/main/java/com/dfsek/terra/api/util/seeded/SourceSeeded.java @@ -2,5 +2,6 @@ package com.dfsek.terra.api.util.seeded; import com.dfsek.terra.api.world.biome.pipeline.source.BiomeSource; +@FunctionalInterface public interface SourceSeeded extends SeededBuilder { } diff --git a/common/src/main/java/com/dfsek/terra/api/util/seeded/StageSeeded.java b/common/src/main/java/com/dfsek/terra/api/util/seeded/StageSeeded.java index 093e54207..02ebbe181 100644 --- a/common/src/main/java/com/dfsek/terra/api/util/seeded/StageSeeded.java +++ b/common/src/main/java/com/dfsek/terra/api/util/seeded/StageSeeded.java @@ -2,5 +2,6 @@ package com.dfsek.terra.api.util.seeded; import com.dfsek.terra.api.world.biome.pipeline.stages.Stage; +@FunctionalInterface public interface StageSeeded extends SeededBuilder { } diff --git a/common/src/main/java/com/dfsek/terra/api/world/biome/TerraBiome.java b/common/src/main/java/com/dfsek/terra/api/world/biome/TerraBiome.java index 1dcd5fdc7..4aaac0e9e 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/biome/TerraBiome.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/TerraBiome.java @@ -1,9 +1,9 @@ package com.dfsek.terra.api.world.biome; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.platform.world.Biome; import com.dfsek.terra.api.platform.world.World; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import java.util.Set; diff --git a/common/src/main/java/com/dfsek/terra/api/world/biome/UserDefinedBiome.java b/common/src/main/java/com/dfsek/terra/api/world/biome/UserDefinedBiome.java index 5f51ff5a7..40d12c428 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/biome/UserDefinedBiome.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/UserDefinedBiome.java @@ -1,8 +1,8 @@ package com.dfsek.terra.api.world.biome; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.platform.world.Biome; import com.dfsek.terra.api.platform.world.World; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.config.builder.GeneratorBuilder; import com.dfsek.terra.config.templates.BiomeTemplate; diff --git a/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/BorderListMutator.java b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/BorderListMutator.java index 5fcfc2e1a..d16016d91 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/BorderListMutator.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/BorderListMutator.java @@ -1,7 +1,7 @@ package com.dfsek.terra.api.world.biome.pipeline.mutator; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.noise.NoiseSampler; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.world.biome.TerraBiome; import java.util.Map; diff --git a/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/BorderMutator.java b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/BorderMutator.java index 15e7edcc9..d6195c7a4 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/BorderMutator.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/BorderMutator.java @@ -1,7 +1,7 @@ package com.dfsek.terra.api.world.biome.pipeline.mutator; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.noise.NoiseSampler; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.world.biome.TerraBiome; public class BorderMutator implements BiomeMutator { diff --git a/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/ReplaceListMutator.java b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/ReplaceListMutator.java index ebd3ec5f2..8d701109a 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/ReplaceListMutator.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/ReplaceListMutator.java @@ -1,7 +1,7 @@ package com.dfsek.terra.api.world.biome.pipeline.mutator; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.noise.NoiseSampler; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.world.biome.TerraBiome; import java.util.Map; diff --git a/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/ReplaceMutator.java b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/ReplaceMutator.java index b37657654..7bc705b66 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/ReplaceMutator.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/mutator/ReplaceMutator.java @@ -1,7 +1,7 @@ package com.dfsek.terra.api.world.biome.pipeline.mutator; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.noise.NoiseSampler; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.world.biome.TerraBiome; public class ReplaceMutator implements BiomeMutator { diff --git a/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/source/RandomSource.java b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/source/RandomSource.java index fa7b9fe01..fa95986b4 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/source/RandomSource.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/source/RandomSource.java @@ -1,7 +1,7 @@ package com.dfsek.terra.api.world.biome.pipeline.source; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.noise.NoiseSampler; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.world.biome.TerraBiome; public class RandomSource implements BiomeSource { diff --git a/common/src/main/java/com/dfsek/terra/api/world/biome/provider/StandardBiomeProvider.java b/common/src/main/java/com/dfsek/terra/api/world/biome/provider/StandardBiomeProvider.java index e53bd4749..397cbe7a4 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/biome/provider/StandardBiomeProvider.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/provider/StandardBiomeProvider.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.world.biome.provider; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.noise.NoiseSampler; import com.dfsek.terra.api.math.vector.Vector2; import com.dfsek.terra.api.world.biome.TerraBiome; diff --git a/common/src/main/java/com/dfsek/terra/api/world/generation/TerraChunkGenerator.java b/common/src/main/java/com/dfsek/terra/api/world/generation/TerraChunkGenerator.java index 71b9e8f90..5b6dba9f0 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/generation/TerraChunkGenerator.java +++ b/common/src/main/java/com/dfsek/terra/api/world/generation/TerraChunkGenerator.java @@ -1,6 +1,6 @@ package com.dfsek.terra.api.world.generation; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.platform.world.BiomeGrid; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.platform.world.generator.ChunkData; diff --git a/common/src/main/java/com/dfsek/terra/async/AsyncBiomeFinder.java b/common/src/main/java/com/dfsek/terra/api/world/locate/AsyncBiomeFinder.java similarity index 93% rename from common/src/main/java/com/dfsek/terra/async/AsyncBiomeFinder.java rename to common/src/main/java/com/dfsek/terra/api/world/locate/AsyncBiomeFinder.java index 38b6662a3..c41892b12 100644 --- a/common/src/main/java/com/dfsek/terra/async/AsyncBiomeFinder.java +++ b/common/src/main/java/com/dfsek/terra/api/world/locate/AsyncBiomeFinder.java @@ -1,6 +1,6 @@ -package com.dfsek.terra.async; +package com.dfsek.terra.api.world.locate; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.world.biome.TerraBiome; diff --git a/common/src/main/java/com/dfsek/terra/async/AsyncFeatureFinder.java b/common/src/main/java/com/dfsek/terra/api/world/locate/AsyncFeatureFinder.java similarity index 97% rename from common/src/main/java/com/dfsek/terra/async/AsyncFeatureFinder.java rename to common/src/main/java/com/dfsek/terra/api/world/locate/AsyncFeatureFinder.java index b44afc711..31b2dec6b 100644 --- a/common/src/main/java/com/dfsek/terra/async/AsyncFeatureFinder.java +++ b/common/src/main/java/com/dfsek/terra/api/world/locate/AsyncFeatureFinder.java @@ -1,6 +1,6 @@ -package com.dfsek.terra.async; +package com.dfsek.terra.api.world.locate; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.world.World; diff --git a/common/src/main/java/com/dfsek/terra/async/AsyncStructureFinder.java b/common/src/main/java/com/dfsek/terra/api/world/locate/AsyncStructureFinder.java similarity index 95% rename from common/src/main/java/com/dfsek/terra/async/AsyncStructureFinder.java rename to common/src/main/java/com/dfsek/terra/api/world/locate/AsyncStructureFinder.java index 4680da9fd..2686fb2db 100644 --- a/common/src/main/java/com/dfsek/terra/async/AsyncStructureFinder.java +++ b/common/src/main/java/com/dfsek/terra/api/world/locate/AsyncStructureFinder.java @@ -1,6 +1,6 @@ -package com.dfsek.terra.async; +package com.dfsek.terra.api.world.locate; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.MathUtil; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.math.vector.Vector3; diff --git a/common/src/main/java/com/dfsek/terra/api/world/palette/Palette.java b/common/src/main/java/com/dfsek/terra/api/world/palette/Palette.java index 0ea01239a..881cd406c 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/palette/Palette.java +++ b/common/src/main/java/com/dfsek/terra/api/world/palette/Palette.java @@ -1,8 +1,8 @@ package com.dfsek.terra.api.world.palette; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.noise.NoiseSampler; import com.dfsek.terra.api.util.GlueList; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import java.util.List; import java.util.Random; diff --git a/common/src/main/java/com/dfsek/terra/api/world/palette/holder/PaletteLayerHolder.java b/common/src/main/java/com/dfsek/terra/api/world/palette/holder/PaletteLayerHolder.java index 8881b1646..cb44e8fb4 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/palette/holder/PaletteLayerHolder.java +++ b/common/src/main/java/com/dfsek/terra/api/world/palette/holder/PaletteLayerHolder.java @@ -1,8 +1,8 @@ package com.dfsek.terra.api.world.palette.holder; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.noise.NoiseSampler; import com.dfsek.terra.api.platform.block.BlockData; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import org.jetbrains.annotations.NotNull; public class PaletteLayerHolder { diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/FractalTree.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/FractalTree.java index 869ed9183..9a95e3d8c 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/FractalTree.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/FractalTree.java @@ -1,11 +1,11 @@ package com.dfsek.terra.api.world.tree.fractal; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.entity.Entity; import com.dfsek.terra.api.platform.entity.EntityType; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; import java.util.Random; import java.util.function.Consumer; diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/TreeGeometry.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/TreeGeometry.java index 7ec3ee28c..46fc1f716 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/TreeGeometry.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/TreeGeometry.java @@ -1,9 +1,9 @@ package com.dfsek.terra.api.world.tree.fractal; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockData; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import java.util.Random; diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/Cactus.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/Cactus.java index 359d59f1d..5b56ea7f6 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/Cactus.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/Cactus.java @@ -1,9 +1,9 @@ package com.dfsek.terra.api.world.tree.fractal.trees; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.world.tree.fractal.FractalTree; import java.util.Random; diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/IceSpike.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/IceSpike.java index abbeb0f2b..dfa231326 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/IceSpike.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/IceSpike.java @@ -1,12 +1,12 @@ package com.dfsek.terra.api.world.tree.fractal.trees; -import com.dfsek.terra.api.core.TerraPlugin; -import com.dfsek.terra.api.math.ProbabilityCollection; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.handle.WorldHandle; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.world.tree.fractal.FractalTree; import com.dfsek.terra.api.world.tree.fractal.TreeGeometry; diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/OakTree.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/OakTree.java index a5502ee6a..c86a2620f 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/OakTree.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/OakTree.java @@ -1,10 +1,10 @@ package com.dfsek.terra.api.world.tree.fractal.trees; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.world.tree.fractal.FractalTree; import com.dfsek.terra.api.world.tree.fractal.TreeGeometry; import net.jafama.FastMath; diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredPillar.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredPillar.java index 0bb915cd5..225947dca 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredPillar.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredPillar.java @@ -1,9 +1,9 @@ package com.dfsek.terra.api.world.tree.fractal.trees; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.world.tree.fractal.FractalTree; import java.util.Random; diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredTree.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredTree.java index 2175df3c1..38425f989 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredTree.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredTree.java @@ -1,12 +1,12 @@ package com.dfsek.terra.api.world.tree.fractal.trees; -import com.dfsek.terra.api.core.TerraPlugin; -import com.dfsek.terra.api.math.ProbabilityCollection; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.handle.WorldHandle; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.world.tree.fractal.FractalTree; import com.dfsek.terra.api.world.tree.fractal.TreeGeometry; import net.jafama.FastMath; diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredPillar.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredPillar.java index a73c5dce9..a1465ef05 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredPillar.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredPillar.java @@ -1,9 +1,9 @@ package com.dfsek.terra.api.world.tree.fractal.trees; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.world.tree.fractal.FractalTree; import java.util.Random; diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredTree.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredTree.java index ce9fa2abf..a5109ba9d 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredTree.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredTree.java @@ -1,12 +1,12 @@ package com.dfsek.terra.api.world.tree.fractal.trees; -import com.dfsek.terra.api.core.TerraPlugin; -import com.dfsek.terra.api.math.ProbabilityCollection; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.handle.WorldHandle; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.world.tree.fractal.FractalTree; import com.dfsek.terra.api.world.tree.fractal.TreeGeometry; import net.jafama.FastMath; diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SpruceTree.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SpruceTree.java index eb51add0c..5f2f91765 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SpruceTree.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SpruceTree.java @@ -1,10 +1,10 @@ package com.dfsek.terra.api.world.tree.fractal.trees; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.world.tree.fractal.FractalTree; import com.dfsek.terra.api.world.tree.fractal.TreeGeometry; import net.jafama.FastMath; diff --git a/common/src/main/java/com/dfsek/terra/carving/CarverCache.java b/common/src/main/java/com/dfsek/terra/carving/CarverCache.java index fe379c53c..00d3427a1 100644 --- a/common/src/main/java/com/dfsek/terra/carving/CarverCache.java +++ b/common/src/main/java/com/dfsek/terra/carving/CarverCache.java @@ -1,6 +1,6 @@ package com.dfsek.terra.carving; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.MathUtil; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.world.World; diff --git a/common/src/main/java/com/dfsek/terra/carving/CarverPalette.java b/common/src/main/java/com/dfsek/terra/carving/CarverPalette.java index 937994d1d..c0c942bcd 100644 --- a/common/src/main/java/com/dfsek/terra/carving/CarverPalette.java +++ b/common/src/main/java/com/dfsek/terra/carving/CarverPalette.java @@ -1,9 +1,9 @@ package com.dfsek.terra.carving; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.MaterialData; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import java.util.Map; import java.util.TreeMap; diff --git a/common/src/main/java/com/dfsek/terra/carving/UserDefinedCarver.java b/common/src/main/java/com/dfsek/terra/carving/UserDefinedCarver.java index e5fd230ab..8172425c9 100644 --- a/common/src/main/java/com/dfsek/terra/carving/UserDefinedCarver.java +++ b/common/src/main/java/com/dfsek/terra/carving/UserDefinedCarver.java @@ -4,7 +4,7 @@ import com.dfsek.paralithic.Expression; import com.dfsek.paralithic.eval.parser.Parser; import com.dfsek.paralithic.eval.parser.Scope; import com.dfsek.paralithic.eval.tokenizer.ParseException; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.math.paralithic.defined.UserDefinedFunction; import com.dfsek.terra.api.math.paralithic.noise.NoiseFunction2; diff --git a/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java b/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java index 82bae3dfb..b848f0fbb 100644 --- a/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java +++ b/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java @@ -1,17 +1,17 @@ package com.dfsek.terra.config; import com.dfsek.tectonic.loading.TypeRegistry; -import com.dfsek.terra.addons.addon.TerraAddon; import com.dfsek.terra.api.LoaderRegistrar; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.addons.TerraAddon; import com.dfsek.terra.api.math.GridSpawn; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.math.noise.samplers.ImageSampler; import com.dfsek.terra.api.math.noise.samplers.noise.CellularSampler; +import com.dfsek.terra.api.util.collections.MaterialSet; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.util.seeded.SourceSeeded; import com.dfsek.terra.api.util.seeded.StageSeeded; -import com.dfsek.terra.api.util.world.MaterialSet; import com.dfsek.terra.api.world.biome.pipeline.stages.ExpanderStage; import com.dfsek.terra.api.world.biome.pipeline.stages.MutatorStage; import com.dfsek.terra.api.world.biome.provider.BiomeProvider; diff --git a/common/src/main/java/com/dfsek/terra/config/PluginConfig.java b/common/src/main/java/com/dfsek/terra/config/PluginConfig.java index 1d058e96a..b9815d4f1 100644 --- a/common/src/main/java/com/dfsek/terra/config/PluginConfig.java +++ b/common/src/main/java/com/dfsek/terra/config/PluginConfig.java @@ -5,7 +5,7 @@ import com.dfsek.tectonic.annotations.Value; import com.dfsek.tectonic.config.ConfigTemplate; import com.dfsek.tectonic.exception.ConfigException; import com.dfsek.tectonic.loading.ConfigLoader; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.util.JarUtil; import java.io.File; diff --git a/common/src/main/java/com/dfsek/terra/config/exception/FileMissingException.java b/common/src/main/java/com/dfsek/terra/config/exception/FileMissingException.java deleted file mode 100644 index c4ac0ecf3..000000000 --- a/common/src/main/java/com/dfsek/terra/config/exception/FileMissingException.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.dfsek.terra.config.exception; - -import com.dfsek.tectonic.exception.ConfigException; - -public class FileMissingException extends ConfigException { - private static final long serialVersionUID = 4489395640246760802L; - - public FileMissingException(String message) { - super(message); - } - - public FileMissingException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java b/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java index f3e987b93..66d871149 100644 --- a/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java +++ b/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java @@ -1,7 +1,7 @@ package com.dfsek.terra.config.factories; import com.dfsek.paralithic.eval.parser.Scope; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.UserDefinedBiome; import com.dfsek.terra.config.builder.GeneratorBuilder; diff --git a/common/src/main/java/com/dfsek/terra/config/factories/CarverFactory.java b/common/src/main/java/com/dfsek/terra/config/factories/CarverFactory.java index 19c16e47e..9b3e681c7 100644 --- a/common/src/main/java/com/dfsek/terra/config/factories/CarverFactory.java +++ b/common/src/main/java/com/dfsek/terra/config/factories/CarverFactory.java @@ -2,7 +2,7 @@ package com.dfsek.terra.config.factories; import com.dfsek.paralithic.eval.tokenizer.ParseException; import com.dfsek.tectonic.exception.LoadException; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.MathUtil; import com.dfsek.terra.carving.UserDefinedCarver; import com.dfsek.terra.config.pack.ConfigPack; diff --git a/common/src/main/java/com/dfsek/terra/config/factories/FloraFactory.java b/common/src/main/java/com/dfsek/terra/config/factories/FloraFactory.java index ba51ca3dd..160e1dc21 100644 --- a/common/src/main/java/com/dfsek/terra/config/factories/FloraFactory.java +++ b/common/src/main/java/com/dfsek/terra/config/factories/FloraFactory.java @@ -1,6 +1,6 @@ package com.dfsek.terra.config.factories; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.noise.samplers.noise.random.WhiteNoiseSampler; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.world.flora.Flora; diff --git a/common/src/main/java/com/dfsek/terra/config/factories/OreFactory.java b/common/src/main/java/com/dfsek/terra/config/factories/OreFactory.java index da74a1a81..9eeede7af 100644 --- a/common/src/main/java/com/dfsek/terra/config/factories/OreFactory.java +++ b/common/src/main/java/com/dfsek/terra/config/factories/OreFactory.java @@ -1,6 +1,6 @@ package com.dfsek.terra.config.factories; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.config.templates.OreTemplate; import com.dfsek.terra.world.population.items.ores.DeformedSphereOre; diff --git a/common/src/main/java/com/dfsek/terra/config/factories/PaletteFactory.java b/common/src/main/java/com/dfsek/terra/config/factories/PaletteFactory.java index 0e113f216..d7cf0a74c 100644 --- a/common/src/main/java/com/dfsek/terra/config/factories/PaletteFactory.java +++ b/common/src/main/java/com/dfsek/terra/config/factories/PaletteFactory.java @@ -1,6 +1,6 @@ package com.dfsek.terra.config.factories; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.world.palette.NoisePalette; import com.dfsek.terra.api.world.palette.Palette; diff --git a/common/src/main/java/com/dfsek/terra/config/factories/StructureFactory.java b/common/src/main/java/com/dfsek/terra/config/factories/StructureFactory.java index 5724e2bfa..afefca45f 100644 --- a/common/src/main/java/com/dfsek/terra/config/factories/StructureFactory.java +++ b/common/src/main/java/com/dfsek/terra/config/factories/StructureFactory.java @@ -1,6 +1,6 @@ package com.dfsek.terra.config.factories; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.config.templates.StructureTemplate; import com.dfsek.terra.world.population.items.TerraStructure; diff --git a/common/src/main/java/com/dfsek/terra/config/factories/TerraFactory.java b/common/src/main/java/com/dfsek/terra/config/factories/TerraFactory.java index 8e7d5ee82..5965eb4ad 100644 --- a/common/src/main/java/com/dfsek/terra/config/factories/TerraFactory.java +++ b/common/src/main/java/com/dfsek/terra/config/factories/TerraFactory.java @@ -2,7 +2,7 @@ package com.dfsek.terra.config.factories; import com.dfsek.tectonic.config.ConfigTemplate; import com.dfsek.tectonic.exception.LoadException; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; public interface TerraFactory { O build(C config, TerraPlugin main) throws LoadException; diff --git a/common/src/main/java/com/dfsek/terra/config/factories/TreeFactory.java b/common/src/main/java/com/dfsek/terra/config/factories/TreeFactory.java index 717ad33cd..681e03b45 100644 --- a/common/src/main/java/com/dfsek/terra/config/factories/TreeFactory.java +++ b/common/src/main/java/com/dfsek/terra/config/factories/TreeFactory.java @@ -1,6 +1,6 @@ package com.dfsek.terra.config.factories; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.world.tree.Tree; import com.dfsek.terra.config.templates.TreeTemplate; import com.dfsek.terra.world.population.items.tree.TerraTree; diff --git a/common/src/main/java/com/dfsek/terra/config/lang/LangUtil.java b/common/src/main/java/com/dfsek/terra/config/lang/LangUtil.java index a3d47ccd1..2c8452d64 100644 --- a/common/src/main/java/com/dfsek/terra/config/lang/LangUtil.java +++ b/common/src/main/java/com/dfsek/terra/config/lang/LangUtil.java @@ -1,6 +1,6 @@ package com.dfsek.terra.config.lang; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.platform.CommandSender; import java.io.File; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/MaterialSetLoader.java b/common/src/main/java/com/dfsek/terra/config/loaders/MaterialSetLoader.java index 4001a8589..d4d7b5c01 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/MaterialSetLoader.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/MaterialSetLoader.java @@ -4,7 +4,7 @@ import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; import com.dfsek.tectonic.loading.TypeLoader; import com.dfsek.terra.api.platform.block.MaterialData; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; import java.lang.reflect.Type; import java.util.List; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/ProbabilityCollectionLoader.java b/common/src/main/java/com/dfsek/terra/config/loaders/ProbabilityCollectionLoader.java index 28a471ce1..050281b4d 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/ProbabilityCollectionLoader.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/ProbabilityCollectionLoader.java @@ -3,7 +3,7 @@ package com.dfsek.terra.config.loaders; import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; import com.dfsek.tectonic.loading.TypeLoader; -import com.dfsek.terra.api.math.ProbabilityCollection; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/Types.java b/common/src/main/java/com/dfsek/terra/config/loaders/Types.java index 206c6226a..9c91e598a 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/Types.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/Types.java @@ -1,8 +1,8 @@ package com.dfsek.terra.config.loaders; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.flora.Flora; import com.dfsek.terra.api.world.palette.Palette; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/FloraLayerLoader.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/FloraLayerLoader.java index 411dd0b5e..719bf9b91 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/FloraLayerLoader.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/FloraLayerLoader.java @@ -4,9 +4,9 @@ import com.dfsek.tectonic.exception.ConfigException; import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; import com.dfsek.tectonic.loading.TypeLoader; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.math.noise.samplers.noise.random.WhiteNoiseSampler; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.util.seeded.NoiseSeeded; import com.dfsek.terra.api.world.flora.Flora; import com.dfsek.terra.config.loaders.Types; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/TreeLayerLoader.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/TreeLayerLoader.java index fa2b98181..0fddd9705 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/TreeLayerLoader.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/TreeLayerLoader.java @@ -3,9 +3,9 @@ package com.dfsek.terra.config.loaders.config; import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; import com.dfsek.tectonic.loading.TypeLoader; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.math.noise.samplers.noise.random.WhiteNoiseSampler; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.util.seeded.NoiseSeeded; import com.dfsek.terra.api.world.tree.Tree; import com.dfsek.terra.config.loaders.Types; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/SourceBuilderLoader.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/SourceBuilderLoader.java index a7d2d61ed..e4509473c 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/SourceBuilderLoader.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/SourceBuilderLoader.java @@ -3,7 +3,7 @@ package com.dfsek.terra.config.loaders.config.biome; import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; import com.dfsek.tectonic.loading.TypeLoader; -import com.dfsek.terra.api.math.ProbabilityCollection; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.util.seeded.NoiseSeeded; import com.dfsek.terra.api.util.seeded.SourceSeeded; import com.dfsek.terra.api.world.biome.TerraBiome; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/BiomePipelineTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/BiomePipelineTemplate.java index 0e3195efb..b0a05add6 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/BiomePipelineTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/BiomePipelineTemplate.java @@ -2,7 +2,7 @@ package com.dfsek.terra.config.loaders.config.biome.templates.source; import com.dfsek.tectonic.annotations.Default; import com.dfsek.tectonic.annotations.Value; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.util.seeded.SourceSeeded; import com.dfsek.terra.api.util.seeded.StageSeeded; import com.dfsek.terra.api.world.biome.pipeline.BiomePipeline; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java index b7eb95219..570b161fc 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java @@ -1,7 +1,7 @@ package com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator; import com.dfsek.tectonic.annotations.Value; -import com.dfsek.terra.api.math.ProbabilityCollection; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator; import com.dfsek.terra.api.world.biome.pipeline.mutator.BorderListMutator; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderMutatorTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderMutatorTemplate.java index 6b06e8bcf..207d2720a 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderMutatorTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderMutatorTemplate.java @@ -1,7 +1,7 @@ package com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator; import com.dfsek.tectonic.annotations.Value; -import com.dfsek.terra.api.math.ProbabilityCollection; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator; import com.dfsek.terra.api.world.biome.pipeline.mutator.BorderMutator; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceListMutatorTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceListMutatorTemplate.java index 52bfdf946..7c3cfd968 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceListMutatorTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceListMutatorTemplate.java @@ -1,7 +1,7 @@ package com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator; import com.dfsek.tectonic.annotations.Value; -import com.dfsek.terra.api.math.ProbabilityCollection; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator; import com.dfsek.terra.api.world.biome.pipeline.mutator.ReplaceListMutator; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceMutatorTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceMutatorTemplate.java index 379b08137..61ad68c1d 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceMutatorTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceMutatorTemplate.java @@ -1,7 +1,7 @@ package com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator; import com.dfsek.tectonic.annotations.Value; -import com.dfsek.terra.api.math.ProbabilityCollection; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator; import com.dfsek.terra.api.world.biome.pipeline.mutator.ReplaceMutator; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/palette/CarverPaletteLoader.java b/common/src/main/java/com/dfsek/terra/config/loaders/palette/CarverPaletteLoader.java index 26f12725e..696683dd5 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/palette/CarverPaletteLoader.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/palette/CarverPaletteLoader.java @@ -4,9 +4,9 @@ import com.dfsek.tectonic.config.Configuration; import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; import com.dfsek.tectonic.loading.TypeLoader; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.carving.CarverPalette; import com.dfsek.terra.config.loaders.Types; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/palette/PaletteLayerLoader.java b/common/src/main/java/com/dfsek/terra/config/loaders/palette/PaletteLayerLoader.java index 12c32224c..01a30a2e2 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/palette/PaletteLayerLoader.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/palette/PaletteLayerLoader.java @@ -3,9 +3,9 @@ package com.dfsek.terra.config.loaders.palette; import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; import com.dfsek.tectonic.loading.TypeLoader; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.noise.NoiseSampler; import com.dfsek.terra.api.platform.block.BlockData; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.util.seeded.NoiseSeeded; import com.dfsek.terra.api.world.palette.holder.PaletteLayerHolder; import com.dfsek.terra.config.loaders.Types; diff --git a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java index d7c32f3c6..2e88fda2b 100644 --- a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java +++ b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java @@ -8,10 +8,11 @@ import com.dfsek.tectonic.loading.ConfigLoader; import com.dfsek.tectonic.loading.TypeRegistry; import com.dfsek.tectonic.loading.object.ObjectTemplate; import com.dfsek.terra.api.LoaderRegistrar; -import com.dfsek.terra.api.core.TerraPlugin; -import com.dfsek.terra.api.core.event.events.config.ConfigPackPostLoadEvent; -import com.dfsek.terra.api.core.event.events.config.ConfigPackPreLoadEvent; +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.event.events.config.ConfigPackPostLoadEvent; +import com.dfsek.terra.api.event.events.config.ConfigPackPreLoadEvent; import com.dfsek.terra.api.platform.block.BlockData; +import com.dfsek.terra.api.registry.CheckedRegistry; import com.dfsek.terra.api.structures.loot.LootTable; import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder; import com.dfsek.terra.api.structures.script.StructureScript; @@ -22,7 +23,6 @@ import com.dfsek.terra.api.world.flora.Flora; import com.dfsek.terra.api.world.palette.Palette; import com.dfsek.terra.api.world.tree.Tree; import com.dfsek.terra.carving.UserDefinedCarver; -import com.dfsek.terra.config.exception.FileMissingException; import com.dfsek.terra.config.factories.BiomeFactory; import com.dfsek.terra.config.factories.CarverFactory; import com.dfsek.terra.config.factories.FloraFactory; @@ -49,7 +49,6 @@ import com.dfsek.terra.config.templates.OreTemplate; import com.dfsek.terra.config.templates.PaletteTemplate; import com.dfsek.terra.config.templates.StructureTemplate; import com.dfsek.terra.config.templates.TreeTemplate; -import com.dfsek.terra.registry.CheckedRegistry; import com.dfsek.terra.registry.OpenRegistry; import com.dfsek.terra.registry.config.BiomeRegistry; import com.dfsek.terra.registry.config.CarverRegistry; @@ -145,7 +144,7 @@ public class ConfigPack implements LoaderRegistrar { biomeProviderBuilder = packPostTemplate.getProviderBuilder(); biomeProviderBuilder.build(0); // Build dummy provider to catch errors at load time. } catch(FileNotFoundException e) { - throw new FileMissingException("No pack.yml file found in " + folder.getAbsolutePath(), e); + throw new LoadException("No pack.yml file found in " + folder.getAbsolutePath(), e); } } catch(Exception e) { main.getLogger().severe("Failed to load config pack from folder \"" + folder.getAbsolutePath() + "\""); @@ -176,7 +175,7 @@ public class ConfigPack implements LoaderRegistrar { if(entry.getName().equals("pack.yml")) pack = entry; } - if(pack == null) throw new FileMissingException("No pack.yml file found in " + file.getName()); + if(pack == null) throw new LoadException("No pack.yml file found in " + file.getName()); selfLoader.load(template, file.getInputStream(pack)); main.getLogger().info("Loading config pack \"" + template.getID() + "\""); diff --git a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPackTemplate.java b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPackTemplate.java index d57615148..593d6e2d7 100644 --- a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPackTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPackTemplate.java @@ -3,7 +3,7 @@ package com.dfsek.terra.config.pack; import com.dfsek.tectonic.annotations.Default; import com.dfsek.tectonic.annotations.Value; import com.dfsek.tectonic.config.ConfigTemplate; -import com.dfsek.terra.addons.addon.TerraAddon; +import com.dfsek.terra.api.addons.TerraAddon; import com.dfsek.terra.api.util.seeded.NoiseSeeded; import com.dfsek.terra.config.loaders.config.function.FunctionTemplate; diff --git a/common/src/main/java/com/dfsek/terra/config/templates/BiomeTemplate.java b/common/src/main/java/com/dfsek/terra/config/templates/BiomeTemplate.java index 230be1ea1..a7aa92403 100644 --- a/common/src/main/java/com/dfsek/terra/config/templates/BiomeTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/templates/BiomeTemplate.java @@ -8,8 +8,7 @@ import com.dfsek.tectonic.annotations.Default; import com.dfsek.tectonic.annotations.Value; import com.dfsek.tectonic.config.ValidatedConfigTemplate; import com.dfsek.tectonic.exception.ValidationException; -import com.dfsek.terra.api.core.TerraPlugin; -import com.dfsek.terra.api.math.ProbabilityCollection; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.noise.NoiseSampler; import com.dfsek.terra.api.math.noise.samplers.noise.ConstantSampler; import com.dfsek.terra.api.math.paralithic.BlankFunction; @@ -18,6 +17,7 @@ import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.platform.world.Biome; import com.dfsek.terra.api.util.GlueList; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.util.seeded.NoiseSeeded; import com.dfsek.terra.api.world.palette.Palette; import com.dfsek.terra.api.world.palette.SinglePalette; diff --git a/common/src/main/java/com/dfsek/terra/config/templates/CarverTemplate.java b/common/src/main/java/com/dfsek/terra/config/templates/CarverTemplate.java index b196852a1..989fe3919 100644 --- a/common/src/main/java/com/dfsek/terra/config/templates/CarverTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/templates/CarverTemplate.java @@ -5,7 +5,7 @@ import com.dfsek.tectonic.annotations.Default; import com.dfsek.tectonic.annotations.Value; import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.platform.block.MaterialData; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.carving.CarverPalette; import java.util.HashMap; diff --git a/common/src/main/java/com/dfsek/terra/config/templates/FloraTemplate.java b/common/src/main/java/com/dfsek/terra/config/templates/FloraTemplate.java index 3b676bee8..8e1564e4a 100644 --- a/common/src/main/java/com/dfsek/terra/config/templates/FloraTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/templates/FloraTemplate.java @@ -3,7 +3,7 @@ package com.dfsek.terra.config.templates; import com.dfsek.tectonic.annotations.Abstractable; import com.dfsek.tectonic.annotations.Default; import com.dfsek.tectonic.annotations.Value; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.world.palette.holder.PaletteLayerHolder; import com.dfsek.terra.world.population.items.flora.TerraFlora; diff --git a/common/src/main/java/com/dfsek/terra/config/templates/OreTemplate.java b/common/src/main/java/com/dfsek/terra/config/templates/OreTemplate.java index 7e56bab83..7362a4c6a 100644 --- a/common/src/main/java/com/dfsek/terra/config/templates/OreTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/templates/OreTemplate.java @@ -5,7 +5,7 @@ import com.dfsek.tectonic.annotations.Default; import com.dfsek.tectonic.annotations.Value; import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.world.population.items.ores.Ore; @SuppressWarnings({"unused", "FieldMayBeFinal"}) diff --git a/common/src/main/java/com/dfsek/terra/config/templates/StructureTemplate.java b/common/src/main/java/com/dfsek/terra/config/templates/StructureTemplate.java index 8da29ddf8..a291ae3f9 100644 --- a/common/src/main/java/com/dfsek/terra/config/templates/StructureTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/templates/StructureTemplate.java @@ -5,10 +5,10 @@ import com.dfsek.tectonic.annotations.Default; import com.dfsek.tectonic.annotations.Value; import com.dfsek.tectonic.config.ConfigTemplate; import com.dfsek.terra.api.math.GridSpawn; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.structures.script.StructureScript; import com.dfsek.terra.api.util.GlueList; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import java.util.List; diff --git a/common/src/main/java/com/dfsek/terra/config/templates/TreeTemplate.java b/common/src/main/java/com/dfsek/terra/config/templates/TreeTemplate.java index 07db47a1c..008d05d4f 100644 --- a/common/src/main/java/com/dfsek/terra/config/templates/TreeTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/templates/TreeTemplate.java @@ -3,9 +3,9 @@ package com.dfsek.terra.config.templates; import com.dfsek.tectonic.annotations.Abstractable; import com.dfsek.tectonic.annotations.Default; import com.dfsek.tectonic.annotations.Value; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.structures.script.StructureScript; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; @SuppressWarnings({"unused", "FieldMayBeFinal"}) public class TreeTemplate extends AbstractableTemplate { diff --git a/common/src/main/java/com/dfsek/terra/registry/OpenRegistry.java b/common/src/main/java/com/dfsek/terra/registry/OpenRegistry.java index 5d3fbb5bd..43fc732bd 100644 --- a/common/src/main/java/com/dfsek/terra/registry/OpenRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/OpenRegistry.java @@ -2,7 +2,7 @@ package com.dfsek.terra.registry; import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; -import com.dfsek.tectonic.loading.TypeLoader; +import com.dfsek.terra.api.registry.Registry; import com.dfsek.terra.registry.exception.DuplicateEntryException; import java.lang.reflect.Type; diff --git a/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java index 3a3905330..c06b8b0d4 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java @@ -1,9 +1,9 @@ package com.dfsek.terra.registry.config; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.MaterialData; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.world.flora.Flora; import com.dfsek.terra.registry.OpenRegistry; import com.dfsek.terra.world.population.items.flora.ConstantFlora; diff --git a/common/src/main/java/com/dfsek/terra/registry/config/PaletteRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/PaletteRegistry.java index 53a857d9e..e54c8ec81 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/PaletteRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/PaletteRegistry.java @@ -1,6 +1,6 @@ package com.dfsek.terra.registry.config; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.world.palette.Palette; import com.dfsek.terra.api.world.palette.SinglePalette; diff --git a/common/src/main/java/com/dfsek/terra/registry/config/TreeRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/TreeRegistry.java index bf9fa629f..05a29d849 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/TreeRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/TreeRegistry.java @@ -1,6 +1,6 @@ package com.dfsek.terra.registry.config; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.BlockFace; import com.dfsek.terra.api.platform.block.MaterialData; diff --git a/common/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java b/common/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java index 3483b3091..6f8ae2663 100644 --- a/common/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java @@ -1,13 +1,13 @@ package com.dfsek.terra.registry.master; -import com.dfsek.terra.addons.addon.TerraAddon; -import com.dfsek.terra.addons.injection.InjectionException; -import com.dfsek.terra.addons.injection.Injector; -import com.dfsek.terra.addons.loading.AddonClassLoader; -import com.dfsek.terra.addons.loading.AddonLoadException; -import com.dfsek.terra.addons.loading.pre.AddonPool; -import com.dfsek.terra.addons.loading.pre.PreLoadAddon; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.addon.AddonClassLoader; +import com.dfsek.terra.addon.AddonPool; +import com.dfsek.terra.addon.PreLoadAddon; +import com.dfsek.terra.addon.exception.AddonLoadException; +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.addons.TerraAddon; +import com.dfsek.terra.api.injection.Injector; +import com.dfsek.terra.api.injection.exception.InjectionException; import com.dfsek.terra.registry.OpenRegistry; import com.dfsek.terra.registry.exception.DuplicateEntryException; diff --git a/common/src/main/java/com/dfsek/terra/registry/master/ConfigRegistry.java b/common/src/main/java/com/dfsek/terra/registry/master/ConfigRegistry.java index 17476237c..c756a2b2b 100644 --- a/common/src/main/java/com/dfsek/terra/registry/master/ConfigRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/master/ConfigRegistry.java @@ -1,7 +1,7 @@ package com.dfsek.terra.registry.master; import com.dfsek.tectonic.exception.ConfigException; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.registry.OpenRegistry; diff --git a/common/src/main/java/com/dfsek/terra/world/TerraWorld.java b/common/src/main/java/com/dfsek/terra/world/TerraWorld.java index 236224aa6..f14773800 100644 --- a/common/src/main/java/com/dfsek/terra/world/TerraWorld.java +++ b/common/src/main/java/com/dfsek/terra/world/TerraWorld.java @@ -1,7 +1,7 @@ package com.dfsek.terra.world; -import com.dfsek.terra.api.core.TerraPlugin; -import com.dfsek.terra.api.core.event.events.world.TerraWorldLoadEvent; +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.event.events.world.TerraWorldLoadEvent; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockData; diff --git a/common/src/main/java/com/dfsek/terra/world/carving/NoiseCarver.java b/common/src/main/java/com/dfsek/terra/world/carving/NoiseCarver.java index 04b961a90..e325e7a0c 100644 --- a/common/src/main/java/com/dfsek/terra/world/carving/NoiseCarver.java +++ b/common/src/main/java/com/dfsek/terra/world/carving/NoiseCarver.java @@ -1,6 +1,6 @@ package com.dfsek.terra.world.carving; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.world.ChunkAccess; diff --git a/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator2D.java b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator2D.java index be6857923..3f841b95a 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator2D.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator2D.java @@ -1,6 +1,6 @@ package com.dfsek.terra.world.generation.generators; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.world.BiomeGrid; diff --git a/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java index 734dbfd59..6fe999c4d 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java @@ -1,6 +1,6 @@ package com.dfsek.terra.world.generation.generators; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockData; diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/SamplerCache.java b/common/src/main/java/com/dfsek/terra/world/generation/math/SamplerCache.java index 31e7e6c00..bfc287d9e 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/math/SamplerCache.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/SamplerCache.java @@ -1,6 +1,6 @@ package com.dfsek.terra.world.generation.math; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.MathUtil; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.world.TerraWorld; diff --git a/common/src/main/java/com/dfsek/terra/world/population/CavePopulator.java b/common/src/main/java/com/dfsek/terra/world/population/CavePopulator.java index 929d41626..38d5755fe 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/CavePopulator.java +++ b/common/src/main/java/com/dfsek/terra/world/population/CavePopulator.java @@ -1,6 +1,6 @@ package com.dfsek.terra.world.population; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.Block; import com.dfsek.terra.api.platform.block.BlockData; @@ -52,28 +52,28 @@ public class CavePopulator implements TerraBlockPopulator { switch(type) { case CENTER: if(template.getInner().canReplace(m)) { - handle.setBlockData(b, template.getInner().get(v.getBlockY()).get(random), false); + b.setBlockData(template.getInner().get(v.getBlockY()).get(random), false); if(template.getUpdate().contains(m)) updateNeeded.add(b); if(template.getShift().containsKey(m)) shiftCandidate.put(b.getLocation(), m); } break; case WALL: if(template.getOuter().canReplace(m)) { - handle.setBlockData(b, template.getOuter().get(v.getBlockY()).get(random), false); + b.setBlockData(template.getOuter().get(v.getBlockY()).get(random), false); if(template.getUpdate().contains(m)) updateNeeded.add(b); if(template.getShift().containsKey(m)) shiftCandidate.put(b.getLocation(), m); } break; case TOP: if(template.getTop().canReplace(m)) { - handle.setBlockData(b, template.getTop().get(v.getBlockY()).get(random), false); + b.setBlockData(template.getTop().get(v.getBlockY()).get(random), false); if(template.getUpdate().contains(m)) updateNeeded.add(b); if(template.getShift().containsKey(m)) shiftCandidate.put(b.getLocation(), m); } break; case BOTTOM: if(template.getBottom().canReplace(m)) { - handle.setBlockData(b, template.getBottom().get(v.getBlockY()).get(random), false); + b.setBlockData(template.getBottom().get(v.getBlockY()).get(random), false); if(template.getUpdate().contains(m)) updateNeeded.add(b); if(template.getShift().containsKey(m)) shiftCandidate.put(b.getLocation(), m); } @@ -95,8 +95,8 @@ public class CavePopulator implements TerraBlockPopulator { } for(Block b : updateNeeded) { BlockData orig = handle.getBlockData(b); - handle.setBlockData(b, AIR, false); - handle.setBlockData(b, orig, true); + b.setBlockData(AIR, false); + b.setBlockData(orig, true); } } diff --git a/common/src/main/java/com/dfsek/terra/world/population/FloraPopulator.java b/common/src/main/java/com/dfsek/terra/world/population/FloraPopulator.java index 4aeca61c2..281854cce 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/FloraPopulator.java +++ b/common/src/main/java/com/dfsek/terra/world/population/FloraPopulator.java @@ -1,6 +1,6 @@ package com.dfsek.terra.world.population; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Vector2; import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.platform.world.World; diff --git a/common/src/main/java/com/dfsek/terra/world/population/OrePopulator.java b/common/src/main/java/com/dfsek/terra/world/population/OrePopulator.java index 1fdc5c961..a67944409 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/OrePopulator.java +++ b/common/src/main/java/com/dfsek/terra/world/population/OrePopulator.java @@ -1,6 +1,6 @@ package com.dfsek.terra.world.population; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.MathUtil; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.world.Chunk; diff --git a/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java b/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java index d19fc1fa0..ed46b15e3 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java +++ b/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java @@ -1,6 +1,6 @@ package com.dfsek.terra.world.population; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.MathUtil; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.world.Chunk; diff --git a/common/src/main/java/com/dfsek/terra/world/population/TreePopulator.java b/common/src/main/java/com/dfsek/terra/world/population/TreePopulator.java index 1b14c80bd..82bf925c7 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/TreePopulator.java +++ b/common/src/main/java/com/dfsek/terra/world/population/TreePopulator.java @@ -1,6 +1,6 @@ package com.dfsek.terra.world.population; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Vector2; import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.platform.world.World; diff --git a/common/src/main/java/com/dfsek/terra/world/population/items/PlaceableLayer.java b/common/src/main/java/com/dfsek/terra/world/population/items/PlaceableLayer.java index 89e39ae67..e150d92fe 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/items/PlaceableLayer.java +++ b/common/src/main/java/com/dfsek/terra/world/population/items/PlaceableLayer.java @@ -1,10 +1,10 @@ package com.dfsek.terra.world.population.items; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.math.noise.NoiseSampler; import com.dfsek.terra.api.math.vector.Vector2; import com.dfsek.terra.api.platform.world.Chunk; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; public abstract class PlaceableLayer { protected final double density; diff --git a/common/src/main/java/com/dfsek/terra/world/population/items/TerraStructure.java b/common/src/main/java/com/dfsek/terra/world/population/items/TerraStructure.java index 975ea34ff..f3976fbab 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/items/TerraStructure.java +++ b/common/src/main/java/com/dfsek/terra/world/population/items/TerraStructure.java @@ -1,9 +1,9 @@ package com.dfsek.terra.world.population.items; import com.dfsek.terra.api.math.GridSpawn; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.structures.script.StructureScript; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.config.templates.StructureTemplate; public class TerraStructure { diff --git a/common/src/main/java/com/dfsek/terra/world/population/items/flora/ConstantFlora.java b/common/src/main/java/com/dfsek/terra/world/population/items/flora/ConstantFlora.java index 0559f61dd..d7bec46bf 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/items/flora/ConstantFlora.java +++ b/common/src/main/java/com/dfsek/terra/world/population/items/flora/ConstantFlora.java @@ -7,7 +7,7 @@ import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.BlockFace; import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.util.GlueList; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.world.flora.Flora; import java.util.List; diff --git a/common/src/main/java/com/dfsek/terra/world/population/items/flora/FloraLayer.java b/common/src/main/java/com/dfsek/terra/world/population/items/flora/FloraLayer.java index a5feb9c84..579b70035 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/items/flora/FloraLayer.java +++ b/common/src/main/java/com/dfsek/terra/world/population/items/flora/FloraLayer.java @@ -1,10 +1,10 @@ package com.dfsek.terra.world.population.items.flora; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.math.noise.NoiseSampler; import com.dfsek.terra.api.math.vector.Vector2; import com.dfsek.terra.api.platform.world.Chunk; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.world.flora.Flora; import com.dfsek.terra.world.population.items.PlaceableLayer; diff --git a/common/src/main/java/com/dfsek/terra/world/population/items/flora/TerraFlora.java b/common/src/main/java/com/dfsek/terra/world/population/items/flora/TerraFlora.java index c542e06b4..28ecac16d 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/items/flora/TerraFlora.java +++ b/common/src/main/java/com/dfsek/terra/world/population/items/flora/TerraFlora.java @@ -1,6 +1,6 @@ package com.dfsek.terra.world.population.items.flora; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.Block; @@ -13,7 +13,7 @@ import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.util.FastRandom; import com.dfsek.terra.api.util.GlueList; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.world.flora.Flora; import com.dfsek.terra.api.world.palette.Palette; import net.jafama.FastMath; diff --git a/common/src/main/java/com/dfsek/terra/world/population/items/ores/DeformedSphereOre.java b/common/src/main/java/com/dfsek/terra/world/population/items/ores/DeformedSphereOre.java index 22c6bb193..9df59e768 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/items/ores/DeformedSphereOre.java +++ b/common/src/main/java/com/dfsek/terra/world/population/items/ores/DeformedSphereOre.java @@ -1,6 +1,6 @@ package com.dfsek.terra.world.population.items.ores; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.math.noise.samplers.noise.simplex.OpenSimplex2Sampler; import com.dfsek.terra.api.math.vector.Vector3; @@ -8,7 +8,7 @@ import com.dfsek.terra.api.platform.block.Block; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.api.platform.world.Chunk; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; import java.util.Random; diff --git a/common/src/main/java/com/dfsek/terra/world/population/items/ores/Ore.java b/common/src/main/java/com/dfsek/terra/world/population/items/ores/Ore.java index 1115ce3c7..541a7dacf 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/items/ores/Ore.java +++ b/common/src/main/java/com/dfsek/terra/world/population/items/ores/Ore.java @@ -1,10 +1,10 @@ package com.dfsek.terra.world.population.items.ores; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.world.Chunk; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; import java.util.Random; diff --git a/common/src/main/java/com/dfsek/terra/world/population/items/ores/VanillaOre.java b/common/src/main/java/com/dfsek/terra/world/population/items/ores/VanillaOre.java index a1b9b3b65..798d7ff01 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/items/ores/VanillaOre.java +++ b/common/src/main/java/com/dfsek/terra/world/population/items/ores/VanillaOre.java @@ -1,13 +1,13 @@ package com.dfsek.terra.world.population.items.ores; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.Block; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.api.platform.world.Chunk; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; import net.jafama.FastMath; import java.util.Random; diff --git a/common/src/main/java/com/dfsek/terra/world/population/items/tree/TerraTree.java b/common/src/main/java/com/dfsek/terra/world/population/items/tree/TerraTree.java index a0abe79aa..07c4ae283 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/items/tree/TerraTree.java +++ b/common/src/main/java/com/dfsek/terra/world/population/items/tree/TerraTree.java @@ -1,10 +1,10 @@ package com.dfsek.terra.world.population.items.tree; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.structures.script.StructureScript; import com.dfsek.terra.api.structures.structure.Rotation; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.world.tree.Tree; import java.util.Random; diff --git a/common/src/main/java/com/dfsek/terra/world/population/items/tree/TreeLayer.java b/common/src/main/java/com/dfsek/terra/world/population/items/tree/TreeLayer.java index 71bb5b077..4f90b1be7 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/items/tree/TreeLayer.java +++ b/common/src/main/java/com/dfsek/terra/world/population/items/tree/TreeLayer.java @@ -1,12 +1,12 @@ package com.dfsek.terra.world.population.items.tree; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.math.noise.NoiseSampler; import com.dfsek.terra.api.math.vector.Vector2; import com.dfsek.terra.api.platform.block.Block; import com.dfsek.terra.api.platform.block.BlockFace; import com.dfsek.terra.api.platform.world.Chunk; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.util.world.PopulationUtil; import com.dfsek.terra.api.world.tree.Tree; import com.dfsek.terra.world.population.items.PlaceableLayer; diff --git a/common/src/test/java/biome/DistributionTest.java b/common/src/test/java/biome/DistributionTest.java index abecc1efd..a6217010a 100644 --- a/common/src/test/java/biome/DistributionTest.java +++ b/common/src/test/java/biome/DistributionTest.java @@ -9,14 +9,17 @@ import com.dfsek.tectonic.config.ValidatedConfigTemplate; import com.dfsek.tectonic.exception.ConfigException; import com.dfsek.tectonic.loading.ConfigLoader; import com.dfsek.tectonic.loading.TypeRegistry; -import com.dfsek.terra.addons.addon.TerraAddon; -import com.dfsek.terra.api.core.TerraPlugin; -import com.dfsek.terra.api.core.event.EventManager; -import com.dfsek.terra.api.math.ProbabilityCollection; +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.addons.TerraAddon; +import com.dfsek.terra.api.event.EventManager; import com.dfsek.terra.api.platform.handle.ItemHandle; import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.api.platform.world.Biome; import com.dfsek.terra.api.platform.world.World; +import com.dfsek.terra.api.registry.CheckedRegistry; +import com.dfsek.terra.api.registry.LockedRegistry; +import com.dfsek.terra.api.util.DebugLogger; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.util.seeded.NoiseSeeded; import com.dfsek.terra.api.world.biome.Generator; import com.dfsek.terra.api.world.biome.TerraBiome; @@ -34,9 +37,6 @@ import com.dfsek.terra.config.loaders.config.biome.templates.source.SingleBiomeP import com.dfsek.terra.config.loaders.config.sampler.NoiseSamplerBuilderLoader; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.config.templates.AbstractableTemplate; -import com.dfsek.terra.debug.DebugLogger; -import com.dfsek.terra.registry.CheckedRegistry; -import com.dfsek.terra.registry.LockedRegistry; import com.dfsek.terra.registry.config.BiomeRegistry; import com.dfsek.terra.registry.config.NoiseRegistry; import com.dfsek.terra.world.TerraWorld; diff --git a/common/src/test/java/biome/ImageTest.java b/common/src/test/java/biome/ImageTest.java index 8e52c0ce9..0569dcc69 100644 --- a/common/src/test/java/biome/ImageTest.java +++ b/common/src/test/java/biome/ImageTest.java @@ -7,9 +7,9 @@ import com.dfsek.tectonic.annotations.Value; import com.dfsek.tectonic.config.ConfigTemplate; import com.dfsek.tectonic.config.ValidatedConfigTemplate; import com.dfsek.tectonic.exception.ConfigException; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.platform.world.Biome; import com.dfsek.terra.api.platform.world.World; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.world.biome.Generator; import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.provider.BiomeProvider; diff --git a/common/src/test/java/noise/ColorConfigTemplate.java b/common/src/test/java/noise/ColorConfigTemplate.java index 0a8c88556..ddc3ba9f0 100644 --- a/common/src/test/java/noise/ColorConfigTemplate.java +++ b/common/src/test/java/noise/ColorConfigTemplate.java @@ -3,7 +3,7 @@ package noise; import com.dfsek.tectonic.annotations.Default; import com.dfsek.tectonic.annotations.Value; import com.dfsek.tectonic.config.ConfigTemplate; -import com.dfsek.terra.api.math.ProbabilityCollection; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; public class ColorConfigTemplate implements ConfigTemplate { @Value("colors") diff --git a/common/src/test/java/noise/NoiseTool.java b/common/src/test/java/noise/NoiseTool.java index ef518aa1b..a335a88de 100644 --- a/common/src/test/java/noise/NoiseTool.java +++ b/common/src/test/java/noise/NoiseTool.java @@ -2,8 +2,8 @@ package noise; import com.dfsek.tectonic.exception.ConfigException; import com.dfsek.tectonic.loading.ConfigLoader; -import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.noise.NoiseSampler; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.util.seeded.NoiseSeeded; import com.dfsek.terra.config.GenericLoaders; import com.dfsek.terra.config.fileloaders.FolderLoader; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitPlayer.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitPlayer.java index 0251d2ada..162e41131 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitPlayer.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitPlayer.java @@ -1,7 +1,7 @@ package com.dfsek.terra.bukkit; import com.dfsek.terra.api.math.vector.Location; -import com.dfsek.terra.api.platform.Player; +import com.dfsek.terra.api.platform.entity.Player; import com.dfsek.terra.bukkit.world.BukkitAdapter; public class BukkitPlayer implements Player { diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java index 1d3b70dcb..5f8e99ee5 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java @@ -1,19 +1,22 @@ package com.dfsek.terra.bukkit; import com.dfsek.tectonic.loading.TypeRegistry; -import com.dfsek.terra.addons.addon.TerraAddon; -import com.dfsek.terra.addons.annotations.Addon; -import com.dfsek.terra.addons.annotations.Author; -import com.dfsek.terra.addons.annotations.Version; -import com.dfsek.terra.api.core.TerraPlugin; -import com.dfsek.terra.api.core.event.EventManager; -import com.dfsek.terra.api.core.event.TerraEventManager; +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.addons.TerraAddon; +import com.dfsek.terra.api.addons.annotations.Addon; +import com.dfsek.terra.api.addons.annotations.Author; +import com.dfsek.terra.api.addons.annotations.Version; +import com.dfsek.terra.api.event.EventManager; +import com.dfsek.terra.api.event.TerraEventManager; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.platform.handle.ItemHandle; import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.api.platform.world.Biome; import com.dfsek.terra.api.platform.world.World; +import com.dfsek.terra.api.registry.CheckedRegistry; +import com.dfsek.terra.api.registry.LockedRegistry; +import com.dfsek.terra.api.util.DebugLogger; import com.dfsek.terra.api.world.generation.TerraChunkGenerator; import com.dfsek.terra.bukkit.command.command.TerraCommand; import com.dfsek.terra.bukkit.command.command.structure.LocateCommand; @@ -31,9 +34,6 @@ import com.dfsek.terra.config.PluginConfig; import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.Language; import com.dfsek.terra.config.pack.ConfigPack; -import com.dfsek.terra.debug.DebugLogger; -import com.dfsek.terra.registry.CheckedRegistry; -import com.dfsek.terra.registry.LockedRegistry; import com.dfsek.terra.registry.master.AddonRegistry; import com.dfsek.terra.registry.master.ConfigRegistry; import com.dfsek.terra.world.TerraWorld; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/Command.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/Command.java index 730389d76..93b1435ab 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/Command.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/Command.java @@ -1,6 +1,6 @@ package com.dfsek.terra.bukkit.command; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.bukkit.BukkitCommandSender; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/PacksCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/PacksCommand.java index 0cdea2157..1bdd037a1 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/PacksCommand.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/PacksCommand.java @@ -1,12 +1,11 @@ package com.dfsek.terra.bukkit.command.command; +import com.dfsek.terra.api.registry.CheckedRegistry; import com.dfsek.terra.bukkit.BukkitCommandSender; import com.dfsek.terra.bukkit.command.Command; import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.config.pack.ConfigPackTemplate; -import com.dfsek.terra.registry.CheckedRegistry; -import com.dfsek.terra.registry.master.ConfigRegistry; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/TerraCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/TerraCommand.java index f844b82e3..639a63345 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/TerraCommand.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/TerraCommand.java @@ -1,6 +1,6 @@ package com.dfsek.terra.bukkit.command.command; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.bukkit.BukkitCommandSender; import com.dfsek.terra.bukkit.command.Command; import com.dfsek.terra.bukkit.command.command.biome.BiomeCommand; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeLocateCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeLocateCommand.java index 07b07e451..a52a7c83b 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeLocateCommand.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeLocateCommand.java @@ -2,7 +2,7 @@ package com.dfsek.terra.bukkit.command.command.biome; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.world.biome.TerraBiome; -import com.dfsek.terra.async.AsyncBiomeFinder; +import com.dfsek.terra.api.world.locate.AsyncBiomeFinder; import com.dfsek.terra.bukkit.TerraBukkitPlugin; import com.dfsek.terra.bukkit.command.WorldCommand; import com.dfsek.terra.bukkit.world.BukkitAdapter; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/LocateCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/LocateCommand.java index 933895da6..e23c95bbc 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/LocateCommand.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/LocateCommand.java @@ -1,7 +1,7 @@ package com.dfsek.terra.bukkit.command.command.structure; import com.dfsek.terra.api.math.vector.Vector3; -import com.dfsek.terra.async.AsyncStructureFinder; +import com.dfsek.terra.api.world.locate.AsyncStructureFinder; import com.dfsek.terra.bukkit.TerraBukkitPlugin; import com.dfsek.terra.bukkit.command.WorldCommand; import com.dfsek.terra.bukkit.world.BukkitAdapter; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java index 8c0e5bb09..20e283332 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java @@ -1,6 +1,6 @@ package com.dfsek.terra.bukkit.generator; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.world.generation.TerraBlockPopulator; import com.dfsek.terra.api.world.generation.TerraChunkGenerator; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/CommonListener.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/CommonListener.java index 753b785c9..98b449536 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/CommonListener.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/CommonListener.java @@ -1,6 +1,6 @@ package com.dfsek.terra.bukkit.listeners; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.transform.MapTransform; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/PaperListener.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/PaperListener.java index 01d298372..fd79cde9b 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/PaperListener.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/PaperListener.java @@ -1,7 +1,7 @@ package com.dfsek.terra.bukkit.listeners; -import com.dfsek.terra.api.core.TerraPlugin; -import com.dfsek.terra.async.AsyncStructureFinder; +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.world.locate.AsyncStructureFinder; import com.dfsek.terra.bukkit.world.BukkitAdapter; import com.dfsek.terra.world.TerraWorld; import com.dfsek.terra.world.population.items.TerraStructure; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/SpigotListener.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/SpigotListener.java index e3bfa8642..01748e1c5 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/SpigotListener.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/SpigotListener.java @@ -1,7 +1,7 @@ package com.dfsek.terra.bukkit.listeners; -import com.dfsek.terra.api.core.TerraPlugin; -import com.dfsek.terra.async.AsyncStructureFinder; +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.world.locate.AsyncStructureFinder; import com.dfsek.terra.bukkit.world.BukkitAdapter; import com.dfsek.terra.world.TerraWorld; import com.dfsek.terra.world.population.items.TerraStructure; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/TerraListener.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/TerraListener.java index edb09bd22..78615d036 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/TerraListener.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/TerraListener.java @@ -1,10 +1,10 @@ package com.dfsek.terra.bukkit.listeners; -import com.dfsek.terra.api.core.TerraPlugin; -import com.dfsek.terra.api.core.event.EventListener; -import com.dfsek.terra.api.core.event.annotations.Global; -import com.dfsek.terra.api.core.event.annotations.Priority; -import com.dfsek.terra.api.core.event.events.config.ConfigPackPreLoadEvent; +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.event.EventListener; +import com.dfsek.terra.api.event.annotations.Global; +import com.dfsek.terra.api.event.annotations.Priority; +import com.dfsek.terra.api.event.events.config.ConfigPackPreLoadEvent; import com.dfsek.terra.bukkit.world.BukkitAdapter; import com.dfsek.terra.bukkit.world.BukkitTree; import com.dfsek.terra.registry.exception.DuplicateEntryException; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/population/PopulationManager.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/population/PopulationManager.java index 99761067e..fedefbaab 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/population/PopulationManager.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/population/PopulationManager.java @@ -1,6 +1,6 @@ package com.dfsek.terra.bukkit.population; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.util.FastRandom; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitAdapter.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitAdapter.java index 737c56bdb..643488ccb 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitAdapter.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitAdapter.java @@ -377,11 +377,11 @@ public final class BukkitAdapter { return ((BukkitEnchantment) enchantment).getHandle(); } - public static Player adapt(com.dfsek.terra.api.platform.Player player) { + public static Player adapt(com.dfsek.terra.api.platform.entity.Player player) { return ((BukkitPlayer) player).getHandle(); } - public static com.dfsek.terra.api.platform.Player adapt(Player player) { + public static com.dfsek.terra.api.platform.entity.Player adapt(Player player) { return new BukkitPlayer(player); } } diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitTree.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitTree.java index ecf87d1e9..69f1e578c 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitTree.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitTree.java @@ -1,10 +1,10 @@ package com.dfsek.terra.bukkit.world; -import com.dfsek.terra.api.core.TerraPlugin; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.platform.handle.WorldHandle; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.world.tree.Tree; import org.bukkit.TreeType; diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index b08cad22f..3bb773ee3 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -1,25 +1,27 @@ package com.dfsek.terra.fabric; import com.dfsek.tectonic.loading.TypeRegistry; -import com.dfsek.terra.addons.addon.TerraAddon; -import com.dfsek.terra.api.core.TerraPlugin; -import com.dfsek.terra.api.core.event.EventManager; -import com.dfsek.terra.api.core.event.TerraEventManager; +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.addons.TerraAddon; +import com.dfsek.terra.api.event.EventManager; +import com.dfsek.terra.api.event.TerraEventManager; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.platform.handle.ItemHandle; import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.api.platform.world.World; +import com.dfsek.terra.api.registry.CheckedRegistry; +import com.dfsek.terra.api.registry.LockedRegistry; import com.dfsek.terra.api.transform.MapTransform; import com.dfsek.terra.api.transform.NotNullValidator; import com.dfsek.terra.api.transform.Transformer; +import com.dfsek.terra.api.util.DebugLogger; import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.config.GenericLoaders; import com.dfsek.terra.config.PluginConfig; import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.Language; import com.dfsek.terra.config.pack.ConfigPack; -import com.dfsek.terra.debug.DebugLogger; import com.dfsek.terra.fabric.inventory.FabricItemHandle; import com.dfsek.terra.fabric.mixin.GeneratorTypeAccessor; import com.dfsek.terra.fabric.world.FabricBiome; @@ -27,8 +29,6 @@ import com.dfsek.terra.fabric.world.FabricWorldHandle; import com.dfsek.terra.fabric.world.TerraBiomeSource; import com.dfsek.terra.fabric.world.features.PopulatorFeature; import com.dfsek.terra.fabric.world.generator.FabricChunkGeneratorWrapper; -import com.dfsek.terra.registry.CheckedRegistry; -import com.dfsek.terra.registry.LockedRegistry; import com.dfsek.terra.registry.master.AddonRegistry; import com.dfsek.terra.registry.master.ConfigRegistry; import com.dfsek.terra.world.TerraWorld; diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricTree.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricTree.java index b5bbabccc..53d727461 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricTree.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricTree.java @@ -2,7 +2,7 @@ package com.dfsek.terra.fabric.world; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.MaterialData; -import com.dfsek.terra.api.util.world.MaterialSet; +import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.world.tree.Tree; import com.dfsek.terra.fabric.TerraFabricPlugin; import com.dfsek.terra.fabric.world.generator.FabricChunkGenerator; diff --git a/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java b/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java index 9257c40ca..d917f5fe9 100644 --- a/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java +++ b/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java @@ -1,26 +1,26 @@ package com.dfsek.terra; import com.dfsek.tectonic.loading.TypeRegistry; -import com.dfsek.terra.addons.addon.TerraAddon; -import com.dfsek.terra.api.core.TerraPlugin; -import com.dfsek.terra.api.core.event.EventManager; -import com.dfsek.terra.api.core.event.TerraEventManager; +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.addons.TerraAddon; +import com.dfsek.terra.api.event.EventManager; +import com.dfsek.terra.api.event.TerraEventManager; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.platform.handle.ItemHandle; import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.api.platform.world.Biome; import com.dfsek.terra.api.platform.world.World; +import com.dfsek.terra.api.registry.CheckedRegistry; +import com.dfsek.terra.api.registry.LockedRegistry; +import com.dfsek.terra.api.util.DebugLogger; import com.dfsek.terra.config.GenericLoaders; import com.dfsek.terra.config.PluginConfig; import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.Language; import com.dfsek.terra.config.pack.ConfigPack; -import com.dfsek.terra.debug.DebugLogger; import com.dfsek.terra.platform.RawBiome; import com.dfsek.terra.platform.RawWorldHandle; -import com.dfsek.terra.registry.CheckedRegistry; -import com.dfsek.terra.registry.LockedRegistry; import com.dfsek.terra.registry.master.AddonRegistry; import com.dfsek.terra.registry.master.ConfigRegistry; import com.dfsek.terra.world.TerraWorld; From 358bd350b59558a00c723838314fe5df6c2be8ef Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 22 Feb 2021 19:47:15 -0700 Subject: [PATCH 14/95] MaterialData is gone --- .../dfsek/terra/api/platform/block/Block.java | 2 +- .../terra/api/platform/block/BlockData.java | 7 ++- .../terra/api/platform/block/BlockType.java | 9 +++ .../api/platform/block/MaterialData.java | 17 ----- .../terra/api/platform/handle/ItemHandle.java | 6 +- .../api/platform/handle/WorldHandle.java | 5 -- .../terra/api/platform/inventory/Item.java | 12 ++++ .../api/platform/inventory/ItemStack.java | 3 +- .../terra/api/structures/loot/Entry.java | 10 ++- .../api/util/collections/MaterialSet.java | 20 ++++-- .../com/dfsek/terra/api/world/tree/Tree.java | 5 +- .../api/world/tree/fractal/trees/Cactus.java | 4 +- .../world/tree/fractal/trees/IceSpike.java | 8 +-- .../api/world/tree/fractal/trees/OakTree.java | 4 +- .../tree/fractal/trees/ShatteredPillar.java | 2 +- .../tree/fractal/trees/ShatteredTree.java | 2 +- .../fractal/trees/SmallShatteredPillar.java | 2 +- .../fractal/trees/SmallShatteredTree.java | 2 +- .../world/tree/fractal/trees/SpruceTree.java | 4 +- .../dfsek/terra/carving/CarverPalette.java | 4 +- .../dfsek/terra/config/GenericLoaders.java | 2 + .../config/loaders/MaterialSetLoader.java | 4 +- .../com/dfsek/terra/config/loaders/Types.java | 8 --- .../terra/config/templates/BiomeTemplate.java | 10 +-- .../config/templates/CarverTemplate.java | 6 +- .../terra/registry/config/FloraRegistry.java | 5 +- .../terra/registry/config/TreeRegistry.java | 5 +- .../generators/DefaultChunkGenerator3D.java | 32 +++++----- .../terra/world/population/CavePopulator.java | 43 ++++++------- .../dfsek/terra/bukkit/TerraBukkitPlugin.java | 2 - .../bukkit/handles/BukkitItemHandle.java | 11 ++-- .../bukkit/handles/BukkitWorldHandle.java | 13 ---- .../terra/bukkit/world/BukkitAdapter.java | 21 +++++++ .../dfsek/terra/bukkit/world/BukkitTree.java | 18 +++--- .../terra/bukkit/world/block/BukkitBlock.java | 6 +- .../world/block/BukkitBlockTypeAndItem.java | 52 +++++++++++++++ .../world/block/BukkitMaterialData.java | 62 ------------------ .../world/block/data/BukkitBlockData.java | 17 +++-- .../world/inventory/BukkitItemStack.java | 8 +-- .../dfsek/terra/fabric/TerraFabricPlugin.java | 2 - .../fabric/inventory/FabricItemHandle.java | 6 +- .../fabric/inventory/FabricItemStack.java | 4 +- .../dfsek/terra/fabric/world/FabricTree.java | 8 +-- .../terra/fabric/world/FabricWorldHandle.java | 12 ---- .../terra/fabric/world/block/FabricBlock.java | 8 +-- .../fabric/world/block/FabricBlockData.java | 15 +++-- .../world/block/FabricMaterialData.java | 63 ------------------- .../com/dfsek/terra/StandalonePlugin.java | 2 - .../java/com/dfsek/terra/platform/Data.java | 35 ++++------- .../com/dfsek/terra/platform/DirectBlock.java | 4 +- .../com/dfsek/terra/platform/RawTree.java | 8 +-- .../dfsek/terra/platform/RawWorldHandle.java | 11 ---- 52 files changed, 266 insertions(+), 365 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/api/platform/block/BlockType.java delete mode 100644 common/src/main/java/com/dfsek/terra/api/platform/block/MaterialData.java create mode 100644 common/src/main/java/com/dfsek/terra/api/platform/inventory/Item.java create mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/BukkitBlockTypeAndItem.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/BukkitMaterialData.java delete mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricMaterialData.java diff --git a/common/src/main/java/com/dfsek/terra/api/platform/block/Block.java b/common/src/main/java/com/dfsek/terra/api/platform/block/Block.java index 47242d6e2..becb5d436 100644 --- a/common/src/main/java/com/dfsek/terra/api/platform/block/Block.java +++ b/common/src/main/java/com/dfsek/terra/api/platform/block/Block.java @@ -19,7 +19,7 @@ public interface Block extends Handle { Location getLocation(); - MaterialData getType(); + BlockType getType(); int getX(); diff --git a/common/src/main/java/com/dfsek/terra/api/platform/block/BlockData.java b/common/src/main/java/com/dfsek/terra/api/platform/block/BlockData.java index d58979fa6..fc7df1172 100644 --- a/common/src/main/java/com/dfsek/terra/api/platform/block/BlockData.java +++ b/common/src/main/java/com/dfsek/terra/api/platform/block/BlockData.java @@ -3,11 +3,14 @@ package com.dfsek.terra.api.platform.block; import com.dfsek.terra.api.platform.Handle; public interface BlockData extends Cloneable, Handle { - MaterialData getMaterial(); - boolean matches(MaterialData materialData); + BlockType getBlockType(); + + boolean matches(BlockData other); BlockData clone(); String getAsString(); + + boolean isAir(); } diff --git a/common/src/main/java/com/dfsek/terra/api/platform/block/BlockType.java b/common/src/main/java/com/dfsek/terra/api/platform/block/BlockType.java new file mode 100644 index 000000000..d7c6c160d --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/platform/block/BlockType.java @@ -0,0 +1,9 @@ +package com.dfsek.terra.api.platform.block; + +import com.dfsek.terra.api.platform.Handle; + +public interface BlockType extends Handle { + BlockData getDefaultData(); + + boolean isSolid(); +} diff --git a/common/src/main/java/com/dfsek/terra/api/platform/block/MaterialData.java b/common/src/main/java/com/dfsek/terra/api/platform/block/MaterialData.java deleted file mode 100644 index c5f3037b1..000000000 --- a/common/src/main/java/com/dfsek/terra/api/platform/block/MaterialData.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.dfsek.terra.api.platform.block; - -import com.dfsek.terra.api.platform.Handle; - -public interface MaterialData extends Handle { - boolean matches(MaterialData other); - - boolean matches(BlockData other); - - boolean isSolid(); - - boolean isAir(); - - double getMaxDurability(); - - BlockData createBlockData(); -} diff --git a/common/src/main/java/com/dfsek/terra/api/platform/handle/ItemHandle.java b/common/src/main/java/com/dfsek/terra/api/platform/handle/ItemHandle.java index fe2fe39d0..1c76e225d 100644 --- a/common/src/main/java/com/dfsek/terra/api/platform/handle/ItemHandle.java +++ b/common/src/main/java/com/dfsek/terra/api/platform/handle/ItemHandle.java @@ -1,13 +1,13 @@ package com.dfsek.terra.api.platform.handle; -import com.dfsek.terra.api.platform.block.MaterialData; -import com.dfsek.terra.api.platform.inventory.ItemStack; +import com.dfsek.terra.api.platform.inventory.Item; import com.dfsek.terra.api.platform.inventory.item.Enchantment; import java.util.Set; public interface ItemHandle { - ItemStack newItemStack(MaterialData material, int amount); + + Item createItem(String data); Enchantment getEnchantment(String id); diff --git a/common/src/main/java/com/dfsek/terra/api/platform/handle/WorldHandle.java b/common/src/main/java/com/dfsek/terra/api/platform/handle/WorldHandle.java index 373d44f15..8e6f4e251 100644 --- a/common/src/main/java/com/dfsek/terra/api/platform/handle/WorldHandle.java +++ b/common/src/main/java/com/dfsek/terra/api/platform/handle/WorldHandle.java @@ -2,7 +2,6 @@ package com.dfsek.terra.api.platform.handle; import com.dfsek.terra.api.platform.block.Block; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.platform.entity.EntityType; /** @@ -13,11 +12,7 @@ public interface WorldHandle { BlockData getBlockData(Block block); - MaterialData getType(Block block); - BlockData createBlockData(String data); - MaterialData createMaterialData(String data); - EntityType getEntity(String id); } diff --git a/common/src/main/java/com/dfsek/terra/api/platform/inventory/Item.java b/common/src/main/java/com/dfsek/terra/api/platform/inventory/Item.java new file mode 100644 index 000000000..4fa70ede3 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/platform/inventory/Item.java @@ -0,0 +1,12 @@ +package com.dfsek.terra.api.platform.inventory; + +import com.dfsek.terra.api.platform.Handle; + +/** + * An inventory item. + */ +public interface Item extends Handle { + ItemStack newItemStack(int amount); + + double getMaxDurability(); +} diff --git a/common/src/main/java/com/dfsek/terra/api/platform/inventory/ItemStack.java b/common/src/main/java/com/dfsek/terra/api/platform/inventory/ItemStack.java index 95b1d299a..b480f6c5a 100644 --- a/common/src/main/java/com/dfsek/terra/api/platform/inventory/ItemStack.java +++ b/common/src/main/java/com/dfsek/terra/api/platform/inventory/ItemStack.java @@ -1,7 +1,6 @@ package com.dfsek.terra.api.platform.inventory; import com.dfsek.terra.api.platform.Handle; -import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.platform.inventory.item.ItemMeta; public interface ItemStack extends Handle, Cloneable { @@ -9,7 +8,7 @@ public interface ItemStack extends Handle, Cloneable { void setAmount(int i); - MaterialData getType(); + Item getType(); ItemStack clone(); diff --git a/common/src/main/java/com/dfsek/terra/api/structures/loot/Entry.java b/common/src/main/java/com/dfsek/terra/api/structures/loot/Entry.java index 4eb506c1d..81c48aab1 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/loot/Entry.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/loot/Entry.java @@ -1,7 +1,7 @@ package com.dfsek.terra.api.structures.loot; import com.dfsek.terra.api.TerraPlugin; -import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.platform.inventory.Item; import com.dfsek.terra.api.platform.inventory.ItemStack; import com.dfsek.terra.api.structures.loot.functions.AmountFunction; import com.dfsek.terra.api.structures.loot.functions.DamageFunction; @@ -19,10 +19,9 @@ import java.util.Random; * Representation of a single item entry within a Loot Table pool. */ public class Entry { - private final MaterialData item; + private final Item item; private final long weight; private final List functions = new GlueList<>(); - private final TerraPlugin main; /** * Instantiates an Entry from a JSON representation. @@ -30,9 +29,8 @@ public class Entry { * @param entry The JSON Object to instantiate from. */ public Entry(JSONObject entry, TerraPlugin main) { - this.main = main; String id = entry.get("name").toString(); - this.item = main.getWorldHandle().createMaterialData(id); + this.item = main.getItemHandle().createItem(id); long weight1; try { @@ -85,7 +83,7 @@ public class Entry { * @return ItemStack - The ItemStack with all functions applied. */ public ItemStack getItem(Random r) { - ItemStack item = main.getItemHandle().newItemStack(this.item, 1); + ItemStack item = this.item.newItemStack(1); for(LootFunction f : functions) { item = f.apply(item, r); } diff --git a/common/src/main/java/com/dfsek/terra/api/util/collections/MaterialSet.java b/common/src/main/java/com/dfsek/terra/api/util/collections/MaterialSet.java index 44b9b16f6..77099137e 100644 --- a/common/src/main/java/com/dfsek/terra/api/util/collections/MaterialSet.java +++ b/common/src/main/java/com/dfsek/terra/api/util/collections/MaterialSet.java @@ -1,27 +1,37 @@ package com.dfsek.terra.api.util.collections; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.platform.block.BlockType; import java.util.Arrays; import java.util.HashSet; -public class MaterialSet extends HashSet { +public class MaterialSet extends HashSet { private static final long serialVersionUID = 3056512763631017301L; - public static MaterialSet singleton(MaterialData material) { + public static MaterialSet singleton(BlockType material) { MaterialSet set = new MaterialSet(); set.add(material); return set; } - public static MaterialSet get(MaterialData... materials) { + public static MaterialSet get(BlockType... materials) { MaterialSet set = new MaterialSet(); set.addAll(Arrays.asList(materials)); return set; } + public static MaterialSet get(BlockData... materials) { + MaterialSet set = new MaterialSet(); + Arrays.stream(materials).forEach(set::add); + return set; + } + + public static MaterialSet empty() { + return new MaterialSet(); + } + private void add(BlockData data) { - add(data.getMaterial()); + add(data.getBlockType()); } } diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/Tree.java b/common/src/main/java/com/dfsek/terra/api/world/tree/Tree.java index 47221fd20..0e14dd176 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/Tree.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/Tree.java @@ -2,13 +2,12 @@ package com.dfsek.terra.api.world.tree; import com.dfsek.terra.api.math.vector.Location; -import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.util.collections.MaterialSet; import java.util.Random; -import java.util.Set; public interface Tree { boolean plant(Location l, Random r); - Set getSpawnable(); + MaterialSet getSpawnable(); } diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/Cactus.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/Cactus.java index 5b56ea7f6..ef5f29197 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/Cactus.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/Cactus.java @@ -11,8 +11,8 @@ import java.util.Random; public class Cactus extends FractalTree { @Override public MaterialSet getSpawnable() { - return MaterialSet.get(main.getWorldHandle().createMaterialData("minecraft:sand"), - main.getWorldHandle().createMaterialData("minecraft:red_sand")); + return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:sand"), + main.getWorldHandle().createBlockData("minecraft:red_sand")); } diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/IceSpike.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/IceSpike.java index dfa231326..716313df4 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/IceSpike.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/IceSpike.java @@ -19,10 +19,10 @@ public class IceSpike extends FractalTree { @Override public MaterialSet getSpawnable() { - return MaterialSet.get(main.getWorldHandle().createMaterialData("minecraft:stone"), - main.getWorldHandle().createMaterialData("minecraft:gravel"), - main.getWorldHandle().createMaterialData("minecraft:snow_block"), - main.getWorldHandle().createMaterialData("minecraft:grass_block")); + return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:stone"), + main.getWorldHandle().createBlockData("minecraft:gravel"), + main.getWorldHandle().createBlockData("minecraft:snow_block"), + main.getWorldHandle().createBlockData("minecraft:grass_block")); } /** diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/OakTree.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/OakTree.java index c86a2620f..ced1db454 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/OakTree.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/OakTree.java @@ -17,8 +17,8 @@ public class OakTree extends FractalTree { @Override public MaterialSet getSpawnable() { - return MaterialSet.get(main.getWorldHandle().createMaterialData("minecraft:podzol"), - main.getWorldHandle().createMaterialData("minecraft:grass_block")); + return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:podzol"), + main.getWorldHandle().createBlockData("minecraft:grass_block")); } /** diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredPillar.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredPillar.java index 225947dca..35c24bff6 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredPillar.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredPillar.java @@ -12,7 +12,7 @@ public class ShatteredPillar extends FractalTree { @Override public MaterialSet getSpawnable() { - return MaterialSet.get(main.getWorldHandle().createMaterialData("minecraft:end_stone")); + return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:end_stone")); } /** diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredTree.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredTree.java index 38425f989..06dded13b 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredTree.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/ShatteredTree.java @@ -20,7 +20,7 @@ public class ShatteredTree extends FractalTree { @Override public MaterialSet getSpawnable() { - return MaterialSet.get(main.getWorldHandle().createMaterialData("minecraft:end_stone")); + return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:end_stone")); } /** diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredPillar.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredPillar.java index a1465ef05..35825e7fe 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredPillar.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredPillar.java @@ -12,7 +12,7 @@ public class SmallShatteredPillar extends FractalTree { @Override public MaterialSet getSpawnable() { - return MaterialSet.get(main.getWorldHandle().createMaterialData("minecraft:end_stone")); + return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:end_stone")); } /** diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredTree.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredTree.java index a5109ba9d..6148d78c4 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredTree.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SmallShatteredTree.java @@ -20,7 +20,7 @@ public class SmallShatteredTree extends FractalTree { @Override public MaterialSet getSpawnable() { - return MaterialSet.get(main.getWorldHandle().createMaterialData("minecraft:end_stone")); + return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:end_stone")); } /** diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SpruceTree.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SpruceTree.java index 5f2f91765..d0db1dea9 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SpruceTree.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/SpruceTree.java @@ -16,8 +16,8 @@ public class SpruceTree extends FractalTree { @Override public MaterialSet getSpawnable() { - return MaterialSet.get(main.getWorldHandle().createMaterialData("minecraft:podzol"), - main.getWorldHandle().createMaterialData("minecraft:grass_block")); + return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:podzol"), + main.getWorldHandle().createBlockData("minecraft:grass_block")); } /** diff --git a/common/src/main/java/com/dfsek/terra/carving/CarverPalette.java b/common/src/main/java/com/dfsek/terra/carving/CarverPalette.java index c0c942bcd..a15d1710c 100644 --- a/common/src/main/java/com/dfsek/terra/carving/CarverPalette.java +++ b/common/src/main/java/com/dfsek/terra/carving/CarverPalette.java @@ -1,7 +1,7 @@ package com.dfsek.terra.carving; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.platform.block.BlockType; import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.util.collections.ProbabilityCollection; @@ -29,7 +29,7 @@ public class CarverPalette { return layers[y]; } - public boolean canReplace(MaterialData material) { + public boolean canReplace(BlockType material) { return blacklist != replace.contains(material); } diff --git a/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java b/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java index b848f0fbb..0e3c7b635 100644 --- a/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java +++ b/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java @@ -8,6 +8,7 @@ import com.dfsek.terra.api.math.GridSpawn; import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.math.noise.samplers.ImageSampler; import com.dfsek.terra.api.math.noise.samplers.noise.CellularSampler; +import com.dfsek.terra.api.platform.block.BlockType; import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.util.seeded.SourceSeeded; @@ -92,6 +93,7 @@ public class GenericLoaders implements LoaderRegistrar { .registerLoader(SourceSeeded.class, new SourceBuilderLoader()) .registerLoader(StageSeeded.class, new StageBuilderLoader()) .registerLoader(TerraAddon.class, main.getAddons()) + .registerLoader(BlockType.class, (t, object, cf) -> main.getWorldHandle().createBlockData((String) object).getBlockType()) .registerLoader(BiomeProvider.BiomeProviderBuilder.class, new BiomeProviderBuilderLoader()) .registerLoader(ImageSampler.Channel.class, (t, object, cf) -> ImageSampler.Channel.valueOf((String) object)) .registerLoader(BiomeProvider.Type.class, (t, object, cf) -> BiomeProvider.Type.valueOf((String) object)) diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/MaterialSetLoader.java b/common/src/main/java/com/dfsek/terra/config/loaders/MaterialSetLoader.java index d4d7b5c01..a98ca9837 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/MaterialSetLoader.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/MaterialSetLoader.java @@ -3,7 +3,7 @@ package com.dfsek.terra.config.loaders; import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; import com.dfsek.tectonic.loading.TypeLoader; -import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.platform.block.BlockType; import com.dfsek.terra.api.util.collections.MaterialSet; import java.lang.reflect.Type; @@ -18,7 +18,7 @@ public class MaterialSetLoader implements TypeLoader { for(String string : stringData) { try { - set.add(configLoader.loadClass(MaterialData.class, string)); + set.add(configLoader.loadClass(BlockType.class, string)); } catch(NullPointerException e) { throw new LoadException("Invalid data identifier \"" + string + "\"", e); } diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/Types.java b/common/src/main/java/com/dfsek/terra/config/loaders/Types.java index 9c91e598a..255c652c0 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/Types.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/Types.java @@ -1,7 +1,6 @@ package com.dfsek.terra.config.loaders; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.flora.Flora; @@ -10,15 +9,12 @@ import com.dfsek.terra.api.world.tree.Tree; import java.lang.reflect.Type; import java.util.Map; -import java.util.Set; /** * Class to hold Type instances for types with generics. */ @SuppressWarnings("unused") public final class Types { - public static final Type MATERIAL_SET_TYPE; - public static final Type MATERIAL_PROBABILITY_COLLECTION_TYPE; public static final Type BLOCK_DATA_PALETTE_TYPE; public static final Type BLOCK_DATA_PROBABILITY_COLLECTION_TYPE; public static final Type FLORA_PROBABILITY_COLLECTION_TYPE; @@ -27,8 +23,6 @@ public final class Types { public static final Type TERRA_BIOME_TERRA_BIOME_PROBABILITY_COLLECTION_MAP; static { - MATERIAL_SET_TYPE = getType("materialSet"); - MATERIAL_PROBABILITY_COLLECTION_TYPE = getType("materialProbabilityCollection"); BLOCK_DATA_PALETTE_TYPE = getType("blockDataPalette"); BLOCK_DATA_PROBABILITY_COLLECTION_TYPE = getType("blockDataProbabilityCollection"); FLORA_PROBABILITY_COLLECTION_TYPE = getType("floraProbabilityCollection"); @@ -37,9 +31,7 @@ public final class Types { TERRA_BIOME_TERRA_BIOME_PROBABILITY_COLLECTION_MAP = getType("terraBiomeProbabilityCollectionMap"); } - private Set materialSet; private Palette blockDataPalette; - private ProbabilityCollection materialProbabilityCollection; private ProbabilityCollection blockDataProbabilityCollection; private ProbabilityCollection floraProbabilityCollection; private ProbabilityCollection treeProbabilityCollection; diff --git a/common/src/main/java/com/dfsek/terra/config/templates/BiomeTemplate.java b/common/src/main/java/com/dfsek/terra/config/templates/BiomeTemplate.java index a7aa92403..42bbdb452 100644 --- a/common/src/main/java/com/dfsek/terra/config/templates/BiomeTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/templates/BiomeTemplate.java @@ -14,7 +14,7 @@ import com.dfsek.terra.api.math.noise.samplers.noise.ConstantSampler; import com.dfsek.terra.api.math.paralithic.BlankFunction; import com.dfsek.terra.api.math.paralithic.defined.UserDefinedFunction; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.platform.block.BlockType; import com.dfsek.terra.api.platform.world.Biome; import com.dfsek.terra.api.util.GlueList; import com.dfsek.terra.api.util.collections.ProbabilityCollection; @@ -158,12 +158,12 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf @Value("slabs.palettes") @Abstractable @Default - private Map> slabPalettes; + private Map> slabPalettes; @Value("slabs.stair-palettes") @Abstractable @Default - private Map> stairPalettes; + private Map> stairPalettes; @Value("slant.threshold") @Abstractable @@ -237,11 +237,11 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf return doSlabs; } - public Map> getSlabPalettes() { + public Map> getSlabPalettes() { return slabPalettes; } - public Map> getStairPalettes() { + public Map> getStairPalettes() { return stairPalettes; } diff --git a/common/src/main/java/com/dfsek/terra/config/templates/CarverTemplate.java b/common/src/main/java/com/dfsek/terra/config/templates/CarverTemplate.java index 989fe3919..96cdbde03 100644 --- a/common/src/main/java/com/dfsek/terra/config/templates/CarverTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/templates/CarverTemplate.java @@ -4,7 +4,7 @@ import com.dfsek.tectonic.annotations.Abstractable; import com.dfsek.tectonic.annotations.Default; import com.dfsek.tectonic.annotations.Value; import com.dfsek.terra.api.math.Range; -import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.platform.block.BlockType; import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.carving.CarverPalette; @@ -104,7 +104,7 @@ public class CarverTemplate extends AbstractableTemplate { @Value("shift") @Abstractable @Default - private Map shift = new HashMap<>(); + private Map shift = new HashMap<>(); @Value("update") @Abstractable @@ -187,7 +187,7 @@ public class CarverTemplate extends AbstractableTemplate { return inner; } - public Map getShift() { + public Map getShift() { return shift; } diff --git a/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java index c06b8b0d4..5a3ce612b 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java @@ -2,7 +2,6 @@ package com.dfsek.terra.registry.config; import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.world.flora.Flora; import com.dfsek.terra.registry.OpenRegistry; @@ -52,8 +51,8 @@ public class FloraRegistry extends OpenRegistry { addItem("BROWN_MUSHROOM", () -> new ConstantFlora(mushroom, Collections.singletonList(data("minecraft:brown_mushroom")))); } - private MaterialData create(String s) { - return main.getWorldHandle().createMaterialData(s); + private BlockData create(String s) { + return main.getWorldHandle().createBlockData(s); } private void addItem(String id, Callable flora) { diff --git a/common/src/main/java/com/dfsek/terra/registry/config/TreeRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/TreeRegistry.java index 05a29d849..fe5cddc6d 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/TreeRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/TreeRegistry.java @@ -3,7 +3,7 @@ package com.dfsek.terra.registry.config; import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.BlockFace; -import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.world.tree.Tree; import com.dfsek.terra.api.world.tree.fractal.FractalTree; import com.dfsek.terra.api.world.tree.fractal.trees.Cactus; @@ -19,7 +19,6 @@ import com.dfsek.terra.registry.OpenRegistry; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.Random; -import java.util.Set; public class TreeRegistry extends OpenRegistry { private final TerraPlugin main; @@ -71,7 +70,7 @@ public class TreeRegistry extends OpenRegistry { } @Override - public Set getSpawnable() { + public MaterialSet getSpawnable() { return tree.getSpawnable(); } } diff --git a/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java index 6fe999c4d..2f51165ec 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java @@ -5,7 +5,7 @@ import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.BlockFace; -import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.platform.block.BlockType; import com.dfsek.terra.api.platform.block.data.Bisected; import com.dfsek.terra.api.platform.block.data.Slab; import com.dfsek.terra.api.platform.block.data.Stairs; @@ -37,7 +37,7 @@ import java.util.Random; public class DefaultChunkGenerator3D implements TerraChunkGenerator { private final ConfigPack configPack; private final TerraPlugin main; - private final MaterialData water; + private final BlockType water; private final SinglePalette blank; private final Carver carver; @@ -49,7 +49,7 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator { this.configPack = c; this.main = main; carver = new NoiseCarver(new Range(0, 255), main.getWorldHandle().createBlockData("minecraft:air"), main); - water = main.getWorldHandle().createMaterialData("minecraft:water"); + water = main.getWorldHandle().createBlockData("minecraft:water").getBlockType(); blank = new SinglePalette<>(main.getWorldHandle().createBlockData("minecraft:air")); this.cache = cache; } @@ -150,11 +150,11 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator { } } - private void prepareBlockPartFloor(BlockData down, BlockData orig, ChunkData chunk, Vector3 block, Map> slabs, - Map> stairs, double thresh, Sampler sampler) { + private void prepareBlockPartFloor(BlockData down, BlockData orig, ChunkData chunk, Vector3 block, Map> slabs, + Map> stairs, double thresh, Sampler sampler) { if(sampler.sample(block.getX(), block.getY() - 0.4, block.getZ()) > thresh) { if(stairs != null) { - Palette stairPalette = stairs.get(down.getMaterial()); + Palette stairPalette = stairs.get(down.getBlockType()); if(stairPalette != null) { BlockData stair = stairPalette.get(0, block.getX(), block.getY(), block.getZ()).clone(); if(stair instanceof Stairs) { @@ -163,19 +163,19 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator { } } } - BlockData slab = slabs.getOrDefault(down.getMaterial(), blank).get(0, block.getX(), block.getY(), block.getZ()); + BlockData slab = slabs.getOrDefault(down.getBlockType(), blank).get(0, block.getX(), block.getY(), block.getZ()); if(slab instanceof Waterlogged) { - ((Waterlogged) slab).setWaterlogged(orig.matches(water)); - } else if(orig.matches(water)) return; + ((Waterlogged) slab).setWaterlogged(orig.getBlockType().equals(water)); + } else if(orig.getBlockType().equals(water)) return; chunk.setBlock(block.getBlockX(), block.getBlockY(), block.getBlockZ(), slab); } } - private void prepareBlockPartCeiling(BlockData up, BlockData orig, ChunkData chunk, Vector3 block, Map> slabs, - Map> stairs, double thresh, Sampler sampler) { + private void prepareBlockPartCeiling(BlockData up, BlockData orig, ChunkData chunk, Vector3 block, Map> slabs, + Map> stairs, double thresh, Sampler sampler) { if(sampler.sample(block.getX(), block.getY() + 0.4, block.getZ()) > thresh) { if(stairs != null) { - Palette stairPalette = stairs.get(up.getMaterial()); + Palette stairPalette = stairs.get(up.getBlockType()); if(stairPalette != null) { BlockData stair = stairPalette.get(0, block.getX(), block.getY(), block.getZ()).clone(); if(stair instanceof Stairs) { @@ -185,12 +185,12 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator { } } } - BlockData slab = slabs.getOrDefault(up.getMaterial(), blank).get(0, block.getX(), block.getY(), block.getZ()).clone(); + BlockData slab = slabs.getOrDefault(up.getBlockType(), blank).get(0, block.getX(), block.getY(), block.getZ()).clone(); if(slab instanceof Bisected) ((Bisected) slab).setHalf(Bisected.Half.TOP); if(slab instanceof Slab) ((Slab) slab).setType(Slab.Type.TOP); if(slab instanceof Waterlogged) { - ((Waterlogged) slab).setWaterlogged(orig.matches(water)); - } else if(orig.matches(water)) return; // Only replace water if waterlogged. + ((Waterlogged) slab).setWaterlogged(orig.getBlockType().equals(water)); + } else if(orig.getBlockType().equals(water)) return; // Only replace water if waterlogged. chunk.setBlock(block.getBlockX(), block.getBlockY(), block.getBlockZ(), slab); } } @@ -208,7 +208,7 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator { stairNew.setFacing(BlockFace.EAST); } else stairNew = null; if(stairNew != null) { - if(orig.matches(water)) stairNew.setWaterlogged(orig.matches(water)); + if(orig.getBlockType().equals(water)) stairNew.setWaterlogged(orig.getBlockType().equals(water)); chunk.setBlock(block.getBlockX(), block.getBlockY(), block.getBlockZ(), stairNew); return true; } diff --git a/common/src/main/java/com/dfsek/terra/world/population/CavePopulator.java b/common/src/main/java/com/dfsek/terra/world/population/CavePopulator.java index 38d5755fe..4b2e7c126 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/CavePopulator.java +++ b/common/src/main/java/com/dfsek/terra/world/population/CavePopulator.java @@ -4,7 +4,7 @@ import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.Block; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.platform.block.BlockType; import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.platform.world.World; @@ -24,7 +24,7 @@ import java.util.Random; import java.util.Set; public class CavePopulator implements TerraBlockPopulator { - private static final Map shiftStorage = new HashMap<>(); // Persist BlockData created for shifts, to avoid re-calculating each time. + private static final Map shiftStorage = new HashMap<>(); // Persist BlockData created for shifts, to avoid re-calculating each time. private final TerraPlugin main; public CavePopulator(TerraPlugin main) { @@ -44,51 +44,52 @@ public class CavePopulator implements TerraBlockPopulator { for(UserDefinedCarver c : config.getCarvers()) { CarverTemplate template = c.getConfig(); - Map shiftCandidate = new HashMap<>(); + Map shiftCandidate = new HashMap<>(); Set updateNeeded = new HashSet<>(); c.carve(chunk.getX(), chunk.getZ(), world, (v, type) -> { Block b = chunk.getBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ()); - MaterialData m = handle.getType(b); + BlockData m = handle.getBlockData(b); + BlockType re = m.getBlockType(); switch(type) { case CENTER: - if(template.getInner().canReplace(m)) { + if(template.getInner().canReplace(re)) { b.setBlockData(template.getInner().get(v.getBlockY()).get(random), false); - if(template.getUpdate().contains(m)) updateNeeded.add(b); - if(template.getShift().containsKey(m)) shiftCandidate.put(b.getLocation(), m); + if(template.getUpdate().contains(re)) updateNeeded.add(b); + if(template.getShift().containsKey(re)) shiftCandidate.put(b.getLocation(), m); } break; case WALL: - if(template.getOuter().canReplace(m)) { + if(template.getOuter().canReplace(re)) { b.setBlockData(template.getOuter().get(v.getBlockY()).get(random), false); - if(template.getUpdate().contains(m)) updateNeeded.add(b); - if(template.getShift().containsKey(m)) shiftCandidate.put(b.getLocation(), m); + if(template.getUpdate().contains(re)) updateNeeded.add(b); + if(template.getShift().containsKey(re)) shiftCandidate.put(b.getLocation(), m); } break; case TOP: - if(template.getTop().canReplace(m)) { + if(template.getTop().canReplace(re)) { b.setBlockData(template.getTop().get(v.getBlockY()).get(random), false); - if(template.getUpdate().contains(m)) updateNeeded.add(b); - if(template.getShift().containsKey(m)) shiftCandidate.put(b.getLocation(), m); + if(template.getUpdate().contains(re)) updateNeeded.add(b); + if(template.getShift().containsKey(re)) shiftCandidate.put(b.getLocation(), m); } break; case BOTTOM: - if(template.getBottom().canReplace(m)) { + if(template.getBottom().canReplace(re)) { b.setBlockData(template.getBottom().get(v.getBlockY()).get(random), false); - if(template.getUpdate().contains(m)) updateNeeded.add(b); - if(template.getShift().containsKey(m)) shiftCandidate.put(b.getLocation(), m); + if(template.getUpdate().contains(re)) updateNeeded.add(b); + if(template.getShift().containsKey(re)) shiftCandidate.put(b.getLocation(), m); } break; } }); - for(Map.Entry entry : shiftCandidate.entrySet()) { + for(Map.Entry entry : shiftCandidate.entrySet()) { Location l = entry.getKey(); Location mut = l.clone(); - MaterialData orig = handle.getType(l.getBlock()); + BlockData orig = handle.getBlockData(l.getBlock()); do mut.subtract(0, 1, 0); - while(mut.getY() > 0 && handle.getType(mut.getBlock()).equals(orig)); + while(mut.getY() > 0 && handle.getBlockData(mut.getBlock()).matches(orig)); try { - if(template.getShift().get(entry.getValue()).contains(mut.getBlock().getType())) { - handle.setBlockData(mut.getBlock(), shiftStorage.computeIfAbsent(entry.getValue(), MaterialData::createBlockData), false); + if(template.getShift().get(entry.getValue().getBlockType()).contains(mut.getBlock().getBlockData().getBlockType())) { + handle.setBlockData(mut.getBlock(), shiftStorage.computeIfAbsent(entry.getValue().getBlockType(), BlockType::getDefaultData), false); } } catch(NullPointerException ignore) { } diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java index 5f8e99ee5..785f85215 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java @@ -9,7 +9,6 @@ import com.dfsek.terra.api.addons.annotations.Version; import com.dfsek.terra.api.event.EventManager; import com.dfsek.terra.api.event.TerraEventManager; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.platform.handle.ItemHandle; import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.api.platform.world.Biome; @@ -262,7 +261,6 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { public void register(TypeRegistry registry) { registry .registerLoader(BlockData.class, (t, o, l) -> handle.createBlockData((String) o)) - .registerLoader(MaterialData.class, (t, o, l) -> handle.createMaterialData((String) o)) .registerLoader(Biome.class, (t, o, l) -> new BukkitBiome(org.bukkit.block.Biome.valueOf((String) o))) .registerLoader(EntityType.class, (t, o, l) -> EntityType.valueOf((String) o)); genericLoaders.register(registry); diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/handles/BukkitItemHandle.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/handles/BukkitItemHandle.java index aa8531e67..f13783203 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/handles/BukkitItemHandle.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/handles/BukkitItemHandle.java @@ -1,13 +1,11 @@ package com.dfsek.terra.bukkit.handles; -import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.platform.handle.ItemHandle; -import com.dfsek.terra.api.platform.inventory.ItemStack; +import com.dfsek.terra.api.platform.inventory.Item; import com.dfsek.terra.api.platform.inventory.item.Enchantment; import com.dfsek.terra.bukkit.util.MinecraftUtils; import com.dfsek.terra.bukkit.world.BukkitAdapter; -import com.dfsek.terra.bukkit.world.block.BukkitMaterialData; -import com.dfsek.terra.bukkit.world.inventory.BukkitItemStack; +import org.bukkit.Material; import org.bukkit.NamespacedKey; import java.util.Arrays; @@ -15,9 +13,10 @@ import java.util.Set; import java.util.stream.Collectors; public class BukkitItemHandle implements ItemHandle { + @Override - public ItemStack newItemStack(MaterialData material, int amount) { - return new BukkitItemStack(new org.bukkit.inventory.ItemStack(((BukkitMaterialData) material).getHandle(), amount)); + public Item createItem(String data) { + return BukkitAdapter.adapt(Material.matchMaterial(data)); } @Override diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/handles/BukkitWorldHandle.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/handles/BukkitWorldHandle.java index 03beeabcb..8bf49a0d9 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/handles/BukkitWorldHandle.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/handles/BukkitWorldHandle.java @@ -2,14 +2,11 @@ package com.dfsek.terra.bukkit.handles; import com.dfsek.terra.api.platform.block.Block; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.platform.entity.EntityType; import com.dfsek.terra.api.platform.handle.WorldHandle; -import com.dfsek.terra.bukkit.world.block.BukkitMaterialData; import com.dfsek.terra.bukkit.world.block.data.BukkitBlockData; import com.dfsek.terra.bukkit.world.entity.BukkitEntityType; import org.bukkit.Bukkit; -import org.bukkit.Material; public class BukkitWorldHandle implements WorldHandle { @Override @@ -22,22 +19,12 @@ public class BukkitWorldHandle implements WorldHandle { return block.getBlockData(); } - @Override - public MaterialData getType(Block block) { - return block.getType(); - } - @Override public BlockData createBlockData(String data) { org.bukkit.block.data.BlockData bukkitData = Bukkit.createBlockData(data); return BukkitBlockData.newInstance(bukkitData); } - @Override - public MaterialData createMaterialData(String data) { - return new BukkitMaterialData(Material.matchMaterial(data)); - } - @Override public EntityType getEntity(String id) { return new BukkitEntityType(org.bukkit.entity.EntityType.valueOf(id)); diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitAdapter.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitAdapter.java index 643488ccb..cd3e61b1d 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitAdapter.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitAdapter.java @@ -6,11 +6,13 @@ import com.dfsek.terra.api.platform.CommandSender; import com.dfsek.terra.api.platform.block.Axis; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.BlockFace; +import com.dfsek.terra.api.platform.block.BlockType; import com.dfsek.terra.api.platform.block.data.Bisected; import com.dfsek.terra.api.platform.block.data.Rail; import com.dfsek.terra.api.platform.block.data.RedstoneWire; import com.dfsek.terra.api.platform.block.data.Slab; import com.dfsek.terra.api.platform.block.data.Stairs; +import com.dfsek.terra.api.platform.inventory.ItemStack; import com.dfsek.terra.api.platform.inventory.item.Enchantment; import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.platform.world.World; @@ -18,9 +20,12 @@ import com.dfsek.terra.api.transform.MapTransform; import com.dfsek.terra.api.transform.Transformer; import com.dfsek.terra.bukkit.BukkitCommandSender; import com.dfsek.terra.bukkit.BukkitPlayer; +import com.dfsek.terra.bukkit.world.block.BukkitBlockTypeAndItem; import com.dfsek.terra.bukkit.world.block.data.BukkitBlockData; +import com.dfsek.terra.bukkit.world.inventory.BukkitItemStack; import com.dfsek.terra.bukkit.world.inventory.meta.BukkitEnchantment; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.TreeType; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -384,4 +389,20 @@ public final class BukkitAdapter { public static com.dfsek.terra.api.platform.entity.Player adapt(Player player) { return new BukkitPlayer(player); } + + public static BukkitBlockTypeAndItem adapt(Material material) { + return new BukkitBlockTypeAndItem(material); + } + + public static Material adapt(BlockType type) { + return ((BukkitBlockTypeAndItem) type).getHandle(); + } + + public static ItemStack adapt(org.bukkit.inventory.ItemStack in) { + return new BukkitItemStack(in); + } + + public static org.bukkit.inventory.ItemStack adapt(ItemStack in) { + return ((BukkitItemStack) in).getHandle(); + } } diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitTree.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitTree.java index 69f1e578c..d4364a1b0 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitTree.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitTree.java @@ -2,14 +2,12 @@ package com.dfsek.terra.bukkit.world; import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; -import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.world.tree.Tree; import org.bukkit.TreeType; import java.util.Random; -import java.util.Set; public class BukkitTree implements Tree { private final TreeType delegate; @@ -26,18 +24,18 @@ public class BukkitTree implements Tree { WorldHandle handle = main.getWorldHandle(); switch(type) { case CRIMSON_FUNGUS: - return MaterialSet.get(handle.createMaterialData("minecraft:crimson_nylium")); + return MaterialSet.get(handle.createBlockData("minecraft:crimson_nylium")); case WARPED_FUNGUS: - return MaterialSet.get(handle.createMaterialData("minecraft:warped_nylium")); + return MaterialSet.get(handle.createBlockData("minecraft:warped_nylium")); case BROWN_MUSHROOM: case RED_MUSHROOM: - return MaterialSet.get(handle.createMaterialData("minecraft:mycelium"), handle.createMaterialData("minecraft:grass_block"), - handle.createMaterialData("minecraft:podzol")); + return MaterialSet.get(handle.createBlockData("minecraft:mycelium"), handle.createBlockData("minecraft:grass_block"), + handle.createBlockData("minecraft:podzol")); case CHORUS_PLANT: - return MaterialSet.get(handle.createMaterialData("minecraft:end_stone")); + return MaterialSet.get(handle.createBlockData("minecraft:end_stone")); default: - return MaterialSet.get(handle.createMaterialData("minecraft:grass_block"), handle.createMaterialData("minecraft:dirt"), - handle.createMaterialData("minecraft:podzol")); + return MaterialSet.get(handle.createBlockData("minecraft:grass_block"), handle.createBlockData("minecraft:dirt"), + handle.createBlockData("minecraft:podzol")); } } @@ -47,7 +45,7 @@ public class BukkitTree implements Tree { } @Override - public Set getSpawnable() { + public MaterialSet getSpawnable() { return spawnable; } } diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/BukkitBlock.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/BukkitBlock.java index aaa5a9b47..dcf49acdd 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/BukkitBlock.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/BukkitBlock.java @@ -4,7 +4,7 @@ import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.Block; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.BlockFace; -import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.platform.block.BlockType; import com.dfsek.terra.api.platform.block.state.BlockState; import com.dfsek.terra.bukkit.world.BukkitAdapter; import com.dfsek.terra.bukkit.world.block.data.BukkitBlockData; @@ -53,8 +53,8 @@ public class BukkitBlock implements Block { } @Override - public MaterialData getType() { - return new BukkitMaterialData(delegate.getType()); + public BlockType getType() { + return BukkitAdapter.adapt(delegate.getType()); } @Override diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/BukkitBlockTypeAndItem.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/BukkitBlockTypeAndItem.java new file mode 100644 index 000000000..aeafa9823 --- /dev/null +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/BukkitBlockTypeAndItem.java @@ -0,0 +1,52 @@ +package com.dfsek.terra.bukkit.world.block; + +import com.dfsek.terra.api.platform.block.BlockData; +import com.dfsek.terra.api.platform.block.BlockType; +import com.dfsek.terra.api.platform.inventory.Item; +import com.dfsek.terra.api.platform.inventory.ItemStack; +import com.dfsek.terra.bukkit.world.BukkitAdapter; +import org.bukkit.Material; + +public class BukkitBlockTypeAndItem implements BlockType, Item { + private final Material delegate; + + public BukkitBlockTypeAndItem(Material delegate) { + this.delegate = delegate; + } + + @Override + public Material getHandle() { + return delegate; + } + + @Override + public BlockData getDefaultData() { + return BukkitAdapter.adapt(delegate.createBlockData()); + } + + @Override + public boolean isSolid() { + return delegate.isSolid(); + } + + @Override + public ItemStack newItemStack(int amount) { + return BukkitAdapter.adapt(new org.bukkit.inventory.ItemStack(delegate, amount)); + } + + @Override + public double getMaxDurability() { + return delegate.getMaxDurability(); + } + + @Override + public int hashCode() { + return delegate.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if(!(obj instanceof BukkitBlockTypeAndItem)) return false; + return delegate == ((BukkitBlockTypeAndItem) obj).delegate; + } +} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/BukkitMaterialData.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/BukkitMaterialData.java deleted file mode 100644 index e0bfba568..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/BukkitMaterialData.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.dfsek.terra.bukkit.world.block; - -import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.platform.block.MaterialData; -import com.dfsek.terra.bukkit.world.block.data.BukkitBlockData; -import org.bukkit.Material; - -public class BukkitMaterialData implements MaterialData { - private final Material delegate; - - public BukkitMaterialData(Material delegate) { - this.delegate = delegate; - } - - @Override - public boolean matches(MaterialData other) { - return ((BukkitMaterialData) other).getHandle().equals(delegate); - } - - @Override - public boolean matches(BlockData other) { - return ((BukkitMaterialData) other.getMaterial()).getHandle().equals(delegate); - } - - @Override - public boolean isSolid() { - return delegate.isSolid(); - } - - @Override - public boolean isAir() { - return delegate.isAir(); - } - - @Override - public double getMaxDurability() { - return delegate.getMaxDurability(); - } - - @Override - public BlockData createBlockData() { - return BukkitBlockData.newInstance(delegate.createBlockData()); - } - - @Override - public Material getHandle() { - return delegate; - } - - @Override - public int hashCode() { - return delegate.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if(!(obj instanceof BukkitMaterialData)) return false; - BukkitMaterialData other = (BukkitMaterialData) obj; - - return other.getHandle().equals(this.delegate); - } -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/data/BukkitBlockData.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/data/BukkitBlockData.java index 6e198a53b..a742d0549 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/data/BukkitBlockData.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/data/BukkitBlockData.java @@ -1,9 +1,9 @@ package com.dfsek.terra.bukkit.world.block.data; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.platform.block.BlockType; import com.dfsek.terra.bukkit.TerraBukkitPlugin; -import com.dfsek.terra.bukkit.world.block.BukkitMaterialData; +import com.dfsek.terra.bukkit.world.BukkitAdapter; import org.bukkit.block.data.AnaloguePowerable; import org.bukkit.block.data.Directional; import org.bukkit.block.data.MultipleFacing; @@ -52,13 +52,13 @@ public class BukkitBlockData implements BlockData { } @Override - public MaterialData getMaterial() { - return new BukkitMaterialData(delegate.getMaterial()); + public BlockType getBlockType() { + return BukkitAdapter.adapt(delegate.getMaterial()); } @Override - public boolean matches(MaterialData materialData) { - return delegate.getMaterial().equals(((BukkitMaterialData) materialData).getHandle()); + public boolean matches(BlockData data) { + return delegate.getMaterial() == ((BukkitBlockData) data).getHandle().getMaterial(); } @Override @@ -76,4 +76,9 @@ public class BukkitBlockData implements BlockData { public String getAsString() { return delegate.getAsString(false); } + + @Override + public boolean isAir() { + return delegate.getMaterial().isAir(); + } } diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/inventory/BukkitItemStack.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/inventory/BukkitItemStack.java index 5d94c45c5..28bbca8f9 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/inventory/BukkitItemStack.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/inventory/BukkitItemStack.java @@ -1,9 +1,9 @@ package com.dfsek.terra.bukkit.world.inventory; -import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.platform.inventory.Item; import com.dfsek.terra.api.platform.inventory.ItemStack; import com.dfsek.terra.api.platform.inventory.item.ItemMeta; -import com.dfsek.terra.bukkit.world.block.BukkitMaterialData; +import com.dfsek.terra.bukkit.world.BukkitAdapter; public class BukkitItemStack implements ItemStack { private org.bukkit.inventory.ItemStack delegate; @@ -23,8 +23,8 @@ public class BukkitItemStack implements ItemStack { } @Override - public MaterialData getType() { - return new BukkitMaterialData(delegate.getType()); + public Item getType() { + return BukkitAdapter.adapt(delegate.getType()); } @Override diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index 3bb773ee3..6433f918b 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -6,7 +6,6 @@ import com.dfsek.terra.api.addons.TerraAddon; import com.dfsek.terra.api.event.EventManager; import com.dfsek.terra.api.event.TerraEventManager; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.platform.handle.ItemHandle; import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.api.platform.world.World; @@ -216,7 +215,6 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { genericLoaders.register(registry); registry .registerLoader(BlockData.class, (t, o, l) -> worldHandle.createBlockData((String) o)) - .registerLoader(MaterialData.class, (t, o, l) -> worldHandle.createMaterialData((String) o)) .registerLoader(com.dfsek.terra.api.platform.world.Biome.class, (t, o, l) -> new FabricBiome(biomeFixer.translate((String) o))); } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemHandle.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemHandle.java index 2c0596b5e..d487bd719 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemHandle.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemHandle.java @@ -1,16 +1,16 @@ package com.dfsek.terra.fabric.inventory; -import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.platform.handle.ItemHandle; -import com.dfsek.terra.api.platform.inventory.ItemStack; +import com.dfsek.terra.api.platform.inventory.Item; import com.dfsek.terra.api.platform.inventory.item.Enchantment; import java.util.Collections; import java.util.Set; public class FabricItemHandle implements ItemHandle { + @Override - public ItemStack newItemStack(MaterialData material, int amount) { + public Item createItem(String data) { return null; } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemStack.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemStack.java index c6caae3e3..1db90510e 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemStack.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemStack.java @@ -1,6 +1,6 @@ package com.dfsek.terra.fabric.inventory; -import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.platform.inventory.Item; import com.dfsek.terra.api.platform.inventory.ItemStack; import com.dfsek.terra.api.platform.inventory.item.ItemMeta; @@ -18,7 +18,7 @@ public class FabricItemStack implements ItemStack { } @Override - public MaterialData getType() { + public Item getType() { return null; } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricTree.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricTree.java index 53d727461..f7480a57d 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricTree.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricTree.java @@ -1,7 +1,6 @@ package com.dfsek.terra.fabric.world; import com.dfsek.terra.api.math.vector.Location; -import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.world.tree.Tree; import com.dfsek.terra.fabric.TerraFabricPlugin; @@ -13,7 +12,6 @@ import net.minecraft.world.gen.chunk.ChunkGenerator; import net.minecraft.world.gen.feature.ConfiguredFeature; import java.util.Random; -import java.util.Set; public class FabricTree implements Tree { private final ConfiguredFeature delegate; @@ -30,8 +28,8 @@ public class FabricTree implements Tree { } @Override - public Set getSpawnable() { - return MaterialSet.get(TerraFabricPlugin.getInstance().getWorldHandle().createMaterialData("minecraft:grass_block"), - TerraFabricPlugin.getInstance().getWorldHandle().createMaterialData("minecraft:podzol")); + public MaterialSet getSpawnable() { + return MaterialSet.get(TerraFabricPlugin.getInstance().getWorldHandle().createBlockData("minecraft:grass_block"), + TerraFabricPlugin.getInstance().getWorldHandle().createBlockData("minecraft:podzol")); } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricWorldHandle.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricWorldHandle.java index e06e8e780..5633b6546 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricWorldHandle.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricWorldHandle.java @@ -2,11 +2,9 @@ package com.dfsek.terra.fabric.world; import com.dfsek.terra.api.platform.block.Block; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.platform.entity.EntityType; import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.fabric.world.block.FabricBlockData; -import com.dfsek.terra.fabric.world.block.FabricMaterialData; import com.dfsek.terra.fabric.world.block.data.FabricMultipleFacing; import com.dfsek.terra.fabric.world.block.data.FabricOrientable; import com.dfsek.terra.fabric.world.block.data.FabricSlab; @@ -31,11 +29,6 @@ public class FabricWorldHandle implements WorldHandle { return block.getBlockData(); } - @Override - public MaterialData getType(Block block) { - return block.getType(); - } - @Override public FabricBlockData createBlockData(String data) { BlockArgumentParser parser = new BlockArgumentParser(new StringReader(data), true); @@ -58,11 +51,6 @@ public class FabricWorldHandle implements WorldHandle { } } - @Override - public MaterialData createMaterialData(String data) { - return new FabricMaterialData(createBlockData(data).getHandle().getBlock()); - } - @Override public EntityType getEntity(String id) { return null; diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlock.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlock.java index 2b22b99ba..eab578d3a 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlock.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlock.java @@ -4,7 +4,7 @@ import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.Block; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.BlockFace; -import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.platform.block.BlockType; import com.dfsek.terra.api.platform.block.state.BlockState; import com.dfsek.terra.fabric.world.FabricAdapters; import com.dfsek.terra.fabric.world.handles.world.FabricWorldAccess; @@ -46,7 +46,7 @@ public class FabricBlock implements Block { @Override public boolean isEmpty() { - return getBlockData().getMaterial().isAir(); + return false; } @Override @@ -55,8 +55,8 @@ public class FabricBlock implements Block { } @Override - public MaterialData getType() { - return getBlockData().getMaterial(); + public BlockType getType() { + return getBlockData().getBlockType(); } @Override diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlockData.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlockData.java index f7fac5fb4..643a849a3 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlockData.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlockData.java @@ -1,7 +1,7 @@ package com.dfsek.terra.fabric.world.block; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.platform.block.BlockType; import net.minecraft.block.BlockState; public class FabricBlockData implements BlockData { @@ -12,13 +12,13 @@ public class FabricBlockData implements BlockData { } @Override - public MaterialData getMaterial() { - return new FabricMaterialData(delegate.getBlock()); + public BlockType getBlockType() { + return null; } @Override - public boolean matches(MaterialData materialData) { - return ((FabricMaterialData) materialData).getHandle().is(delegate.getBlock()); + public boolean matches(BlockData other) { + return false; } @Override @@ -35,6 +35,11 @@ public class FabricBlockData implements BlockData { return delegate.toString(); } + @Override + public boolean isAir() { + return false; + } + @Override public BlockState getHandle() { return delegate; diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricMaterialData.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricMaterialData.java deleted file mode 100644 index dd9941d03..000000000 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricMaterialData.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.dfsek.terra.fabric.world.block; - -import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.platform.block.MaterialData; -import net.minecraft.block.Block; -import net.minecraft.block.Blocks; - -public class FabricMaterialData implements MaterialData { - private final Block delegate; - - public FabricMaterialData(Block delegate) { - this.delegate = delegate; - } - - @Override - public boolean matches(MaterialData other) { - return delegate.equals(((FabricMaterialData) other).getHandle()); - } - - @Override - public boolean matches(BlockData other) { - return delegate.equals(((FabricMaterialData) other.getMaterial()).getHandle()); - } - - @Override - public boolean isSolid() { - return !delegate.is(Blocks.AIR); - } - - @Override - public boolean isAir() { - return delegate.is(Blocks.AIR); // TODO: better impl - } - - @Override - public double getMaxDurability() { - return 0; - } - - @Override - public BlockData createBlockData() { - return new FabricBlockData(delegate.getDefaultState()); - } - - @Override - public Block getHandle() { - return delegate; - } - - - @Override - public int hashCode() { - return delegate.asItem().hashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj instanceof FabricMaterialData) { - return ((FabricMaterialData) obj).matches(this); - } - return false; - } -} diff --git a/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java b/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java index d917f5fe9..68a686669 100644 --- a/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java +++ b/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java @@ -6,7 +6,6 @@ import com.dfsek.terra.api.addons.TerraAddon; import com.dfsek.terra.api.event.EventManager; import com.dfsek.terra.api.event.TerraEventManager; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.platform.handle.ItemHandle; import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.api.platform.world.Biome; @@ -123,7 +122,6 @@ public class StandalonePlugin implements TerraPlugin { registry .registerLoader(BlockData.class, (t, o, l) -> worldHandle.createBlockData((String) o)) .registerLoader(Biome.class, (t, o, l) -> new RawBiome(o.toString())) - .registerLoader(MaterialData.class, (t, o, l) -> worldHandle.createMaterialData((String) o)); new GenericLoaders(this).register(registry); } diff --git a/platforms/region/src/main/java/com/dfsek/terra/platform/Data.java b/platforms/region/src/main/java/com/dfsek/terra/platform/Data.java index 0ba30f150..98c3ee0ec 100644 --- a/platforms/region/src/main/java/com/dfsek/terra/platform/Data.java +++ b/platforms/region/src/main/java/com/dfsek/terra/platform/Data.java @@ -1,10 +1,10 @@ package com.dfsek.terra.platform; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.platform.block.BlockType; import net.querz.nbt.tag.CompoundTag; -public class Data implements BlockData, MaterialData { +public class Data implements BlockData, BlockType { private final CompoundTag data; private final String noProp; @@ -38,39 +38,20 @@ public class Data implements BlockData, MaterialData { @Override - public MaterialData getMaterial() { + public BlockType getBlockType() { return this; } - @Override - public boolean matches(MaterialData materialData) { - return ((Data) materialData).noProp.equals(noProp); - } - @Override public boolean matches(BlockData other) { return ((Data) other).noProp.equals(noProp); } - @Override - public boolean isSolid() { - return !isAir(); //TODO: actual implementation - } - @Override public boolean isAir() { return noProp.equals("minecraft:air"); } - @Override - public double getMaxDurability() { - return 0; - } - - @Override - public BlockData createBlockData() { - return this; - } @Override public BlockData clone() { @@ -101,4 +82,14 @@ public class Data implements BlockData, MaterialData { if(!(obj instanceof Data)) return false; return ((Data) obj).noProp.equals(noProp); } + + @Override + public BlockData getDefaultData() { + return this; + } + + @Override + public boolean isSolid() { + return false; + } } diff --git a/platforms/region/src/main/java/com/dfsek/terra/platform/DirectBlock.java b/platforms/region/src/main/java/com/dfsek/terra/platform/DirectBlock.java index 55372978b..3169d0667 100644 --- a/platforms/region/src/main/java/com/dfsek/terra/platform/DirectBlock.java +++ b/platforms/region/src/main/java/com/dfsek/terra/platform/DirectBlock.java @@ -5,7 +5,7 @@ import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.Block; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.BlockFace; -import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.platform.block.BlockType; import com.dfsek.terra.api.platform.block.state.BlockState; import net.jafama.FastMath; @@ -56,7 +56,7 @@ public class DirectBlock implements Block { } @Override - public MaterialData getType() { + public BlockType getType() { return new Data(world.getData(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ())); } diff --git a/platforms/region/src/main/java/com/dfsek/terra/platform/RawTree.java b/platforms/region/src/main/java/com/dfsek/terra/platform/RawTree.java index 867e1bd4a..b58efb7e0 100644 --- a/platforms/region/src/main/java/com/dfsek/terra/platform/RawTree.java +++ b/platforms/region/src/main/java/com/dfsek/terra/platform/RawTree.java @@ -1,12 +1,10 @@ package com.dfsek.terra.platform; import com.dfsek.terra.api.math.vector.Location; -import com.dfsek.terra.api.platform.block.MaterialData; +import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.world.tree.Tree; -import java.util.Collections; import java.util.Random; -import java.util.Set; public class RawTree implements Tree { // TODO: implement @Override @@ -15,7 +13,7 @@ public class RawTree implements Tree { // TODO: implement } @Override - public Set getSpawnable() { - return Collections.emptySet(); + public MaterialSet getSpawnable() { + return MaterialSet.empty(); } } diff --git a/platforms/region/src/main/java/com/dfsek/terra/platform/RawWorldHandle.java b/platforms/region/src/main/java/com/dfsek/terra/platform/RawWorldHandle.java index a6c487aa7..dcf094708 100644 --- a/platforms/region/src/main/java/com/dfsek/terra/platform/RawWorldHandle.java +++ b/platforms/region/src/main/java/com/dfsek/terra/platform/RawWorldHandle.java @@ -2,7 +2,6 @@ package com.dfsek.terra.platform; import com.dfsek.terra.api.platform.block.Block; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.platform.block.MaterialData; import com.dfsek.terra.api.platform.entity.EntityType; import com.dfsek.terra.api.platform.handle.WorldHandle; @@ -17,21 +16,11 @@ public class RawWorldHandle implements WorldHandle { return null; } - @Override - public MaterialData getType(Block block) { - return null; - } - @Override public BlockData createBlockData(String data) { return new Data(data); } - @Override - public MaterialData createMaterialData(String data) { - return new Data(data); - } - @Override public EntityType getEntity(String id) { return null; From 268cc7c48b15149e3adda6b01a3aac6c24737de8 Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 22 Feb 2021 20:47:06 -0700 Subject: [PATCH 15/95] fabric stuff --- .../dfsek/terra/fabric/TerraFabricPlugin.java | 110 ++++++++++++------ .../terra/fabric/mixin/StateAccessor.java | 17 +++ .../terra/fabric/world/FabricAdapter.java | 45 +++++++ .../terra/fabric/world/FabricAdapters.java | 14 --- .../terra/fabric/world/FabricWorldHandle.java | 20 +--- .../terra/fabric/world/block/FabricBlock.java | 6 +- .../fabric/world/block/FabricBlockData.java | 19 ++- .../fabric/world/block/FabricBlockType.java | 40 +++++++ .../src/main/resources/terra.mixins.json | 4 +- .../com/dfsek/terra/StandalonePlugin.java | 2 +- 10 files changed, 199 insertions(+), 78 deletions(-) create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/StateAccessor.java create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java delete mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapters.java create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlockType.java diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index 6433f918b..be376bfa4 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -3,19 +3,27 @@ package com.dfsek.terra.fabric; import com.dfsek.tectonic.loading.TypeRegistry; import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.addons.TerraAddon; +import com.dfsek.terra.api.addons.annotations.Addon; +import com.dfsek.terra.api.addons.annotations.Author; +import com.dfsek.terra.api.addons.annotations.Version; +import com.dfsek.terra.api.event.EventListener; import com.dfsek.terra.api.event.EventManager; import com.dfsek.terra.api.event.TerraEventManager; +import com.dfsek.terra.api.event.annotations.Global; +import com.dfsek.terra.api.event.annotations.Priority; +import com.dfsek.terra.api.event.events.config.ConfigPackPreLoadEvent; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.handle.ItemHandle; import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.registry.CheckedRegistry; import com.dfsek.terra.api.registry.LockedRegistry; -import com.dfsek.terra.api.transform.MapTransform; import com.dfsek.terra.api.transform.NotNullValidator; import com.dfsek.terra.api.transform.Transformer; import com.dfsek.terra.api.util.DebugLogger; +import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.tree.Tree; import com.dfsek.terra.config.GenericLoaders; import com.dfsek.terra.config.PluginConfig; import com.dfsek.terra.config.lang.LangUtil; @@ -23,11 +31,14 @@ import com.dfsek.terra.config.lang.Language; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.fabric.inventory.FabricItemHandle; import com.dfsek.terra.fabric.mixin.GeneratorTypeAccessor; +import com.dfsek.terra.fabric.world.FabricAdapter; import com.dfsek.terra.fabric.world.FabricBiome; +import com.dfsek.terra.fabric.world.FabricTree; import com.dfsek.terra.fabric.world.FabricWorldHandle; import com.dfsek.terra.fabric.world.TerraBiomeSource; import com.dfsek.terra.fabric.world.features.PopulatorFeature; import com.dfsek.terra.fabric.world.generator.FabricChunkGeneratorWrapper; +import com.dfsek.terra.registry.exception.DuplicateEntryException; import com.dfsek.terra.registry.master.AddonRegistry; import com.dfsek.terra.registry.master.ConfigRegistry; import com.dfsek.terra.world.TerraWorld; @@ -61,7 +72,6 @@ import org.apache.commons.io.FileUtils; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -90,33 +100,12 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { private final ConfigRegistry registry = new ConfigRegistry(); private final CheckedRegistry checkedRegistry = new CheckedRegistry<>(registry); - private final AddonRegistry addonRegistry = new AddonRegistry(this); + private final AddonRegistry addonRegistry = new AddonRegistry(new FabricAddon(this), this); private final LockedRegistry addonLockedRegistry = new LockedRegistry<>(addonRegistry); private File config; - private static final Transformer> TREE_TRANSFORMER = new Transformer.Builder>() - .addTransform(TerraFabricPlugin::getFeature) - .addTransform(new MapTransform>() - .add("BROWN_MUSHROOM", ConfiguredFeatures.BROWN_MUSHROOM_GIANT) - .add("RED_MUSHROOM", ConfiguredFeatures.RED_MUSHROOM_GIANT) - .add("JUNGLE", ConfiguredFeatures.MEGA_JUNGLE_TREE) - .add("JUNGLE_COCOA", ConfiguredFeatures.JUNGLE_TREE) - .add("LARGE_OAK", ConfiguredFeatures.FANCY_OAK) - .add("LARGE_SPRUCE", ConfiguredFeatures.PINE) - .add("SMALL_JUNGLE", ConfiguredFeatures.JUNGLE_TREE) - .add("SWAMP_OAK", ConfiguredFeatures.SWAMP_TREE) - .add("TALL_BIRCH", ConfiguredFeatures.BIRCH_TALL) - .add("ACACIA", ConfiguredFeatures.ACACIA) - .add("BIRCH", ConfiguredFeatures.BIRCH) - .add("DARK_OAK", ConfiguredFeatures.DARK_OAK) - .add("OAK", ConfiguredFeatures.OAK) - .add("CHORUS_PLANT", ConfiguredFeatures.CHORUS_PLANT) - .add("SPRUCE", ConfiguredFeatures.SPRUCE) - .add("JUNGLE_BUSH", ConfiguredFeatures.JUNGLE_BUSH) - .add("MEGA_SPRUCE", ConfiguredFeatures.MEGA_SPRUCE) - .add("CRIMSON_FUNGUS", ConfiguredFeatures.CRIMSON_FUNGI) - .add("WARPED_FUNGUS", ConfiguredFeatures.WARPED_FUNGI)).build(); + private final PluginConfig plugin = new PluginConfig(); @Override @@ -259,20 +248,15 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { .build(); } - private static ConfiguredFeature getFeature(String name) { - Class featuresClass = ConfiguredFeatures.class; - Field feature; - try { - feature = featuresClass.getField(name); - return (ConfiguredFeature) feature.get(null); - } catch(NoSuchFieldException | IllegalAccessException e) { - throw new IllegalArgumentException("No such feature: " + name); - } - } - @Override public void onInitialize() { logger.setLevel(Level.INFO); + MaterialSet set = MaterialSet.get(FabricAdapter.adapt(Blocks.GRASS_BLOCK), FabricAdapter.adapt(Blocks.STONE)); + logger.info("thing: " + set.contains(FabricAdapter.adapt(Blocks.STONE))); + logger.info("thing2: " + set.contains(FabricAdapter.adapt(Blocks.OAK_BUTTON))); + logger.info("thing3: " + Blocks.ACACIA_FENCE.getDefaultState().toString()); + logger.info("thing4: " + Blocks.ACACIA_FENCE.toString()); + instance = this; config = new File(FabricLoader.getInstance().getConfigDir().toFile(), "Terra"); @@ -281,6 +265,10 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { LangUtil.load("en_us", this); logger.info("Initializing Terra..."); + if(!addonRegistry.loadAll()) { + throw new IllegalStateException("Failed to load addons. Please correct addon installations to continue."); + } + registry.loadAll(this); Registry.register(Registry.FEATURE, new Identifier("terra", "flora_populator"), POPULATOR_FEATURE); @@ -307,4 +295,54 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { public EventManager getEventManager() { return eventManager; } + + @Addon("Terra-Fabric") + @Author("Terra") + @Version("1.0.0") + private static final class FabricAddon extends TerraAddon implements EventListener { + + private final TerraPlugin main; + + private FabricAddon(TerraPlugin main) { + this.main = main; + } + + @Override + public void initialize() { + main.getEventManager().registerListener(this, this); + } + + @Priority(Priority.LOWEST) + @Global + public void injectTrees(ConfigPackPreLoadEvent event) { + CheckedRegistry treeRegistry = event.getPack().getTreeRegistry(); + injectTree(treeRegistry, "BROWN_MUSHROOM", ConfiguredFeatures.BROWN_MUSHROOM_GIANT); + injectTree(treeRegistry, "RED_MUSHROOM", ConfiguredFeatures.RED_MUSHROOM_GIANT); + injectTree(treeRegistry, "JUNGLE", ConfiguredFeatures.MEGA_JUNGLE_TREE); + injectTree(treeRegistry, "JUNGLE_COCOA", ConfiguredFeatures.JUNGLE_TREE); + injectTree(treeRegistry, "LARGE_OAK", ConfiguredFeatures.FANCY_OAK); + injectTree(treeRegistry, "LARGE_SPRUCE", ConfiguredFeatures.PINE); + injectTree(treeRegistry, "SMALL_JUNGLE", ConfiguredFeatures.JUNGLE_TREE); + injectTree(treeRegistry, "SWAMP_OAK", ConfiguredFeatures.SWAMP_TREE); + injectTree(treeRegistry, "TALL_BIRCH", ConfiguredFeatures.BIRCH_TALL); + injectTree(treeRegistry, "ACACIA", ConfiguredFeatures.ACACIA); + injectTree(treeRegistry, "BIRCH", ConfiguredFeatures.BIRCH); + injectTree(treeRegistry, "DARK_OAK", ConfiguredFeatures.DARK_OAK); + injectTree(treeRegistry, "OAK", ConfiguredFeatures.OAK); + injectTree(treeRegistry, "CHORUS_PLANT", ConfiguredFeatures.CHORUS_PLANT); + injectTree(treeRegistry, "SPRUCE", ConfiguredFeatures.SPRUCE); + injectTree(treeRegistry, "JUNGLE_BUSH", ConfiguredFeatures.JUNGLE_BUSH); + injectTree(treeRegistry, "MEGA_SPRUCE", ConfiguredFeatures.MEGA_SPRUCE); + injectTree(treeRegistry, "CRIMSON_FUNGUS", ConfiguredFeatures.CRIMSON_FUNGI); + injectTree(treeRegistry, "WARPED_FUNGUS", ConfiguredFeatures.WARPED_FUNGI); + } + + + private void injectTree(CheckedRegistry registry, String id, ConfiguredFeature tree) { + try { + registry.add(id, new FabricTree(tree)); + } catch(DuplicateEntryException ignore) { + } + } + } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/StateAccessor.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/StateAccessor.java new file mode 100644 index 000000000..8baa09158 --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/StateAccessor.java @@ -0,0 +1,17 @@ +package com.dfsek.terra.fabric.mixin; + +import net.minecraft.state.State; +import net.minecraft.state.property.Property; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.Map; +import java.util.function.Function; + +@Mixin(State.class) +public interface StateAccessor { + @Accessor + static Function, Comparable>, String> getPROPERTY_MAP_PRINTER() { + throw new UnsupportedOperationException(); + } +} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java new file mode 100644 index 000000000..1a4df9a36 --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java @@ -0,0 +1,45 @@ +package com.dfsek.terra.fabric.world; + +import com.dfsek.terra.api.math.vector.Vector3; +import com.dfsek.terra.api.platform.block.BlockType; +import com.dfsek.terra.fabric.world.block.FabricBlockData; +import com.dfsek.terra.fabric.world.block.FabricBlockType; +import com.dfsek.terra.fabric.world.block.data.FabricMultipleFacing; +import com.dfsek.terra.fabric.world.block.data.FabricOrientable; +import com.dfsek.terra.fabric.world.block.data.FabricSlab; +import com.dfsek.terra.fabric.world.block.data.FabricStairs; +import com.dfsek.terra.fabric.world.block.data.FabricWaterlogged; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.state.property.Properties; +import net.minecraft.util.math.BlockPos; + +import java.util.Arrays; + +public final class FabricAdapter { + public static BlockPos adapt(Vector3 v) { + return new BlockPos(v.getBlockX(), v.getBlockY(), v.getBlockZ()); + } + + public static Vector3 adapt(BlockPos pos) { + return new Vector3(pos.getX(), pos.getY(), pos.getZ()); + } + + public static FabricBlockData adapt(BlockState state) { + if(state.contains(Properties.STAIR_SHAPE)) return new FabricStairs(state); + + if(state.contains(Properties.SLAB_TYPE)) return new FabricSlab(state); + + if(state.contains(Properties.AXIS)) return new FabricOrientable(state); + + if(state.getProperties().containsAll(Arrays.asList(Properties.NORTH, Properties.SOUTH, Properties.EAST, Properties.WEST))) + return new FabricMultipleFacing(state); + if(state.contains(Properties.WATERLOGGED)) return new FabricWaterlogged(state); + return new FabricBlockData(state); + } + + public static BlockType adapt(Block block) { + return new FabricBlockType(block); + } + +} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapters.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapters.java deleted file mode 100644 index a65e456d5..000000000 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapters.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.dfsek.terra.fabric.world; - -import com.dfsek.terra.api.math.vector.Vector3; -import net.minecraft.util.math.BlockPos; - -public final class FabricAdapters { - public static BlockPos fromVector(Vector3 v) { - return new BlockPos(v.getBlockX(), v.getBlockY(), v.getBlockZ()); - } - - public static Vector3 toVector(BlockPos pos) { - return new Vector3(pos.getX(), pos.getY(), pos.getZ()); - } -} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricWorldHandle.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricWorldHandle.java index 5633b6546..08e3e8e4a 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricWorldHandle.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricWorldHandle.java @@ -5,18 +5,10 @@ import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.entity.EntityType; import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.fabric.world.block.FabricBlockData; -import com.dfsek.terra.fabric.world.block.data.FabricMultipleFacing; -import com.dfsek.terra.fabric.world.block.data.FabricOrientable; -import com.dfsek.terra.fabric.world.block.data.FabricSlab; -import com.dfsek.terra.fabric.world.block.data.FabricStairs; -import com.dfsek.terra.fabric.world.block.data.FabricWaterlogged; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.block.BlockState; import net.minecraft.command.argument.BlockArgumentParser; -import net.minecraft.state.property.Properties; - -import java.util.Arrays; public class FabricWorldHandle implements WorldHandle { @Override @@ -35,17 +27,7 @@ public class FabricWorldHandle implements WorldHandle { try { BlockState state = parser.parse(true).getBlockState(); if(state == null) throw new IllegalArgumentException("Invalid data: " + data); - - if(state.contains(Properties.STAIR_SHAPE)) return new FabricStairs(state); - - if(state.contains(Properties.SLAB_TYPE)) return new FabricSlab(state); - - if(state.contains(Properties.AXIS)) return new FabricOrientable(state); - - if(state.getProperties().containsAll(Arrays.asList(Properties.NORTH, Properties.SOUTH, Properties.EAST, Properties.WEST))) - return new FabricMultipleFacing(state); - if(state.contains(Properties.WATERLOGGED)) return new FabricWaterlogged(state); - return new FabricBlockData(state); + return FabricAdapter.adapt(state); } catch(CommandSyntaxException e) { throw new IllegalArgumentException(e); } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlock.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlock.java index eab578d3a..5cfc04fab 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlock.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlock.java @@ -6,7 +6,7 @@ import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.BlockFace; import com.dfsek.terra.api.platform.block.BlockType; import com.dfsek.terra.api.platform.block.state.BlockState; -import com.dfsek.terra.fabric.world.FabricAdapters; +import com.dfsek.terra.fabric.world.FabricAdapter; import com.dfsek.terra.fabric.world.handles.world.FabricWorldAccess; import net.minecraft.util.math.BlockPos; import net.minecraft.world.WorldAccess; @@ -46,12 +46,12 @@ public class FabricBlock implements Block { @Override public boolean isEmpty() { - return false; + return getBlockData().isAir(); } @Override public Location getLocation() { - return FabricAdapters.toVector(delegate.position).toLocation(new FabricWorldAccess(delegate.worldAccess)); + return FabricAdapter.adapt(delegate.position).toLocation(new FabricWorldAccess(delegate.worldAccess)); } @Override diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlockData.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlockData.java index 643a849a3..5f3ea00a9 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlockData.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlockData.java @@ -2,7 +2,12 @@ package com.dfsek.terra.fabric.world.block; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.BlockType; +import com.dfsek.terra.fabric.mixin.StateAccessor; +import com.dfsek.terra.fabric.world.FabricAdapter; import net.minecraft.block.BlockState; +import net.minecraft.util.registry.Registry; + +import java.util.stream.Collectors; public class FabricBlockData implements BlockData { protected BlockState delegate; @@ -13,12 +18,12 @@ public class FabricBlockData implements BlockData { @Override public BlockType getBlockType() { - return null; + return FabricAdapter.adapt(delegate.getBlock()); } @Override public boolean matches(BlockData other) { - return false; + return delegate.getBlock() == ((FabricBlockData) other).delegate.getBlock(); } @Override @@ -32,12 +37,18 @@ public class FabricBlockData implements BlockData { @Override public String getAsString() { - return delegate.toString(); + StringBuilder data = new StringBuilder(Registry.BLOCK.getId(delegate.getBlock()).toString()); + if(!delegate.getEntries().isEmpty()) { + data.append('['); + data.append(delegate.getEntries().entrySet().stream().map(StateAccessor.getPROPERTY_MAP_PRINTER()).collect(Collectors.joining(","))); + data.append(']'); + } + return data.toString(); } @Override public boolean isAir() { - return false; + return delegate.isAir(); } @Override diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlockType.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlockType.java new file mode 100644 index 000000000..ae72e4caa --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlockType.java @@ -0,0 +1,40 @@ +package com.dfsek.terra.fabric.world.block; + +import com.dfsek.terra.api.platform.block.BlockData; +import com.dfsek.terra.api.platform.block.BlockType; +import com.dfsek.terra.fabric.world.FabricAdapter; +import net.minecraft.block.Block; + +public class FabricBlockType implements BlockType { + private final Block delegate; + + public FabricBlockType(Block delegate) { + this.delegate = delegate; + } + + @Override + public Block getHandle() { + return delegate; + } + + @Override + public BlockData getDefaultData() { + return FabricAdapter.adapt(delegate.getDefaultState()); + } + + @Override + public boolean isSolid() { + return delegate.getDefaultState().isOpaque(); + } + + @Override + public int hashCode() { + return delegate.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if(!(obj instanceof FabricBlockType)) return false; + return ((FabricBlockType) obj).delegate == delegate; + } +} diff --git a/platforms/fabric/src/main/resources/terra.mixins.json b/platforms/fabric/src/main/resources/terra.mixins.json index a6b050657..fda32e1f8 100644 --- a/platforms/fabric/src/main/resources/terra.mixins.json +++ b/platforms/fabric/src/main/resources/terra.mixins.json @@ -3,7 +3,9 @@ "minVersion": "0.8", "package": "com.dfsek.terra.fabric.mixin", "compatibilityLevel": "JAVA_8", - "mixins": [], + "mixins": [ + "StateAccessor" + ], "client": [ "GeneratorTypeAccessor" ], diff --git a/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java b/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java index 68a686669..05aadba56 100644 --- a/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java +++ b/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java @@ -121,7 +121,7 @@ public class StandalonePlugin implements TerraPlugin { public void register(TypeRegistry registry) { registry .registerLoader(BlockData.class, (t, o, l) -> worldHandle.createBlockData((String) o)) - .registerLoader(Biome.class, (t, o, l) -> new RawBiome(o.toString())) + .registerLoader(Biome.class, (t, o, l) -> new RawBiome(o.toString())); new GenericLoaders(this).register(registry); } From ac09e059fcdc2a67903dca5330b838d449f89efd Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 22 Feb 2021 21:02:59 -0700 Subject: [PATCH 16/95] caves on fabric actually work now --- .../dfsek/terra/fabric/world/features/PopulatorFeature.java | 1 + .../fabric/world/generator/FabricChunkGeneratorWrapper.java | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/features/PopulatorFeature.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/features/PopulatorFeature.java index 490a14c6b..501ae64f3 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/features/PopulatorFeature.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/features/PopulatorFeature.java @@ -27,6 +27,7 @@ public class PopulatorFeature extends Feature { FabricChunkGeneratorWrapper gen = (FabricChunkGeneratorWrapper) chunkGenerator; FabricChunkWorldAccess chunk = new FabricChunkWorldAccess(world, pos.getX() >> 4, pos.getZ() >> 4); FabricWorld world1 = new FabricWorld(world.toServerWorld(), new FabricChunkGenerator(chunkGenerator)); + gen.getCavePopulator().populate(new FabricSeededWorldAccess(world, world.getSeed(), chunkGenerator), chunk); gen.getStructurePopulator().populate(new FabricSeededWorldAccess(world, world.getSeed(), chunkGenerator), chunk); gen.getOrePopulator().populate(world1, chunk); gen.getTreePopulator().populate(world1, chunk); diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java index 1bb87f0e1..e595bbcb4 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java @@ -6,6 +6,7 @@ import com.dfsek.terra.fabric.TerraFabricPlugin; import com.dfsek.terra.fabric.world.TerraBiomeSource; import com.dfsek.terra.fabric.world.handles.world.FabricSeededWorldAccess; import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D; +import com.dfsek.terra.world.population.CavePopulator; import com.dfsek.terra.world.population.FloraPopulator; import com.dfsek.terra.world.population.OrePopulator; import com.dfsek.terra.world.population.StructurePopulator; @@ -48,6 +49,7 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements com.d private final OrePopulator orePopulator = new OrePopulator(TerraFabricPlugin.getInstance()); private final TreePopulator treePopulator = new TreePopulator(TerraFabricPlugin.getInstance()); private final StructurePopulator structurePopulator = new StructurePopulator(TerraFabricPlugin.getInstance()); + private final CavePopulator cavePopulator = new CavePopulator(TerraFabricPlugin.getInstance()); public TreePopulator getTreePopulator() { return treePopulator; @@ -65,6 +67,10 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements com.d return structurePopulator; } + public CavePopulator getCavePopulator() { + return cavePopulator; + } + public FabricChunkGeneratorWrapper(TerraBiomeSource biomeSource, long seed, ConfigPack configPack) { super(biomeSource, new StructuresConfig(false)); this.pack = configPack; From 415df211ed1c609c701b6afd54a951fdca6a031e Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 22 Feb 2021 21:41:15 -0700 Subject: [PATCH 17/95] fabric cleanup --- .../java/com/dfsek/terra/api/TerraPlugin.java | 2 - .../src/test/java/biome/DistributionTest.java | 5 -- .../bukkit/population/PopulationManager.java | 3 +- .../dfsek/terra/fabric/TerraFabricPlugin.java | 23 ++++--- .../block/state/FabricBlankBlockState.java | 50 ++++++++++++++ .../world/block/state/FabricBlockState.java | 67 +++++++++++++++++++ .../fabric/world/block/state/FabricSign.java | 27 ++++++++ .../fabric/world/handles/FabricWorld.java | 10 ++- .../com/dfsek/terra/StandalonePlugin.java | 5 -- 9 files changed, 167 insertions(+), 25 deletions(-) create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlankBlockState.java create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricSign.java diff --git a/common/src/main/java/com/dfsek/terra/api/TerraPlugin.java b/common/src/main/java/com/dfsek/terra/api/TerraPlugin.java index 707038f3f..fecee9f5a 100644 --- a/common/src/main/java/com/dfsek/terra/api/TerraPlugin.java +++ b/common/src/main/java/com/dfsek/terra/api/TerraPlugin.java @@ -22,8 +22,6 @@ import java.util.logging.Logger; public interface TerraPlugin extends LoaderRegistrar { WorldHandle getWorldHandle(); - boolean isEnabled(); - TerraWorld getWorld(World world); Logger getLogger(); diff --git a/common/src/test/java/biome/DistributionTest.java b/common/src/test/java/biome/DistributionTest.java index a6217010a..2c763f80a 100644 --- a/common/src/test/java/biome/DistributionTest.java +++ b/common/src/test/java/biome/DistributionTest.java @@ -64,11 +64,6 @@ public class DistributionTest { return null; } - @Override - public boolean isEnabled() { - return false; - } - @Override public TerraWorld getWorld(World world) { return null; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/population/PopulationManager.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/population/PopulationManager.java index fedefbaab..34ec49d68 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/population/PopulationManager.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/population/PopulationManager.java @@ -6,6 +6,7 @@ import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.util.FastRandom; import com.dfsek.terra.api.util.GlueList; import com.dfsek.terra.api.world.generation.TerraBlockPopulator; +import com.dfsek.terra.bukkit.TerraBukkitPlugin; import com.dfsek.terra.profiler.ProfileFuture; import com.dfsek.terra.profiler.WorldProfiler; import org.jetbrains.annotations.NotNull; @@ -40,7 +41,7 @@ public class PopulationManager implements TerraBlockPopulator { needsPop.add(new ChunkCoordinate(chunk)); int x = chunk.getX(); int z = chunk.getZ(); - if(main.isEnabled()) { + if(((TerraBukkitPlugin) main).isEnabled()) { for(int xi = -1; xi <= 1; xi++) { for(int zi = -1; zi <= 1; zi++) { if(xi == 0 && zi == 0) continue; diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index be376bfa4..67ac5bf6b 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -76,6 +76,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; +import java.util.logging.LogManager; import java.util.logging.Logger; public class TerraFabricPlugin implements TerraPlugin, ModInitializer { @@ -85,6 +86,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { private final EventManager eventManager = new TerraEventManager(this); + public static TerraFabricPlugin getInstance() { return instance; } @@ -93,8 +95,16 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { public static final ConfiguredFeature POPULATOR_CONFIGURED_FEATURE = POPULATOR_FEATURE.configure(FeatureConfig.DEFAULT).decorate(Decorator.NOPE.configure(NopeDecoratorConfig.INSTANCE)); private final GenericLoaders genericLoaders = new GenericLoaders(this); - private final Logger logger = Logger.getLogger("Terra"); - private final DebugLogger debugLogger = new DebugLogger(logger); + private final Logger logger; + private final DebugLogger debugLogger; + + { + Logger logger = Logger.getLogger("Terra"); + LogManager.getLogManager().addLogger(logger); + this.logger = logger; + debugLogger = new DebugLogger(logger); + } + private final ItemHandle itemHandle = new FabricItemHandle(); private final WorldHandle worldHandle = new FabricWorldHandle(); private final ConfigRegistry registry = new ConfigRegistry(); @@ -113,11 +123,6 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { return worldHandle; } - @Override - public boolean isEnabled() { - return false; - } - @Override public TerraWorld getWorld(World world) { return worldMap.computeIfAbsent(world.getSeed(), w -> { @@ -252,10 +257,6 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { public void onInitialize() { logger.setLevel(Level.INFO); MaterialSet set = MaterialSet.get(FabricAdapter.adapt(Blocks.GRASS_BLOCK), FabricAdapter.adapt(Blocks.STONE)); - logger.info("thing: " + set.contains(FabricAdapter.adapt(Blocks.STONE))); - logger.info("thing2: " + set.contains(FabricAdapter.adapt(Blocks.OAK_BUTTON))); - logger.info("thing3: " + Blocks.ACACIA_FENCE.getDefaultState().toString()); - logger.info("thing4: " + Blocks.ACACIA_FENCE.toString()); instance = this; diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlankBlockState.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlankBlockState.java new file mode 100644 index 000000000..eb7d18fb9 --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlankBlockState.java @@ -0,0 +1,50 @@ +package com.dfsek.terra.fabric.world.block.state; + +import com.dfsek.terra.api.platform.block.Block; +import com.dfsek.terra.api.platform.block.BlockData; +import com.dfsek.terra.api.platform.block.state.BlockState; +import com.dfsek.terra.fabric.world.block.FabricBlock; + +public class FabricBlankBlockState implements BlockState { + private final FabricBlock delegate; + + public FabricBlankBlockState(FabricBlock delegate) { + this.delegate = delegate; + } + + + @Override + public Block getHandle() { + return delegate; + } + + @Override + public Block getBlock() { + return delegate; + } + + @Override + public int getX() { + return delegate.getX(); + } + + @Override + public int getY() { + return delegate.getY(); + } + + @Override + public int getZ() { + return delegate.getZ(); + } + + @Override + public BlockData getBlockData() { + return delegate.getBlockData(); + } + + @Override + public boolean update(boolean applyPhysics) { + return true; + } +} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java new file mode 100644 index 000000000..99d179e86 --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java @@ -0,0 +1,67 @@ +package com.dfsek.terra.fabric.world.block.state; + +import com.dfsek.terra.api.platform.block.Block; +import com.dfsek.terra.api.platform.block.BlockData; +import com.dfsek.terra.api.platform.block.state.BlockState; +import com.dfsek.terra.fabric.world.FabricAdapter; +import com.dfsek.terra.fabric.world.block.FabricBlock; +import com.dfsek.terra.fabric.world.block.FabricBlockData; +import com.dfsek.terra.fabric.world.handles.FabricWorld; +import net.minecraft.block.ChestBlock; +import net.minecraft.block.SignBlock; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.SignBlockEntity; + +public class FabricBlockState implements BlockState { + protected final BlockEntity blockEntity; + + public FabricBlockState(BlockEntity blockEntity) { + this.blockEntity = blockEntity; + } + + public static FabricBlockState newInstance(Block block) { + net.minecraft.block.Block block1 = ((FabricBlockData) block.getBlockData()).getHandle().getBlock(); + if(block1 instanceof SignBlock) { + return new FabricSign((SignBlockEntity) ((SignBlock) block1).createBlockEntity(((FabricWorld) block.getLocation().getWorld()).getHandle().getWorld())); + } + if(block1 instanceof ChestBlock) { + return new FabricSign((SignBlockEntity) ((SignBlock) block1).createBlockEntity(((FabricWorld) block.getLocation().getWorld()).getHandle().getWorld())); + } + return null; + } + + @Override + public BlockEntity getHandle() { + return blockEntity; + } + + @Override + public Block getBlock() { + return new FabricBlock(blockEntity.getPos(), blockEntity.getWorld()); + } + + @Override + public int getX() { + return blockEntity.getPos().getX(); + } + + @Override + public int getY() { + return blockEntity.getPos().getY(); + } + + @Override + public int getZ() { + return blockEntity.getPos().getZ(); + } + + @Override + public BlockData getBlockData() { + return FabricAdapter.adapt(blockEntity.getCachedState()); + } + + @Override + public boolean update(boolean applyPhysics) { + return true; + } +} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricSign.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricSign.java new file mode 100644 index 000000000..e11b4f596 --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricSign.java @@ -0,0 +1,27 @@ +package com.dfsek.terra.fabric.world.block.state; + +import com.dfsek.terra.api.platform.block.state.Sign; +import net.minecraft.block.entity.SignBlockEntity; +import net.minecraft.text.LiteralText; +import org.jetbrains.annotations.NotNull; + +public class FabricSign extends FabricBlockState implements Sign { + public FabricSign(SignBlockEntity blockEntity) { + super(blockEntity); + } + + @Override + public @NotNull String[] getLines() { + return new String[0]; + } + + @Override + public @NotNull String getLine(int index) throws IndexOutOfBoundsException { + return ((SignBlockEntity) blockEntity).getTextOnRow(index).asString(); + } + + @Override + public void setLine(int index, @NotNull String line) throws IndexOutOfBoundsException { + ((SignBlockEntity) blockEntity).setTextOnRow(index, new LiteralText(line)); + } +} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java index df0be992d..6bd579f88 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java @@ -95,7 +95,7 @@ public class FabricWorld implements World { return null; } - private static final class Handle { + public static final class Handle { private final ServerWorld world; private final ChunkGenerator generator; @@ -103,5 +103,13 @@ public class FabricWorld implements World { this.world = world; this.generator = generator; } + + public ChunkGenerator getGenerator() { + return generator; + } + + public ServerWorld getWorld() { + return world; + } } } diff --git a/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java b/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java index 05aadba56..6a8762a12 100644 --- a/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java +++ b/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java @@ -43,11 +43,6 @@ public class StandalonePlugin implements TerraPlugin { return worldHandle; } - @Override - public boolean isEnabled() { - return true; - } - @Override public TerraWorld getWorld(World world) { return new TerraWorld(world, registry.get("DEFAULT"), this); From 98c1fea7fddfaf522dd758cc8b98be0d62c6e2c7 Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 22 Feb 2021 22:23:57 -0700 Subject: [PATCH 18/95] more fabric stuff --- .../buffer/items/BufferedStateManipulator.java | 1 + .../dfsek/terra/fabric/TerraFabricPlugin.java | 6 ++---- .../dfsek/terra/fabric/world/FabricAdapter.java | 6 ++++++ .../terra/fabric/world/block/FabricBlock.java | 3 ++- .../world/block/state/FabricBlockState.java | 16 +++++++++------- .../fabric/world/block/state/FabricSign.java | 5 +++-- .../terra/fabric/world/handles/FabricWorld.java | 9 ++++++++- .../handles/world/FabricSeededWorldAccess.java | 7 ++++++- .../world/handles/world/FabricWorldAccess.java | 7 ++++++- .../handles/world/FabricWorldChunkRegion.java | 8 +++++++- .../world/handles/world/FabricWorldHandle.java | 7 +++++++ 11 files changed, 57 insertions(+), 18 deletions(-) create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldHandle.java diff --git a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedStateManipulator.java b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedStateManipulator.java index 3edf9873d..ef3ef0501 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedStateManipulator.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedStateManipulator.java @@ -21,6 +21,7 @@ public class BufferedStateManipulator implements BufferedItem { state.update(false); } catch(Exception e) { main.getLogger().warning("Could not apply BlockState at " + origin + ": " + e.getMessage()); + main.getDebugLogger().stack(e); } } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index 67ac5bf6b..4c1aabf52 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -21,7 +21,6 @@ import com.dfsek.terra.api.registry.LockedRegistry; import com.dfsek.terra.api.transform.NotNullValidator; import com.dfsek.terra.api.transform.Transformer; import com.dfsek.terra.api.util.DebugLogger; -import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.tree.Tree; import com.dfsek.terra.config.GenericLoaders; @@ -31,7 +30,6 @@ import com.dfsek.terra.config.lang.Language; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.fabric.inventory.FabricItemHandle; import com.dfsek.terra.fabric.mixin.GeneratorTypeAccessor; -import com.dfsek.terra.fabric.world.FabricAdapter; import com.dfsek.terra.fabric.world.FabricBiome; import com.dfsek.terra.fabric.world.FabricTree; import com.dfsek.terra.fabric.world.FabricWorldHandle; @@ -103,6 +101,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { LogManager.getLogManager().addLogger(logger); this.logger = logger; debugLogger = new DebugLogger(logger); + debugLogger.setDebug(true); } private final ItemHandle itemHandle = new FabricItemHandle(); @@ -148,7 +147,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { @Override public boolean isDebug() { - return false; + return true; } @Override @@ -256,7 +255,6 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { @Override public void onInitialize() { logger.setLevel(Level.INFO); - MaterialSet set = MaterialSet.get(FabricAdapter.adapt(Blocks.GRASS_BLOCK), FabricAdapter.adapt(Blocks.STONE)); instance = this; diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java index 1a4df9a36..743c15550 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java @@ -9,10 +9,12 @@ import com.dfsek.terra.fabric.world.block.data.FabricOrientable; import com.dfsek.terra.fabric.world.block.data.FabricSlab; import com.dfsek.terra.fabric.world.block.data.FabricStairs; import com.dfsek.terra.fabric.world.block.data.FabricWaterlogged; +import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.state.property.Properties; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.WorldAccess; import java.util.Arrays; @@ -42,4 +44,8 @@ public final class FabricAdapter { return new FabricBlockType(block); } + public WorldAccess adapt(FabricWorldHandle worldHandle) { + return worldHandle.getWorld(); + } + } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlock.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlock.java index 5cfc04fab..93a1e9191 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlock.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlock.java @@ -7,6 +7,7 @@ import com.dfsek.terra.api.platform.block.BlockFace; import com.dfsek.terra.api.platform.block.BlockType; import com.dfsek.terra.api.platform.block.state.BlockState; import com.dfsek.terra.fabric.world.FabricAdapter; +import com.dfsek.terra.fabric.world.block.state.FabricBlockState; import com.dfsek.terra.fabric.world.handles.world.FabricWorldAccess; import net.minecraft.util.math.BlockPos; import net.minecraft.world.WorldAccess; @@ -30,7 +31,7 @@ public class FabricBlock implements Block { @Override public BlockState getState() { - return null; + return FabricBlockState.newInstance(this); } @Override diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java index 99d179e86..a076f5ec5 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java @@ -6,26 +6,27 @@ import com.dfsek.terra.api.platform.block.state.BlockState; import com.dfsek.terra.fabric.world.FabricAdapter; import com.dfsek.terra.fabric.world.block.FabricBlock; import com.dfsek.terra.fabric.world.block.FabricBlockData; -import com.dfsek.terra.fabric.world.handles.FabricWorld; -import net.minecraft.block.ChestBlock; +import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle; import net.minecraft.block.SignBlock; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.SignBlockEntity; +import net.minecraft.world.WorldAccess; public class FabricBlockState implements BlockState { protected final BlockEntity blockEntity; + private final WorldAccess worldAccess; - public FabricBlockState(BlockEntity blockEntity) { + public FabricBlockState(BlockEntity blockEntity, WorldAccess worldAccess) { this.blockEntity = blockEntity; + this.worldAccess = worldAccess; } public static FabricBlockState newInstance(Block block) { net.minecraft.block.Block block1 = ((FabricBlockData) block.getBlockData()).getHandle().getBlock(); if(block1 instanceof SignBlock) { - return new FabricSign((SignBlockEntity) ((SignBlock) block1).createBlockEntity(((FabricWorld) block.getLocation().getWorld()).getHandle().getWorld())); - } - if(block1 instanceof ChestBlock) { - return new FabricSign((SignBlockEntity) ((SignBlock) block1).createBlockEntity(((FabricWorld) block.getLocation().getWorld()).getHandle().getWorld())); + SignBlockEntity signBlockEntity = (SignBlockEntity) ((SignBlock) block1).createBlockEntity(((FabricWorldHandle) block.getLocation().getWorld()).getWorld()); + signBlockEntity.setLocation(null, FabricAdapter.adapt(block.getLocation().toVector())); + return new FabricSign(signBlockEntity, ((FabricWorldHandle) block.getLocation().getWorld()).getWorld()); } return null; } @@ -62,6 +63,7 @@ public class FabricBlockState implements BlockState { @Override public boolean update(boolean applyPhysics) { + (worldAccess).getChunk(blockEntity.getPos()).setBlockEntity(blockEntity.getPos(), blockEntity); return true; } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricSign.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricSign.java index e11b4f596..c5b3a291f 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricSign.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricSign.java @@ -3,11 +3,12 @@ package com.dfsek.terra.fabric.world.block.state; import com.dfsek.terra.api.platform.block.state.Sign; import net.minecraft.block.entity.SignBlockEntity; import net.minecraft.text.LiteralText; +import net.minecraft.world.WorldAccess; import org.jetbrains.annotations.NotNull; public class FabricSign extends FabricBlockState implements Sign { - public FabricSign(SignBlockEntity blockEntity) { - super(blockEntity); + public FabricSign(SignBlockEntity blockEntity, WorldAccess worldAccess) { + super(blockEntity, worldAccess); } @Override diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java index 6bd579f88..5318be6ca 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java @@ -9,13 +9,15 @@ import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.platform.world.generator.ChunkGenerator; import com.dfsek.terra.fabric.world.block.FabricBlock; import com.dfsek.terra.fabric.world.handles.chunk.FabricChunk; +import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.WorldAccess; import java.io.File; import java.util.UUID; -public class FabricWorld implements World { +public class FabricWorld implements World, FabricWorldHandle { private final Handle delegate; @@ -95,6 +97,11 @@ public class FabricWorld implements World { return null; } + @Override + public WorldAccess getWorld() { + return delegate.getWorld(); + } + public static final class Handle { private final ServerWorld world; private final ChunkGenerator generator; diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricSeededWorldAccess.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricSeededWorldAccess.java index 0f3c386d2..9446c1c79 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricSeededWorldAccess.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricSeededWorldAccess.java @@ -15,7 +15,7 @@ import net.minecraft.world.WorldAccess; import java.io.File; import java.util.UUID; -public class FabricSeededWorldAccess implements World { +public class FabricSeededWorldAccess implements World, FabricWorldHandle { private final Handle handle; @@ -94,6 +94,11 @@ public class FabricSeededWorldAccess implements World { return handle; } + @Override + public WorldAccess getWorld() { + return handle.worldAccess; + } + public static class Handle { private final WorldAccess worldAccess; private final long seed; diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java index 29d4c3fc2..d6bea52e0 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java @@ -17,7 +17,7 @@ import net.minecraft.world.WorldAccess; import java.io.File; import java.util.UUID; -public class FabricWorldAccess implements World { +public class FabricWorldAccess implements World, FabricWorldHandle { private final WorldAccess delegate; public FabricWorldAccess(WorldAccess delegate) { @@ -84,4 +84,9 @@ public class FabricWorldAccess implements World { public WorldAccess getHandle() { return delegate; } + + @Override + public WorldAccess getWorld() { + return delegate; + } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java index de898e032..cbe973289 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java @@ -11,11 +11,12 @@ import com.dfsek.terra.fabric.world.block.FabricBlock; import com.dfsek.terra.fabric.world.generator.FabricChunkGenerator; import net.minecraft.util.math.BlockPos; import net.minecraft.world.ChunkRegion; +import net.minecraft.world.WorldAccess; import java.io.File; import java.util.UUID; -public class FabricWorldChunkRegion implements World { +public class FabricWorldChunkRegion implements World, FabricWorldHandle { private final Handle delegate; public FabricWorldChunkRegion(ChunkRegion delegate, net.minecraft.world.gen.chunk.ChunkGenerator generator) { @@ -94,6 +95,11 @@ public class FabricWorldChunkRegion implements World { return null; } + @Override + public WorldAccess getWorld() { + return delegate.chunk; + } + public static final class Handle { private final ChunkRegion chunk; private final net.minecraft.world.gen.chunk.ChunkGenerator generator; diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldHandle.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldHandle.java new file mode 100644 index 000000000..7565201aa --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldHandle.java @@ -0,0 +1,7 @@ +package com.dfsek.terra.fabric.world.handles.world; + +import net.minecraft.world.WorldAccess; + +public interface FabricWorldHandle { + WorldAccess getWorld(); +} From 9c2b844290dee0cd42f3ea851ff0ad7dc704fe13 Mon Sep 17 00:00:00 2001 From: dfsek Date: Tue, 23 Feb 2021 15:57:27 -0700 Subject: [PATCH 19/95] preparations for Sponge API8 --- .../java/com/dfsek/terra/api/TerraPlugin.java | 6 +- .../terra/api/event/TerraEventManager.java | 12 +- .../api/platform/handle/WorldHandle.java | 8 +- .../loot/functions/EnchantFunction.java | 2 +- .../structures/script/StructureScript.java | 2 +- .../script/functions/LootFunction.java | 2 +- .../script/functions/StructureFunction.java | 4 +- .../buffer/items/BufferedLootApplication.java | 2 +- .../items/BufferedStateManipulator.java | 2 +- .../api/util/{ => logging}/DebugLogger.java | 4 +- .../terra/api/util/logging/JavaLogger.java | 24 +++ .../dfsek/terra/api/util/logging/Logger.java | 9 ++ .../com/dfsek/terra/config/PluginConfig.java | 4 +- .../com/dfsek/terra/config/lang/LangUtil.java | 10 +- .../dfsek/terra/config/pack/ConfigPack.java | 12 +- .../terra/registry/config/FloraRegistry.java | 2 +- .../terra/registry/config/TreeRegistry.java | 2 +- .../terra/registry/master/AddonRegistry.java | 10 +- .../src/test/java/biome/DistributionTest.java | 9 +- .../dfsek/terra/bukkit/TerraBukkitPlugin.java | 11 +- .../BukkitChunkGeneratorWrapper.java | 6 +- .../terra/bukkit/listeners/PaperListener.java | 2 +- .../bukkit/listeners/SpigotListener.java | 14 +- .../dfsek/terra/fabric/TerraFabricPlugin.java | 37 +++-- .../FabricChunkGeneratorWrapper.java | 2 +- .../com/dfsek/terra/StandalonePlugin.java | 25 +++- platforms/sponge/build.gradle.kts | 28 ++++ .../com/dfsek/terra/sponge/SpongeAdapter.java | 15 ++ .../com/dfsek/terra/sponge/SpongeLogger.java | 26 ++++ .../dfsek/terra/sponge/TerraSpongePlugin.java | 141 ++++++++++++++++++ .../terra/sponge/world/SpongeWorldHandle.java | 20 +++ .../world/block/data/SpongeBlockData.java | 43 ++++++ settings.gradle.kts | 1 + 33 files changed, 413 insertions(+), 84 deletions(-) rename common/src/main/java/com/dfsek/terra/api/util/{ => logging}/DebugLogger.java (90%) create mode 100644 common/src/main/java/com/dfsek/terra/api/util/logging/JavaLogger.java create mode 100644 common/src/main/java/com/dfsek/terra/api/util/logging/Logger.java create mode 100644 platforms/sponge/build.gradle.kts create mode 100644 platforms/sponge/src/main/java/com/dfsek/terra/sponge/SpongeAdapter.java create mode 100644 platforms/sponge/src/main/java/com/dfsek/terra/sponge/SpongeLogger.java create mode 100644 platforms/sponge/src/main/java/com/dfsek/terra/sponge/TerraSpongePlugin.java create mode 100644 platforms/sponge/src/main/java/com/dfsek/terra/sponge/world/SpongeWorldHandle.java create mode 100644 platforms/sponge/src/main/java/com/dfsek/terra/sponge/world/block/data/SpongeBlockData.java diff --git a/common/src/main/java/com/dfsek/terra/api/TerraPlugin.java b/common/src/main/java/com/dfsek/terra/api/TerraPlugin.java index fecee9f5a..07f9441e4 100644 --- a/common/src/main/java/com/dfsek/terra/api/TerraPlugin.java +++ b/common/src/main/java/com/dfsek/terra/api/TerraPlugin.java @@ -7,14 +7,14 @@ import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.registry.CheckedRegistry; import com.dfsek.terra.api.registry.LockedRegistry; -import com.dfsek.terra.api.util.DebugLogger; +import com.dfsek.terra.api.util.logging.DebugLogger; +import com.dfsek.terra.api.util.logging.Logger; import com.dfsek.terra.config.PluginConfig; import com.dfsek.terra.config.lang.Language; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.world.TerraWorld; import java.io.File; -import java.util.logging.Logger; /** * Represents a Terra mod/plugin instance. @@ -24,7 +24,7 @@ public interface TerraPlugin extends LoaderRegistrar { TerraWorld getWorld(World world); - Logger getLogger(); + Logger logger(); PluginConfig getTerraConfig(); diff --git a/common/src/main/java/com/dfsek/terra/api/event/TerraEventManager.java b/common/src/main/java/com/dfsek/terra/api/event/TerraEventManager.java index c25b5c1ee..493efa364 100644 --- a/common/src/main/java/com/dfsek/terra/api/event/TerraEventManager.java +++ b/common/src/main/java/com/dfsek/terra/api/event/TerraEventManager.java @@ -47,15 +47,15 @@ public class TerraEventManager implements EventManager { } catch(InvocationTargetException e) { StringWriter writer = new StringWriter(); e.getTargetException().printStackTrace(new PrintWriter(writer)); - main.getLogger().warning("Exception occurred during event handling:"); - main.getLogger().warning(writer.toString()); - main.getLogger().warning("Report this to the maintainers of " + listenerHolder.method.getName()); + main.logger().warning("Exception occurred during event handling:"); + main.logger().warning(writer.toString()); + main.logger().warning("Report this to the maintainers of " + listenerHolder.method.getName()); } catch(Exception e) { StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); - main.getLogger().warning("Exception occurred during event handling:"); - main.getLogger().warning(writer.toString()); - main.getLogger().warning("Report this to the maintainers of " + listenerHolder.method.getName()); + main.logger().warning("Exception occurred during event handling:"); + main.logger().warning(writer.toString()); + main.logger().warning("Report this to the maintainers of " + listenerHolder.method.getName()); } } ); diff --git a/common/src/main/java/com/dfsek/terra/api/platform/handle/WorldHandle.java b/common/src/main/java/com/dfsek/terra/api/platform/handle/WorldHandle.java index 8e6f4e251..f4ce3096b 100644 --- a/common/src/main/java/com/dfsek/terra/api/platform/handle/WorldHandle.java +++ b/common/src/main/java/com/dfsek/terra/api/platform/handle/WorldHandle.java @@ -8,9 +8,13 @@ import com.dfsek.terra.api.platform.entity.EntityType; * Interface to be implemented for world manipulation. */ public interface WorldHandle { - void setBlockData(Block block, BlockData data, boolean physics); + default void setBlockData(Block block, BlockData data, boolean physics) { + block.setBlockData(data, physics); + } - BlockData getBlockData(Block block); + default BlockData getBlockData(Block block) { + return block.getBlockData(); + } BlockData createBlockData(String data); diff --git a/common/src/main/java/com/dfsek/terra/api/structures/loot/functions/EnchantFunction.java b/common/src/main/java/com/dfsek/terra/api/structures/loot/functions/EnchantFunction.java index 555f0cf21..ff19b24c1 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/loot/functions/EnchantFunction.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/loot/functions/EnchantFunction.java @@ -55,7 +55,7 @@ public class EnchantFunction implements LootFunction { try { meta.addEnchantment(chosen, FastMath.max(lvl, 1)); } catch(IllegalArgumentException e) { - main.getLogger().warning("Attempted to enchant " + original.getType() + " with " + chosen + " at level " + FastMath.max(lvl, 1) + ", but an unexpected exception occurred! Usually this is caused by a misbehaving enchantment plugin."); + main.logger().warning("Attempted to enchant " + original.getType() + " with " + chosen + " at level " + FastMath.max(lvl, 1) + ", but an unexpected exception occurred! Usually this is caused by a misbehaving enchantment plugin."); } } original.setItemMeta(meta); diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java b/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java index c3d8a70fc..8d6795294 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java @@ -149,7 +149,7 @@ public class StructureScript { try { return !block.apply(arguments).getLevel().equals(Block.ReturnLevel.FAIL); } catch(RuntimeException e) { - main.getLogger().severe("Failed to generate structure at " + arguments.getBuffer().getOrigin() + ": " + e.getMessage()); + main.logger().severe("Failed to generate structure at " + arguments.getBuffer().getOrigin() + ": " + e.getMessage()); main.getDebugLogger().stack(e); return false; } diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/LootFunction.java b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/LootFunction.java index 09f1af284..353294c73 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/LootFunction.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/LootFunction.java @@ -45,7 +45,7 @@ public class LootFunction implements Function { LootTable table = registry.get(id); if(table == null) { - main.getLogger().severe("No such loot table " + id); + main.logger().severe("No such loot table " + id); return null; } diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/StructureFunction.java b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/StructureFunction.java index 6fdefff68..7b9b38830 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/StructureFunction.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/StructureFunction.java @@ -57,7 +57,7 @@ public class StructureFunction implements Function { String app = id.apply(implementationArguments, variableMap); StructureScript script = registry.get(app); if(script == null) { - main.getLogger().severe("No such structure " + app); + main.logger().severe("No such structure " + app); return null; } @@ -66,7 +66,7 @@ public class StructureFunction implements Function { try { rotation1 = Rotation.valueOf(rotString); } catch(IllegalArgumentException e) { - main.getLogger().severe("Invalid rotation " + rotString); + main.logger().severe("Invalid rotation " + rotString); return null; } diff --git a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedLootApplication.java b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedLootApplication.java index 482b242fd..34ef61853 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedLootApplication.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedLootApplication.java @@ -20,7 +20,7 @@ public class BufferedLootApplication implements BufferedItem { public void paste(Location origin) { BlockState data = origin.getBlock().getState(); if(!(data instanceof Container)) { - main.getLogger().severe("Failed to place loot at " + origin + "; block " + data + " is not container."); + main.logger().severe("Failed to place loot at " + origin + "; block " + data + " is not container."); return; } Container container = (Container) data; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedStateManipulator.java b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedStateManipulator.java index ef3ef0501..c486e02d5 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedStateManipulator.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedStateManipulator.java @@ -20,7 +20,7 @@ public class BufferedStateManipulator implements BufferedItem { state.applyState(data); state.update(false); } catch(Exception e) { - main.getLogger().warning("Could not apply BlockState at " + origin + ": " + e.getMessage()); + main.logger().warning("Could not apply BlockState at " + origin + ": " + e.getMessage()); main.getDebugLogger().stack(e); } } diff --git a/common/src/main/java/com/dfsek/terra/api/util/DebugLogger.java b/common/src/main/java/com/dfsek/terra/api/util/logging/DebugLogger.java similarity index 90% rename from common/src/main/java/com/dfsek/terra/api/util/DebugLogger.java rename to common/src/main/java/com/dfsek/terra/api/util/logging/DebugLogger.java index 35604d620..5236401f9 100644 --- a/common/src/main/java/com/dfsek/terra/api/util/DebugLogger.java +++ b/common/src/main/java/com/dfsek/terra/api/util/logging/DebugLogger.java @@ -1,6 +1,4 @@ -package com.dfsek.terra.api.util; - -import java.util.logging.Logger; +package com.dfsek.terra.api.util.logging; public class DebugLogger { private final Logger logger; diff --git a/common/src/main/java/com/dfsek/terra/api/util/logging/JavaLogger.java b/common/src/main/java/com/dfsek/terra/api/util/logging/JavaLogger.java new file mode 100644 index 000000000..8a8a62e56 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/util/logging/JavaLogger.java @@ -0,0 +1,24 @@ +package com.dfsek.terra.api.util.logging; + +public class JavaLogger implements Logger { + private final java.util.logging.Logger logger; + + public JavaLogger(java.util.logging.Logger logger) { + this.logger = logger; + } + + @Override + public void info(String message) { + logger.info(message); + } + + @Override + public void warning(String message) { + logger.warning(message); + } + + @Override + public void severe(String message) { + logger.severe(message); + } +} diff --git a/common/src/main/java/com/dfsek/terra/api/util/logging/Logger.java b/common/src/main/java/com/dfsek/terra/api/util/logging/Logger.java new file mode 100644 index 000000000..df812533f --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/util/logging/Logger.java @@ -0,0 +1,9 @@ +package com.dfsek.terra.api.util.logging; + +public interface Logger { + void info(String message); + + void warning(String message); + + void severe(String message); +} diff --git a/common/src/main/java/com/dfsek/terra/config/PluginConfig.java b/common/src/main/java/com/dfsek/terra/config/PluginConfig.java index b9815d4f1..e1112dcf4 100644 --- a/common/src/main/java/com/dfsek/terra/config/PluginConfig.java +++ b/common/src/main/java/com/dfsek/terra/config/PluginConfig.java @@ -7,6 +7,7 @@ import com.dfsek.tectonic.exception.ConfigException; import com.dfsek.tectonic.loading.ConfigLoader; import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.util.JarUtil; +import com.dfsek.terra.api.util.logging.Logger; import java.io.File; import java.io.FileInputStream; @@ -14,7 +15,6 @@ import java.io.IOException; import java.net.URISyntaxException; import java.time.Duration; import java.util.jar.JarFile; -import java.util.logging.Logger; @SuppressWarnings("FieldMayBeFinal") public class PluginConfig implements ConfigTemplate { @@ -63,7 +63,7 @@ public class PluginConfig implements ConfigTemplate { private int maxRecursion = 1000; public void load(TerraPlugin main) { - Logger logger = main.getLogger(); + Logger logger = main.logger(); logger.info("Loading config values"); try(FileInputStream file = new FileInputStream(new File(main.getDataFolder(), "config.yml"))) { ConfigLoader loader = new ConfigLoader(); diff --git a/common/src/main/java/com/dfsek/terra/config/lang/LangUtil.java b/common/src/main/java/com/dfsek/terra/config/lang/LangUtil.java index 2c8452d64..347a1e577 100644 --- a/common/src/main/java/com/dfsek/terra/config/lang/LangUtil.java +++ b/common/src/main/java/com/dfsek/terra/config/lang/LangUtil.java @@ -2,22 +2,20 @@ package com.dfsek.terra.config.lang; import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.util.logging.Logger; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.util.jar.JarFile; -import java.util.logging.Level; -import java.util.logging.Logger; import static com.dfsek.terra.api.util.JarUtil.copyResourcesToDirectory; public final class LangUtil { private static Language language; - private static Logger logger; public static void load(String langID, TerraPlugin main) { - logger = main.getLogger(); + Logger logger = main.logger(); File file = new File(main.getDataFolder(), "lang"); try(JarFile jar = new JarFile(new File(TerraPlugin.class.getProtectionDomain().getCodeSource().getLocation().toURI()))) { copyResourcesToDirectory(jar, "lang", file.toString()); @@ -41,10 +39,6 @@ public final class LangUtil { return language; } - public static void log(String messageID, Level level, String... args) { - language.getMessage(messageID).log(logger, level, args); - } - public static void send(String messageID, CommandSender sender, String... args) { language.getMessage(messageID).send(sender, args); } diff --git a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java index 2e88fda2b..dafcc73e4 100644 --- a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java +++ b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java @@ -34,7 +34,6 @@ import com.dfsek.terra.config.factories.TreeFactory; import com.dfsek.terra.config.fileloaders.FolderLoader; import com.dfsek.terra.config.fileloaders.Loader; import com.dfsek.terra.config.fileloaders.ZIPLoader; -import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.loaders.config.BufferedImageLoader; import com.dfsek.terra.config.loaders.config.biome.templates.source.BiomePipelineTemplate; import com.dfsek.terra.config.loaders.config.biome.templates.source.ImageProviderTemplate; @@ -79,7 +78,6 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.Supplier; -import java.util.logging.Level; import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -136,7 +134,7 @@ public class ConfigPack implements LoaderRegistrar { try { selfLoader.load(template, new FileInputStream(pack)); - main.getLogger().info("Loading config pack \"" + template.getID() + "\""); + main.logger().info("Loading config pack \"" + template.getID() + "\""); load(l, main); ConfigPackPostTemplate packPostTemplate = new ConfigPackPostTemplate(); @@ -147,7 +145,7 @@ public class ConfigPack implements LoaderRegistrar { throw new LoadException("No pack.yml file found in " + folder.getAbsolutePath(), e); } } catch(Exception e) { - main.getLogger().severe("Failed to load config pack from folder \"" + folder.getAbsolutePath() + "\""); + main.logger().severe("Failed to load config pack from folder \"" + folder.getAbsolutePath() + "\""); throw e; } } @@ -178,7 +176,7 @@ public class ConfigPack implements LoaderRegistrar { if(pack == null) throw new LoadException("No pack.yml file found in " + file.getName()); selfLoader.load(template, file.getInputStream(pack)); - main.getLogger().info("Loading config pack \"" + template.getID() + "\""); + main.logger().info("Loading config pack \"" + template.getID() + "\""); load(l, main); @@ -191,7 +189,7 @@ public class ConfigPack implements LoaderRegistrar { throw new LoadException("Unable to load pack.yml from ZIP file", e); } } catch(Exception e) { - main.getLogger().severe("Failed to load config pack from ZIP archive \"" + file.getName() + "\""); + main.logger().severe("Failed to load config pack from ZIP archive \"" + file.getName() + "\""); throw e; } } @@ -236,7 +234,7 @@ public class ConfigPack implements LoaderRegistrar { .open("biomes", ".yml").then(streams -> buildAll(new BiomeFactory(this), biomeRegistry, abstractConfigLoader.load(streams, () -> new BiomeTemplate(this, main)), main)).close(); main.getEventManager().callEvent(new ConfigPackPostLoadEvent(this)); - LangUtil.log("config-pack.loaded", Level.INFO, template.getID(), String.valueOf((System.nanoTime() - start) / 1000000D), template.getAuthor(), template.getVersion()); + main.logger().info("Loaded config pack \"" + template.getID() + "\" v" + template.getVersion() + " by " + template.getAuthor() + " in " + (System.nanoTime() - start) / 1000000D + "ms."); } public TerraBiome getBiome(String id) { diff --git a/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java index 5a3ce612b..71fd680cd 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/FloraRegistry.java @@ -59,7 +59,7 @@ public class FloraRegistry extends OpenRegistry { try { add(id, flora.call()); } catch(Exception e) { - main.getLogger().warning("Failed to load Flora item: " + id + ": " + e.getMessage()); + main.logger().warning("Failed to load Flora item: " + id + ": " + e.getMessage()); } } diff --git a/common/src/main/java/com/dfsek/terra/registry/config/TreeRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/TreeRegistry.java index fe5cddc6d..b786c64f4 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/TreeRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/TreeRegistry.java @@ -39,7 +39,7 @@ public class TreeRegistry extends OpenRegistry { try { add(id, new FractalTreeHolder(value)); } catch(Exception e) { - main.getLogger().warning("Unable to load tree " + id + ": " + e.getMessage()); + main.logger().warning("Unable to load tree " + id + ": " + e.getMessage()); } } diff --git a/common/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java b/common/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java index 6f8ae2663..9ee605061 100644 --- a/common/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java @@ -35,7 +35,7 @@ public class AddonRegistry extends OpenRegistry { public boolean add(String identifier, TerraAddon addon) { if(contains(identifier)) throw new IllegalArgumentException("Addon " + identifier + " is already registered."); addon.initialize(); - main.getLogger().info("Loaded addon " + addon.getName() + " v" + addon.getVersion() + ", by " + addon.getAuthor()); + main.logger().info("Loaded addon " + addon.getName() + " v" + addon.getVersion() + ", by " + addon.getAuthor()); return super.add(identifier, addon); } @@ -56,7 +56,7 @@ public class AddonRegistry extends OpenRegistry { try { for(File jar : addonsFolder.listFiles(file -> file.getName().endsWith(".jar"))) { - main.getLogger().info("Loading Addon(s) from: " + jar.getName()); + main.logger().info("Loading Addon(s) from: " + jar.getName()); for(Class addonClass : AddonClassLoader.fetchAddonClasses(jar)) { pool.add(new PreLoadAddon(addonClass)); } @@ -95,9 +95,9 @@ public class AddonRegistry extends OpenRegistry { addChecked(loadedAddon.getName(), loadedAddon); } catch(DuplicateEntryException e) { valid = false; - main.getLogger().severe("Duplicate addon ID; addon with ID " + loadedAddon.getName() + " is already loaded."); - main.getLogger().severe("Existing addon class: " + get(loadedAddon.getName()).getClass().getCanonicalName()); - main.getLogger().severe("Duplicate addon class: " + addonClass.getCanonicalName()); + main.logger().severe("Duplicate addon ID; addon with ID " + loadedAddon.getName() + " is already loaded."); + main.logger().severe("Existing addon class: " + get(loadedAddon.getName()).getClass().getCanonicalName()); + main.logger().severe("Duplicate addon class: " + addonClass.getCanonicalName()); } } } catch(AddonLoadException | IOException e) { diff --git a/common/src/test/java/biome/DistributionTest.java b/common/src/test/java/biome/DistributionTest.java index 2c763f80a..3a6d8d6df 100644 --- a/common/src/test/java/biome/DistributionTest.java +++ b/common/src/test/java/biome/DistributionTest.java @@ -18,8 +18,9 @@ import com.dfsek.terra.api.platform.world.Biome; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.registry.CheckedRegistry; import com.dfsek.terra.api.registry.LockedRegistry; -import com.dfsek.terra.api.util.DebugLogger; import com.dfsek.terra.api.util.collections.ProbabilityCollection; +import com.dfsek.terra.api.util.logging.DebugLogger; +import com.dfsek.terra.api.util.logging.JavaLogger; import com.dfsek.terra.api.util.seeded.NoiseSeeded; import com.dfsek.terra.api.world.biome.Generator; import com.dfsek.terra.api.world.biome.TerraBiome; @@ -70,8 +71,8 @@ public class DistributionTest { } @Override - public Logger getLogger() { - return Logger.getLogger("Terra"); + public com.dfsek.terra.api.util.logging.Logger logger() { + return new JavaLogger(Logger.getLogger("Terra")); } @Override @@ -126,7 +127,7 @@ public class DistributionTest { @Override public DebugLogger getDebugLogger() { - return new DebugLogger(Logger.getLogger("Terra")); + return new DebugLogger(new JavaLogger(Logger.getLogger("Terra"))); } @Override diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java index 785f85215..57f75d073 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java @@ -15,7 +15,9 @@ import com.dfsek.terra.api.platform.world.Biome; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.registry.CheckedRegistry; import com.dfsek.terra.api.registry.LockedRegistry; -import com.dfsek.terra.api.util.DebugLogger; +import com.dfsek.terra.api.util.logging.DebugLogger; +import com.dfsek.terra.api.util.logging.JavaLogger; +import com.dfsek.terra.api.util.logging.Logger; import com.dfsek.terra.api.world.generation.TerraChunkGenerator; import com.dfsek.terra.bukkit.command.command.TerraCommand; import com.dfsek.terra.bukkit.command.command.structure.LocateCommand; @@ -136,7 +138,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { @Override public void onEnable() { - debugLogger = new DebugLogger(getLogger()); + debugLogger = new DebugLogger(logger()); getLogger().info("Running on version " + BUKKIT_VERSION); if(BUKKIT_VERSION == BukkitVersion.UNKNOWN) { @@ -245,6 +247,11 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { return worldMap.computeIfAbsent(w, world -> new TerraWorld(w, worlds.get(w.getName()), this)); } + @Override + public Logger logger() { + return new JavaLogger(getLogger()); + } + @NotNull @Override public PluginConfig getTerraConfig() { diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java index 20e283332..278583560 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java @@ -7,7 +7,6 @@ import com.dfsek.terra.api.world.generation.TerraChunkGenerator; import com.dfsek.terra.bukkit.population.PopulationManager; import com.dfsek.terra.bukkit.world.BukkitAdapter; import com.dfsek.terra.bukkit.world.BukkitBiomeGrid; -import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.profiler.DataType; import com.dfsek.terra.profiler.Measurement; import com.dfsek.terra.world.TerraWorld; @@ -28,7 +27,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Random; -import java.util.logging.Level; import java.util.stream.Collectors; public class BukkitChunkGeneratorWrapper extends ChunkGenerator implements com.dfsek.terra.api.platform.world.generator.ChunkGenerator { @@ -76,8 +74,8 @@ public class BukkitChunkGeneratorWrapper extends ChunkGenerator implements com.d private void load(com.dfsek.terra.api.platform.world.World w) { try { popMan.loadBlocks(w); - } catch(FileNotFoundException e) { - LangUtil.log("warning.no-population", Level.WARNING); + } catch(FileNotFoundException ignore) { + } catch(IOException | ClassNotFoundException e) { e.printStackTrace(); } diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/PaperListener.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/PaperListener.java index fd79cde9b..94370dfb0 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/PaperListener.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/PaperListener.java @@ -32,7 +32,7 @@ public class PaperListener implements Listener { }, main); finder.run(); // Do this synchronously. } else { - main.getLogger().warning("No overrides are defined for \"" + name + "\""); + main.logger().warning("No overrides are defined for \"" + name + "\""); } } diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/SpigotListener.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/SpigotListener.java index 01748e1c5..87fb29b53 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/SpigotListener.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/SpigotListener.java @@ -47,7 +47,7 @@ public class SpigotListener implements Listener { }, main); finder.run(); // Do this synchronously so eye doesn't change direction several ticks after spawning. } else - main.getLogger().warning("No overrides are defined for Strongholds. Ender Signals will not work correctly."); + main.logger().warning("No overrides are defined for Strongholds. Ender Signals will not work correctly."); } } @@ -56,9 +56,9 @@ public class SpigotListener implements Listener { if(!TerraWorld.isTerraWorld(BukkitAdapter.adapt(e.getEntity().getWorld()))) return; if(!(e.getEntity() instanceof Villager)) return; if(((Villager) e.getEntity()).getProfession().equals(Villager.Profession.CARTOGRAPHER)) { - main.getLogger().severe("Prevented server crash by stopping Cartographer villager from spawning."); - main.getLogger().severe("Please upgrade to Paper, which has a StructureLocateEvent that fixes this issue"); - main.getLogger().severe("at the source, and doesn't require us to do stupid band-aids."); + main.logger().severe("Prevented server crash by stopping Cartographer villager from spawning."); + main.logger().severe("Please upgrade to Paper, which has a StructureLocateEvent that fixes this issue"); + main.logger().severe("at the source, and doesn't require us to do stupid band-aids."); e.setCancelled(true); // Cancel leveling if the villager is a Cartographer, to prevent crashing server. } } @@ -67,9 +67,9 @@ public class SpigotListener implements Listener { public void onCartographerLevel(VillagerCareerChangeEvent e) { if(!TerraWorld.isTerraWorld(BukkitAdapter.adapt(e.getEntity().getWorld()))) return; if(e.getProfession().equals(Villager.Profession.CARTOGRAPHER)) { - main.getLogger().severe("Prevented server crash by stopping Cartographer villager from spawning."); - main.getLogger().severe("Please upgrade to Paper, which has a StructureLocateEvent that fixes this issue"); - main.getLogger().severe("at the source, and doesn't require us to do stupid band-aids."); + main.logger().severe("Prevented server crash by stopping Cartographer villager from spawning."); + main.logger().severe("Please upgrade to Paper, which has a StructureLocateEvent that fixes this issue"); + main.logger().severe("at the source, and doesn't require us to do stupid band-aids."); e.getEntity().setProfession(Villager.Profession.NITWIT); // Give villager new profession to prevent server crash. e.setCancelled(true); } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index 4c1aabf52..1e99898bb 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -20,7 +20,8 @@ import com.dfsek.terra.api.registry.CheckedRegistry; import com.dfsek.terra.api.registry.LockedRegistry; import com.dfsek.terra.api.transform.NotNullValidator; import com.dfsek.terra.api.transform.Transformer; -import com.dfsek.terra.api.util.DebugLogger; +import com.dfsek.terra.api.util.logging.DebugLogger; +import com.dfsek.terra.api.util.logging.Logger; import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.tree.Tree; import com.dfsek.terra.config.GenericLoaders; @@ -73,9 +74,7 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; -import java.util.logging.Level; -import java.util.logging.LogManager; -import java.util.logging.Logger; + public class TerraFabricPlugin implements TerraPlugin, ModInitializer { @@ -93,16 +92,24 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { public static final ConfiguredFeature POPULATOR_CONFIGURED_FEATURE = POPULATOR_FEATURE.configure(FeatureConfig.DEFAULT).decorate(Decorator.NOPE.configure(NopeDecoratorConfig.INSTANCE)); private final GenericLoaders genericLoaders = new GenericLoaders(this); - private final Logger logger; - private final DebugLogger debugLogger; + private final Logger logger = new Logger() { + @Override + public void info(String message) { + + } + + @Override + public void warning(String message) { + + } + + @Override + public void severe(String message) { + + } + }; + private final DebugLogger debugLogger = new DebugLogger(logger); - { - Logger logger = Logger.getLogger("Terra"); - LogManager.getLogManager().addLogger(logger); - this.logger = logger; - debugLogger = new DebugLogger(logger); - debugLogger.setDebug(true); - } private final ItemHandle itemHandle = new FabricItemHandle(); private final WorldHandle worldHandle = new FabricWorldHandle(); @@ -131,7 +138,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { } @Override - public Logger getLogger() { + public Logger logger() { return logger; } @@ -254,8 +261,6 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { @Override public void onInitialize() { - logger.setLevel(Level.INFO); - instance = this; config = new File(FabricLoader.getInstance().getConfigDir().toFile(), "Terra"); diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java index e595bbcb4..d28a1cde9 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java @@ -76,7 +76,7 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements com.d this.pack = configPack; this.delegate = new DefaultChunkGenerator3D(configPack, TerraFabricPlugin.getInstance(), pack.getSamplerCache()); - delegate.getMain().getLogger().info("Loading world..."); + delegate.getMain().logger().info("Loading world..."); this.biomeSource = biomeSource; this.seed = seed; diff --git a/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java b/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java index 6a8762a12..a1dd2e4c9 100644 --- a/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java +++ b/platforms/region/src/main/java/com/dfsek/terra/StandalonePlugin.java @@ -12,7 +12,8 @@ import com.dfsek.terra.api.platform.world.Biome; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.registry.CheckedRegistry; import com.dfsek.terra.api.registry.LockedRegistry; -import com.dfsek.terra.api.util.DebugLogger; +import com.dfsek.terra.api.util.logging.DebugLogger; +import com.dfsek.terra.api.util.logging.JavaLogger; import com.dfsek.terra.config.GenericLoaders; import com.dfsek.terra.config.PluginConfig; import com.dfsek.terra.config.lang.LangUtil; @@ -49,8 +50,8 @@ public class StandalonePlugin implements TerraPlugin { } @Override - public Logger getLogger() { - return Logger.getLogger("Terra"); + public com.dfsek.terra.api.util.logging.Logger logger() { + return new JavaLogger(Logger.getLogger("Terra")); } @Override @@ -109,7 +110,23 @@ public class StandalonePlugin implements TerraPlugin { @Override public DebugLogger getDebugLogger() { - return new DebugLogger(Logger.getLogger("Terra")); + Logger logger = Logger.getLogger("Terra"); + return new DebugLogger(new com.dfsek.terra.api.util.logging.Logger() { + @Override + public void info(String message) { + logger.info(message); + } + + @Override + public void warning(String message) { + logger.warning(message); + } + + @Override + public void severe(String message) { + logger.severe(message); + } + }); } @Override diff --git a/platforms/sponge/build.gradle.kts b/platforms/sponge/build.gradle.kts new file mode 100644 index 000000000..9880b8c93 --- /dev/null +++ b/platforms/sponge/build.gradle.kts @@ -0,0 +1,28 @@ +import com.dfsek.terra.configureCommon + +plugins { + java + id("org.spongepowered.plugin").version("0.9.0") +} + +configureCommon() + +group = "com.dfsek.terra" + +repositories { + mavenCentral() + jcenter() +} + +dependencies { + "compileOnly"("org.spongepowered:spongeapi:7.2.0") + "shadedApi"(project(":common")) + "shadedImplementation"("org.yaml:snakeyaml:1.27") + "shadedImplementation"("com.googlecode.json-simple:json-simple:1.1.1") +} + +sponge { + plugin { + id = "terra" + } +} \ No newline at end of file diff --git a/platforms/sponge/src/main/java/com/dfsek/terra/sponge/SpongeAdapter.java b/platforms/sponge/src/main/java/com/dfsek/terra/sponge/SpongeAdapter.java new file mode 100644 index 000000000..781b5f91e --- /dev/null +++ b/platforms/sponge/src/main/java/com/dfsek/terra/sponge/SpongeAdapter.java @@ -0,0 +1,15 @@ +package com.dfsek.terra.sponge; + +import com.dfsek.terra.api.platform.block.BlockData; +import com.dfsek.terra.sponge.world.block.data.SpongeBlockData; +import org.spongepowered.api.block.BlockState; + +public final class SpongeAdapter { + public static BlockData adapt(BlockState state) { + return new SpongeBlockData(state); + } + + public static BlockState adapt(BlockData data) { + return ((SpongeBlockData) data).getHandle(); + } +} diff --git a/platforms/sponge/src/main/java/com/dfsek/terra/sponge/SpongeLogger.java b/platforms/sponge/src/main/java/com/dfsek/terra/sponge/SpongeLogger.java new file mode 100644 index 000000000..1ead85e8d --- /dev/null +++ b/platforms/sponge/src/main/java/com/dfsek/terra/sponge/SpongeLogger.java @@ -0,0 +1,26 @@ +package com.dfsek.terra.sponge; + +import com.dfsek.terra.api.util.logging.Logger; + +public class SpongeLogger implements Logger { + private final org.slf4j.Logger logger; + + public SpongeLogger(org.slf4j.Logger logger) { + this.logger = logger; + } + + @Override + public void info(String message) { + logger.info(message); + } + + @Override + public void warning(String message) { + logger.warn(message); + } + + @Override + public void severe(String message) { + logger.error(message); + } +} diff --git a/platforms/sponge/src/main/java/com/dfsek/terra/sponge/TerraSpongePlugin.java b/platforms/sponge/src/main/java/com/dfsek/terra/sponge/TerraSpongePlugin.java new file mode 100644 index 000000000..78baf45d5 --- /dev/null +++ b/platforms/sponge/src/main/java/com/dfsek/terra/sponge/TerraSpongePlugin.java @@ -0,0 +1,141 @@ +package com.dfsek.terra.sponge; + +import com.dfsek.tectonic.loading.TypeRegistry; +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.addons.TerraAddon; +import com.dfsek.terra.api.event.EventManager; +import com.dfsek.terra.api.event.TerraEventManager; +import com.dfsek.terra.api.platform.handle.ItemHandle; +import com.dfsek.terra.api.platform.handle.WorldHandle; +import com.dfsek.terra.api.platform.world.World; +import com.dfsek.terra.api.registry.CheckedRegistry; +import com.dfsek.terra.api.registry.LockedRegistry; +import com.dfsek.terra.api.util.logging.DebugLogger; +import com.dfsek.terra.config.PluginConfig; +import com.dfsek.terra.config.lang.Language; +import com.dfsek.terra.config.pack.ConfigPack; +import com.dfsek.terra.registry.master.AddonRegistry; +import com.dfsek.terra.registry.master.ConfigRegistry; +import com.dfsek.terra.sponge.world.SpongeWorldHandle; +import com.dfsek.terra.world.TerraWorld; +import com.google.inject.Inject; +import org.slf4j.Logger; +import org.spongepowered.api.config.ConfigDir; +import org.spongepowered.api.event.Listener; +import org.spongepowered.api.event.game.state.GameStartedServerEvent; +import org.spongepowered.api.plugin.Plugin; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; + +@Plugin(id = "terra", name = "Terra-Sponge", version = "", description = "Terra") +public class TerraSpongePlugin implements TerraPlugin { + private final ConfigRegistry configRegistry = new ConfigRegistry(); + private final CheckedRegistry packCheckedRegistry = new CheckedRegistry<>(configRegistry); + private final PluginConfig config = new PluginConfig(); + private final AddonRegistry addonRegistry = new AddonRegistry(this); + private final LockedRegistry addonLockedRegistry = new LockedRegistry<>(addonRegistry); + + private final SpongeWorldHandle spongeWorldHandle = new SpongeWorldHandle(); + + private final EventManager eventManager = new TerraEventManager(this); + + @Inject + @ConfigDir(sharedRoot = false) + private Path privateConfigDir; + + @Inject + private Logger logger; + + + @Listener + public void initialize(GameStartedServerEvent event) { + addonRegistry.loadAll(); + configRegistry.loadAll(this); + } + + @Override + public void register(TypeRegistry registry) { + + } + + @Override + public WorldHandle getWorldHandle() { + return spongeWorldHandle; + } + + @Override + public TerraWorld getWorld(World world) { + return null; + } + + @Override + public com.dfsek.terra.api.util.logging.Logger logger() { + return new SpongeLogger(logger); + } + + @Override + public PluginConfig getTerraConfig() { + return config; + } + + @Override + public File getDataFolder() { + return privateConfigDir.toFile(); + } + + @Override + public boolean isDebug() { + return true; + } + + @Override + public Language getLanguage() { + try { + return new Language(new File(getDataFolder(), "lang/en_us.yml")); + } catch(IOException e) { + throw new IllegalArgumentException(); + } + } + + @Override + public CheckedRegistry getConfigRegistry() { + return packCheckedRegistry; + } + + @Override + public LockedRegistry getAddons() { + return addonLockedRegistry; + } + + @Override + public boolean reload() { + return false; + } + + @Override + public ItemHandle getItemHandle() { + return null; + } + + @Override + public void saveDefaultConfig() { + + } + + @Override + public String platformName() { + return "Sponge"; + } + + @Override + public DebugLogger getDebugLogger() { + return null; + } + + @Override + public EventManager getEventManager() { + return eventManager; + } +} diff --git a/platforms/sponge/src/main/java/com/dfsek/terra/sponge/world/SpongeWorldHandle.java b/platforms/sponge/src/main/java/com/dfsek/terra/sponge/world/SpongeWorldHandle.java new file mode 100644 index 000000000..422229ba9 --- /dev/null +++ b/platforms/sponge/src/main/java/com/dfsek/terra/sponge/world/SpongeWorldHandle.java @@ -0,0 +1,20 @@ +package com.dfsek.terra.sponge.world; + +import com.dfsek.terra.api.platform.block.BlockData; +import com.dfsek.terra.api.platform.entity.EntityType; +import com.dfsek.terra.api.platform.handle.WorldHandle; +import com.dfsek.terra.sponge.SpongeAdapter; +import org.spongepowered.api.Sponge; +import org.spongepowered.api.block.BlockState; + +public class SpongeWorldHandle implements WorldHandle { + @Override + public BlockData createBlockData(String data) { + return SpongeAdapter.adapt(Sponge.getRegistry().getType(BlockState.class, data).orElseThrow(() -> new IllegalArgumentException("Invalid block data \"" + data + "\""))); + } + + @Override + public EntityType getEntity(String id) { + return null; + } +} diff --git a/platforms/sponge/src/main/java/com/dfsek/terra/sponge/world/block/data/SpongeBlockData.java b/platforms/sponge/src/main/java/com/dfsek/terra/sponge/world/block/data/SpongeBlockData.java new file mode 100644 index 000000000..9dc5dd3bd --- /dev/null +++ b/platforms/sponge/src/main/java/com/dfsek/terra/sponge/world/block/data/SpongeBlockData.java @@ -0,0 +1,43 @@ +package com.dfsek.terra.sponge.world.block.data; + +import com.dfsek.terra.api.platform.block.BlockData; +import com.dfsek.terra.api.platform.block.BlockType; +import org.spongepowered.api.block.BlockState; + +public class SpongeBlockData implements BlockData { + private final BlockState delegate; + + public SpongeBlockData(BlockState delegate) { + this.delegate = delegate; + } + + @Override + public BlockState getHandle() { + return delegate; + } + + @Override + public BlockType getBlockType() { + return null; + } + + @Override + public boolean matches(BlockData other) { + return false; + } + + @Override + public BlockData clone() { + return null; + } + + @Override + public String getAsString() { + return null; + } + + @Override + public boolean isAir() { + return false; + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 682f7912b..303d70045 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -12,6 +12,7 @@ include("common") include("platforms:bukkit") include("platforms:fabric") include("platforms:region") +include("platforms:sponge") pluginManagement { repositories { From 533380107b783fa6e479e66e9f9f927bf9f22f96 Mon Sep 17 00:00:00 2001 From: dfsek Date: Tue, 23 Feb 2021 17:29:39 -0700 Subject: [PATCH 20/95] working FabricSign --- .../bukkit/world/block/state/BukkitSign.java | 5 ++--- .../dfsek/terra/fabric/TerraFabricPlugin.java | 8 +++++--- .../world/block/state/FabricBlockState.java | 11 ++++++----- .../fabric/world/block/state/FabricSign.java | 18 +++++++++++++++++- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/state/BukkitSign.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/state/BukkitSign.java index 6b90ec18f..fe19fac78 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/state/BukkitSign.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/state/BukkitSign.java @@ -24,12 +24,11 @@ public class BukkitSign extends BukkitBlockState implements Sign { ((org.bukkit.block.Sign) getHandle()).setLine(index, line); } - @Override public void applyState(String state) { SerialState.parse(state).forEach((k, v) -> { - if(!v.startsWith("text")) throw new IllegalArgumentException("Invalid property: " + k); - setLine(Integer.parseInt(k) + 1, v.substring(4)); + if(!k.startsWith("text")) throw new IllegalArgumentException("Invalid property: " + k); + setLine(Integer.parseInt(k.substring(4)), v); }); } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index 1e99898bb..8dc0a1c06 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -67,6 +67,7 @@ import net.minecraft.world.gen.feature.FeatureConfig; import net.minecraft.world.gen.surfacebuilder.SurfaceBuilder; import net.minecraft.world.gen.surfacebuilder.TernarySurfaceConfig; import org.apache.commons.io.FileUtils; +import org.apache.logging.log4j.LogManager; import java.io.File; import java.io.IOException; @@ -93,19 +94,20 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { private final GenericLoaders genericLoaders = new GenericLoaders(this); private final Logger logger = new Logger() { + private final org.apache.logging.log4j.Logger logger = LogManager.getLogger(); @Override public void info(String message) { - + logger.info(message); } @Override public void warning(String message) { - + logger.warn(message); } @Override public void severe(String message) { - + logger.error(message); } }; private final DebugLogger debugLogger = new DebugLogger(logger); diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java index a076f5ec5..09c09ed95 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java @@ -7,7 +7,7 @@ import com.dfsek.terra.fabric.world.FabricAdapter; import com.dfsek.terra.fabric.world.block.FabricBlock; import com.dfsek.terra.fabric.world.block.FabricBlockData; import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle; -import net.minecraft.block.SignBlock; +import net.minecraft.block.AbstractSignBlock; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.SignBlockEntity; import net.minecraft.world.WorldAccess; @@ -23,10 +23,11 @@ public class FabricBlockState implements BlockState { public static FabricBlockState newInstance(Block block) { net.minecraft.block.Block block1 = ((FabricBlockData) block.getBlockData()).getHandle().getBlock(); - if(block1 instanceof SignBlock) { - SignBlockEntity signBlockEntity = (SignBlockEntity) ((SignBlock) block1).createBlockEntity(((FabricWorldHandle) block.getLocation().getWorld()).getWorld()); - signBlockEntity.setLocation(null, FabricAdapter.adapt(block.getLocation().toVector())); - return new FabricSign(signBlockEntity, ((FabricWorldHandle) block.getLocation().getWorld()).getWorld()); + WorldAccess worldAccess = ((FabricWorldHandle) block.getLocation().getWorld()).getWorld(); + + if(block1 instanceof AbstractSignBlock) { + SignBlockEntity signBlockEntity = (SignBlockEntity) worldAccess.getBlockEntity(FabricAdapter.adapt(block.getLocation().toVector())); + return new FabricSign(signBlockEntity, worldAccess); } return null; } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricSign.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricSign.java index c5b3a291f..382e05387 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricSign.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricSign.java @@ -1,5 +1,6 @@ package com.dfsek.terra.fabric.world.block.state; +import com.dfsek.terra.api.platform.block.state.SerialState; import com.dfsek.terra.api.platform.block.state.Sign; import net.minecraft.block.entity.SignBlockEntity; import net.minecraft.text.LiteralText; @@ -13,7 +14,14 @@ public class FabricSign extends FabricBlockState implements Sign { @Override public @NotNull String[] getLines() { - return new String[0]; + SignBlockEntity sign = (SignBlockEntity) blockEntity; + + return new String[] { + sign.getTextOnRow(0).asString(), + sign.getTextOnRow(1).asString(), + sign.getTextOnRow(2).asString(), + sign.getTextOnRow(3).asString() + }; } @Override @@ -25,4 +33,12 @@ public class FabricSign extends FabricBlockState implements Sign { public void setLine(int index, @NotNull String line) throws IndexOutOfBoundsException { ((SignBlockEntity) blockEntity).setTextOnRow(index, new LiteralText(line)); } + + @Override + public void applyState(String state) { + SerialState.parse(state).forEach((k, v) -> { + if(!k.startsWith("text")) throw new IllegalArgumentException("Invalid property: " + k); + setLine(Integer.parseInt(k.substring(4)), v); + }); + } } From df2acfaa4084b66d98964a7890912712dd7169ba Mon Sep 17 00:00:00 2001 From: dfsek Date: Tue, 23 Feb 2021 20:44:40 -0700 Subject: [PATCH 21/95] FabricMobSpawner --- .../fabric/mixin/MobSpawnerLogicAccessor.java | 12 ++ .../terra/fabric/world/FabricAdapter.java | 10 ++ .../terra/fabric/world/FabricWorldHandle.java | 8 +- .../world/block/state/FabricBlockState.java | 5 + .../world/block/state/FabricMobSpawner.java | 134 ++++++++++++++++++ .../fabric/world/entity/FabricEntity.java | 21 +++ .../fabric/world/entity/FabricEntityType.java | 16 +++ .../src/main/resources/terra.mixins.json | 1 + 8 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/MobSpawnerLogicAccessor.java create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricMobSpawner.java create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricEntity.java create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricEntityType.java diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/MobSpawnerLogicAccessor.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/MobSpawnerLogicAccessor.java new file mode 100644 index 000000000..15c213f38 --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/MobSpawnerLogicAccessor.java @@ -0,0 +1,12 @@ +package com.dfsek.terra.fabric.mixin; + +import net.minecraft.util.Identifier; +import net.minecraft.world.MobSpawnerLogic; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(MobSpawnerLogic.class) +public interface MobSpawnerLogicAccessor { + @Invoker + Identifier callGetEntityId(); +} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java index 743c15550..0c2b5857b 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java @@ -2,6 +2,7 @@ package com.dfsek.terra.fabric.world; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockType; +import com.dfsek.terra.api.platform.entity.EntityType; import com.dfsek.terra.fabric.world.block.FabricBlockData; import com.dfsek.terra.fabric.world.block.FabricBlockType; import com.dfsek.terra.fabric.world.block.data.FabricMultipleFacing; @@ -9,6 +10,7 @@ import com.dfsek.terra.fabric.world.block.data.FabricOrientable; import com.dfsek.terra.fabric.world.block.data.FabricSlab; import com.dfsek.terra.fabric.world.block.data.FabricStairs; import com.dfsek.terra.fabric.world.block.data.FabricWaterlogged; +import com.dfsek.terra.fabric.world.entity.FabricEntityType; import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -48,4 +50,12 @@ public final class FabricAdapter { return worldHandle.getWorld(); } + public static EntityType adapt(net.minecraft.entity.EntityType entityType) { + return new FabricEntityType(entityType); + } + + public static net.minecraft.entity.EntityType adapt(EntityType entityType) { + return ((FabricEntityType) entityType).getHandle(); + } + } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricWorldHandle.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricWorldHandle.java index 08e3e8e4a..cccdaa8ae 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricWorldHandle.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricWorldHandle.java @@ -9,6 +9,10 @@ import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.block.BlockState; import net.minecraft.command.argument.BlockArgumentParser; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; + +import java.util.Locale; public class FabricWorldHandle implements WorldHandle { @Override @@ -35,6 +39,8 @@ public class FabricWorldHandle implements WorldHandle { @Override public EntityType getEntity(String id) { - return null; + Identifier identifier = Identifier.tryParse(id); + if(identifier == null) identifier = Identifier.tryParse("minecraft:" + id.toLowerCase(Locale.ROOT)); + return FabricAdapter.adapt(Registry.ENTITY_TYPE.get(identifier)); } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java index 09c09ed95..24ede5b8f 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java @@ -8,7 +8,9 @@ import com.dfsek.terra.fabric.world.block.FabricBlock; import com.dfsek.terra.fabric.world.block.FabricBlockData; import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle; import net.minecraft.block.AbstractSignBlock; +import net.minecraft.block.SpawnerBlock; import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.MobSpawnerBlockEntity; import net.minecraft.block.entity.SignBlockEntity; import net.minecraft.world.WorldAccess; @@ -28,6 +30,9 @@ public class FabricBlockState implements BlockState { if(block1 instanceof AbstractSignBlock) { SignBlockEntity signBlockEntity = (SignBlockEntity) worldAccess.getBlockEntity(FabricAdapter.adapt(block.getLocation().toVector())); return new FabricSign(signBlockEntity, worldAccess); + } else if(block1 instanceof SpawnerBlock) { + MobSpawnerBlockEntity mobSpawnerBlockEntity = (MobSpawnerBlockEntity) worldAccess.getBlockEntity(FabricAdapter.adapt(block.getLocation().toVector())); + return new FabricMobSpawner(mobSpawnerBlockEntity, worldAccess); } return null; } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricMobSpawner.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricMobSpawner.java new file mode 100644 index 000000000..8f9f3d2ee --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricMobSpawner.java @@ -0,0 +1,134 @@ +package com.dfsek.terra.fabric.world.block.state; + +import com.dfsek.terra.api.platform.block.state.MobSpawner; +import com.dfsek.terra.api.platform.block.state.SerialState; +import com.dfsek.terra.api.platform.entity.EntityType; +import com.dfsek.terra.fabric.TerraFabricPlugin; +import com.dfsek.terra.fabric.mixin.MobSpawnerLogicAccessor; +import com.dfsek.terra.fabric.world.FabricAdapter; +import net.minecraft.block.entity.MobSpawnerBlockEntity; +import net.minecraft.util.registry.Registry; +import net.minecraft.world.WorldAccess; +import org.jetbrains.annotations.NotNull; + +public class FabricMobSpawner extends FabricBlockState implements MobSpawner { // TODO: finish implementation / refactor API because bukkit doesnt expose most of the stuff spawners can do + + + public FabricMobSpawner(MobSpawnerBlockEntity blockEntity, WorldAccess worldAccess) { + super(blockEntity, worldAccess); + } + + @Override + public EntityType getSpawnedType() { + return FabricAdapter.adapt(Registry.ENTITY_TYPE.get(((MobSpawnerLogicAccessor) ((MobSpawnerBlockEntity) blockEntity).getLogic()).callGetEntityId())); + } + + @Override + public void setSpawnedType(@NotNull EntityType creatureType) { + ((MobSpawnerBlockEntity) blockEntity).getLogic().setEntityId(FabricAdapter.adapt(creatureType)); + } + + @Override + public int getDelay() { + return 0; + } + + @Override + public void setDelay(int delay) { + + } + + @Override + public int getMinSpawnDelay() { + return 0; + } + + @Override + public void setMinSpawnDelay(int delay) { + + } + + @Override + public int getMaxSpawnDelay() { + return 0; + } + + @Override + public void setMaxSpawnDelay(int delay) { + + } + + @Override + public int getSpawnCount() { + return 0; + } + + @Override + public void setSpawnCount(int spawnCount) { + + } + + @Override + public int getMaxNearbyEntities() { + return 0; + } + + @Override + public void setMaxNearbyEntities(int maxNearbyEntities) { + + } + + @Override + public int getRequiredPlayerRange() { + return 0; + } + + @Override + public void setRequiredPlayerRange(int requiredPlayerRange) { + + } + + @Override + public int getSpawnRange() { + return 0; + } + + @Override + public void setSpawnRange(int spawnRange) { + + } + + @Override + public void applyState(String state) { + SerialState.parse(state).forEach((k, v) -> { + switch(k) { + case "type": + setSpawnedType(TerraFabricPlugin.getInstance().getWorldHandle().getEntity(v)); + return; + case "delay": + setDelay(Integer.parseInt(v)); + return; + case "min_delay": + setMinSpawnDelay(Integer.parseInt(v)); + return; + case "max_delay": + setMaxSpawnDelay(Integer.parseInt(v)); + return; + case "spawn_count": + setSpawnCount(Integer.parseInt(v)); + return; + case "spawn_range": + setSpawnRange(Integer.parseInt(v)); + return; + case "max_nearby": + setMaxNearbyEntities(Integer.parseInt(v)); + return; + case "required_player_range": + setRequiredPlayerRange(Integer.parseInt(v)); + return; + default: + throw new IllegalArgumentException("Invalid property: " + k); + } + }); + } +} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricEntity.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricEntity.java new file mode 100644 index 000000000..72cbf83b4 --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricEntity.java @@ -0,0 +1,21 @@ +package com.dfsek.terra.fabric.world.entity; + +import com.dfsek.terra.api.math.vector.Location; +import com.dfsek.terra.api.platform.entity.Entity; + +public class FabricEntity implements Entity { + @Override + public void sendMessage(String message) { + + } + + @Override + public Object getHandle() { + return null; + } + + @Override + public Location getLocation() { + return null; + } +} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricEntityType.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricEntityType.java new file mode 100644 index 000000000..31d6aceb1 --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricEntityType.java @@ -0,0 +1,16 @@ +package com.dfsek.terra.fabric.world.entity; + +import com.dfsek.terra.api.platform.entity.EntityType; + +public class FabricEntityType implements EntityType { + private final net.minecraft.entity.EntityType type; + + public FabricEntityType(net.minecraft.entity.EntityType type) { + this.type = type; + } + + @Override + public net.minecraft.entity.EntityType getHandle() { + return type; + } +} diff --git a/platforms/fabric/src/main/resources/terra.mixins.json b/platforms/fabric/src/main/resources/terra.mixins.json index fda32e1f8..6bf2e183f 100644 --- a/platforms/fabric/src/main/resources/terra.mixins.json +++ b/platforms/fabric/src/main/resources/terra.mixins.json @@ -4,6 +4,7 @@ "package": "com.dfsek.terra.fabric.mixin", "compatibilityLevel": "JAVA_8", "mixins": [ + "MobSpawnerLogicAccessor", "StateAccessor" ], "client": [ From 4171768cc9f7950b3e579db12599eafc0b0ca2ba Mon Sep 17 00:00:00 2001 From: dfsek Date: Tue, 23 Feb 2021 22:33:08 -0700 Subject: [PATCH 22/95] semi working fabric inventories --- .../terra/api/structures/loot/LootTable.java | 1 + .../buffer/items/BufferedLootApplication.java | 1 + .../dfsek/terra/fabric/TerraFabricPlugin.java | 2 +- .../fabric/inventory/FabricInventory.java | 39 +++++++++++++++++++ .../terra/fabric/inventory/FabricItem.java | 27 +++++++++++++ .../fabric/inventory/FabricItemHandle.java | 10 ++++- .../fabric/inventory/FabricItemStack.java | 18 +++++++-- .../fabric/mixin/GeneratorTypeAccessor.java | 4 +- .../terra/fabric/world/FabricAdapter.java | 15 +++++++ .../world/block/state/FabricBlockState.java | 7 +++- .../world/block/state/FabricContainer.java | 19 +++++++++ 11 files changed, 134 insertions(+), 9 deletions(-) create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricInventory.java create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItem.java create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricContainer.java diff --git a/common/src/main/java/com/dfsek/terra/api/structures/loot/LootTable.java b/common/src/main/java/com/dfsek/terra/api/structures/loot/LootTable.java index f5da89b65..163984c90 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/loot/LootTable.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/loot/LootTable.java @@ -62,6 +62,7 @@ public class LootTable { newStack.setAmount(1); int slot = r.nextInt(i.getSize()); ItemStack slotItem = i.getItem(slot); + System.out.println("attempt: " + (slotItem == null ? null : slotItem.getHandle())); if(slotItem == null) { i.setItem(slot, newStack); stack.setAmount(stack.getAmount() - 1); diff --git a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedLootApplication.java b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedLootApplication.java index 34ef61853..403c7f40c 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedLootApplication.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedLootApplication.java @@ -25,5 +25,6 @@ public class BufferedLootApplication implements BufferedItem { } Container container = (Container) data; table.fillInventory(container.getInventory(), new FastRandom(origin.hashCode())); + data.update(false); } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index 8dc0a1c06..41291e2e1 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -286,7 +286,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { Registry.register(Registry.BIOME_SOURCE, new Identifier("terra:terra"), TerraBiomeSource.CODEC); if(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { - GeneratorTypeAccessor.getValues().add(new GeneratorType("terra") { + GeneratorTypeAccessor.getVALUES().add(new GeneratorType("terra") { @Override protected ChunkGenerator getChunkGenerator(Registry biomeRegistry, Registry chunkGeneratorSettingsRegistry, long seed) { ConfigPack pack = registry.get("DEFAULT"); diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricInventory.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricInventory.java new file mode 100644 index 000000000..140964686 --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricInventory.java @@ -0,0 +1,39 @@ +package com.dfsek.terra.fabric.inventory; + +import com.dfsek.terra.api.platform.inventory.Inventory; +import com.dfsek.terra.api.platform.inventory.ItemStack; +import com.dfsek.terra.fabric.world.FabricAdapter; +import net.minecraft.block.entity.LootableContainerBlockEntity; +import net.minecraft.item.Items; + +public class FabricInventory implements Inventory { + private final LootableContainerBlockEntity delegate; + + public FabricInventory(LootableContainerBlockEntity delegate) { + this.delegate = delegate; + } + + @Override + public net.minecraft.inventory.Inventory getHandle() { + return delegate; + } + + @Override + public int getSize() { + return delegate.size(); + } + + @Override + public ItemStack getItem(int slot) { + net.minecraft.item.ItemStack itemStack = delegate.getStack(slot); + System.out.println("item @ " + slot + " GET: " + itemStack); + return itemStack.getItem() == Items.AIR ? null : FabricAdapter.adapt(itemStack); + } + + @Override + public void setItem(int slot, ItemStack newStack) { + System.out.println("item @ " + slot + ": " + newStack.getHandle()); + delegate.setStack(slot, FabricAdapter.adapt(newStack)); + + } +} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItem.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItem.java new file mode 100644 index 000000000..40c683119 --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItem.java @@ -0,0 +1,27 @@ +package com.dfsek.terra.fabric.inventory; + +import com.dfsek.terra.api.platform.inventory.Item; +import com.dfsek.terra.api.platform.inventory.ItemStack; + +public class FabricItem implements Item { + private final net.minecraft.item.Item delegate; + + public FabricItem(net.minecraft.item.Item delegate) { + this.delegate = delegate; + } + + @Override + public net.minecraft.item.Item getHandle() { + return delegate; + } + + @Override + public ItemStack newItemStack(int amount) { + return new FabricItemStack(new net.minecraft.item.ItemStack(delegate, amount)); + } + + @Override + public double getMaxDurability() { + return delegate.getMaxDamage(); + } +} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemHandle.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemHandle.java index d487bd719..3900a67e7 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemHandle.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemHandle.java @@ -3,6 +3,10 @@ package com.dfsek.terra.fabric.inventory; import com.dfsek.terra.api.platform.handle.ItemHandle; import com.dfsek.terra.api.platform.inventory.Item; import com.dfsek.terra.api.platform.inventory.item.Enchantment; +import com.dfsek.terra.fabric.world.FabricAdapter; +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.command.argument.ItemStackArgumentType; import java.util.Collections; import java.util.Set; @@ -11,7 +15,11 @@ public class FabricItemHandle implements ItemHandle { @Override public Item createItem(String data) { - return null; + try { + return FabricAdapter.adapt(new ItemStackArgumentType().parse(new StringReader(data)).getItem()); + } catch(CommandSyntaxException e) { + throw new IllegalArgumentException("Invalid item data \"" + data + "\"", e); + } } @Override diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemStack.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemStack.java index 1db90510e..f5c414d2b 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemStack.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemStack.java @@ -5,7 +5,11 @@ import com.dfsek.terra.api.platform.inventory.ItemStack; import com.dfsek.terra.api.platform.inventory.item.ItemMeta; public class FabricItemStack implements ItemStack { - net.minecraft.item.ItemStack delegate; + private net.minecraft.item.ItemStack delegate; + + public FabricItemStack(net.minecraft.item.ItemStack delegate) { + this.delegate = delegate; + } @Override public int getAmount() { @@ -19,12 +23,18 @@ public class FabricItemStack implements ItemStack { @Override public Item getType() { - return null; + return new FabricItem(delegate.getItem()); } @Override public ItemStack clone() { - return null; + try { + FabricItemStack stack = (FabricItemStack) super.clone(); + stack.delegate = delegate; + return stack; + } catch(CloneNotSupportedException e) { + throw new Error(); + } } @Override @@ -38,7 +48,7 @@ public class FabricItemStack implements ItemStack { } @Override - public Object getHandle() { + public net.minecraft.item.ItemStack getHandle() { return delegate; } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/GeneratorTypeAccessor.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/GeneratorTypeAccessor.java index e251ebd59..707ad6f1e 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/GeneratorTypeAccessor.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/GeneratorTypeAccessor.java @@ -8,8 +8,8 @@ import java.util.List; @Mixin(GeneratorType.class) public interface GeneratorTypeAccessor { - @Accessor("VALUES") - static List getValues() { + @Accessor + static List getVALUES() { throw new AssertionError(); } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java index 0c2b5857b..b6105f262 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java @@ -3,6 +3,8 @@ package com.dfsek.terra.fabric.world; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockType; import com.dfsek.terra.api.platform.entity.EntityType; +import com.dfsek.terra.fabric.inventory.FabricItem; +import com.dfsek.terra.fabric.inventory.FabricItemStack; import com.dfsek.terra.fabric.world.block.FabricBlockData; import com.dfsek.terra.fabric.world.block.FabricBlockType; import com.dfsek.terra.fabric.world.block.data.FabricMultipleFacing; @@ -14,6 +16,8 @@ import com.dfsek.terra.fabric.world.entity.FabricEntityType; import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle; import net.minecraft.block.Block; import net.minecraft.block.BlockState; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.state.property.Properties; import net.minecraft.util.math.BlockPos; import net.minecraft.world.WorldAccess; @@ -58,4 +62,15 @@ public final class FabricAdapter { return ((FabricEntityType) entityType).getHandle(); } + public static ItemStack adapt(com.dfsek.terra.api.platform.inventory.ItemStack itemStack) { + return ((FabricItemStack) itemStack).getHandle(); + } + + public static com.dfsek.terra.api.platform.inventory.ItemStack adapt(ItemStack itemStack) { + return new FabricItemStack(itemStack); + } + + public static com.dfsek.terra.api.platform.inventory.Item adapt(Item item) { + return new FabricItem(item); + } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java index 24ede5b8f..333c7cde5 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java @@ -7,6 +7,7 @@ import com.dfsek.terra.fabric.world.FabricAdapter; import com.dfsek.terra.fabric.world.block.FabricBlock; import com.dfsek.terra.fabric.world.block.FabricBlockData; import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle; +import net.minecraft.block.AbstractChestBlock; import net.minecraft.block.AbstractSignBlock; import net.minecraft.block.SpawnerBlock; import net.minecraft.block.entity.BlockEntity; @@ -33,6 +34,10 @@ public class FabricBlockState implements BlockState { } else if(block1 instanceof SpawnerBlock) { MobSpawnerBlockEntity mobSpawnerBlockEntity = (MobSpawnerBlockEntity) worldAccess.getBlockEntity(FabricAdapter.adapt(block.getLocation().toVector())); return new FabricMobSpawner(mobSpawnerBlockEntity, worldAccess); + } else if(block1 instanceof AbstractChestBlock) { + BlockEntity abstractChestBlock = worldAccess.getBlockEntity(FabricAdapter.adapt(block.getLocation().toVector())); + System.out.println("inventory: " + block1); + return new FabricContainer(abstractChestBlock, worldAccess); } return null; } @@ -69,7 +74,7 @@ public class FabricBlockState implements BlockState { @Override public boolean update(boolean applyPhysics) { - (worldAccess).getChunk(blockEntity.getPos()).setBlockEntity(blockEntity.getPos(), blockEntity); + worldAccess.getChunk(blockEntity.getPos()).setBlockEntity(blockEntity.getPos(), blockEntity); return true; } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricContainer.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricContainer.java new file mode 100644 index 000000000..bca4f2dc0 --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricContainer.java @@ -0,0 +1,19 @@ +package com.dfsek.terra.fabric.world.block.state; + +import com.dfsek.terra.api.platform.block.state.Container; +import com.dfsek.terra.api.platform.inventory.Inventory; +import com.dfsek.terra.fabric.inventory.FabricInventory; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.LootableContainerBlockEntity; +import net.minecraft.world.WorldAccess; + +public class FabricContainer extends FabricBlockState implements Container { + public FabricContainer(BlockEntity blockEntity, WorldAccess worldAccess) { + super(blockEntity, worldAccess); + } + + @Override + public Inventory getInventory() { + return new FabricInventory(((LootableContainerBlockEntity) blockEntity)); + } +} From 83f981111a55b8cbae402e6fcda6f5faf08e5d2d Mon Sep 17 00:00:00 2001 From: dfsek Date: Tue, 23 Feb 2021 22:36:22 -0700 Subject: [PATCH 23/95] remove debug stuff --- .../src/main/java/com/dfsek/terra/api/injection/Injector.java | 4 ---- .../java/com/dfsek/terra/api/structures/loot/LootTable.java | 1 - .../com/dfsek/terra/fabric/inventory/FabricInventory.java | 2 -- 3 files changed, 7 deletions(-) diff --git a/common/src/main/java/com/dfsek/terra/api/injection/Injector.java b/common/src/main/java/com/dfsek/terra/api/injection/Injector.java index d3df1d554..8156ac142 100644 --- a/common/src/main/java/com/dfsek/terra/api/injection/Injector.java +++ b/common/src/main/java/com/dfsek/terra/api/injection/Injector.java @@ -25,11 +25,7 @@ public class Injector { for(Field field : ReflectionUtil.getFields(object.getClass())) { Inject inject = field.getAnnotation(Inject.class); if(inject == null) continue; - - System.out.println(field); - System.out.println("attempting to inject " + value.getClass() + " to " + field.getClass()); if(value.getClass().equals(field.getType()) || targets.contains(field.getType())) { - System.out.println("injecting..."); int mod = field.getModifiers(); if(Modifier.isFinal(mod)) { throw new InjectionException("Attempted to inject final field: " + field); diff --git a/common/src/main/java/com/dfsek/terra/api/structures/loot/LootTable.java b/common/src/main/java/com/dfsek/terra/api/structures/loot/LootTable.java index 163984c90..f5da89b65 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/loot/LootTable.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/loot/LootTable.java @@ -62,7 +62,6 @@ public class LootTable { newStack.setAmount(1); int slot = r.nextInt(i.getSize()); ItemStack slotItem = i.getItem(slot); - System.out.println("attempt: " + (slotItem == null ? null : slotItem.getHandle())); if(slotItem == null) { i.setItem(slot, newStack); stack.setAmount(stack.getAmount() - 1); diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricInventory.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricInventory.java index 140964686..3463ce06a 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricInventory.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricInventory.java @@ -26,7 +26,6 @@ public class FabricInventory implements Inventory { @Override public ItemStack getItem(int slot) { net.minecraft.item.ItemStack itemStack = delegate.getStack(slot); - System.out.println("item @ " + slot + " GET: " + itemStack); return itemStack.getItem() == Items.AIR ? null : FabricAdapter.adapt(itemStack); } @@ -34,6 +33,5 @@ public class FabricInventory implements Inventory { public void setItem(int slot, ItemStack newStack) { System.out.println("item @ " + slot + ": " + newStack.getHandle()); delegate.setStack(slot, FabricAdapter.adapt(newStack)); - } } From 5c0482e97278a4c9fa2bf18ec7ee0a35adc72351 Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 24 Feb 2021 01:33:19 -0700 Subject: [PATCH 24/95] more fabric stuff --- .../loot/functions/DamageFunction.java | 1 + .../loot/functions/EnchantFunction.java | 2 ++ .../structures/script/StructureScript.java | 1 + .../script/functions/BlockFunction.java | 4 +++- .../structure/buffer/StructureBuffer.java | 6 +++--- .../structure/buffer/items/BufferedBlock.java | 12 ++++++++++-- .../world/population/StructurePopulator.java | 1 + gradle/wrapper/gradle-wrapper.properties | 2 +- platforms/fabric/build.gradle.kts | 2 +- .../dfsek/terra/fabric/TerraFabricPlugin.java | 19 +++++++++++++------ .../fabric/inventory/FabricInventory.java | 1 - .../fabric/mixin/GeneratorTypeAccessor.java | 19 +++++++++++++++++++ .../world/block/state/FabricBlockState.java | 1 - .../fabric/world/handles/FabricWorld.java | 5 +++-- .../world/FabricSeededWorldAccess.java | 6 ++++-- .../handles/world/FabricWorldAccess.java | 11 +++++++++++ .../handles/world/FabricWorldChunkRegion.java | 8 +++++--- 17 files changed, 78 insertions(+), 23 deletions(-) diff --git a/common/src/main/java/com/dfsek/terra/api/structures/loot/functions/DamageFunction.java b/common/src/main/java/com/dfsek/terra/api/structures/loot/functions/DamageFunction.java index 704fdcfa8..158c2248d 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/loot/functions/DamageFunction.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/loot/functions/DamageFunction.java @@ -33,6 +33,7 @@ public class DamageFunction implements LootFunction { */ @Override public ItemStack apply(ItemStack original, Random r) { + if(!(original instanceof Damageable)) return original; double itemDurability = (r.nextDouble() * (max - min)) + min; Damageable damage = (Damageable) original.getItemMeta(); damage.setDamage((int) (original.getType().getMaxDurability() - (itemDurability / 100) * original.getType().getMaxDurability())); diff --git a/common/src/main/java/com/dfsek/terra/api/structures/loot/functions/EnchantFunction.java b/common/src/main/java/com/dfsek/terra/api/structures/loot/functions/EnchantFunction.java index ff19b24c1..50818d871 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/loot/functions/EnchantFunction.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/loot/functions/EnchantFunction.java @@ -35,6 +35,8 @@ public class EnchantFunction implements LootFunction { */ @Override public ItemStack apply(ItemStack original, Random r) { + if(original.getItemMeta() == null) return original; + double enchant = (r.nextDouble() * (max - min)) + min; List possible = new GlueList<>(); for(Enchantment ench : main.getItemHandle().getEnchantments()) { diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java b/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java index 8d6795294..573ac5451 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java @@ -123,6 +123,7 @@ public class StructureScript { private StructureBuffer computeBuffer(Location location, Random random, Rotation rotation) { try { return cache.get(location, () -> { + System.out.println("{" + FastMath.floorDiv(location.getBlockX(), 16) + ", " + FastMath.floorDiv(location.getBlockZ(), 16) + "} : " + cache.size() + " : " + location.hashCode()); StructureBuffer buf = new StructureBuffer(location); buf.setSucceeded(applyBlock(new TerraImplementationArguments(buf, rotation, random, 0))); return buf; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/BlockFunction.java b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/BlockFunction.java index 0373fe5fe..cf9c07ef5 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/BlockFunction.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/BlockFunction.java @@ -23,9 +23,11 @@ public class BlockFunction implements Function { private final Returnable x, y, z; private final Position position; private final Returnable overwrite; + private final TerraPlugin main; public BlockFunction(Returnable x, Returnable y, Returnable z, Returnable data, Returnable overwrite, TerraPlugin main, Position position) throws ParseException { this.position = position; + this.main = main; if(!(data instanceof ConstantExpression)) throw new ParseException("Block data must be constant", data.getPosition()); try { @@ -49,7 +51,7 @@ public class BlockFunction implements Function { RotationUtil.rotateVector(xz, arguments.getRotation()); RotationUtil.rotateBlockData(rot, arguments.getRotation().inverse()); - arguments.getBuffer().addItem(new BufferedBlock(rot, overwrite.apply(implementationArguments, variableMap)), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).doubleValue(), FastMath.roundToInt(xz.getZ())).toLocation(arguments.getBuffer().getOrigin().getWorld())); + arguments.getBuffer().addItem(new BufferedBlock(rot, overwrite.apply(implementationArguments, variableMap), main), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).doubleValue(), FastMath.roundToInt(xz.getZ())).toLocation(arguments.getBuffer().getOrigin().getWorld())); return null; } diff --git a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/StructureBuffer.java b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/StructureBuffer.java index 6ff3029c6..c95b9555e 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/StructureBuffer.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/StructureBuffer.java @@ -22,11 +22,11 @@ public class StructureBuffer implements Buffer { } public void paste(Chunk chunk) { - bufferedItemMap.forEach(((vector3, item) -> { - Location current = origin.clone().add(vector3); + bufferedItemMap.forEach(((location, item) -> { + Location current = origin.clone().add(location); if(FastMath.floorDiv(current.getBlockX(), 16) != chunk.getX() || FastMath.floorDiv(current.getBlockZ(), 16) != chunk.getZ()) return; - item.paste(origin.clone().add(vector3)); + item.paste(current); })); } diff --git a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedBlock.java b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedBlock.java index 932efbd15..efb706ea9 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedBlock.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedBlock.java @@ -1,5 +1,6 @@ package com.dfsek.terra.api.structures.structure.buffer.items; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.Block; import com.dfsek.terra.api.platform.block.BlockData; @@ -7,15 +8,22 @@ import com.dfsek.terra.api.platform.block.BlockData; public class BufferedBlock implements BufferedItem { private final BlockData data; private final boolean overwrite; + private final TerraPlugin main; - public BufferedBlock(BlockData data, boolean overwrite) { + public BufferedBlock(BlockData data, boolean overwrite, TerraPlugin main) { this.data = data; this.overwrite = overwrite; + this.main = main; } @Override public void paste(Location origin) { Block block = origin.getBlock(); - if(overwrite || block.isEmpty()) block.setBlockData(data, false); + try { + if(overwrite || block.isEmpty()) block.setBlockData(data, false); + } catch(RuntimeException e) { + main.logger().severe("Failed to place block at location " + origin + ": " + e.getMessage()); + main.getDebugLogger().stack(e); + } } } diff --git a/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java b/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java index ed46b15e3..2af261696 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java +++ b/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java @@ -42,6 +42,7 @@ public class StructurePopulator implements TerraBlockPopulator { if(!((UserDefinedBiome) provider.getBiome(spawn)).getConfig().getStructures().contains(conf)) continue; Random random = new FastRandom(MathUtil.getCarverChunkSeed(FastMath.floorDiv(spawn.getBlockX(), 16), FastMath.floorDiv(spawn.getBlockZ(), 16), world.getSeed())); + System.out.println("chunk: {" + chunk.getX() + ", " + chunk.getZ() + "}"); conf.getStructure().get(random).execute(spawn.setY(conf.getSpawnStart().get(random)), chunk, random, Rotation.fromDegrees(90 * random.nextInt(4))); } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6ca79a242..aec6aa17c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionPath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -org.gradle.jvmargs=-Xmx2048m \ No newline at end of file +org.gradle.jvmargs=-Xmx4096m \ No newline at end of file diff --git a/platforms/fabric/build.gradle.kts b/platforms/fabric/build.gradle.kts index 78d279159..78ec35ede 100644 --- a/platforms/fabric/build.gradle.kts +++ b/platforms/fabric/build.gradle.kts @@ -31,7 +31,7 @@ configure { } tasks.register("remapShadedJar") { - setProperty("input", file("build/libs/fabric-${version}-shaded.jar")) + setProperty("input", file("build/libs/Terra-fabric-${version}-shaded.jar")) setProperty("addNestedDependencies", false) setProperty("remapAccessWidener", true) } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index 41291e2e1..37a201fed 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -46,6 +46,7 @@ import net.fabricmc.api.ModInitializer; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.block.Blocks; import net.minecraft.client.world.GeneratorType; +import net.minecraft.text.LiteralText; import net.minecraft.util.Identifier; import net.minecraft.util.registry.BuiltinRegistries; import net.minecraft.util.registry.Registry; @@ -286,17 +287,23 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { Registry.register(Registry.BIOME_SOURCE, new Identifier("terra:terra"), TerraBiomeSource.CODEC); if(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { - GeneratorTypeAccessor.getVALUES().add(new GeneratorType("terra") { - @Override - protected ChunkGenerator getChunkGenerator(Registry biomeRegistry, Registry chunkGeneratorSettingsRegistry, long seed) { - ConfigPack pack = registry.get("DEFAULT"); - return new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed, pack), seed, pack); - } + registry.forEach(pack -> { + System.out.println(pack.getTemplate().getID()); + pack.getBiomeRegistry().forEach(b -> System.out.println(b.getID())); + final GeneratorType generatorType = new GeneratorType("terra." + pack.getTemplate().getID()) { + @Override + protected ChunkGenerator getChunkGenerator(Registry biomeRegistry, Registry chunkGeneratorSettingsRegistry, long seed) { + return new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed, pack), seed, pack); + } + }; + ((GeneratorTypeAccessor) generatorType).setTranslationKey(new LiteralText("Terra:" + pack.getTemplate().getID())); + GeneratorTypeAccessor.getVALUES().add(generatorType); }); } } + @Override public EventManager getEventManager() { return eventManager; diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricInventory.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricInventory.java index 3463ce06a..43fa95d9c 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricInventory.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricInventory.java @@ -31,7 +31,6 @@ public class FabricInventory implements Inventory { @Override public void setItem(int slot, ItemStack newStack) { - System.out.println("item @ " + slot + ": " + newStack.getHandle()); delegate.setStack(slot, FabricAdapter.adapt(newStack)); } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/GeneratorTypeAccessor.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/GeneratorTypeAccessor.java index 707ad6f1e..74fec5920 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/GeneratorTypeAccessor.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/GeneratorTypeAccessor.java @@ -1,10 +1,14 @@ package com.dfsek.terra.fabric.mixin; import net.minecraft.client.world.GeneratorType; +import net.minecraft.text.Text; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.gen.Accessor; import java.util.List; +import java.util.Map; +import java.util.Optional; @Mixin(GeneratorType.class) public interface GeneratorTypeAccessor { @@ -12,4 +16,19 @@ public interface GeneratorTypeAccessor { static List getVALUES() { throw new AssertionError(); } + + @Accessor + static Map, GeneratorType.ScreenProvider> getSCREEN_PROVIDERS() { + throw new UnsupportedOperationException(); + } + + @Mutable + @Accessor + static void setSCREEN_PROVIDERS(Map, GeneratorType.ScreenProvider> SCREEN_PROVIDERS) { + throw new UnsupportedOperationException(); + } + + @Mutable + @Accessor + void setTranslationKey(Text translationKey); } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java index 333c7cde5..2347f452f 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java @@ -36,7 +36,6 @@ public class FabricBlockState implements BlockState { return new FabricMobSpawner(mobSpawnerBlockEntity, worldAccess); } else if(block1 instanceof AbstractChestBlock) { BlockEntity abstractChestBlock = worldAccess.getBlockEntity(FabricAdapter.adapt(block.getLocation().toVector())); - System.out.println("inventory: " + block1); return new FabricContainer(abstractChestBlock, worldAccess); } return null; diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java index 5318be6ca..3c470f0a7 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java @@ -12,6 +12,7 @@ import com.dfsek.terra.fabric.world.handles.chunk.FabricChunk; import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.ServerWorldAccess; import net.minecraft.world.WorldAccess; import java.io.File; @@ -73,13 +74,13 @@ public class FabricWorld implements World, FabricWorldHandle { @Override public int hashCode() { - return delegate.generator.hashCode(); + return ((ServerWorldAccess) delegate.world).toServerWorld().hashCode(); } @Override public boolean equals(Object obj) { if(!(obj instanceof FabricWorld)) return false; - return ((FabricWorld) obj).delegate.generator.equals(delegate.generator); + return ((ServerWorldAccess) ((FabricWorld) obj).delegate.world).toServerWorld().equals(((ServerWorldAccess) delegate.world).toServerWorld()); } @Override diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricSeededWorldAccess.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricSeededWorldAccess.java index 9446c1c79..106d1e2a4 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricSeededWorldAccess.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricSeededWorldAccess.java @@ -10,6 +10,7 @@ import com.dfsek.terra.api.platform.world.generator.ChunkGenerator; import com.dfsek.terra.fabric.world.block.FabricBlock; import com.dfsek.terra.fabric.world.generator.FabricChunkGenerator; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.ServerWorldAccess; import net.minecraft.world.WorldAccess; import java.io.File; @@ -81,12 +82,13 @@ public class FabricSeededWorldAccess implements World, FabricWorldHandle { @Override public int hashCode() { - return handle.worldAccess.hashCode(); + return ((ServerWorldAccess) handle.worldAccess).toServerWorld().hashCode(); } @Override public boolean equals(Object obj) { - return super.equals(obj); + if(!(obj instanceof FabricSeededWorldAccess)) return false; + return ((ServerWorldAccess) ((FabricSeededWorldAccess) obj).handle.worldAccess).toServerWorld().equals(((ServerWorldAccess) handle.worldAccess).toServerWorld()); } @Override diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java index d6bea52e0..b7780f837 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java @@ -89,4 +89,15 @@ public class FabricWorldAccess implements World, FabricWorldHandle { public WorldAccess getWorld() { return delegate; } + + @Override + public int hashCode() { + return ((ServerWorldAccess) delegate).toServerWorld().hashCode(); + } + + @Override + public boolean equals(Object obj) { + if(!(obj instanceof FabricWorldAccess)) return false; + return ((ServerWorldAccess) ((FabricWorldAccess) obj).delegate).toServerWorld().equals(((ServerWorldAccess) delegate).toServerWorld()); + } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java index cbe973289..66c61e0d5 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java @@ -11,6 +11,7 @@ import com.dfsek.terra.fabric.world.block.FabricBlock; import com.dfsek.terra.fabric.world.generator.FabricChunkGenerator; import net.minecraft.util.math.BlockPos; import net.minecraft.world.ChunkRegion; +import net.minecraft.world.ServerWorldAccess; import net.minecraft.world.WorldAccess; import java.io.File; @@ -71,13 +72,14 @@ public class FabricWorldChunkRegion implements World, FabricWorldHandle { @Override public int hashCode() { - return delegate.generator.hashCode(); + return ((ServerWorldAccess) delegate.chunk).toServerWorld().hashCode(); } @Override public boolean equals(Object obj) { if(!(obj instanceof FabricWorldChunkRegion)) return false; - return ((FabricWorldChunkRegion) obj).delegate.generator.equals(delegate.generator); + return super.equals(obj); + //return ((ServerWorldAccess) ((FabricWorldChunkRegion) obj).delegate.chunk).toServerWorld().equals(((ServerWorldAccess) delegate.chunk).toServerWorld()); } @Override @@ -92,7 +94,7 @@ public class FabricWorldChunkRegion implements World, FabricWorldHandle { @Override public Object getHandle() { - return null; + return delegate; } @Override From 3c56813d6bf77a2acf6b6b714c8ca2bac565f34a Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 24 Feb 2021 02:00:47 -0700 Subject: [PATCH 25/95] cursed #equals --- .../buffer/items/BufferedLootApplication.java | 19 ++++++++++++------- .../items/BufferedStateManipulator.java | 2 +- .../world/population/StructurePopulator.java | 1 + .../world/features/PopulatorFeature.java | 6 +++--- .../fabric/world/handles/FabricWorld.java | 2 +- .../handles/world/FabricWorldChunkRegion.java | 2 +- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedLootApplication.java b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedLootApplication.java index 403c7f40c..5f69a6470 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedLootApplication.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedLootApplication.java @@ -18,13 +18,18 @@ public class BufferedLootApplication implements BufferedItem { @Override public void paste(Location origin) { - BlockState data = origin.getBlock().getState(); - if(!(data instanceof Container)) { - main.logger().severe("Failed to place loot at " + origin + "; block " + data + " is not container."); - return; + try { + BlockState data = origin.getBlock().getState(); + if(!(data instanceof Container)) { + main.logger().severe("Failed to place loot at " + origin + "; block " + data + " is not container."); + return; + } + Container container = (Container) data; + table.fillInventory(container.getInventory(), new FastRandom(origin.hashCode())); + data.update(false); + } catch(Exception e) { + main.logger().warning("Could not apply loot at " + origin + ": " + e.getMessage()); + main.getDebugLogger().stack(e); } - Container container = (Container) data; - table.fillInventory(container.getInventory(), new FastRandom(origin.hashCode())); - data.update(false); } } diff --git a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedStateManipulator.java b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedStateManipulator.java index c486e02d5..703ca2695 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedStateManipulator.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedStateManipulator.java @@ -15,8 +15,8 @@ public class BufferedStateManipulator implements BufferedItem { @Override public void paste(Location origin) { - BlockState state = origin.getBlock().getState(); try { + BlockState state = origin.getBlock().getState(); state.applyState(data); state.update(false); } catch(Exception e) { diff --git a/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java b/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java index 2af261696..e52195e48 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java +++ b/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java @@ -43,6 +43,7 @@ public class StructurePopulator implements TerraBlockPopulator { continue; Random random = new FastRandom(MathUtil.getCarverChunkSeed(FastMath.floorDiv(spawn.getBlockX(), 16), FastMath.floorDiv(spawn.getBlockZ(), 16), world.getSeed())); System.out.println("chunk: {" + chunk.getX() + ", " + chunk.getZ() + "}"); + System.out.println(world.getBlockAt(cx, 255, cz).getBlockData()); conf.getStructure().get(random).execute(spawn.setY(conf.getSpawnStart().get(random)), chunk, random, Rotation.fromDegrees(90 * random.nextInt(4))); } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/features/PopulatorFeature.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/features/PopulatorFeature.java index 501ae64f3..fdb39fe78 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/features/PopulatorFeature.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/features/PopulatorFeature.java @@ -4,7 +4,7 @@ import com.dfsek.terra.fabric.world.generator.FabricChunkGenerator; import com.dfsek.terra.fabric.world.generator.FabricChunkGeneratorWrapper; import com.dfsek.terra.fabric.world.handles.FabricWorld; import com.dfsek.terra.fabric.world.handles.chunk.FabricChunkWorldAccess; -import com.dfsek.terra.fabric.world.handles.world.FabricSeededWorldAccess; +import com.dfsek.terra.fabric.world.handles.world.FabricWorldAccess; import com.mojang.serialization.Codec; import net.minecraft.util.math.BlockPos; import net.minecraft.world.StructureWorldAccess; @@ -27,8 +27,8 @@ public class PopulatorFeature extends Feature { FabricChunkGeneratorWrapper gen = (FabricChunkGeneratorWrapper) chunkGenerator; FabricChunkWorldAccess chunk = new FabricChunkWorldAccess(world, pos.getX() >> 4, pos.getZ() >> 4); FabricWorld world1 = new FabricWorld(world.toServerWorld(), new FabricChunkGenerator(chunkGenerator)); - gen.getCavePopulator().populate(new FabricSeededWorldAccess(world, world.getSeed(), chunkGenerator), chunk); - gen.getStructurePopulator().populate(new FabricSeededWorldAccess(world, world.getSeed(), chunkGenerator), chunk); + gen.getCavePopulator().populate(new FabricWorldAccess(world), chunk); + gen.getStructurePopulator().populate(new FabricWorldAccess(world), chunk); gen.getOrePopulator().populate(world1, chunk); gen.getTreePopulator().populate(world1, chunk); gen.getFloraPopulator().populate(world1, chunk); diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java index 3c470f0a7..cf6a48df6 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java @@ -80,7 +80,7 @@ public class FabricWorld implements World, FabricWorldHandle { @Override public boolean equals(Object obj) { if(!(obj instanceof FabricWorld)) return false; - return ((ServerWorldAccess) ((FabricWorld) obj).delegate.world).toServerWorld().equals(((ServerWorldAccess) delegate.world).toServerWorld()); + return ((ServerWorldAccess) ((FabricWorld) obj).delegate.world).toServerWorld().equals(((ServerWorldAccess) delegate.world).toServerWorld()); // FIXME this method is cursed. } @Override diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java index 66c61e0d5..df769cfdf 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java @@ -78,7 +78,7 @@ public class FabricWorldChunkRegion implements World, FabricWorldHandle { @Override public boolean equals(Object obj) { if(!(obj instanceof FabricWorldChunkRegion)) return false; - return super.equals(obj); + return delegate.chunk.equals(((FabricWorldChunkRegion) obj).delegate.chunk); //return ((ServerWorldAccess) ((FabricWorldChunkRegion) obj).delegate.chunk).toServerWorld().equals(((ServerWorldAccess) delegate.chunk).toServerWorld()); } From bb6dcb3880944082adb4b22b13c54f56eb63617f Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 24 Feb 2021 08:51:35 -0700 Subject: [PATCH 26/95] fix structure buffer weirdness --- .../dfsek/terra/api/structures/script/StructureScript.java | 1 - .../api/structures/structure/buffer/StructureBuffer.java | 2 +- .../api/structures/structure/buffer/items/BufferedItem.java | 6 ++++++ .../dfsek/terra/world/population/StructurePopulator.java | 2 -- .../com/dfsek/terra/fabric/world/handles/FabricWorld.java | 2 +- .../fabric/world/handles/world/FabricWorldChunkRegion.java | 3 +-- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java b/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java index 573ac5451..8d6795294 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java @@ -123,7 +123,6 @@ public class StructureScript { private StructureBuffer computeBuffer(Location location, Random random, Rotation rotation) { try { return cache.get(location, () -> { - System.out.println("{" + FastMath.floorDiv(location.getBlockX(), 16) + ", " + FastMath.floorDiv(location.getBlockZ(), 16) + "} : " + cache.size() + " : " + location.hashCode()); StructureBuffer buf = new StructureBuffer(location); buf.setSucceeded(applyBlock(new TerraImplementationArguments(buf, rotation, random, 0))); return buf; diff --git a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/StructureBuffer.java b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/StructureBuffer.java index c95b9555e..7b4e49a2e 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/StructureBuffer.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/StructureBuffer.java @@ -26,7 +26,7 @@ public class StructureBuffer implements Buffer { Location current = origin.clone().add(location); if(FastMath.floorDiv(current.getBlockX(), 16) != chunk.getX() || FastMath.floorDiv(current.getBlockZ(), 16) != chunk.getZ()) return; - item.paste(current); + item.paste(chunk, current); })); } diff --git a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedItem.java b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedItem.java index a4cfa2e17..7d6ddef2c 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedItem.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/structure/buffer/items/BufferedItem.java @@ -1,7 +1,13 @@ package com.dfsek.terra.api.structures.structure.buffer.items; import com.dfsek.terra.api.math.vector.Location; +import com.dfsek.terra.api.platform.world.Chunk; public interface BufferedItem { void paste(Location origin); + + default void paste(Chunk chunk, Location origin) { + origin.setWorld(chunk.getWorld()); // Fabric weirdness + paste(origin); + } } diff --git a/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java b/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java index e52195e48..ed46b15e3 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java +++ b/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java @@ -42,8 +42,6 @@ public class StructurePopulator implements TerraBlockPopulator { if(!((UserDefinedBiome) provider.getBiome(spawn)).getConfig().getStructures().contains(conf)) continue; Random random = new FastRandom(MathUtil.getCarverChunkSeed(FastMath.floorDiv(spawn.getBlockX(), 16), FastMath.floorDiv(spawn.getBlockZ(), 16), world.getSeed())); - System.out.println("chunk: {" + chunk.getX() + ", " + chunk.getZ() + "}"); - System.out.println(world.getBlockAt(cx, 255, cz).getBlockData()); conf.getStructure().get(random).execute(spawn.setY(conf.getSpawnStart().get(random)), chunk, random, Rotation.fromDegrees(90 * random.nextInt(4))); } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java index cf6a48df6..3c470f0a7 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java @@ -80,7 +80,7 @@ public class FabricWorld implements World, FabricWorldHandle { @Override public boolean equals(Object obj) { if(!(obj instanceof FabricWorld)) return false; - return ((ServerWorldAccess) ((FabricWorld) obj).delegate.world).toServerWorld().equals(((ServerWorldAccess) delegate.world).toServerWorld()); // FIXME this method is cursed. + return ((ServerWorldAccess) ((FabricWorld) obj).delegate.world).toServerWorld().equals(((ServerWorldAccess) delegate.world).toServerWorld()); } @Override diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java index df769cfdf..ffb12595a 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java @@ -78,8 +78,7 @@ public class FabricWorldChunkRegion implements World, FabricWorldHandle { @Override public boolean equals(Object obj) { if(!(obj instanceof FabricWorldChunkRegion)) return false; - return delegate.chunk.equals(((FabricWorldChunkRegion) obj).delegate.chunk); - //return ((ServerWorldAccess) ((FabricWorldChunkRegion) obj).delegate.chunk).toServerWorld().equals(((ServerWorldAccess) delegate.chunk).toServerWorld()); + return ((ServerWorldAccess) ((FabricWorldChunkRegion) obj).delegate.chunk).toServerWorld().equals(((ServerWorldAccess) delegate.chunk).toServerWorld()); } @Override From d29c1e572eb75542b54cc895a052cd32fc688217 Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 24 Feb 2021 09:17:44 -0700 Subject: [PATCH 27/95] basic Fabric pack selection --- .../java/com/dfsek/terra/fabric/TerraFabricPlugin.java | 4 +++- .../world/generator/FabricChunkGeneratorWrapper.java | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index 37a201fed..bc69f8ebc 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -36,6 +36,7 @@ import com.dfsek.terra.fabric.world.FabricTree; import com.dfsek.terra.fabric.world.FabricWorldHandle; import com.dfsek.terra.fabric.world.TerraBiomeSource; import com.dfsek.terra.fabric.world.features.PopulatorFeature; +import com.dfsek.terra.fabric.world.generator.FabricChunkGenerator; import com.dfsek.terra.fabric.world.generator.FabricChunkGeneratorWrapper; import com.dfsek.terra.registry.exception.DuplicateEntryException; import com.dfsek.terra.registry.master.AddonRegistry; @@ -134,9 +135,10 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { @Override public TerraWorld getWorld(World world) { + if(worldMap.size() > 1) System.out.println(worldMap.size()); return worldMap.computeIfAbsent(world.getSeed(), w -> { logger.info("Loading world " + w); - return new TerraWorld(world, getConfigRegistry().get("DEFAULT"), this); + return new TerraWorld(world, ((FabricChunkGeneratorWrapper) ((FabricChunkGenerator) world.getGenerator()).getHandle()).getPack(), this); }); } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java index d28a1cde9..302f3ee83 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java @@ -44,6 +44,9 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements com.d .apply(instance, instance.stable(FabricChunkGeneratorWrapper::new))); private final ConfigPack pack; + public ConfigPack getPack() { + return pack; + } private final FloraPopulator floraPopulator = new FloraPopulator(TerraFabricPlugin.getInstance()); private final OrePopulator orePopulator = new OrePopulator(TerraFabricPlugin.getInstance()); @@ -75,8 +78,8 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements com.d super(biomeSource, new StructuresConfig(false)); this.pack = configPack; - this.delegate = new DefaultChunkGenerator3D(configPack, TerraFabricPlugin.getInstance(), pack.getSamplerCache()); - delegate.getMain().logger().info("Loading world..."); + this.delegate = new DefaultChunkGenerator3D(pack, TerraFabricPlugin.getInstance(), pack.getSamplerCache()); + delegate.getMain().logger().info("Loading world with config pack " + pack.getTemplate().getID()); this.biomeSource = biomeSource; this.seed = seed; From 32746e8dd95c13ed0f0619e99ae7a1bc955ce324 Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 24 Feb 2021 09:40:56 -0700 Subject: [PATCH 28/95] target 1.16.5 for Fabric --- platforms/fabric/build.gradle.kts | 8 ++++---- .../java/com/dfsek/terra/fabric/TerraFabricPlugin.java | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/platforms/fabric/build.gradle.kts b/platforms/fabric/build.gradle.kts index 78ec35ede..afdf9c820 100644 --- a/platforms/fabric/build.gradle.kts +++ b/platforms/fabric/build.gradle.kts @@ -43,12 +43,12 @@ dependencies { // To change the versions see the gradle.properties file - "minecraft"("com.mojang:minecraft:1.16.4") - "mappings"("net.fabricmc:yarn:1.16.4+build.6:v2") - "modImplementation"("net.fabricmc:fabric-loader:0.10.6+build.214") + "minecraft"("com.mojang:minecraft:1.16.5") + "mappings"("net.fabricmc:yarn:1.16.5+build.5:v2") + "modImplementation"("net.fabricmc:fabric-loader:0.11.2") // Fabric API. This is technically optional, but you probably want it anyway. - "modImplementation"("net.fabricmc.fabric-api:fabric-api:0.25.1+build.416-1.16") + "modImplementation"("net.fabricmc.fabric-api:fabric-api:0.31.0+1.16") "compileOnly"("net.fabricmc:sponge-mixin:+") "annotationProcessor"("net.fabricmc:sponge-mixin:+") diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index bc69f8ebc..ca8d6f331 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -298,6 +298,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { return new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed, pack), seed, pack); } }; + //noinspection ConstantConditions ((GeneratorTypeAccessor) generatorType).setTranslationKey(new LiteralText("Terra:" + pack.getTemplate().getID())); GeneratorTypeAccessor.getVALUES().add(generatorType); }); From 2b114f225eb2154268c84c5d48ef502bf815522b Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 24 Feb 2021 09:54:20 -0700 Subject: [PATCH 29/95] bump version --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index cfe89a530..7b8933395 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,6 @@ import com.dfsek.terra.getGitHash -val versionObj = Version("4", "3", "0", true) +val versionObj = Version("5", "0", "0", true) allprojects { version = versionObj From 1637644bdd484e5b5091ae2e0c39c464904ef64c Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 24 Feb 2021 13:14:21 -0700 Subject: [PATCH 30/95] accesswideners B) --- platforms/fabric/build.gradle.kts | 1 + .../dfsek/terra/fabric/TerraFabricPlugin.java | 5 ++- .../fabric/mixin/GeneratorTypeAccessor.java | 34 ------------------- .../fabric/mixin/MobSpawnerLogicAccessor.java | 12 ------- .../terra/fabric/mixin/StateAccessor.java | 17 ---------- .../fabric/world/block/FabricBlockData.java | 4 +-- .../world/block/state/FabricMobSpawner.java | 3 +- .../src/main/resources/terra.accesswidener | 10 +++++- .../src/main/resources/terra.mixins.json | 3 -- 9 files changed, 15 insertions(+), 74 deletions(-) delete mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/GeneratorTypeAccessor.java delete mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/MobSpawnerLogicAccessor.java delete mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/StateAccessor.java diff --git a/platforms/fabric/build.gradle.kts b/platforms/fabric/build.gradle.kts index afdf9c820..79787e1bd 100644 --- a/platforms/fabric/build.gradle.kts +++ b/platforms/fabric/build.gradle.kts @@ -31,6 +31,7 @@ configure { } tasks.register("remapShadedJar") { + dependsOn("shadowJar") setProperty("input", file("build/libs/Terra-fabric-${version}-shaded.jar")) setProperty("addNestedDependencies", false) setProperty("remapAccessWidener", true) diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index ca8d6f331..358bac109 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -30,7 +30,6 @@ import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.Language; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.fabric.inventory.FabricItemHandle; -import com.dfsek.terra.fabric.mixin.GeneratorTypeAccessor; import com.dfsek.terra.fabric.world.FabricBiome; import com.dfsek.terra.fabric.world.FabricTree; import com.dfsek.terra.fabric.world.FabricWorldHandle; @@ -299,8 +298,8 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { } }; //noinspection ConstantConditions - ((GeneratorTypeAccessor) generatorType).setTranslationKey(new LiteralText("Terra:" + pack.getTemplate().getID())); - GeneratorTypeAccessor.getVALUES().add(generatorType); + generatorType.translationKey = (new LiteralText("Terra:" + pack.getTemplate().getID())); + GeneratorType.VALUES.add(generatorType); }); } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/GeneratorTypeAccessor.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/GeneratorTypeAccessor.java deleted file mode 100644 index 74fec5920..000000000 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/GeneratorTypeAccessor.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.dfsek.terra.fabric.mixin; - -import net.minecraft.client.world.GeneratorType; -import net.minecraft.text.Text; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.gen.Accessor; - -import java.util.List; -import java.util.Map; -import java.util.Optional; - -@Mixin(GeneratorType.class) -public interface GeneratorTypeAccessor { - @Accessor - static List getVALUES() { - throw new AssertionError(); - } - - @Accessor - static Map, GeneratorType.ScreenProvider> getSCREEN_PROVIDERS() { - throw new UnsupportedOperationException(); - } - - @Mutable - @Accessor - static void setSCREEN_PROVIDERS(Map, GeneratorType.ScreenProvider> SCREEN_PROVIDERS) { - throw new UnsupportedOperationException(); - } - - @Mutable - @Accessor - void setTranslationKey(Text translationKey); -} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/MobSpawnerLogicAccessor.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/MobSpawnerLogicAccessor.java deleted file mode 100644 index 15c213f38..000000000 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/MobSpawnerLogicAccessor.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.dfsek.terra.fabric.mixin; - -import net.minecraft.util.Identifier; -import net.minecraft.world.MobSpawnerLogic; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Invoker; - -@Mixin(MobSpawnerLogic.class) -public interface MobSpawnerLogicAccessor { - @Invoker - Identifier callGetEntityId(); -} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/StateAccessor.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/StateAccessor.java deleted file mode 100644 index 8baa09158..000000000 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/StateAccessor.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.dfsek.terra.fabric.mixin; - -import net.minecraft.state.State; -import net.minecraft.state.property.Property; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import java.util.Map; -import java.util.function.Function; - -@Mixin(State.class) -public interface StateAccessor { - @Accessor - static Function, Comparable>, String> getPROPERTY_MAP_PRINTER() { - throw new UnsupportedOperationException(); - } -} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlockData.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlockData.java index 5f3ea00a9..e2608cb2c 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlockData.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlockData.java @@ -2,9 +2,9 @@ package com.dfsek.terra.fabric.world.block; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.BlockType; -import com.dfsek.terra.fabric.mixin.StateAccessor; import com.dfsek.terra.fabric.world.FabricAdapter; import net.minecraft.block.BlockState; +import net.minecraft.state.State; import net.minecraft.util.registry.Registry; import java.util.stream.Collectors; @@ -40,7 +40,7 @@ public class FabricBlockData implements BlockData { StringBuilder data = new StringBuilder(Registry.BLOCK.getId(delegate.getBlock()).toString()); if(!delegate.getEntries().isEmpty()) { data.append('['); - data.append(delegate.getEntries().entrySet().stream().map(StateAccessor.getPROPERTY_MAP_PRINTER()).collect(Collectors.joining(","))); + data.append(delegate.getEntries().entrySet().stream().map(State.PROPERTY_MAP_PRINTER).collect(Collectors.joining(","))); data.append(']'); } return data.toString(); diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricMobSpawner.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricMobSpawner.java index 8f9f3d2ee..8486e20c9 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricMobSpawner.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricMobSpawner.java @@ -4,7 +4,6 @@ import com.dfsek.terra.api.platform.block.state.MobSpawner; import com.dfsek.terra.api.platform.block.state.SerialState; import com.dfsek.terra.api.platform.entity.EntityType; import com.dfsek.terra.fabric.TerraFabricPlugin; -import com.dfsek.terra.fabric.mixin.MobSpawnerLogicAccessor; import com.dfsek.terra.fabric.world.FabricAdapter; import net.minecraft.block.entity.MobSpawnerBlockEntity; import net.minecraft.util.registry.Registry; @@ -20,7 +19,7 @@ public class FabricMobSpawner extends FabricBlockState implements MobSpawner { / @Override public EntityType getSpawnedType() { - return FabricAdapter.adapt(Registry.ENTITY_TYPE.get(((MobSpawnerLogicAccessor) ((MobSpawnerBlockEntity) blockEntity).getLogic()).callGetEntityId())); + return FabricAdapter.adapt(Registry.ENTITY_TYPE.get(((MobSpawnerBlockEntity) blockEntity).getLogic().getEntityId())); } @Override diff --git a/platforms/fabric/src/main/resources/terra.accesswidener b/platforms/fabric/src/main/resources/terra.accesswidener index edfa21bd4..1b6dfe0be 100644 --- a/platforms/fabric/src/main/resources/terra.accesswidener +++ b/platforms/fabric/src/main/resources/terra.accesswidener @@ -2,5 +2,13 @@ accessWidener v1 named extendable method net/minecraft/client/world/GeneratorType (Ljava/lang/String;)V +accessible field net/minecraft/client/world/GeneratorType translationKey Lnet/minecraft/text/Text; +mutable field net/minecraft/client/world/GeneratorType translationKey Lnet/minecraft/text/Text; + +accessible field net/minecraft/client/world/GeneratorType VALUES Ljava/util/List; + accessible field net/minecraft/server/world/ServerWorld worldProperties Lnet/minecraft/world/level/ServerWorldProperties; -mutable field net/minecraft/server/world/ServerWorld worldProperties Lnet/minecraft/world/level/ServerWorldProperties; \ No newline at end of file + +accessible method net/minecraft/world/MobSpawnerLogic getEntityId ()Lnet/minecraft/util/Identifier; + +accessible field net/minecraft/state/State PROPERTY_MAP_PRINTER Ljava/util/function/Function; \ No newline at end of file diff --git a/platforms/fabric/src/main/resources/terra.mixins.json b/platforms/fabric/src/main/resources/terra.mixins.json index 6bf2e183f..b69106b5f 100644 --- a/platforms/fabric/src/main/resources/terra.mixins.json +++ b/platforms/fabric/src/main/resources/terra.mixins.json @@ -4,11 +4,8 @@ "package": "com.dfsek.terra.fabric.mixin", "compatibilityLevel": "JAVA_8", "mixins": [ - "MobSpawnerLogicAccessor", - "StateAccessor" ], "client": [ - "GeneratorTypeAccessor" ], "server": [], "injectors": { From 0fcc0f798c25dd81b31a42e52f4e61684f6340d9 Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 24 Feb 2021 13:59:25 -0700 Subject: [PATCH 31/95] fabric cleanup, move lang and config to common --- .../kotlin/com/dfsek/terra/CompilationConfig.kt | 11 +++++++++++ common/build.gradle.kts | 2 +- .../src/main/resources/config.yml | 0 .../src/main/resources/lang/afr_sa.yml | 0 .../src/main/resources/lang/da.yml | 0 .../src/main/resources/lang/de_de.yml | 0 .../src/main/resources/lang/en_us.yml | 0 .../src/main/resources/lang/es.yml | 0 .../src/main/resources/lang/it_it.yml | 0 .../src/main/resources/lang/ja_jp.yml | 0 .../src/main/resources/lang/nl_NL.yml | 0 .../src/main/resources/lang/pl.yml | 0 .../src/main/resources/lang/zh_cn.yml | 0 platforms/bukkit/build.gradle.kts | 9 +-------- platforms/fabric/build.gradle.kts | 6 ++++++ .../com/dfsek/terra/fabric/TerraFabricPlugin.java | 10 +++------- .../fabric/src/main/resources/fabric.mod.json | 1 - .../fabric/src/main/resources/terra.mixins.json | 14 -------------- 18 files changed, 22 insertions(+), 31 deletions(-) rename {platforms/bukkit => common}/src/main/resources/config.yml (100%) rename {platforms/bukkit => common}/src/main/resources/lang/afr_sa.yml (100%) rename {platforms/bukkit => common}/src/main/resources/lang/da.yml (100%) rename {platforms/bukkit => common}/src/main/resources/lang/de_de.yml (100%) rename {platforms/bukkit => common}/src/main/resources/lang/en_us.yml (100%) rename {platforms/bukkit => common}/src/main/resources/lang/es.yml (100%) rename {platforms/bukkit => common}/src/main/resources/lang/it_it.yml (100%) rename {platforms/bukkit => common}/src/main/resources/lang/ja_jp.yml (100%) rename {platforms/bukkit => common}/src/main/resources/lang/nl_NL.yml (100%) rename {platforms/bukkit => common}/src/main/resources/lang/pl.yml (100%) rename {platforms/bukkit => common}/src/main/resources/lang/zh_cn.yml (100%) delete mode 100644 platforms/fabric/src/main/resources/terra.mixins.json diff --git a/buildSrc/src/main/kotlin/com/dfsek/terra/CompilationConfig.kt b/buildSrc/src/main/kotlin/com/dfsek/terra/CompilationConfig.kt index ae2f81b9c..a6619cc1f 100644 --- a/buildSrc/src/main/kotlin/com/dfsek/terra/CompilationConfig.kt +++ b/buildSrc/src/main/kotlin/com/dfsek/terra/CompilationConfig.kt @@ -6,7 +6,9 @@ import org.gradle.api.plugins.JavaPluginConvention import org.gradle.api.tasks.compile.JavaCompile import org.gradle.api.tasks.javadoc.Javadoc import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.filter import org.gradle.kotlin.dsl.withType +import org.gradle.language.jvm.tasks.ProcessResources fun Project.configureCompilation() { configure { @@ -21,6 +23,15 @@ fun Project.configureCompilation() { } } + tasks.withType { + include("**/*.*") + filter( + "tokens" to mapOf( + "VERSION" to project.version.toString() + ) + ) + } + tasks.withType { options.encoding = "UTF-8" } diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 38a1a4f8e..fad3faf0c 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -22,7 +22,7 @@ dependencies { "compileOnly"("com.googlecode.json-simple:json-simple:1.1") - "shadedApi"("com.google.guava:guava:30.0-jre") + "compileOnly"("com.google.guava:guava:30.0-jre") } publishing { diff --git a/platforms/bukkit/src/main/resources/config.yml b/common/src/main/resources/config.yml similarity index 100% rename from platforms/bukkit/src/main/resources/config.yml rename to common/src/main/resources/config.yml diff --git a/platforms/bukkit/src/main/resources/lang/afr_sa.yml b/common/src/main/resources/lang/afr_sa.yml similarity index 100% rename from platforms/bukkit/src/main/resources/lang/afr_sa.yml rename to common/src/main/resources/lang/afr_sa.yml diff --git a/platforms/bukkit/src/main/resources/lang/da.yml b/common/src/main/resources/lang/da.yml similarity index 100% rename from platforms/bukkit/src/main/resources/lang/da.yml rename to common/src/main/resources/lang/da.yml diff --git a/platforms/bukkit/src/main/resources/lang/de_de.yml b/common/src/main/resources/lang/de_de.yml similarity index 100% rename from platforms/bukkit/src/main/resources/lang/de_de.yml rename to common/src/main/resources/lang/de_de.yml diff --git a/platforms/bukkit/src/main/resources/lang/en_us.yml b/common/src/main/resources/lang/en_us.yml similarity index 100% rename from platforms/bukkit/src/main/resources/lang/en_us.yml rename to common/src/main/resources/lang/en_us.yml diff --git a/platforms/bukkit/src/main/resources/lang/es.yml b/common/src/main/resources/lang/es.yml similarity index 100% rename from platforms/bukkit/src/main/resources/lang/es.yml rename to common/src/main/resources/lang/es.yml diff --git a/platforms/bukkit/src/main/resources/lang/it_it.yml b/common/src/main/resources/lang/it_it.yml similarity index 100% rename from platforms/bukkit/src/main/resources/lang/it_it.yml rename to common/src/main/resources/lang/it_it.yml diff --git a/platforms/bukkit/src/main/resources/lang/ja_jp.yml b/common/src/main/resources/lang/ja_jp.yml similarity index 100% rename from platforms/bukkit/src/main/resources/lang/ja_jp.yml rename to common/src/main/resources/lang/ja_jp.yml diff --git a/platforms/bukkit/src/main/resources/lang/nl_NL.yml b/common/src/main/resources/lang/nl_NL.yml similarity index 100% rename from platforms/bukkit/src/main/resources/lang/nl_NL.yml rename to common/src/main/resources/lang/nl_NL.yml diff --git a/platforms/bukkit/src/main/resources/lang/pl.yml b/common/src/main/resources/lang/pl.yml similarity index 100% rename from platforms/bukkit/src/main/resources/lang/pl.yml rename to common/src/main/resources/lang/pl.yml diff --git a/platforms/bukkit/src/main/resources/lang/zh_cn.yml b/common/src/main/resources/lang/zh_cn.yml similarity index 100% rename from platforms/bukkit/src/main/resources/lang/zh_cn.yml rename to common/src/main/resources/lang/zh_cn.yml diff --git a/platforms/bukkit/build.gradle.kts b/platforms/bukkit/build.gradle.kts index 09c58492d..dbf066f36 100644 --- a/platforms/bukkit/build.gradle.kts +++ b/platforms/bukkit/build.gradle.kts @@ -31,15 +31,8 @@ dependencies { "shadedImplementation"("org.bstats:bstats-bukkit:1.7") "compileOnly"("com.sk89q.worldedit:worldedit-bukkit:7.2.0-SNAPSHOT") -} -tasks.withType { - include("**/*.*") - filter( - "tokens" to mapOf( - "VERSION" to project.version.toString() - ) - ) + "shadedImplementation"("com.google.guava:guava:30.0-jre") } val testDir = "target/server/" diff --git a/platforms/fabric/build.gradle.kts b/platforms/fabric/build.gradle.kts index 79787e1bd..73dc69a3e 100644 --- a/platforms/fabric/build.gradle.kts +++ b/platforms/fabric/build.gradle.kts @@ -1,4 +1,5 @@ import com.dfsek.terra.configureCommon +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import net.fabricmc.loom.LoomGradleExtension import net.fabricmc.loom.task.RemapJarTask @@ -23,6 +24,11 @@ plugins { configureCommon() +tasks.named("shadowJar") { + relocate("org.json", "com.dfsek.terra.lib.json") + relocate("org.yaml", "com.dfsek.terra.lib.yaml") +} + group = "com.dfsek.terra.fabric" diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index 358bac109..efd7ef7be 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -163,11 +163,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { @Override public Language getLanguage() { - try { - return new Language(new File(getDataFolder(), "lang/en_us.yml")); - } catch(IOException e) { - throw new IllegalArgumentException(); - } + return LangUtil.getLanguage(); } @Override @@ -267,10 +263,10 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { public void onInitialize() { instance = this; - config = new File(FabricLoader.getInstance().getConfigDir().toFile(), "Terra"); + this.config = new File(FabricLoader.getInstance().getConfigDir().toFile(), "Terra"); saveDefaultConfig(); plugin.load(this); - LangUtil.load("en_us", this); + LangUtil.load(plugin.getLanguage(), this); logger.info("Initializing Terra..."); if(!addonRegistry.loadAll()) { diff --git a/platforms/fabric/src/main/resources/fabric.mod.json b/platforms/fabric/src/main/resources/fabric.mod.json index d86abc872..0468f1530 100644 --- a/platforms/fabric/src/main/resources/fabric.mod.json +++ b/platforms/fabric/src/main/resources/fabric.mod.json @@ -20,7 +20,6 @@ ] }, "mixins": [ - "terra.mixins.json" ], "depends": { "fabricloader": ">=0.7.4", diff --git a/platforms/fabric/src/main/resources/terra.mixins.json b/platforms/fabric/src/main/resources/terra.mixins.json deleted file mode 100644 index b69106b5f..000000000 --- a/platforms/fabric/src/main/resources/terra.mixins.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "com.dfsek.terra.fabric.mixin", - "compatibilityLevel": "JAVA_8", - "mixins": [ - ], - "client": [ - ], - "server": [], - "injectors": { - "defaultRequire": 1 - } -} \ No newline at end of file From dd446b303491deaa8c6ef85f05fdc1068dad63a3 Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 24 Feb 2021 14:12:30 -0700 Subject: [PATCH 32/95] add HPROF to ignored files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ab2a28212..b1c99d269 100644 --- a/.gitignore +++ b/.gitignore @@ -52,6 +52,7 @@ gradle-app.setting # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* +*.hprof ### JetBrains template # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider From 4a47815be7fe293c1ea125ffe16ca35743af865d Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 24 Feb 2021 19:48:43 -0700 Subject: [PATCH 33/95] remove assumption that world starts at Y=0 --- .../dfsek/terra/api/platform/world/World.java | 2 + .../terra/carving/UserDefinedCarver.java | 4 +- .../generators/DefaultChunkGenerator3D.java | 2 +- .../interpolation/ChunkInterpolator3D.java | 21 ++++++-- .../dfsek/terra/bukkit/world/BukkitWorld.java | 5 ++ .../block/state/FabricBlankBlockState.java | 50 ------------------- .../fabric/world/handles/FabricWorld.java | 5 ++ .../world/FabricSeededWorldAccess.java | 5 ++ .../handles/world/FabricWorldAccess.java | 5 ++ .../handles/world/FabricWorldChunkRegion.java | 5 ++ .../com/dfsek/terra/platform/DirectWorld.java | 5 ++ 11 files changed, 51 insertions(+), 58 deletions(-) delete mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlankBlockState.java diff --git a/common/src/main/java/com/dfsek/terra/api/platform/world/World.java b/common/src/main/java/com/dfsek/terra/api/platform/world/World.java index 57ee58b7d..3a96ba1c5 100644 --- a/common/src/main/java/com/dfsek/terra/api/platform/world/World.java +++ b/common/src/main/java/com/dfsek/terra/api/platform/world/World.java @@ -32,4 +32,6 @@ public interface World extends Handle { Block getBlockAt(Location l); Entity spawnEntity(Location location, EntityType entityType); + + int getMinHeight(); } diff --git a/common/src/main/java/com/dfsek/terra/carving/UserDefinedCarver.java b/common/src/main/java/com/dfsek/terra/carving/UserDefinedCarver.java index 8172425c9..79bd897a4 100644 --- a/common/src/main/java/com/dfsek/terra/carving/UserDefinedCarver.java +++ b/common/src/main/java/com/dfsek/terra/carving/UserDefinedCarver.java @@ -39,7 +39,7 @@ public class UserDefinedCarver extends Carver { private final Expression yRad; private final Expression zRad; - private final Map cacheMap = new ConcurrentHashMap<>(); + private final Map cacheMap = new ConcurrentHashMap<>(); private final TerraPlugin main; private double step = 2; private Range recalc = new Range(8, 10); @@ -108,7 +108,7 @@ public class UserDefinedCarver extends Carver { @Override public void carve(int chunkX, int chunkZ, World w, BiConsumer consumer) { synchronized(cacheMap) { - CarverCache cache = cacheMap.computeIfAbsent(w, world -> new CarverCache(world, main, this)); + CarverCache cache = cacheMap.computeIfAbsent(w.getSeed(), world -> new CarverCache(w, main, this)); int carvingRadius = getCarvingRadius(); for(int x = chunkX - carvingRadius; x <= chunkX + carvingRadius; x++) { for(int z = chunkZ - carvingRadius; z <= chunkZ + carvingRadius; z++) { diff --git a/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java index 2f51165ec..b4ab83e49 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java @@ -116,7 +116,7 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator { boolean justSet = false; BlockData data = null; - for(int y = world.getMaxHeight() - 1; y >= 0; y--) { + for(int y = world.getMaxHeight() - 1; y >= world.getMinHeight(); y--) { if(sampler.sample(x, y, z) > 0) { justSet = true; data = PaletteUtil.getPalette(x, y, z, c, sampler).get(paletteLevel, cx, y, cz); diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator3D.java b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator3D.java index cb077620e..e6e274465 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator3D.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator3D.java @@ -16,9 +16,12 @@ import java.util.function.BiFunction; * Contains method to get interpolated noise at a coordinate within the chunk. */ public class ChunkInterpolator3D implements ChunkInterpolator { - private final Interpolator3[][][] interpGrid = new Interpolator3[4][64][4]; + private final Interpolator3[][][] interpGrid; private final BiFunction noiseGetter; + private final int min; + private final int max; + /** * Instantiates a 3D ChunkInterpolator3D at a pair of chunk coordinates. * @@ -31,7 +34,15 @@ public class ChunkInterpolator3D implements ChunkInterpolator { int xOrigin = chunkX << 4; int zOrigin = chunkZ << 4; - double[][][] noiseStorage = new double[5][5][65]; + this.max = w.getMaxHeight(); + this.min = w.getMinHeight(); + int range = max - min + 1; + + int size = range >> 2; + + interpGrid = new Interpolator3[4][size][4]; + + double[][][] noiseStorage = new double[5][5][size + 1]; for(int x = 0; x < 5; x++) { for(int z = 0; z < 5; z++) { @@ -47,7 +58,7 @@ public class ChunkInterpolator3D implements ChunkInterpolator { } } - for(int y = 0; y < 65; y++) { + for(int y = 0; y < size + 1; y++) { noiseStorage[x][z][y] = computeNoise(genMap, (x << 2) + xOrigin, y << 2, (z << 2) + zOrigin); } } @@ -55,7 +66,7 @@ public class ChunkInterpolator3D implements ChunkInterpolator { for(int x = 0; x < 4; x++) { for(int z = 0; z < 4; z++) { - for(int y = 0; y < 64; y++) { + for(int y = 0; y < size; y++) { interpGrid[x][y][z] = new Interpolator3( noiseStorage[x][z][y], noiseStorage[x + 1][z][y], @@ -87,6 +98,6 @@ public class ChunkInterpolator3D implements ChunkInterpolator { */ @Override public double getNoise(double x, double y, double z) { - return interpGrid[reRange(((int) x) / 4, 3)][reRange(((int) y) / 4, 63)][reRange(((int) z) / 4, 3)].trilerp((x % 4) / 4, (y % 4) / 4, (z % 4) / 4); + return interpGrid[reRange(((int) x) / 4, 3)][FastMath.max(FastMath.min(((int) y), max), min) / 4][reRange(((int) z) / 4, 3)].trilerp((x % 4) / 4, (y % 4) / 4, (z % 4) / 4); } } diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitWorld.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitWorld.java index 720315bca..05a9fd982 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitWorld.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitWorld.java @@ -77,6 +77,11 @@ public class BukkitWorld implements World { return new BukkitEntity(delegate.spawnEntity(BukkitAdapter.adapt(location), ((BukkitEntityType) entityType).getHandle())); } + @Override + public int getMinHeight() { + return 0; + } + @Override public org.bukkit.World getHandle() { return delegate; diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlankBlockState.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlankBlockState.java deleted file mode 100644 index eb7d18fb9..000000000 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlankBlockState.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.dfsek.terra.fabric.world.block.state; - -import com.dfsek.terra.api.platform.block.Block; -import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.platform.block.state.BlockState; -import com.dfsek.terra.fabric.world.block.FabricBlock; - -public class FabricBlankBlockState implements BlockState { - private final FabricBlock delegate; - - public FabricBlankBlockState(FabricBlock delegate) { - this.delegate = delegate; - } - - - @Override - public Block getHandle() { - return delegate; - } - - @Override - public Block getBlock() { - return delegate; - } - - @Override - public int getX() { - return delegate.getX(); - } - - @Override - public int getY() { - return delegate.getY(); - } - - @Override - public int getZ() { - return delegate.getZ(); - } - - @Override - public BlockData getBlockData() { - return delegate.getBlockData(); - } - - @Override - public boolean update(boolean applyPhysics) { - return true; - } -} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java index 3c470f0a7..b32483ebb 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java @@ -93,6 +93,11 @@ public class FabricWorld implements World, FabricWorldHandle { return null; } + @Override + public int getMinHeight() { + return 0; + } + @Override public Handle getHandle() { return null; diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricSeededWorldAccess.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricSeededWorldAccess.java index 106d1e2a4..4f9f3d9d1 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricSeededWorldAccess.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricSeededWorldAccess.java @@ -80,6 +80,11 @@ public class FabricSeededWorldAccess implements World, FabricWorldHandle { return null; } + @Override + public int getMinHeight() { + return 0; + } + @Override public int hashCode() { return ((ServerWorldAccess) handle.worldAccess).toServerWorld().hashCode(); diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java index b7780f837..603be63dd 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java @@ -80,6 +80,11 @@ public class FabricWorldAccess implements World, FabricWorldHandle { return null; } + @Override + public int getMinHeight() { + return 0; + } + @Override public WorldAccess getHandle() { return delegate; diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java index ffb12595a..1255a966a 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java @@ -91,6 +91,11 @@ public class FabricWorldChunkRegion implements World, FabricWorldHandle { return null; } + @Override + public int getMinHeight() { + return 0; + } + @Override public Object getHandle() { return delegate; diff --git a/platforms/region/src/main/java/com/dfsek/terra/platform/DirectWorld.java b/platforms/region/src/main/java/com/dfsek/terra/platform/DirectWorld.java index c27f47abf..1fce4cd70 100644 --- a/platforms/region/src/main/java/com/dfsek/terra/platform/DirectWorld.java +++ b/platforms/region/src/main/java/com/dfsek/terra/platform/DirectWorld.java @@ -92,6 +92,11 @@ public class DirectWorld implements World { return null; } + @Override + public int getMinHeight() { + return 0; + } + @Override public Object getHandle() { return generator; From 4ca2f0c08d33c9adb33d35f8abe8a02d14a931e1 Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 24 Feb 2021 23:46:43 -0700 Subject: [PATCH 34/95] fabric inventory stuff --- .../api/platform/inventory/ItemStack.java | 4 +- .../terra/api/structures/loot/LootTable.java | 6 ++- .../loot/functions/DamageFunction.java | 6 ++- .../world/block/state/BukkitContainer.java | 4 ++ .../world/inventory/BukkitItemStack.java | 14 +------ .../fabric/inventory/FabricEnchantment.java | 41 ++++++++++++++++++ .../fabric/inventory/FabricInventory.java | 5 +-- .../fabric/inventory/FabricItemStack.java | 18 +++----- .../inventory/meta/FabricDamageable.java | 26 ++++++++++++ .../fabric/inventory/meta/FabricItemMeta.java | 42 +++++++++++++++++++ .../terra/fabric/world/FabricAdapter.java | 10 +++++ .../world/block/state/FabricBlockState.java | 22 ++++------ .../world/block/state/FabricContainer.java | 3 +- .../src/main/resources/terra.accesswidener | 5 ++- 14 files changed, 153 insertions(+), 53 deletions(-) create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricEnchantment.java create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/meta/FabricDamageable.java create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/meta/FabricItemMeta.java diff --git a/common/src/main/java/com/dfsek/terra/api/platform/inventory/ItemStack.java b/common/src/main/java/com/dfsek/terra/api/platform/inventory/ItemStack.java index b480f6c5a..dfa8d9719 100644 --- a/common/src/main/java/com/dfsek/terra/api/platform/inventory/ItemStack.java +++ b/common/src/main/java/com/dfsek/terra/api/platform/inventory/ItemStack.java @@ -3,15 +3,13 @@ package com.dfsek.terra.api.platform.inventory; import com.dfsek.terra.api.platform.Handle; import com.dfsek.terra.api.platform.inventory.item.ItemMeta; -public interface ItemStack extends Handle, Cloneable { +public interface ItemStack extends Handle { int getAmount(); void setAmount(int i); Item getType(); - ItemStack clone(); - ItemMeta getItemMeta(); void setItemMeta(ItemMeta meta); diff --git a/common/src/main/java/com/dfsek/terra/api/structures/loot/LootTable.java b/common/src/main/java/com/dfsek/terra/api/structures/loot/LootTable.java index f5da89b65..886d72178 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/loot/LootTable.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/loot/LootTable.java @@ -58,7 +58,8 @@ public class LootTable { for(ItemStack stack : loot) { int attempts = 0; while(stack.getAmount() != 0 && attempts < 10) { - ItemStack newStack = stack.clone(); + ItemStack newStack = stack.getType().newItemStack(stack.getAmount()); + newStack.setItemMeta(stack.getItemMeta()); newStack.setAmount(1); int slot = r.nextInt(i.getSize()); ItemStack slotItem = i.getItem(slot); @@ -66,7 +67,8 @@ public class LootTable { i.setItem(slot, newStack); stack.setAmount(stack.getAmount() - 1); } else if(slotItem.getType().equals(newStack.getType())) { - ItemStack dep = newStack.clone(); + ItemStack dep = newStack.getType().newItemStack(newStack.getAmount()); + dep.setItemMeta(newStack.getItemMeta()); dep.setAmount(newStack.getAmount() + slotItem.getAmount()); i.setItem(slot, dep); stack.setAmount(stack.getAmount() - 1); diff --git a/common/src/main/java/com/dfsek/terra/api/structures/loot/functions/DamageFunction.java b/common/src/main/java/com/dfsek/terra/api/structures/loot/functions/DamageFunction.java index 158c2248d..189a0c100 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/loot/functions/DamageFunction.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/loot/functions/DamageFunction.java @@ -33,9 +33,11 @@ public class DamageFunction implements LootFunction { */ @Override public ItemStack apply(ItemStack original, Random r) { - if(!(original instanceof Damageable)) return original; + if(original == null) return null; + ItemMeta meta = original.getItemMeta(); + if(!(meta instanceof Damageable)) return original; double itemDurability = (r.nextDouble() * (max - min)) + min; - Damageable damage = (Damageable) original.getItemMeta(); + Damageable damage = (Damageable) meta; damage.setDamage((int) (original.getType().getMaxDurability() - (itemDurability / 100) * original.getType().getMaxDurability())); original.setItemMeta((ItemMeta) damage); return original; diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/state/BukkitContainer.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/state/BukkitContainer.java index c95040f8c..cdb1fe636 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/state/BukkitContainer.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/state/BukkitContainer.java @@ -15,4 +15,8 @@ public class BukkitContainer extends BukkitBlockState implements Container { return new BukkitInventory(((org.bukkit.block.Container) getHandle()).getInventory()); } + @Override + public boolean update(boolean applyPhysics) { + return false; // This clears the inventory. we don't want that. + } } diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/inventory/BukkitItemStack.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/inventory/BukkitItemStack.java index 28bbca8f9..b42f7319d 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/inventory/BukkitItemStack.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/inventory/BukkitItemStack.java @@ -6,7 +6,7 @@ import com.dfsek.terra.api.platform.inventory.item.ItemMeta; import com.dfsek.terra.bukkit.world.BukkitAdapter; public class BukkitItemStack implements ItemStack { - private org.bukkit.inventory.ItemStack delegate; + private final org.bukkit.inventory.ItemStack delegate; public BukkitItemStack(org.bukkit.inventory.ItemStack delegate) { this.delegate = delegate; @@ -27,18 +27,6 @@ public class BukkitItemStack implements ItemStack { return BukkitAdapter.adapt(delegate.getType()); } - @Override - public ItemStack clone() { - BukkitItemStack clone; - try { - clone = (BukkitItemStack) super.clone(); - clone.delegate = delegate.clone(); - } catch(CloneNotSupportedException e) { - throw new Error(e); - } - return clone; - } - @Override public ItemMeta getItemMeta() { return BukkitItemMeta.newInstance(delegate.getItemMeta()); diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricEnchantment.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricEnchantment.java new file mode 100644 index 000000000..347f53315 --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricEnchantment.java @@ -0,0 +1,41 @@ +package com.dfsek.terra.fabric.inventory; + +import com.dfsek.terra.api.platform.inventory.ItemStack; +import com.dfsek.terra.api.platform.inventory.item.Enchantment; +import com.dfsek.terra.fabric.world.FabricAdapter; +import net.minecraft.util.registry.Registry; + +import java.util.Objects; + +public class FabricEnchantment implements Enchantment { + private final net.minecraft.enchantment.Enchantment enchantment; + + public FabricEnchantment(net.minecraft.enchantment.Enchantment enchantment) { + this.enchantment = enchantment; + } + + @Override + public net.minecraft.enchantment.Enchantment getHandle() { + return enchantment; + } + + @Override + public boolean canEnchantItem(ItemStack itemStack) { + return enchantment.isAcceptableItem(FabricAdapter.adapt(itemStack)); + } + + @Override + public String getID() { + return Objects.requireNonNull(Registry.ENCHANTMENT.getId(enchantment)).toString(); + } + + @Override + public boolean conflictsWith(Enchantment other) { + return !enchantment.canCombine(FabricAdapter.adapt(other)); + } + + @Override + public int getMaxLevel() { + return enchantment.getMaxLevel(); + } +} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricInventory.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricInventory.java index 43fa95d9c..8b86f657d 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricInventory.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricInventory.java @@ -3,13 +3,12 @@ package com.dfsek.terra.fabric.inventory; import com.dfsek.terra.api.platform.inventory.Inventory; import com.dfsek.terra.api.platform.inventory.ItemStack; import com.dfsek.terra.fabric.world.FabricAdapter; -import net.minecraft.block.entity.LootableContainerBlockEntity; import net.minecraft.item.Items; public class FabricInventory implements Inventory { - private final LootableContainerBlockEntity delegate; + private final net.minecraft.inventory.Inventory delegate; - public FabricInventory(LootableContainerBlockEntity delegate) { + public FabricInventory(net.minecraft.inventory.Inventory delegate) { this.delegate = delegate; } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemStack.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemStack.java index f5c414d2b..6184d5e50 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemStack.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemStack.java @@ -3,6 +3,8 @@ package com.dfsek.terra.fabric.inventory; import com.dfsek.terra.api.platform.inventory.Item; import com.dfsek.terra.api.platform.inventory.ItemStack; import com.dfsek.terra.api.platform.inventory.item.ItemMeta; +import com.dfsek.terra.fabric.inventory.meta.FabricDamageable; +import com.dfsek.terra.fabric.inventory.meta.FabricItemMeta; public class FabricItemStack implements ItemStack { private net.minecraft.item.ItemStack delegate; @@ -26,25 +28,15 @@ public class FabricItemStack implements ItemStack { return new FabricItem(delegate.getItem()); } - @Override - public ItemStack clone() { - try { - FabricItemStack stack = (FabricItemStack) super.clone(); - stack.delegate = delegate; - return stack; - } catch(CloneNotSupportedException e) { - throw new Error(); - } - } - @Override public ItemMeta getItemMeta() { - return null; + if(delegate.isDamageable()) return new FabricDamageable(delegate); + return new FabricItemMeta(delegate.copy()); } @Override public void setItemMeta(ItemMeta meta) { - + this.delegate = ((FabricItemMeta) meta).getHandle(); } @Override diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/meta/FabricDamageable.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/meta/FabricDamageable.java new file mode 100644 index 000000000..0f97472e2 --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/meta/FabricDamageable.java @@ -0,0 +1,26 @@ +package com.dfsek.terra.fabric.inventory.meta; + +import com.dfsek.terra.api.platform.inventory.item.Damageable; +import net.minecraft.item.ItemStack; + +public class FabricDamageable extends FabricItemMeta implements Damageable { + public FabricDamageable(ItemStack delegate) { + super(delegate); + } + + @Override + public int getDamage() { + return delegate.getDamage(); + } + + @Override + public void setDamage(int damage) { + System.out.println("Setting damage: " + damage); + delegate.setDamage(damage); + } + + @Override + public boolean hasDamage() { + return delegate.isDamageable(); + } +} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/meta/FabricItemMeta.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/meta/FabricItemMeta.java new file mode 100644 index 000000000..45290b1be --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/meta/FabricItemMeta.java @@ -0,0 +1,42 @@ +package com.dfsek.terra.fabric.inventory.meta; + +import com.dfsek.terra.api.platform.inventory.item.Enchantment; +import com.dfsek.terra.api.platform.inventory.item.ItemMeta; +import com.dfsek.terra.fabric.world.FabricAdapter; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundTag; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +public class FabricItemMeta implements ItemMeta { + protected final ItemStack delegate; + + public FabricItemMeta(ItemStack delegate) { + this.delegate = delegate; + } + + @Override + public ItemStack getHandle() { + return delegate; + } + + @Override + public Map getEnchantments() { + if(!delegate.hasEnchantments()) return Collections.emptyMap(); + Map map = new HashMap<>(); + + delegate.getEnchantments().forEach(enchantment -> { + CompoundTag eTag = (CompoundTag) enchantment; + map.put(FabricAdapter.adapt(net.minecraft.enchantment.Enchantment.byRawId(eTag.getInt("id"))), eTag.getInt("lvl")); + }); + return map; + } + + @Override + public void addEnchantment(Enchantment enchantment, int level) { + System.out.println("Enchanting: " + enchantment.getHandle() + ", " + level); + delegate.addEnchantment(FabricAdapter.adapt(enchantment), level); + } +} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java index b6105f262..0a457b632 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java @@ -3,6 +3,8 @@ package com.dfsek.terra.fabric.world; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockType; import com.dfsek.terra.api.platform.entity.EntityType; +import com.dfsek.terra.api.platform.inventory.item.Enchantment; +import com.dfsek.terra.fabric.inventory.FabricEnchantment; import com.dfsek.terra.fabric.inventory.FabricItem; import com.dfsek.terra.fabric.inventory.FabricItemStack; import com.dfsek.terra.fabric.world.block.FabricBlockData; @@ -73,4 +75,12 @@ public final class FabricAdapter { public static com.dfsek.terra.api.platform.inventory.Item adapt(Item item) { return new FabricItem(item); } + + public static Enchantment adapt(net.minecraft.enchantment.Enchantment enchantment) { + return new FabricEnchantment(enchantment); + } + + public static net.minecraft.enchantment.Enchantment adapt(Enchantment enchantment) { + return ((FabricEnchantment) enchantment).getHandle(); + } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java index 2347f452f..d0dbf5bf4 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricBlockState.java @@ -5,12 +5,9 @@ import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.state.BlockState; import com.dfsek.terra.fabric.world.FabricAdapter; import com.dfsek.terra.fabric.world.block.FabricBlock; -import com.dfsek.terra.fabric.world.block.FabricBlockData; import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle; -import net.minecraft.block.AbstractChestBlock; -import net.minecraft.block.AbstractSignBlock; -import net.minecraft.block.SpawnerBlock; import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.LootableContainerBlockEntity; import net.minecraft.block.entity.MobSpawnerBlockEntity; import net.minecraft.block.entity.SignBlockEntity; import net.minecraft.world.WorldAccess; @@ -25,18 +22,15 @@ public class FabricBlockState implements BlockState { } public static FabricBlockState newInstance(Block block) { - net.minecraft.block.Block block1 = ((FabricBlockData) block.getBlockData()).getHandle().getBlock(); WorldAccess worldAccess = ((FabricWorldHandle) block.getLocation().getWorld()).getWorld(); - if(block1 instanceof AbstractSignBlock) { - SignBlockEntity signBlockEntity = (SignBlockEntity) worldAccess.getBlockEntity(FabricAdapter.adapt(block.getLocation().toVector())); - return new FabricSign(signBlockEntity, worldAccess); - } else if(block1 instanceof SpawnerBlock) { - MobSpawnerBlockEntity mobSpawnerBlockEntity = (MobSpawnerBlockEntity) worldAccess.getBlockEntity(FabricAdapter.adapt(block.getLocation().toVector())); - return new FabricMobSpawner(mobSpawnerBlockEntity, worldAccess); - } else if(block1 instanceof AbstractChestBlock) { - BlockEntity abstractChestBlock = worldAccess.getBlockEntity(FabricAdapter.adapt(block.getLocation().toVector())); - return new FabricContainer(abstractChestBlock, worldAccess); + BlockEntity entity = worldAccess.getBlockEntity(FabricAdapter.adapt(block.getLocation().toVector())); + if(entity instanceof SignBlockEntity) { + return new FabricSign((SignBlockEntity) entity, worldAccess); + } else if(entity instanceof MobSpawnerBlockEntity) { + return new FabricMobSpawner((MobSpawnerBlockEntity) entity, worldAccess); + } else if(entity instanceof LootableContainerBlockEntity) { + return new FabricContainer((LootableContainerBlockEntity) entity, worldAccess); } return null; } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricContainer.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricContainer.java index bca4f2dc0..743c06d83 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricContainer.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/state/FabricContainer.java @@ -3,12 +3,11 @@ package com.dfsek.terra.fabric.world.block.state; import com.dfsek.terra.api.platform.block.state.Container; import com.dfsek.terra.api.platform.inventory.Inventory; import com.dfsek.terra.fabric.inventory.FabricInventory; -import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.LootableContainerBlockEntity; import net.minecraft.world.WorldAccess; public class FabricContainer extends FabricBlockState implements Container { - public FabricContainer(BlockEntity blockEntity, WorldAccess worldAccess) { + public FabricContainer(LootableContainerBlockEntity blockEntity, WorldAccess worldAccess) { super(blockEntity, worldAccess); } diff --git a/platforms/fabric/src/main/resources/terra.accesswidener b/platforms/fabric/src/main/resources/terra.accesswidener index 1b6dfe0be..c501a7abb 100644 --- a/platforms/fabric/src/main/resources/terra.accesswidener +++ b/platforms/fabric/src/main/resources/terra.accesswidener @@ -11,4 +11,7 @@ accessible field net/minecraft/server/world/ServerWorld worldProperties Lnet/min accessible method net/minecraft/world/MobSpawnerLogic getEntityId ()Lnet/minecraft/util/Identifier; -accessible field net/minecraft/state/State PROPERTY_MAP_PRINTER Ljava/util/function/Function; \ No newline at end of file +accessible field net/minecraft/state/State PROPERTY_MAP_PRINTER Ljava/util/function/Function; + +accessible method net/minecraft/block/entity/LootableContainerBlockEntity setInvStackList (Lnet/minecraft/util/collection/DefaultedList;)V +accessible method net/minecraft/block/entity/LootableContainerBlockEntity getInvStackList ()Lnet/minecraft/util/collection/DefaultedList; \ No newline at end of file From 4569a9ed130765f0a5b438b0e46bce4387d60d41 Mon Sep 17 00:00:00 2001 From: dfsek Date: Thu, 25 Feb 2021 00:45:25 -0700 Subject: [PATCH 35/95] working damage --- .../java/com/dfsek/terra/fabric/inventory/FabricItemStack.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemStack.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemStack.java index 6184d5e50..19d33b524 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemStack.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemStack.java @@ -30,7 +30,7 @@ public class FabricItemStack implements ItemStack { @Override public ItemMeta getItemMeta() { - if(delegate.isDamageable()) return new FabricDamageable(delegate); + if(delegate.isDamageable()) return new FabricDamageable(delegate.copy()); return new FabricItemMeta(delegate.copy()); } From 924bc6e46945f0ab29c6b82a84d68c1af0d5fa09 Mon Sep 17 00:00:00 2001 From: dfsek Date: Thu, 25 Feb 2021 00:57:36 -0700 Subject: [PATCH 36/95] Fabric Enchantments --- .../java/com/dfsek/terra/fabric/TerraFabricPlugin.java | 3 +++ .../dfsek/terra/fabric/inventory/FabricItemHandle.java | 8 +++++--- .../terra/fabric/inventory/meta/FabricDamageable.java | 1 - .../dfsek/terra/fabric/inventory/meta/FabricItemMeta.java | 1 - 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index efd7ef7be..439278413 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -272,9 +272,12 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { if(!addonRegistry.loadAll()) { throw new IllegalStateException("Failed to load addons. Please correct addon installations to continue."); } + logger.info("Loaded addons."); registry.loadAll(this); + logger.info("Loaded packs."); + Registry.register(Registry.FEATURE, new Identifier("terra", "flora_populator"), POPULATOR_FEATURE); RegistryKey> floraKey = RegistryKey.of(Registry.CONFIGURED_FEATURE_WORLDGEN, new Identifier("terra", "flora_populator")); Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, floraKey.getValue(), POPULATOR_CONFIGURED_FEATURE); diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemHandle.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemHandle.java index 3900a67e7..ef77d9928 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemHandle.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/FabricItemHandle.java @@ -7,9 +7,11 @@ import com.dfsek.terra.fabric.world.FabricAdapter; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.command.argument.ItemStackArgumentType; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; -import java.util.Collections; import java.util.Set; +import java.util.stream.Collectors; public class FabricItemHandle implements ItemHandle { @@ -24,11 +26,11 @@ public class FabricItemHandle implements ItemHandle { @Override public Enchantment getEnchantment(String id) { - return null; + return FabricAdapter.adapt(Registry.ENCHANTMENT.get(Identifier.tryParse(id))); } @Override public Set getEnchantments() { - return Collections.emptySet(); + return Registry.ENCHANTMENT.stream().map(FabricAdapter::adapt).collect(Collectors.toSet()); } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/meta/FabricDamageable.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/meta/FabricDamageable.java index 0f97472e2..4a4cc918e 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/meta/FabricDamageable.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/meta/FabricDamageable.java @@ -15,7 +15,6 @@ public class FabricDamageable extends FabricItemMeta implements Damageable { @Override public void setDamage(int damage) { - System.out.println("Setting damage: " + damage); delegate.setDamage(damage); } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/meta/FabricItemMeta.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/meta/FabricItemMeta.java index 45290b1be..13a0431e2 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/meta/FabricItemMeta.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/meta/FabricItemMeta.java @@ -36,7 +36,6 @@ public class FabricItemMeta implements ItemMeta { @Override public void addEnchantment(Enchantment enchantment, int level) { - System.out.println("Enchanting: " + enchantment.getHandle() + ", " + level); delegate.addEnchantment(FabricAdapter.adapt(enchantment), level); } } From 12af19edbadb316011c261d9cd8cd08df4996d1a Mon Sep 17 00:00:00 2001 From: dfsek Date: Thu, 25 Feb 2021 01:21:28 -0700 Subject: [PATCH 37/95] fabric entities --- .../terra/fabric/world/FabricAdapter.java | 3 +- .../fabric/world/entity/FabricEntity.java | 10 +- .../fabric/world/handles/FabricWorld.java | 7 +- .../world/FabricSeededWorldAccess.java | 8 +- .../handles/world/FabricWorldAccess.java | 8 +- .../handles/world/FabricWorldChunkRegion.java | 126 ------------------ 6 files changed, 31 insertions(+), 131 deletions(-) delete mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java index 0a457b632..ba20cdf97 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java @@ -18,6 +18,7 @@ import com.dfsek.terra.fabric.world.entity.FabricEntityType; import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle; import net.minecraft.block.Block; import net.minecraft.block.BlockState; +import net.minecraft.entity.Entity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.state.property.Properties; @@ -60,7 +61,7 @@ public final class FabricAdapter { return new FabricEntityType(entityType); } - public static net.minecraft.entity.EntityType adapt(EntityType entityType) { + public static net.minecraft.entity.EntityType adapt(EntityType entityType) { return ((FabricEntityType) entityType).getHandle(); } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricEntity.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricEntity.java index 72cbf83b4..fd7da3d05 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricEntity.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricEntity.java @@ -2,8 +2,16 @@ package com.dfsek.terra.fabric.world.entity; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.entity.Entity; +import com.dfsek.terra.fabric.world.FabricAdapter; +import com.dfsek.terra.fabric.world.handles.world.FabricWorldAccess; public class FabricEntity implements Entity { + private final net.minecraft.entity.Entity delegate; + + public FabricEntity(net.minecraft.entity.Entity delegate) { + this.delegate = delegate; + } + @Override public void sendMessage(String message) { @@ -16,6 +24,6 @@ public class FabricEntity implements Entity { @Override public Location getLocation() { - return null; + return new Location(new FabricWorldAccess(delegate.world), FabricAdapter.adapt(delegate.getBlockPos())); } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java index b32483ebb..840559c83 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java @@ -7,7 +7,9 @@ import com.dfsek.terra.api.platform.entity.EntityType; import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.platform.world.generator.ChunkGenerator; +import com.dfsek.terra.fabric.world.FabricAdapter; import com.dfsek.terra.fabric.world.block.FabricBlock; +import com.dfsek.terra.fabric.world.entity.FabricEntity; import com.dfsek.terra.fabric.world.handles.chunk.FabricChunk; import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle; import net.minecraft.server.world.ServerWorld; @@ -90,7 +92,10 @@ public class FabricWorld implements World, FabricWorldHandle { @Override public Entity spawnEntity(Location location, EntityType entityType) { - return null; + net.minecraft.entity.Entity entity = FabricAdapter.adapt(entityType).create(delegate.world); + entity.setPos(location.getX(), location.getY(), location.getZ()); + delegate.world.spawnEntity(entity); + return new FabricEntity(entity); } @Override diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricSeededWorldAccess.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricSeededWorldAccess.java index 4f9f3d9d1..3db150d99 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricSeededWorldAccess.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricSeededWorldAccess.java @@ -7,8 +7,11 @@ import com.dfsek.terra.api.platform.entity.EntityType; import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.platform.world.generator.ChunkGenerator; +import com.dfsek.terra.fabric.world.FabricAdapter; import com.dfsek.terra.fabric.world.block.FabricBlock; +import com.dfsek.terra.fabric.world.entity.FabricEntity; import com.dfsek.terra.fabric.world.generator.FabricChunkGenerator; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.world.ServerWorldAccess; import net.minecraft.world.WorldAccess; @@ -77,7 +80,10 @@ public class FabricSeededWorldAccess implements World, FabricWorldHandle { @Override public Entity spawnEntity(Location location, EntityType entityType) { - return null; + net.minecraft.entity.Entity entity = FabricAdapter.adapt(entityType).create((ServerWorld) handle.worldAccess); + entity.setPos(location.getX(), location.getY(), location.getZ()); + handle.worldAccess.spawnEntity(entity); + return new FabricEntity(entity); } @Override diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java index 603be63dd..3bf422496 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java @@ -7,7 +7,9 @@ import com.dfsek.terra.api.platform.entity.EntityType; import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.platform.world.generator.ChunkGenerator; +import com.dfsek.terra.fabric.world.FabricAdapter; import com.dfsek.terra.fabric.world.block.FabricBlock; +import com.dfsek.terra.fabric.world.entity.FabricEntity; import com.dfsek.terra.fabric.world.generator.FabricChunkGenerator; import net.minecraft.util.math.BlockPos; import net.minecraft.world.ServerWorldAccess; @@ -77,7 +79,11 @@ public class FabricWorldAccess implements World, FabricWorldHandle { @Override public Entity spawnEntity(Location location, EntityType entityType) { - return null; + net.minecraft.entity.Entity entity = FabricAdapter.adapt(entityType).create(((ServerWorldAccess) delegate).toServerWorld()); + entity.setPos(location.getX(), location.getY(), location.getZ()); + delegate.spawnEntity(entity); + System.out.println("Spawned " + entity); + return new FabricEntity(entity); } @Override diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java deleted file mode 100644 index 1255a966a..000000000 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldChunkRegion.java +++ /dev/null @@ -1,126 +0,0 @@ -package com.dfsek.terra.fabric.world.handles.world; - -import com.dfsek.terra.api.math.vector.Location; -import com.dfsek.terra.api.platform.block.Block; -import com.dfsek.terra.api.platform.entity.Entity; -import com.dfsek.terra.api.platform.entity.EntityType; -import com.dfsek.terra.api.platform.world.Chunk; -import com.dfsek.terra.api.platform.world.World; -import com.dfsek.terra.api.platform.world.generator.ChunkGenerator; -import com.dfsek.terra.fabric.world.block.FabricBlock; -import com.dfsek.terra.fabric.world.generator.FabricChunkGenerator; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.ChunkRegion; -import net.minecraft.world.ServerWorldAccess; -import net.minecraft.world.WorldAccess; - -import java.io.File; -import java.util.UUID; - -public class FabricWorldChunkRegion implements World, FabricWorldHandle { - private final Handle delegate; - - public FabricWorldChunkRegion(ChunkRegion delegate, net.minecraft.world.gen.chunk.ChunkGenerator generator) { - this.delegate = new Handle(delegate, generator); - } - - @Override - public long getSeed() { - return delegate.getChunk().getSeed(); - } - - @Override - public int getMaxHeight() { - return delegate.getChunk().getHeight(); - } - - @Override - public ChunkGenerator getGenerator() { - return new FabricChunkGenerator(delegate.getGenerator()); - } - - @Override - public String getName() { - return delegate.chunk.toString(); - } - - @Override - public UUID getUID() { - return UUID.randomUUID(); - } - - @Override - public boolean isChunkGenerated(int x, int z) { - return delegate.chunk.isChunkLoaded(x, z); - } - - @Override - public Chunk getChunkAt(int x, int z) { - return null; - } - - @Override - public File getWorldFolder() { - return null; - } - - @Override - public Block getBlockAt(int x, int y, int z) { - BlockPos pos = new BlockPos(x, y, z); - return new FabricBlock(pos, delegate.chunk); - } - - @Override - public int hashCode() { - return ((ServerWorldAccess) delegate.chunk).toServerWorld().hashCode(); - } - - @Override - public boolean equals(Object obj) { - if(!(obj instanceof FabricWorldChunkRegion)) return false; - return ((ServerWorldAccess) ((FabricWorldChunkRegion) obj).delegate.chunk).toServerWorld().equals(((ServerWorldAccess) delegate.chunk).toServerWorld()); - } - - @Override - public Block getBlockAt(Location l) { - return getBlockAt(l.getBlockX(), l.getBlockY(), l.getBlockZ()); - } - - @Override - public Entity spawnEntity(Location location, EntityType entityType) { - return null; - } - - @Override - public int getMinHeight() { - return 0; - } - - @Override - public Object getHandle() { - return delegate; - } - - @Override - public WorldAccess getWorld() { - return delegate.chunk; - } - - public static final class Handle { - private final ChunkRegion chunk; - private final net.minecraft.world.gen.chunk.ChunkGenerator generator; - - public Handle(ChunkRegion chunk, net.minecraft.world.gen.chunk.ChunkGenerator generator) { - this.chunk = chunk; - this.generator = generator; - } - - public net.minecraft.world.gen.chunk.ChunkGenerator getGenerator() { - return generator; - } - - public ChunkRegion getChunk() { - return chunk; - } - } -} From 7c177d568b04be8ea3656a0f91bfc59e601788a8 Mon Sep 17 00:00:00 2001 From: dfsek Date: Thu, 25 Feb 2021 01:33:10 -0700 Subject: [PATCH 38/95] implement FabricRotatable --- .../terra/fabric/world/FabricAdapter.java | 3 + .../world/block/data/FabricRotatable.java | 111 ++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/data/FabricRotatable.java diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java index ba20cdf97..3c7035f88 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java @@ -11,6 +11,7 @@ import com.dfsek.terra.fabric.world.block.FabricBlockData; import com.dfsek.terra.fabric.world.block.FabricBlockType; import com.dfsek.terra.fabric.world.block.data.FabricMultipleFacing; import com.dfsek.terra.fabric.world.block.data.FabricOrientable; +import com.dfsek.terra.fabric.world.block.data.FabricRotatable; import com.dfsek.terra.fabric.world.block.data.FabricSlab; import com.dfsek.terra.fabric.world.block.data.FabricStairs; import com.dfsek.terra.fabric.world.block.data.FabricWaterlogged; @@ -43,6 +44,8 @@ public final class FabricAdapter { if(state.contains(Properties.AXIS)) return new FabricOrientable(state); + if(state.contains(Properties.ROTATION)) return new FabricRotatable(state); + if(state.getProperties().containsAll(Arrays.asList(Properties.NORTH, Properties.SOUTH, Properties.EAST, Properties.WEST))) return new FabricMultipleFacing(state); if(state.contains(Properties.WATERLOGGED)) return new FabricWaterlogged(state); diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/data/FabricRotatable.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/data/FabricRotatable.java new file mode 100644 index 000000000..a238f21e1 --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/data/FabricRotatable.java @@ -0,0 +1,111 @@ +package com.dfsek.terra.fabric.world.block.data; + +import com.dfsek.terra.api.platform.block.BlockFace; +import com.dfsek.terra.api.platform.block.data.Rotatable; +import com.dfsek.terra.fabric.world.block.FabricBlockData; +import net.minecraft.block.BlockState; +import net.minecraft.state.property.Properties; + +public class FabricRotatable extends FabricBlockData implements Rotatable { + public FabricRotatable(BlockState delegate) { + super(delegate); + } + + @Override + public BlockFace getRotation() { + int r = delegate.get(Properties.ROTATION); + switch(r) { + case 0: + return BlockFace.SOUTH; + case 1: + return BlockFace.SOUTH_SOUTH_WEST; + case 2: + return BlockFace.SOUTH_WEST; + case 3: + return BlockFace.WEST_SOUTH_WEST; + case 4: + return BlockFace.WEST; + case 5: + return BlockFace.WEST_NORTH_WEST; + case 6: + return BlockFace.NORTH_WEST; + case 7: + return BlockFace.NORTH_NORTH_WEST; + case 8: + return BlockFace.NORTH; + case 9: + return BlockFace.NORTH_NORTH_EAST; + case 10: + return BlockFace.NORTH_EAST; + case 11: + return BlockFace.EAST_NORTH_EAST; + case 12: + return BlockFace.EAST; + case 13: + return BlockFace.EAST_SOUTH_EAST; + case 14: + return BlockFace.SOUTH_EAST; + case 15: + return BlockFace.SOUTH_SOUTH_EAST; + default: + throw new IllegalArgumentException("Unknown rotation " + r); + } + } + + @Override + public void setRotation(BlockFace face) { + switch(face) { + case UP: + case DOWN: + throw new IllegalArgumentException("Illegal rotation " + face); + case SOUTH: + delegate = delegate.with(Properties.ROTATION, 0); + return; + case SOUTH_SOUTH_WEST: + delegate = delegate.with(Properties.ROTATION, 1); + return; + case SOUTH_WEST: + delegate = delegate.with(Properties.ROTATION, 2); + return; + case WEST_SOUTH_WEST: + delegate = delegate.with(Properties.ROTATION, 3); + return; + case WEST: + delegate = delegate.with(Properties.ROTATION, 4); + return; + case WEST_NORTH_WEST: + delegate = delegate.with(Properties.ROTATION, 5); + return; + case NORTH_WEST: + delegate = delegate.with(Properties.ROTATION, 6); + return; + case NORTH_NORTH_WEST: + delegate = delegate.with(Properties.ROTATION, 7); + return; + case NORTH: + delegate = delegate.with(Properties.ROTATION, 8); + return; + case NORTH_NORTH_EAST: + delegate = delegate.with(Properties.ROTATION, 9); + return; + case NORTH_EAST: + delegate = delegate.with(Properties.ROTATION, 10); + return; + case EAST_NORTH_EAST: + delegate = delegate.with(Properties.ROTATION, 11); + return; + case EAST: + delegate = delegate.with(Properties.ROTATION, 12); + return; + case EAST_SOUTH_EAST: + delegate = delegate.with(Properties.ROTATION, 13); + return; + case SOUTH_EAST: + delegate = delegate.with(Properties.ROTATION, 14); + return; + case SOUTH_SOUTH_EAST: + delegate = delegate.with(Properties.ROTATION, 15); + return; + } + } +} From 7f988dcf267d8e3a8eff8f49f3e7d5d763399c68 Mon Sep 17 00:00:00 2001 From: dfsek Date: Thu, 25 Feb 2021 01:43:01 -0700 Subject: [PATCH 39/95] implement FabricDirectional --- .../terra/fabric/world/FabricAdapter.java | 37 +++++++++++++--- .../world/block/data/FabricDirectional.java | 42 +++++++++++++++++++ .../world/block/data/FabricOrientable.java | 12 ++++-- 3 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/data/FabricDirectional.java diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java index 3c7035f88..eb73af5a7 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java @@ -1,6 +1,7 @@ package com.dfsek.terra.fabric.world; import com.dfsek.terra.api.math.vector.Vector3; +import com.dfsek.terra.api.platform.block.BlockFace; import com.dfsek.terra.api.platform.block.BlockType; import com.dfsek.terra.api.platform.entity.EntityType; import com.dfsek.terra.api.platform.inventory.item.Enchantment; @@ -9,6 +10,7 @@ import com.dfsek.terra.fabric.inventory.FabricItem; import com.dfsek.terra.fabric.inventory.FabricItemStack; import com.dfsek.terra.fabric.world.block.FabricBlockData; import com.dfsek.terra.fabric.world.block.FabricBlockType; +import com.dfsek.terra.fabric.world.block.data.FabricDirectional; import com.dfsek.terra.fabric.world.block.data.FabricMultipleFacing; import com.dfsek.terra.fabric.world.block.data.FabricOrientable; import com.dfsek.terra.fabric.world.block.data.FabricRotatable; @@ -24,6 +26,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.state.property.Properties; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; import net.minecraft.world.WorldAccess; import java.util.Arrays; @@ -42,22 +45,42 @@ public final class FabricAdapter { if(state.contains(Properties.SLAB_TYPE)) return new FabricSlab(state); - if(state.contains(Properties.AXIS)) return new FabricOrientable(state); + if(state.contains(Properties.AXIS)) return new FabricOrientable(state, Properties.AXIS); + if(state.contains(Properties.HORIZONTAL_AXIS)) return new FabricOrientable(state, Properties.HORIZONTAL_AXIS); if(state.contains(Properties.ROTATION)) return new FabricRotatable(state); + if(state.contains(Properties.FACING)) return new FabricDirectional(state, Properties.FACING); + if(state.contains(Properties.HOPPER_FACING)) return new FabricDirectional(state, Properties.HOPPER_FACING); + if(state.contains(Properties.HORIZONTAL_FACING)) return new FabricDirectional(state, Properties.HORIZONTAL_FACING); + if(state.getProperties().containsAll(Arrays.asList(Properties.NORTH, Properties.SOUTH, Properties.EAST, Properties.WEST))) return new FabricMultipleFacing(state); if(state.contains(Properties.WATERLOGGED)) return new FabricWaterlogged(state); return new FabricBlockData(state); } - public static BlockType adapt(Block block) { - return new FabricBlockType(block); + public static Direction adapt(BlockFace face) { + switch(face) { + case NORTH: + return Direction.NORTH; + case WEST: + return Direction.WEST; + case SOUTH: + return Direction.SOUTH; + case EAST: + return Direction.EAST; + case UP: + return Direction.UP; + case DOWN: + return Direction.DOWN; + default: + throw new IllegalArgumentException("Illegal direction: " + face); + } } - public WorldAccess adapt(FabricWorldHandle worldHandle) { - return worldHandle.getWorld(); + public static BlockType adapt(Block block) { + return new FabricBlockType(block); } public static EntityType adapt(net.minecraft.entity.EntityType entityType) { @@ -87,4 +110,8 @@ public final class FabricAdapter { public static net.minecraft.enchantment.Enchantment adapt(Enchantment enchantment) { return ((FabricEnchantment) enchantment).getHandle(); } + + public WorldAccess adapt(FabricWorldHandle worldHandle) { + return worldHandle.getWorld(); + } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/data/FabricDirectional.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/data/FabricDirectional.java new file mode 100644 index 000000000..21584a8e8 --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/data/FabricDirectional.java @@ -0,0 +1,42 @@ +package com.dfsek.terra.fabric.world.block.data; + +import com.dfsek.terra.api.platform.block.BlockFace; +import com.dfsek.terra.api.platform.block.data.Directional; +import com.dfsek.terra.fabric.world.FabricAdapter; +import com.dfsek.terra.fabric.world.block.FabricBlockData; +import net.minecraft.block.BlockState; +import net.minecraft.state.property.DirectionProperty; + +public class FabricDirectional extends FabricBlockData implements Directional { + private final DirectionProperty property; + + public FabricDirectional(BlockState delegate, DirectionProperty property) { + super(delegate); + this.property = property; + } + + @Override + public BlockFace getFacing() { + switch(delegate.get(property)) { + case SOUTH: + return BlockFace.SOUTH; + case DOWN: + return BlockFace.DOWN; + case UP: + return BlockFace.UP; + case EAST: + return BlockFace.EAST; + case WEST: + return BlockFace.WEST; + case NORTH: + return BlockFace.NORTH; + default: + throw new IllegalStateException(); + } + } + + @Override + public void setFacing(BlockFace facing) { + delegate = delegate.with(property, FabricAdapter.adapt(facing)); + } +} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/data/FabricOrientable.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/data/FabricOrientable.java index c817a917a..5c9e179d0 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/data/FabricOrientable.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/data/FabricOrientable.java @@ -4,15 +4,19 @@ import com.dfsek.terra.api.platform.block.Axis; import com.dfsek.terra.api.platform.block.data.Orientable; import com.dfsek.terra.fabric.world.block.FabricBlockData; import net.minecraft.block.BlockState; -import net.minecraft.state.property.Properties; +import net.minecraft.state.property.EnumProperty; +import net.minecraft.util.math.Direction; import java.util.Arrays; import java.util.Set; import java.util.stream.Collectors; public class FabricOrientable extends FabricBlockData implements Orientable { - public FabricOrientable(BlockState delegate) { + private final EnumProperty property; + + public FabricOrientable(BlockState delegate, EnumProperty property) { super(delegate); + this.property = property; } @Override @@ -22,11 +26,11 @@ public class FabricOrientable extends FabricBlockData implements Orientable { @Override public Axis getAxis() { - return FabricEnumAdapter.adapt(getHandle().get(Properties.AXIS)); + return FabricEnumAdapter.adapt(getHandle().get(property)); } @Override public void setAxis(Axis axis) { - delegate = delegate.with(Properties.AXIS, FabricEnumAdapter.adapt(axis)); + delegate = delegate.with(property, FabricEnumAdapter.adapt(axis)); } } From 5a6b7ac4c1b1f9f757fc80c60131eb877ed1df8f Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 1 Mar 2021 09:58:18 -0700 Subject: [PATCH 40/95] begin work on WorldConfig stuff This doesn't compile right now. A lot of work needs to be done. --- .../events/world/TerraWorldLoadEvent.java | 7 +- .../terra/api/registry/LockedRegistry.java | 4 +- .../structures/script/StructureScript.java | 5 +- .../script/builders/CheckFunctionBuilder.java | 6 +- .../script/functions/CheckFunction.java | 14 +- .../api/world/biome/UserDefinedBiome.java | 9 +- .../biome/provider/ImageBiomeProvider.java | 3 +- .../terra/config/builder/BiomeBuilder.java | 57 ++++++++ .../terra/config/builder/ConfigBuilder.java | 8 ++ .../terra/config/builder/ScriptBuilder.java | 12 ++ .../dfsek/terra/config/dummy/DummyWorld.java | 79 +++++++++++ .../terra/config/factories/BiomeFactory.java | 40 +----- .../terra/config/factories/CarverFactory.java | 2 +- .../{TerraFactory.java => ConfigFactory.java} | 2 +- .../terra/config/factories/FloraFactory.java | 2 +- .../terra/config/factories/OreFactory.java | 2 +- .../config/factories/PaletteFactory.java | 2 +- .../config/factories/StructureFactory.java | 2 +- .../terra/config/factories/TreeFactory.java | 2 +- .../source/BiomeProviderTemplate.java | 6 +- .../source/ImageProviderTemplate.java | 4 +- .../dfsek/terra/config/pack/ConfigPack.java | 39 +++--- .../dfsek/terra/config/pack/WorldConfig.java | 124 ++++++++++++++++++ .../terra/config/templates/BiomeTemplate.java | 3 +- .../dfsek/terra/registry/OpenRegistry.java | 2 +- .../terra/registry/config/BiomeRegistry.java | 7 +- .../com/dfsek/terra/world/TerraWorld.java | 12 +- .../generators/DefaultChunkGenerator2D.java | 2 +- .../generators/DefaultChunkGenerator3D.java | 2 +- .../world/generation/math/SamplerCache.java | 64 +++------ .../terra/world/population/CavePopulator.java | 3 +- .../world/population/StructurePopulator.java | 3 +- 32 files changed, 377 insertions(+), 152 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/config/builder/BiomeBuilder.java create mode 100644 common/src/main/java/com/dfsek/terra/config/builder/ConfigBuilder.java create mode 100644 common/src/main/java/com/dfsek/terra/config/builder/ScriptBuilder.java create mode 100644 common/src/main/java/com/dfsek/terra/config/dummy/DummyWorld.java rename common/src/main/java/com/dfsek/terra/config/factories/{TerraFactory.java => ConfigFactory.java} (80%) create mode 100644 common/src/main/java/com/dfsek/terra/config/pack/WorldConfig.java diff --git a/common/src/main/java/com/dfsek/terra/api/event/events/world/TerraWorldLoadEvent.java b/common/src/main/java/com/dfsek/terra/api/event/events/world/TerraWorldLoadEvent.java index 483f2deef..213786432 100644 --- a/common/src/main/java/com/dfsek/terra/api/event/events/world/TerraWorldLoadEvent.java +++ b/common/src/main/java/com/dfsek/terra/api/event/events/world/TerraWorldLoadEvent.java @@ -1,13 +1,15 @@ package com.dfsek.terra.api.event.events.world; +import com.dfsek.terra.api.event.events.Event; import com.dfsek.terra.api.event.events.PackEvent; import com.dfsek.terra.config.pack.ConfigPack; +import com.dfsek.terra.config.pack.WorldConfig; import com.dfsek.terra.world.TerraWorld; /** * Called upon initialization of a TerraWorld. */ -public class TerraWorldLoadEvent implements PackEvent { +public class TerraWorldLoadEvent implements Event { private final TerraWorld world; public TerraWorldLoadEvent(TerraWorld world) { @@ -18,8 +20,7 @@ public class TerraWorldLoadEvent implements PackEvent { return world; } - @Override - public ConfigPack getPack() { + public WorldConfig getPack() { return world.getConfig(); } } diff --git a/common/src/main/java/com/dfsek/terra/api/registry/LockedRegistry.java b/common/src/main/java/com/dfsek/terra/api/registry/LockedRegistry.java index e53e21e08..6c9525e98 100644 --- a/common/src/main/java/com/dfsek/terra/api/registry/LockedRegistry.java +++ b/common/src/main/java/com/dfsek/terra/api/registry/LockedRegistry.java @@ -15,9 +15,9 @@ import java.util.function.Consumer; * @param Type in registry */ public class LockedRegistry implements Registry { - private final OpenRegistry registry; + private final Registry registry; - public LockedRegistry(OpenRegistry registry) { + public LockedRegistry(Registry registry) { this.registry = registry; } diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java b/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java index 8d6795294..8ceb1bf28 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/StructureScript.java @@ -31,7 +31,6 @@ import com.dfsek.terra.api.structures.structure.buffer.StructureBuffer; import com.dfsek.terra.registry.config.FunctionRegistry; import com.dfsek.terra.registry.config.LootRegistry; import com.dfsek.terra.registry.config.ScriptRegistry; -import com.dfsek.terra.world.generation.math.SamplerCache; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import net.jafama.FastMath; @@ -49,7 +48,7 @@ public class StructureScript { private final TerraPlugin main; private String tempID; - public StructureScript(InputStream inputStream, TerraPlugin main, ScriptRegistry registry, LootRegistry lootRegistry, SamplerCache cache, FunctionRegistry functionRegistry) throws ParseException { + public StructureScript(InputStream inputStream, TerraPlugin main, ScriptRegistry registry, LootRegistry lootRegistry, FunctionRegistry functionRegistry) throws ParseException { Parser parser; try { parser = new Parser(IOUtils.toString(inputStream)); @@ -60,7 +59,7 @@ public class StructureScript { functionRegistry.forEach(parser::registerFunction); // Register registry functions. parser.registerFunction("block", new BlockFunctionBuilder(main)) - .registerFunction("check", new CheckFunctionBuilder(main, cache)) + .registerFunction("check", new CheckFunctionBuilder(main)) .registerFunction("structure", new StructureFunctionBuilder(registry, main)) .registerFunction("randomInt", new RandomFunctionBuilder()) .registerFunction("recursions", new RecursionsFunctionBuilder()) diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/builders/CheckFunctionBuilder.java b/common/src/main/java/com/dfsek/terra/api/structures/script/builders/CheckFunctionBuilder.java index c4e26486a..4ac870f49 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/builders/CheckFunctionBuilder.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/builders/CheckFunctionBuilder.java @@ -12,17 +12,15 @@ import java.util.List; public class CheckFunctionBuilder implements FunctionBuilder { private final TerraPlugin main; - private final SamplerCache cache; - public CheckFunctionBuilder(TerraPlugin main, SamplerCache cache) { + public CheckFunctionBuilder(TerraPlugin main) { this.main = main; - this.cache = cache; } @SuppressWarnings("unchecked") @Override public CheckFunction build(List> argumentList, Position position) throws ParseException { - return new CheckFunction(main, (Returnable) argumentList.get(0), (Returnable) argumentList.get(1), (Returnable) argumentList.get(2), cache, position); + return new CheckFunction(main, (Returnable) argumentList.get(0), (Returnable) argumentList.get(1), (Returnable) argumentList.get(2), position); } @Override diff --git a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/CheckFunction.java b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/CheckFunction.java index 7e1a1b6c8..fee00e6c6 100644 --- a/common/src/main/java/com/dfsek/terra/api/structures/script/functions/CheckFunction.java +++ b/common/src/main/java/com/dfsek/terra/api/structures/script/functions/CheckFunction.java @@ -25,22 +25,23 @@ public class CheckFunction implements Function { private final TerraPlugin main; private final Returnable x, y, z; private final Position position; - private final SamplerCache cache; - public CheckFunction(TerraPlugin main, Returnable x, Returnable y, Returnable z, SamplerCache cache, Position position) { + public CheckFunction(TerraPlugin main, Returnable x, Returnable y, Returnable z, Position position) { this.main = main; this.x = x; this.y = y; this.z = z; this.position = position; - this.cache = cache; } @Override public String apply(ImplementationArguments implementationArguments, Map> variableMap) { + + TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments; + Vector2 xz = new Vector2(x.apply(implementationArguments, variableMap).doubleValue(), z.apply(implementationArguments, variableMap).doubleValue()); RotationUtil.rotateVector(xz, arguments.getRotation()); @@ -52,7 +53,8 @@ public class CheckFunction implements Function { private String apply(Location vector, World world) { TerraWorld tw = main.getWorld(world); - double comp = sample(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ(), world); + SamplerCache cache = tw.getConfig().getSamplerCache(); + double comp = sample(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ(), cache); if(comp > 0) return "LAND"; // If noise val is greater than zero, location will always be land. @@ -64,10 +66,10 @@ public class CheckFunction implements Function { return "OCEAN"; // Below sea level } - private double sample(int x, int y, int z, World w) { + private double sample(int x, int y, int z, SamplerCache cache) { int cx = FastMath.floorDiv(x, 16); int cz = FastMath.floorDiv(z, 16); - return cache.get(w, x, z).sample(x - (cx << 4), y, z - (cz << 4)); + return cache.get(x, z).sample(x - (cx << 4), y, z - (cz << 4)); } @Override diff --git a/common/src/main/java/com/dfsek/terra/api/world/biome/UserDefinedBiome.java b/common/src/main/java/com/dfsek/terra/api/world/biome/UserDefinedBiome.java index 40d12c428..4425bc70a 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/biome/UserDefinedBiome.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/UserDefinedBiome.java @@ -5,6 +5,7 @@ import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.config.builder.GeneratorBuilder; import com.dfsek.terra.config.templates.BiomeTemplate; +import com.dfsek.terra.world.generation.WorldGenerator; import java.util.HashSet; import java.util.Set; @@ -13,7 +14,7 @@ import java.util.Set; * Class representing a config-defined biome */ public class UserDefinedBiome implements TerraBiome { - private final GeneratorBuilder gen; + private final WorldGenerator gen; private final ProbabilityCollection vanilla; private final String id; private final BiomeTemplate config; @@ -21,13 +22,13 @@ public class UserDefinedBiome implements TerraBiome { private final Set tags; - public UserDefinedBiome(ProbabilityCollection vanilla, GeneratorBuilder gen, BiomeTemplate config) { + public UserDefinedBiome(ProbabilityCollection vanilla, WorldGenerator gen, BiomeTemplate config) { this.vanilla = vanilla; this.gen = gen; this.id = config.getID(); this.config = config; this.color = config.getColor(); - this.tags = config.getTags() == null ? new HashSet<>() : config.getTags(); + this.tags = config.getTags(); tags.add("BIOME:" + id); } @@ -52,7 +53,7 @@ public class UserDefinedBiome implements TerraBiome { @Override public Generator getGenerator(World w) { - return gen.build(w.getSeed()); + return gen; } @Override diff --git a/common/src/main/java/com/dfsek/terra/api/world/biome/provider/ImageBiomeProvider.java b/common/src/main/java/com/dfsek/terra/api/world/biome/provider/ImageBiomeProvider.java index abf5de855..5d0c0007f 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/biome/provider/ImageBiomeProvider.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/provider/ImageBiomeProvider.java @@ -1,5 +1,6 @@ package com.dfsek.terra.api.world.biome.provider; +import com.dfsek.terra.api.registry.Registry; import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.registry.OpenRegistry; import net.jafama.FastMath; @@ -15,7 +16,7 @@ public class ImageBiomeProvider implements BiomeProvider, BiomeProvider.BiomePro private final int resolution; private final Align align; - public ImageBiomeProvider(OpenRegistry registry, BufferedImage image, int resolution, Align align) { + public ImageBiomeProvider(Registry registry, BufferedImage image, int resolution, Align align) { this.image = image; this.resolution = resolution; this.align = align; diff --git a/common/src/main/java/com/dfsek/terra/config/builder/BiomeBuilder.java b/common/src/main/java/com/dfsek/terra/config/builder/BiomeBuilder.java new file mode 100644 index 000000000..a9929c23f --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/config/builder/BiomeBuilder.java @@ -0,0 +1,57 @@ +package com.dfsek.terra.config.builder; + +import com.dfsek.paralithic.eval.parser.Scope; +import com.dfsek.paralithic.eval.tokenizer.ParseException; +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.math.noise.NoiseSampler; +import com.dfsek.terra.api.math.noise.samplers.ExpressionSampler; +import com.dfsek.terra.api.math.noise.samplers.noise.ConstantSampler; +import com.dfsek.terra.api.util.seeded.NoiseSeeded; +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.UserDefinedBiome; +import com.dfsek.terra.config.loaders.config.function.FunctionTemplate; +import com.dfsek.terra.config.pack.ConfigPack; +import com.dfsek.terra.config.templates.BiomeTemplate; +import com.dfsek.terra.world.TerraWorld; +import com.dfsek.terra.world.generation.WorldGenerator; + +import java.util.HashMap; +import java.util.Map; + +public class BiomeBuilder implements ConfigBuilder { + private final BiomeTemplate template; + private final ConfigPack pack; + + public BiomeBuilder(BiomeTemplate template, ConfigPack pack) { + this.template = template; + this.pack = pack; + } + + @Override + public TerraBiome build(TerraWorld world, TerraPlugin main) { + NoiseSampler noise; + NoiseSampler elevation; + NoiseSampler carving; + Scope varScope = new Scope().withParent(pack.getVarScope()); + + template.getVariables().forEach(varScope::create); + + Map noiseBuilderMap = pack.getTemplate().getNoiseBuilderMap(); + Map functionTemplateMap = new HashMap<>(template.getFunctions()); + + functionTemplateMap.putAll(template.getFunctions()); + + long seed = world.getWorld().getSeed(); + try { + noise = new ExpressionSampler(template.getNoiseEquation(), varScope, seed, noiseBuilderMap, functionTemplateMap); + elevation = template.getElevationEquation() == null ? new ConstantSampler(0) : new ExpressionSampler(template.getElevationEquation(), varScope, seed, noiseBuilderMap, functionTemplateMap); + carving = new ExpressionSampler(template.getCarvingEquation(), varScope, seed, noiseBuilderMap, functionTemplateMap); + } catch(ParseException e) { + throw new RuntimeException(e); + } + + WorldGenerator generator = new WorldGenerator(template.getPalette(), template.getSlantPalette(), noise, elevation, carving, template.getBiomeNoise().apply(seed), template.getElevationWeight(), + template.getBlendDistance(), template.getBlendStep(), template.getBlendWeight()); + return new UserDefinedBiome(template.getVanilla(), generator, template); + } +} diff --git a/common/src/main/java/com/dfsek/terra/config/builder/ConfigBuilder.java b/common/src/main/java/com/dfsek/terra/config/builder/ConfigBuilder.java new file mode 100644 index 000000000..2657c09d4 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/config/builder/ConfigBuilder.java @@ -0,0 +1,8 @@ +package com.dfsek.terra.config.builder; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.world.TerraWorld; + +public interface ConfigBuilder { + O build(TerraWorld world, TerraPlugin main); +} diff --git a/common/src/main/java/com/dfsek/terra/config/builder/ScriptBuilder.java b/common/src/main/java/com/dfsek/terra/config/builder/ScriptBuilder.java new file mode 100644 index 000000000..9e9afde95 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/config/builder/ScriptBuilder.java @@ -0,0 +1,12 @@ +package com.dfsek.terra.config.builder; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.structures.script.StructureScript; +import com.dfsek.terra.world.TerraWorld; + +public class ScriptBuilder implements ConfigBuilder { + @Override + public StructureScript build(TerraWorld world, TerraPlugin main) { + return null; + } +} diff --git a/common/src/main/java/com/dfsek/terra/config/dummy/DummyWorld.java b/common/src/main/java/com/dfsek/terra/config/dummy/DummyWorld.java new file mode 100644 index 000000000..3c2e100fe --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/config/dummy/DummyWorld.java @@ -0,0 +1,79 @@ +package com.dfsek.terra.config.dummy; + +import com.dfsek.terra.api.math.vector.Location; +import com.dfsek.terra.api.platform.block.Block; +import com.dfsek.terra.api.platform.entity.Entity; +import com.dfsek.terra.api.platform.entity.EntityType; +import com.dfsek.terra.api.platform.world.Chunk; +import com.dfsek.terra.api.platform.world.World; +import com.dfsek.terra.api.platform.world.generator.ChunkGenerator; + +import java.io.File; +import java.util.UUID; + +public class DummyWorld implements World { + @Override + public Object getHandle() { + throw new UnsupportedOperationException("Cannot get handle of DummyWorld"); + } + + @Override + public long getSeed() { + return 2403L; + } + + @Override + public int getMaxHeight() { + return 155; + } + + @Override + public ChunkGenerator getGenerator() { + throw new UnsupportedOperationException("Cannot get generator of DummyWorld"); + } + + @Override + public String getName() { + return "DUMMY"; + } + + @Override + public UUID getUID() { + return UUID.randomUUID(); + } + + @Override + public boolean isChunkGenerated(int x, int z) { + return false; + } + + @Override + public Chunk getChunkAt(int x, int z) { + throw new UnsupportedOperationException("Cannot get chunk in DummyWorld"); + } + + @Override + public File getWorldFolder() { + throw new UnsupportedOperationException("Cannot get folder of DummyWorld"); + } + + @Override + public Block getBlockAt(int x, int y, int z) { + throw new UnsupportedOperationException("Cannot get block in DummyWorld"); + } + + @Override + public Block getBlockAt(Location l) { + throw new UnsupportedOperationException("Cannot get block in DummyWorld"); + } + + @Override + public Entity spawnEntity(Location location, EntityType entityType) { + throw new UnsupportedOperationException("Cannot spawn entity in DummyWorld"); + } + + @Override + public int getMinHeight() { + return 0; + } +} diff --git a/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java b/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java index 66d871149..03c396461 100644 --- a/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java +++ b/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java @@ -1,18 +1,13 @@ package com.dfsek.terra.config.factories; -import com.dfsek.paralithic.eval.parser.Scope; import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.world.biome.TerraBiome; -import com.dfsek.terra.api.world.biome.UserDefinedBiome; -import com.dfsek.terra.config.builder.GeneratorBuilder; -import com.dfsek.terra.config.loaders.config.function.FunctionTemplate; +import com.dfsek.terra.config.builder.BiomeBuilder; +import com.dfsek.terra.config.builder.ConfigBuilder; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.config.templates.BiomeTemplate; -import java.util.LinkedHashMap; -import java.util.Map; - -public class BiomeFactory implements TerraFactory { +public class BiomeFactory implements ConfigFactory> { private final ConfigPack pack; public BiomeFactory(ConfigPack pack) { @@ -20,32 +15,7 @@ public class BiomeFactory implements TerraFactory { } @Override - public UserDefinedBiome build(BiomeTemplate template, TerraPlugin main) { - GeneratorBuilder generatorBuilder = new GeneratorBuilder(); - generatorBuilder.setElevationEquation(template.getElevationEquation()); - generatorBuilder.setNoiseEquation(template.getNoiseEquation()); - generatorBuilder.setCarvingEquation(template.getCarvingEquation()); - generatorBuilder.setNoiseBuilderMap(pack.getTemplate().getNoiseBuilderMap()); - - Map functions = new LinkedHashMap<>(pack.getTemplate().getFunctions()); // linked map to preserve order. - functions.putAll(template.getFunctions()); - generatorBuilder.setFunctionTemplateMap(functions); - - generatorBuilder.setPalettes(template.getPalette()); - generatorBuilder.setSlantPalettes(template.getSlantPalette()); - - Scope vars = new Scope().withParent(pack.getVarScope()); - template.getVariables().forEach(vars::create); - generatorBuilder.setVarScope(vars); - - generatorBuilder.setInterpolateElevation(template.interpolateElevation()); - generatorBuilder.setElevationWeight(template.getElevationWeight()); - generatorBuilder.setBiomeNoise(template.getBiomeNoise()); - generatorBuilder.setBlendDistance(template.getBlendDistance()); - generatorBuilder.setBlendStep(template.getBlendStep()); - generatorBuilder.setBlendWeight(template.getBlendWeight()); - - - return new UserDefinedBiome(template.getVanilla(), generatorBuilder, template); + public BiomeBuilder build(BiomeTemplate template, TerraPlugin main) { + return new BiomeBuilder(template, pack); } } diff --git a/common/src/main/java/com/dfsek/terra/config/factories/CarverFactory.java b/common/src/main/java/com/dfsek/terra/config/factories/CarverFactory.java index 9b3e681c7..e572f3e6c 100644 --- a/common/src/main/java/com/dfsek/terra/config/factories/CarverFactory.java +++ b/common/src/main/java/com/dfsek/terra/config/factories/CarverFactory.java @@ -11,7 +11,7 @@ import com.dfsek.terra.config.templates.CarverTemplate; import java.util.Arrays; import java.util.List; -public class CarverFactory implements TerraFactory { +public class CarverFactory implements ConfigFactory { private final ConfigPack pack; public CarverFactory(ConfigPack pack) { diff --git a/common/src/main/java/com/dfsek/terra/config/factories/TerraFactory.java b/common/src/main/java/com/dfsek/terra/config/factories/ConfigFactory.java similarity index 80% rename from common/src/main/java/com/dfsek/terra/config/factories/TerraFactory.java rename to common/src/main/java/com/dfsek/terra/config/factories/ConfigFactory.java index 5965eb4ad..cf676a8d6 100644 --- a/common/src/main/java/com/dfsek/terra/config/factories/TerraFactory.java +++ b/common/src/main/java/com/dfsek/terra/config/factories/ConfigFactory.java @@ -4,6 +4,6 @@ import com.dfsek.tectonic.config.ConfigTemplate; import com.dfsek.tectonic.exception.LoadException; import com.dfsek.terra.api.TerraPlugin; -public interface TerraFactory { +public interface ConfigFactory { O build(C config, TerraPlugin main) throws LoadException; } diff --git a/common/src/main/java/com/dfsek/terra/config/factories/FloraFactory.java b/common/src/main/java/com/dfsek/terra/config/factories/FloraFactory.java index 160e1dc21..279dbf3e4 100644 --- a/common/src/main/java/com/dfsek/terra/config/factories/FloraFactory.java +++ b/common/src/main/java/com/dfsek/terra/config/factories/FloraFactory.java @@ -10,7 +10,7 @@ import com.dfsek.terra.api.world.palette.holder.PaletteLayerHolder; import com.dfsek.terra.config.templates.FloraTemplate; import com.dfsek.terra.world.population.items.flora.TerraFlora; -public class FloraFactory implements TerraFactory { +public class FloraFactory implements ConfigFactory { @Override public TerraFlora build(FloraTemplate config, TerraPlugin main) { Palette palette = new NoisePalette<>(new WhiteNoiseSampler(2403), false); diff --git a/common/src/main/java/com/dfsek/terra/config/factories/OreFactory.java b/common/src/main/java/com/dfsek/terra/config/factories/OreFactory.java index 9eeede7af..fdbf6ea90 100644 --- a/common/src/main/java/com/dfsek/terra/config/factories/OreFactory.java +++ b/common/src/main/java/com/dfsek/terra/config/factories/OreFactory.java @@ -7,7 +7,7 @@ import com.dfsek.terra.world.population.items.ores.DeformedSphereOre; import com.dfsek.terra.world.population.items.ores.Ore; import com.dfsek.terra.world.population.items.ores.VanillaOre; -public class OreFactory implements TerraFactory { +public class OreFactory implements ConfigFactory { @Override public Ore build(OreTemplate config, TerraPlugin main) { BlockData m = config.getMaterial(); diff --git a/common/src/main/java/com/dfsek/terra/config/factories/PaletteFactory.java b/common/src/main/java/com/dfsek/terra/config/factories/PaletteFactory.java index d7cf0a74c..d4983c076 100644 --- a/common/src/main/java/com/dfsek/terra/config/factories/PaletteFactory.java +++ b/common/src/main/java/com/dfsek/terra/config/factories/PaletteFactory.java @@ -7,7 +7,7 @@ import com.dfsek.terra.api.world.palette.Palette; import com.dfsek.terra.api.world.palette.holder.PaletteLayerHolder; import com.dfsek.terra.config.templates.PaletteTemplate; -public class PaletteFactory implements TerraFactory> { +public class PaletteFactory implements ConfigFactory> { @Override public Palette build(PaletteTemplate config, TerraPlugin main) { NoisePalette palette = new NoisePalette<>(config.getNoise().apply(2403L), config.getNoise().getDimensions() == 2); diff --git a/common/src/main/java/com/dfsek/terra/config/factories/StructureFactory.java b/common/src/main/java/com/dfsek/terra/config/factories/StructureFactory.java index afefca45f..0fa25315d 100644 --- a/common/src/main/java/com/dfsek/terra/config/factories/StructureFactory.java +++ b/common/src/main/java/com/dfsek/terra/config/factories/StructureFactory.java @@ -4,7 +4,7 @@ import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.config.templates.StructureTemplate; import com.dfsek.terra.world.population.items.TerraStructure; -public class StructureFactory implements TerraFactory { +public class StructureFactory implements ConfigFactory { @Override public TerraStructure build(StructureTemplate config, TerraPlugin main) { return new TerraStructure(config.getStructures(), config.getY(), config.getSpawn(), config); diff --git a/common/src/main/java/com/dfsek/terra/config/factories/TreeFactory.java b/common/src/main/java/com/dfsek/terra/config/factories/TreeFactory.java index 681e03b45..9d6963e0e 100644 --- a/common/src/main/java/com/dfsek/terra/config/factories/TreeFactory.java +++ b/common/src/main/java/com/dfsek/terra/config/factories/TreeFactory.java @@ -5,7 +5,7 @@ import com.dfsek.terra.api.world.tree.Tree; import com.dfsek.terra.config.templates.TreeTemplate; import com.dfsek.terra.world.population.items.tree.TerraTree; -public class TreeFactory implements TerraFactory { +public class TreeFactory implements ConfigFactory { @Override public Tree build(TreeTemplate config, TerraPlugin main) { return new TerraTree(config.getSpawnable(), config.getyOffset(), config.getStructures()); diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/BiomeProviderTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/BiomeProviderTemplate.java index 89b6d2b6c..85e0a5ea5 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/BiomeProviderTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/BiomeProviderTemplate.java @@ -5,12 +5,14 @@ import com.dfsek.tectonic.annotations.Value; import com.dfsek.tectonic.loading.object.ObjectTemplate; import com.dfsek.terra.api.math.noise.NoiseSampler; import com.dfsek.terra.api.math.noise.samplers.noise.ConstantSampler; +import com.dfsek.terra.api.registry.Registry; import com.dfsek.terra.api.util.seeded.NoiseSeeded; +import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.registry.config.BiomeRegistry; public abstract class BiomeProviderTemplate implements ObjectTemplate, BiomeProvider.BiomeProviderBuilder { - protected final BiomeRegistry registry; + protected final Registry registry; @Value("resolution") @Default protected int resolution = 1; @@ -33,7 +35,7 @@ public abstract class BiomeProviderTemplate implements ObjectTemplate registry) { this.registry = registry; } diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/ImageProviderTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/ImageProviderTemplate.java index d9668b2ca..857385f77 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/ImageProviderTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/ImageProviderTemplate.java @@ -1,6 +1,8 @@ package com.dfsek.terra.config.loaders.config.biome.templates.source; import com.dfsek.tectonic.annotations.Value; +import com.dfsek.terra.api.registry.Registry; +import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.api.world.biome.provider.ImageBiomeProvider; import com.dfsek.terra.registry.config.BiomeRegistry; @@ -14,7 +16,7 @@ public class ImageProviderTemplate extends BiomeProviderTemplate { @Value("image.align") private ImageBiomeProvider.Align align; - public ImageProviderTemplate(BiomeRegistry registry) { + public ImageProviderTemplate(Registry registry) { super(registry); } diff --git a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java index dafcc73e4..60aaccea9 100644 --- a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java +++ b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java @@ -23,13 +23,15 @@ import com.dfsek.terra.api.world.flora.Flora; import com.dfsek.terra.api.world.palette.Palette; import com.dfsek.terra.api.world.tree.Tree; import com.dfsek.terra.carving.UserDefinedCarver; +import com.dfsek.terra.config.builder.ConfigBuilder; +import com.dfsek.terra.config.dummy.DummyWorld; import com.dfsek.terra.config.factories.BiomeFactory; import com.dfsek.terra.config.factories.CarverFactory; import com.dfsek.terra.config.factories.FloraFactory; import com.dfsek.terra.config.factories.OreFactory; import com.dfsek.terra.config.factories.PaletteFactory; import com.dfsek.terra.config.factories.StructureFactory; -import com.dfsek.terra.config.factories.TerraFactory; +import com.dfsek.terra.config.factories.ConfigFactory; import com.dfsek.terra.config.factories.TreeFactory; import com.dfsek.terra.config.fileloaders.FolderLoader; import com.dfsek.terra.config.fileloaders.Loader; @@ -60,7 +62,7 @@ import com.dfsek.terra.registry.config.PaletteRegistry; import com.dfsek.terra.registry.config.ScriptRegistry; import com.dfsek.terra.registry.config.StructureRegistry; import com.dfsek.terra.registry.config.TreeRegistry; -import com.dfsek.terra.world.generation.math.SamplerCache; +import com.dfsek.terra.world.TerraWorld; import com.dfsek.terra.world.population.items.TerraStructure; import com.dfsek.terra.world.population.items.ores.Ore; import org.apache.commons.io.IOUtils; @@ -106,8 +108,6 @@ public class ConfigPack implements LoaderRegistrar { private final ConfigLoader selfLoader = new ConfigLoader(); private final Scope varScope = new Scope(); - private final SamplerCache samplerCache; - private final TerraPlugin main; private final Loader loader; @@ -119,7 +119,6 @@ public class ConfigPack implements LoaderRegistrar { this.loader = new FolderLoader(folder.toPath()); this.main = main; long l = System.nanoTime(); - this.samplerCache = new SamplerCache(main); floraRegistry = new FloraRegistry(main); paletteRegistry = new PaletteRegistry(main); treeRegistry = new TreeRegistry(main); @@ -148,6 +147,7 @@ public class ConfigPack implements LoaderRegistrar { main.logger().severe("Failed to load config pack from folder \"" + folder.getAbsolutePath() + "\""); throw e; } + toWorldConfig(new TerraWorld(new DummyWorld(), this, main)); // Build now to catch any errors immediately. } public ConfigPack(ZipFile file, TerraPlugin main) throws ConfigException { @@ -155,7 +155,6 @@ public class ConfigPack implements LoaderRegistrar { this.loader = new ZIPLoader(file); this.main = main; long l = System.nanoTime(); - this.samplerCache = new SamplerCache(main); floraRegistry = new FloraRegistry(main); paletteRegistry = new PaletteRegistry(main); treeRegistry = new TreeRegistry(main); @@ -192,9 +191,11 @@ public class ConfigPack implements LoaderRegistrar { main.logger().severe("Failed to load config pack from ZIP archive \"" + file.getName() + "\""); throw e; } + + toWorldConfig(new TerraWorld(new DummyWorld(), this, main)); // Build now to catch any errors immediately. } - public static void buildAll(TerraFactory factory, OpenRegistry registry, List configTemplates, TerraPlugin main) throws LoadException { + public static void buildAll(ConfigFactory factory, OpenRegistry registry, List configTemplates, TerraPlugin main) throws LoadException { for(C template : configTemplates) registry.add(template.getID(), factory.build(template, main)); } @@ -207,10 +208,10 @@ public class ConfigPack implements LoaderRegistrar { loader.open("structures/data", ".tesf").thenEntries(entries -> { for(Map.Entry entry : entries) { - try { - StructureScript structureScript = new StructureScript(entry.getValue(), main, scriptRegistry, lootRegistry, samplerCache, functionRegistry); + try(InputStream stream = entry.getValue()) { + StructureScript structureScript = new StructureScript(stream, main, scriptRegistry, lootRegistry, functionRegistry); scriptRegistry.add(structureScript.getId(), structureScript); - } catch(com.dfsek.terra.api.structures.parser.exceptions.ParseException e) { + } catch(com.dfsek.terra.api.structures.parser.exceptions.ParseException | IOException e) { throw new LoadException("Unable to load script \"" + entry.getKey() + "\"", e); } } @@ -237,14 +238,6 @@ public class ConfigPack implements LoaderRegistrar { main.logger().info("Loaded config pack \"" + template.getID() + "\" v" + template.getVersion() + " by " + template.getAuthor() + " in " + (System.nanoTime() - start) / 1000000D + "ms."); } - public TerraBiome getBiome(String id) { - return biomeRegistry.get(id); - } - - public List getBiomeIDs() { - return biomeRegistry.entries().stream().map(TerraBiome::getID).collect(Collectors.toList()); - } - public TerraStructure getStructure(String id) { return structureRegistry.get(id); } @@ -285,10 +278,6 @@ public class ConfigPack implements LoaderRegistrar { .registerLoader(ImageSamplerTemplate.class, () -> new ImageProviderTemplate(biomeRegistry)); } - public SamplerCache getSamplerCache() { - return samplerCache; - } - public Set getCarvers() { return carverRegistry.entries(); } @@ -301,7 +290,7 @@ public class ConfigPack implements LoaderRegistrar { return new CheckedRegistry<>(scriptRegistry); } - public CheckedRegistry getBiomeRegistry() { + public CheckedRegistry> getBiomeRegistry() { return new CheckedRegistry<>(biomeRegistry); } @@ -340,4 +329,8 @@ public class ConfigPack implements LoaderRegistrar { public CheckedRegistry getStructureRegistry() { return new CheckedRegistry<>(structureRegistry); } + + public WorldConfig toWorldConfig(TerraWorld world){ + return new WorldConfig(world, this, main); + } } diff --git a/common/src/main/java/com/dfsek/terra/config/pack/WorldConfig.java b/common/src/main/java/com/dfsek/terra/config/pack/WorldConfig.java new file mode 100644 index 000000000..036192d77 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/config/pack/WorldConfig.java @@ -0,0 +1,124 @@ +package com.dfsek.terra.config.pack; + +import com.dfsek.tectonic.loading.object.ObjectTemplate; +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.platform.block.BlockData; +import com.dfsek.terra.api.platform.world.World; +import com.dfsek.terra.api.registry.LockedRegistry; +import com.dfsek.terra.api.structures.loot.LootTable; +import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder; +import com.dfsek.terra.api.structures.script.StructureScript; +import com.dfsek.terra.api.util.seeded.NoiseSeeded; +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; +import com.dfsek.terra.api.world.flora.Flora; +import com.dfsek.terra.api.world.palette.Palette; +import com.dfsek.terra.api.world.tree.Tree; +import com.dfsek.terra.carving.UserDefinedCarver; +import com.dfsek.terra.registry.OpenRegistry; +import com.dfsek.terra.world.TerraWorld; +import com.dfsek.terra.world.generation.math.SamplerCache; +import com.dfsek.terra.world.population.items.TerraStructure; +import com.dfsek.terra.world.population.items.ores.Ore; + +import java.util.Set; +import java.util.function.Supplier; + +public class WorldConfig { + private final LockedRegistry scriptRegistry; + private final LockedRegistry biomeRegistry; + private final SamplerCache samplerCache; + private final LockedRegistry carverRegistry; + private final LockedRegistry treeRegistry; + private final LockedRegistry floraRegistry; + private final LockedRegistry lootRegistry; + private final LockedRegistry oreRegistry; + private final LockedRegistry> paletteRegistry; + private final LockedRegistry structureRegistry; + + private final BiomeProvider provider; + + private final TerraWorld world; + private final ConfigPack pack; + + public WorldConfig(TerraWorld world, ConfigPack pack, TerraPlugin main) { + this.world = world; + this.pack = pack; + this.samplerCache = new SamplerCache(main, world); + this.scriptRegistry = new LockedRegistry<>(pack.getScriptRegistry()); + + OpenRegistry biomeOpenRegistry = new OpenRegistry<>(); + pack.getBiomeRegistry().forEach((id, biome) -> biomeOpenRegistry.add(id, biome.build(world, main))); + + this.biomeRegistry = new LockedRegistry<>(biomeOpenRegistry); + this.carverRegistry = new LockedRegistry<>(pack.getCarverRegistry()); + this.treeRegistry = new LockedRegistry<>(pack.getTreeRegistry()); + this.floraRegistry = new LockedRegistry<>(pack.getFloraRegistry()); + this.lootRegistry = new LockedRegistry<>(pack.getLootRegistry()); + this.oreRegistry = new LockedRegistry<>(pack.getOreRegistry()); + this.paletteRegistry = new LockedRegistry<>(pack.getPaletteRegistry()); + this.structureRegistry = new LockedRegistry<>(pack.getStructureRegistry()); + + this.provider = pack.getBiomeProviderBuilder().build(world.getWorld().getSeed()); + } + + public TerraWorld getWorld() { + return world; + } + + public SamplerCache getSamplerCache() { + return samplerCache; + } + + public Set getCarvers() { + return carverRegistry.entries(); + } + + public LockedRegistry getScriptRegistry() { + return scriptRegistry; + } + + public LockedRegistry getBiomeRegistry() { + return biomeRegistry; + } + + public LockedRegistry getTreeRegistry() { + return treeRegistry; + } + + public LockedRegistry getCarverRegistry() { + return carverRegistry; + } + + public LockedRegistry getFloraRegistry() { + return floraRegistry; + } + + public LockedRegistry getLootRegistry() { + return lootRegistry; + } + + public LockedRegistry getOreRegistry() { + return oreRegistry; + } + + public LockedRegistry> getPaletteRegistry() { + return paletteRegistry; + } + + public LockedRegistry getStructureRegistry() { + return structureRegistry; + } + + public BiomeProvider getProvider() { + return provider; + } + + public Set getStructures() { + return structureRegistry.entries(); + } + + public ConfigPackTemplate getTemplate() { + return pack.getTemplate(); + } +} diff --git a/common/src/main/java/com/dfsek/terra/config/templates/BiomeTemplate.java b/common/src/main/java/com/dfsek/terra/config/templates/BiomeTemplate.java index 42bbdb452..b3a28548b 100644 --- a/common/src/main/java/com/dfsek/terra/config/templates/BiomeTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/templates/BiomeTemplate.java @@ -31,6 +31,7 @@ import com.dfsek.terra.world.population.items.ores.OreHolder; import com.dfsek.terra.world.population.items.tree.TreeLayer; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -182,7 +183,7 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf @Value("tags") @Default @Abstractable - private Set tags; + private Set tags = new HashSet<>(); @Value("carving") @Abstractable diff --git a/common/src/main/java/com/dfsek/terra/registry/OpenRegistry.java b/common/src/main/java/com/dfsek/terra/registry/OpenRegistry.java index 43fc732bd..5838a158c 100644 --- a/common/src/main/java/com/dfsek/terra/registry/OpenRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/OpenRegistry.java @@ -17,7 +17,7 @@ import java.util.function.Consumer; * Registry implementation with read/write access. For internal use only. * @param */ -public abstract class OpenRegistry implements Registry { +public class OpenRegistry implements Registry { private final Map objects = new HashMap<>(); @Override diff --git a/common/src/main/java/com/dfsek/terra/registry/config/BiomeRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/BiomeRegistry.java index 924efc3d6..cd06f3678 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/BiomeRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/BiomeRegistry.java @@ -3,15 +3,16 @@ package com.dfsek.terra.registry.config; import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.config.builder.ConfigBuilder; import com.dfsek.terra.registry.OpenRegistry; import java.lang.reflect.Type; -public class BiomeRegistry extends OpenRegistry { +public class BiomeRegistry extends OpenRegistry> { @Override - public TerraBiome load(Type type, Object o, ConfigLoader configLoader) throws LoadException { + public ConfigBuilder load(Type type, Object o, ConfigLoader configLoader) throws LoadException { if(o.equals("SELF")) return null; - TerraBiome biome = get((String) o); + ConfigBuilder biome = get((String) o); if(biome == null) throw new LoadException("No such " + type.getTypeName() + " matching \"" + o + "\" was found in this registry."); return biome; diff --git a/common/src/main/java/com/dfsek/terra/world/TerraWorld.java b/common/src/main/java/com/dfsek/terra/world/TerraWorld.java index f14773800..6866a6047 100644 --- a/common/src/main/java/com/dfsek/terra/world/TerraWorld.java +++ b/common/src/main/java/com/dfsek/terra/world/TerraWorld.java @@ -12,13 +12,14 @@ import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.api.world.generation.TerraChunkGenerator; import com.dfsek.terra.api.world.palette.Palette; import com.dfsek.terra.config.pack.ConfigPack; +import com.dfsek.terra.config.pack.WorldConfig; import com.dfsek.terra.profiler.WorldProfiler; import com.dfsek.terra.world.generation.math.samplers.Sampler; import net.jafama.FastMath; public class TerraWorld { private final BiomeProvider provider; - private final ConfigPack config; + private final WorldConfig config; private final boolean safe; private final WorldProfiler profiler; private final World world; @@ -27,10 +28,9 @@ public class TerraWorld { public TerraWorld(World w, ConfigPack c, TerraPlugin main) { if(!isTerraWorld(w)) throw new IllegalArgumentException("World " + w + " is not a Terra World!"); - c.getBiomeRegistry().forEach(biome -> biome.getGenerator(w)); // Load all gens to cache - config = c; + config = c.toWorldConfig(this); profiler = new WorldProfiler(w); - this.provider = config.getBiomeProviderBuilder().build(w.getSeed()); + this.provider = config.getProvider(); this.world = w; air = main.getWorldHandle().createBlockData("minecraft:air"); main.getEventManager().callEvent(new TerraWorldLoadEvent(this)); @@ -53,7 +53,7 @@ public class TerraWorld { return provider; } - public ConfigPack getConfig() { + public WorldConfig getConfig() { return config; } @@ -76,7 +76,7 @@ public class TerraWorld { public BlockData getUngeneratedBlock(int x, int y, int z) { UserDefinedBiome biome = (UserDefinedBiome) provider.getBiome(x, z); Palette palette = biome.getGenerator(world).getPalette(y); - Sampler sampler = config.getSamplerCache().get(world, x, z); + Sampler sampler = config.getSamplerCache().get(x, z); int fdX = FastMath.floorMod(x, 16); int fdZ = FastMath.floorMod(z, 16); double noise = sampler.sample(fdX, y, fdZ); diff --git a/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator2D.java b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator2D.java index 3f841b95a..32ab4801d 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator2D.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator2D.java @@ -86,7 +86,7 @@ public class DefaultChunkGenerator2D implements TerraChunkGenerator { int xOrig = (chunkX << 4); int zOrig = (chunkZ << 4); - Sampler sampler = cache.getChunk(world, chunkX, chunkZ); + Sampler sampler = cache.getChunk(chunkX, chunkZ); for(int x = 0; x < 16; x++) { for(int z = 0; z < 16; z++) { diff --git a/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java index b4ab83e49..4b93250c9 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java @@ -99,7 +99,7 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator { int xOrig = (chunkX << 4); int zOrig = (chunkZ << 4); - Sampler sampler = cache.getChunk(world, chunkX, chunkZ); + Sampler sampler = cache.getChunk(chunkX, chunkZ); for(int x = 0; x < 16; x++) { for(int z = 0; z < 16; z++) { diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/SamplerCache.java b/common/src/main/java/com/dfsek/terra/world/generation/math/SamplerCache.java index bfc287d9e..f3ebae0d5 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/math/SamplerCache.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/SamplerCache.java @@ -16,56 +16,28 @@ import java.util.HashMap; import java.util.Map; public class SamplerCache { - private final Map containerMap; - private final TerraPlugin main; + private final LoadingCache cache; - public SamplerCache(TerraPlugin main) { - containerMap = Collections.synchronizedMap(new HashMap<>()); - this.main = main; + public SamplerCache(TerraPlugin main, TerraWorld world) { + cache = CacheBuilder.newBuilder().maximumSize(main.getTerraConfig().getSamplerCache()) + .build(new CacheLoader() { + @Override + public Sampler load(@NotNull Long key) { + int cx = (int) (key >> 32); + int cz = (int) key.longValue(); + return world.getGenerator().createSampler(cx, cz, world.getBiomeProvider(), world.getWorld(), world.getConfig().getTemplate().getElevationBlend()); + } + }); } - public Sampler get(World world, int x, int z) { - synchronized(containerMap) { - return containerMap.computeIfAbsent(world.getSeed(), seed -> new Container(world)).get(x, z); - } + public Sampler get(int x, int z) { + int cx = FastMath.floorDiv(x, 16); + int cz = FastMath.floorDiv(z, 16); + return getChunk(cx, cz); } - public Sampler getChunk(World world, int chunkX, int chunkZ) { - synchronized(containerMap) { - return containerMap.computeIfAbsent(world.getSeed(), seed -> new Container(world)).getChunk(chunkX, chunkZ); - } - } - - public void clear() { - containerMap.clear(); - } - - private final class Container { - private final TerraWorld terraWorld; - private final LoadingCache cache; - - private Container(World world) { - cache = CacheBuilder.newBuilder().maximumSize(main.getTerraConfig().getSamplerCache()) - .build(new CacheLoader() { - @Override - public Sampler load(@NotNull Long key) { - int cx = (int) (key >> 32); - int cz = (int) key.longValue(); - return terraWorld.getGenerator().createSampler(cx, cz, terraWorld.getBiomeProvider(), world, terraWorld.getConfig().getTemplate().getElevationBlend()); - } - }); - terraWorld = main.getWorld(world); - } - - public Sampler get(int x, int z) { - int cx = FastMath.floorDiv(x, 16); - int cz = FastMath.floorDiv(z, 16); - return getChunk(cx, cz); - } - - public Sampler getChunk(int cx, int cz) { - long key = MathUtil.squash(cx, cz); - return cache.getUnchecked(key); - } + public Sampler getChunk(int cx, int cz) { + long key = MathUtil.squash(cx, cz); + return cache.getUnchecked(key); } } diff --git a/common/src/main/java/com/dfsek/terra/world/population/CavePopulator.java b/common/src/main/java/com/dfsek/terra/world/population/CavePopulator.java index 4b2e7c126..9767b0acc 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/CavePopulator.java +++ b/common/src/main/java/com/dfsek/terra/world/population/CavePopulator.java @@ -12,6 +12,7 @@ import com.dfsek.terra.api.util.world.PopulationUtil; import com.dfsek.terra.api.world.generation.TerraBlockPopulator; import com.dfsek.terra.carving.UserDefinedCarver; import com.dfsek.terra.config.pack.ConfigPack; +import com.dfsek.terra.config.pack.WorldConfig; import com.dfsek.terra.config.templates.CarverTemplate; import com.dfsek.terra.profiler.ProfileFuture; import com.dfsek.terra.world.TerraWorld; @@ -40,7 +41,7 @@ public class CavePopulator implements TerraBlockPopulator { try(ProfileFuture ignored = tw.getProfiler().measure("CaveTime")) { Random random = PopulationUtil.getRandom(chunk); if(!tw.isSafe()) return; - ConfigPack config = tw.getConfig(); + WorldConfig config = tw.getConfig(); for(UserDefinedCarver c : config.getCarvers()) { CarverTemplate template = c.getConfig(); diff --git a/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java b/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java index ed46b15e3..17bb41221 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java +++ b/common/src/main/java/com/dfsek/terra/world/population/StructurePopulator.java @@ -11,6 +11,7 @@ import com.dfsek.terra.api.world.biome.UserDefinedBiome; import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.api.world.generation.TerraBlockPopulator; import com.dfsek.terra.config.pack.ConfigPack; +import com.dfsek.terra.config.pack.WorldConfig; import com.dfsek.terra.profiler.ProfileFuture; import com.dfsek.terra.world.TerraWorld; import com.dfsek.terra.world.population.items.TerraStructure; @@ -35,7 +36,7 @@ public class StructurePopulator implements TerraBlockPopulator { int cz = (chunk.getZ() << 4); if(!tw.isSafe()) return; BiomeProvider provider = tw.getBiomeProvider(); - ConfigPack config = tw.getConfig(); + WorldConfig config = tw.getConfig(); for(TerraStructure conf : config.getStructures()) { Location spawn = conf.getSpawn().getNearestSpawn(cx + 8, cz + 8, world.getSeed()).toLocation(world); From a28f3fa660616350ae188d4728e9ab89f4e81417 Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 1 Mar 2021 15:20:09 -0700 Subject: [PATCH 41/95] working WorldConfig impl --- .../collections/ProbabilityCollection.java | 12 ++++ .../biome/pipeline/source/BiomeSource.java | 4 ++ .../biome/provider/ImageBiomeProvider.java | 3 +- .../world/generation/TerraChunkGenerator.java | 2 - .../dfsek/terra/config/GenericLoaders.java | 4 ++ .../terra/config/builder/BiomeBuilder.java | 55 ++--------------- .../terra/config/builder/ConfigBuilder.java | 8 --- .../terra/config/builder/ScriptBuilder.java | 12 ---- .../builder/UserDefinedBiomeBuilder.java | 60 +++++++++++++++++++ .../dfsek/terra/config/dummy/DummyWorld.java | 2 +- .../terra/config/factories/BiomeFactory.java | 8 +-- .../biome/BiomeProviderBuilderLoader.java | 6 +- .../config/biome/SourceBuilderLoader.java | 10 ++-- .../BiomePipelineTemplate.java | 6 +- .../BiomeProviderTemplate.java | 10 +--- .../ImageProviderTemplate.java | 12 ++-- .../SingleBiomeProviderTemplate.java | 6 +- .../templates/source/NoiseSourceTemplate.java | 22 +++++++ .../templates/source/SourceTemplate.java | 12 ++++ .../mutator/BorderListMutatorTemplate.java | 13 +++- .../stage/mutator/BorderMutatorTemplate.java | 6 +- .../mutator/ReplaceListMutatorTemplate.java | 13 +++- .../stage/mutator/ReplaceMutatorTemplate.java | 6 +- .../dfsek/terra/config/pack/ConfigPack.java | 17 +++--- .../dfsek/terra/config/pack/WorldConfig.java | 2 +- .../terra/registry/config/BiomeRegistry.java | 8 +-- .../com/dfsek/terra/world/TerraWorld.java | 6 +- .../generators/DefaultChunkGenerator2D.java | 5 -- .../generators/DefaultChunkGenerator3D.java | 12 +--- .../world/generation/math/SamplerCache.java | 5 ++ .../src/test/java/biome/DistributionTest.java | 20 ++++--- common/src/test/java/biome/ImageTest.java | 2 +- .../dfsek/terra/bukkit/TerraBukkitPlugin.java | 4 +- .../command/biome/BiomeInfoCommand.java | 10 +++- .../command/biome/BiomeLocateCommand.java | 7 ++- .../command/structure/LocateCommand.java | 7 ++- .../command/structure/SpawnCommand.java | 2 +- .../bukkit/listeners/CommonListener.java | 3 +- .../terra/bukkit/listeners/PaperListener.java | 2 +- .../bukkit/listeners/SpigotListener.java | 2 +- .../dfsek/terra/fabric/TerraFabricPlugin.java | 11 ++-- .../terra/fabric/world/TerraBiomeSource.java | 4 +- .../FabricChunkGeneratorWrapper.java | 2 +- .../com/dfsek/terra/region/Generator.java | 3 +- 44 files changed, 246 insertions(+), 180 deletions(-) delete mode 100644 common/src/main/java/com/dfsek/terra/config/builder/ConfigBuilder.java delete mode 100644 common/src/main/java/com/dfsek/terra/config/builder/ScriptBuilder.java create mode 100644 common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java rename common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/{source => provider}/BiomePipelineTemplate.java (85%) rename common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/{source => provider}/BiomeProviderTemplate.java (74%) rename common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/{source => provider}/ImageProviderTemplate.java (53%) rename common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/{source => provider}/SingleBiomeProviderTemplate.java (68%) create mode 100644 common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/NoiseSourceTemplate.java create mode 100644 common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/SourceTemplate.java diff --git a/common/src/main/java/com/dfsek/terra/api/util/collections/ProbabilityCollection.java b/common/src/main/java/com/dfsek/terra/api/util/collections/ProbabilityCollection.java index ecdd520b4..9a7ac4032 100644 --- a/common/src/main/java/com/dfsek/terra/api/util/collections/ProbabilityCollection.java +++ b/common/src/main/java/com/dfsek/terra/api/util/collections/ProbabilityCollection.java @@ -10,6 +10,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Random; import java.util.Set; +import java.util.function.Function; @SuppressWarnings("unchecked") public class ProbabilityCollection implements Collection { @@ -43,6 +44,17 @@ public class ProbabilityCollection implements Collection { return (E) array[MathUtil.normalizeIndex(n.getNoise(x, z), array.length)]; } + public ProbabilityCollection map(Function mapper, boolean carryNull) { + ProbabilityCollection newCollection = new ProbabilityCollection<>(); + newCollection.array = new Object[array.length]; + + for(int i = 0; i < array.length; i++) { + if(carryNull && array[i] == null) continue; + newCollection.array[i] = mapper.apply((E) array[i]); + } + return newCollection; + } + public int getTotalProbability() { return array.length; } diff --git a/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/source/BiomeSource.java b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/source/BiomeSource.java index 81ab9c858..b2e2e37cc 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/source/BiomeSource.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/pipeline/source/BiomeSource.java @@ -4,4 +4,8 @@ import com.dfsek.terra.api.world.biome.TerraBiome; public interface BiomeSource { TerraBiome getBiome(double x, double z); + + enum Type { + NOISE + } } diff --git a/common/src/main/java/com/dfsek/terra/api/world/biome/provider/ImageBiomeProvider.java b/common/src/main/java/com/dfsek/terra/api/world/biome/provider/ImageBiomeProvider.java index 5d0c0007f..5e210abc7 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/biome/provider/ImageBiomeProvider.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/provider/ImageBiomeProvider.java @@ -9,6 +9,7 @@ import java.awt.*; import java.awt.image.BufferedImage; import java.util.HashMap; import java.util.Map; +import java.util.Set; public class ImageBiomeProvider implements BiomeProvider, BiomeProvider.BiomeProviderBuilder { // This provider does not need a seed, so it is its own builder. private final Map colorBiomeMap = new HashMap<>(); @@ -16,7 +17,7 @@ public class ImageBiomeProvider implements BiomeProvider, BiomeProvider.BiomePro private final int resolution; private final Align align; - public ImageBiomeProvider(Registry registry, BufferedImage image, int resolution, Align align) { + public ImageBiomeProvider(Set registry, BufferedImage image, int resolution, Align align) { this.image = image; this.resolution = resolution; this.align = align; diff --git a/common/src/main/java/com/dfsek/terra/api/world/generation/TerraChunkGenerator.java b/common/src/main/java/com/dfsek/terra/api/world/generation/TerraChunkGenerator.java index 5b6dba9f0..280ee8f96 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/generation/TerraChunkGenerator.java +++ b/common/src/main/java/com/dfsek/terra/api/world/generation/TerraChunkGenerator.java @@ -31,7 +31,5 @@ public interface TerraChunkGenerator { TerraPlugin getMain(); - SamplerCache getCache(); - Sampler createSampler(int chunkX, int chunkZ, BiomeProvider provider, World world, int elevationSmooth); } diff --git a/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java b/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java index 0e3c7b635..6eafad8d9 100644 --- a/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java +++ b/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java @@ -13,6 +13,7 @@ import com.dfsek.terra.api.util.collections.MaterialSet; import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.util.seeded.SourceSeeded; import com.dfsek.terra.api.util.seeded.StageSeeded; +import com.dfsek.terra.api.world.biome.pipeline.source.BiomeSource; import com.dfsek.terra.api.world.biome.pipeline.stages.ExpanderStage; import com.dfsek.terra.api.world.biome.pipeline.stages.MutatorStage; import com.dfsek.terra.api.world.biome.provider.BiomeProvider; @@ -32,6 +33,7 @@ import com.dfsek.terra.config.loaders.config.TreeLayerLoader; import com.dfsek.terra.config.loaders.config.biome.BiomeProviderBuilderLoader; import com.dfsek.terra.config.loaders.config.biome.SourceBuilderLoader; import com.dfsek.terra.config.loaders.config.biome.StageBuilderLoader; +import com.dfsek.terra.config.loaders.config.biome.templates.source.NoiseSourceTemplate; import com.dfsek.terra.config.loaders.config.biome.templates.stage.expander.ExpanderStageTemplate; import com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator.BorderListMutatorTemplate; import com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator.BorderMutatorTemplate; @@ -87,6 +89,7 @@ public class GenericLoaders implements LoaderRegistrar { .registerLoader(ReplaceListMutatorTemplate.class, ReplaceListMutatorTemplate::new) .registerLoader(BorderMutatorTemplate.class, BorderMutatorTemplate::new) .registerLoader(BorderListMutatorTemplate.class, BorderListMutatorTemplate::new) + .registerLoader(NoiseSourceTemplate.class, NoiseSourceTemplate::new) .registerLoader(FunctionTemplate.class, FunctionTemplate::new) .registerLoader(LinkedHashMap.class, new LinkedHashMapLoader()) .registerLoader(CarverPalette.class, new CarverPaletteLoader()) @@ -97,6 +100,7 @@ public class GenericLoaders implements LoaderRegistrar { .registerLoader(BiomeProvider.BiomeProviderBuilder.class, new BiomeProviderBuilderLoader()) .registerLoader(ImageSampler.Channel.class, (t, object, cf) -> ImageSampler.Channel.valueOf((String) object)) .registerLoader(BiomeProvider.Type.class, (t, object, cf) -> BiomeProvider.Type.valueOf((String) object)) + .registerLoader(BiomeSource.Type.class, (t, object, cf) -> BiomeSource.Type.valueOf((String) object)) .registerLoader(ImageBiomeProvider.Align.class, (t, object, cf) -> ImageBiomeProvider.Align.valueOf((String) object)) .registerLoader(ExpanderStage.Type.class, (t, object, cf) -> ExpanderStage.Type.valueOf((String) object)) .registerLoader(MutatorStage.Type.class, (t, object, cf) -> MutatorStage.Type.valueOf((String) object)) diff --git a/common/src/main/java/com/dfsek/terra/config/builder/BiomeBuilder.java b/common/src/main/java/com/dfsek/terra/config/builder/BiomeBuilder.java index a9929c23f..27fdef9f3 100644 --- a/common/src/main/java/com/dfsek/terra/config/builder/BiomeBuilder.java +++ b/common/src/main/java/com/dfsek/terra/config/builder/BiomeBuilder.java @@ -1,57 +1,12 @@ package com.dfsek.terra.config.builder; -import com.dfsek.paralithic.eval.parser.Scope; -import com.dfsek.paralithic.eval.tokenizer.ParseException; import com.dfsek.terra.api.TerraPlugin; -import com.dfsek.terra.api.math.noise.NoiseSampler; -import com.dfsek.terra.api.math.noise.samplers.ExpressionSampler; -import com.dfsek.terra.api.math.noise.samplers.noise.ConstantSampler; -import com.dfsek.terra.api.util.seeded.NoiseSeeded; +import com.dfsek.terra.api.platform.world.Biome; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; +import com.dfsek.terra.api.util.seeded.SeededBuilder; import com.dfsek.terra.api.world.biome.TerraBiome; -import com.dfsek.terra.api.world.biome.UserDefinedBiome; -import com.dfsek.terra.config.loaders.config.function.FunctionTemplate; -import com.dfsek.terra.config.pack.ConfigPack; -import com.dfsek.terra.config.templates.BiomeTemplate; import com.dfsek.terra.world.TerraWorld; -import com.dfsek.terra.world.generation.WorldGenerator; -import java.util.HashMap; -import java.util.Map; - -public class BiomeBuilder implements ConfigBuilder { - private final BiomeTemplate template; - private final ConfigPack pack; - - public BiomeBuilder(BiomeTemplate template, ConfigPack pack) { - this.template = template; - this.pack = pack; - } - - @Override - public TerraBiome build(TerraWorld world, TerraPlugin main) { - NoiseSampler noise; - NoiseSampler elevation; - NoiseSampler carving; - Scope varScope = new Scope().withParent(pack.getVarScope()); - - template.getVariables().forEach(varScope::create); - - Map noiseBuilderMap = pack.getTemplate().getNoiseBuilderMap(); - Map functionTemplateMap = new HashMap<>(template.getFunctions()); - - functionTemplateMap.putAll(template.getFunctions()); - - long seed = world.getWorld().getSeed(); - try { - noise = new ExpressionSampler(template.getNoiseEquation(), varScope, seed, noiseBuilderMap, functionTemplateMap); - elevation = template.getElevationEquation() == null ? new ConstantSampler(0) : new ExpressionSampler(template.getElevationEquation(), varScope, seed, noiseBuilderMap, functionTemplateMap); - carving = new ExpressionSampler(template.getCarvingEquation(), varScope, seed, noiseBuilderMap, functionTemplateMap); - } catch(ParseException e) { - throw new RuntimeException(e); - } - - WorldGenerator generator = new WorldGenerator(template.getPalette(), template.getSlantPalette(), noise, elevation, carving, template.getBiomeNoise().apply(seed), template.getElevationWeight(), - template.getBlendDistance(), template.getBlendStep(), template.getBlendWeight()); - return new UserDefinedBiome(template.getVanilla(), generator, template); - } +public interface BiomeBuilder extends SeededBuilder { + ProbabilityCollection getVanillaBiomes(); } diff --git a/common/src/main/java/com/dfsek/terra/config/builder/ConfigBuilder.java b/common/src/main/java/com/dfsek/terra/config/builder/ConfigBuilder.java deleted file mode 100644 index 2657c09d4..000000000 --- a/common/src/main/java/com/dfsek/terra/config/builder/ConfigBuilder.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.dfsek.terra.config.builder; - -import com.dfsek.terra.api.TerraPlugin; -import com.dfsek.terra.world.TerraWorld; - -public interface ConfigBuilder { - O build(TerraWorld world, TerraPlugin main); -} diff --git a/common/src/main/java/com/dfsek/terra/config/builder/ScriptBuilder.java b/common/src/main/java/com/dfsek/terra/config/builder/ScriptBuilder.java deleted file mode 100644 index 9e9afde95..000000000 --- a/common/src/main/java/com/dfsek/terra/config/builder/ScriptBuilder.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.dfsek.terra.config.builder; - -import com.dfsek.terra.api.TerraPlugin; -import com.dfsek.terra.api.structures.script.StructureScript; -import com.dfsek.terra.world.TerraWorld; - -public class ScriptBuilder implements ConfigBuilder { - @Override - public StructureScript build(TerraWorld world, TerraPlugin main) { - return null; - } -} diff --git a/common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java b/common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java new file mode 100644 index 000000000..a30161b07 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java @@ -0,0 +1,60 @@ +package com.dfsek.terra.config.builder; + +import com.dfsek.paralithic.eval.parser.Scope; +import com.dfsek.paralithic.eval.tokenizer.ParseException; +import com.dfsek.terra.api.math.noise.NoiseSampler; +import com.dfsek.terra.api.math.noise.samplers.ExpressionSampler; +import com.dfsek.terra.api.math.noise.samplers.noise.ConstantSampler; +import com.dfsek.terra.api.platform.world.Biome; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; +import com.dfsek.terra.api.util.seeded.NoiseSeeded; +import com.dfsek.terra.api.world.biome.UserDefinedBiome; +import com.dfsek.terra.config.loaders.config.function.FunctionTemplate; +import com.dfsek.terra.config.pack.ConfigPack; +import com.dfsek.terra.config.templates.BiomeTemplate; +import com.dfsek.terra.world.generation.WorldGenerator; + +import java.util.HashMap; +import java.util.Map; + +public class UserDefinedBiomeBuilder implements BiomeBuilder { + private final BiomeTemplate template; + private final ConfigPack pack; + + public UserDefinedBiomeBuilder(BiomeTemplate template, ConfigPack pack) { + this.template = template; + this.pack = pack; + } + + @Override + public UserDefinedBiome apply(Long seed) { + NoiseSampler noise; + NoiseSampler elevation; + NoiseSampler carving; + Scope varScope = new Scope().withParent(pack.getVarScope()); + + template.getVariables().forEach(varScope::create); + + Map noiseBuilderMap = pack.getTemplate().getNoiseBuilderMap(); + Map functionTemplateMap = new HashMap<>(template.getFunctions()); + + functionTemplateMap.putAll(template.getFunctions()); + + try { + noise = new ExpressionSampler(template.getNoiseEquation(), varScope, seed, noiseBuilderMap, functionTemplateMap); + elevation = template.getElevationEquation() == null ? new ConstantSampler(0) : new ExpressionSampler(template.getElevationEquation(), varScope, seed, noiseBuilderMap, functionTemplateMap); + carving = new ExpressionSampler(template.getCarvingEquation(), varScope, seed, noiseBuilderMap, functionTemplateMap); + } catch(ParseException e) { + throw new RuntimeException(e); + } + + WorldGenerator generator = new WorldGenerator(template.getPalette(), template.getSlantPalette(), noise, elevation, carving, template.getBiomeNoise().apply(seed), template.getElevationWeight(), + template.getBlendDistance(), template.getBlendStep(), template.getBlendWeight()); + return new UserDefinedBiome(template.getVanilla(), generator, template); + } + + @Override + public ProbabilityCollection getVanillaBiomes() { + return template.getVanilla(); + } +} diff --git a/common/src/main/java/com/dfsek/terra/config/dummy/DummyWorld.java b/common/src/main/java/com/dfsek/terra/config/dummy/DummyWorld.java index 3c2e100fe..d55d813ff 100644 --- a/common/src/main/java/com/dfsek/terra/config/dummy/DummyWorld.java +++ b/common/src/main/java/com/dfsek/terra/config/dummy/DummyWorld.java @@ -29,7 +29,7 @@ public class DummyWorld implements World { @Override public ChunkGenerator getGenerator() { - throw new UnsupportedOperationException("Cannot get generator of DummyWorld"); + return () -> (ChunkGenerator) () -> null; } @Override diff --git a/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java b/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java index 03c396461..8e99d3bfe 100644 --- a/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java +++ b/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java @@ -2,12 +2,12 @@ package com.dfsek.terra.config.factories; import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.config.builder.UserDefinedBiomeBuilder; import com.dfsek.terra.config.builder.BiomeBuilder; -import com.dfsek.terra.config.builder.ConfigBuilder; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.config.templates.BiomeTemplate; -public class BiomeFactory implements ConfigFactory> { +public class BiomeFactory implements ConfigFactory> { private final ConfigPack pack; public BiomeFactory(ConfigPack pack) { @@ -15,7 +15,7 @@ public class BiomeFactory implements ConfigFactory build(BiomeTemplate template, TerraPlugin main) { + return new UserDefinedBiomeBuilder(template, pack); } } diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/BiomeProviderBuilderLoader.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/BiomeProviderBuilderLoader.java index 1e45c5536..718d33907 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/BiomeProviderBuilderLoader.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/BiomeProviderBuilderLoader.java @@ -4,9 +4,9 @@ import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; import com.dfsek.tectonic.loading.TypeLoader; import com.dfsek.terra.api.world.biome.provider.BiomeProvider; -import com.dfsek.terra.config.loaders.config.biome.templates.source.BiomePipelineTemplate; -import com.dfsek.terra.config.loaders.config.biome.templates.source.ImageProviderTemplate; -import com.dfsek.terra.config.loaders.config.biome.templates.source.SingleBiomeProviderTemplate; +import com.dfsek.terra.config.loaders.config.biome.templates.provider.BiomePipelineTemplate; +import com.dfsek.terra.config.loaders.config.biome.templates.provider.ImageProviderTemplate; +import com.dfsek.terra.config.loaders.config.biome.templates.provider.SingleBiomeProviderTemplate; import java.lang.reflect.Type; import java.util.Map; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/SourceBuilderLoader.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/SourceBuilderLoader.java index e4509473c..33f1dcd42 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/SourceBuilderLoader.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/SourceBuilderLoader.java @@ -7,8 +7,10 @@ import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.util.seeded.NoiseSeeded; import com.dfsek.terra.api.util.seeded.SourceSeeded; import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.pipeline.source.BiomeSource; import com.dfsek.terra.api.world.biome.pipeline.source.RandomSource; import com.dfsek.terra.config.loaders.Types; +import com.dfsek.terra.config.loaders.config.biome.templates.source.NoiseSourceTemplate; import java.lang.reflect.Type; import java.util.Map; @@ -19,12 +21,10 @@ public class SourceBuilderLoader implements TypeLoader { public SourceSeeded load(Type t, Object c, ConfigLoader loader) throws LoadException { Map source = (Map) c; - String type = source.get("type").toString(); + BiomeSource.Type type = loader.loadClass(BiomeSource.Type.class, source.get("type")); - if("NOISE".equals(type)) { - ProbabilityCollection sourceBiomes = (ProbabilityCollection) loader.loadType(Types.TERRA_BIOME_PROBABILITY_COLLECTION_TYPE, source.get("biomes")); - NoiseSeeded sourceNoise = loader.loadClass(NoiseSeeded.class, source.get("noise")); - return seed -> new RandomSource(sourceBiomes, sourceNoise.apply(seed)); + if(type == BiomeSource.Type.NOISE) { + return loader.loadClass(NoiseSourceTemplate.class, source); } throw new LoadException("No such loader type: " + type); } diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/BiomePipelineTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/BiomePipelineTemplate.java similarity index 85% rename from common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/BiomePipelineTemplate.java rename to common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/BiomePipelineTemplate.java index b0a05add6..31f448553 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/BiomePipelineTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/BiomePipelineTemplate.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.config.loaders.config.biome.templates.source; +package com.dfsek.terra.config.loaders.config.biome.templates.provider; import com.dfsek.tectonic.annotations.Default; import com.dfsek.tectonic.annotations.Value; @@ -8,7 +8,6 @@ import com.dfsek.terra.api.util.seeded.StageSeeded; import com.dfsek.terra.api.world.biome.pipeline.BiomePipeline; import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.api.world.biome.provider.StandardBiomeProvider; -import com.dfsek.terra.registry.config.BiomeRegistry; import java.util.List; @@ -25,8 +24,7 @@ public class BiomePipelineTemplate extends BiomeProviderTemplate { @Value("pipeline.source") private SourceSeeded source; - public BiomePipelineTemplate(BiomeRegistry registry, TerraPlugin main) { - super(registry); + public BiomePipelineTemplate(TerraPlugin main) { this.main = main; } diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/BiomeProviderTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/BiomeProviderTemplate.java similarity index 74% rename from common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/BiomeProviderTemplate.java rename to common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/BiomeProviderTemplate.java index 85e0a5ea5..2b0799b87 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/BiomeProviderTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/BiomeProviderTemplate.java @@ -1,18 +1,14 @@ -package com.dfsek.terra.config.loaders.config.biome.templates.source; +package com.dfsek.terra.config.loaders.config.biome.templates.provider; import com.dfsek.tectonic.annotations.Default; import com.dfsek.tectonic.annotations.Value; import com.dfsek.tectonic.loading.object.ObjectTemplate; import com.dfsek.terra.api.math.noise.NoiseSampler; import com.dfsek.terra.api.math.noise.samplers.noise.ConstantSampler; -import com.dfsek.terra.api.registry.Registry; import com.dfsek.terra.api.util.seeded.NoiseSeeded; -import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.provider.BiomeProvider; -import com.dfsek.terra.registry.config.BiomeRegistry; public abstract class BiomeProviderTemplate implements ObjectTemplate, BiomeProvider.BiomeProviderBuilder { - protected final Registry registry; @Value("resolution") @Default protected int resolution = 1; @@ -35,10 +31,6 @@ public abstract class BiomeProviderTemplate implements ObjectTemplate registry) { - this.registry = registry; - } - @Override public BiomeProvider.BiomeProviderBuilder get() { return this; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/ImageProviderTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/ImageProviderTemplate.java similarity index 53% rename from common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/ImageProviderTemplate.java rename to common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/ImageProviderTemplate.java index 857385f77..7524a632e 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/ImageProviderTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/ImageProviderTemplate.java @@ -1,27 +1,29 @@ -package com.dfsek.terra.config.loaders.config.biome.templates.source; +package com.dfsek.terra.config.loaders.config.biome.templates.provider; import com.dfsek.tectonic.annotations.Value; import com.dfsek.terra.api.registry.Registry; import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.api.world.biome.provider.ImageBiomeProvider; -import com.dfsek.terra.registry.config.BiomeRegistry; +import com.dfsek.terra.config.builder.BiomeBuilder; import java.awt.image.BufferedImage; +import java.util.stream.Collectors; public class ImageProviderTemplate extends BiomeProviderTemplate { + private final Registry> biomes; @Value("image.name") private BufferedImage image; @Value("image.align") private ImageBiomeProvider.Align align; - public ImageProviderTemplate(Registry registry) { - super(registry); + public ImageProviderTemplate(Registry> set) { + this.biomes = set; } @Override public BiomeProvider build(long seed) { - return new ImageBiomeProvider(registry, image, resolution, align); + return new ImageBiomeProvider(biomes.entries().stream().map(biomeBuilder -> biomeBuilder.apply(seed)).collect(Collectors.toSet()), image, resolution, align); } } diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/SingleBiomeProviderTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/SingleBiomeProviderTemplate.java similarity index 68% rename from common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/SingleBiomeProviderTemplate.java rename to common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/SingleBiomeProviderTemplate.java index 4c7aa3279..dadc4b968 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/SingleBiomeProviderTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/SingleBiomeProviderTemplate.java @@ -1,17 +1,15 @@ -package com.dfsek.terra.config.loaders.config.biome.templates.source; +package com.dfsek.terra.config.loaders.config.biome.templates.provider; import com.dfsek.tectonic.annotations.Value; import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.api.world.biome.provider.SingleBiomeProvider; -import com.dfsek.terra.registry.config.BiomeRegistry; public class SingleBiomeProviderTemplate extends BiomeProviderTemplate { @Value("biome") private TerraBiome biome; - public SingleBiomeProviderTemplate(BiomeRegistry registry) { - super(registry); + public SingleBiomeProviderTemplate() { } @Override diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/NoiseSourceTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/NoiseSourceTemplate.java new file mode 100644 index 000000000..404c53226 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/NoiseSourceTemplate.java @@ -0,0 +1,22 @@ +package com.dfsek.terra.config.loaders.config.biome.templates.source; + +import com.dfsek.tectonic.annotations.Value; +import com.dfsek.terra.api.util.collections.ProbabilityCollection; +import com.dfsek.terra.api.util.seeded.NoiseSeeded; +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.pipeline.source.BiomeSource; +import com.dfsek.terra.api.world.biome.pipeline.source.RandomSource; +import com.dfsek.terra.config.builder.BiomeBuilder; + +public class NoiseSourceTemplate extends SourceTemplate { + @Value("noise") + private NoiseSeeded noise; + + @Value("biomes") + private ProbabilityCollection> biomes; + + @Override + public BiomeSource apply(Long seed) { + return new RandomSource(biomes.map((biome) -> biome.apply(seed), false), noise.apply(seed)); + } +} diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/SourceTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/SourceTemplate.java new file mode 100644 index 000000000..cee30713b --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/SourceTemplate.java @@ -0,0 +1,12 @@ +package com.dfsek.terra.config.loaders.config.biome.templates.source; + +import com.dfsek.tectonic.loading.object.ObjectTemplate; +import com.dfsek.terra.api.util.seeded.SourceSeeded; +import com.dfsek.terra.api.world.biome.pipeline.source.BiomeSource; + +public abstract class SourceTemplate implements ObjectTemplate, SourceSeeded { + @Override + public SourceSeeded get() { + return this; + } +} diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java index 570b161fc..492bdc70a 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java @@ -5,7 +5,10 @@ import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator; import com.dfsek.terra.api.world.biome.pipeline.mutator.BorderListMutator; +import com.dfsek.terra.config.builder.BiomeBuilder; +import com.dfsek.terra.config.builder.UserDefinedBiomeBuilder; +import java.util.HashMap; import java.util.Map; public class BorderListMutatorTemplate extends MutatorStageTemplate { @@ -16,14 +19,18 @@ public class BorderListMutatorTemplate extends MutatorStageTemplate { private String defaultReplace; @Value("default-to") - private ProbabilityCollection defaultTo; + private ProbabilityCollection defaultTo; @Value("replace") - private Map> replace; + private Map, ProbabilityCollection>> replace; @Override public BiomeMutator build(long seed) { - return new BorderListMutator(replace, from, defaultReplace, noise.apply(seed), defaultTo); + Map> replaceMap = new HashMap<>(); + + replace.forEach((biomeBuilder, biomeBuilders) -> replaceMap.put(biomeBuilder.apply(seed), biomeBuilders.map(builder -> builder.apply(seed), true))); + + return new BorderListMutator(replaceMap, from, defaultReplace, noise.apply(seed), defaultTo.map(biomeBuilder -> biomeBuilder.apply(seed), true)); } } diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderMutatorTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderMutatorTemplate.java index 207d2720a..fd44e261c 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderMutatorTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderMutatorTemplate.java @@ -5,6 +5,8 @@ import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator; import com.dfsek.terra.api.world.biome.pipeline.mutator.BorderMutator; +import com.dfsek.terra.config.builder.BiomeBuilder; +import com.dfsek.terra.config.builder.UserDefinedBiomeBuilder; @SuppressWarnings("unused") public class BorderMutatorTemplate extends MutatorStageTemplate { @@ -15,10 +17,10 @@ public class BorderMutatorTemplate extends MutatorStageTemplate { private String replace; @Value("to") - private ProbabilityCollection to; + private ProbabilityCollection> to; @Override public BiomeMutator build(long seed) { - return new BorderMutator(from, replace, noise.apply(seed), to); + return new BorderMutator(from, replace, noise.apply(seed), to.map(biomeBuilder -> biomeBuilder.apply(seed), true)); } } diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceListMutatorTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceListMutatorTemplate.java index 7c3cfd968..6635f59c0 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceListMutatorTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceListMutatorTemplate.java @@ -5,7 +5,10 @@ import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator; import com.dfsek.terra.api.world.biome.pipeline.mutator.ReplaceListMutator; +import com.dfsek.terra.config.builder.BiomeBuilder; +import com.dfsek.terra.config.builder.UserDefinedBiomeBuilder; +import java.util.HashMap; import java.util.Map; @SuppressWarnings("unused") @@ -14,13 +17,17 @@ public class ReplaceListMutatorTemplate extends MutatorStageTemplate { private String defaultFrom; @Value("default-to") - private ProbabilityCollection defaultTo; + private ProbabilityCollection> defaultTo; @Value("to") - private Map> replace; + private Map, ProbabilityCollection>> replace; @Override public BiomeMutator build(long seed) { - return new ReplaceListMutator(replace, defaultFrom, defaultTo, noise.apply(seed)); + Map> replaceMap = new HashMap<>(); + + replace.forEach((biomeBuilder, biomeBuilders) -> replaceMap.put(biomeBuilder.apply(seed), biomeBuilders.map(builder -> builder.apply(seed), true))); + + return new ReplaceListMutator(replaceMap, defaultFrom, defaultTo.map(biomeBuilder -> biomeBuilder.apply(seed), true), noise.apply(seed)); } } diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceMutatorTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceMutatorTemplate.java index 61ad68c1d..36b2e542e 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceMutatorTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceMutatorTemplate.java @@ -5,6 +5,8 @@ import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator; import com.dfsek.terra.api.world.biome.pipeline.mutator.ReplaceMutator; +import com.dfsek.terra.config.builder.BiomeBuilder; +import com.dfsek.terra.config.builder.UserDefinedBiomeBuilder; @SuppressWarnings("unused") public class ReplaceMutatorTemplate extends MutatorStageTemplate { @@ -12,10 +14,10 @@ public class ReplaceMutatorTemplate extends MutatorStageTemplate { private String from; @Value("to") - private ProbabilityCollection to; + private ProbabilityCollection> to; @Override public BiomeMutator build(long seed) { - return new ReplaceMutator(from, to, noise.apply(seed)); + return new ReplaceMutator(from, to.map(biomeBuilder -> biomeBuilder.apply(seed), true), noise.apply(seed)); } } diff --git a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java index 60aaccea9..5f557e711 100644 --- a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java +++ b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java @@ -23,7 +23,8 @@ import com.dfsek.terra.api.world.flora.Flora; import com.dfsek.terra.api.world.palette.Palette; import com.dfsek.terra.api.world.tree.Tree; import com.dfsek.terra.carving.UserDefinedCarver; -import com.dfsek.terra.config.builder.ConfigBuilder; +import com.dfsek.terra.config.builder.UserDefinedBiomeBuilder; +import com.dfsek.terra.config.builder.BiomeBuilder; import com.dfsek.terra.config.dummy.DummyWorld; import com.dfsek.terra.config.factories.BiomeFactory; import com.dfsek.terra.config.factories.CarverFactory; @@ -37,9 +38,9 @@ import com.dfsek.terra.config.fileloaders.FolderLoader; import com.dfsek.terra.config.fileloaders.Loader; import com.dfsek.terra.config.fileloaders.ZIPLoader; import com.dfsek.terra.config.loaders.config.BufferedImageLoader; -import com.dfsek.terra.config.loaders.config.biome.templates.source.BiomePipelineTemplate; -import com.dfsek.terra.config.loaders.config.biome.templates.source.ImageProviderTemplate; -import com.dfsek.terra.config.loaders.config.biome.templates.source.SingleBiomeProviderTemplate; +import com.dfsek.terra.config.loaders.config.biome.templates.provider.BiomePipelineTemplate; +import com.dfsek.terra.config.loaders.config.biome.templates.provider.ImageProviderTemplate; +import com.dfsek.terra.config.loaders.config.biome.templates.provider.SingleBiomeProviderTemplate; import com.dfsek.terra.config.loaders.config.sampler.NoiseSamplerBuilderLoader; import com.dfsek.terra.config.loaders.config.sampler.templates.ImageSamplerTemplate; import com.dfsek.terra.config.templates.AbstractableTemplate; @@ -263,7 +264,7 @@ public class ConfigPack implements LoaderRegistrar { public void register(TypeRegistry registry) { registry .registerLoader(Palette.class, paletteRegistry) - .registerLoader(TerraBiome.class, biomeRegistry) + .registerLoader(BiomeBuilder.class, biomeRegistry) .registerLoader(Flora.class, floraRegistry) .registerLoader(Ore.class, oreRegistry) .registerLoader(Tree.class, treeRegistry) @@ -273,8 +274,8 @@ public class ConfigPack implements LoaderRegistrar { .registerLoader(UserDefinedCarver.class, carverRegistry) .registerLoader(BufferedImage.class, new BufferedImageLoader(loader)) .registerLoader(NoiseSeeded.class, new NoiseSamplerBuilderLoader(noiseRegistry)) - .registerLoader(SingleBiomeProviderTemplate.class, () -> new SingleBiomeProviderTemplate(biomeRegistry)) - .registerLoader(BiomePipelineTemplate.class, () -> new BiomePipelineTemplate(biomeRegistry, main)) + .registerLoader(SingleBiomeProviderTemplate.class, SingleBiomeProviderTemplate::new) + .registerLoader(BiomePipelineTemplate.class, () -> new BiomePipelineTemplate(main)) .registerLoader(ImageSamplerTemplate.class, () -> new ImageProviderTemplate(biomeRegistry)); } @@ -290,7 +291,7 @@ public class ConfigPack implements LoaderRegistrar { return new CheckedRegistry<>(scriptRegistry); } - public CheckedRegistry> getBiomeRegistry() { + public CheckedRegistry> getBiomeRegistry() { return new CheckedRegistry<>(biomeRegistry); } diff --git a/common/src/main/java/com/dfsek/terra/config/pack/WorldConfig.java b/common/src/main/java/com/dfsek/terra/config/pack/WorldConfig.java index 036192d77..f5f836ee0 100644 --- a/common/src/main/java/com/dfsek/terra/config/pack/WorldConfig.java +++ b/common/src/main/java/com/dfsek/terra/config/pack/WorldConfig.java @@ -48,7 +48,7 @@ public class WorldConfig { this.scriptRegistry = new LockedRegistry<>(pack.getScriptRegistry()); OpenRegistry biomeOpenRegistry = new OpenRegistry<>(); - pack.getBiomeRegistry().forEach((id, biome) -> biomeOpenRegistry.add(id, biome.build(world, main))); + pack.getBiomeRegistry().forEach((id, biome) -> biomeOpenRegistry.add(id, biome.apply(world.getWorld().getSeed()))); this.biomeRegistry = new LockedRegistry<>(biomeOpenRegistry); this.carverRegistry = new LockedRegistry<>(pack.getCarverRegistry()); diff --git a/common/src/main/java/com/dfsek/terra/registry/config/BiomeRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/BiomeRegistry.java index cd06f3678..580c59d99 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/BiomeRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/BiomeRegistry.java @@ -3,16 +3,16 @@ package com.dfsek.terra.registry.config; import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; import com.dfsek.terra.api.world.biome.TerraBiome; -import com.dfsek.terra.config.builder.ConfigBuilder; +import com.dfsek.terra.config.builder.BiomeBuilder; import com.dfsek.terra.registry.OpenRegistry; import java.lang.reflect.Type; -public class BiomeRegistry extends OpenRegistry> { +public class BiomeRegistry extends OpenRegistry> { @Override - public ConfigBuilder load(Type type, Object o, ConfigLoader configLoader) throws LoadException { + public BiomeBuilder load(Type type, Object o, ConfigLoader configLoader) throws LoadException { if(o.equals("SELF")) return null; - ConfigBuilder biome = get((String) o); + BiomeBuilder biome = get((String) o); if(biome == null) throw new LoadException("No such " + type.getTypeName() + " matching \"" + o + "\" was found in this registry."); return biome; diff --git a/common/src/main/java/com/dfsek/terra/world/TerraWorld.java b/common/src/main/java/com/dfsek/terra/world/TerraWorld.java index 6866a6047..cfec49efe 100644 --- a/common/src/main/java/com/dfsek/terra/world/TerraWorld.java +++ b/common/src/main/java/com/dfsek/terra/world/TerraWorld.java @@ -28,10 +28,10 @@ public class TerraWorld { public TerraWorld(World w, ConfigPack c, TerraPlugin main) { if(!isTerraWorld(w)) throw new IllegalArgumentException("World " + w + " is not a Terra World!"); - config = c.toWorldConfig(this); - profiler = new WorldProfiler(w); - this.provider = config.getProvider(); this.world = w; + config = c.toWorldConfig(this); + this.provider = config.getProvider(); + profiler = new WorldProfiler(w); air = main.getWorldHandle().createBlockData("minecraft:air"); main.getEventManager().callEvent(new TerraWorldLoadEvent(this)); safe = true; diff --git a/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator2D.java b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator2D.java index 32ab4801d..ed93986bc 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator2D.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator2D.java @@ -121,11 +121,6 @@ public class DefaultChunkGenerator2D implements TerraChunkGenerator { DefaultChunkGenerator3D.biomes(world, chunkX, chunkZ, biome, main); } - @Override - public SamplerCache getCache() { - return cache; - } - @Override public Sampler createSampler(int chunkX, int chunkZ, BiomeProvider provider, World world, int elevationSmooth) { return new Sampler2D(chunkX, chunkZ, provider, world, elevationSmooth); diff --git a/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java index 4b93250c9..af656ac84 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/generators/DefaultChunkGenerator3D.java @@ -26,7 +26,6 @@ import com.dfsek.terra.profiler.ProfileFuture; import com.dfsek.terra.world.Carver; import com.dfsek.terra.world.TerraWorld; import com.dfsek.terra.world.carving.NoiseCarver; -import com.dfsek.terra.world.generation.math.SamplerCache; import com.dfsek.terra.world.generation.math.samplers.Sampler; import com.dfsek.terra.world.generation.math.samplers.Sampler3D; import org.jetbrains.annotations.NotNull; @@ -42,16 +41,14 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator { private final Carver carver; - private final SamplerCache cache; - public DefaultChunkGenerator3D(ConfigPack c, TerraPlugin main, SamplerCache cache) { + public DefaultChunkGenerator3D(ConfigPack c, TerraPlugin main) { this.configPack = c; this.main = main; carver = new NoiseCarver(new Range(0, 255), main.getWorldHandle().createBlockData("minecraft:air"), main); water = main.getWorldHandle().createBlockData("minecraft:water").getBlockType(); blank = new SinglePalette<>(main.getWorldHandle().createBlockData("minecraft:air")); - this.cache = cache; } @Override @@ -99,7 +96,7 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator { int xOrig = (chunkX << 4); int zOrig = (chunkZ << 4); - Sampler sampler = cache.getChunk(chunkX, chunkZ); + Sampler sampler = tw.getConfig().getSamplerCache().getChunk(chunkX, chunkZ); for(int x = 0; x < 16; x++) { for(int z = 0; z < 16; z++) { @@ -235,11 +232,6 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator { biomes(world, chunkX, chunkZ, biome, main); } - @Override - public SamplerCache getCache() { - return cache; - } - @Override public Sampler createSampler(int chunkX, int chunkZ, BiomeProvider provider, World world, int elevationSmooth) { return new Sampler3D(chunkX, chunkZ, provider, world, elevationSmooth); diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/SamplerCache.java b/common/src/main/java/com/dfsek/terra/world/generation/math/SamplerCache.java index f3ebae0d5..64d4577b1 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/math/SamplerCache.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/SamplerCache.java @@ -40,4 +40,9 @@ public class SamplerCache { long key = MathUtil.squash(cx, cz); return cache.getUnchecked(key); } + + public void clear() { + cache.invalidateAll(); + cache.cleanUp(); + } } diff --git a/common/src/test/java/biome/DistributionTest.java b/common/src/test/java/biome/DistributionTest.java index 3a6d8d6df..9468243a0 100644 --- a/common/src/test/java/biome/DistributionTest.java +++ b/common/src/test/java/biome/DistributionTest.java @@ -27,14 +27,15 @@ import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.config.GenericLoaders; import com.dfsek.terra.config.PluginConfig; +import com.dfsek.terra.config.builder.BiomeBuilder; import com.dfsek.terra.config.fileloaders.FolderLoader; import com.dfsek.terra.config.lang.Language; import com.dfsek.terra.config.loaders.ProbabilityCollectionLoader; import com.dfsek.terra.config.loaders.config.BufferedImageLoader; import com.dfsek.terra.config.loaders.config.biome.BiomeProviderBuilderLoader; -import com.dfsek.terra.config.loaders.config.biome.templates.source.BiomePipelineTemplate; -import com.dfsek.terra.config.loaders.config.biome.templates.source.ImageProviderTemplate; -import com.dfsek.terra.config.loaders.config.biome.templates.source.SingleBiomeProviderTemplate; +import com.dfsek.terra.config.loaders.config.biome.templates.provider.BiomePipelineTemplate; +import com.dfsek.terra.config.loaders.config.biome.templates.provider.ImageProviderTemplate; +import com.dfsek.terra.config.loaders.config.biome.templates.provider.SingleBiomeProviderTemplate; import com.dfsek.terra.config.loaders.config.sampler.NoiseSamplerBuilderLoader; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.config.templates.AbstractableTemplate; @@ -157,10 +158,10 @@ public class DistributionTest { ConfigLoader pipeLoader = new ConfigLoader() .registerLoader(BiomeProvider.BiomeProviderBuilder.class, new BiomeProviderBuilderLoader()) .registerLoader(ProbabilityCollection.class, new ProbabilityCollectionLoader()) - .registerLoader(TerraBiome.class, biomeRegistry) + .registerLoader(BiomeBuilder.class, biomeRegistry) .registerLoader(BufferedImage.class, new BufferedImageLoader(folderLoader)) - .registerLoader(SingleBiomeProviderTemplate.class, () -> new SingleBiomeProviderTemplate(biomeRegistry)) - .registerLoader(BiomePipelineTemplate.class, () -> new BiomePipelineTemplate(biomeRegistry, MAIN)) + .registerLoader(SingleBiomeProviderTemplate.class, SingleBiomeProviderTemplate::new) + .registerLoader(BiomePipelineTemplate.class, () -> new BiomePipelineTemplate(MAIN)) .registerLoader(ImageProviderTemplate.class, () -> new ImageProviderTemplate(biomeRegistry)); new GenericLoaders(null).register(pipeLoader); @@ -285,7 +286,7 @@ public class DistributionTest { } } - private static final class TestBiome extends AbstractableTemplate implements TerraBiome, ValidatedConfigTemplate { + private static final class TestBiome extends AbstractableTemplate implements TerraBiome, ValidatedConfigTemplate, BiomeBuilder { @Value("color") @Default @@ -336,5 +337,10 @@ public class DistributionTest { public String toString() { return id; } + + @Override + public TestBiome apply(Long aLong) { + return this; + } } } diff --git a/common/src/test/java/biome/ImageTest.java b/common/src/test/java/biome/ImageTest.java index 0569dcc69..ddc96dafc 100644 --- a/common/src/test/java/biome/ImageTest.java +++ b/common/src/test/java/biome/ImageTest.java @@ -48,7 +48,7 @@ public class ImageTest { }; folderLoader.open("biomes", ".yml").then(inputStreams -> ConfigPack.buildAll((template, main) -> template, biomeRegistry, loader.load(inputStreams, TestBiome::new), null)); - return new ImageBiomeProvider(biomeRegistry, ImageIO.read(ImageTest.class.getResourceAsStream("/map.jpg")), 1, ImageBiomeProvider.Align.CENTER); + return new ImageBiomeProvider(biomeRegistry.entries(), ImageIO.read(ImageTest.class.getResourceAsStream("/map.jpg")), 1, ImageBiomeProvider.Align.CENTER); } @Test diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java index 57f75d073..eec52f7fb 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java @@ -92,7 +92,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { boolean succeed = registry.loadAll(this); Map newMap = new HashMap<>(); worldMap.forEach((world, tw) -> { - ((BukkitChunkGeneratorWrapper) world.getGenerator().getHandle()).getHandle().getCache().clear(); + tw.getConfig().getSamplerCache().clear(); String packID = tw.getConfig().getTemplate().getID(); newMap.put(world, new TerraWorld(world, registry.get(packID), this)); }); @@ -218,7 +218,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { if(!registry.contains(id)) throw new IllegalArgumentException("No such config pack \"" + id + "\""); ConfigPack pack = registry.get(id); worlds.put(worldName, pack); - return new DefaultChunkGenerator3D(registry.get(id), this, pack.getSamplerCache()); + return new DefaultChunkGenerator3D(registry.get(id), this); })); } diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeInfoCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeInfoCommand.java index c3faf300c..2eee4e2ec 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeInfoCommand.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeInfoCommand.java @@ -6,6 +6,7 @@ import com.dfsek.terra.bukkit.command.WorldCommand; import com.dfsek.terra.bukkit.world.BukkitAdapter; import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.pack.ConfigPack; +import com.dfsek.terra.config.pack.WorldConfig; import com.dfsek.terra.config.templates.BiomeTemplate; import com.dfsek.terra.world.TerraWorld; import com.dfsek.terra.world.population.items.TerraStructure; @@ -15,6 +16,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -27,10 +29,10 @@ public class BiomeInfoCommand extends WorldCommand { @Override public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) { String id = args[0]; - ConfigPack cfg = getMain().getWorld(BukkitAdapter.adapt(world)).getConfig(); + WorldConfig cfg = getMain().getWorld(BukkitAdapter.adapt(world)).getConfig(); UserDefinedBiome b; try { - b = (UserDefinedBiome) cfg.getBiome(id); + b = (UserDefinedBiome) cfg.getBiomeRegistry().get(id); } catch(IllegalArgumentException | NullPointerException e) { LangUtil.send("command.biome.invalid", new BukkitCommandSender(sender), id); return true; @@ -74,7 +76,9 @@ public class BiomeInfoCommand extends WorldCommand { public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { if(!(sender instanceof Player) || !TerraWorld.isTerraWorld(BukkitAdapter.adapt(((Player) sender).getWorld()))) return Collections.emptyList(); - List ids = getMain().getWorld(BukkitAdapter.adapt(((Player) sender).getWorld())).getConfig().getBiomeIDs(); + List ids = new ArrayList<>(); + + getMain().getWorld(BukkitAdapter.adapt(((Player) sender).getWorld())).getConfig().getBiomeRegistry().forEach((id, biome) -> ids.add(id)); if(args.length == 1) return ids.stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList()); return Collections.emptyList(); diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeLocateCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeLocateCommand.java index a52a7c83b..ec8800123 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeLocateCommand.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeLocateCommand.java @@ -21,6 +21,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -44,7 +45,7 @@ public class BiomeLocateCommand extends WorldCommand { } TerraBiome b; try { - b = getMain().getWorld(BukkitAdapter.adapt(world)).getConfig().getBiome(id); + b = getMain().getWorld(BukkitAdapter.adapt(world)).getConfig().getBiomeRegistry().get(id); } catch(IllegalArgumentException | NullPointerException e) { LangUtil.send("command.biome.invalid", BukkitAdapter.adapt(sender), id); return true; @@ -84,7 +85,9 @@ public class BiomeLocateCommand extends WorldCommand { public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { if(!(sender instanceof Player) || !TerraWorld.isTerraWorld(BukkitAdapter.adapt(((Player) sender).getWorld()))) return Collections.emptyList(); - List ids = getMain().getWorld(BukkitAdapter.adapt(((Player) sender).getWorld())).getConfig().getBiomeIDs(); + List ids = new ArrayList<>(); + + getMain().getWorld(BukkitAdapter.adapt(((Player) sender).getWorld())).getConfig().getBiomeRegistry().forEach((id, biome) -> ids.add(id)); if(args.length == 1) return ids.stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList()); return Collections.emptyList(); diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/LocateCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/LocateCommand.java index e23c95bbc..df8f86e83 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/LocateCommand.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/LocateCommand.java @@ -21,6 +21,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; @@ -46,7 +47,7 @@ public class LocateCommand extends WorldCommand { } TerraStructure s; try { - s = Objects.requireNonNull(getMain().getWorld(BukkitAdapter.adapt(world)).getConfig().getStructure(id)); + s = Objects.requireNonNull(getMain().getWorld(BukkitAdapter.adapt(world)).getConfig().getStructureRegistry().get(id)); } catch(IllegalArgumentException | NullPointerException e) { LangUtil.send("command.structure.invalid", BukkitAdapter.adapt(sender), id); return true; @@ -90,7 +91,9 @@ public class LocateCommand extends WorldCommand { if(!(sender instanceof Player) || !(TerraWorld.isTerraWorld(BukkitAdapter.adapt(((Player) sender).getWorld())))) return Collections.emptyList(); - List ids = getMain().getWorld(BukkitAdapter.adapt(((Player) sender).getWorld())).getConfig().getStructureIDs(); + List ids = new ArrayList<>(); + + getMain().getWorld(BukkitAdapter.adapt(((Player) sender).getWorld())).getConfig().getStructureRegistry().forEach((id, struct) -> ids.add(id)); if(args.length == 1) return ids.stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList()); diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/SpawnCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/SpawnCommand.java index 0c78c10ce..c46556751 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/SpawnCommand.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/SpawnCommand.java @@ -34,7 +34,7 @@ public class SpawnCommand extends WorldCommand implements DebugCommand { int z = p.getBlockZ(); Position dummy = new Position(0, 0); com.dfsek.terra.api.platform.world.World w = BukkitAdapter.adapt(world); - String check = new CheckFunction(getMain(), new NumericConstant(0, dummy), new NumericConstant(0, dummy), new NumericConstant(0, dummy), getMain().getWorld(w).getConfig().getSamplerCache(), dummy).apply(new TerraImplementationArguments(new StructureBuffer( + String check = new CheckFunction(getMain(), new NumericConstant(0, dummy), new NumericConstant(0, dummy), new NumericConstant(0, dummy), dummy).apply(new TerraImplementationArguments(new StructureBuffer( new com.dfsek.terra.api.math.vector.Location(w, x, y, z) ), Rotation.NONE, new FastRandom(), 0), new HashMap<>()); diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/CommonListener.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/CommonListener.java index 98b449536..5e35d174a 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/CommonListener.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/CommonListener.java @@ -9,6 +9,7 @@ import com.dfsek.terra.api.util.FastRandom; import com.dfsek.terra.api.world.tree.Tree; import com.dfsek.terra.bukkit.world.BukkitAdapter; import com.dfsek.terra.config.pack.ConfigPack; +import com.dfsek.terra.config.pack.WorldConfig; import com.dfsek.terra.world.TerraWorld; import org.bukkit.Material; import org.bukkit.TreeType; @@ -46,7 +47,7 @@ public class CommonListener implements Listener { World bukkit = BukkitAdapter.adapt(e.getWorld()); if(!TerraWorld.isTerraWorld(bukkit)) return; TerraWorld tw = main.getWorld(bukkit); - ConfigPack c = tw.getConfig(); + WorldConfig c = tw.getConfig(); if(c.getTemplate().isDisableSaplings()) return; e.setCancelled(true); Block block = e.getLocation().getBlock(); diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/PaperListener.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/PaperListener.java index 94370dfb0..3945451f4 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/PaperListener.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/PaperListener.java @@ -23,7 +23,7 @@ public class PaperListener implements Listener { String name = "minecraft:" + e.getType().getName(); main.getDebugLogger().info("Overriding structure location for \"" + name + "\""); TerraWorld tw = main.getWorld(BukkitAdapter.adapt(e.getWorld())); - TerraStructure config = tw.getConfig().getStructure(tw.getConfig().getTemplate().getLocatable().get(name)); + TerraStructure config = tw.getConfig().getStructureRegistry().get(tw.getConfig().getTemplate().getLocatable().get(name)); if(config != null) { AsyncStructureFinder finder = new AsyncStructureFinder(tw.getBiomeProvider(), config, BukkitAdapter.adapt(e.getOrigin()), 0, 500, location -> { if(location != null) diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/SpigotListener.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/SpigotListener.java index 87fb29b53..fe4681e61 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/SpigotListener.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/listeners/SpigotListener.java @@ -37,7 +37,7 @@ public class SpigotListener implements Listener { if(!TerraWorld.isTerraWorld(BukkitAdapter.adapt(e.getEntity().getWorld()))) return; TerraWorld tw = main.getWorld(BukkitAdapter.adapt(e.getEntity().getWorld())); EnderSignal signal = (EnderSignal) entity; - TerraStructure config = tw.getConfig().getStructure(tw.getConfig().getTemplate().getLocatable().get("STRONGHOLD")); + TerraStructure config = tw.getConfig().getStructureRegistry().get(tw.getConfig().getTemplate().getLocatable().get("STRONGHOLD")); if(config != null) { main.getDebugLogger().info("Overriding Ender Signal..."); AsyncStructureFinder finder = new AsyncStructureFinder(tw.getBiomeProvider(), config, BukkitAdapter.adapt(e.getLocation()), 0, 500, location -> { diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index 439278413..5fa16b5ef 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -26,6 +26,7 @@ import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.tree.Tree; import com.dfsek.terra.config.GenericLoaders; import com.dfsek.terra.config.PluginConfig; +import com.dfsek.terra.config.builder.BiomeBuilder; import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.Language; import com.dfsek.terra.config.pack.ConfigPack; @@ -218,11 +219,11 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { .registerLoader(com.dfsek.terra.api.platform.world.Biome.class, (t, o, l) -> new FabricBiome(biomeFixer.translate((String) o))); } - public static String createBiomeID(ConfigPack pack, TerraBiome biome) { - return pack.getTemplate().getID().toLowerCase() + "/" + biome.getID().toLowerCase(); + public static String createBiomeID(ConfigPack pack, String biomeID) { + return pack.getTemplate().getID().toLowerCase() + "/" + biomeID; } - private Biome createBiome(TerraBiome biome) { + private Biome createBiome(BiomeBuilder biome) { SpawnSettings.Builder spawnSettings = new SpawnSettings.Builder(); DefaultBiomeFeatures.addFarmAnimals(spawnSettings); DefaultBiomeFeatures.addMonsters(spawnSettings, 95, 5, 100); @@ -282,14 +283,12 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { RegistryKey> floraKey = RegistryKey.of(Registry.CONFIGURED_FEATURE_WORLDGEN, new Identifier("terra", "flora_populator")); Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, floraKey.getValue(), POPULATOR_CONFIGURED_FEATURE); - registry.forEach(pack -> pack.getBiomeRegistry().forEach(biome -> Registry.register(BuiltinRegistries.BIOME, new Identifier("terra", createBiomeID(pack, biome)), createBiome(biome)))); // Register all Terra biomes. + registry.forEach(pack -> pack.getBiomeRegistry().forEach((id, biome) -> Registry.register(BuiltinRegistries.BIOME, new Identifier("terra", createBiomeID(pack, id)), createBiome(biome)))); // Register all Terra biomes. Registry.register(Registry.CHUNK_GENERATOR, new Identifier("terra:terra"), FabricChunkGeneratorWrapper.CODEC); Registry.register(Registry.BIOME_SOURCE, new Identifier("terra:terra"), TerraBiomeSource.CODEC); if(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { registry.forEach(pack -> { - System.out.println(pack.getTemplate().getID()); - pack.getBiomeRegistry().forEach(b -> System.out.println(b.getID())); final GeneratorType generatorType = new GeneratorType("terra." + pack.getTemplate().getID()) { @Override protected ChunkGenerator getChunkGenerator(Registry biomeRegistry, Registry chunkGeneratorSettingsRegistry, long seed) { diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/TerraBiomeSource.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/TerraBiomeSource.java index 2f0903ab8..46b628eac 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/TerraBiomeSource.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/TerraBiomeSource.java @@ -50,8 +50,8 @@ public class TerraBiomeSource extends BiomeSource { @Override public Biome getBiomeForNoiseGen(int biomeX, int biomeY, int biomeZ) { - UserDefinedBiome biome = (UserDefinedBiome) grid.getBiome(biomeX * 4, biomeZ * 4); - return biomeRegistry.get(new Identifier("terra", TerraFabricPlugin.createBiomeID(pack, biome))); + UserDefinedBiome biome = (UserDefinedBiome) grid.getBiome(biomeX << 2, biomeZ << 2); + return biomeRegistry.get(new Identifier("terra", TerraFabricPlugin.createBiomeID(pack, biome.getID()))); } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java index 302f3ee83..dad4cba8f 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java @@ -78,7 +78,7 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements com.d super(biomeSource, new StructuresConfig(false)); this.pack = configPack; - this.delegate = new DefaultChunkGenerator3D(pack, TerraFabricPlugin.getInstance(), pack.getSamplerCache()); + this.delegate = new DefaultChunkGenerator3D(pack, TerraFabricPlugin.getInstance()); delegate.getMain().logger().info("Loading world with config pack " + pack.getTemplate().getID()); this.biomeSource = biomeSource; diff --git a/platforms/region/src/main/java/com/dfsek/terra/region/Generator.java b/platforms/region/src/main/java/com/dfsek/terra/region/Generator.java index d1725b3c5..cd6a55e66 100644 --- a/platforms/region/src/main/java/com/dfsek/terra/region/Generator.java +++ b/platforms/region/src/main/java/com/dfsek/terra/region/Generator.java @@ -1,6 +1,7 @@ package com.dfsek.terra.region; import com.dfsek.terra.StandalonePlugin; +import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.platform.DirectChunkData; import com.dfsek.terra.platform.DirectWorld; import com.dfsek.terra.platform.GenWrapper; @@ -31,7 +32,7 @@ public class Generator { structurePopulator = new StructurePopulator(plugin); treePopulator = new TreePopulator(plugin); orePopulator = new OrePopulator(plugin); - generator = new DefaultChunkGenerator3D(plugin.getConfigRegistry().get("DEFAULT"), plugin, new SamplerCache(plugin)); + generator = new DefaultChunkGenerator3D(plugin.getConfigRegistry().get("DEFAULT"), plugin); this.seed = seed; } From 1125b498ecf787f232b434becec0047809011717 Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 1 Mar 2021 15:39:10 -0700 Subject: [PATCH 42/95] remove unneeded generic from BiomeBuilder --- .../java/com/dfsek/terra/config/builder/BiomeBuilder.java | 4 +--- .../terra/config/builder/UserDefinedBiomeBuilder.java | 2 +- .../com/dfsek/terra/config/factories/BiomeFactory.java | 7 +++---- .../biome/templates/provider/ImageProviderTemplate.java | 5 ++--- .../biome/templates/source/NoiseSourceTemplate.java | 3 +-- .../stage/mutator/BorderListMutatorTemplate.java | 2 +- .../templates/stage/mutator/BorderMutatorTemplate.java | 4 +--- .../stage/mutator/ReplaceListMutatorTemplate.java | 5 ++--- .../templates/stage/mutator/ReplaceMutatorTemplate.java | 4 +--- .../main/java/com/dfsek/terra/config/pack/ConfigPack.java | 6 ++---- .../com/dfsek/terra/registry/config/BiomeRegistry.java | 7 +++---- common/src/test/java/biome/DistributionTest.java | 8 ++++---- platforms/bukkit/build.gradle.kts | 2 ++ .../java/com/dfsek/terra/fabric/TerraFabricPlugin.java | 3 +-- 14 files changed, 25 insertions(+), 37 deletions(-) diff --git a/common/src/main/java/com/dfsek/terra/config/builder/BiomeBuilder.java b/common/src/main/java/com/dfsek/terra/config/builder/BiomeBuilder.java index 27fdef9f3..a454cb07c 100644 --- a/common/src/main/java/com/dfsek/terra/config/builder/BiomeBuilder.java +++ b/common/src/main/java/com/dfsek/terra/config/builder/BiomeBuilder.java @@ -1,12 +1,10 @@ package com.dfsek.terra.config.builder; -import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.platform.world.Biome; import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.util.seeded.SeededBuilder; import com.dfsek.terra.api.world.biome.TerraBiome; -import com.dfsek.terra.world.TerraWorld; -public interface BiomeBuilder extends SeededBuilder { +public interface BiomeBuilder extends SeededBuilder { ProbabilityCollection getVanillaBiomes(); } diff --git a/common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java b/common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java index a30161b07..e320b7517 100644 --- a/common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java +++ b/common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java @@ -17,7 +17,7 @@ import com.dfsek.terra.world.generation.WorldGenerator; import java.util.HashMap; import java.util.Map; -public class UserDefinedBiomeBuilder implements BiomeBuilder { +public class UserDefinedBiomeBuilder implements BiomeBuilder { private final BiomeTemplate template; private final ConfigPack pack; diff --git a/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java b/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java index 8e99d3bfe..c19ea0988 100644 --- a/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java +++ b/common/src/main/java/com/dfsek/terra/config/factories/BiomeFactory.java @@ -1,13 +1,12 @@ package com.dfsek.terra.config.factories; import com.dfsek.terra.api.TerraPlugin; -import com.dfsek.terra.api.world.biome.TerraBiome; -import com.dfsek.terra.config.builder.UserDefinedBiomeBuilder; import com.dfsek.terra.config.builder.BiomeBuilder; +import com.dfsek.terra.config.builder.UserDefinedBiomeBuilder; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.config.templates.BiomeTemplate; -public class BiomeFactory implements ConfigFactory> { +public class BiomeFactory implements ConfigFactory { private final ConfigPack pack; public BiomeFactory(ConfigPack pack) { @@ -15,7 +14,7 @@ public class BiomeFactory implements ConfigFactory build(BiomeTemplate template, TerraPlugin main) { + public BiomeBuilder build(BiomeTemplate template, TerraPlugin main) { return new UserDefinedBiomeBuilder(template, pack); } } diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/ImageProviderTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/ImageProviderTemplate.java index 7524a632e..b66e25cba 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/ImageProviderTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/ImageProviderTemplate.java @@ -2,7 +2,6 @@ package com.dfsek.terra.config.loaders.config.biome.templates.provider; import com.dfsek.tectonic.annotations.Value; import com.dfsek.terra.api.registry.Registry; -import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.api.world.biome.provider.ImageBiomeProvider; import com.dfsek.terra.config.builder.BiomeBuilder; @@ -11,14 +10,14 @@ import java.awt.image.BufferedImage; import java.util.stream.Collectors; public class ImageProviderTemplate extends BiomeProviderTemplate { - private final Registry> biomes; + private final Registry biomes; @Value("image.name") private BufferedImage image; @Value("image.align") private ImageBiomeProvider.Align align; - public ImageProviderTemplate(Registry> set) { + public ImageProviderTemplate(Registry set) { this.biomes = set; } diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/NoiseSourceTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/NoiseSourceTemplate.java index 404c53226..7df6255d0 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/NoiseSourceTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/source/NoiseSourceTemplate.java @@ -3,7 +3,6 @@ package com.dfsek.terra.config.loaders.config.biome.templates.source; import com.dfsek.tectonic.annotations.Value; import com.dfsek.terra.api.util.collections.ProbabilityCollection; import com.dfsek.terra.api.util.seeded.NoiseSeeded; -import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.pipeline.source.BiomeSource; import com.dfsek.terra.api.world.biome.pipeline.source.RandomSource; import com.dfsek.terra.config.builder.BiomeBuilder; @@ -13,7 +12,7 @@ public class NoiseSourceTemplate extends SourceTemplate { private NoiseSeeded noise; @Value("biomes") - private ProbabilityCollection> biomes; + private ProbabilityCollection biomes; @Override public BiomeSource apply(Long seed) { diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java index 492bdc70a..c853ee0a4 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java @@ -22,7 +22,7 @@ public class BorderListMutatorTemplate extends MutatorStageTemplate { private ProbabilityCollection defaultTo; @Value("replace") - private Map, ProbabilityCollection>> replace; + private Map> replace; @Override diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderMutatorTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderMutatorTemplate.java index fd44e261c..5502a412f 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderMutatorTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderMutatorTemplate.java @@ -2,11 +2,9 @@ package com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator; import com.dfsek.tectonic.annotations.Value; import com.dfsek.terra.api.util.collections.ProbabilityCollection; -import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator; import com.dfsek.terra.api.world.biome.pipeline.mutator.BorderMutator; import com.dfsek.terra.config.builder.BiomeBuilder; -import com.dfsek.terra.config.builder.UserDefinedBiomeBuilder; @SuppressWarnings("unused") public class BorderMutatorTemplate extends MutatorStageTemplate { @@ -17,7 +15,7 @@ public class BorderMutatorTemplate extends MutatorStageTemplate { private String replace; @Value("to") - private ProbabilityCollection> to; + private ProbabilityCollection to; @Override public BiomeMutator build(long seed) { diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceListMutatorTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceListMutatorTemplate.java index 6635f59c0..d40eec7b4 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceListMutatorTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceListMutatorTemplate.java @@ -6,7 +6,6 @@ import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator; import com.dfsek.terra.api.world.biome.pipeline.mutator.ReplaceListMutator; import com.dfsek.terra.config.builder.BiomeBuilder; -import com.dfsek.terra.config.builder.UserDefinedBiomeBuilder; import java.util.HashMap; import java.util.Map; @@ -17,10 +16,10 @@ public class ReplaceListMutatorTemplate extends MutatorStageTemplate { private String defaultFrom; @Value("default-to") - private ProbabilityCollection> defaultTo; + private ProbabilityCollection defaultTo; @Value("to") - private Map, ProbabilityCollection>> replace; + private Map> replace; @Override public BiomeMutator build(long seed) { diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceMutatorTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceMutatorTemplate.java index 36b2e542e..fbe801fbf 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceMutatorTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/ReplaceMutatorTemplate.java @@ -2,11 +2,9 @@ package com.dfsek.terra.config.loaders.config.biome.templates.stage.mutator; import com.dfsek.tectonic.annotations.Value; import com.dfsek.terra.api.util.collections.ProbabilityCollection; -import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator; import com.dfsek.terra.api.world.biome.pipeline.mutator.ReplaceMutator; import com.dfsek.terra.config.builder.BiomeBuilder; -import com.dfsek.terra.config.builder.UserDefinedBiomeBuilder; @SuppressWarnings("unused") public class ReplaceMutatorTemplate extends MutatorStageTemplate { @@ -14,7 +12,7 @@ public class ReplaceMutatorTemplate extends MutatorStageTemplate { private String from; @Value("to") - private ProbabilityCollection> to; + private ProbabilityCollection to; @Override public BiomeMutator build(long seed) { diff --git a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java index 5f557e711..6139ef7f8 100644 --- a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java +++ b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java @@ -17,22 +17,20 @@ import com.dfsek.terra.api.structures.loot.LootTable; import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder; import com.dfsek.terra.api.structures.script.StructureScript; import com.dfsek.terra.api.util.seeded.NoiseSeeded; -import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.api.world.flora.Flora; import com.dfsek.terra.api.world.palette.Palette; import com.dfsek.terra.api.world.tree.Tree; import com.dfsek.terra.carving.UserDefinedCarver; -import com.dfsek.terra.config.builder.UserDefinedBiomeBuilder; import com.dfsek.terra.config.builder.BiomeBuilder; import com.dfsek.terra.config.dummy.DummyWorld; import com.dfsek.terra.config.factories.BiomeFactory; import com.dfsek.terra.config.factories.CarverFactory; +import com.dfsek.terra.config.factories.ConfigFactory; import com.dfsek.terra.config.factories.FloraFactory; import com.dfsek.terra.config.factories.OreFactory; import com.dfsek.terra.config.factories.PaletteFactory; import com.dfsek.terra.config.factories.StructureFactory; -import com.dfsek.terra.config.factories.ConfigFactory; import com.dfsek.terra.config.factories.TreeFactory; import com.dfsek.terra.config.fileloaders.FolderLoader; import com.dfsek.terra.config.fileloaders.Loader; @@ -291,7 +289,7 @@ public class ConfigPack implements LoaderRegistrar { return new CheckedRegistry<>(scriptRegistry); } - public CheckedRegistry> getBiomeRegistry() { + public CheckedRegistry getBiomeRegistry() { return new CheckedRegistry<>(biomeRegistry); } diff --git a/common/src/main/java/com/dfsek/terra/registry/config/BiomeRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/BiomeRegistry.java index 580c59d99..5ad1d32a6 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/BiomeRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/BiomeRegistry.java @@ -2,17 +2,16 @@ package com.dfsek.terra.registry.config; import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; -import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.config.builder.BiomeBuilder; import com.dfsek.terra.registry.OpenRegistry; import java.lang.reflect.Type; -public class BiomeRegistry extends OpenRegistry> { +public class BiomeRegistry extends OpenRegistry { @Override - public BiomeBuilder load(Type type, Object o, ConfigLoader configLoader) throws LoadException { + public BiomeBuilder load(Type type, Object o, ConfigLoader configLoader) throws LoadException { if(o.equals("SELF")) return null; - BiomeBuilder biome = get((String) o); + BiomeBuilder biome = get((String) o); if(biome == null) throw new LoadException("No such " + type.getTypeName() + " matching \"" + o + "\" was found in this registry."); return biome; diff --git a/common/src/test/java/biome/DistributionTest.java b/common/src/test/java/biome/DistributionTest.java index 9468243a0..226da5898 100644 --- a/common/src/test/java/biome/DistributionTest.java +++ b/common/src/test/java/biome/DistributionTest.java @@ -145,11 +145,11 @@ public class DistributionTest { private static BiomeProvider getProvider(long seed) throws ConfigException, IOException { System.out.println(seed); - File pack = new File("/home/dfsek/Documents/Terra/platforms/bukkit/target/server/plugins/Terra/packs/betterend/"); + File pack = new File("/home/dfsek/Documents/Terra/platforms/bukkit/target/server/plugins/Terra/packs/default/"); FolderLoader folderLoader = new FolderLoader(pack.toPath()); AbstractConfigLoader loader = new AbstractConfigLoader(); - new GenericLoaders(null).register(loader); + new GenericLoaders(MAIN).register(loader); BiomeRegistry biomeRegistry = new BiomeRegistry(); folderLoader.open("biomes", ".yml").then(inputStreams -> ConfigPack.buildAll((template, main) -> template, biomeRegistry, loader.load(inputStreams, TestBiome::new), MAIN)); @@ -163,7 +163,7 @@ public class DistributionTest { .registerLoader(SingleBiomeProviderTemplate.class, SingleBiomeProviderTemplate::new) .registerLoader(BiomePipelineTemplate.class, () -> new BiomePipelineTemplate(MAIN)) .registerLoader(ImageProviderTemplate.class, () -> new ImageProviderTemplate(biomeRegistry)); - new GenericLoaders(null).register(pipeLoader); + new GenericLoaders(MAIN).register(pipeLoader); pipeLoader.registerLoader(NoiseSeeded.class, new NoiseSamplerBuilderLoader(new NoiseRegistry())); @@ -286,7 +286,7 @@ public class DistributionTest { } } - private static final class TestBiome extends AbstractableTemplate implements TerraBiome, ValidatedConfigTemplate, BiomeBuilder { + private static final class TestBiome extends AbstractableTemplate implements TerraBiome, ValidatedConfigTemplate, BiomeBuilder { @Value("color") @Default diff --git a/platforms/bukkit/build.gradle.kts b/platforms/bukkit/build.gradle.kts index dbf066f36..e3a942319 100644 --- a/platforms/bukkit/build.gradle.kts +++ b/platforms/bukkit/build.gradle.kts @@ -33,6 +33,8 @@ dependencies { "compileOnly"("com.sk89q.worldedit:worldedit-bukkit:7.2.0-SNAPSHOT") "shadedImplementation"("com.google.guava:guava:30.0-jre") + + "testImplementation"("com.google.guava:guava:30.0-jre") } val testDir = "target/server/" diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index 5fa16b5ef..e426fa2b2 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -22,7 +22,6 @@ import com.dfsek.terra.api.transform.NotNullValidator; import com.dfsek.terra.api.transform.Transformer; import com.dfsek.terra.api.util.logging.DebugLogger; import com.dfsek.terra.api.util.logging.Logger; -import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.tree.Tree; import com.dfsek.terra.config.GenericLoaders; import com.dfsek.terra.config.PluginConfig; @@ -223,7 +222,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { return pack.getTemplate().getID().toLowerCase() + "/" + biomeID; } - private Biome createBiome(BiomeBuilder biome) { + private Biome createBiome(BiomeBuilder biome) { SpawnSettings.Builder spawnSettings = new SpawnSettings.Builder(); DefaultBiomeFeatures.addFarmAnimals(spawnSettings); DefaultBiomeFeatures.addMonsters(spawnSettings, 95, 5, 100); From 265449c5a75137d80e12e4d21e96853cbb8b6d93 Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 1 Mar 2021 16:43:14 -0700 Subject: [PATCH 43/95] fix ProbabilityCollection map issues --- common/build.gradle.kts | 2 + .../collections/ProbabilityCollection.java | 42 +++++++++++++---- .../api/world/biome/UserDefinedBiome.java | 7 ++- .../builder/UserDefinedBiomeBuilder.java | 46 +++++++++++-------- .../mutator/BorderListMutatorTemplate.java | 5 +- platforms/bukkit/build.gradle.kts | 2 - 6 files changed, 70 insertions(+), 34 deletions(-) diff --git a/common/build.gradle.kts b/common/build.gradle.kts index fad3faf0c..5938324de 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -23,6 +23,8 @@ dependencies { "compileOnly"("com.googlecode.json-simple:json-simple:1.1") "compileOnly"("com.google.guava:guava:30.0-jre") + + "testImplementation"("com.google.guava:guava:30.0-jre") } publishing { diff --git a/common/src/main/java/com/dfsek/terra/api/util/collections/ProbabilityCollection.java b/common/src/main/java/com/dfsek/terra/api/util/collections/ProbabilityCollection.java index 9a7ac4032..f9ec64992 100644 --- a/common/src/main/java/com/dfsek/terra/api/util/collections/ProbabilityCollection.java +++ b/common/src/main/java/com/dfsek/terra/api/util/collections/ProbabilityCollection.java @@ -2,25 +2,28 @@ package com.dfsek.terra.api.util.collections; import com.dfsek.terra.api.math.MathUtil; import com.dfsek.terra.api.math.noise.NoiseSampler; +import com.dfsek.terra.api.util.mutable.MutableInteger; import org.jetbrains.annotations.NotNull; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.Map; import java.util.Random; import java.util.Set; import java.util.function.Function; @SuppressWarnings("unchecked") public class ProbabilityCollection implements Collection { - private final Set cont = new HashSet<>(); + protected final Map cont = new HashMap<>(); private Object[] array = new Object[0]; private int size; public ProbabilityCollection add(E item, int probability) { - if(!cont.contains(item)) size++; - cont.add(item); + if(!cont.containsKey(item)) size++; + cont.computeIfAbsent(item, i -> new MutableInteger(0)).increment(); int oldLength = array.length; Object[] newArray = new Object[array.length + probability]; System.arraycopy(array, 0, newArray, 0, array.length); // Expand array. @@ -59,6 +62,20 @@ public class ProbabilityCollection implements Collection { return array.length; } + public int getProbability(E item) { + MutableInteger integer = cont.get(item); + return integer == null ? 0 : integer.get(); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder("["); + + cont.forEach((item, prob) -> builder.append(item).append(": ").append(prob).append(", ")); + + return builder.append("]").toString(); + } + @Override public int size() { return size; @@ -71,26 +88,26 @@ public class ProbabilityCollection implements Collection { @Override public boolean contains(Object o) { - return cont.contains(o); + return cont.containsKey(o); } @NotNull @Override public Iterator iterator() { - return cont.iterator(); + return cont.keySet().iterator(); } @NotNull @Override public Object[] toArray() { - return cont.toArray(); + return cont.keySet().toArray(); } @SuppressWarnings("SuspiciousToArrayCall") @NotNull @Override public T[] toArray(@NotNull T[] a) { - return cont.toArray(a); + return cont.keySet().toArray(a); } /** @@ -109,7 +126,7 @@ public class ProbabilityCollection implements Collection { @Override public boolean containsAll(@NotNull Collection c) { - return cont.containsAll(c); + return cont.keySet().containsAll(c); } @Override @@ -135,7 +152,7 @@ public class ProbabilityCollection implements Collection { } public Set getContents() { - return new HashSet<>(cont); + return new HashSet<>(cont.keySet()); } public static final class Singleton extends ProbabilityCollection { @@ -143,6 +160,7 @@ public class ProbabilityCollection implements Collection { public Singleton(T single) { this.single = single; + cont.put(single, new MutableInteger(1)); } @Override @@ -150,6 +168,12 @@ public class ProbabilityCollection implements Collection { throw new UnsupportedOperationException(); } + @Override + public ProbabilityCollection map(Function mapper, boolean carryNull) { + if(carryNull && single == null) return new Singleton<>(null); + return new Singleton<>(mapper.apply(single)); + } + @Override public T get(Random r) { return single; diff --git a/common/src/main/java/com/dfsek/terra/api/world/biome/UserDefinedBiome.java b/common/src/main/java/com/dfsek/terra/api/world/biome/UserDefinedBiome.java index 4425bc70a..b6e5d9570 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/biome/UserDefinedBiome.java +++ b/common/src/main/java/com/dfsek/terra/api/world/biome/UserDefinedBiome.java @@ -3,11 +3,9 @@ package com.dfsek.terra.api.world.biome; import com.dfsek.terra.api.platform.world.Biome; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.util.collections.ProbabilityCollection; -import com.dfsek.terra.config.builder.GeneratorBuilder; import com.dfsek.terra.config.templates.BiomeTemplate; import com.dfsek.terra.world.generation.WorldGenerator; -import java.util.HashSet; import java.util.Set; /** @@ -65,4 +63,9 @@ public class UserDefinedBiome implements TerraBiome { public Set getTags() { return tags; } + + @Override + public String toString() { + return "{BIOME:" + getID() + "}"; + } } diff --git a/common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java b/common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java index e320b7517..83c458bb5 100644 --- a/common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java +++ b/common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java @@ -16,11 +16,14 @@ import com.dfsek.terra.world.generation.WorldGenerator; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; public class UserDefinedBiomeBuilder implements BiomeBuilder { private final BiomeTemplate template; private final ConfigPack pack; + private final Map biomeMap = new ConcurrentHashMap<>(); + public UserDefinedBiomeBuilder(BiomeTemplate template, ConfigPack pack) { this.template = template; this.pack = pack; @@ -28,29 +31,36 @@ public class UserDefinedBiomeBuilder implements BiomeBuilder { @Override public UserDefinedBiome apply(Long seed) { - NoiseSampler noise; - NoiseSampler elevation; - NoiseSampler carving; - Scope varScope = new Scope().withParent(pack.getVarScope()); + synchronized(biomeMap) { + return biomeMap.computeIfAbsent(seed, + s -> { + NoiseSampler noise; + NoiseSampler elevation; + NoiseSampler carving; + Scope varScope = new Scope().withParent(pack.getVarScope()); - template.getVariables().forEach(varScope::create); + template.getVariables().forEach(varScope::create); + System.out.println("Building biome " + template.getID() + " for seed " + s); - Map noiseBuilderMap = pack.getTemplate().getNoiseBuilderMap(); - Map functionTemplateMap = new HashMap<>(template.getFunctions()); + Map noiseBuilderMap = pack.getTemplate().getNoiseBuilderMap(); + Map functionTemplateMap = new HashMap<>(template.getFunctions()); - functionTemplateMap.putAll(template.getFunctions()); + functionTemplateMap.putAll(template.getFunctions()); - try { - noise = new ExpressionSampler(template.getNoiseEquation(), varScope, seed, noiseBuilderMap, functionTemplateMap); - elevation = template.getElevationEquation() == null ? new ConstantSampler(0) : new ExpressionSampler(template.getElevationEquation(), varScope, seed, noiseBuilderMap, functionTemplateMap); - carving = new ExpressionSampler(template.getCarvingEquation(), varScope, seed, noiseBuilderMap, functionTemplateMap); - } catch(ParseException e) { - throw new RuntimeException(e); + try { + noise = new ExpressionSampler(template.getNoiseEquation(), varScope, seed, noiseBuilderMap, functionTemplateMap); + elevation = template.getElevationEquation() == null ? new ConstantSampler(0) : new ExpressionSampler(template.getElevationEquation(), varScope, seed, noiseBuilderMap, functionTemplateMap); + carving = new ExpressionSampler(template.getCarvingEquation(), varScope, seed, noiseBuilderMap, functionTemplateMap); + } catch(ParseException e) { + throw new RuntimeException(e); + } + + WorldGenerator generator = new WorldGenerator(template.getPalette(), template.getSlantPalette(), noise, elevation, carving, template.getBiomeNoise().apply(seed), template.getElevationWeight(), + template.getBlendDistance(), template.getBlendStep(), template.getBlendWeight()); + return new UserDefinedBiome(template.getVanilla(), generator, template); + } + ); } - - WorldGenerator generator = new WorldGenerator(template.getPalette(), template.getSlantPalette(), noise, elevation, carving, template.getBiomeNoise().apply(seed), template.getElevationWeight(), - template.getBlendDistance(), template.getBlendStep(), template.getBlendWeight()); - return new UserDefinedBiome(template.getVanilla(), generator, template); } @Override diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java index c853ee0a4..9c565621d 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java @@ -6,7 +6,6 @@ import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.pipeline.mutator.BiomeMutator; import com.dfsek.terra.api.world.biome.pipeline.mutator.BorderListMutator; import com.dfsek.terra.config.builder.BiomeBuilder; -import com.dfsek.terra.config.builder.UserDefinedBiomeBuilder; import java.util.HashMap; import java.util.Map; @@ -19,7 +18,7 @@ public class BorderListMutatorTemplate extends MutatorStageTemplate { private String defaultReplace; @Value("default-to") - private ProbabilityCollection defaultTo; + private ProbabilityCollection defaultTo; @Value("replace") private Map> replace; @@ -29,7 +28,7 @@ public class BorderListMutatorTemplate extends MutatorStageTemplate { public BiomeMutator build(long seed) { Map> replaceMap = new HashMap<>(); - replace.forEach((biomeBuilder, biomeBuilders) -> replaceMap.put(biomeBuilder.apply(seed), biomeBuilders.map(builder -> builder.apply(seed), true))); + replace.forEach((keyBuilder, replacements) -> replaceMap.put(keyBuilder.apply(seed), replacements.map(replacement -> replacement.apply(seed), true))); return new BorderListMutator(replaceMap, from, defaultReplace, noise.apply(seed), defaultTo.map(biomeBuilder -> biomeBuilder.apply(seed), true)); } diff --git a/platforms/bukkit/build.gradle.kts b/platforms/bukkit/build.gradle.kts index e3a942319..dbf066f36 100644 --- a/platforms/bukkit/build.gradle.kts +++ b/platforms/bukkit/build.gradle.kts @@ -33,8 +33,6 @@ dependencies { "compileOnly"("com.sk89q.worldedit:worldedit-bukkit:7.2.0-SNAPSHOT") "shadedImplementation"("com.google.guava:guava:30.0-jre") - - "testImplementation"("com.google.guava:guava:30.0-jre") } val testDir = "target/server/" From 72296cf9600e5d3411145bc947f6aad914cf59cb Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 1 Mar 2021 16:45:27 -0700 Subject: [PATCH 44/95] cleanup --- .../biome/templates/stage/mutator/BorderListMutatorTemplate.java | 1 + 1 file changed, 1 insertion(+) diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java index 9c565621d..76146a088 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/stage/mutator/BorderListMutatorTemplate.java @@ -10,6 +10,7 @@ import com.dfsek.terra.config.builder.BiomeBuilder; import java.util.HashMap; import java.util.Map; +@SuppressWarnings("unused") public class BorderListMutatorTemplate extends MutatorStageTemplate { @Value("from") private String from; From c5a174ba7adcb8cd21b76c5ab2ae5c25a86f94e7 Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 1 Mar 2021 16:49:32 -0700 Subject: [PATCH 45/95] remove sys.out --- .../com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java | 1 - 1 file changed, 1 deletion(-) diff --git a/common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java b/common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java index 83c458bb5..34f356ece 100644 --- a/common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java +++ b/common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java @@ -40,7 +40,6 @@ public class UserDefinedBiomeBuilder implements BiomeBuilder { Scope varScope = new Scope().withParent(pack.getVarScope()); template.getVariables().forEach(varScope::create); - System.out.println("Building biome " + template.getID() + " for seed " + s); Map noiseBuilderMap = pack.getTemplate().getNoiseBuilderMap(); Map functionTemplateMap = new HashMap<>(template.getFunctions()); From 613e9c0c54f6de792ec1130e5616146a2b6faab8 Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 1 Mar 2021 16:54:56 -0700 Subject: [PATCH 46/95] fabric ID fix --- .../main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index e426fa2b2..181472590 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -75,6 +75,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; +import java.util.Locale; import java.util.Map; @@ -219,7 +220,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { } public static String createBiomeID(ConfigPack pack, String biomeID) { - return pack.getTemplate().getID().toLowerCase() + "/" + biomeID; + return pack.getTemplate().getID().toLowerCase() + "/" + biomeID.toLowerCase(Locale.ROOT); } private Biome createBiome(BiomeBuilder biome) { From e4c1a056ae81b83723de67bc82d3ca1ef2e3cc77 Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 1 Mar 2021 17:20:19 -0700 Subject: [PATCH 47/95] fix server issues --- platforms/fabric/build.gradle.kts | 10 +++--- .../dfsek/terra/fabric/TerraFabricPlugin.java | 26 +++++++++------- .../fabric/mixin/BiomeEffectsAccessor.java | 31 +++++++++++++++++++ .../fabric/mixin/GeneratorTypeAccessor.java | 24 ++++++++++++++ .../fabric/src/main/resources/fabric.mod.json | 1 + .../src/main/resources/terra.accesswidener | 10 +----- .../src/main/resources/terra.mixins.json | 16 ++++++++++ 7 files changed, 94 insertions(+), 24 deletions(-) create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/BiomeEffectsAccessor.java create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/GeneratorTypeAccessor.java create mode 100644 platforms/fabric/src/main/resources/terra.mixins.json diff --git a/platforms/fabric/build.gradle.kts b/platforms/fabric/build.gradle.kts index 73dc69a3e..35078842a 100644 --- a/platforms/fabric/build.gradle.kts +++ b/platforms/fabric/build.gradle.kts @@ -37,10 +37,12 @@ configure { } tasks.register("remapShadedJar") { - dependsOn("shadowJar") - setProperty("input", file("build/libs/Terra-fabric-${version}-shaded.jar")) - setProperty("addNestedDependencies", false) - setProperty("remapAccessWidener", true) + val shadowJar = tasks.getByName("shadowJar") + dependsOn(shadowJar) + input.set(shadowJar.archiveFile) + archiveFileName.set(shadowJar.archiveFileName.get().replace(Regex("-shaded\\.jar$"), "shaded-mapped.jar")) + addNestedDependencies.set(true) + remapAccessWidener.set(true) } dependencies { diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index 181472590..ce0cd677c 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -30,6 +30,8 @@ import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.Language; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.fabric.inventory.FabricItemHandle; +import com.dfsek.terra.fabric.mixin.BiomeEffectsAccessor; +import com.dfsek.terra.fabric.mixin.GeneratorTypeAccessor; import com.dfsek.terra.fabric.world.FabricBiome; import com.dfsek.terra.fabric.world.FabricTree; import com.dfsek.terra.fabric.world.FabricWorldHandle; @@ -234,17 +236,19 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { generationSettings.surfaceBuilder(SurfaceBuilder.DEFAULT.withConfig(new TernarySurfaceConfig(Blocks.GRASS_BLOCK.getDefaultState(), Blocks.DIRT.getDefaultState(), Blocks.GRAVEL.getDefaultState()))); // It needs a surfacebuilder, even though we dont use it. generationSettings.feature(GenerationStep.Feature.VEGETAL_DECORATION, POPULATOR_CONFIGURED_FEATURE); + BiomeEffectsAccessor biomeEffectsAccessor = (BiomeEffectsAccessor) vanilla.getEffects(); + BiomeEffects.Builder effects = new BiomeEffects.Builder() - .waterColor(vanilla.getWaterColor()) - .waterFogColor(vanilla.getWaterFogColor()) - .fogColor(vanilla.getFogColor()) - .skyColor(vanilla.getSkyColor()) - .grassColorModifier(vanilla.getEffects().getGrassColorModifier()); - if(vanilla.getEffects().getGrassColor().isPresent()) { - effects.grassColor(vanilla.getEffects().getGrassColor().get()); + .waterColor(biomeEffectsAccessor.getWaterColor()) + .waterFogColor(biomeEffectsAccessor.getWaterFogColor()) + .fogColor(biomeEffectsAccessor.getFogColor()) + .skyColor(biomeEffectsAccessor.getSkyColor()) + .grassColorModifier(biomeEffectsAccessor.getGrassColorModifier()); + if(biomeEffectsAccessor.getGrassColor().isPresent()) { + effects.grassColor(biomeEffectsAccessor.getGrassColor().get()); } - if(vanilla.getEffects().getFoliageColor().isPresent()) { - effects.foliageColor(vanilla.getEffects().getFoliageColor().get()); + if(biomeEffectsAccessor.getFoliageColor().isPresent()) { + effects.foliageColor(biomeEffectsAccessor.getFoliageColor().get()); } return (new Biome.Builder()) @@ -296,8 +300,8 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { } }; //noinspection ConstantConditions - generatorType.translationKey = (new LiteralText("Terra:" + pack.getTemplate().getID())); - GeneratorType.VALUES.add(generatorType); + ((GeneratorTypeAccessor) generatorType).setTranslationKey(new LiteralText("Terra:" + pack.getTemplate().getID())); + GeneratorTypeAccessor.getVALUES().add(generatorType); }); } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/BiomeEffectsAccessor.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/BiomeEffectsAccessor.java new file mode 100644 index 000000000..a21d77e9d --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/BiomeEffectsAccessor.java @@ -0,0 +1,31 @@ +package com.dfsek.terra.fabric.mixin; + +import net.minecraft.world.biome.BiomeEffects; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.Optional; + +@Mixin(BiomeEffects.class) +public interface BiomeEffectsAccessor { + @Accessor + int getFogColor(); + + @Accessor + int getWaterColor(); + + @Accessor + int getWaterFogColor(); + + @Accessor + int getSkyColor(); + + @Accessor + Optional getFoliageColor(); + + @Accessor + Optional getGrassColor(); + + @Accessor + BiomeEffects.GrassColorModifier getGrassColorModifier(); +} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/GeneratorTypeAccessor.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/GeneratorTypeAccessor.java new file mode 100644 index 000000000..7af215e73 --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/GeneratorTypeAccessor.java @@ -0,0 +1,24 @@ +package com.dfsek.terra.fabric.mixin; + +import net.minecraft.client.world.GeneratorType; +import net.minecraft.text.Text; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.List; + +@Mixin(GeneratorType.class) +public interface GeneratorTypeAccessor { + @Accessor + static List getVALUES() { + throw new UnsupportedOperationException(); + } + + @Accessor + Text getTranslationKey(); + + @Mutable + @Accessor + void setTranslationKey(Text translationKey); +} diff --git a/platforms/fabric/src/main/resources/fabric.mod.json b/platforms/fabric/src/main/resources/fabric.mod.json index 0468f1530..d86abc872 100644 --- a/platforms/fabric/src/main/resources/fabric.mod.json +++ b/platforms/fabric/src/main/resources/fabric.mod.json @@ -20,6 +20,7 @@ ] }, "mixins": [ + "terra.mixins.json" ], "depends": { "fabricloader": ">=0.7.4", diff --git a/platforms/fabric/src/main/resources/terra.accesswidener b/platforms/fabric/src/main/resources/terra.accesswidener index c501a7abb..9f2064838 100644 --- a/platforms/fabric/src/main/resources/terra.accesswidener +++ b/platforms/fabric/src/main/resources/terra.accesswidener @@ -2,16 +2,8 @@ accessWidener v1 named extendable method net/minecraft/client/world/GeneratorType (Ljava/lang/String;)V -accessible field net/minecraft/client/world/GeneratorType translationKey Lnet/minecraft/text/Text; -mutable field net/minecraft/client/world/GeneratorType translationKey Lnet/minecraft/text/Text; - -accessible field net/minecraft/client/world/GeneratorType VALUES Ljava/util/List; - accessible field net/minecraft/server/world/ServerWorld worldProperties Lnet/minecraft/world/level/ServerWorldProperties; accessible method net/minecraft/world/MobSpawnerLogic getEntityId ()Lnet/minecraft/util/Identifier; -accessible field net/minecraft/state/State PROPERTY_MAP_PRINTER Ljava/util/function/Function; - -accessible method net/minecraft/block/entity/LootableContainerBlockEntity setInvStackList (Lnet/minecraft/util/collection/DefaultedList;)V -accessible method net/minecraft/block/entity/LootableContainerBlockEntity getInvStackList ()Lnet/minecraft/util/collection/DefaultedList; \ No newline at end of file +accessible field net/minecraft/state/State PROPERTY_MAP_PRINTER Ljava/util/function/Function; \ No newline at end of file diff --git a/platforms/fabric/src/main/resources/terra.mixins.json b/platforms/fabric/src/main/resources/terra.mixins.json new file mode 100644 index 000000000..1020b1459 --- /dev/null +++ b/platforms/fabric/src/main/resources/terra.mixins.json @@ -0,0 +1,16 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "com.dfsek.terra.fabric.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "BiomeEffectsAccessor" + ], + "client": [ + "GeneratorTypeAccessor" + ], + "server": [], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file From 7828de74aab39e6f0fd7d872d7ec4363742bc1cb Mon Sep 17 00:00:00 2001 From: dfsek Date: Tue, 2 Mar 2021 00:30:26 -0700 Subject: [PATCH 48/95] work on loom stuff --- platforms/fabric/build.gradle.kts | 62 +++++++++---------- .../dfsek/terra/fabric/TerraFabricPlugin.java | 20 +++--- .../fabric/mixin/BiomeEffectsAccessor.java | 31 ---------- .../fabric/mixin/GeneratorTypeAccessor.java | 3 - .../src/main/resources/terra.accesswidener | 12 +++- .../src/main/resources/terra.mixins.json | 1 - 6 files changed, 48 insertions(+), 81 deletions(-) delete mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/BiomeEffectsAccessor.java diff --git a/platforms/fabric/build.gradle.kts b/platforms/fabric/build.gradle.kts index 35078842a..da1591bb5 100644 --- a/platforms/fabric/build.gradle.kts +++ b/platforms/fabric/build.gradle.kts @@ -11,39 +11,18 @@ buildscript { url = uri("https://maven.fabricmc.net/") } } -// dependencies { -// classpath("net.fabricmc:fabric-loom:+") -// } + dependencies { + classpath("net.fabricmc:fabric-loom:0.6-SNAPSHOT") + } } -plugins { - id("fabric-loom").version("0.5.9") - `java-library` -} -//apply(plugin = "fabric-loom") +apply(plugin = "fabric-loom") +apply(plugin = "java-library") configureCommon() -tasks.named("shadowJar") { - relocate("org.json", "com.dfsek.terra.lib.json") - relocate("org.yaml", "com.dfsek.terra.lib.yaml") -} - -group = "com.dfsek.terra.fabric" - - -configure { - accessWidener("src/main/resources/terra.accesswidener") -} - -tasks.register("remapShadedJar") { - val shadowJar = tasks.getByName("shadowJar") - dependsOn(shadowJar) - input.set(shadowJar.archiveFile) - archiveFileName.set(shadowJar.archiveFileName.get().replace(Regex("-shaded\\.jar$"), "shaded-mapped.jar")) - addNestedDependencies.set(true) - remapAccessWidener.set(true) -} +val mixinVersion = "0.8.1+build.21" +val loomVersion = "0.6-SNAPSHOT" dependencies { "shadedApi"(project(":common")) @@ -59,7 +38,26 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. "modImplementation"("net.fabricmc.fabric-api:fabric-api:0.31.0+1.16") - "compileOnly"("net.fabricmc:sponge-mixin:+") - "annotationProcessor"("net.fabricmc:sponge-mixin:+") - "annotationProcessor"("net.fabricmc:fabric-loom:+") -} \ No newline at end of file + "compileOnly"("net.fabricmc:sponge-mixin:${mixinVersion}") + "annotationProcessor"("net.fabricmc:sponge-mixin:${mixinVersion}") + "annotationProcessor"("net.fabricmc:fabric-loom:${loomVersion}") +} + +tasks.named("shadowJar") { + relocate("org.json", "com.dfsek.terra.lib.json") + relocate("org.yaml", "com.dfsek.terra.lib.yaml") +} + + +configure { + accessWidener("src/main/resources/terra.accesswidener") +} + +tasks.register("remapShadedJar") { + val shadowJar = tasks.getByName("shadowJar") + dependsOn(shadowJar) + input.set(shadowJar.archiveFile) + archiveFileName.set(shadowJar.archiveFileName.get().replace(Regex("-shaded\\.jar$"), "-shaded-mapped.jar")) + addNestedDependencies.set(true) + remapAccessWidener.set(true) +} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index ce0cd677c..8f83ecea1 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -30,7 +30,6 @@ import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.lang.Language; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.fabric.inventory.FabricItemHandle; -import com.dfsek.terra.fabric.mixin.BiomeEffectsAccessor; import com.dfsek.terra.fabric.mixin.GeneratorTypeAccessor; import com.dfsek.terra.fabric.world.FabricBiome; import com.dfsek.terra.fabric.world.FabricTree; @@ -236,20 +235,15 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { generationSettings.surfaceBuilder(SurfaceBuilder.DEFAULT.withConfig(new TernarySurfaceConfig(Blocks.GRASS_BLOCK.getDefaultState(), Blocks.DIRT.getDefaultState(), Blocks.GRAVEL.getDefaultState()))); // It needs a surfacebuilder, even though we dont use it. generationSettings.feature(GenerationStep.Feature.VEGETAL_DECORATION, POPULATOR_CONFIGURED_FEATURE); - BiomeEffectsAccessor biomeEffectsAccessor = (BiomeEffectsAccessor) vanilla.getEffects(); BiomeEffects.Builder effects = new BiomeEffects.Builder() - .waterColor(biomeEffectsAccessor.getWaterColor()) - .waterFogColor(biomeEffectsAccessor.getWaterFogColor()) - .fogColor(biomeEffectsAccessor.getFogColor()) - .skyColor(biomeEffectsAccessor.getSkyColor()) - .grassColorModifier(biomeEffectsAccessor.getGrassColorModifier()); - if(biomeEffectsAccessor.getGrassColor().isPresent()) { - effects.grassColor(biomeEffectsAccessor.getGrassColor().get()); - } - if(biomeEffectsAccessor.getFoliageColor().isPresent()) { - effects.foliageColor(biomeEffectsAccessor.getFoliageColor().get()); - } + .waterColor(vanilla.getEffects().waterColor) + .waterFogColor(vanilla.getEffects().waterFogColor) + .fogColor(vanilla.getEffects().fogColor) + .skyColor(vanilla.getEffects().skyColor) + .grassColorModifier(vanilla.getEffects().grassColorModifier); + vanilla.getEffects().grassColor.ifPresent(effects::grassColor); + vanilla.getEffects().foliageColor.ifPresent(effects::foliageColor); return (new Biome.Builder()) .precipitation(vanilla.getPrecipitation()) diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/BiomeEffectsAccessor.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/BiomeEffectsAccessor.java deleted file mode 100644 index a21d77e9d..000000000 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/BiomeEffectsAccessor.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.dfsek.terra.fabric.mixin; - -import net.minecraft.world.biome.BiomeEffects; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import java.util.Optional; - -@Mixin(BiomeEffects.class) -public interface BiomeEffectsAccessor { - @Accessor - int getFogColor(); - - @Accessor - int getWaterColor(); - - @Accessor - int getWaterFogColor(); - - @Accessor - int getSkyColor(); - - @Accessor - Optional getFoliageColor(); - - @Accessor - Optional getGrassColor(); - - @Accessor - BiomeEffects.GrassColorModifier getGrassColorModifier(); -} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/GeneratorTypeAccessor.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/GeneratorTypeAccessor.java index 7af215e73..07449ae3a 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/GeneratorTypeAccessor.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/GeneratorTypeAccessor.java @@ -15,9 +15,6 @@ public interface GeneratorTypeAccessor { throw new UnsupportedOperationException(); } - @Accessor - Text getTranslationKey(); - @Mutable @Accessor void setTranslationKey(Text translationKey); diff --git a/platforms/fabric/src/main/resources/terra.accesswidener b/platforms/fabric/src/main/resources/terra.accesswidener index 9f2064838..fcf59a730 100644 --- a/platforms/fabric/src/main/resources/terra.accesswidener +++ b/platforms/fabric/src/main/resources/terra.accesswidener @@ -6,4 +6,14 @@ accessible field net/minecraft/server/world/ServerWorld worldProperties Lnet/min accessible method net/minecraft/world/MobSpawnerLogic getEntityId ()Lnet/minecraft/util/Identifier; -accessible field net/minecraft/state/State PROPERTY_MAP_PRINTER Ljava/util/function/Function; \ No newline at end of file +accessible field net/minecraft/state/State PROPERTY_MAP_PRINTER Ljava/util/function/Function; + + +accessible field net/minecraft/world/biome/BiomeEffects fogColor I +accessible field net/minecraft/world/biome/BiomeEffects waterColor I +accessible field net/minecraft/world/biome/BiomeEffects waterFogColor I +accessible field net/minecraft/world/biome/BiomeEffects skyColor I + +accessible field net/minecraft/world/biome/BiomeEffects foliageColor Ljava/util/Optional; +accessible field net/minecraft/world/biome/BiomeEffects grassColor Ljava/util/Optional; +accessible field net/minecraft/world/biome/BiomeEffects grassColorModifier Lnet/minecraft/world/biome/BiomeEffects$GrassColorModifier; diff --git a/platforms/fabric/src/main/resources/terra.mixins.json b/platforms/fabric/src/main/resources/terra.mixins.json index 1020b1459..486efc32b 100644 --- a/platforms/fabric/src/main/resources/terra.mixins.json +++ b/platforms/fabric/src/main/resources/terra.mixins.json @@ -4,7 +4,6 @@ "package": "com.dfsek.terra.fabric.mixin", "compatibilityLevel": "JAVA_8", "mixins": [ - "BiomeEffectsAccessor" ], "client": [ "GeneratorTypeAccessor" From c0d26256af8c8fc8c450d24afdcff4d41905c93a Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 3 Mar 2021 13:42:15 -0700 Subject: [PATCH 49/95] fix typo --- .../com/dfsek/terra/api/world/tree/fractal/trees/OakTree.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/OakTree.java b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/OakTree.java index ced1db454..c973d872a 100644 --- a/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/OakTree.java +++ b/common/src/main/java/com/dfsek/terra/api/world/tree/fractal/trees/OakTree.java @@ -39,7 +39,7 @@ public class OakTree extends FractalTree { private void growBranch(Location l1, Vector3 diff, double d1, int recursions, Random r) { BlockData wood = getMain().getWorldHandle().createBlockData("minecraft:oak_wood"); - BlockData leaves = getMain().getWorldHandle().createBlockData("minecraft:oak_leave"); + BlockData leaves = getMain().getWorldHandle().createBlockData("minecraft:oak_leaves"); if(recursions > 1) { geo.generateSphere(l1, leaves, 1 + r.nextInt(2) + (3 - recursions), false, r); if(recursions > 2) return; From dc52dd635b3e8fe96a4c2eeafcc2b6d491d13c41 Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 3 Mar 2021 15:59:26 -0700 Subject: [PATCH 50/95] update README.md --- README.md | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 42b12fcbc..759f27aaf 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,22 @@ # Terra -Terra is a data-driven world generator based on [Gaea](https://github.com/PolyhedralDev/Gaea). Find out more on our -[Spigot page](https://www.spigotmc.org/resources/85151/)! + +Terra is an incredibly powerful free & open-source data-driven, platform-agnostic world generator. It allows you to create a world exactly +to your specifications, with no knowledge of Java required. + +## Downloads: + +* Paper+ servers (Paper, Tuinity, Purpur, etc): [SpigotMC](https://www.spigotmc.org/resources/85151/) +* Fabric: [Modrinth](https://modrinth.com/mod/terra) / [CurseForge](https://www.curseforge.com/minecraft/mc-mods/terra-world-generator) ## Building and running Terra -To build, simply run `./gradlew build` on Linux/MacOS, or `gradlew.bat build` on Windows. -This will produce a jar in `build/libs` called `Terra-[CURRENT VERSION].jar`. -You can put this right into your plugins dir, along with the correct Gaea version. + +To build, simply run `./gradlew build` (`gradlew.bat build` on Windows). This will produce a jar in `build/libs` +called `Terra-[CURRENT VERSION].jar`. You can put this right into your plugins dir, along with the correct Gaea version. If you would like to test it with a default server config, just run `./gradlew setupServer` or -`./gradlew.bat setupServer` to set up the server, then `./gradlew testWithPaper` or `gradlew.bat testWithPaper` to run -the server. If you want a clean installation of the server, re-run the `setupServer` task. -This will download a default server config from [here](https://github.com/PolyhedralDev/WorldGenTestServer) +`./gradlew.bat setupServer` to set up the server, then `./gradlew testWithPaper` or `gradlew.bat testWithPaper` to run the server. If you +want a clean installation of the server, re-run the `setupServer` task. This will download a default server config +from [here](https://github.com/PolyhedralDev/WorldGenTestServer) and install the server in the `target/server` directory, along with all the needed plugins. **Note: You will need to adjust the `NAME` variable `bukkit.yml` of the test server if you are not using the default From c8c3ab312b7008c03217be68cf9868823f899878 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sat, 6 Mar 2021 10:04:25 -0700 Subject: [PATCH 51/95] separate generator and GeneratorWrapper --- .../platform/world/generator/GeneratorWrapper.java | 9 +++++++++ .../com/dfsek/terra/config/dummy/DummyWorld.java | 5 +++-- .../main/java/com/dfsek/terra/world/TerraWorld.java | 10 +++++----- .../generator/BukkitChunkGeneratorWrapper.java | 3 ++- .../generator/FabricChunkGeneratorWrapper.java | 13 ++++++++----- 5 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/api/platform/world/generator/GeneratorWrapper.java diff --git a/common/src/main/java/com/dfsek/terra/api/platform/world/generator/GeneratorWrapper.java b/common/src/main/java/com/dfsek/terra/api/platform/world/generator/GeneratorWrapper.java new file mode 100644 index 000000000..127f9e5bf --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/platform/world/generator/GeneratorWrapper.java @@ -0,0 +1,9 @@ +package com.dfsek.terra.api.platform.world.generator; + +import com.dfsek.terra.api.platform.Handle; +import com.dfsek.terra.api.world.generation.TerraChunkGenerator; + +public interface GeneratorWrapper extends Handle { + @Override + TerraChunkGenerator getHandle(); +} diff --git a/common/src/main/java/com/dfsek/terra/config/dummy/DummyWorld.java b/common/src/main/java/com/dfsek/terra/config/dummy/DummyWorld.java index d55d813ff..a71cb0867 100644 --- a/common/src/main/java/com/dfsek/terra/config/dummy/DummyWorld.java +++ b/common/src/main/java/com/dfsek/terra/config/dummy/DummyWorld.java @@ -7,6 +7,7 @@ import com.dfsek.terra.api.platform.entity.EntityType; import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.platform.world.generator.ChunkGenerator; +import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper; import java.io.File; import java.util.UUID; @@ -24,12 +25,12 @@ public class DummyWorld implements World { @Override public int getMaxHeight() { - return 155; + return 255; } @Override public ChunkGenerator getGenerator() { - return () -> (ChunkGenerator) () -> null; + return () -> (GeneratorWrapper) () -> null; } @Override diff --git a/common/src/main/java/com/dfsek/terra/world/TerraWorld.java b/common/src/main/java/com/dfsek/terra/world/TerraWorld.java index cfec49efe..d173d12f2 100644 --- a/common/src/main/java/com/dfsek/terra/world/TerraWorld.java +++ b/common/src/main/java/com/dfsek/terra/world/TerraWorld.java @@ -6,7 +6,7 @@ import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.world.World; -import com.dfsek.terra.api.platform.world.generator.ChunkGenerator; +import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper; import com.dfsek.terra.api.world.biome.UserDefinedBiome; import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.api.world.generation.TerraChunkGenerator; @@ -37,16 +37,16 @@ public class TerraWorld { safe = true; } - public TerraChunkGenerator getGenerator() { - return (TerraChunkGenerator) ((ChunkGenerator) world.getGenerator().getHandle()).getHandle(); + public static boolean isTerraWorld(World w) { + return w.getGenerator().getHandle() instanceof GeneratorWrapper; } public World getWorld() { return world; } - public static boolean isTerraWorld(World w) { - return w.getGenerator().getHandle() instanceof ChunkGenerator; + public TerraChunkGenerator getGenerator() { + return ((GeneratorWrapper) world.getGenerator().getHandle()).getHandle(); } public BiomeProvider getBiomeProvider() { diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java index 278583560..092b486f2 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/generator/BukkitChunkGeneratorWrapper.java @@ -2,6 +2,7 @@ package com.dfsek.terra.bukkit.generator; import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.platform.world.Chunk; +import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper; import com.dfsek.terra.api.world.generation.TerraBlockPopulator; import com.dfsek.terra.api.world.generation.TerraChunkGenerator; import com.dfsek.terra.bukkit.population.PopulationManager; @@ -29,7 +30,7 @@ import java.util.Map; import java.util.Random; import java.util.stream.Collectors; -public class BukkitChunkGeneratorWrapper extends ChunkGenerator implements com.dfsek.terra.api.platform.world.generator.ChunkGenerator { +public class BukkitChunkGeneratorWrapper extends ChunkGenerator implements GeneratorWrapper { private static final Map popMap = new HashMap<>(); diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java index dad4cba8f..b1d769cef 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java @@ -1,6 +1,8 @@ package com.dfsek.terra.fabric.world.generator; +import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper; import com.dfsek.terra.api.util.FastRandom; +import com.dfsek.terra.api.world.generation.TerraChunkGenerator; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.fabric.TerraFabricPlugin; import com.dfsek.terra.fabric.world.TerraBiomeSource; @@ -30,7 +32,7 @@ import net.minecraft.world.gen.chunk.ChunkGenerator; import net.minecraft.world.gen.chunk.StructuresConfig; import net.minecraft.world.gen.chunk.VerticalBlockSample; -public class FabricChunkGeneratorWrapper extends ChunkGenerator implements com.dfsek.terra.api.platform.world.generator.ChunkGenerator { +public class FabricChunkGeneratorWrapper extends ChunkGenerator implements GeneratorWrapper { private final long seed; private final DefaultChunkGenerator3D delegate; private final TerraBiomeSource biomeSource; @@ -85,10 +87,6 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements com.d this.seed = seed; } - @Override - public DefaultChunkGenerator3D getHandle() { - return delegate; - } @Override protected Codec getCodec() { @@ -149,4 +147,9 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements com.d return new VerticalBlockSample(array); } + + @Override + public TerraChunkGenerator getHandle() { + return delegate; + } } From f989e4dc89310ce0fba126cb9d8f6b9f6525fe88 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sat, 6 Mar 2021 11:37:28 -0700 Subject: [PATCH 52/95] fix fabric mixin stuff --- platforms/fabric/build.gradle.kts | 6 +++--- platforms/fabric/gradle.properties | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 platforms/fabric/gradle.properties diff --git a/platforms/fabric/build.gradle.kts b/platforms/fabric/build.gradle.kts index 73dc69a3e..2aea53e83 100644 --- a/platforms/fabric/build.gradle.kts +++ b/platforms/fabric/build.gradle.kts @@ -39,7 +39,7 @@ configure { tasks.register("remapShadedJar") { dependsOn("shadowJar") setProperty("input", file("build/libs/Terra-fabric-${version}-shaded.jar")) - setProperty("addNestedDependencies", false) + setProperty("addNestedDependencies", true) setProperty("remapAccessWidener", true) } @@ -57,7 +57,7 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. "modImplementation"("net.fabricmc.fabric-api:fabric-api:0.31.0+1.16") - "compileOnly"("net.fabricmc:sponge-mixin:+") - "annotationProcessor"("net.fabricmc:sponge-mixin:+") + "compileOnly"("net.fabricmc:sponge-mixin:0.8.1") + "annotationProcessor"("net.fabricmc:sponge-mixin:0.8.1") "annotationProcessor"("net.fabricmc:fabric-loom:+") } \ No newline at end of file diff --git a/platforms/fabric/gradle.properties b/platforms/fabric/gradle.properties new file mode 100644 index 000000000..95b4763a8 --- /dev/null +++ b/platforms/fabric/gradle.properties @@ -0,0 +1 @@ +org.gradle.jvmargs=-Xmx4G From c44d26cc18218496e9d00f18bf7c8106993e1492 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 7 Mar 2021 21:41:13 -0700 Subject: [PATCH 53/95] loom is pain --- .../fabric/inventory/meta/FabricItemMeta.java | 3 +- .../fabric/mixin/MixinGeneratorOptions.java | 62 +++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/MixinGeneratorOptions.java diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/meta/FabricItemMeta.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/meta/FabricItemMeta.java index 13a0431e2..2c4d9d079 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/meta/FabricItemMeta.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/inventory/meta/FabricItemMeta.java @@ -5,6 +5,7 @@ import com.dfsek.terra.api.platform.inventory.item.ItemMeta; import com.dfsek.terra.fabric.world.FabricAdapter; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; +import net.minecraft.util.registry.Registry; import java.util.Collections; import java.util.HashMap; @@ -29,7 +30,7 @@ public class FabricItemMeta implements ItemMeta { delegate.getEnchantments().forEach(enchantment -> { CompoundTag eTag = (CompoundTag) enchantment; - map.put(FabricAdapter.adapt(net.minecraft.enchantment.Enchantment.byRawId(eTag.getInt("id"))), eTag.getInt("lvl")); + map.put(FabricAdapter.adapt(Registry.ENCHANTMENT.get(eTag.getInt("id"))), eTag.getInt("lvl")); }); return map; } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/MixinGeneratorOptions.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/MixinGeneratorOptions.java new file mode 100644 index 000000000..aa588249a --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/mixin/MixinGeneratorOptions.java @@ -0,0 +1,62 @@ +package com.dfsek.terra.fabric.mixin; + +import com.dfsek.terra.config.pack.ConfigPack; +import com.dfsek.terra.fabric.TerraFabricPlugin; +import com.dfsek.terra.fabric.world.TerraBiomeSource; +import com.dfsek.terra.fabric.world.generator.FabricChunkGeneratorWrapper; +import com.google.common.base.MoreObjects; +import net.minecraft.util.registry.DynamicRegistryManager; +import net.minecraft.util.registry.Registry; +import net.minecraft.util.registry.SimpleRegistry; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.dimension.DimensionOptions; +import net.minecraft.world.dimension.DimensionType; +import net.minecraft.world.gen.GeneratorOptions; +import net.minecraft.world.gen.chunk.ChunkGeneratorSettings; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.Properties; +import java.util.Random; + +// Mixins commented out until loom fixes multi-project builds. + +//@Mixin(GeneratorOptions.class) +public class MixinGeneratorOptions { + //@Inject(method = "fromProperties(Lnet/minecraft/util/registry/DynamicRegistryManager;Ljava/util/Properties;)Lnet/minecraft/world/gen/GeneratorOptions;", at = @At("HEAD"), cancellable = true) + private static void fromProperties(DynamicRegistryManager dynamicRegistryManager, Properties properties, CallbackInfoReturnable cir) { + if(properties.get("level-type") == null) { + return; + } + + String prop = properties.get("level-type").toString().trim(); + if(prop.startsWith("Terra")) { + String seed = (String) MoreObjects.firstNonNull(properties.get("level-seed"), ""); + long l = new Random().nextLong(); + if(!seed.isEmpty()) { + try { + long m = Long.parseLong(seed); + if(m != 0L) { + l = m; + } + } catch(NumberFormatException exception) { + l = seed.hashCode(); + } + } + + String generate_structures = (String) properties.get("generate-structures"); + boolean generateStructures = generate_structures == null || Boolean.parseBoolean(generate_structures); + Registry dimensionTypes = dynamicRegistryManager.get(Registry.DIMENSION_TYPE_KEY); + Registry biomes = dynamicRegistryManager.get(Registry.BIOME_KEY); + Registry chunkGeneratorSettings = dynamicRegistryManager.get(Registry.NOISE_SETTINGS_WORLDGEN); + SimpleRegistry dimensionOptions = DimensionType.createDefaultDimensionOptions(dimensionTypes, biomes, chunkGeneratorSettings, l); + + prop = prop.substring(prop.indexOf(":") + 1); + + ConfigPack pack = TerraFabricPlugin.getInstance().getConfigRegistry().get(prop); + + if(pack == null) throw new IllegalArgumentException("No such pack " + prop); + + cir.setReturnValue(new GeneratorOptions(l, generateStructures, false, GeneratorOptions.method_28608(dimensionTypes, dimensionOptions, new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomes, l, pack), l, pack)))); + } + } +} From 0d58201e3f929b57b1318a008550c2bf587a3958 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 7 Mar 2021 23:44:19 -0700 Subject: [PATCH 54/95] mock command API --- .../terra/api/command/CommandManager.java | 9 ++ .../terra/api/command/CommandTemplate.java | 5 ++ .../terra/api/command/ExecutionState.java | 45 ++++++++++ .../api/command/TerraCommandManager.java | 85 +++++++++++++++++++ .../api/command/annotation/Argument.java | 16 ++++ .../terra/api/command/annotation/Command.java | 16 ++++ .../terra/api/command/annotation/Flag.java | 16 ++++ .../api/command/annotation/Subcommand.java | 18 ++++ .../dfsek/terra/commands/ReloadCommand.java | 13 +++ .../terra/commands/StructureCommand.java | 29 +++++++ .../structure/StructureExportCommand.java | 13 +++ .../structure/StructureLoadCommand.java | 25 ++++++ .../dfsek/terra/bukkit/command/Command.java | 9 +- .../terra/bukkit/command/PlayerCommand.java | 11 +-- 14 files changed, 301 insertions(+), 9 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/api/command/CommandManager.java create mode 100644 common/src/main/java/com/dfsek/terra/api/command/CommandTemplate.java create mode 100644 common/src/main/java/com/dfsek/terra/api/command/ExecutionState.java create mode 100644 common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java create mode 100644 common/src/main/java/com/dfsek/terra/api/command/annotation/Argument.java create mode 100644 common/src/main/java/com/dfsek/terra/api/command/annotation/Command.java create mode 100644 common/src/main/java/com/dfsek/terra/api/command/annotation/Flag.java create mode 100644 common/src/main/java/com/dfsek/terra/api/command/annotation/Subcommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/ReloadCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/StructureCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/structure/StructureExportCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java diff --git a/common/src/main/java/com/dfsek/terra/api/command/CommandManager.java b/common/src/main/java/com/dfsek/terra/api/command/CommandManager.java new file mode 100644 index 000000000..3f5bae579 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/CommandManager.java @@ -0,0 +1,9 @@ +package com.dfsek.terra.api.command; + +import java.util.List; + +public interface CommandManager { + void execute(String command, List args); + + void register(String name, Class clazz); +} diff --git a/common/src/main/java/com/dfsek/terra/api/command/CommandTemplate.java b/common/src/main/java/com/dfsek/terra/api/command/CommandTemplate.java new file mode 100644 index 000000000..bb01ab198 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/CommandTemplate.java @@ -0,0 +1,5 @@ +package com.dfsek.terra.api.command; + +public interface CommandTemplate { + void execute(ExecutionState state); +} diff --git a/common/src/main/java/com/dfsek/terra/api/command/ExecutionState.java b/common/src/main/java/com/dfsek/terra/api/command/ExecutionState.java new file mode 100644 index 000000000..515993a0b --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/ExecutionState.java @@ -0,0 +1,45 @@ +package com.dfsek.terra.api.command; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public final class ExecutionState { + private final Set flags = new HashSet<>(); + private final Map args = new HashMap<>(); + + protected ExecutionState() { + + } + + protected void addFlag(String flag) { + flags.add(flag); + } + + protected void addArgument(String arg, String value) { + args.put(arg, value); + } + + @SuppressWarnings("unchecked") + public T getArgument(String argument, Class clazz) { + + String value = args.get(argument); + if(value == null) throw new IllegalArgumentException("Argument \"" + argument + "\" does not exist!"); + + if(clazz == int.class || clazz == Integer.class) { + return (T) new Integer(Integer.parseInt(value)); + } + if(clazz == double.class || clazz == Double.class) { + return (T) new Double(Double.parseDouble(value)); + } + + // TODO: type loaders + + return (T) value; + } + + public boolean hasFlag(String flag) { + return flags.contains(flag); + } +} diff --git a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java new file mode 100644 index 000000000..6c7ebfe77 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java @@ -0,0 +1,85 @@ +package com.dfsek.terra.api.command; + +import com.dfsek.terra.api.command.annotation.Argument; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.Subcommand; + +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class TerraCommandManager implements CommandManager { + Map commands = new HashMap<>(); + + @Override + public void execute(String commandName, List args) { + + ExecutionState state = new ExecutionState(); + + CommandHolder commandHolder = commands.get(commandName); + Class commandClass = commandHolder.clazz; + + if(!commandClass.isAnnotationPresent(Command.class)) { + invoke(commandClass, state); + } + + Command command = commandClass.getAnnotation(Command.class); + + if(command.arguments().length == 0 && command.subcommands().length == 0) { + if(args.isEmpty()) invoke(commandClass, state); + else throw new IllegalArgumentException("Expected 0 arguments, found " + args.size()); + } + + if(commandHolder.subcommands.containsKey(args.get(0))) { + invoke(commandClass, state); + } + + + boolean req = true; + for(Argument argument : command.arguments()) { + if(!req && argument.required()) + throw new IllegalStateException("Required arguments must come first! Arguments: " + Arrays.toString(command.arguments())); + req = argument.required(); + + String arg = args.get(0); + + if(arg.startsWith("-")) { // flags have started. + + } + + } + } + + private void invoke(Class clazz, ExecutionState state) { + try { + clazz.getConstructor().newInstance().execute(state); + } catch(InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { + e.printStackTrace(); + } + } + + @Override + public void register(String name, Class clazz) { + commands.put(name, new CommandHolder(clazz)); + } + + private static final class CommandHolder { + private final Class clazz; + private final Map subcommands = new HashMap<>(); + + private CommandHolder(Class clazz) { + this.clazz = clazz; + if(clazz.isAnnotationPresent(Command.class)) { + Command command = clazz.getAnnotation(Command.class); + for(Subcommand subcommand : command.subcommands()) { + subcommands.put(subcommand.value(), subcommand); + for(String alias : subcommand.aliases()) { + subcommands.put(alias, subcommand); + } + } + } + } + } +} diff --git a/common/src/main/java/com/dfsek/terra/api/command/annotation/Argument.java b/common/src/main/java/com/dfsek/terra/api/command/annotation/Argument.java new file mode 100644 index 000000000..b020a03d3 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/annotation/Argument.java @@ -0,0 +1,16 @@ +package com.dfsek.terra.api.command.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.ANNOTATION_TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface Argument { + String value(); + + boolean required() default true; + + Class type() default String.class; +} diff --git a/common/src/main/java/com/dfsek/terra/api/command/annotation/Command.java b/common/src/main/java/com/dfsek/terra/api/command/annotation/Command.java new file mode 100644 index 000000000..5eebc1ec3 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/annotation/Command.java @@ -0,0 +1,16 @@ +package com.dfsek.terra.api.command.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface Command { + Argument[] arguments() default {}; + + Flag[] flags() default {}; + + Subcommand[] subcommands() default {}; +} diff --git a/common/src/main/java/com/dfsek/terra/api/command/annotation/Flag.java b/common/src/main/java/com/dfsek/terra/api/command/annotation/Flag.java new file mode 100644 index 000000000..836b0eb0f --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/annotation/Flag.java @@ -0,0 +1,16 @@ +package com.dfsek.terra.api.command.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.ANNOTATION_TYPE) +public @interface Flag { + String value(); + + String shorthand() default ""; + + String defaultValue() default ""; +} diff --git a/common/src/main/java/com/dfsek/terra/api/command/annotation/Subcommand.java b/common/src/main/java/com/dfsek/terra/api/command/annotation/Subcommand.java new file mode 100644 index 000000000..7f729ba0a --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/annotation/Subcommand.java @@ -0,0 +1,18 @@ +package com.dfsek.terra.api.command.annotation; + +import com.dfsek.terra.api.command.CommandTemplate; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.ANNOTATION_TYPE) +public @interface Subcommand { + String value(); + + String[] aliases() default {}; + + Class clazz(); +} diff --git a/common/src/main/java/com/dfsek/terra/commands/ReloadCommand.java b/common/src/main/java/com/dfsek/terra/commands/ReloadCommand.java new file mode 100644 index 000000000..119429dc6 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/ReloadCommand.java @@ -0,0 +1,13 @@ +package com.dfsek.terra.commands; + +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.ExecutionState; +import com.dfsek.terra.api.command.annotation.Command; + +@Command() +public class ReloadCommand implements CommandTemplate { + @Override + public void execute(ExecutionState state) { + + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/StructureCommand.java b/common/src/main/java/com/dfsek/terra/commands/StructureCommand.java new file mode 100644 index 000000000..a2d176ea7 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/StructureCommand.java @@ -0,0 +1,29 @@ +package com.dfsek.terra.commands; + +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.ExecutionState; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.Subcommand; +import com.dfsek.terra.commands.structure.StructureExportCommand; +import com.dfsek.terra.commands.structure.StructureLoadCommand; + +@Command( + subcommands = { + @Subcommand( + clazz = StructureExportCommand.class, + value = "export", + aliases = "ex" + ), + @Subcommand( + clazz = StructureLoadCommand.class, + value = "load", + aliases = "ld" + ) + } +) +public class StructureCommand implements CommandTemplate { + @Override + public void execute(ExecutionState state) { + + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/StructureExportCommand.java b/common/src/main/java/com/dfsek/terra/commands/structure/StructureExportCommand.java new file mode 100644 index 000000000..8d36c6c56 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/structure/StructureExportCommand.java @@ -0,0 +1,13 @@ +package com.dfsek.terra.commands.structure; + +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.ExecutionState; +import com.dfsek.terra.api.command.annotation.Command; + +@Command +public class StructureExportCommand implements CommandTemplate { + @Override + public void execute(ExecutionState state) { + + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java b/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java new file mode 100644 index 000000000..49ced1583 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java @@ -0,0 +1,25 @@ +package com.dfsek.terra.commands.structure; + +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.ExecutionState; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.Flag; + +@Command( + flags = { + @Flag(value = "rotation", + defaultValue = "0", + shorthand = "r" + ), + @Flag(value = "load", + defaultValue = "FULL", + shorthand = "l" + ) + } +) +public class StructureLoadCommand implements CommandTemplate { + @Override + public void execute(ExecutionState state) { + + } +} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/Command.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/Command.java index 93b1435ab..6fd8bbfee 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/Command.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/Command.java @@ -13,7 +13,7 @@ import java.util.Arrays; import java.util.List; /** - * Represents a command or subcommand, can be nested via getSubCommands. + * Represents a command or subcommands, can be nested via getSubCommands. */ public abstract class Command implements CommandExecutor, TabCompleter { private final TerraPlugin main; @@ -29,7 +29,8 @@ public abstract class Command implements CommandExecutor, TabCompleter { } /** - * Gets the name of the command/subcommand + * Gets the name of the command/subcommands + * * @return Name of command */ public abstract String getName(); @@ -47,7 +48,7 @@ public abstract class Command implements CommandExecutor, TabCompleter { * (if defined) will be sent to the player. * * @param sender Source of the command - * @param command Command which was executed + * @param command CommandTemplate which was executed * @param label Alias of the command which was used * @param args Passed command arguments * @return true if a valid command, otherwise false @@ -67,7 +68,7 @@ public abstract class Command implements CommandExecutor, TabCompleter { * (if defined) will be sent to the player. * * @param sender Source of the command - * @param command Command which was executed + * @param command CommandTemplate which was executed * @param label Alias of the command which was used * @param args Passed command arguments * @return true if a valid command, otherwise false diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/PlayerCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/PlayerCommand.java index 4f19eb741..cf52d897d 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/PlayerCommand.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/PlayerCommand.java @@ -19,10 +19,10 @@ public abstract class PlayerCommand extends Command { * If false is returned, then the "usage" plugin.yml entry for this command * (if defined) will be sent to the player. * - * @param sender Source of the command - * @param command Command which was executed - * @param label Alias of the command which was used - * @param args Passed command arguments + * @param sender Source of the command + * @param command CommandTemplate which was executed + * @param label Alias of the command which was used + * @param args Passed command arguments * @return true if a valid command, otherwise false */ @Override @@ -34,6 +34,7 @@ public abstract class PlayerCommand extends Command { Player p = (Player) sender; return execute(p, command, label, args); } + /** * Executes the given command, returning its success. *
@@ -41,7 +42,7 @@ public abstract class PlayerCommand extends Command { * (if defined) will be sent to the player. * * @param sender Player that executed command - * @param command Command which was executed + * @param command CommandTemplate which was executed * @param label Alias of the command which was used * @param args Passed command arguments * @return true if a valid command, otherwise false From c1b04d177235a20c2d0c2771383d3afb21077719 Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 8 Mar 2021 00:14:19 -0700 Subject: [PATCH 55/95] argument parsing --- .../terra/api/command/CommandManager.java | 4 +- .../api/command/TerraCommandManager.java | 32 ++++++-- .../terra/api/command/annotation/Command.java | 2 + .../command/exception/CommandException.java | 13 +++ .../exception/InvalidArgumentsException.java | 13 +++ .../exception/MalformedCommandException.java | 16 ++++ .../structure/StructureExportCommand.java | 2 +- common/src/test/java/command/CommandTest.java | 79 +++++++++++++++++++ 8 files changed, 151 insertions(+), 10 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/api/command/exception/CommandException.java create mode 100644 common/src/main/java/com/dfsek/terra/api/command/exception/InvalidArgumentsException.java create mode 100644 common/src/main/java/com/dfsek/terra/api/command/exception/MalformedCommandException.java create mode 100644 common/src/test/java/command/CommandTest.java diff --git a/common/src/main/java/com/dfsek/terra/api/command/CommandManager.java b/common/src/main/java/com/dfsek/terra/api/command/CommandManager.java index 3f5bae579..8caa03072 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/CommandManager.java +++ b/common/src/main/java/com/dfsek/terra/api/command/CommandManager.java @@ -1,9 +1,11 @@ package com.dfsek.terra.api.command; +import com.dfsek.terra.api.command.exception.CommandException; + import java.util.List; public interface CommandManager { - void execute(String command, List args); + void execute(String command, List args) throws CommandException; void register(String name, Class clazz); } diff --git a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java index 6c7ebfe77..18a13de68 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java +++ b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java @@ -3,19 +3,24 @@ package com.dfsek.terra.api.command; import com.dfsek.terra.api.command.annotation.Argument; import com.dfsek.terra.api.command.annotation.Command; import com.dfsek.terra.api.command.annotation.Subcommand; +import com.dfsek.terra.api.command.exception.CommandException; +import com.dfsek.terra.api.command.exception.InvalidArgumentsException; +import com.dfsek.terra.api.command.exception.MalformedCommandException; import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; public class TerraCommandManager implements CommandManager { - Map commands = new HashMap<>(); + private final Map commands = new HashMap<>(); @Override - public void execute(String commandName, List args) { + public void execute(String commandName, List argsIn) throws CommandException { + List args = new ArrayList<>(argsIn); ExecutionState state = new ExecutionState(); CommandHolder commandHolder = commands.get(commandName); @@ -29,34 +34,45 @@ public class TerraCommandManager implements CommandManager { if(command.arguments().length == 0 && command.subcommands().length == 0) { if(args.isEmpty()) invoke(commandClass, state); - else throw new IllegalArgumentException("Expected 0 arguments, found " + args.size()); + else throw new InvalidArgumentsException("Expected 0 arguments, found " + args.size()); } if(commandHolder.subcommands.containsKey(args.get(0))) { - invoke(commandClass, state); + invoke(commandHolder.subcommands.get(args.get(0)).clazz(), state); } boolean req = true; for(Argument argument : command.arguments()) { if(!req && argument.required()) - throw new IllegalStateException("Required arguments must come first! Arguments: " + Arrays.toString(command.arguments())); + throw new MalformedCommandException("Required arguments must come first! Arguments: " + Arrays.toString(command.arguments())); req = argument.required(); + if(args.isEmpty()) { + if(req) throw new InvalidArgumentsException("Invalid arguments: " + command.usage()); + break; + } + String arg = args.get(0); if(arg.startsWith("-")) { // flags have started. - + if(req) throw new InvalidArgumentsException("Flags must come after arguments."); + break; } + state.addArgument(argument.value(), args.remove(0)); } + + + invoke(commandClass, state); } - private void invoke(Class clazz, ExecutionState state) { + private void invoke(Class clazz, ExecutionState state) throws MalformedCommandException { try { + System.out.println("invocation"); clazz.getConstructor().newInstance().execute(state); } catch(InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { - e.printStackTrace(); + throw new MalformedCommandException("Unable to reflectively instantiate command: ", e); } } diff --git a/common/src/main/java/com/dfsek/terra/api/command/annotation/Command.java b/common/src/main/java/com/dfsek/terra/api/command/annotation/Command.java index 5eebc1ec3..01cd11e97 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/annotation/Command.java +++ b/common/src/main/java/com/dfsek/terra/api/command/annotation/Command.java @@ -13,4 +13,6 @@ public @interface Command { Flag[] flags() default {}; Subcommand[] subcommands() default {}; + + String usage() default ""; } diff --git a/common/src/main/java/com/dfsek/terra/api/command/exception/CommandException.java b/common/src/main/java/com/dfsek/terra/api/command/exception/CommandException.java new file mode 100644 index 000000000..3fd6537ef --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/exception/CommandException.java @@ -0,0 +1,13 @@ +package com.dfsek.terra.api.command.exception; + +public abstract class CommandException extends Exception { + private static final long serialVersionUID = -2955328495045879822L; + + public CommandException(String message) { + super(message); + } + + public CommandException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/common/src/main/java/com/dfsek/terra/api/command/exception/InvalidArgumentsException.java b/common/src/main/java/com/dfsek/terra/api/command/exception/InvalidArgumentsException.java new file mode 100644 index 000000000..5ad88d0b3 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/exception/InvalidArgumentsException.java @@ -0,0 +1,13 @@ +package com.dfsek.terra.api.command.exception; + +public class InvalidArgumentsException extends CommandException { + private static final long serialVersionUID = 7563619667472569824L; + + public InvalidArgumentsException(String message) { + super(message); + } + + public InvalidArgumentsException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/common/src/main/java/com/dfsek/terra/api/command/exception/MalformedCommandException.java b/common/src/main/java/com/dfsek/terra/api/command/exception/MalformedCommandException.java new file mode 100644 index 000000000..c124a8b85 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/exception/MalformedCommandException.java @@ -0,0 +1,16 @@ +package com.dfsek.terra.api.command.exception; + +/** + * Thrown when command is incorrectly defined. + */ +public class MalformedCommandException extends CommandException { + private static final long serialVersionUID = -5417760860407895496L; + + public MalformedCommandException(String message) { + super(message); + } + + public MalformedCommandException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/StructureExportCommand.java b/common/src/main/java/com/dfsek/terra/commands/structure/StructureExportCommand.java index 8d36c6c56..fa368668b 100644 --- a/common/src/main/java/com/dfsek/terra/commands/structure/StructureExportCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/structure/StructureExportCommand.java @@ -8,6 +8,6 @@ import com.dfsek.terra.api.command.annotation.Command; public class StructureExportCommand implements CommandTemplate { @Override public void execute(ExecutionState state) { - + System.out.println("export command"); } } diff --git a/common/src/test/java/command/CommandTest.java b/common/src/test/java/command/CommandTest.java new file mode 100644 index 000000000..41f37d22f --- /dev/null +++ b/common/src/test/java/command/CommandTest.java @@ -0,0 +1,79 @@ +package command; + +import com.dfsek.terra.api.command.CommandManager; +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.ExecutionState; +import com.dfsek.terra.api.command.TerraCommandManager; +import com.dfsek.terra.api.command.annotation.Argument; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.exception.CommandException; +import com.dfsek.terra.api.command.exception.MalformedCommandException; +import com.dfsek.terra.commands.StructureCommand; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; + +import static org.junit.jupiter.api.Assertions.fail; + +public class CommandTest { + @Test + public void subcommand() throws CommandException { + CommandManager manager = new TerraCommandManager(); + manager.register("structure", StructureCommand.class); + + manager.execute("structure", Arrays.asList("export")); + } + + @Test + public void args() throws CommandException { + CommandManager manager = new TerraCommandManager(); + manager.register("test", DemoCommand.class); + + manager.execute("test", Arrays.asList("first", "2")); + manager.execute("test", Arrays.asList("first", "2", "3.4")); + } + + @Test + public void requiredArgsFirst() throws CommandException { + CommandManager manager = new TerraCommandManager(); + manager.register("test", DemoInvalidCommand.class); + + try { + manager.execute("test", Arrays.asList("first", "2")); + fail(); + } catch(MalformedCommandException ignore) { + } + } + + @Command(arguments = { + @Argument(value = "arg0"), + @Argument(value = "arg1", type = int.class), + @Argument(value = "arg2", type = double.class, required = false) + }) + public static final class DemoCommand implements CommandTemplate { + + @Override + public void execute(ExecutionState state) { + System.out.println(state.getArgument("arg0", String.class)); + System.out.println(state.getArgument("arg1", String.class)); + try { + System.out.println(state.getArgument("arg2", String.class)); + } catch(IllegalArgumentException e) { + System.out.println("arg2 undefined."); + } + } + } + + @Command(arguments = { + @Argument(value = "arg0"), + @Argument(value = "arg2", type = double.class, required = false), // optional arguments must be last. this command is invalid. + @Argument(value = "arg1", type = int.class) + }) + public static final class DemoInvalidCommand implements CommandTemplate { + + @Override + public void execute(ExecutionState state) { + throw new Error("this should never be reached"); + } + } +} From a5d101ff615db8ef1feb609c58889271fd8da90d Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 8 Mar 2021 00:36:01 -0700 Subject: [PATCH 56/95] fix child command issues --- .../api/command/TerraCommandManager.java | 21 ++-- common/src/test/java/command/CommandTest.java | 103 +++++++++++++++--- 2 files changed, 102 insertions(+), 22 deletions(-) diff --git a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java index 18a13de68..f92b40ab4 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java +++ b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java @@ -19,11 +19,14 @@ public class TerraCommandManager implements CommandManager { @Override public void execute(String commandName, List argsIn) throws CommandException { + execute(commands.get(commandName), new ArrayList<>(argsIn)); + } + + private void execute(CommandHolder commandHolder, List args) throws CommandException { + List ogArgs = new ArrayList<>(args); - List args = new ArrayList<>(argsIn); ExecutionState state = new ExecutionState(); - CommandHolder commandHolder = commands.get(commandName); Class commandClass = commandHolder.clazz; if(!commandClass.isAnnotationPresent(Command.class)) { @@ -38,7 +41,10 @@ public class TerraCommandManager implements CommandManager { } if(commandHolder.subcommands.containsKey(args.get(0))) { - invoke(commandHolder.subcommands.get(args.get(0)).clazz(), state); + String c = args.get(0); + args.remove(0); + execute(commandHolder.subcommands.get(c), args); + return; } @@ -49,7 +55,7 @@ public class TerraCommandManager implements CommandManager { req = argument.required(); if(args.isEmpty()) { - if(req) throw new InvalidArgumentsException("Invalid arguments: " + command.usage()); + if(req) throw new InvalidArgumentsException("Invalid arguments: " + ogArgs + ", usage: " + command.usage()); break; } @@ -83,16 +89,17 @@ public class TerraCommandManager implements CommandManager { private static final class CommandHolder { private final Class clazz; - private final Map subcommands = new HashMap<>(); + private final Map subcommands = new HashMap<>(); private CommandHolder(Class clazz) { this.clazz = clazz; if(clazz.isAnnotationPresent(Command.class)) { Command command = clazz.getAnnotation(Command.class); for(Subcommand subcommand : command.subcommands()) { - subcommands.put(subcommand.value(), subcommand); + CommandHolder holder = new CommandHolder(subcommand.clazz()); + subcommands.put(subcommand.value(), holder); for(String alias : subcommand.aliases()) { - subcommands.put(alias, subcommand); + subcommands.put(alias, holder); } } } diff --git a/common/src/test/java/command/CommandTest.java b/common/src/test/java/command/CommandTest.java index 41f37d22f..d89d6a248 100644 --- a/common/src/test/java/command/CommandTest.java +++ b/common/src/test/java/command/CommandTest.java @@ -6,9 +6,10 @@ import com.dfsek.terra.api.command.ExecutionState; import com.dfsek.terra.api.command.TerraCommandManager; import com.dfsek.terra.api.command.annotation.Argument; import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.Subcommand; import com.dfsek.terra.api.command.exception.CommandException; +import com.dfsek.terra.api.command.exception.InvalidArgumentsException; import com.dfsek.terra.api.command.exception.MalformedCommandException; -import com.dfsek.terra.commands.StructureCommand; import org.junit.jupiter.api.Test; import java.util.Arrays; @@ -19,9 +20,14 @@ public class CommandTest { @Test public void subcommand() throws CommandException { CommandManager manager = new TerraCommandManager(); - manager.register("structure", StructureCommand.class); + manager.register("test", DemoParentCommand.class); - manager.execute("structure", Arrays.asList("export")); + manager.execute("test", Arrays.asList("subcommand1", "first", "2")); + manager.execute("test", Arrays.asList("subcommand2", "first", "2")); + manager.execute("test", Arrays.asList("s1", "first", "2", "3.4")); + manager.execute("test", Arrays.asList("s2", "first", "2")); + manager.execute("test", Arrays.asList("sub1", "first", "2", "3.4")); + manager.execute("test", Arrays.asList("sub2", "first", "2")); } @Test @@ -33,6 +39,18 @@ public class CommandTest { manager.execute("test", Arrays.asList("first", "2", "3.4")); } + @Test + public void argsBeforeFlags() throws CommandException { + CommandManager manager = new TerraCommandManager(); + manager.register("test", DemoCommand.class); + + try { + manager.execute("test", Arrays.asList("first", "-flag", "2")); + fail(); + } catch(InvalidArgumentsException ignore) { + } + } + @Test public void requiredArgsFirst() throws CommandException { CommandManager manager = new TerraCommandManager(); @@ -45,30 +63,32 @@ public class CommandTest { } } - @Command(arguments = { - @Argument(value = "arg0"), - @Argument(value = "arg1", type = int.class), - @Argument(value = "arg2", type = double.class, required = false) - }) + @Command( + arguments = { + @Argument(value = "arg0"), + @Argument(value = "arg1", type = int.class), + @Argument(value = "arg2", type = double.class, required = false) + }) public static final class DemoCommand implements CommandTemplate { @Override public void execute(ExecutionState state) { System.out.println(state.getArgument("arg0", String.class)); - System.out.println(state.getArgument("arg1", String.class)); + System.out.println(state.getArgument("arg1", int.class)); try { - System.out.println(state.getArgument("arg2", String.class)); + System.out.println(state.getArgument("arg2", double.class)); } catch(IllegalArgumentException e) { System.out.println("arg2 undefined."); } } } - @Command(arguments = { - @Argument(value = "arg0"), - @Argument(value = "arg2", type = double.class, required = false), // optional arguments must be last. this command is invalid. - @Argument(value = "arg1", type = int.class) - }) + @Command( + arguments = { + @Argument(value = "arg0"), + @Argument(value = "arg2", type = double.class, required = false), // optional arguments must be last. this command is invalid. + @Argument(value = "arg1", type = int.class) + }) public static final class DemoInvalidCommand implements CommandTemplate { @Override @@ -76,4 +96,57 @@ public class CommandTest { throw new Error("this should never be reached"); } } + + @Command( + arguments = { + @Argument(value = "arg0"), + @Argument(value = "arg1", type = int.class), + @Argument(value = "arg2", type = double.class, required = false), + }, + subcommands = { + @Subcommand( + value = "subcommand1", + aliases = {"s1", "sub1"}, + clazz = DemoChildCommand.class + ), + @Subcommand( + value = "subcommand2", + aliases = {"s2", "sub2"}, + clazz = DemoChildCommand.class // Duplicate command intentional. + ) + }) + public static final class DemoParentCommand implements CommandTemplate { + + @Override + public void execute(ExecutionState state) { + System.out.println("Parent command"); + System.out.println(state.getArgument("arg0", String.class)); + System.out.println(state.getArgument("arg1", int.class)); + try { + System.out.println(state.getArgument("arg2", double.class)); + } catch(IllegalArgumentException e) { + System.out.println("arg2 undefined."); + } + } + } + + @Command( + arguments = { + @Argument(value = "arg0"), + @Argument(value = "arg1", type = int.class), + @Argument(value = "arg2", type = double.class, required = false), + }) + public static final class DemoChildCommand implements CommandTemplate { + @Override + public void execute(ExecutionState state) { + System.out.println("Child command"); + System.out.println(state.getArgument("arg0", String.class)); + System.out.println(state.getArgument("arg1", int.class)); + try { + System.out.println(state.getArgument("arg2", double.class)); + } catch(IllegalArgumentException e) { + System.out.println("arg2 undefined."); + } + } + } } From 0cd58981079cf94de522bda390b71f48b8a41aa6 Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 8 Mar 2021 00:37:25 -0700 Subject: [PATCH 57/95] fix child command issues --- .../java/com/dfsek/terra/api/command/TerraCommandManager.java | 3 ++- common/src/test/java/command/CommandTest.java | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java index f92b40ab4..3a89936a1 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java +++ b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java @@ -50,8 +50,9 @@ public class TerraCommandManager implements CommandManager { boolean req = true; for(Argument argument : command.arguments()) { - if(!req && argument.required()) + if(!req && argument.required()) { throw new MalformedCommandException("Required arguments must come first! Arguments: " + Arrays.toString(command.arguments())); + } req = argument.required(); if(args.isEmpty()) { diff --git a/common/src/test/java/command/CommandTest.java b/common/src/test/java/command/CommandTest.java index d89d6a248..4c2a7c987 100644 --- a/common/src/test/java/command/CommandTest.java +++ b/common/src/test/java/command/CommandTest.java @@ -28,6 +28,7 @@ public class CommandTest { manager.execute("test", Arrays.asList("s2", "first", "2")); manager.execute("test", Arrays.asList("sub1", "first", "2", "3.4")); manager.execute("test", Arrays.asList("sub2", "first", "2")); + manager.execute("test", Arrays.asList("first", "2")); // Parent command args } @Test From 026a6066d3c69487f29a41dc7a709dd9345cfada Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 8 Mar 2021 00:52:57 -0700 Subject: [PATCH 58/95] implement switches --- .../terra/api/command/ExecutionState.java | 10 ++-- .../api/command/TerraCommandManager.java | 24 +++++++++- .../terra/api/command/annotation/Command.java | 2 +- .../annotation/{Flag.java => Switch.java} | 6 +-- .../exception/SwitchFormatException.java | 13 +++++ .../structure/StructureLoadCommand.java | 21 +++++---- common/src/test/java/command/CommandTest.java | 47 +++++++++++++++++++ 7 files changed, 102 insertions(+), 21 deletions(-) rename common/src/main/java/com/dfsek/terra/api/command/annotation/{Flag.java => Switch.java} (75%) create mode 100644 common/src/main/java/com/dfsek/terra/api/command/exception/SwitchFormatException.java diff --git a/common/src/main/java/com/dfsek/terra/api/command/ExecutionState.java b/common/src/main/java/com/dfsek/terra/api/command/ExecutionState.java index 515993a0b..b1665ff90 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/ExecutionState.java +++ b/common/src/main/java/com/dfsek/terra/api/command/ExecutionState.java @@ -6,15 +6,15 @@ import java.util.Map; import java.util.Set; public final class ExecutionState { - private final Set flags = new HashSet<>(); + private final Set switches = new HashSet<>(); private final Map args = new HashMap<>(); protected ExecutionState() { } - protected void addFlag(String flag) { - flags.add(flag); + protected void addSwitch(String flag) { + switches.add(flag); } protected void addArgument(String arg, String value) { @@ -39,7 +39,7 @@ public final class ExecutionState { return (T) value; } - public boolean hasFlag(String flag) { - return flags.contains(flag); + public boolean hasSwitch(String flag) { + return switches.contains(flag); } } diff --git a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java index 3a89936a1..57360bb0e 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java +++ b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java @@ -3,9 +3,11 @@ package com.dfsek.terra.api.command; import com.dfsek.terra.api.command.annotation.Argument; import com.dfsek.terra.api.command.annotation.Command; import com.dfsek.terra.api.command.annotation.Subcommand; +import com.dfsek.terra.api.command.annotation.Switch; import com.dfsek.terra.api.command.exception.CommandException; import com.dfsek.terra.api.command.exception.InvalidArgumentsException; import com.dfsek.terra.api.command.exception.MalformedCommandException; +import com.dfsek.terra.api.command.exception.SwitchFormatException; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; @@ -62,14 +64,25 @@ public class TerraCommandManager implements CommandManager { String arg = args.get(0); - if(arg.startsWith("-")) { // flags have started. - if(req) throw new InvalidArgumentsException("Flags must come after arguments."); + if(arg.startsWith("-")) { // switches have started. + if(req) throw new InvalidArgumentsException("Switches must come after arguments."); break; } state.addArgument(argument.value(), args.remove(0)); } + while(!args.isEmpty()) { + String aSwitch = args.remove(0); + if(!aSwitch.startsWith("-")) throw new SwitchFormatException("Invalid switch \"" + aSwitch + "\""); + + String val = aSwitch.substring(1); // remove dash + + if(!commandHolder.switches.containsKey(val)) throw new SwitchFormatException("No such switch \"" + aSwitch + "\""); + + state.addSwitch(commandHolder.switches.get(val)); + } + invoke(commandClass, state); } @@ -91,6 +104,7 @@ public class TerraCommandManager implements CommandManager { private static final class CommandHolder { private final Class clazz; private final Map subcommands = new HashMap<>(); + private final Map switches = new HashMap<>(); private CommandHolder(Class clazz) { this.clazz = clazz; @@ -103,6 +117,12 @@ public class TerraCommandManager implements CommandManager { subcommands.put(alias, holder); } } + for(Switch aSwitch : command.switches()) { + switches.put(aSwitch.value(), aSwitch.value()); + for(String alias : aSwitch.aliases()) { + switches.put(alias, aSwitch.value()); + } + } } } } diff --git a/common/src/main/java/com/dfsek/terra/api/command/annotation/Command.java b/common/src/main/java/com/dfsek/terra/api/command/annotation/Command.java index 01cd11e97..fb5fd81ea 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/annotation/Command.java +++ b/common/src/main/java/com/dfsek/terra/api/command/annotation/Command.java @@ -10,7 +10,7 @@ import java.lang.annotation.Target; public @interface Command { Argument[] arguments() default {}; - Flag[] flags() default {}; + Switch[] switches() default {}; Subcommand[] subcommands() default {}; diff --git a/common/src/main/java/com/dfsek/terra/api/command/annotation/Flag.java b/common/src/main/java/com/dfsek/terra/api/command/annotation/Switch.java similarity index 75% rename from common/src/main/java/com/dfsek/terra/api/command/annotation/Flag.java rename to common/src/main/java/com/dfsek/terra/api/command/annotation/Switch.java index 836b0eb0f..16ea3e21a 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/annotation/Flag.java +++ b/common/src/main/java/com/dfsek/terra/api/command/annotation/Switch.java @@ -7,10 +7,8 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.ANNOTATION_TYPE) -public @interface Flag { +public @interface Switch { String value(); - String shorthand() default ""; - - String defaultValue() default ""; + String[] aliases() default {}; } diff --git a/common/src/main/java/com/dfsek/terra/api/command/exception/SwitchFormatException.java b/common/src/main/java/com/dfsek/terra/api/command/exception/SwitchFormatException.java new file mode 100644 index 000000000..c7e545ae7 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/exception/SwitchFormatException.java @@ -0,0 +1,13 @@ +package com.dfsek.terra.api.command.exception; + +public class SwitchFormatException extends CommandException { + private static final long serialVersionUID = -965858989317844628L; + + public SwitchFormatException(String message) { + super(message); + } + + public SwitchFormatException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java b/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java index 49ced1583..9182b5bbe 100644 --- a/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java @@ -2,18 +2,21 @@ package com.dfsek.terra.commands.structure; import com.dfsek.terra.api.command.CommandTemplate; import com.dfsek.terra.api.command.ExecutionState; +import com.dfsek.terra.api.command.annotation.Argument; import com.dfsek.terra.api.command.annotation.Command; -import com.dfsek.terra.api.command.annotation.Flag; +import com.dfsek.terra.api.command.annotation.Switch; @Command( - flags = { - @Flag(value = "rotation", - defaultValue = "0", - shorthand = "r" - ), - @Flag(value = "load", - defaultValue = "FULL", - shorthand = "l" + arguments = { + @Argument( + value = "rotation", + required = false, + type = int.class + ) + }, + switches = { + @Switch(value = "chunk", + aliases = "c" ) } ) diff --git a/common/src/test/java/command/CommandTest.java b/common/src/test/java/command/CommandTest.java index 4c2a7c987..1a7df8ccf 100644 --- a/common/src/test/java/command/CommandTest.java +++ b/common/src/test/java/command/CommandTest.java @@ -7,6 +7,7 @@ import com.dfsek.terra.api.command.TerraCommandManager; import com.dfsek.terra.api.command.annotation.Argument; import com.dfsek.terra.api.command.annotation.Command; import com.dfsek.terra.api.command.annotation.Subcommand; +import com.dfsek.terra.api.command.annotation.Switch; import com.dfsek.terra.api.command.exception.CommandException; import com.dfsek.terra.api.command.exception.InvalidArgumentsException; import com.dfsek.terra.api.command.exception.MalformedCommandException; @@ -64,6 +65,24 @@ public class CommandTest { } } + @Test + public void switches() throws CommandException { + CommandManager manager = new TerraCommandManager(); + manager.register("test", DemoSwitchCommand.class); + + manager.execute("test", Arrays.asList("first", "2")); + manager.execute("test", Arrays.asList("first", "2", "3.4")); + + manager.execute("test", Arrays.asList("first", "2", "-a")); + manager.execute("test", Arrays.asList("first", "2", "3.4", "-b")); + + manager.execute("test", Arrays.asList("first", "2", "-aSwitch")); + manager.execute("test", Arrays.asList("first", "2", "3.4", "-bSwitch")); + + manager.execute("test", Arrays.asList("first", "2", "-aSwitch", "-b")); + manager.execute("test", Arrays.asList("first", "2", "3.4", "-bSwitch", "-a")); + } + @Command( arguments = { @Argument(value = "arg0"), @@ -84,6 +103,34 @@ public class CommandTest { } } + @Command( + arguments = { + @Argument(value = "arg0"), + @Argument(value = "arg1", type = int.class), + @Argument(value = "arg2", type = double.class, required = false) + }, + switches = { + @Switch(value = "a", aliases = {"aSwitch"}), + @Switch(value = "b", aliases = {"bSwitch"}) + } + ) + public static final class DemoSwitchCommand implements CommandTemplate { + + @Override + public void execute(ExecutionState state) { + System.out.println(state.getArgument("arg0", String.class)); + System.out.println(state.getArgument("arg1", int.class)); + try { + System.out.println(state.getArgument("arg2", double.class)); + } catch(IllegalArgumentException e) { + System.out.println("arg2 undefined."); + } + + System.out.println("A: " + state.hasSwitch("a")); + System.out.println("B: " + state.hasSwitch("b")); + } + } + @Command( arguments = { @Argument(value = "arg0"), From b1256427a2fdb7f23f63f4058c0369ad7a33bb04 Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 8 Mar 2021 01:40:12 -0700 Subject: [PATCH 59/95] basic bukkit implementation --- .../terra/api/command/CommandManager.java | 3 +- .../terra/api/command/ExecutionState.java | 11 ++- .../api/command/TerraCommandManager.java | 68 +++++++++++++++---- .../command/annotation/type/DebugCommand.java | 14 ++++ .../annotation/type/PlayerCommand.java | 14 ++++ .../command/annotation/type/WorldCommand.java | 14 ++++ .../terra/api/platform/entity/Entity.java | 3 + .../commands/profiler/ProfileCommand.java | 28 ++++++++ .../profiler/ProfileQueryCommand.java | 28 ++++++++ .../profiler/ProfileResetCommand.java | 29 ++++++++ .../profiler/ProfileStartCommand.java | 29 ++++++++ .../commands/profiler/ProfileStopCommand.java | 29 ++++++++ common/src/test/java/command/CommandTest.java | 60 ++++++++-------- .../com/dfsek/terra/bukkit/BukkitEntity.java | 6 ++ .../com/dfsek/terra/bukkit/BukkitPlayer.java | 6 ++ .../dfsek/terra/bukkit/TerraBukkitPlugin.java | 22 +++--- .../bukkit/command/BukkitCommandAdapter.java | 36 ++++++++++ .../terra/bukkit/world/BukkitAdapter.java | 4 ++ .../fabric/world/entity/FabricEntity.java | 6 ++ 19 files changed, 356 insertions(+), 54 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/api/command/annotation/type/DebugCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/api/command/annotation/type/PlayerCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/api/command/annotation/type/WorldCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/profiler/ProfileCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/profiler/ProfileQueryCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/profiler/ProfileResetCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/profiler/ProfileStartCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/profiler/ProfileStopCommand.java create mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/BukkitCommandAdapter.java diff --git a/common/src/main/java/com/dfsek/terra/api/command/CommandManager.java b/common/src/main/java/com/dfsek/terra/api/command/CommandManager.java index 8caa03072..e46517e7d 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/CommandManager.java +++ b/common/src/main/java/com/dfsek/terra/api/command/CommandManager.java @@ -1,11 +1,12 @@ package com.dfsek.terra.api.command; import com.dfsek.terra.api.command.exception.CommandException; +import com.dfsek.terra.api.platform.CommandSender; import java.util.List; public interface CommandManager { - void execute(String command, List args) throws CommandException; + void execute(String command, CommandSender sender, List args) throws CommandException; void register(String name, Class clazz); } diff --git a/common/src/main/java/com/dfsek/terra/api/command/ExecutionState.java b/common/src/main/java/com/dfsek/terra/api/command/ExecutionState.java index b1665ff90..2a57b73a6 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/ExecutionState.java +++ b/common/src/main/java/com/dfsek/terra/api/command/ExecutionState.java @@ -1,5 +1,7 @@ package com.dfsek.terra.api.command; +import com.dfsek.terra.api.platform.CommandSender; + import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -8,9 +10,10 @@ import java.util.Set; public final class ExecutionState { private final Set switches = new HashSet<>(); private final Map args = new HashMap<>(); + private final CommandSender sender; - protected ExecutionState() { - + protected ExecutionState(CommandSender sender) { + this.sender = sender; } protected void addSwitch(String flag) { @@ -42,4 +45,8 @@ public final class ExecutionState { public boolean hasSwitch(String flag) { return switches.contains(flag); } + + public CommandSender getSender() { + return sender; + } } diff --git a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java index 57360bb0e..b7b57f818 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java +++ b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java @@ -1,13 +1,22 @@ package com.dfsek.terra.api.command; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.command.annotation.Argument; import com.dfsek.terra.api.command.annotation.Command; import com.dfsek.terra.api.command.annotation.Subcommand; import com.dfsek.terra.api.command.annotation.Switch; +import com.dfsek.terra.api.command.annotation.type.DebugCommand; +import com.dfsek.terra.api.command.annotation.type.PlayerCommand; +import com.dfsek.terra.api.command.annotation.type.WorldCommand; import com.dfsek.terra.api.command.exception.CommandException; import com.dfsek.terra.api.command.exception.InvalidArgumentsException; import com.dfsek.terra.api.command.exception.MalformedCommandException; import com.dfsek.terra.api.command.exception.SwitchFormatException; +import com.dfsek.terra.api.injection.Injector; +import com.dfsek.terra.api.injection.exception.InjectionException; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.world.TerraWorld; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; @@ -18,38 +27,63 @@ import java.util.Map; public class TerraCommandManager implements CommandManager { private final Map commands = new HashMap<>(); + private final Injector pluginInjector; + private final TerraPlugin main; - @Override - public void execute(String commandName, List argsIn) throws CommandException { - execute(commands.get(commandName), new ArrayList<>(argsIn)); + public TerraCommandManager(TerraPlugin main) { + this.main = main; + this.pluginInjector = new Injector<>(main); + pluginInjector.addExplicitTarget(TerraPlugin.class); } - private void execute(CommandHolder commandHolder, List args) throws CommandException { + @Override + public void execute(String commandName, CommandSender sender, List argsIn) throws CommandException { + execute(commands.get(commandName), sender, new ArrayList<>(argsIn)); + } + + private void execute(CommandHolder commandHolder, CommandSender sender, List args) throws CommandException { + Class commandClass = commandHolder.clazz; + + if(commandClass.isAnnotationPresent(DebugCommand.class) && !main.isDebug()) { + sender.sendMessage("Command must be executed with debug mode enabled."); + return; + } + + if(commandClass.isAnnotationPresent(PlayerCommand.class) && !(sender instanceof Player)) { + sender.sendMessage("Command must be executed by player."); + return; + } + + if(commandClass.isAnnotationPresent(WorldCommand.class) && (!(sender instanceof Player) || !TerraWorld.isTerraWorld(((Player) sender).getWorld()))) { + sender.sendMessage("Command must be executed in a Terra world."); + return; + } + List ogArgs = new ArrayList<>(args); - ExecutionState state = new ExecutionState(); - - Class commandClass = commandHolder.clazz; + ExecutionState state = new ExecutionState(sender); if(!commandClass.isAnnotationPresent(Command.class)) { invoke(commandClass, state); + return; } Command command = commandClass.getAnnotation(Command.class); if(command.arguments().length == 0 && command.subcommands().length == 0) { - if(args.isEmpty()) invoke(commandClass, state); - else throw new InvalidArgumentsException("Expected 0 arguments, found " + args.size()); + if(args.isEmpty()) { + invoke(commandClass, state); + return; + } else throw new InvalidArgumentsException("Expected 0 arguments, found " + args.size()); } if(commandHolder.subcommands.containsKey(args.get(0))) { String c = args.get(0); args.remove(0); - execute(commandHolder.subcommands.get(c), args); + execute(commandHolder.subcommands.get(c), sender, args); return; } - boolean req = true; for(Argument argument : command.arguments()) { if(!req && argument.required()) { @@ -83,15 +117,18 @@ public class TerraCommandManager implements CommandManager { state.addSwitch(commandHolder.switches.get(val)); } - invoke(commandClass, state); } private void invoke(Class clazz, ExecutionState state) throws MalformedCommandException { try { System.out.println("invocation"); - clazz.getConstructor().newInstance().execute(state); - } catch(InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { + CommandTemplate template = clazz.getConstructor().newInstance(); + + pluginInjector.inject(template); + + template.execute(state); + } catch(InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | InjectionException e) { throw new MalformedCommandException("Unable to reflectively instantiate command: ", e); } } @@ -101,6 +138,9 @@ public class TerraCommandManager implements CommandManager { commands.put(name, new CommandHolder(clazz)); } + /** + * Pre-processes command metadata. + */ private static final class CommandHolder { private final Class clazz; private final Map subcommands = new HashMap<>(); diff --git a/common/src/main/java/com/dfsek/terra/api/command/annotation/type/DebugCommand.java b/common/src/main/java/com/dfsek/terra/api/command/annotation/type/DebugCommand.java new file mode 100644 index 000000000..174710401 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/annotation/type/DebugCommand.java @@ -0,0 +1,14 @@ +package com.dfsek.terra.api.command.annotation.type; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Command may only be executed with debug mode enabled. + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface DebugCommand { +} diff --git a/common/src/main/java/com/dfsek/terra/api/command/annotation/type/PlayerCommand.java b/common/src/main/java/com/dfsek/terra/api/command/annotation/type/PlayerCommand.java new file mode 100644 index 000000000..fd7b1e320 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/annotation/type/PlayerCommand.java @@ -0,0 +1,14 @@ +package com.dfsek.terra.api.command.annotation.type; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Marks command as player-only + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface PlayerCommand { +} diff --git a/common/src/main/java/com/dfsek/terra/api/command/annotation/type/WorldCommand.java b/common/src/main/java/com/dfsek/terra/api/command/annotation/type/WorldCommand.java new file mode 100644 index 000000000..c51ee570b --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/annotation/type/WorldCommand.java @@ -0,0 +1,14 @@ +package com.dfsek.terra.api.command.annotation.type; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Command may only be executed in a Terra world. + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface WorldCommand { +} diff --git a/common/src/main/java/com/dfsek/terra/api/platform/entity/Entity.java b/common/src/main/java/com/dfsek/terra/api/platform/entity/Entity.java index e69ffbcbc..692ae6498 100644 --- a/common/src/main/java/com/dfsek/terra/api/platform/entity/Entity.java +++ b/common/src/main/java/com/dfsek/terra/api/platform/entity/Entity.java @@ -3,7 +3,10 @@ package com.dfsek.terra.api.platform.entity; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.CommandSender; import com.dfsek.terra.api.platform.Handle; +import com.dfsek.terra.api.platform.world.World; public interface Entity extends Handle, CommandSender { Location getLocation(); + + World getWorld(); } diff --git a/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileCommand.java b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileCommand.java new file mode 100644 index 000000000..b5bd9d270 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileCommand.java @@ -0,0 +1,28 @@ +package com.dfsek.terra.commands.profiler; + +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.ExecutionState; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.Subcommand; +import com.dfsek.terra.api.command.annotation.type.DebugCommand; +import com.dfsek.terra.api.command.annotation.type.PlayerCommand; +import com.dfsek.terra.api.command.annotation.type.WorldCommand; + +@Command( + subcommands = { + @Subcommand(value = "query", aliases = {"q"}, clazz = ProfileQueryCommand.class), + @Subcommand(value = "start", aliases = {"s"}, clazz = ProfileStartCommand.class), + @Subcommand(value = "stop", aliases = {"st"}, clazz = ProfileStopCommand.class), + @Subcommand(value = "reset", aliases = {"r"}, clazz = ProfileResetCommand.class) + }, + usage = "Commands to enable/disable/query/reset the profiler." +) +@WorldCommand +@PlayerCommand +@DebugCommand +public class ProfileCommand implements CommandTemplate { + @Override + public void execute(ExecutionState state) { + + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileQueryCommand.java b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileQueryCommand.java new file mode 100644 index 000000000..b0004799f --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileQueryCommand.java @@ -0,0 +1,28 @@ +package com.dfsek.terra.commands.profiler; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.ExecutionState; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.type.DebugCommand; +import com.dfsek.terra.api.command.annotation.type.PlayerCommand; +import com.dfsek.terra.api.command.annotation.type.WorldCommand; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.world.TerraWorld; + +@Command +@WorldCommand +@PlayerCommand +@DebugCommand +public class ProfileQueryCommand implements CommandTemplate { + @Inject + private TerraPlugin main; + + @Override + public void execute(ExecutionState state) { + Player player = (Player) state.getSender(); + TerraWorld world = main.getWorld(player.getWorld()); + state.getSender().sendMessage(world.getProfiler().getResultsFormatted()); + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileResetCommand.java b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileResetCommand.java new file mode 100644 index 000000000..4d2349291 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileResetCommand.java @@ -0,0 +1,29 @@ +package com.dfsek.terra.commands.profiler; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.ExecutionState; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.type.DebugCommand; +import com.dfsek.terra.api.command.annotation.type.PlayerCommand; +import com.dfsek.terra.api.command.annotation.type.WorldCommand; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.world.TerraWorld; + +@Command +@WorldCommand +@PlayerCommand +@DebugCommand +public class ProfileResetCommand implements CommandTemplate { + @Inject + private TerraPlugin main; + + @Override + public void execute(ExecutionState state) { + Player player = (Player) state.getSender(); + TerraWorld world = main.getWorld(player.getWorld()); + world.getProfiler().reset(); + state.getSender().sendMessage("Profiler reset."); + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileStartCommand.java b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileStartCommand.java new file mode 100644 index 000000000..bb42588a1 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileStartCommand.java @@ -0,0 +1,29 @@ +package com.dfsek.terra.commands.profiler; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.ExecutionState; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.type.DebugCommand; +import com.dfsek.terra.api.command.annotation.type.PlayerCommand; +import com.dfsek.terra.api.command.annotation.type.WorldCommand; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.world.TerraWorld; + +@Command +@WorldCommand +@PlayerCommand +@DebugCommand +public class ProfileStartCommand implements CommandTemplate { + @Inject + private TerraPlugin main; + + @Override + public void execute(ExecutionState state) { + Player player = (Player) state.getSender(); + TerraWorld world = main.getWorld(player.getWorld()); + world.getProfiler().setProfiling(true); + state.getSender().sendMessage("Profiling enabled."); + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileStopCommand.java b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileStopCommand.java new file mode 100644 index 000000000..67b0537d4 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileStopCommand.java @@ -0,0 +1,29 @@ +package com.dfsek.terra.commands.profiler; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.ExecutionState; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.type.DebugCommand; +import com.dfsek.terra.api.command.annotation.type.PlayerCommand; +import com.dfsek.terra.api.command.annotation.type.WorldCommand; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.world.TerraWorld; + +@Command +@WorldCommand +@PlayerCommand +@DebugCommand +public class ProfileStopCommand implements CommandTemplate { + @Inject + private TerraPlugin main; + + @Override + public void execute(ExecutionState state) { + Player player = (Player) state.getSender(); + TerraWorld world = main.getWorld(player.getWorld()); + world.getProfiler().setProfiling(false); + state.getSender().sendMessage("Profiling enabled."); + } +} diff --git a/common/src/test/java/command/CommandTest.java b/common/src/test/java/command/CommandTest.java index 1a7df8ccf..42a419c49 100644 --- a/common/src/test/java/command/CommandTest.java +++ b/common/src/test/java/command/CommandTest.java @@ -20,34 +20,34 @@ import static org.junit.jupiter.api.Assertions.fail; public class CommandTest { @Test public void subcommand() throws CommandException { - CommandManager manager = new TerraCommandManager(); + CommandManager manager = new TerraCommandManager(null); manager.register("test", DemoParentCommand.class); - manager.execute("test", Arrays.asList("subcommand1", "first", "2")); - manager.execute("test", Arrays.asList("subcommand2", "first", "2")); - manager.execute("test", Arrays.asList("s1", "first", "2", "3.4")); - manager.execute("test", Arrays.asList("s2", "first", "2")); - manager.execute("test", Arrays.asList("sub1", "first", "2", "3.4")); - manager.execute("test", Arrays.asList("sub2", "first", "2")); - manager.execute("test", Arrays.asList("first", "2")); // Parent command args + manager.execute("test", null, Arrays.asList("subcommand1", "first", "2")); + manager.execute("test", null, Arrays.asList("subcommand2", "first", "2")); + manager.execute("test", null, Arrays.asList("s1", "first", "2", "3.4")); + manager.execute("test", null, Arrays.asList("s2", "first", "2")); + manager.execute("test", null, Arrays.asList("sub1", "first", "2", "3.4")); + manager.execute("test", null, Arrays.asList("sub2", "first", "2")); + manager.execute("test", null, Arrays.asList("first", "2")); // Parent command args } @Test public void args() throws CommandException { - CommandManager manager = new TerraCommandManager(); + CommandManager manager = new TerraCommandManager(null); manager.register("test", DemoCommand.class); - manager.execute("test", Arrays.asList("first", "2")); - manager.execute("test", Arrays.asList("first", "2", "3.4")); + manager.execute("test", null, Arrays.asList("first", "2")); + manager.execute("test", null, Arrays.asList("first", "2", "3.4")); } @Test public void argsBeforeFlags() throws CommandException { - CommandManager manager = new TerraCommandManager(); + CommandManager manager = new TerraCommandManager(null); manager.register("test", DemoCommand.class); try { - manager.execute("test", Arrays.asList("first", "-flag", "2")); + manager.execute("test", null, Arrays.asList("first", "-flag", "2")); fail(); } catch(InvalidArgumentsException ignore) { } @@ -55,11 +55,11 @@ public class CommandTest { @Test public void requiredArgsFirst() throws CommandException { - CommandManager manager = new TerraCommandManager(); + CommandManager manager = new TerraCommandManager(null); manager.register("test", DemoInvalidCommand.class); try { - manager.execute("test", Arrays.asList("first", "2")); + manager.execute("test", null, Arrays.asList("first", "2")); fail(); } catch(MalformedCommandException ignore) { } @@ -67,20 +67,20 @@ public class CommandTest { @Test public void switches() throws CommandException { - CommandManager manager = new TerraCommandManager(); + CommandManager manager = new TerraCommandManager(null); manager.register("test", DemoSwitchCommand.class); - manager.execute("test", Arrays.asList("first", "2")); - manager.execute("test", Arrays.asList("first", "2", "3.4")); + manager.execute("test", null, Arrays.asList("first", "2")); + manager.execute("test", null, Arrays.asList("first", "2", "3.4")); - manager.execute("test", Arrays.asList("first", "2", "-a")); - manager.execute("test", Arrays.asList("first", "2", "3.4", "-b")); + manager.execute("test", null, Arrays.asList("first", "2", "-a")); + manager.execute("test", null, Arrays.asList("first", "2", "3.4", "-b")); - manager.execute("test", Arrays.asList("first", "2", "-aSwitch")); - manager.execute("test", Arrays.asList("first", "2", "3.4", "-bSwitch")); + manager.execute("test", null, Arrays.asList("first", "2", "-aSwitch")); + manager.execute("test", null, Arrays.asList("first", "2", "3.4", "-bSwitch")); - manager.execute("test", Arrays.asList("first", "2", "-aSwitch", "-b")); - manager.execute("test", Arrays.asList("first", "2", "3.4", "-bSwitch", "-a")); + manager.execute("test", null, Arrays.asList("first", "2", "-aSwitch", "-b")); + manager.execute("test", null, Arrays.asList("first", "2", "3.4", "-bSwitch", "-a")); } @Command( @@ -88,7 +88,8 @@ public class CommandTest { @Argument(value = "arg0"), @Argument(value = "arg1", type = int.class), @Argument(value = "arg2", type = double.class, required = false) - }) + } + ) public static final class DemoCommand implements CommandTemplate { @Override @@ -136,7 +137,8 @@ public class CommandTest { @Argument(value = "arg0"), @Argument(value = "arg2", type = double.class, required = false), // optional arguments must be last. this command is invalid. @Argument(value = "arg1", type = int.class) - }) + } + ) public static final class DemoInvalidCommand implements CommandTemplate { @Override @@ -162,7 +164,8 @@ public class CommandTest { aliases = {"s2", "sub2"}, clazz = DemoChildCommand.class // Duplicate command intentional. ) - }) + } + ) public static final class DemoParentCommand implements CommandTemplate { @Override @@ -183,7 +186,8 @@ public class CommandTest { @Argument(value = "arg0"), @Argument(value = "arg1", type = int.class), @Argument(value = "arg2", type = double.class, required = false), - }) + } + ) public static final class DemoChildCommand implements CommandTemplate { @Override public void execute(ExecutionState state) { diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitEntity.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitEntity.java index 8d70cfa10..bb20cda6f 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitEntity.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitEntity.java @@ -2,6 +2,7 @@ package com.dfsek.terra.bukkit; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.entity.Entity; +import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.bukkit.world.BukkitAdapter; public class BukkitEntity implements Entity { @@ -21,6 +22,11 @@ public class BukkitEntity implements Entity { return BukkitAdapter.adapt(entity.getLocation()); } + @Override + public World getWorld() { + return BukkitAdapter.adapt(entity.getWorld()); + } + @Override public void sendMessage(String message) { entity.sendMessage(message); diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitPlayer.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitPlayer.java index 162e41131..fbf763e6b 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitPlayer.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitPlayer.java @@ -2,6 +2,7 @@ package com.dfsek.terra.bukkit; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.bukkit.world.BukkitAdapter; public class BukkitPlayer implements Player { @@ -22,6 +23,11 @@ public class BukkitPlayer implements Player { return new Location(BukkitAdapter.adapt(bukkit.getWorld()), bukkit.getX(), bukkit.getY(), bukkit.getZ()); } + @Override + public World getWorld() { + return BukkitAdapter.adapt(delegate.getWorld()); + } + @Override public void sendMessage(String message) { delegate.sendMessage(message); diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java index eec52f7fb..87fd760d5 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java @@ -6,6 +6,8 @@ import com.dfsek.terra.api.addons.TerraAddon; import com.dfsek.terra.api.addons.annotations.Addon; import com.dfsek.terra.api.addons.annotations.Author; import com.dfsek.terra.api.addons.annotations.Version; +import com.dfsek.terra.api.command.CommandManager; +import com.dfsek.terra.api.command.TerraCommandManager; import com.dfsek.terra.api.event.EventManager; import com.dfsek.terra.api.event.TerraEventManager; import com.dfsek.terra.api.platform.block.BlockData; @@ -19,8 +21,7 @@ import com.dfsek.terra.api.util.logging.DebugLogger; import com.dfsek.terra.api.util.logging.JavaLogger; import com.dfsek.terra.api.util.logging.Logger; import com.dfsek.terra.api.world.generation.TerraChunkGenerator; -import com.dfsek.terra.bukkit.command.command.TerraCommand; -import com.dfsek.terra.bukkit.command.command.structure.LocateCommand; +import com.dfsek.terra.bukkit.command.BukkitCommandAdapter; import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper; import com.dfsek.terra.bukkit.handles.BukkitItemHandle; import com.dfsek.terra.bukkit.handles.BukkitWorldHandle; @@ -30,6 +31,7 @@ import com.dfsek.terra.bukkit.listeners.SpigotListener; import com.dfsek.terra.bukkit.listeners.TerraListener; import com.dfsek.terra.bukkit.util.PaperUtil; import com.dfsek.terra.bukkit.world.BukkitBiome; +import com.dfsek.terra.commands.profiler.ProfileCommand; import com.dfsek.terra.config.GenericLoaders; import com.dfsek.terra.config.PluginConfig; import com.dfsek.terra.config.lang.LangUtil; @@ -163,14 +165,16 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { registry.loadAll(this); // Load all config packs. PluginCommand c = Objects.requireNonNull(getCommand("terra")); - TerraCommand command = new TerraCommand(this); // Set up main Terra command. - c.setExecutor(command); - c.setTabCompleter(command); + //TerraCommand command = new TerraCommand(this); // Set up main Terra command. - LocateCommand locate = new LocateCommand(command); - PluginCommand locatePl = Objects.requireNonNull(getCommand("locate")); - locatePl.setExecutor(locate); // Override locate command. Once Paper accepts StructureLocateEvent this will be unneeded on Paper implementations. - locatePl.setTabCompleter(locate); + CommandManager manager = new TerraCommandManager(this); + + manager.register("profile", ProfileCommand.class); + + BukkitCommandAdapter command = new BukkitCommandAdapter(manager); + + c.setExecutor(command); + //c.setTabCompleter(command); long save = config.getDataSaveInterval(); diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/BukkitCommandAdapter.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/BukkitCommandAdapter.java new file mode 100644 index 000000000..0d1bb052c --- /dev/null +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/BukkitCommandAdapter.java @@ -0,0 +1,36 @@ +package com.dfsek.terra.bukkit.command; + +import com.dfsek.terra.api.command.CommandManager; +import com.dfsek.terra.api.command.exception.CommandException; +import com.dfsek.terra.bukkit.world.BukkitAdapter; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class BukkitCommandAdapter implements CommandExecutor { + private final CommandManager manager; + + public BukkitCommandAdapter(CommandManager manager) { + this.manager = manager; + } + + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + List argList = new ArrayList<>(Arrays.asList(args)); + if(argList.isEmpty()) { + sender.sendMessage("Command requires arguments."); + return true; + } + try { + manager.execute(argList.remove(0), BukkitAdapter.adapt(sender), argList); + } catch(CommandException e) { + sender.sendMessage(e.getMessage()); + } + return true; + } +} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitAdapter.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitAdapter.java index cd3e61b1d..c50cd2711 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitAdapter.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitAdapter.java @@ -19,6 +19,7 @@ import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.transform.MapTransform; import com.dfsek.terra.api.transform.Transformer; import com.dfsek.terra.bukkit.BukkitCommandSender; +import com.dfsek.terra.bukkit.BukkitEntity; import com.dfsek.terra.bukkit.BukkitPlayer; import com.dfsek.terra.bukkit.world.block.BukkitBlockTypeAndItem; import com.dfsek.terra.bukkit.world.block.data.BukkitBlockData; @@ -27,6 +28,7 @@ import com.dfsek.terra.bukkit.world.inventory.meta.BukkitEnchantment; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.TreeType; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -351,6 +353,8 @@ public final class BukkitAdapter { } public static CommandSender adapt(org.bukkit.command.CommandSender sender) { + if(sender instanceof Player) return new BukkitPlayer((Player) sender); + if(sender instanceof Entity) return new BukkitEntity((Entity) sender); return new BukkitCommandSender(sender); } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricEntity.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricEntity.java index fd7da3d05..f19d6d820 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricEntity.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricEntity.java @@ -2,6 +2,7 @@ package com.dfsek.terra.fabric.world.entity; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.entity.Entity; +import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.fabric.world.FabricAdapter; import com.dfsek.terra.fabric.world.handles.world.FabricWorldAccess; @@ -26,4 +27,9 @@ public class FabricEntity implements Entity { public Location getLocation() { return new Location(new FabricWorldAccess(delegate.world), FabricAdapter.adapt(delegate.getBlockPos())); } + + @Override + public World getWorld() { + return new FabricWorldAccess(delegate.world); + } } From 22d6fdf293b7c1b434c78104e2600899bb51e50b Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 8 Mar 2021 02:27:35 -0700 Subject: [PATCH 60/95] add tab completion --- .../terra/api/command/CommandManager.java | 3 +++ .../terra/api/command/ExecutionState.java | 11 ++++---- .../api/command/TerraCommandManager.java | 25 ++++++++++++++++++- .../api/command/annotation/Argument.java | 5 ++++ .../api/command/tab/NothingCompleter.java | 13 ++++++++++ .../terra/api/command/tab/TabCompleter.java | 9 +++++++ .../commands/profiler/ProfileStopCommand.java | 2 +- .../dfsek/terra/bukkit/TerraBukkitPlugin.java | 2 +- .../bukkit/command/BukkitCommandAdapter.java | 17 ++++++++++++- 9 files changed, 77 insertions(+), 10 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/api/command/tab/NothingCompleter.java create mode 100644 common/src/main/java/com/dfsek/terra/api/command/tab/TabCompleter.java diff --git a/common/src/main/java/com/dfsek/terra/api/command/CommandManager.java b/common/src/main/java/com/dfsek/terra/api/command/CommandManager.java index e46517e7d..c46724d6c 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/CommandManager.java +++ b/common/src/main/java/com/dfsek/terra/api/command/CommandManager.java @@ -1,6 +1,7 @@ package com.dfsek.terra.api.command; import com.dfsek.terra.api.command.exception.CommandException; +import com.dfsek.terra.api.command.exception.MalformedCommandException; import com.dfsek.terra.api.platform.CommandSender; import java.util.List; @@ -9,4 +10,6 @@ public interface CommandManager { void execute(String command, CommandSender sender, List args) throws CommandException; void register(String name, Class clazz); + + List tabComplete(String command, CommandSender sender, List args) throws MalformedCommandException, CommandException; } diff --git a/common/src/main/java/com/dfsek/terra/api/command/ExecutionState.java b/common/src/main/java/com/dfsek/terra/api/command/ExecutionState.java index 2a57b73a6..b262249fd 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/ExecutionState.java +++ b/common/src/main/java/com/dfsek/terra/api/command/ExecutionState.java @@ -27,19 +27,18 @@ public final class ExecutionState { @SuppressWarnings("unchecked") public T getArgument(String argument, Class clazz) { - String value = args.get(argument); + Object value = args.get(argument); if(value == null) throw new IllegalArgumentException("Argument \"" + argument + "\" does not exist!"); if(clazz == int.class || clazz == Integer.class) { - return (T) new Integer(Integer.parseInt(value)); - } - if(clazz == double.class || clazz == Double.class) { - return (T) new Double(Double.parseDouble(value)); + value = Integer.parseInt(value.toString()); + } else if(clazz == double.class || clazz == Double.class) { + value = Double.parseDouble(value.toString()); } // TODO: type loaders - return (T) value; + return clazz.cast(value); } public boolean hasSwitch(String flag) { diff --git a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java index b7b57f818..efa4fb575 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java +++ b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java @@ -21,6 +21,7 @@ import com.dfsek.terra.world.TerraWorld; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -138,6 +139,26 @@ public class TerraCommandManager implements CommandManager { commands.put(name, new CommandHolder(clazz)); } + @Override + public List tabComplete(String command, CommandSender sender, List args) throws CommandException { + if(args.isEmpty()) return new ArrayList<>(commands.keySet()); + + List completions = new ArrayList<>(); + + if(args.size() == 1) { + completions.addAll(commands.get(command).subcommands.keySet()); + } + + if(args.size() <= commands.get(command).arguments.size()) { + try { + completions.addAll(commands.get(command).arguments.get(args.size()).tabCompleter().getConstructor().newInstance().complete(sender)); + } catch(InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { + throw new MalformedCommandException("Unable to reflectively instantiate tab-completer: ", e); + } + } + return completions; + } + /** * Pre-processes command metadata. */ @@ -145,6 +166,7 @@ public class TerraCommandManager implements CommandManager { private final Class clazz; private final Map subcommands = new HashMap<>(); private final Map switches = new HashMap<>(); + private final List arguments; private CommandHolder(Class clazz) { this.clazz = clazz; @@ -163,7 +185,8 @@ public class TerraCommandManager implements CommandManager { switches.put(alias, aSwitch.value()); } } - } + arguments = Arrays.asList(command.arguments()); + } else arguments = Collections.emptyList(); } } } diff --git a/common/src/main/java/com/dfsek/terra/api/command/annotation/Argument.java b/common/src/main/java/com/dfsek/terra/api/command/annotation/Argument.java index b020a03d3..6ace3b0ce 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/annotation/Argument.java +++ b/common/src/main/java/com/dfsek/terra/api/command/annotation/Argument.java @@ -1,5 +1,8 @@ package com.dfsek.terra.api.command.annotation; +import com.dfsek.terra.api.command.tab.NothingCompleter; +import com.dfsek.terra.api.command.tab.TabCompleter; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -13,4 +16,6 @@ public @interface Argument { boolean required() default true; Class type() default String.class; + + Class tabCompleter() default NothingCompleter.class; } diff --git a/common/src/main/java/com/dfsek/terra/api/command/tab/NothingCompleter.java b/common/src/main/java/com/dfsek/terra/api/command/tab/NothingCompleter.java new file mode 100644 index 000000000..111125505 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/tab/NothingCompleter.java @@ -0,0 +1,13 @@ +package com.dfsek.terra.api.command.tab; + +import com.dfsek.terra.api.platform.CommandSender; + +import java.util.Collections; +import java.util.List; + +public class NothingCompleter implements TabCompleter { + @Override + public List complete(CommandSender sender) { + return Collections.emptyList(); + } +} diff --git a/common/src/main/java/com/dfsek/terra/api/command/tab/TabCompleter.java b/common/src/main/java/com/dfsek/terra/api/command/tab/TabCompleter.java new file mode 100644 index 000000000..33f875234 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/tab/TabCompleter.java @@ -0,0 +1,9 @@ +package com.dfsek.terra.api.command.tab; + +import com.dfsek.terra.api.platform.CommandSender; + +import java.util.List; + +public interface TabCompleter { + List complete(CommandSender sender); +} diff --git a/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileStopCommand.java b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileStopCommand.java index 67b0537d4..80330e40a 100644 --- a/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileStopCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileStopCommand.java @@ -24,6 +24,6 @@ public class ProfileStopCommand implements CommandTemplate { Player player = (Player) state.getSender(); TerraWorld world = main.getWorld(player.getWorld()); world.getProfiler().setProfiling(false); - state.getSender().sendMessage("Profiling enabled."); + state.getSender().sendMessage("Profiling disabled."); } } diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java index 87fd760d5..b8c6c9e54 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java @@ -174,7 +174,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { BukkitCommandAdapter command = new BukkitCommandAdapter(manager); c.setExecutor(command); - //c.setTabCompleter(command); + c.setTabCompleter(command); long save = config.getDataSaveInterval(); diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/BukkitCommandAdapter.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/BukkitCommandAdapter.java index 0d1bb052c..e31fc0d75 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/BukkitCommandAdapter.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/BukkitCommandAdapter.java @@ -6,13 +6,16 @@ import com.dfsek.terra.bukkit.world.BukkitAdapter; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; -public class BukkitCommandAdapter implements CommandExecutor { +public class BukkitCommandAdapter implements CommandExecutor, TabCompleter { private final CommandManager manager; public BukkitCommandAdapter(CommandManager manager) { @@ -33,4 +36,16 @@ public class BukkitCommandAdapter implements CommandExecutor { } return true; } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) { + List argList = new ArrayList<>(Arrays.asList(args)); + + try { + return manager.tabComplete(argList.remove(0), BukkitAdapter.adapt(sender), argList); + } catch(CommandException e) { + e.printStackTrace(); + return Collections.emptyList(); + } + } } From 52c56af02c51962b0bb659ac8cbbbec49c3e81c1 Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 8 Mar 2021 03:17:22 -0700 Subject: [PATCH 61/95] tab completion --- .../api/command/TerraCommandManager.java | 26 +++++++++++++------ .../commands/structure/RotationCompleter.java | 14 ++++++++++ .../structure/StructureLoadCommand.java | 3 ++- .../dfsek/terra/bukkit/TerraBukkitPlugin.java | 2 ++ 4 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/commands/structure/RotationCompleter.java diff --git a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java index efa4fb575..82f7784ec 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java +++ b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java @@ -25,6 +25,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; public class TerraCommandManager implements CommandManager { private final Map commands = new HashMap<>(); @@ -78,7 +79,7 @@ public class TerraCommandManager implements CommandManager { } else throw new InvalidArgumentsException("Expected 0 arguments, found " + args.size()); } - if(commandHolder.subcommands.containsKey(args.get(0))) { + if(!args.isEmpty() && commandHolder.subcommands.containsKey(args.get(0))) { String c = args.get(0); args.remove(0); execute(commandHolder.subcommands.get(c), sender, args); @@ -141,20 +142,29 @@ public class TerraCommandManager implements CommandManager { @Override public List tabComplete(String command, CommandSender sender, List args) throws CommandException { - if(args.isEmpty()) return new ArrayList<>(commands.keySet()); + if(args.isEmpty()) return new ArrayList<>(commands.keySet()).stream().sorted(String::compareTo).collect(Collectors.toList()); + return tabComplete(commands.get(command), sender, new ArrayList<>(args)).stream().filter(s -> s.toLowerCase().startsWith(args.get(args.size() - 1).toLowerCase())).sorted(String::compareTo).collect(Collectors.toList()); + } + private List tabComplete(CommandHolder holder, CommandSender sender, List args) throws CommandException { + if(args.isEmpty()) return Collections.emptyList(); List completions = new ArrayList<>(); if(args.size() == 1) { - completions.addAll(commands.get(command).subcommands.keySet()); + completions.addAll(holder.subcommands.keySet()); } - if(args.size() <= commands.get(command).arguments.size()) { - try { - completions.addAll(commands.get(command).arguments.get(args.size()).tabCompleter().getConstructor().newInstance().complete(sender)); - } catch(InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { - throw new MalformedCommandException("Unable to reflectively instantiate tab-completer: ", e); + if(holder.subcommands.containsKey(args.get(0))) { + List newArgs = new ArrayList<>(args); + newArgs.remove(0); + completions.addAll(tabComplete(holder.subcommands.get(args.get(0)), sender, newArgs)); + } + try { + if(args.size() <= holder.arguments.size()) { + completions.addAll(holder.arguments.get(args.size() - 1).tabCompleter().getConstructor().newInstance().complete(sender)); } + } catch(InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { + throw new MalformedCommandException("Unable to reflectively instantiate tab-completer: ", e); } return completions; } diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/RotationCompleter.java b/common/src/main/java/com/dfsek/terra/commands/structure/RotationCompleter.java new file mode 100644 index 000000000..d0f3933bb --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/structure/RotationCompleter.java @@ -0,0 +1,14 @@ +package com.dfsek.terra.commands.structure; + +import com.dfsek.terra.api.command.tab.TabCompleter; +import com.dfsek.terra.api.platform.CommandSender; + +import java.util.Arrays; +import java.util.List; + +public class RotationCompleter implements TabCompleter { + @Override + public List complete(CommandSender sender) { + return Arrays.asList("0", "90", "180", "270"); + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java b/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java index 9182b5bbe..2c9d06b67 100644 --- a/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java @@ -11,7 +11,8 @@ import com.dfsek.terra.api.command.annotation.Switch; @Argument( value = "rotation", required = false, - type = int.class + type = int.class, + tabCompleter = RotationCompleter.class ) }, switches = { diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java index b8c6c9e54..3d14e49fd 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java @@ -31,6 +31,7 @@ import com.dfsek.terra.bukkit.listeners.SpigotListener; import com.dfsek.terra.bukkit.listeners.TerraListener; import com.dfsek.terra.bukkit.util.PaperUtil; import com.dfsek.terra.bukkit.world.BukkitBiome; +import com.dfsek.terra.commands.StructureCommand; import com.dfsek.terra.commands.profiler.ProfileCommand; import com.dfsek.terra.config.GenericLoaders; import com.dfsek.terra.config.PluginConfig; @@ -170,6 +171,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { CommandManager manager = new TerraCommandManager(this); manager.register("profile", ProfileCommand.class); + manager.register("structure", StructureCommand.class); BukkitCommandAdapter command = new BukkitCommandAdapter(manager); From f773ca2322332f0abadc7ce535caedb7a358eea6 Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 8 Mar 2021 23:56:06 -0700 Subject: [PATCH 62/95] ArgumentTarget and SwitchTarget --- .../terra/api/command/CommandManager.java | 2 +- .../terra/api/command/CommandTemplate.java | 4 +- .../terra/api/command/ExecutionState.java | 17 +-- .../api/command/TerraCommandManager.java | 58 ++++++-- .../api/command/annotation/Argument.java | 6 +- .../annotation/inject/ArgumentTarget.java | 12 ++ .../annotation/inject/SwitchTarget.java | 12 ++ .../terra/api/command/arg/ArgumentParser.java | 7 + .../api/command/arg/DoubleArgumentParser.java | 10 ++ .../command/arg/IntegerArgumentParser.java | 10 ++ .../api/command/arg/StringArgumentParser.java | 10 ++ .../dfsek/terra/commands/ReloadCommand.java | 4 +- .../terra/commands/StructureCommand.java | 4 +- .../commands/profiler/ProfileCommand.java | 4 +- .../profiler/ProfileQueryCommand.java | 8 +- .../profiler/ProfileResetCommand.java | 8 +- .../profiler/ProfileStartCommand.java | 8 +- .../commands/profiler/ProfileStopCommand.java | 8 +- .../structure/StructureExportCommand.java | 4 +- .../structure/StructureLoadCommand.java | 15 ++- common/src/test/java/command/CommandTest.java | 126 +++++++++++------- .../dfsek/terra/bukkit/TerraBukkitPlugin.java | 14 +- 22 files changed, 245 insertions(+), 106 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/api/command/annotation/inject/ArgumentTarget.java create mode 100644 common/src/main/java/com/dfsek/terra/api/command/annotation/inject/SwitchTarget.java create mode 100644 common/src/main/java/com/dfsek/terra/api/command/arg/ArgumentParser.java create mode 100644 common/src/main/java/com/dfsek/terra/api/command/arg/DoubleArgumentParser.java create mode 100644 common/src/main/java/com/dfsek/terra/api/command/arg/IntegerArgumentParser.java create mode 100644 common/src/main/java/com/dfsek/terra/api/command/arg/StringArgumentParser.java diff --git a/common/src/main/java/com/dfsek/terra/api/command/CommandManager.java b/common/src/main/java/com/dfsek/terra/api/command/CommandManager.java index c46724d6c..d2ff2c820 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/CommandManager.java +++ b/common/src/main/java/com/dfsek/terra/api/command/CommandManager.java @@ -9,7 +9,7 @@ import java.util.List; public interface CommandManager { void execute(String command, CommandSender sender, List args) throws CommandException; - void register(String name, Class clazz); + void register(String name, Class clazz) throws MalformedCommandException; List tabComplete(String command, CommandSender sender, List args) throws MalformedCommandException, CommandException; } diff --git a/common/src/main/java/com/dfsek/terra/api/command/CommandTemplate.java b/common/src/main/java/com/dfsek/terra/api/command/CommandTemplate.java index bb01ab198..836192b6b 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/CommandTemplate.java +++ b/common/src/main/java/com/dfsek/terra/api/command/CommandTemplate.java @@ -1,5 +1,7 @@ package com.dfsek.terra.api.command; +import com.dfsek.terra.api.platform.CommandSender; + public interface CommandTemplate { - void execute(ExecutionState state); + void execute(CommandSender sender); } diff --git a/common/src/main/java/com/dfsek/terra/api/command/ExecutionState.java b/common/src/main/java/com/dfsek/terra/api/command/ExecutionState.java index b262249fd..89216bd89 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/ExecutionState.java +++ b/common/src/main/java/com/dfsek/terra/api/command/ExecutionState.java @@ -24,21 +24,8 @@ public final class ExecutionState { args.put(arg, value); } - @SuppressWarnings("unchecked") - public T getArgument(String argument, Class clazz) { - - Object value = args.get(argument); - if(value == null) throw new IllegalArgumentException("Argument \"" + argument + "\" does not exist!"); - - if(clazz == int.class || clazz == Integer.class) { - value = Integer.parseInt(value.toString()); - } else if(clazz == double.class || clazz == Double.class) { - value = Double.parseDouble(value.toString()); - } - - // TODO: type loaders - - return clazz.cast(value); + public String getArgument(String argument) { + return args.get(argument); } public boolean hasSwitch(String flag) { diff --git a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java index 82f7784ec..2def7fad1 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java +++ b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java @@ -5,9 +5,12 @@ import com.dfsek.terra.api.command.annotation.Argument; import com.dfsek.terra.api.command.annotation.Command; import com.dfsek.terra.api.command.annotation.Subcommand; import com.dfsek.terra.api.command.annotation.Switch; +import com.dfsek.terra.api.command.annotation.inject.ArgumentTarget; +import com.dfsek.terra.api.command.annotation.inject.SwitchTarget; import com.dfsek.terra.api.command.annotation.type.DebugCommand; import com.dfsek.terra.api.command.annotation.type.PlayerCommand; import com.dfsek.terra.api.command.annotation.type.WorldCommand; +import com.dfsek.terra.api.command.arg.ArgumentParser; import com.dfsek.terra.api.command.exception.CommandException; import com.dfsek.terra.api.command.exception.InvalidArgumentsException; import com.dfsek.terra.api.command.exception.MalformedCommandException; @@ -16,8 +19,10 @@ import com.dfsek.terra.api.injection.Injector; import com.dfsek.terra.api.injection.exception.InjectionException; import com.dfsek.terra.api.platform.CommandSender; import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.api.util.ReflectionUtil; import com.dfsek.terra.world.TerraWorld; +import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Arrays; @@ -66,7 +71,7 @@ public class TerraCommandManager implements CommandManager { ExecutionState state = new ExecutionState(sender); if(!commandClass.isAnnotationPresent(Command.class)) { - invoke(commandClass, state); + invoke(commandClass, state, commandHolder); return; } @@ -74,7 +79,7 @@ public class TerraCommandManager implements CommandManager { if(command.arguments().length == 0 && command.subcommands().length == 0) { if(args.isEmpty()) { - invoke(commandClass, state); + invoke(commandClass, state, commandHolder); return; } else throw new InvalidArgumentsException("Expected 0 arguments, found " + args.size()); } @@ -119,24 +124,53 @@ public class TerraCommandManager implements CommandManager { state.addSwitch(commandHolder.switches.get(val)); } - invoke(commandClass, state); + invoke(commandClass, state, commandHolder); } - private void invoke(Class clazz, ExecutionState state) throws MalformedCommandException { + private void invoke(Class clazz, ExecutionState state, CommandHolder holder) throws MalformedCommandException { try { - System.out.println("invocation"); CommandTemplate template = clazz.getConstructor().newInstance(); pluginInjector.inject(template); - template.execute(state); + for(Field field : ReflectionUtil.getFields(clazz)) { + if(field.isAnnotationPresent(ArgumentTarget.class)) { + ArgumentTarget argumentTarget = field.getAnnotation(ArgumentTarget.class); + if(!holder.argumentMap.containsKey(argumentTarget.value())) { + throw new MalformedCommandException("Argument Target specifies nonexistent argument \"" + argumentTarget.value() + "\""); + } + + String argument = argumentTarget.value(); + + ArgumentParser argumentParser = holder.argumentMap.get(argumentTarget.value()).argumentParser().getConstructor().newInstance(); + + field.setAccessible(true); + field.set(template, argumentParser.parse(state.getSender(), state.getArgument(argument))); + } + if(field.isAnnotationPresent(SwitchTarget.class)) { + SwitchTarget switchTarget = field.getAnnotation(SwitchTarget.class); + if(!holder.switches.containsValue(switchTarget.value())) { + System.out.println(holder.switches); + throw new MalformedCommandException("Switch Target specifies nonexistent switch \"" + switchTarget.value() + "\""); + } + + if(!(field.getType() == boolean.class)) { + throw new MalformedCommandException("Switch Target must be of type boolean."); + } + + field.setAccessible(true); + field.setBoolean(template, state.hasSwitch(switchTarget.value())); + } + } + + template.execute(state.getSender()); } catch(InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | InjectionException e) { throw new MalformedCommandException("Unable to reflectively instantiate command: ", e); } } @Override - public void register(String name, Class clazz) { + public void register(String name, Class clazz) throws MalformedCommandException { commands.put(name, new CommandHolder(clazz)); } @@ -177,12 +211,15 @@ public class TerraCommandManager implements CommandManager { private final Map subcommands = new HashMap<>(); private final Map switches = new HashMap<>(); private final List arguments; + private final Map argumentMap = new HashMap<>(); - private CommandHolder(Class clazz) { + private CommandHolder(Class clazz) throws MalformedCommandException { this.clazz = clazz; if(clazz.isAnnotationPresent(Command.class)) { Command command = clazz.getAnnotation(Command.class); for(Subcommand subcommand : command.subcommands()) { + if(subcommands.containsKey(subcommand.value())) + throw new MalformedCommandException("Duplicate subcommand: " + subcommand); CommandHolder holder = new CommandHolder(subcommand.clazz()); subcommands.put(subcommand.value(), holder); for(String alias : subcommand.aliases()) { @@ -190,11 +227,16 @@ public class TerraCommandManager implements CommandManager { } } for(Switch aSwitch : command.switches()) { + if(switches.containsKey(aSwitch.value())) throw new MalformedCommandException("Duplicate switch: " + aSwitch); switches.put(aSwitch.value(), aSwitch.value()); for(String alias : aSwitch.aliases()) { switches.put(alias, aSwitch.value()); } } + for(Argument argument : command.arguments()) { + if(argumentMap.containsKey(argument.value())) throw new MalformedCommandException("Duplicate argument: " + argument); + argumentMap.put(argument.value(), argument); + } arguments = Arrays.asList(command.arguments()); } else arguments = Collections.emptyList(); } diff --git a/common/src/main/java/com/dfsek/terra/api/command/annotation/Argument.java b/common/src/main/java/com/dfsek/terra/api/command/annotation/Argument.java index 6ace3b0ce..a2625ee26 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/annotation/Argument.java +++ b/common/src/main/java/com/dfsek/terra/api/command/annotation/Argument.java @@ -1,5 +1,7 @@ package com.dfsek.terra.api.command.annotation; +import com.dfsek.terra.api.command.arg.ArgumentParser; +import com.dfsek.terra.api.command.arg.StringArgumentParser; import com.dfsek.terra.api.command.tab.NothingCompleter; import com.dfsek.terra.api.command.tab.TabCompleter; @@ -15,7 +17,7 @@ public @interface Argument { boolean required() default true; - Class type() default String.class; - Class tabCompleter() default NothingCompleter.class; + + Class> argumentParser() default StringArgumentParser.class; } diff --git a/common/src/main/java/com/dfsek/terra/api/command/annotation/inject/ArgumentTarget.java b/common/src/main/java/com/dfsek/terra/api/command/annotation/inject/ArgumentTarget.java new file mode 100644 index 000000000..89dbc5245 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/annotation/inject/ArgumentTarget.java @@ -0,0 +1,12 @@ +package com.dfsek.terra.api.command.annotation.inject; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ArgumentTarget { + String value(); +} diff --git a/common/src/main/java/com/dfsek/terra/api/command/annotation/inject/SwitchTarget.java b/common/src/main/java/com/dfsek/terra/api/command/annotation/inject/SwitchTarget.java new file mode 100644 index 000000000..67478373a --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/annotation/inject/SwitchTarget.java @@ -0,0 +1,12 @@ +package com.dfsek.terra.api.command.annotation.inject; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface SwitchTarget { + String value(); +} diff --git a/common/src/main/java/com/dfsek/terra/api/command/arg/ArgumentParser.java b/common/src/main/java/com/dfsek/terra/api/command/arg/ArgumentParser.java new file mode 100644 index 000000000..3fcc5aeef --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/arg/ArgumentParser.java @@ -0,0 +1,7 @@ +package com.dfsek.terra.api.command.arg; + +import com.dfsek.terra.api.platform.CommandSender; + +public interface ArgumentParser { + T parse(CommandSender sender, String arg); +} diff --git a/common/src/main/java/com/dfsek/terra/api/command/arg/DoubleArgumentParser.java b/common/src/main/java/com/dfsek/terra/api/command/arg/DoubleArgumentParser.java new file mode 100644 index 000000000..3f229b444 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/arg/DoubleArgumentParser.java @@ -0,0 +1,10 @@ +package com.dfsek.terra.api.command.arg; + +import com.dfsek.terra.api.platform.CommandSender; + +public class DoubleArgumentParser implements ArgumentParser { + @Override + public Double parse(CommandSender sender, String arg) { + return arg == null ? null : Double.parseDouble(arg); + } +} diff --git a/common/src/main/java/com/dfsek/terra/api/command/arg/IntegerArgumentParser.java b/common/src/main/java/com/dfsek/terra/api/command/arg/IntegerArgumentParser.java new file mode 100644 index 000000000..24e3186ca --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/arg/IntegerArgumentParser.java @@ -0,0 +1,10 @@ +package com.dfsek.terra.api.command.arg; + +import com.dfsek.terra.api.platform.CommandSender; + +public class IntegerArgumentParser implements ArgumentParser { + @Override + public Integer parse(CommandSender sender, String arg) { + return arg == null ? null : Integer.parseInt(arg); + } +} diff --git a/common/src/main/java/com/dfsek/terra/api/command/arg/StringArgumentParser.java b/common/src/main/java/com/dfsek/terra/api/command/arg/StringArgumentParser.java new file mode 100644 index 000000000..736b335d0 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/arg/StringArgumentParser.java @@ -0,0 +1,10 @@ +package com.dfsek.terra.api.command.arg; + +import com.dfsek.terra.api.platform.CommandSender; + +public class StringArgumentParser implements ArgumentParser { + @Override + public String parse(CommandSender sender, String arg) { + return arg; + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/ReloadCommand.java b/common/src/main/java/com/dfsek/terra/commands/ReloadCommand.java index 119429dc6..512ccfbd2 100644 --- a/common/src/main/java/com/dfsek/terra/commands/ReloadCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/ReloadCommand.java @@ -1,13 +1,13 @@ package com.dfsek.terra.commands; import com.dfsek.terra.api.command.CommandTemplate; -import com.dfsek.terra.api.command.ExecutionState; import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.platform.CommandSender; @Command() public class ReloadCommand implements CommandTemplate { @Override - public void execute(ExecutionState state) { + public void execute(CommandSender sender) { } } diff --git a/common/src/main/java/com/dfsek/terra/commands/StructureCommand.java b/common/src/main/java/com/dfsek/terra/commands/StructureCommand.java index a2d176ea7..9b9e7355c 100644 --- a/common/src/main/java/com/dfsek/terra/commands/StructureCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/StructureCommand.java @@ -1,9 +1,9 @@ package com.dfsek.terra.commands; import com.dfsek.terra.api.command.CommandTemplate; -import com.dfsek.terra.api.command.ExecutionState; import com.dfsek.terra.api.command.annotation.Command; import com.dfsek.terra.api.command.annotation.Subcommand; +import com.dfsek.terra.api.platform.CommandSender; import com.dfsek.terra.commands.structure.StructureExportCommand; import com.dfsek.terra.commands.structure.StructureLoadCommand; @@ -23,7 +23,7 @@ import com.dfsek.terra.commands.structure.StructureLoadCommand; ) public class StructureCommand implements CommandTemplate { @Override - public void execute(ExecutionState state) { + public void execute(CommandSender sender) { } } diff --git a/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileCommand.java b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileCommand.java index b5bd9d270..4caad6957 100644 --- a/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileCommand.java @@ -1,12 +1,12 @@ package com.dfsek.terra.commands.profiler; import com.dfsek.terra.api.command.CommandTemplate; -import com.dfsek.terra.api.command.ExecutionState; import com.dfsek.terra.api.command.annotation.Command; import com.dfsek.terra.api.command.annotation.Subcommand; import com.dfsek.terra.api.command.annotation.type.DebugCommand; import com.dfsek.terra.api.command.annotation.type.PlayerCommand; import com.dfsek.terra.api.command.annotation.type.WorldCommand; +import com.dfsek.terra.api.platform.CommandSender; @Command( subcommands = { @@ -22,7 +22,7 @@ import com.dfsek.terra.api.command.annotation.type.WorldCommand; @DebugCommand public class ProfileCommand implements CommandTemplate { @Override - public void execute(ExecutionState state) { + public void execute(CommandSender sender) { } } diff --git a/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileQueryCommand.java b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileQueryCommand.java index b0004799f..16f383b2d 100644 --- a/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileQueryCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileQueryCommand.java @@ -2,12 +2,12 @@ package com.dfsek.terra.commands.profiler; import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.command.CommandTemplate; -import com.dfsek.terra.api.command.ExecutionState; import com.dfsek.terra.api.command.annotation.Command; import com.dfsek.terra.api.command.annotation.type.DebugCommand; import com.dfsek.terra.api.command.annotation.type.PlayerCommand; import com.dfsek.terra.api.command.annotation.type.WorldCommand; import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.platform.CommandSender; import com.dfsek.terra.api.platform.entity.Player; import com.dfsek.terra.world.TerraWorld; @@ -20,9 +20,9 @@ public class ProfileQueryCommand implements CommandTemplate { private TerraPlugin main; @Override - public void execute(ExecutionState state) { - Player player = (Player) state.getSender(); + public void execute(CommandSender sender) { + Player player = (Player) sender; TerraWorld world = main.getWorld(player.getWorld()); - state.getSender().sendMessage(world.getProfiler().getResultsFormatted()); + player.sendMessage(world.getProfiler().getResultsFormatted()); } } diff --git a/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileResetCommand.java b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileResetCommand.java index 4d2349291..1a4c47e6e 100644 --- a/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileResetCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileResetCommand.java @@ -2,12 +2,12 @@ package com.dfsek.terra.commands.profiler; import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.command.CommandTemplate; -import com.dfsek.terra.api.command.ExecutionState; import com.dfsek.terra.api.command.annotation.Command; import com.dfsek.terra.api.command.annotation.type.DebugCommand; import com.dfsek.terra.api.command.annotation.type.PlayerCommand; import com.dfsek.terra.api.command.annotation.type.WorldCommand; import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.platform.CommandSender; import com.dfsek.terra.api.platform.entity.Player; import com.dfsek.terra.world.TerraWorld; @@ -20,10 +20,10 @@ public class ProfileResetCommand implements CommandTemplate { private TerraPlugin main; @Override - public void execute(ExecutionState state) { - Player player = (Player) state.getSender(); + public void execute(CommandSender sender) { + Player player = (Player) sender; TerraWorld world = main.getWorld(player.getWorld()); world.getProfiler().reset(); - state.getSender().sendMessage("Profiler reset."); + player.sendMessage("Profiler reset."); } } diff --git a/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileStartCommand.java b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileStartCommand.java index bb42588a1..36dcec85b 100644 --- a/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileStartCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileStartCommand.java @@ -2,12 +2,12 @@ package com.dfsek.terra.commands.profiler; import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.command.CommandTemplate; -import com.dfsek.terra.api.command.ExecutionState; import com.dfsek.terra.api.command.annotation.Command; import com.dfsek.terra.api.command.annotation.type.DebugCommand; import com.dfsek.terra.api.command.annotation.type.PlayerCommand; import com.dfsek.terra.api.command.annotation.type.WorldCommand; import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.platform.CommandSender; import com.dfsek.terra.api.platform.entity.Player; import com.dfsek.terra.world.TerraWorld; @@ -20,10 +20,10 @@ public class ProfileStartCommand implements CommandTemplate { private TerraPlugin main; @Override - public void execute(ExecutionState state) { - Player player = (Player) state.getSender(); + public void execute(CommandSender sender) { + Player player = (Player) sender; TerraWorld world = main.getWorld(player.getWorld()); world.getProfiler().setProfiling(true); - state.getSender().sendMessage("Profiling enabled."); + player.sendMessage("Profiling enabled."); } } diff --git a/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileStopCommand.java b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileStopCommand.java index 80330e40a..64e46fe39 100644 --- a/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileStopCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileStopCommand.java @@ -2,12 +2,12 @@ package com.dfsek.terra.commands.profiler; import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.command.CommandTemplate; -import com.dfsek.terra.api.command.ExecutionState; import com.dfsek.terra.api.command.annotation.Command; import com.dfsek.terra.api.command.annotation.type.DebugCommand; import com.dfsek.terra.api.command.annotation.type.PlayerCommand; import com.dfsek.terra.api.command.annotation.type.WorldCommand; import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.platform.CommandSender; import com.dfsek.terra.api.platform.entity.Player; import com.dfsek.terra.world.TerraWorld; @@ -20,10 +20,10 @@ public class ProfileStopCommand implements CommandTemplate { private TerraPlugin main; @Override - public void execute(ExecutionState state) { - Player player = (Player) state.getSender(); + public void execute(CommandSender sender) { + Player player = (Player) sender; TerraWorld world = main.getWorld(player.getWorld()); world.getProfiler().setProfiling(false); - state.getSender().sendMessage("Profiling disabled."); + player.sendMessage("Profiling disabled."); } } diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/StructureExportCommand.java b/common/src/main/java/com/dfsek/terra/commands/structure/StructureExportCommand.java index fa368668b..499493cb8 100644 --- a/common/src/main/java/com/dfsek/terra/commands/structure/StructureExportCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/structure/StructureExportCommand.java @@ -1,13 +1,13 @@ package com.dfsek.terra.commands.structure; import com.dfsek.terra.api.command.CommandTemplate; -import com.dfsek.terra.api.command.ExecutionState; import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.platform.CommandSender; @Command public class StructureExportCommand implements CommandTemplate { @Override - public void execute(ExecutionState state) { + public void execute(CommandSender sender) { System.out.println("export command"); } } diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java b/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java index 2c9d06b67..3f8382588 100644 --- a/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java @@ -1,18 +1,20 @@ package com.dfsek.terra.commands.structure; import com.dfsek.terra.api.command.CommandTemplate; -import com.dfsek.terra.api.command.ExecutionState; import com.dfsek.terra.api.command.annotation.Argument; import com.dfsek.terra.api.command.annotation.Command; import com.dfsek.terra.api.command.annotation.Switch; +import com.dfsek.terra.api.command.annotation.inject.ArgumentTarget; +import com.dfsek.terra.api.command.arg.IntegerArgumentParser; +import com.dfsek.terra.api.platform.CommandSender; @Command( arguments = { @Argument( value = "rotation", required = false, - type = int.class, - tabCompleter = RotationCompleter.class + tabCompleter = RotationCompleter.class, + argumentParser = IntegerArgumentParser.class ) }, switches = { @@ -22,8 +24,11 @@ import com.dfsek.terra.api.command.annotation.Switch; } ) public class StructureLoadCommand implements CommandTemplate { - @Override - public void execute(ExecutionState state) { + @ArgumentTarget("rotation") + private Integer rotation; + @Override + public void execute(CommandSender sender) { + System.out.println(rotation); } } diff --git a/common/src/test/java/command/CommandTest.java b/common/src/test/java/command/CommandTest.java index 42a419c49..343b4971a 100644 --- a/common/src/test/java/command/CommandTest.java +++ b/common/src/test/java/command/CommandTest.java @@ -2,15 +2,19 @@ package command; import com.dfsek.terra.api.command.CommandManager; import com.dfsek.terra.api.command.CommandTemplate; -import com.dfsek.terra.api.command.ExecutionState; import com.dfsek.terra.api.command.TerraCommandManager; import com.dfsek.terra.api.command.annotation.Argument; import com.dfsek.terra.api.command.annotation.Command; import com.dfsek.terra.api.command.annotation.Subcommand; import com.dfsek.terra.api.command.annotation.Switch; +import com.dfsek.terra.api.command.annotation.inject.ArgumentTarget; +import com.dfsek.terra.api.command.annotation.inject.SwitchTarget; +import com.dfsek.terra.api.command.arg.DoubleArgumentParser; +import com.dfsek.terra.api.command.arg.IntegerArgumentParser; import com.dfsek.terra.api.command.exception.CommandException; import com.dfsek.terra.api.command.exception.InvalidArgumentsException; import com.dfsek.terra.api.command.exception.MalformedCommandException; +import com.dfsek.terra.api.platform.CommandSender; import org.junit.jupiter.api.Test; import java.util.Arrays; @@ -86,29 +90,35 @@ public class CommandTest { @Command( arguments = { @Argument(value = "arg0"), - @Argument(value = "arg1", type = int.class), - @Argument(value = "arg2", type = double.class, required = false) + @Argument(value = "arg1", argumentParser = IntegerArgumentParser.class), + @Argument(value = "arg2", required = false, argumentParser = DoubleArgumentParser.class) } ) public static final class DemoCommand implements CommandTemplate { + @ArgumentTarget("arg0") + private String arg0; + + @ArgumentTarget("arg1") + private Integer arg1; + + @ArgumentTarget("arg2") + private Double arg2; + + @Override - public void execute(ExecutionState state) { - System.out.println(state.getArgument("arg0", String.class)); - System.out.println(state.getArgument("arg1", int.class)); - try { - System.out.println(state.getArgument("arg2", double.class)); - } catch(IllegalArgumentException e) { - System.out.println("arg2 undefined."); - } + public void execute(CommandSender sender) { + System.out.println(arg0); + System.out.println(arg1); + System.out.println(arg2); } } @Command( arguments = { @Argument(value = "arg0"), - @Argument(value = "arg1", type = int.class), - @Argument(value = "arg2", type = double.class, required = false) + @Argument(value = "arg1"), + @Argument(value = "arg2", required = false) }, switches = { @Switch(value = "a", aliases = {"aSwitch"}), @@ -116,33 +126,44 @@ public class CommandTest { } ) public static final class DemoSwitchCommand implements CommandTemplate { + @ArgumentTarget("arg0") + private String arg0; + + @ArgumentTarget("arg1") + private String arg1; + + @ArgumentTarget("arg2") + private String arg2; + + @SwitchTarget("a") + private boolean a; + + @SwitchTarget("b") + private boolean b; + @Override - public void execute(ExecutionState state) { - System.out.println(state.getArgument("arg0", String.class)); - System.out.println(state.getArgument("arg1", int.class)); - try { - System.out.println(state.getArgument("arg2", double.class)); - } catch(IllegalArgumentException e) { - System.out.println("arg2 undefined."); - } + public void execute(CommandSender sender) { + System.out.println(arg0); + System.out.println(arg1); + System.out.println(arg2); - System.out.println("A: " + state.hasSwitch("a")); - System.out.println("B: " + state.hasSwitch("b")); + System.out.println("A: " + a); + System.out.println("B: " + b); } } @Command( arguments = { @Argument(value = "arg0"), - @Argument(value = "arg2", type = double.class, required = false), // optional arguments must be last. this command is invalid. - @Argument(value = "arg1", type = int.class) + @Argument(value = "arg2", required = false), // optional arguments must be last. this command is invalid. + @Argument(value = "arg1") } ) public static final class DemoInvalidCommand implements CommandTemplate { @Override - public void execute(ExecutionState state) { + public void execute(CommandSender sender) { throw new Error("this should never be reached"); } } @@ -150,8 +171,8 @@ public class CommandTest { @Command( arguments = { @Argument(value = "arg0"), - @Argument(value = "arg1", type = int.class), - @Argument(value = "arg2", type = double.class, required = false), + @Argument(value = "arg1"), + @Argument(value = "arg2", required = false), }, subcommands = { @Subcommand( @@ -167,38 +188,47 @@ public class CommandTest { } ) public static final class DemoParentCommand implements CommandTemplate { + @ArgumentTarget("arg0") + private String arg0; + + @ArgumentTarget("arg1") + private String arg1; + + @ArgumentTarget("arg2") + private String arg2; + @Override - public void execute(ExecutionState state) { - System.out.println("Parent command"); - System.out.println(state.getArgument("arg0", String.class)); - System.out.println(state.getArgument("arg1", int.class)); - try { - System.out.println(state.getArgument("arg2", double.class)); - } catch(IllegalArgumentException e) { - System.out.println("arg2 undefined."); - } + public void execute(CommandSender sender) { + System.out.println(arg0); + System.out.println(arg1); + System.out.println(arg2); } } @Command( arguments = { @Argument(value = "arg0"), - @Argument(value = "arg1", type = int.class), - @Argument(value = "arg2", type = double.class, required = false), + @Argument(value = "arg1"), + @Argument(value = "arg2", required = false), } ) public static final class DemoChildCommand implements CommandTemplate { + @ArgumentTarget("arg0") + private String arg0; + + @ArgumentTarget("arg1") + private String arg1; + + @ArgumentTarget("arg2") + private String arg2; + + @Override - public void execute(ExecutionState state) { - System.out.println("Child command"); - System.out.println(state.getArgument("arg0", String.class)); - System.out.println(state.getArgument("arg1", int.class)); - try { - System.out.println(state.getArgument("arg2", double.class)); - } catch(IllegalArgumentException e) { - System.out.println("arg2 undefined."); - } + public void execute(CommandSender sender) { + System.out.println(arg0); + System.out.println(arg1); + System.out.println(arg2); } } } diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java index 3d14e49fd..5b436b084 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java @@ -8,6 +8,7 @@ import com.dfsek.terra.api.addons.annotations.Author; import com.dfsek.terra.api.addons.annotations.Version; import com.dfsek.terra.api.command.CommandManager; import com.dfsek.terra.api.command.TerraCommandManager; +import com.dfsek.terra.api.command.exception.MalformedCommandException; import com.dfsek.terra.api.event.EventManager; import com.dfsek.terra.api.event.TerraEventManager; import com.dfsek.terra.api.platform.block.BlockData; @@ -170,8 +171,17 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { CommandManager manager = new TerraCommandManager(this); - manager.register("profile", ProfileCommand.class); - manager.register("structure", StructureCommand.class); + + try { + manager.register("structure", StructureCommand.class); + manager.register("profile", ProfileCommand.class); + } catch(MalformedCommandException e) { // This should never happen. + logger().severe("Errors occurred while registering commands."); + e.printStackTrace(); + logger().severe("Please report this to Terra."); + Bukkit.getPluginManager().disablePlugin(this); + return; + } BukkitCommandAdapter command = new BukkitCommandAdapter(manager); From 5fc012f7baebc0c444754814c0fea7898e1a3670 Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 8 Mar 2021 23:56:58 -0700 Subject: [PATCH 63/95] injection for argumentparser --- .../java/com/dfsek/terra/api/command/TerraCommandManager.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java index 2def7fad1..ec2a46c42 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java +++ b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java @@ -144,6 +144,8 @@ public class TerraCommandManager implements CommandManager { ArgumentParser argumentParser = holder.argumentMap.get(argumentTarget.value()).argumentParser().getConstructor().newInstance(); + pluginInjector.inject(argumentParser); + field.setAccessible(true); field.set(template, argumentParser.parse(state.getSender(), state.getArgument(argument))); } From 0f39d64d721e9e3a2dc096b61fd88b396122ef03 Mon Sep 17 00:00:00 2001 From: dfsek Date: Tue, 9 Mar 2021 03:07:02 -0700 Subject: [PATCH 64/95] sort of working Fabric commands --- .../terra/api/command/CommandManager.java | 4 +- .../api/command/TerraCommandManager.java | 19 +++ .../com/dfsek/terra/commands/CommandUtil.java | 12 ++ common/src/test/java/command/CommandTest.java | 2 + .../dfsek/terra/bukkit/TerraBukkitPlugin.java | 6 +- .../dfsek/terra/fabric/TerraFabricPlugin.java | 109 ++++++++++++++---- .../fabric/command/FabricCommandAdapter.java | 7 ++ .../command/StringListArgumentType.java | 17 +++ .../terra/fabric/world/FabricAdapter.java | 10 ++ .../world/entity/FabricCommandSender.java | 23 ++++ .../fabric/world/entity/FabricPlayer.java | 37 ++++++ 11 files changed, 216 insertions(+), 30 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/commands/CommandUtil.java create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/command/FabricCommandAdapter.java create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/command/StringListArgumentType.java create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricCommandSender.java create mode 100644 platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricPlayer.java diff --git a/common/src/main/java/com/dfsek/terra/api/command/CommandManager.java b/common/src/main/java/com/dfsek/terra/api/command/CommandManager.java index d2ff2c820..a33d70921 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/CommandManager.java +++ b/common/src/main/java/com/dfsek/terra/api/command/CommandManager.java @@ -11,5 +11,7 @@ public interface CommandManager { void register(String name, Class clazz) throws MalformedCommandException; - List tabComplete(String command, CommandSender sender, List args) throws MalformedCommandException, CommandException; + List tabComplete(String command, CommandSender sender, List args) throws CommandException; + + int getMaxArgumentDepth(); } diff --git a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java index ec2a46c42..bc729e041 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java +++ b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java @@ -21,6 +21,7 @@ import com.dfsek.terra.api.platform.CommandSender; import com.dfsek.terra.api.platform.entity.Player; import com.dfsek.terra.api.util.ReflectionUtil; import com.dfsek.terra.world.TerraWorld; +import net.jafama.FastMath; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -182,6 +183,24 @@ public class TerraCommandManager implements CommandManager { return tabComplete(commands.get(command), sender, new ArrayList<>(args)).stream().filter(s -> s.toLowerCase().startsWith(args.get(args.size() - 1).toLowerCase())).sorted(String::compareTo).collect(Collectors.toList()); } + @Override + public int getMaxArgumentDepth() { + int max = 0; + for(CommandHolder value : commands.values()) { + max = FastMath.max(getMaxArgumentDepth(value), max); + } + return max; + } + + private int getMaxArgumentDepth(CommandHolder holder) { + int max = 0; + max = FastMath.max(holder.arguments.size(), max); + for(CommandHolder value : holder.subcommands.values()) { + max = FastMath.max(max, getMaxArgumentDepth(value) + 1); + } + return max; + } + private List tabComplete(CommandHolder holder, CommandSender sender, List args) throws CommandException { if(args.isEmpty()) return Collections.emptyList(); List completions = new ArrayList<>(); diff --git a/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java b/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java new file mode 100644 index 000000000..bac8bc882 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java @@ -0,0 +1,12 @@ +package com.dfsek.terra.commands; + +import com.dfsek.terra.api.command.CommandManager; +import com.dfsek.terra.api.command.exception.MalformedCommandException; +import com.dfsek.terra.commands.profiler.ProfileCommand; + +public final class CommandUtil { + public static void registerAll(CommandManager manager) throws MalformedCommandException { + manager.register("structure", StructureCommand.class); + manager.register("profile", ProfileCommand.class); + } +} diff --git a/common/src/test/java/command/CommandTest.java b/common/src/test/java/command/CommandTest.java index 343b4971a..f3cd29337 100644 --- a/common/src/test/java/command/CommandTest.java +++ b/common/src/test/java/command/CommandTest.java @@ -34,6 +34,8 @@ public class CommandTest { manager.execute("test", null, Arrays.asList("sub1", "first", "2", "3.4")); manager.execute("test", null, Arrays.asList("sub2", "first", "2")); manager.execute("test", null, Arrays.asList("first", "2")); // Parent command args + + System.out.println("ARGS: " + manager.getMaxArgumentDepth()); } @Test diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java index 5b436b084..7a4a3ed5b 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java @@ -32,8 +32,7 @@ import com.dfsek.terra.bukkit.listeners.SpigotListener; import com.dfsek.terra.bukkit.listeners.TerraListener; import com.dfsek.terra.bukkit.util.PaperUtil; import com.dfsek.terra.bukkit.world.BukkitBiome; -import com.dfsek.terra.commands.StructureCommand; -import com.dfsek.terra.commands.profiler.ProfileCommand; +import com.dfsek.terra.commands.CommandUtil; import com.dfsek.terra.config.GenericLoaders; import com.dfsek.terra.config.PluginConfig; import com.dfsek.terra.config.lang.LangUtil; @@ -173,8 +172,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { try { - manager.register("structure", StructureCommand.class); - manager.register("profile", ProfileCommand.class); + CommandUtil.registerAll(manager); } catch(MalformedCommandException e) { // This should never happen. logger().severe("Errors occurred while registering commands."); e.printStackTrace(); diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index 8f83ecea1..7f0ad0871 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -6,6 +6,10 @@ import com.dfsek.terra.api.addons.TerraAddon; import com.dfsek.terra.api.addons.annotations.Addon; import com.dfsek.terra.api.addons.annotations.Author; import com.dfsek.terra.api.addons.annotations.Version; +import com.dfsek.terra.api.command.CommandManager; +import com.dfsek.terra.api.command.TerraCommandManager; +import com.dfsek.terra.api.command.exception.CommandException; +import com.dfsek.terra.api.command.exception.MalformedCommandException; import com.dfsek.terra.api.event.EventListener; import com.dfsek.terra.api.event.EventManager; import com.dfsek.terra.api.event.TerraEventManager; @@ -23,6 +27,7 @@ import com.dfsek.terra.api.transform.Transformer; import com.dfsek.terra.api.util.logging.DebugLogger; import com.dfsek.terra.api.util.logging.Logger; import com.dfsek.terra.api.world.tree.Tree; +import com.dfsek.terra.commands.CommandUtil; import com.dfsek.terra.config.GenericLoaders; import com.dfsek.terra.config.PluginConfig; import com.dfsek.terra.config.builder.BiomeBuilder; @@ -31,6 +36,7 @@ import com.dfsek.terra.config.lang.Language; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.fabric.inventory.FabricItemHandle; import com.dfsek.terra.fabric.mixin.GeneratorTypeAccessor; +import com.dfsek.terra.fabric.world.FabricAdapter; import com.dfsek.terra.fabric.world.FabricBiome; import com.dfsek.terra.fabric.world.FabricTree; import com.dfsek.terra.fabric.world.FabricWorldHandle; @@ -42,11 +48,16 @@ import com.dfsek.terra.registry.exception.DuplicateEntryException; import com.dfsek.terra.registry.master.AddonRegistry; import com.dfsek.terra.registry.master.ConfigRegistry; import com.dfsek.terra.world.TerraWorld; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; import net.fabricmc.api.EnvType; import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.block.Blocks; import net.minecraft.client.world.GeneratorType; +import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.LiteralText; import net.minecraft.util.Identifier; import net.minecraft.util.registry.BuiltinRegistries; @@ -75,29 +86,24 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Map; public class TerraFabricPlugin implements TerraPlugin, ModInitializer { - private final Map worldMap = new HashMap<>(); - private static TerraFabricPlugin instance; - - private final EventManager eventManager = new TerraEventManager(this); - - - public static TerraFabricPlugin getInstance() { - return instance; - } - public static final PopulatorFeature POPULATOR_FEATURE = new PopulatorFeature(DefaultFeatureConfig.CODEC); public static final ConfiguredFeature POPULATOR_CONFIGURED_FEATURE = POPULATOR_FEATURE.configure(FeatureConfig.DEFAULT).decorate(Decorator.NOPE.configure(NopeDecoratorConfig.INSTANCE)); - + private static TerraFabricPlugin instance; + private final Map worldMap = new HashMap<>(); + private final EventManager eventManager = new TerraEventManager(this); private final GenericLoaders genericLoaders = new GenericLoaders(this); private final Logger logger = new Logger() { private final org.apache.logging.log4j.Logger logger = LogManager.getLogger(); + @Override public void info(String message) { logger.info(message); @@ -114,20 +120,25 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { } }; private final DebugLogger debugLogger = new DebugLogger(logger); - - private final ItemHandle itemHandle = new FabricItemHandle(); private final WorldHandle worldHandle = new FabricWorldHandle(); private final ConfigRegistry registry = new ConfigRegistry(); private final CheckedRegistry checkedRegistry = new CheckedRegistry<>(registry); - private final AddonRegistry addonRegistry = new AddonRegistry(new FabricAddon(this), this); private final LockedRegistry addonLockedRegistry = new LockedRegistry<>(addonRegistry); - - + private final PluginConfig plugin = new PluginConfig(); + private final Transformer biomeFixer = new Transformer.Builder() + .addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse(id)), new NotNullValidator<>()) + .addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse("minecraft:" + id.toLowerCase())), new NotNullValidator<>()).build(); private File config; - private final PluginConfig plugin = new PluginConfig(); + public static TerraFabricPlugin getInstance() { + return instance; + } + + public static String createBiomeID(ConfigPack pack, String biomeID) { + return pack.getTemplate().getID().toLowerCase() + "/" + biomeID.toLowerCase(Locale.ROOT); + } @Override public WorldHandle getWorldHandle() { @@ -208,10 +219,6 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { return debugLogger; } - private final Transformer biomeFixer = new Transformer.Builder() - .addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse(id)), new NotNullValidator<>()) - .addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse("minecraft:" + id.toLowerCase())), new NotNullValidator<>()).build(); - @Override public void register(TypeRegistry registry) { genericLoaders.register(registry); @@ -220,10 +227,6 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { .registerLoader(com.dfsek.terra.api.platform.world.Biome.class, (t, o, l) -> new FabricBiome(biomeFixer.translate((String) o))); } - public static String createBiomeID(ConfigPack pack, String biomeID) { - return pack.getTemplate().getID().toLowerCase() + "/" + biomeID.toLowerCase(Locale.ROOT); - } - private Biome createBiome(BiomeBuilder biome) { SpawnSettings.Builder spawnSettings = new SpawnSettings.Builder(); DefaultBiomeFeatures.addFarmAnimals(spawnSettings); @@ -258,6 +261,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { .build(); } + @SuppressWarnings("unchecked") @Override public void onInitialize() { instance = this; @@ -299,6 +303,61 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { }); } + CommandManager manager = new TerraCommandManager(this); + try { + CommandUtil.registerAll(manager); + } catch(MalformedCommandException e) { + e.printStackTrace(); // TODO do something here even though this should literally never happen + } + + + CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> { + LiteralArgumentBuilder argumentBuilder = net.minecraft.server.command.CommandManager.literal("terra").executes(context -> { + System.out.println(context.getNodes()); + System.out.println(context); + System.out.println(context.getInput()); + return 1; + }); + + int max = manager.getMaxArgumentDepth(); + System.out.println("MAX:" + max); + RequiredArgumentBuilder arg = RequiredArgumentBuilder.argument("arg0", StringArgumentType.string()); + for(int i = 0; i < max; i++) { + System.out.println("arg " + i); + int finalI = i; + RequiredArgumentBuilder next = RequiredArgumentBuilder.argument("arg" + i, StringArgumentType.string()); + + arg = arg.then(next.suggests((context, builder) -> { + List args = parseCommand(context.getInput()); + System.out.println("Tab completing " + finalI); + System.out.println(args); + try { + manager.tabComplete(args.remove(0), FabricAdapter.adapt(context.getSource()), args).forEach(builder::suggest); + } catch(CommandException e) { + e.printStackTrace(); + } + return builder.buildFuture(); + }).executes(context -> { + List args = parseCommand(context.getInput()); + try { + manager.execute(args.remove(0), FabricAdapter.adapt(context.getSource()), args); + } catch(CommandException e) { + e.printStackTrace(); + return -1; + } + return 1; + })); + } + dispatcher.register(argumentBuilder.then(arg)); + } + ); + + } + + private List parseCommand(String command) { + if(command.startsWith("/terra ")) command = command.substring("/terra ".length()); + else if(command.startsWith("/te ")) command = command.substring("/te ".length()); + return new ArrayList<>(Arrays.asList(command.split(" "))); } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/command/FabricCommandAdapter.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/command/FabricCommandAdapter.java new file mode 100644 index 000000000..a8db1bb54 --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/command/FabricCommandAdapter.java @@ -0,0 +1,7 @@ +package com.dfsek.terra.fabric.command; + +public class FabricCommandAdapter { + public static void register() { + + } +} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/command/StringListArgumentType.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/command/StringListArgumentType.java new file mode 100644 index 000000000..392aaf1af --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/command/StringListArgumentType.java @@ -0,0 +1,17 @@ +package com.dfsek.terra.fabric.command; + +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.arguments.ArgumentType; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class StringListArgumentType implements ArgumentType> { + @Override + public List parse(StringReader reader) { + final String text = reader.getRemaining(); + reader.setCursor(reader.getTotalLength()); + return new ArrayList<>(Arrays.asList(text.split(" "))); + } +} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java index eb73af5a7..e151013f0 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricAdapter.java @@ -1,6 +1,7 @@ package com.dfsek.terra.fabric.world; import com.dfsek.terra.api.math.vector.Vector3; +import com.dfsek.terra.api.platform.CommandSender; import com.dfsek.terra.api.platform.block.BlockFace; import com.dfsek.terra.api.platform.block.BlockType; import com.dfsek.terra.api.platform.entity.EntityType; @@ -17,13 +18,17 @@ import com.dfsek.terra.fabric.world.block.data.FabricRotatable; import com.dfsek.terra.fabric.world.block.data.FabricSlab; import com.dfsek.terra.fabric.world.block.data.FabricStairs; import com.dfsek.terra.fabric.world.block.data.FabricWaterlogged; +import com.dfsek.terra.fabric.world.entity.FabricCommandSender; import com.dfsek.terra.fabric.world.entity.FabricEntityType; +import com.dfsek.terra.fabric.world.entity.FabricPlayer; import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.server.command.ServerCommandSource; import net.minecraft.state.property.Properties; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -60,6 +65,11 @@ public final class FabricAdapter { return new FabricBlockData(state); } + public static CommandSender adapt(ServerCommandSource serverCommandSource) { + if(serverCommandSource.getEntity() instanceof PlayerEntity) return new FabricPlayer((PlayerEntity) serverCommandSource.getEntity()); + return new FabricCommandSender(serverCommandSource); + } + public static Direction adapt(BlockFace face) { switch(face) { case NORTH: diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricCommandSender.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricCommandSender.java new file mode 100644 index 000000000..e7f946008 --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricCommandSender.java @@ -0,0 +1,23 @@ +package com.dfsek.terra.fabric.world.entity; + +import com.dfsek.terra.api.platform.CommandSender; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; + +public class FabricCommandSender implements CommandSender { + private final ServerCommandSource delegate; + + public FabricCommandSender(ServerCommandSource delegate) { + this.delegate = delegate; + } + + @Override + public void sendMessage(String message) { + delegate.sendFeedback(new LiteralText(message), true); + } + + @Override + public Object getHandle() { + return delegate; + } +} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricPlayer.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricPlayer.java new file mode 100644 index 000000000..d57d9d642 --- /dev/null +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricPlayer.java @@ -0,0 +1,37 @@ +package com.dfsek.terra.fabric.world.entity; + +import com.dfsek.terra.api.math.vector.Location; +import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.api.platform.world.World; +import com.dfsek.terra.fabric.world.FabricAdapter; +import com.dfsek.terra.fabric.world.handles.world.FabricWorldAccess; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.text.LiteralText; + +public class FabricPlayer implements Player { + private final PlayerEntity delegate; + + public FabricPlayer(PlayerEntity delegate) { + this.delegate = delegate; + } + + @Override + public void sendMessage(String message) { + delegate.sendMessage(new LiteralText(message), false); + } + + @Override + public Object getHandle() { + return delegate; + } + + @Override + public Location getLocation() { + return FabricAdapter.adapt(delegate.getBlockPos()).toLocation(new FabricWorldAccess(delegate.world)); + } + + @Override + public World getWorld() { + return new FabricWorldAccess(delegate.world); + } +} From fac4cb43a84c16b2e0d2ba8d8e144240aef8f9bd Mon Sep 17 00:00:00 2001 From: dfsek Date: Tue, 9 Mar 2021 03:15:43 -0700 Subject: [PATCH 65/95] cleanup fabric commands --- .../com/dfsek/terra/commands/CommandUtil.java | 1 + .../dfsek/terra/commands/ReloadCommand.java | 12 ++- .../dfsek/terra/fabric/TerraFabricPlugin.java | 73 +++++++++++-------- 3 files changed, 55 insertions(+), 31 deletions(-) diff --git a/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java b/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java index bac8bc882..7da197051 100644 --- a/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java +++ b/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java @@ -8,5 +8,6 @@ public final class CommandUtil { public static void registerAll(CommandManager manager) throws MalformedCommandException { manager.register("structure", StructureCommand.class); manager.register("profile", ProfileCommand.class); + manager.register("reload", ReloadCommand.class); } } diff --git a/common/src/main/java/com/dfsek/terra/commands/ReloadCommand.java b/common/src/main/java/com/dfsek/terra/commands/ReloadCommand.java index 512ccfbd2..af95197da 100644 --- a/common/src/main/java/com/dfsek/terra/commands/ReloadCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/ReloadCommand.java @@ -1,13 +1,23 @@ package com.dfsek.terra.commands; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.command.CommandTemplate; import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.injection.annotations.Inject; import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.config.lang.LangUtil; @Command() public class ReloadCommand implements CommandTemplate { + @Inject + private TerraPlugin main; + @Override public void execute(CommandSender sender) { - + if(!main.reload()) { + LangUtil.send("command.reload-error", sender); + } else { + LangUtil.send("command.reload", sender); + } } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index 7f0ad0871..70fd1baac 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -126,11 +126,11 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { private final CheckedRegistry checkedRegistry = new CheckedRegistry<>(registry); private final AddonRegistry addonRegistry = new AddonRegistry(new FabricAddon(this), this); private final LockedRegistry addonLockedRegistry = new LockedRegistry<>(addonRegistry); - private final PluginConfig plugin = new PluginConfig(); + private final PluginConfig config = new PluginConfig(); private final Transformer biomeFixer = new Transformer.Builder() .addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse(id)), new NotNullValidator<>()) .addTransform(id -> BuiltinRegistries.BIOME.get(Identifier.tryParse("minecraft:" + id.toLowerCase())), new NotNullValidator<>()).build(); - private File config; + private File dataFolder; public static TerraFabricPlugin getInstance() { return instance; @@ -161,12 +161,12 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { @Override public PluginConfig getTerraConfig() { - return plugin; + return config; } @Override public File getDataFolder() { - return config; + return dataFolder; } @Override @@ -191,7 +191,18 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { @Override public boolean reload() { - return true; + config.load(this); + LangUtil.load(config.getLanguage(), this); // Load language. + boolean succeed = registry.loadAll(this); + Map newMap = new HashMap<>(); + worldMap.forEach((seed, tw) -> { + tw.getConfig().getSamplerCache().clear(); + String packID = tw.getConfig().getTemplate().getID(); + newMap.put(seed, new TerraWorld(tw.getWorld(), registry.get(packID), this)); + }); + worldMap.clear(); + worldMap.putAll(newMap); + return succeed; } @Override @@ -266,10 +277,10 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { public void onInitialize() { instance = this; - this.config = new File(FabricLoader.getInstance().getConfigDir().toFile(), "Terra"); + this.dataFolder = new File(FabricLoader.getInstance().getConfigDir().toFile(), "Terra"); saveDefaultConfig(); - plugin.load(this); - LangUtil.load(plugin.getLanguage(), this); + config.load(this); + LangUtil.load(config.getLanguage(), this); logger.info("Initializing Terra..."); if(!addonRegistry.loadAll()) { @@ -324,36 +335,38 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { RequiredArgumentBuilder arg = RequiredArgumentBuilder.argument("arg0", StringArgumentType.string()); for(int i = 0; i < max; i++) { System.out.println("arg " + i); - int finalI = i; RequiredArgumentBuilder next = RequiredArgumentBuilder.argument("arg" + i, StringArgumentType.string()); - arg = arg.then(next.suggests((context, builder) -> { - List args = parseCommand(context.getInput()); - System.out.println("Tab completing " + finalI); - System.out.println(args); - try { - manager.tabComplete(args.remove(0), FabricAdapter.adapt(context.getSource()), args).forEach(builder::suggest); - } catch(CommandException e) { - e.printStackTrace(); - } - return builder.buildFuture(); - }).executes(context -> { - List args = parseCommand(context.getInput()); - try { - manager.execute(args.remove(0), FabricAdapter.adapt(context.getSource()), args); - } catch(CommandException e) { - e.printStackTrace(); - return -1; - } - return 1; - })); + arg = arg.then(assemble(next, manager)); } - dispatcher.register(argumentBuilder.then(arg)); + dispatcher.register(argumentBuilder.then(assemble(arg, manager))); } ); } + private RequiredArgumentBuilder assemble(RequiredArgumentBuilder in, CommandManager manager) { + return in.suggests((context, builder) -> { + List args = parseCommand(context.getInput()); + System.out.println(args); + try { + manager.tabComplete(args.remove(0), FabricAdapter.adapt(context.getSource()), args).forEach(builder::suggest); + } catch(CommandException e) { + e.printStackTrace(); + } + return builder.buildFuture(); + }).executes(context -> { + List args = parseCommand(context.getInput()); + try { + manager.execute(args.remove(0), FabricAdapter.adapt(context.getSource()), args); + } catch(CommandException e) { + e.printStackTrace(); + return -1; + } + return 1; + }); + } + private List parseCommand(String command) { if(command.startsWith("/terra ")) command = command.substring("/terra ".length()); else if(command.startsWith("/te ")) command = command.substring("/te ".length()); From 31b583910e9b0f1140ce9cdaac2344a2484ccd9c Mon Sep 17 00:00:00 2001 From: dfsek Date: Tue, 9 Mar 2021 03:48:26 -0700 Subject: [PATCH 66/95] fabric command fixes --- .../dfsek/terra/fabric/TerraFabricPlugin.java | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index 70fd1baac..c84a8b1b6 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -16,6 +16,7 @@ import com.dfsek.terra.api.event.TerraEventManager; import com.dfsek.terra.api.event.annotations.Global; import com.dfsek.terra.api.event.annotations.Priority; import com.dfsek.terra.api.event.events.config.ConfigPackPreLoadEvent; +import com.dfsek.terra.api.platform.CommandSender; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.handle.ItemHandle; import com.dfsek.terra.api.platform.handle.WorldHandle; @@ -49,7 +50,6 @@ import com.dfsek.terra.registry.master.AddonRegistry; import com.dfsek.terra.registry.master.ConfigRegistry; import com.dfsek.terra.world.TerraWorld; import com.mojang.brigadier.arguments.StringArgumentType; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import net.fabricmc.api.EnvType; import net.fabricmc.api.ModInitializer; @@ -92,6 +92,9 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + public class TerraFabricPlugin implements TerraPlugin, ModInitializer { @@ -323,23 +326,19 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> { - LiteralArgumentBuilder argumentBuilder = net.minecraft.server.command.CommandManager.literal("terra").executes(context -> { - System.out.println(context.getNodes()); - System.out.println(context); - System.out.println(context.getInput()); - return 1; - }); - int max = manager.getMaxArgumentDepth(); System.out.println("MAX:" + max); - RequiredArgumentBuilder arg = RequiredArgumentBuilder.argument("arg0", StringArgumentType.string()); + RequiredArgumentBuilder arg = argument("arg" + (max - 1), StringArgumentType.word()); for(int i = 0; i < max; i++) { System.out.println("arg " + i); - RequiredArgumentBuilder next = RequiredArgumentBuilder.argument("arg" + i, StringArgumentType.string()); + RequiredArgumentBuilder next = argument("arg" + (max - i - 1), StringArgumentType.word()); - arg = arg.then(assemble(next, manager)); + arg = next.then(assemble(arg, manager)); } - dispatcher.register(argumentBuilder.then(assemble(arg, manager))); + + dispatcher.register(literal("terra").executes(context -> 1).then(assemble(arg, manager))); + dispatcher.register(literal("te").executes(context -> 1).then(assemble(arg, manager))); + //dispatcher.register(literal("te").redirect(root)); } ); @@ -348,11 +347,11 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { private RequiredArgumentBuilder assemble(RequiredArgumentBuilder in, CommandManager manager) { return in.suggests((context, builder) -> { List args = parseCommand(context.getInput()); - System.out.println(args); + CommandSender sender = FabricAdapter.adapt(context.getSource()); try { - manager.tabComplete(args.remove(0), FabricAdapter.adapt(context.getSource()), args).forEach(builder::suggest); + manager.tabComplete(args.remove(0), sender, args).forEach(builder::suggest); } catch(CommandException e) { - e.printStackTrace(); + sender.sendMessage(e.getMessage()); } return builder.buildFuture(); }).executes(context -> { @@ -370,7 +369,9 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { private List parseCommand(String command) { if(command.startsWith("/terra ")) command = command.substring("/terra ".length()); else if(command.startsWith("/te ")) command = command.substring("/te ".length()); - return new ArrayList<>(Arrays.asList(command.split(" "))); + List c = new ArrayList<>(Arrays.asList(command.split(" "))); + if(command.endsWith(" ")) c.add(""); + return c; } From f5c0174473da4f48293e32bb70f08d48a28558d2 Mon Sep 17 00:00:00 2001 From: dfsek Date: Tue, 9 Mar 2021 20:05:42 -0700 Subject: [PATCH 67/95] more command stuff --- .../api/command/TerraCommandManager.java | 16 +++-- .../command/exception/ExecutionException.java | 13 ++++ .../dfsek/terra/api/platform/world/World.java | 8 ++- .../dfsek/terra/api/util/ReflectionUtil.java | 8 +++ .../dfsek/terra/commands/AddonsCommand.java | 17 ++++++ .../com/dfsek/terra/commands/CommandUtil.java | 1 + .../structure/ScriptArgumentParser.java | 18 ++++++ .../commands/structure/ScriptCompleter.java | 21 +++++++ .../structure/StructureLoadCommand.java | 55 ++++++++++++++++- .../dfsek/terra/config/dummy/DummyWorld.java | 5 -- .../bukkit/command/command/AddonsCommand.java | 41 ------------- .../bukkit/command/command/ReloadCommand.java | 48 --------------- .../bukkit/command/command/TerraCommand.java | 60 ------------------- .../command/profile/ProfileCommand.java | 46 -------------- .../command/command/profile/QueryCommand.java | 46 -------------- .../command/command/profile/ResetCommand.java | 49 --------------- .../command/command/profile/StartCommand.java | 49 --------------- .../command/command/profile/StopCommand.java | 49 --------------- .../dfsek/terra/bukkit/world/BukkitWorld.java | 5 -- .../fabric/world/handles/FabricWorld.java | 5 -- .../world/FabricSeededWorldAccess.java | 5 -- .../handles/world/FabricWorldAccess.java | 5 -- .../com/dfsek/terra/platform/DirectWorld.java | 5 -- 23 files changed, 151 insertions(+), 424 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/api/command/exception/ExecutionException.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/AddonsCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/structure/ScriptArgumentParser.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/structure/ScriptCompleter.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/AddonsCommand.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/ReloadCommand.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/TerraCommand.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/profile/ProfileCommand.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/profile/QueryCommand.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/profile/ResetCommand.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/profile/StartCommand.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/profile/StopCommand.java diff --git a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java index bc729e041..14bfb52c5 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java +++ b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java @@ -12,9 +12,11 @@ import com.dfsek.terra.api.command.annotation.type.PlayerCommand; import com.dfsek.terra.api.command.annotation.type.WorldCommand; import com.dfsek.terra.api.command.arg.ArgumentParser; import com.dfsek.terra.api.command.exception.CommandException; +import com.dfsek.terra.api.command.exception.ExecutionException; import com.dfsek.terra.api.command.exception.InvalidArgumentsException; import com.dfsek.terra.api.command.exception.MalformedCommandException; import com.dfsek.terra.api.command.exception.SwitchFormatException; +import com.dfsek.terra.api.command.tab.TabCompleter; import com.dfsek.terra.api.injection.Injector; import com.dfsek.terra.api.injection.exception.InjectionException; import com.dfsek.terra.api.platform.CommandSender; @@ -128,7 +130,7 @@ public class TerraCommandManager implements CommandManager { invoke(commandClass, state, commandHolder); } - private void invoke(Class clazz, ExecutionState state, CommandHolder holder) throws MalformedCommandException { + private void invoke(Class clazz, ExecutionState state, CommandHolder holder) throws CommandException { try { CommandTemplate template = clazz.getConstructor().newInstance(); @@ -166,7 +168,11 @@ public class TerraCommandManager implements CommandManager { } } - template.execute(state.getSender()); + try { + template.execute(state.getSender()); + } catch(Throwable e) { + throw new ExecutionException("Failed to execute command: ", e); + } } catch(InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | InjectionException e) { throw new MalformedCommandException("Unable to reflectively instantiate command: ", e); } @@ -216,9 +222,11 @@ public class TerraCommandManager implements CommandManager { } try { if(args.size() <= holder.arguments.size()) { - completions.addAll(holder.arguments.get(args.size() - 1).tabCompleter().getConstructor().newInstance().complete(sender)); + TabCompleter completer = holder.arguments.get(args.size() - 1).tabCompleter().getConstructor().newInstance(); + pluginInjector.inject(completer); + completions.addAll(completer.complete(sender)); } - } catch(InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { + } catch(InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | InjectionException e) { throw new MalformedCommandException("Unable to reflectively instantiate tab-completer: ", e); } return completions; diff --git a/common/src/main/java/com/dfsek/terra/api/command/exception/ExecutionException.java b/common/src/main/java/com/dfsek/terra/api/command/exception/ExecutionException.java new file mode 100644 index 000000000..061bfc64b --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/command/exception/ExecutionException.java @@ -0,0 +1,13 @@ +package com.dfsek.terra.api.command.exception; + +public class ExecutionException extends CommandException { + private static final long serialVersionUID = -6345523475880607959L; + + public ExecutionException(String message) { + super(message); + } + + public ExecutionException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/common/src/main/java/com/dfsek/terra/api/platform/world/World.java b/common/src/main/java/com/dfsek/terra/api/platform/world/World.java index 3a96ba1c5..1dbcd85a6 100644 --- a/common/src/main/java/com/dfsek/terra/api/platform/world/World.java +++ b/common/src/main/java/com/dfsek/terra/api/platform/world/World.java @@ -25,11 +25,17 @@ public interface World extends Handle { Chunk getChunkAt(int x, int z); + default Chunk getChunkAt(Location location) { + return getChunkAt(location.getBlockX() >> 4, location.getBlockZ() >> 4); + } + File getWorldFolder(); Block getBlockAt(int x, int y, int z); - Block getBlockAt(Location l); + default Block getBlockAt(Location l) { + return getBlockAt(l.getBlockX(), l.getBlockY(), l.getBlockZ()); + } Entity spawnEntity(Location location, EntityType entityType); diff --git a/common/src/main/java/com/dfsek/terra/api/util/ReflectionUtil.java b/common/src/main/java/com/dfsek/terra/api/util/ReflectionUtil.java index 74ee5fecd..34c70dae9 100644 --- a/common/src/main/java/com/dfsek/terra/api/util/ReflectionUtil.java +++ b/common/src/main/java/com/dfsek/terra/api/util/ReflectionUtil.java @@ -2,9 +2,12 @@ package com.dfsek.terra.api.util; import org.jetbrains.annotations.NotNull; +import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.Arrays; +import java.util.function.Consumer; import java.util.stream.Stream; public class ReflectionUtil { @@ -25,4 +28,9 @@ public class ReflectionUtil { } return result; } + + public static void ifAnnotationPresent(AnnotatedElement element, Class annotation, Consumer operation) { + T a = element.getAnnotation(annotation); + if(a != null) operation.accept(a); + } } diff --git a/common/src/main/java/com/dfsek/terra/commands/AddonsCommand.java b/common/src/main/java/com/dfsek/terra/commands/AddonsCommand.java new file mode 100644 index 000000000..26a69caf6 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/AddonsCommand.java @@ -0,0 +1,17 @@ +package com.dfsek.terra.commands; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.platform.CommandSender; + +public class AddonsCommand implements CommandTemplate { + @Inject + private TerraPlugin main; + + @Override + public void execute(CommandSender sender) { + sender.sendMessage("Installed Addons:"); + main.getAddons().forEach(addon -> sender.sendMessage(" - " + addon.getName() + " v" + addon.getVersion() + " by " + addon.getAuthor())); + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java b/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java index 7da197051..c6157d439 100644 --- a/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java +++ b/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java @@ -9,5 +9,6 @@ public final class CommandUtil { manager.register("structure", StructureCommand.class); manager.register("profile", ProfileCommand.class); manager.register("reload", ReloadCommand.class); + manager.register("addons", AddonsCommand.class); } } diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/ScriptArgumentParser.java b/common/src/main/java/com/dfsek/terra/commands/structure/ScriptArgumentParser.java new file mode 100644 index 000000000..3c34c74af --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/structure/ScriptArgumentParser.java @@ -0,0 +1,18 @@ +package com.dfsek.terra.commands.structure; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.arg.ArgumentParser; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.api.structures.script.StructureScript; + +public class ScriptArgumentParser implements ArgumentParser { + @Inject + private TerraPlugin main; + + @Override + public StructureScript parse(CommandSender sender, String arg) { + return main.getWorld(((Player) sender).getWorld()).getConfig().getScriptRegistry().get(arg); + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/ScriptCompleter.java b/common/src/main/java/com/dfsek/terra/commands/structure/ScriptCompleter.java new file mode 100644 index 000000000..c650ef685 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/structure/ScriptCompleter.java @@ -0,0 +1,21 @@ +package com.dfsek.terra.commands.structure; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.tab.TabCompleter; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.api.structures.script.StructureScript; + +import java.util.List; +import java.util.stream.Collectors; + +public class ScriptCompleter implements TabCompleter { + @Inject + private TerraPlugin main; + + @Override + public List complete(CommandSender sender) { + return main.getWorld(((Player) sender).getWorld()).getConfig().getScriptRegistry().entries().stream().map(StructureScript::getId).collect(Collectors.toList()); + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java b/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java index 3f8382588..b395b50b8 100644 --- a/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java @@ -1,15 +1,35 @@ package com.dfsek.terra.commands.structure; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.command.CommandTemplate; import com.dfsek.terra.api.command.annotation.Argument; import com.dfsek.terra.api.command.annotation.Command; import com.dfsek.terra.api.command.annotation.Switch; import com.dfsek.terra.api.command.annotation.inject.ArgumentTarget; +import com.dfsek.terra.api.command.annotation.inject.SwitchTarget; +import com.dfsek.terra.api.command.annotation.type.DebugCommand; +import com.dfsek.terra.api.command.annotation.type.PlayerCommand; +import com.dfsek.terra.api.command.annotation.type.WorldCommand; import com.dfsek.terra.api.command.arg.IntegerArgumentParser; +import com.dfsek.terra.api.injection.annotations.Inject; import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.api.structures.script.StructureScript; +import com.dfsek.terra.api.structures.structure.Rotation; +import com.dfsek.terra.api.util.FastRandom; +import java.util.concurrent.ThreadLocalRandom; + +@PlayerCommand +@DebugCommand +@WorldCommand @Command( arguments = { + @Argument( + value = "structure", + tabCompleter = ScriptCompleter.class, + argumentParser = ScriptArgumentParser.class + ), @Argument( value = "rotation", required = false, @@ -25,10 +45,43 @@ import com.dfsek.terra.api.platform.CommandSender; ) public class StructureLoadCommand implements CommandTemplate { @ArgumentTarget("rotation") - private Integer rotation; + private Integer rotation = 0; + + @SwitchTarget("chunk") + private boolean chunk; + + @ArgumentTarget("structure") + private StructureScript script; + + @Inject + private TerraPlugin main; @Override public void execute(CommandSender sender) { System.out.println(rotation); + + Player player = (Player) sender; + + long t = System.nanoTime(); + FastRandom random = new FastRandom(ThreadLocalRandom.current().nextLong()); + Rotation r; + try { + r = Rotation.fromDegrees(rotation); + } catch(Exception e) { + sender.sendMessage("Invalid rotation: " + rotation); + return; + } + if(script == null) { + sender.sendMessage("Invalid structure."); + return; + } + if(this.chunk) { + script.execute(player.getLocation(), player.getWorld().getChunkAt(player.getLocation()), random, r); + } else { + script.execute(player.getLocation(), random, r); + } + long l = System.nanoTime() - t; + + sender.sendMessage("Took " + ((double) l) / 1000000 + "ms"); } } diff --git a/common/src/main/java/com/dfsek/terra/config/dummy/DummyWorld.java b/common/src/main/java/com/dfsek/terra/config/dummy/DummyWorld.java index a71cb0867..06cd712fc 100644 --- a/common/src/main/java/com/dfsek/terra/config/dummy/DummyWorld.java +++ b/common/src/main/java/com/dfsek/terra/config/dummy/DummyWorld.java @@ -63,11 +63,6 @@ public class DummyWorld implements World { throw new UnsupportedOperationException("Cannot get block in DummyWorld"); } - @Override - public Block getBlockAt(Location l) { - throw new UnsupportedOperationException("Cannot get block in DummyWorld"); - } - @Override public Entity spawnEntity(Location location, EntityType entityType) { throw new UnsupportedOperationException("Cannot spawn entity in DummyWorld"); diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/AddonsCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/AddonsCommand.java deleted file mode 100644 index c7dba7e80..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/AddonsCommand.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.dfsek.terra.bukkit.command.command; - -import com.dfsek.terra.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; -import java.util.List; - -public class AddonsCommand extends Command { - public AddonsCommand(Command parent) { - super(parent); - } - - @Override - public String getName() { - return "addons"; - } - - @Override - public List getSubCommands() { - return Collections.emptyList(); - } - - @Override - public boolean execute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) { - sender.sendMessage("Installed Addons:"); - getMain().getAddons().forEach(addon -> sender.sendMessage(" - " + addon.getName() + " v" + addon.getVersion() + " by " + addon.getAuthor())); - return true; - } - - @Override - public int arguments() { - return 0; - } - - @Override - public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - return Collections.emptyList(); - } -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/ReloadCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/ReloadCommand.java deleted file mode 100644 index 50e6a2cc9..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/ReloadCommand.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.dfsek.terra.bukkit.command.command; - - -import com.dfsek.terra.bukkit.BukkitCommandSender; -import com.dfsek.terra.bukkit.command.Command; -import com.dfsek.terra.bukkit.command.DebugCommand; -import com.dfsek.terra.config.lang.LangUtil; -import org.bukkit.command.CommandSender; -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; -import java.util.List; - -public class ReloadCommand extends Command implements DebugCommand { - public ReloadCommand(Command parent) { - super(parent); - } - - @Override - public String getName() { - return "reload"; - } - - @Override - public List getSubCommands() { - return Collections.emptyList(); - } - - @Override - public boolean execute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) { - if(!getMain().reload()) { - LangUtil.send("command.reload-error", new BukkitCommandSender(sender)); - return true; - } - LangUtil.send("command.reload", new BukkitCommandSender(sender)); - return true; - } - - @Override - public int arguments() { - return 0; - } - - @Override - public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - return Collections.emptyList(); - } -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/TerraCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/TerraCommand.java deleted file mode 100644 index 639a63345..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/TerraCommand.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.dfsek.terra.bukkit.command.command; - -import com.dfsek.terra.api.TerraPlugin; -import com.dfsek.terra.bukkit.BukkitCommandSender; -import com.dfsek.terra.bukkit.command.Command; -import com.dfsek.terra.bukkit.command.command.biome.BiomeCommand; -import com.dfsek.terra.bukkit.command.command.geometry.GeometryCommand; -import com.dfsek.terra.bukkit.command.command.profile.ProfileCommand; -import com.dfsek.terra.bukkit.command.command.structure.StructureCommand; -import com.dfsek.terra.config.lang.LangUtil; -import org.bukkit.command.CommandSender; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -public class TerraCommand extends Command { - private final List commands = Arrays.asList(new ReloadCommand(this), - new BiomeCommand(this), - new ProfileCommand(this), - new SaveDataCommand(this), - new StructureCommand(this), - new GeometryCommand(this), - new FixChunkCommand(this), - new VersionCommand(this), - new GetBlockCommand(this), - new PacksCommand(this), - new AddonsCommand(this)); - - public TerraCommand(TerraPlugin main) { - super(main); - } - - @Override - public String getName() { - return "terra"; - } - - @Override - public List getSubCommands() { - return commands; - } - - @Override - public boolean execute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) { - LangUtil.send("command.main-menu", new BukkitCommandSender(sender)); - return true; - } - - @Override - public int arguments() { - return 0; - } - - @Override - public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - return Collections.emptyList(); - } -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/profile/ProfileCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/profile/ProfileCommand.java deleted file mode 100644 index 5eb4b4ec1..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/profile/ProfileCommand.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.dfsek.terra.bukkit.command.command.profile; - -import com.dfsek.terra.bukkit.BukkitCommandSender; -import com.dfsek.terra.bukkit.command.WorldCommand; -import com.dfsek.terra.config.lang.LangUtil; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -public class ProfileCommand extends WorldCommand { - public ProfileCommand(com.dfsek.terra.bukkit.command.Command parent) { - super(parent); - } - - @Override - public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) { - LangUtil.send("command.profile.main-menu", new BukkitCommandSender(sender)); - return true; - } - - @Override - public String getName() { - return "profile"; - } - - @Override - public List getSubCommands() { - return Arrays.asList(new QueryCommand(this), new ResetCommand(this), new StartCommand(this), new StopCommand(this)); - } - - @Override - public int arguments() { - return 1; - } - - @Override - public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - return Collections.emptyList(); - } -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/profile/QueryCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/profile/QueryCommand.java deleted file mode 100644 index b958b83cb..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/profile/QueryCommand.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.dfsek.terra.bukkit.command.command.profile; - -import com.dfsek.terra.bukkit.command.WorldCommand; -import com.dfsek.terra.bukkit.world.BukkitAdapter; -import com.dfsek.terra.profiler.WorldProfiler; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; -import java.util.List; - -public class QueryCommand extends WorldCommand { - public QueryCommand(com.dfsek.terra.bukkit.command.Command parent) { - super(parent); - } - - @Override - public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) { - WorldProfiler profile = getMain().getWorld(BukkitAdapter.adapt(world)).getProfiler(); - sender.sendMessage(profile.getResultsFormatted()); - return true; - } - - @Override - public String getName() { - return "query"; - } - - @Override - public List getSubCommands() { - return Collections.emptyList(); - } - - @Override - public int arguments() { - return 0; - } - - @Override - public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - return Collections.emptyList(); - } -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/profile/ResetCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/profile/ResetCommand.java deleted file mode 100644 index 958b48eb4..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/profile/ResetCommand.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.dfsek.terra.bukkit.command.command.profile; - -import com.dfsek.terra.bukkit.BukkitCommandSender; -import com.dfsek.terra.bukkit.command.WorldCommand; -import com.dfsek.terra.bukkit.world.BukkitAdapter; -import com.dfsek.terra.config.lang.LangUtil; -import com.dfsek.terra.profiler.WorldProfiler; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; -import java.util.List; - -public class ResetCommand extends WorldCommand { - public ResetCommand(com.dfsek.terra.bukkit.command.Command parent) { - super(parent); - } - - @Override - public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) { - WorldProfiler profile = getMain().getWorld(BukkitAdapter.adapt(world)).getProfiler(); - profile.reset(); - LangUtil.send("command.profile.reset", new BukkitCommandSender(sender)); - return true; - } - - @Override - public String getName() { - return "reset"; - } - - @Override - public List getSubCommands() { - return Collections.emptyList(); - } - - @Override - public int arguments() { - return 0; - } - - @Override - public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - return Collections.emptyList(); - } -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/profile/StartCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/profile/StartCommand.java deleted file mode 100644 index bdd5055d4..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/profile/StartCommand.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.dfsek.terra.bukkit.command.command.profile; - -import com.dfsek.terra.bukkit.BukkitCommandSender; -import com.dfsek.terra.bukkit.command.WorldCommand; -import com.dfsek.terra.bukkit.world.BukkitAdapter; -import com.dfsek.terra.config.lang.LangUtil; -import com.dfsek.terra.profiler.WorldProfiler; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; -import java.util.List; - -public class StartCommand extends WorldCommand { - public StartCommand(com.dfsek.terra.bukkit.command.Command parent) { - super(parent); - } - - @Override - public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) { - WorldProfiler profile = getMain().getWorld(BukkitAdapter.adapt(world)).getProfiler(); - profile.setProfiling(true); - LangUtil.send("command.profile.start", new BukkitCommandSender(sender)); - return true; - } - - @Override - public String getName() { - return "start"; - } - - @Override - public List getSubCommands() { - return Collections.emptyList(); - } - - @Override - public int arguments() { - return 0; - } - - @Override - public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - return Collections.emptyList(); - } -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/profile/StopCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/profile/StopCommand.java deleted file mode 100644 index 322cff032..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/profile/StopCommand.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.dfsek.terra.bukkit.command.command.profile; - -import com.dfsek.terra.bukkit.BukkitCommandSender; -import com.dfsek.terra.bukkit.command.WorldCommand; -import com.dfsek.terra.bukkit.world.BukkitAdapter; -import com.dfsek.terra.config.lang.LangUtil; -import com.dfsek.terra.profiler.WorldProfiler; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; -import java.util.List; - -public class StopCommand extends WorldCommand { - public StopCommand(com.dfsek.terra.bukkit.command.Command parent) { - super(parent); - } - - @Override - public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) { - WorldProfiler profile = getMain().getWorld(BukkitAdapter.adapt(world)).getProfiler(); - profile.setProfiling(false); - LangUtil.send("command.profile.stop", new BukkitCommandSender(sender)); - return true; - } - - @Override - public String getName() { - return "stop"; - } - - @Override - public List getSubCommands() { - return Collections.emptyList(); - } - - @Override - public int arguments() { - return 0; - } - - @Override - public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - return Collections.emptyList(); - } -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitWorld.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitWorld.java index 05a9fd982..294314cbf 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitWorld.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/BukkitWorld.java @@ -67,11 +67,6 @@ public class BukkitWorld implements World { return new BukkitBlock(delegate.getBlockAt(x, y, z)); } - @Override - public Block getBlockAt(Location l) { - return new BukkitBlock(delegate.getBlockAt(l.getBlockX(), l.getBlockY(), l.getBlockZ())); - } - @Override public Entity spawnEntity(Location location, EntityType entityType) { return new BukkitEntity(delegate.spawnEntity(BukkitAdapter.adapt(location), ((BukkitEntityType) entityType).getHandle())); diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java index 840559c83..097ddfcb1 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/FabricWorld.java @@ -85,11 +85,6 @@ public class FabricWorld implements World, FabricWorldHandle { return ((ServerWorldAccess) ((FabricWorld) obj).delegate.world).toServerWorld().equals(((ServerWorldAccess) delegate.world).toServerWorld()); } - @Override - public Block getBlockAt(Location l) { - return getBlockAt(l.getBlockX(), l.getBlockY(), l.getBlockZ()); - } - @Override public Entity spawnEntity(Location location, EntityType entityType) { net.minecraft.entity.Entity entity = FabricAdapter.adapt(entityType).create(delegate.world); diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricSeededWorldAccess.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricSeededWorldAccess.java index 3db150d99..05b1dbb1e 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricSeededWorldAccess.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricSeededWorldAccess.java @@ -73,11 +73,6 @@ public class FabricSeededWorldAccess implements World, FabricWorldHandle { return new FabricBlock(pos, handle.worldAccess); } - @Override - public Block getBlockAt(Location l) { - return getBlockAt(l.getBlockX(), l.getBlockY(), l.getBlockZ()); - } - @Override public Entity spawnEntity(Location location, EntityType entityType) { net.minecraft.entity.Entity entity = FabricAdapter.adapt(entityType).create((ServerWorld) handle.worldAccess); diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java index 3bf422496..a8dfe28b1 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java @@ -72,11 +72,6 @@ public class FabricWorldAccess implements World, FabricWorldHandle { return new FabricBlock(pos, delegate); } - @Override - public Block getBlockAt(Location l) { - return getBlockAt(l.getBlockX(), l.getBlockY(), l.getBlockZ()); - } - @Override public Entity spawnEntity(Location location, EntityType entityType) { net.minecraft.entity.Entity entity = FabricAdapter.adapt(entityType).create(((ServerWorldAccess) delegate).toServerWorld()); diff --git a/platforms/region/src/main/java/com/dfsek/terra/platform/DirectWorld.java b/platforms/region/src/main/java/com/dfsek/terra/platform/DirectWorld.java index 1fce4cd70..3aacfabb9 100644 --- a/platforms/region/src/main/java/com/dfsek/terra/platform/DirectWorld.java +++ b/platforms/region/src/main/java/com/dfsek/terra/platform/DirectWorld.java @@ -82,11 +82,6 @@ public class DirectWorld implements World { return new DirectBlock(this, new Vector3(x, y, z)); } - @Override - public Block getBlockAt(Location l) { - return getBlockAt(l.getBlockX(), l.getBlockY(), l.getBlockZ()); - } - @Override public Entity spawnEntity(Location location, EntityType entityType) { return null; From 5820fe1db3256dc272c8b93665b0a6fe24d7d974 Mon Sep 17 00:00:00 2001 From: dfsek Date: Tue, 9 Mar 2021 20:05:52 -0700 Subject: [PATCH 68/95] fix imageloader issue --- common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java | 1 + 1 file changed, 1 insertion(+) diff --git a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java index 6139ef7f8..5755ec0e9 100644 --- a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java +++ b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPack.java @@ -274,6 +274,7 @@ public class ConfigPack implements LoaderRegistrar { .registerLoader(NoiseSeeded.class, new NoiseSamplerBuilderLoader(noiseRegistry)) .registerLoader(SingleBiomeProviderTemplate.class, SingleBiomeProviderTemplate::new) .registerLoader(BiomePipelineTemplate.class, () -> new BiomePipelineTemplate(main)) + .registerLoader(ImageProviderTemplate.class, () -> new ImageProviderTemplate(biomeRegistry)) .registerLoader(ImageSamplerTemplate.class, () -> new ImageProviderTemplate(biomeRegistry)); } From 5e9b841cac6b0a79d4f573e077bf2d1b4e3230c1 Mon Sep 17 00:00:00 2001 From: dfsek Date: Tue, 9 Mar 2021 23:20:47 -0700 Subject: [PATCH 69/95] trigger block re-render on Fabric --- .../java/com/dfsek/terra/fabric/world/block/FabricBlock.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlock.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlock.java index 93a1e9191..a4d2d0017 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlock.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlock.java @@ -21,7 +21,7 @@ public class FabricBlock implements Block { @Override public void setBlockData(BlockData data, boolean physics) { - delegate.worldAccess.setBlockState(delegate.position, ((FabricBlockData) data).getHandle(), 0, 0); + delegate.worldAccess.setBlockState(delegate.position, ((FabricBlockData) data).getHandle(), physics ? 3 : 1042, 0); } @Override From 13346daa6a6858fb737765fd275f7aab37f0f48f Mon Sep 17 00:00:00 2001 From: Daniil Z Date: Wed, 10 Mar 2021 09:30:14 +0300 Subject: [PATCH 70/95] Russian translation (#88) * Russian translation * Move file to commons --- common/src/main/resources/lang/ru.yml | 122 ++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 common/src/main/resources/lang/ru.yml diff --git a/common/src/main/resources/lang/ru.yml b/common/src/main/resources/lang/ru.yml new file mode 100644 index 000000000..f0c8db834 --- /dev/null +++ b/common/src/main/resources/lang/ru.yml @@ -0,0 +1,122 @@ +enable: + - "Если вам нравится Terra, пожалуйста, поддержите проект на Patreon!" + - "Вы получите доступ к экспериментальным функциям ещё до их релиза!" + - "Поддержите проект здесь: https://www.patreon.com/dfsek" +disable: + - "Благодарим за использование Terra!" +command: + debug-only: "Эта команда может быть введена только в режиме отладки!" + player-only: "Эту команду могут вводить только игроки!" + invalid: "Неверная команда. (Ожидался аргумент %1$s, найден %2$s)." + players-only: "Команда только для игроков." + world: "Эта команда может быть введена только в мире с Terra!" + reload: "Конфигурации Terra перезагружена." + reload-error: "Во время перезагрузки конфигураций Terra произошла ошибка. Просмотрите логи для более детальной информации." + version: "This server is running Terra version \"%1$s\", on platform \"%2$s\"" + main-menu: + - "--------------------Terra--------------------" + - "reload - Перезагрузить конфигурации" + - "biome - Узнать текущий биом" + - "ore - Сгенерировать жилу руд на месте вашего взора (Для отладки)" + - "save-data - Сохранить данные популяции" + - "structure - Загрузить и экспортировать структуры" + - "profile - Команды профайлера" + - "image - Команды образа/интерфейса" + biome: + biome-found: "Биом найден на (%1$s, %2$s)" + unable-to-locate: "Не получилось найти биом." + invalid-radius: "Неверный радиус: \"%s\"" + invalid: "Неверный ID биома: \"%s\"" + in: "Вы находитесь в \"%s\"" + packs: + main: "Установленные наборы конфигураций:" + pack: " - %1$s вер.%3$s от %2$s" + none: "Наборы конфигураций не установлены." + ore: + main-menu: + - "---------------Terra/ore---------------" + - "Генерирует жилу руд на месте вашего взора." + out-of-range: "Блок слишком далеко" + invalid-ore: "Не получилось найти руду \"%s\"" + geometry: + main-menu: + - "---------------Terra/geometry----------------" + - "Различные команды отладки воксельной геометрии" + - "sphere - Сгенерировать сферу" + - "deformsphere - Сгенерировать деформированную сферу" + - "tube - Сгенерировать трубу" + deform: + invalid-radius: "Неверный радиус: \"%s\"" + invalid-deform: "Неверная деформация: \"%s\"" + invalid-frequency: "Неверная частота: \"%s\"" + sphere: + invalid-radius: "Неверный радиус: \"%s\"" + tube: + invalid-radius: "Неверный радиус: \"%s\"" + image: + main-menu: + - "---------------Terra/image---------------" + - "render - Прорендерить образ с указанными шириной и высотой, который позже может быть импортирован как мир." + - "gui - Открыть интерфейс отладки (Должно быть включено в конфигурации)" + gui: + main-menu: + - "-------------Terra/image/gui-------------" + - "raw - Открыть интерфейс с сырыми данными биомов" + - "step - Перерендерить данные для более ясного видения границ" + debug: "Для использования этого интерфейса должен быть включен режим отладки! Режим отладки НЕБЕЗОПАСЕН ДЛЯ СЕРВЕРОВ!" + render: + save: "Образ сохранен как \"%s\"" + error: "Во время генерации образа произошла ошибка!" + profile: + main-menu: + - "---------------Terra/profile---------------" + - "start - Начать анализ профайлером" + - "stop - Остановить анализ профайлером" + - "query - Получить данные профайлера" + - "reset - Обнулить данные профайлера" + reset: "Данные профайлера были обнулены." + start: "Анализ профайлером начат." + stop: "Анализ профайлером остановлен." + structure: + main-menu: + - "---------------Terra/structure---------------" + - "export - Экспортировать выделение WorldEdit'а как структуру Terra" + - "load - Загрузить структуру Terra" + invalid-radius: "Неверный радиус: \"%s\"" + invalid-rotation: "Неверный поворот: \"%s\"" + invalid: "Неверный ID структуры: \"%s\"" + export: "Структура сохранена как \"%s\"" +world-config: + load: "Значения конфигурации мира \"%s\" загружаются..." + not-found: "Конфигурация мира \"%s\" не найдена. Копирование обычной." + using-image: "Загрузка мира с образа." + error: "Не получилось загрузить конфигурацию мира %s" + done: "Загрузка мира \"%1$s\" завершена. Затрачено времени: %2$sмс" +config-pack: + loaded: "Набор конфигураций %1$s вер.%4$s от %3$s загружен за %2$sмс." +config: + loaded: "Загружен %1$s с файла %2$s" + loaded-all: "Загружено %1$s %2$s за %3$sмс." + error: + invalid-failover: "Неверный тип аварийного переключения: \"%s\"" + duplicate: "Дублирующийся ID найден в файле: %s" + file: + - "Ошибка конфигурации объекта Terra. Файл: %1$s" + - "%2$s" + - "Прежде чем продолжить, исправьте это!" + generic: + - "Во время загрузки конфигураций произошла ошибка." + - "Пожалуйста, сообщите об этом разработчикам Terra." +warning: + no-population: "Не было загружено популяторов чанков. Если вы впервые запускаете сервер с Terra или создаете новый мир, то всё в порядке." +error: + severe-config: "Несколько ошибок конфигруации не позволили Terra сгенерировать область нормально по этим координатам: %1$s, %2$s. Пожалуйста, проверьте свою конфигурацию на наличие ошибок. Все ошибки были показаны выше." +debug: + data-save: "Данные популяции мира \"%s\" сохранены" +use-paper: + - "Похоже, что вы используете Spigot/CraftBukkit." + - "Пускай Terra и &oработает&r со Spigot, часть функционала плагина не работает. (Terra не тестировался с CraftBukkit; не ожидайте поддержки для CraftBukkit)." + - "Чтобы получить весь функционал Terra, пожалуйста, используйте Paper." + - "Кроме того, Paper намного производительнее, чем Spigot, а все плагины Spigot должны работать и на Paper!" + - "Если вы хотите получить лучший опыт использования Terra и иных плагинов, пожалуйста, предпочтите Paper." + - "Больше о Paper можно узнать на сайте: https://papermc.io/" From 67aae877542e69abe6087b017d9273f6c5d220cb Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 10 Mar 2021 01:57:01 -0700 Subject: [PATCH 71/95] work on fabric commands --- .../java/com/dfsek/terra/api/TerraPlugin.java | 4 ++ .../api/command/TerraCommandManager.java | 15 ++++-- .../api/command/annotation/Argument.java | 2 + .../com/dfsek/terra/commands/CommandUtil.java | 1 + .../terra/commands/StructureCommand.java | 6 +++ .../dfsek/terra/commands/VersionCommand.java | 20 ++++++++ .../commands/structure/SpawnCommand.java | 46 +++++++++++++++++++ .../structure/StructureLoadCommand.java | 6 ++- .../{ => argument}/ScriptArgumentParser.java | 2 +- .../{ => completer}/RotationCompleter.java | 2 +- .../{ => completer}/ScriptCompleter.java | 2 +- .../provider/SingleBiomeProviderTemplate.java | 6 +-- .../command/command/VersionCommand.java | 44 ------------------ 13 files changed, 102 insertions(+), 54 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/commands/VersionCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/structure/SpawnCommand.java rename common/src/main/java/com/dfsek/terra/commands/structure/{ => argument}/ScriptArgumentParser.java (92%) rename common/src/main/java/com/dfsek/terra/commands/structure/{ => completer}/RotationCompleter.java (86%) rename common/src/main/java/com/dfsek/terra/commands/structure/{ => completer}/ScriptCompleter.java (93%) delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/VersionCommand.java diff --git a/common/src/main/java/com/dfsek/terra/api/TerraPlugin.java b/common/src/main/java/com/dfsek/terra/api/TerraPlugin.java index 07f9441e4..6bd141802 100644 --- a/common/src/main/java/com/dfsek/terra/api/TerraPlugin.java +++ b/common/src/main/java/com/dfsek/terra/api/TerraPlugin.java @@ -49,4 +49,8 @@ public interface TerraPlugin extends LoaderRegistrar { DebugLogger getDebugLogger(); EventManager getEventManager(); + + default String getVersion() { + return "@VERSION@"; + } } diff --git a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java index 14bfb52c5..0a89fdd15 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java +++ b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java @@ -150,7 +150,11 @@ public class TerraCommandManager implements CommandManager { pluginInjector.inject(argumentParser); field.setAccessible(true); - field.set(template, argumentParser.parse(state.getSender(), state.getArgument(argument))); + String value = state.getArgument(argument); + + if(value == null) value = holder.argumentMap.get(argumentTarget.value()).defaultValue(); + + field.set(template, argumentParser.parse(state.getSender(), value)); } if(field.isAnnotationPresent(SwitchTarget.class)) { SwitchTarget switchTarget = field.getAnnotation(SwitchTarget.class); @@ -200,7 +204,7 @@ public class TerraCommandManager implements CommandManager { private int getMaxArgumentDepth(CommandHolder holder) { int max = 0; - max = FastMath.max(holder.arguments.size(), max); + max = FastMath.max(holder.arguments.size() + holder.switchList.size(), max); for(CommandHolder value : holder.subcommands.values()) { max = FastMath.max(max, getMaxArgumentDepth(value) + 1); } @@ -240,6 +244,7 @@ public class TerraCommandManager implements CommandManager { private final Map subcommands = new HashMap<>(); private final Map switches = new HashMap<>(); private final List arguments; + private final List switchList; private final Map argumentMap = new HashMap<>(); private CommandHolder(Class clazz) throws MalformedCommandException { @@ -267,7 +272,11 @@ public class TerraCommandManager implements CommandManager { argumentMap.put(argument.value(), argument); } arguments = Arrays.asList(command.arguments()); - } else arguments = Collections.emptyList(); + switchList = Arrays.asList(command.switches()); + } else { + arguments = Collections.emptyList(); + switchList = Collections.emptyList(); + } } } } diff --git a/common/src/main/java/com/dfsek/terra/api/command/annotation/Argument.java b/common/src/main/java/com/dfsek/terra/api/command/annotation/Argument.java index a2625ee26..d0c91a965 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/annotation/Argument.java +++ b/common/src/main/java/com/dfsek/terra/api/command/annotation/Argument.java @@ -20,4 +20,6 @@ public @interface Argument { Class tabCompleter() default NothingCompleter.class; Class> argumentParser() default StringArgumentParser.class; + + String defaultValue() default ""; } diff --git a/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java b/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java index c6157d439..ae5bdd1aa 100644 --- a/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java +++ b/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java @@ -10,5 +10,6 @@ public final class CommandUtil { manager.register("profile", ProfileCommand.class); manager.register("reload", ReloadCommand.class); manager.register("addons", AddonsCommand.class); + manager.register("version", VersionCommand.class); } } diff --git a/common/src/main/java/com/dfsek/terra/commands/StructureCommand.java b/common/src/main/java/com/dfsek/terra/commands/StructureCommand.java index 9b9e7355c..1d5ca4044 100644 --- a/common/src/main/java/com/dfsek/terra/commands/StructureCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/StructureCommand.java @@ -4,6 +4,7 @@ import com.dfsek.terra.api.command.CommandTemplate; import com.dfsek.terra.api.command.annotation.Command; import com.dfsek.terra.api.command.annotation.Subcommand; import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.commands.structure.SpawnCommand; import com.dfsek.terra.commands.structure.StructureExportCommand; import com.dfsek.terra.commands.structure.StructureLoadCommand; @@ -18,6 +19,11 @@ import com.dfsek.terra.commands.structure.StructureLoadCommand; clazz = StructureLoadCommand.class, value = "load", aliases = "ld" + ), + @Subcommand( + clazz = SpawnCommand.class, + value = "spawn", + aliases = "s" ) } ) diff --git a/common/src/main/java/com/dfsek/terra/commands/VersionCommand.java b/common/src/main/java/com/dfsek/terra/commands/VersionCommand.java new file mode 100644 index 000000000..b03a3a9ba --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/VersionCommand.java @@ -0,0 +1,20 @@ +package com.dfsek.terra.commands; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.config.lang.LangUtil; + +@Command +public class VersionCommand implements CommandTemplate { + @Inject + private TerraPlugin main; + + @Override + public void execute(CommandSender sender) { + String terraVersion = main.getVersion(); + LangUtil.send("command.version", sender, terraVersion, main.platformName()); + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/SpawnCommand.java b/common/src/main/java/com/dfsek/terra/commands/structure/SpawnCommand.java new file mode 100644 index 000000000..629261288 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/structure/SpawnCommand.java @@ -0,0 +1,46 @@ +package com.dfsek.terra.commands.structure; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.type.DebugCommand; +import com.dfsek.terra.api.command.annotation.type.PlayerCommand; +import com.dfsek.terra.api.command.annotation.type.WorldCommand; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.math.vector.Location; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.api.structures.parser.lang.constants.NumericConstant; +import com.dfsek.terra.api.structures.script.TerraImplementationArguments; +import com.dfsek.terra.api.structures.script.functions.CheckFunction; +import com.dfsek.terra.api.structures.structure.Rotation; +import com.dfsek.terra.api.structures.structure.buffer.StructureBuffer; +import com.dfsek.terra.api.structures.tokenizer.Position; +import com.dfsek.terra.api.util.FastRandom; + +import java.util.HashMap; + +@DebugCommand +@PlayerCommand +@WorldCommand +@Command +public class SpawnCommand implements CommandTemplate { + @Inject + private TerraPlugin main; + + @Override + public void execute(CommandSender sender) { + Player player = (Player) sender; + Location p = player.getLocation(); + int x = p.getBlockX(); + int y = p.getBlockY(); + int z = p.getBlockZ(); + Position dummy = new Position(0, 0); + + String check = new CheckFunction(main, new NumericConstant(0, dummy), new NumericConstant(0, dummy), new NumericConstant(0, dummy), dummy).apply(new TerraImplementationArguments(new StructureBuffer( + new com.dfsek.terra.api.math.vector.Location(player.getWorld(), x, y, z) + ), Rotation.NONE, new FastRandom(), 0), new HashMap<>()); + + sender.sendMessage("Found: " + check); + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java b/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java index b395b50b8..62b172373 100644 --- a/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java @@ -17,6 +17,9 @@ import com.dfsek.terra.api.platform.entity.Player; import com.dfsek.terra.api.structures.script.StructureScript; import com.dfsek.terra.api.structures.structure.Rotation; import com.dfsek.terra.api.util.FastRandom; +import com.dfsek.terra.commands.structure.argument.ScriptArgumentParser; +import com.dfsek.terra.commands.structure.completer.RotationCompleter; +import com.dfsek.terra.commands.structure.completer.ScriptCompleter; import java.util.concurrent.ThreadLocalRandom; @@ -34,7 +37,8 @@ import java.util.concurrent.ThreadLocalRandom; value = "rotation", required = false, tabCompleter = RotationCompleter.class, - argumentParser = IntegerArgumentParser.class + argumentParser = IntegerArgumentParser.class, + defaultValue = "0" ) }, switches = { diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/ScriptArgumentParser.java b/common/src/main/java/com/dfsek/terra/commands/structure/argument/ScriptArgumentParser.java similarity index 92% rename from common/src/main/java/com/dfsek/terra/commands/structure/ScriptArgumentParser.java rename to common/src/main/java/com/dfsek/terra/commands/structure/argument/ScriptArgumentParser.java index 3c34c74af..3797c08cd 100644 --- a/common/src/main/java/com/dfsek/terra/commands/structure/ScriptArgumentParser.java +++ b/common/src/main/java/com/dfsek/terra/commands/structure/argument/ScriptArgumentParser.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.commands.structure; +package com.dfsek.terra.commands.structure.argument; import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.command.arg.ArgumentParser; diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/RotationCompleter.java b/common/src/main/java/com/dfsek/terra/commands/structure/completer/RotationCompleter.java similarity index 86% rename from common/src/main/java/com/dfsek/terra/commands/structure/RotationCompleter.java rename to common/src/main/java/com/dfsek/terra/commands/structure/completer/RotationCompleter.java index d0f3933bb..3bfed746d 100644 --- a/common/src/main/java/com/dfsek/terra/commands/structure/RotationCompleter.java +++ b/common/src/main/java/com/dfsek/terra/commands/structure/completer/RotationCompleter.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.commands.structure; +package com.dfsek.terra.commands.structure.completer; import com.dfsek.terra.api.command.tab.TabCompleter; import com.dfsek.terra.api.platform.CommandSender; diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/ScriptCompleter.java b/common/src/main/java/com/dfsek/terra/commands/structure/completer/ScriptCompleter.java similarity index 93% rename from common/src/main/java/com/dfsek/terra/commands/structure/ScriptCompleter.java rename to common/src/main/java/com/dfsek/terra/commands/structure/completer/ScriptCompleter.java index c650ef685..24f927baa 100644 --- a/common/src/main/java/com/dfsek/terra/commands/structure/ScriptCompleter.java +++ b/common/src/main/java/com/dfsek/terra/commands/structure/completer/ScriptCompleter.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.commands.structure; +package com.dfsek.terra.commands.structure.completer; import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.command.tab.TabCompleter; diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/SingleBiomeProviderTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/SingleBiomeProviderTemplate.java index dadc4b968..525315454 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/SingleBiomeProviderTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/biome/templates/provider/SingleBiomeProviderTemplate.java @@ -1,19 +1,19 @@ package com.dfsek.terra.config.loaders.config.biome.templates.provider; import com.dfsek.tectonic.annotations.Value; -import com.dfsek.terra.api.world.biome.TerraBiome; import com.dfsek.terra.api.world.biome.provider.BiomeProvider; import com.dfsek.terra.api.world.biome.provider.SingleBiomeProvider; +import com.dfsek.terra.config.builder.BiomeBuilder; public class SingleBiomeProviderTemplate extends BiomeProviderTemplate { @Value("biome") - private TerraBiome biome; + private BiomeBuilder biome; public SingleBiomeProviderTemplate() { } @Override public BiomeProvider build(long seed) { - return new SingleBiomeProvider(biome); + return new SingleBiomeProvider(biome.apply(seed)); } } diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/VersionCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/VersionCommand.java deleted file mode 100644 index b9686d186..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/VersionCommand.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.dfsek.terra.bukkit.command.command; - -import com.dfsek.terra.bukkit.BukkitCommandSender; -import com.dfsek.terra.bukkit.TerraBukkitPlugin; -import com.dfsek.terra.bukkit.command.Command; -import com.dfsek.terra.config.lang.LangUtil; -import org.bukkit.command.CommandSender; -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; -import java.util.List; - -public class VersionCommand extends Command { - public VersionCommand(Command parent) { - super(parent); - } - - @Override - public String getName() { - return "version"; - } - - @Override - public List getSubCommands() { - return Collections.emptyList(); - } - - @Override - public boolean execute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) { - String terraVersion = ((TerraBukkitPlugin) getMain()).getDescription().getVersion(); - LangUtil.send("command.version", new BukkitCommandSender(sender), terraVersion, getMain().platformName()); - return true; - } - - @Override - public int arguments() { - return 0; - } - - @Override - public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - return Collections.emptyList(); - } -} From 41933b84a0a96ae016d570adb041d5f42e2e0ef2 Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 10 Mar 2021 02:46:00 -0700 Subject: [PATCH 72/95] implement entity teleportation and biome locate --- .../dfsek/terra/api/math/vector/Location.java | 5 ++ .../terra/api/platform/entity/Entity.java | 2 + .../dfsek/terra/commands/BiomeCommand.java | 46 +++++++++++ .../com/dfsek/terra/commands/CommandUtil.java | 3 + .../dfsek/terra/commands/GetBlockCommand.java | 26 +++++++ .../dfsek/terra/commands/PacksCommand.java | 33 ++++++++ .../commands/biome/BiomeInfoCommand.java | 24 ++++++ .../commands/biome/BiomeLocateCommand.java | 78 +++++++++++++++++++ .../biome/arg/BiomeArgumentParser.java | 19 +++++ .../commands/biome/tab/BiomeTabCompleter.java | 22 ++++++ .../com/dfsek/terra/bukkit/BukkitEntity.java | 5 ++ .../com/dfsek/terra/bukkit/BukkitPlayer.java | 5 ++ .../command/command/GetBlockCommand.java | 44 ----------- .../bukkit/command/command/PacksCommand.java | 58 -------------- .../fabric/world/entity/FabricEntity.java | 8 ++ .../fabric/world/entity/FabricPlayer.java | 8 ++ 16 files changed, 284 insertions(+), 102 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/commands/BiomeCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/GetBlockCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/PacksCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/biome/BiomeInfoCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/biome/BiomeLocateCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/biome/arg/BiomeArgumentParser.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/biome/tab/BiomeTabCompleter.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/GetBlockCommand.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/PacksCommand.java diff --git a/common/src/main/java/com/dfsek/terra/api/math/vector/Location.java b/common/src/main/java/com/dfsek/terra/api/math/vector/Location.java index a030f9e49..de01cce98 100644 --- a/common/src/main/java/com/dfsek/terra/api/math/vector/Location.java +++ b/common/src/main/java/com/dfsek/terra/api/math/vector/Location.java @@ -170,4 +170,9 @@ public class Location implements Cloneable { public String toString() { return "[" + world + ": (" + getX() + ", " + getY() + ", " + getZ() + ")]"; } + + public Location multiply(double v) { + vector.multiply(v); + return this; + } } diff --git a/common/src/main/java/com/dfsek/terra/api/platform/entity/Entity.java b/common/src/main/java/com/dfsek/terra/api/platform/entity/Entity.java index 692ae6498..51c9be6e5 100644 --- a/common/src/main/java/com/dfsek/terra/api/platform/entity/Entity.java +++ b/common/src/main/java/com/dfsek/terra/api/platform/entity/Entity.java @@ -8,5 +8,7 @@ import com.dfsek.terra.api.platform.world.World; public interface Entity extends Handle, CommandSender { Location getLocation(); + void setLocation(Location location); + World getWorld(); } diff --git a/common/src/main/java/com/dfsek/terra/commands/BiomeCommand.java b/common/src/main/java/com/dfsek/terra/commands/BiomeCommand.java new file mode 100644 index 000000000..91c97f2d5 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/BiomeCommand.java @@ -0,0 +1,46 @@ +package com.dfsek.terra.commands; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.Subcommand; +import com.dfsek.terra.api.command.annotation.type.PlayerCommand; +import com.dfsek.terra.api.command.annotation.type.WorldCommand; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.api.world.biome.UserDefinedBiome; +import com.dfsek.terra.api.world.biome.provider.BiomeProvider; +import com.dfsek.terra.commands.biome.BiomeInfoCommand; +import com.dfsek.terra.commands.biome.BiomeLocateCommand; +import com.dfsek.terra.config.lang.LangUtil; + +@Command( + subcommands = { + @Subcommand( + value = "info", + aliases = {"i"}, + clazz = BiomeInfoCommand.class + ), + @Subcommand( + value = "locate", + aliases = {"l"}, + clazz = BiomeLocateCommand.class + ) + } +) +@WorldCommand +@PlayerCommand +public class BiomeCommand implements CommandTemplate { + @Inject + private TerraPlugin main; + + @Override + public void execute(CommandSender sender) { + Player player = (Player) sender; + + BiomeProvider provider = main.getWorld(player.getWorld()).getBiomeProvider(); + UserDefinedBiome biome = (UserDefinedBiome) provider.getBiome(player.getLocation()); + LangUtil.send("command.biome.in", sender, biome.getID()); + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java b/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java index ae5bdd1aa..75ea0fa03 100644 --- a/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java +++ b/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java @@ -11,5 +11,8 @@ public final class CommandUtil { manager.register("reload", ReloadCommand.class); manager.register("addons", AddonsCommand.class); manager.register("version", VersionCommand.class); + manager.register("getblock", GetBlockCommand.class); + manager.register("packs", PacksCommand.class); + manager.register("biome", BiomeCommand.class); } } diff --git a/common/src/main/java/com/dfsek/terra/commands/GetBlockCommand.java b/common/src/main/java/com/dfsek/terra/commands/GetBlockCommand.java new file mode 100644 index 000000000..982ba3262 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/GetBlockCommand.java @@ -0,0 +1,26 @@ +package com.dfsek.terra.commands; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.type.DebugCommand; +import com.dfsek.terra.api.command.annotation.type.PlayerCommand; +import com.dfsek.terra.api.command.annotation.type.WorldCommand; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.platform.entity.Player; + +@WorldCommand +@DebugCommand +@PlayerCommand +@Command +public class GetBlockCommand implements CommandTemplate { + @Inject + private TerraPlugin main; + + @Override + public void execute(CommandSender sender) { + Player player = (Player) sender; + sender.sendMessage("Block: " + main.getWorld(player.getWorld()).getUngeneratedBlock(player.getLocation()).getAsString()); + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/PacksCommand.java b/common/src/main/java/com/dfsek/terra/commands/PacksCommand.java new file mode 100644 index 000000000..4a92fa8fa --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/PacksCommand.java @@ -0,0 +1,33 @@ +package com.dfsek.terra.commands; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.registry.CheckedRegistry; +import com.dfsek.terra.config.lang.LangUtil; +import com.dfsek.terra.config.pack.ConfigPack; +import com.dfsek.terra.config.pack.ConfigPackTemplate; + +@Command +public class PacksCommand implements CommandTemplate { + @Inject + private TerraPlugin main; + + @Override + public void execute(CommandSender sender) { + CheckedRegistry registry = main.getConfigRegistry(); + + if(registry.entries().size() == 0) { + LangUtil.send("command.packs.none", sender); + return; + } + + LangUtil.send("command.packs.main", sender); + registry.entries().forEach(entry -> { + ConfigPackTemplate template = entry.getTemplate(); + LangUtil.send("command.packs.pack", sender, template.getID(), template.getAuthor(), template.getVersion()); + }); + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/biome/BiomeInfoCommand.java b/common/src/main/java/com/dfsek/terra/commands/biome/BiomeInfoCommand.java new file mode 100644 index 000000000..e87033e63 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/biome/BiomeInfoCommand.java @@ -0,0 +1,24 @@ +package com.dfsek.terra.commands.biome; + +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.annotation.Argument; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.commands.biome.arg.BiomeArgumentParser; +import com.dfsek.terra.commands.biome.tab.BiomeTabCompleter; + +@Command( + arguments = { + @Argument( + value = "biome", + tabCompleter = BiomeTabCompleter.class, + argumentParser = BiomeArgumentParser.class + ) + } +) +public class BiomeInfoCommand implements CommandTemplate { + @Override + public void execute(CommandSender sender) { + + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/biome/BiomeLocateCommand.java b/common/src/main/java/com/dfsek/terra/commands/biome/BiomeLocateCommand.java new file mode 100644 index 000000000..09f20dde8 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/biome/BiomeLocateCommand.java @@ -0,0 +1,78 @@ +package com.dfsek.terra.commands.biome; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.annotation.Argument; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.Switch; +import com.dfsek.terra.api.command.annotation.inject.ArgumentTarget; +import com.dfsek.terra.api.command.annotation.inject.SwitchTarget; +import com.dfsek.terra.api.command.annotation.type.PlayerCommand; +import com.dfsek.terra.api.command.annotation.type.WorldCommand; +import com.dfsek.terra.api.command.arg.IntegerArgumentParser; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.math.vector.Location; +import com.dfsek.terra.api.math.vector.Vector3; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.locate.AsyncBiomeFinder; +import com.dfsek.terra.commands.biome.arg.BiomeArgumentParser; +import com.dfsek.terra.commands.biome.tab.BiomeTabCompleter; +import com.dfsek.terra.config.lang.LangUtil; + +import java.util.Locale; + +@PlayerCommand +@WorldCommand +@Command( + arguments = { + @Argument( + value = "biome", + tabCompleter = BiomeTabCompleter.class, + argumentParser = BiomeArgumentParser.class + ), + @Argument( + value = "radius", + required = false, + defaultValue = "1000", + argumentParser = IntegerArgumentParser.class + ) + }, + switches = { + @Switch( + value = "teleport", + aliases = {"t", "tp"} + ) + } +) +public class BiomeLocateCommand implements CommandTemplate { + + @ArgumentTarget("radius") + private Integer radius; + + @ArgumentTarget("biome") + private TerraBiome biome; + + @SwitchTarget("teleport") + private boolean teleport; + + @Inject + private TerraPlugin main; + + @Override + public void execute(CommandSender sender) { + + Player player = (Player) sender; + + new Thread(new AsyncBiomeFinder(main.getWorld(player.getWorld()).getBiomeProvider(), biome, player.getLocation().clone().multiply((1D / main.getTerraConfig().getBiomeSearchResolution())), 0, radius, location -> { + if(location != null) { + sender.sendMessage(String.format("The nearest %s is at [%d, ~, %d] (%.1f blocks away)", biome.getID().toLowerCase(Locale.ROOT), location.getBlockX(), location.getBlockZ(), location.add(new Vector3(0, player.getLocation().getY(), 0)).distance(player.getLocation().toVector()))); + if(teleport) { + player.setLocation(new Location(player.getWorld(), location.getX(), player.getLocation().getY(), location.getZ())); + } + } else LangUtil.send("command.biome.unable-to-locate", sender); + }, main), "Biome Location Thread").start(); + + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/biome/arg/BiomeArgumentParser.java b/common/src/main/java/com/dfsek/terra/commands/biome/arg/BiomeArgumentParser.java new file mode 100644 index 000000000..251036d39 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/biome/arg/BiomeArgumentParser.java @@ -0,0 +1,19 @@ +package com.dfsek.terra.commands.biome.arg; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.arg.ArgumentParser; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.api.world.biome.TerraBiome; + +public class BiomeArgumentParser implements ArgumentParser { + @Inject + private TerraPlugin main; + + @Override + public TerraBiome parse(CommandSender sender, String arg) { + Player player = (Player) sender; + return main.getWorld(player.getWorld()).getConfig().getBiomeRegistry().get(arg); + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/biome/tab/BiomeTabCompleter.java b/common/src/main/java/com/dfsek/terra/commands/biome/tab/BiomeTabCompleter.java new file mode 100644 index 000000000..f2461c532 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/biome/tab/BiomeTabCompleter.java @@ -0,0 +1,22 @@ +package com.dfsek.terra.commands.biome.tab; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.tab.TabCompleter; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.api.world.biome.TerraBiome; + +import java.util.List; +import java.util.stream.Collectors; + +public class BiomeTabCompleter implements TabCompleter { + @Inject + private TerraPlugin main; + + @Override + public List complete(CommandSender sender) { + Player player = (Player) sender; + return main.getWorld(player.getWorld()).getConfig().getBiomeRegistry().entries().stream().map(TerraBiome::getID).collect(Collectors.toList()); + } +} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitEntity.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitEntity.java index bb20cda6f..ff3bd80ec 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitEntity.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitEntity.java @@ -22,6 +22,11 @@ public class BukkitEntity implements Entity { return BukkitAdapter.adapt(entity.getLocation()); } + @Override + public void setLocation(Location location) { + entity.teleport(BukkitAdapter.adapt(location)); + } + @Override public World getWorld() { return BukkitAdapter.adapt(entity.getWorld()); diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitPlayer.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitPlayer.java index fbf763e6b..822fa0d7c 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitPlayer.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/BukkitPlayer.java @@ -23,6 +23,11 @@ public class BukkitPlayer implements Player { return new Location(BukkitAdapter.adapt(bukkit.getWorld()), bukkit.getX(), bukkit.getY(), bukkit.getZ()); } + @Override + public void setLocation(Location location) { + delegate.teleport(BukkitAdapter.adapt(location)); + } + @Override public World getWorld() { return BukkitAdapter.adapt(delegate.getWorld()); diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/GetBlockCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/GetBlockCommand.java deleted file mode 100644 index 2585430c6..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/GetBlockCommand.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.dfsek.terra.bukkit.command.command; - -import com.dfsek.terra.bukkit.command.WorldCommand; -import com.dfsek.terra.bukkit.world.BukkitAdapter; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; -import java.util.List; - -public class GetBlockCommand extends WorldCommand { - public GetBlockCommand(com.dfsek.terra.bukkit.command.Command parent) { - super(parent); - } - - @Override - public boolean execute(@NotNull Player player, @NotNull Command command, @NotNull String s, @NotNull String[] strings, World world) { - player.sendMessage("Block: " + getMain().getWorld(BukkitAdapter.adapt(world)).getUngeneratedBlock(BukkitAdapter.adapt(player.getLocation())).getAsString()); - return true; - } - - @Override - public String getName() { - return "block"; - } - - @Override - public List getSubCommands() { - return Collections.emptyList(); - } - - @Override - public int arguments() { - return 0; - } - - @Override - public List getTabCompletions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) { - return Collections.emptyList(); - } -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/PacksCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/PacksCommand.java deleted file mode 100644 index 1bdd037a1..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/PacksCommand.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.dfsek.terra.bukkit.command.command; - -import com.dfsek.terra.api.registry.CheckedRegistry; -import com.dfsek.terra.bukkit.BukkitCommandSender; -import com.dfsek.terra.bukkit.command.Command; -import com.dfsek.terra.config.lang.LangUtil; -import com.dfsek.terra.config.pack.ConfigPack; -import com.dfsek.terra.config.pack.ConfigPackTemplate; -import org.bukkit.command.CommandSender; -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; -import java.util.List; - -public class PacksCommand extends Command { - public PacksCommand(Command parent) { - super(parent); - } - - @Override - public String getName() { - return "packs"; - } - - @Override - public List getSubCommands() { - return Collections.emptyList(); - } - - @Override - public boolean execute(@NotNull CommandSender commandSender, org.bukkit.command.@NotNull Command command, @NotNull String s, @NotNull String[] strings) { - - CheckedRegistry registry = getMain().getConfigRegistry(); - - if(registry.entries().size() == 0) { - LangUtil.send("command.packs.none", new BukkitCommandSender(commandSender)); - return true; - } - - LangUtil.send("command.packs.main", new BukkitCommandSender(commandSender)); - registry.entries().forEach(entry -> { - ConfigPackTemplate template = entry.getTemplate(); - LangUtil.send("command.packs.pack", new BukkitCommandSender(commandSender), template.getID(), template.getAuthor(), template.getVersion()); - }); - - return true; - } - - @Override - public int arguments() { - return 0; - } - - @Override - public List getTabCompletions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) { - return Collections.emptyList(); - } -} diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricEntity.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricEntity.java index f19d6d820..65c26849d 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricEntity.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricEntity.java @@ -5,6 +5,8 @@ import com.dfsek.terra.api.platform.entity.Entity; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.fabric.world.FabricAdapter; import com.dfsek.terra.fabric.world.handles.world.FabricWorldAccess; +import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle; +import net.minecraft.server.world.ServerWorld; public class FabricEntity implements Entity { private final net.minecraft.entity.Entity delegate; @@ -28,6 +30,12 @@ public class FabricEntity implements Entity { return new Location(new FabricWorldAccess(delegate.world), FabricAdapter.adapt(delegate.getBlockPos())); } + @Override + public void setLocation(Location location) { + delegate.teleport(location.getX(), location.getY(), location.getZ()); + delegate.moveToWorld((ServerWorld) ((FabricWorldHandle) location).getWorld()); + } + @Override public World getWorld() { return new FabricWorldAccess(delegate.world); diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricPlayer.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricPlayer.java index d57d9d642..25f3a4caa 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricPlayer.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricPlayer.java @@ -5,7 +5,9 @@ import com.dfsek.terra.api.platform.entity.Player; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.fabric.world.FabricAdapter; import com.dfsek.terra.fabric.world.handles.world.FabricWorldAccess; +import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.server.world.ServerWorld; import net.minecraft.text.LiteralText; public class FabricPlayer implements Player { @@ -34,4 +36,10 @@ public class FabricPlayer implements Player { public World getWorld() { return new FabricWorldAccess(delegate.world); } + + @Override + public void setLocation(Location location) { + delegate.teleport(location.getX(), location.getY(), location.getZ()); + delegate.moveToWorld((ServerWorld) ((FabricWorldHandle) location).getWorld()); + } } From 5a85aced45e48fa11062abc724040b445422b55a Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 10 Mar 2021 02:50:40 -0700 Subject: [PATCH 73/95] BiomeInfoCommand --- .../commands/biome/BiomeInfoCommand.java | 28 ++++++ .../command/command/biome/BiomeCommand.java | 50 ---------- .../command/biome/BiomeInfoCommand.java | 86 ----------------- .../command/biome/BiomeLocateCommand.java | 95 ------------------- 4 files changed, 28 insertions(+), 231 deletions(-) delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeCommand.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeInfoCommand.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeLocateCommand.java diff --git a/common/src/main/java/com/dfsek/terra/commands/biome/BiomeInfoCommand.java b/common/src/main/java/com/dfsek/terra/commands/biome/BiomeInfoCommand.java index e87033e63..4fe3fe2ac 100644 --- a/common/src/main/java/com/dfsek/terra/commands/biome/BiomeInfoCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/biome/BiomeInfoCommand.java @@ -3,9 +3,16 @@ package com.dfsek.terra.commands.biome; import com.dfsek.terra.api.command.CommandTemplate; import com.dfsek.terra.api.command.annotation.Argument; import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.inject.ArgumentTarget; import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.world.biome.TerraBiome; +import com.dfsek.terra.api.world.biome.UserDefinedBiome; import com.dfsek.terra.commands.biome.arg.BiomeArgumentParser; import com.dfsek.terra.commands.biome.tab.BiomeTabCompleter; +import com.dfsek.terra.config.templates.BiomeTemplate; +import com.dfsek.terra.world.population.items.TerraStructure; + +import java.util.List; @Command( arguments = { @@ -17,8 +24,29 @@ import com.dfsek.terra.commands.biome.tab.BiomeTabCompleter; } ) public class BiomeInfoCommand implements CommandTemplate { + @ArgumentTarget("biome") + private TerraBiome biome; + @Override public void execute(CommandSender sender) { + sender.sendMessage("Biome info for \"" + biome.getID() + "\"."); + sender.sendMessage("Vanilla biome: " + biome.getVanillaBiomes()); + + if(biome instanceof UserDefinedBiome) { + BiomeTemplate bio = ((UserDefinedBiome) biome).getConfig(); + + if(bio.getExtend() != null) sender.sendMessage("Extends: " + bio.getExtend()); + + List structureConfigs = bio.getStructures(); + + if(structureConfigs.size() == 0) sender.sendMessage("No Structures"); + else { + sender.sendMessage("-------Structures-------"); + for(TerraStructure c : structureConfigs) { + sender.sendMessage(" - " + c.getTemplate().getID()); + } + } + } } } diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeCommand.java deleted file mode 100644 index 216897347..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeCommand.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.dfsek.terra.bukkit.command.command.biome; - -import com.dfsek.terra.api.world.biome.UserDefinedBiome; -import com.dfsek.terra.api.world.biome.provider.BiomeProvider; -import com.dfsek.terra.bukkit.command.WorldCommand; -import com.dfsek.terra.bukkit.world.BukkitAdapter; -import com.dfsek.terra.config.lang.LangUtil; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -public class BiomeCommand extends WorldCommand { - public BiomeCommand(com.dfsek.terra.bukkit.command.Command parent) { - super(parent); - } - - @Override - public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) { - BiomeProvider grid = getMain().getWorld(BukkitAdapter.adapt(sender.getWorld())).getBiomeProvider(); - UserDefinedBiome biome = (UserDefinedBiome) grid.getBiome(BukkitAdapter.adapt(sender.getLocation())); - LangUtil.send("command.biome.in", BukkitAdapter.adapt(sender), biome.getID()); - return true; - } - - @Override - public String getName() { - return "biome"; - } - - @Override - public List getSubCommands() { - return Arrays.asList(new BiomeLocateCommand(this), new BiomeInfoCommand(this)); - } - - @Override - public int arguments() { - return 0; - } - - @Override - public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - return Collections.emptyList(); - } -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeInfoCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeInfoCommand.java deleted file mode 100644 index 2eee4e2ec..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeInfoCommand.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.dfsek.terra.bukkit.command.command.biome; - -import com.dfsek.terra.api.world.biome.UserDefinedBiome; -import com.dfsek.terra.bukkit.BukkitCommandSender; -import com.dfsek.terra.bukkit.command.WorldCommand; -import com.dfsek.terra.bukkit.world.BukkitAdapter; -import com.dfsek.terra.config.lang.LangUtil; -import com.dfsek.terra.config.pack.ConfigPack; -import com.dfsek.terra.config.pack.WorldConfig; -import com.dfsek.terra.config.templates.BiomeTemplate; -import com.dfsek.terra.world.TerraWorld; -import com.dfsek.terra.world.population.items.TerraStructure; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -public class BiomeInfoCommand extends WorldCommand { - public BiomeInfoCommand(com.dfsek.terra.bukkit.command.Command parent) { - super(parent); - } - - @Override - public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) { - String id = args[0]; - WorldConfig cfg = getMain().getWorld(BukkitAdapter.adapt(world)).getConfig(); - UserDefinedBiome b; - try { - b = (UserDefinedBiome) cfg.getBiomeRegistry().get(id); - } catch(IllegalArgumentException | NullPointerException e) { - LangUtil.send("command.biome.invalid", new BukkitCommandSender(sender), id); - return true; - } - sender.sendMessage("TerraBiome info for \"" + b.getID() + "\"."); - sender.sendMessage("Vanilla biome: " + b.getVanillaBiomes()); - - BiomeTemplate bio = b.getConfig(); - - if(bio.getExtend() != null) sender.sendMessage("Extends: " + bio.getExtend()); - - List structureConfigs = bio.getStructures(); - - if(structureConfigs.size() == 0) sender.sendMessage("No Structures"); - else { - sender.sendMessage("-------Structures-------"); - for(TerraStructure c : structureConfigs) { - sender.sendMessage(" - " + c.getTemplate().getID()); - } - } - - return true; - } - - @Override - public String getName() { - return "info"; - } - - @Override - public List getSubCommands() { - return Collections.emptyList(); - } - - @Override - public int arguments() { - return 1; - } - - @Override - public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - if(!(sender instanceof Player) || !TerraWorld.isTerraWorld(BukkitAdapter.adapt(((Player) sender).getWorld()))) - return Collections.emptyList(); - List ids = new ArrayList<>(); - - getMain().getWorld(BukkitAdapter.adapt(((Player) sender).getWorld())).getConfig().getBiomeRegistry().forEach((id, biome) -> ids.add(id)); - if(args.length == 1) - return ids.stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList()); - return Collections.emptyList(); - } -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeLocateCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeLocateCommand.java deleted file mode 100644 index ec8800123..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/biome/BiomeLocateCommand.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.dfsek.terra.bukkit.command.command.biome; - -import com.dfsek.terra.api.math.vector.Vector3; -import com.dfsek.terra.api.world.biome.TerraBiome; -import com.dfsek.terra.api.world.locate.AsyncBiomeFinder; -import com.dfsek.terra.bukkit.TerraBukkitPlugin; -import com.dfsek.terra.bukkit.command.WorldCommand; -import com.dfsek.terra.bukkit.world.BukkitAdapter; -import com.dfsek.terra.config.lang.LangUtil; -import com.dfsek.terra.world.TerraWorld; -import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -@SuppressWarnings("deprecation") -public class BiomeLocateCommand extends WorldCommand { - public BiomeLocateCommand(com.dfsek.terra.bukkit.command.Command parent) { - super(parent); - } - - @SuppressWarnings("DuplicatedCode") - @Override - public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) { - String id = args[0]; - int maxRadius; - try { - maxRadius = Integer.parseInt(args[1]); - } catch(NumberFormatException e) { - LangUtil.send("command.biome.invalid-radius", BukkitAdapter.adapt(sender), args[1]); - return true; - } - TerraBiome b; - try { - b = getMain().getWorld(BukkitAdapter.adapt(world)).getConfig().getBiomeRegistry().get(id); - } catch(IllegalArgumentException | NullPointerException e) { - LangUtil.send("command.biome.invalid", BukkitAdapter.adapt(sender), id); - return true; - } - Bukkit.getScheduler().runTaskAsynchronously((TerraBukkitPlugin) getMain(), new AsyncBiomeFinder(getMain().getWorld(BukkitAdapter.adapt(world)).getBiomeProvider(), b, BukkitAdapter.adapt(sender.getLocation().clone().multiply((1D / ((TerraBukkitPlugin) getMain()).getTerraConfig().getBiomeSearchResolution()))), 0, maxRadius, location -> { - if(location != null) { - ComponentBuilder cm = new ComponentBuilder(String.format("The nearest %s is at ", id.toLowerCase())) - .append(String.format("[%d, ~, %d]", location.getBlockX(), location.getBlockZ()), ComponentBuilder.FormatRetention.NONE) - .event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/minecraft:tp %s %d.0 %.2f %d.0", sender.getName(), location.getBlockX(), sender.getLocation().getY(), location.getBlockZ()))) - .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new BaseComponent[] {new TextComponent("Click to teleport")})) - .color(ChatColor.GREEN) - .append(String.format(" (%.1f blocks away)", location.add(new Vector3(0, sender.getLocation().getY(), 0)).distance(BukkitAdapter.adapt(sender.getLocation().toVector()))), ComponentBuilder.FormatRetention.NONE); - sender.spigot().sendMessage(cm.create()); - // LangUtil.send("command.biome.biome-found", sender, String.valueOf(location.getBlockX()), String.valueOf(location.getBlockZ())); - } else LangUtil.send("command.biome.unable-to-locate", BukkitAdapter.adapt(sender)); - }, getMain())); - - return true; - } - - @Override - public String getName() { - return "locate"; - } - - @Override - public List getSubCommands() { - return Collections.emptyList(); - } - - @Override - public int arguments() { - return 2; - } - - @Override - public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - if(!(sender instanceof Player) || !TerraWorld.isTerraWorld(BukkitAdapter.adapt(((Player) sender).getWorld()))) - return Collections.emptyList(); - List ids = new ArrayList<>(); - - getMain().getWorld(BukkitAdapter.adapt(((Player) sender).getWorld())).getConfig().getBiomeRegistry().forEach((id, biome) -> ids.add(id)); - if(args.length == 1) - return ids.stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList()); - return Collections.emptyList(); - } -} From 513c6a647febfbfa4b6aa5d309c4eb32f2d91e39 Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 10 Mar 2021 02:54:03 -0700 Subject: [PATCH 74/95] Bukkit command cleanup --- .../command/structure/SpawnCommand.java | 64 -------------- .../command/structure/StructureCommand.java | 3 +- .../command/structure/load/LoadCommand.java | 55 ------------ .../structure/load/LoadFullCommand.java | 85 ------------------- 4 files changed, 1 insertion(+), 206 deletions(-) delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/SpawnCommand.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/load/LoadCommand.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/load/LoadFullCommand.java diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/SpawnCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/SpawnCommand.java deleted file mode 100644 index c46556751..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/SpawnCommand.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.dfsek.terra.bukkit.command.command.structure; - -import com.dfsek.terra.api.structures.parser.lang.constants.NumericConstant; -import com.dfsek.terra.api.structures.script.TerraImplementationArguments; -import com.dfsek.terra.api.structures.script.functions.CheckFunction; -import com.dfsek.terra.api.structures.structure.Rotation; -import com.dfsek.terra.api.structures.structure.buffer.StructureBuffer; -import com.dfsek.terra.api.structures.tokenizer.Position; -import com.dfsek.terra.api.util.FastRandom; -import com.dfsek.terra.bukkit.command.DebugCommand; -import com.dfsek.terra.bukkit.command.WorldCommand; -import com.dfsek.terra.bukkit.world.BukkitAdapter; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; -import java.util.HashMap; -import java.util.List; - -public class SpawnCommand extends WorldCommand implements DebugCommand { - public SpawnCommand(com.dfsek.terra.bukkit.command.Command parent) { - super(parent); - } - - @Override - public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) { - Location p = sender.getLocation(); - int x = p.getBlockX(); - int y = p.getBlockY(); - int z = p.getBlockZ(); - Position dummy = new Position(0, 0); - com.dfsek.terra.api.platform.world.World w = BukkitAdapter.adapt(world); - String check = new CheckFunction(getMain(), new NumericConstant(0, dummy), new NumericConstant(0, dummy), new NumericConstant(0, dummy), dummy).apply(new TerraImplementationArguments(new StructureBuffer( - new com.dfsek.terra.api.math.vector.Location(w, x, y, z) - ), Rotation.NONE, new FastRandom(), 0), new HashMap<>()); - - sender.sendMessage("Found: " + check); - return true; - } - - @Override - public String getName() { - return "spawn"; - } - - @Override - public List getSubCommands() { - return Collections.emptyList(); - } - - @Override - public int arguments() { - return 0; - } - - @Override - public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - return Collections.emptyList(); - } -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/StructureCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/StructureCommand.java index 16c6b277a..e722a6cc7 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/StructureCommand.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/StructureCommand.java @@ -2,7 +2,6 @@ package com.dfsek.terra.bukkit.command.command.structure; import com.dfsek.terra.bukkit.BukkitCommandSender; import com.dfsek.terra.bukkit.command.PlayerCommand; -import com.dfsek.terra.bukkit.command.command.structure.load.LoadCommand; import com.dfsek.terra.config.lang.LangUtil; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -31,7 +30,7 @@ public class StructureCommand extends PlayerCommand { @Override public List getSubCommands() { - return Arrays.asList(new ExportCommand(this), new LoadCommand(this), new LocateCommand(this), new SpawnCommand(this)); + return Arrays.asList(new ExportCommand(this), new LocateCommand(this)); } @Override diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/load/LoadCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/load/LoadCommand.java deleted file mode 100644 index c8a88e325..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/load/LoadCommand.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.dfsek.terra.bukkit.command.command.structure.load; - -import com.dfsek.terra.api.platform.world.World; -import com.dfsek.terra.bukkit.command.DebugCommand; -import com.dfsek.terra.bukkit.command.PlayerCommand; -import com.dfsek.terra.world.TerraWorld; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -public class LoadCommand extends PlayerCommand implements DebugCommand { - public LoadCommand(com.dfsek.terra.bukkit.command.Command parent) { - super(parent); - } - - public List getStructureNames(World world) { - List names = new ArrayList<>(); - TerraWorld terraWorld = getMain().getWorld(world); - - terraWorld.getConfig().getScriptRegistry().forEach(script -> names.add(script.getId())); - - return names; - } - - @Override - public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - return true; - } - - @Override - public String getName() { - return "load"; - } - - @Override - public List getSubCommands() { - return Arrays.asList(new LoadFullCommand(this, true), new LoadFullCommand(this, false)); - } - - @Override - public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - return Collections.emptyList(); - } - - @Override - public int arguments() { - return 0; - } -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/load/LoadFullCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/load/LoadFullCommand.java deleted file mode 100644 index 33ab614a6..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/load/LoadFullCommand.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.dfsek.terra.bukkit.command.command.structure.load; - -import com.dfsek.terra.api.platform.world.World; -import com.dfsek.terra.api.structures.script.StructureScript; -import com.dfsek.terra.api.structures.structure.Rotation; -import com.dfsek.terra.api.util.FastRandom; -import com.dfsek.terra.api.util.world.PopulationUtil; -import com.dfsek.terra.bukkit.command.DebugCommand; -import com.dfsek.terra.bukkit.world.BukkitAdapter; -import com.dfsek.terra.bukkit.world.BukkitChunk; -import com.dfsek.terra.world.TerraWorld; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class LoadFullCommand extends LoadCommand implements DebugCommand { - private final boolean chunk; - - public LoadFullCommand(com.dfsek.terra.bukkit.command.Command parent, boolean chunk) { - super(parent); - this.chunk = chunk; - } - - @Override - public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) { - TerraWorld terraWorld = getMain().getWorld(BukkitAdapter.adapt(sender.getWorld())); - long t = System.nanoTime(); - FastRandom chunk = PopulationUtil.getRandom(new BukkitChunk(sender.getLocation().getChunk())); - Rotation r; - try { - r = Rotation.fromDegrees(Integer.parseInt(args[1])); - } catch(Exception e) { - sender.sendMessage("Invalid rotation: " + args[1]); - return true; - } - StructureScript script = terraWorld.getConfig().getScriptRegistry().get(args[0]); - if(script == null) { - sender.sendMessage("Invalid structure: " + args[0]); - return true; - } - if(this.chunk) { - script.execute(BukkitAdapter.adapt(sender.getLocation()), BukkitAdapter.adapt(sender.getLocation().getChunk()), chunk, r); - } else { - script.execute(BukkitAdapter.adapt(sender.getLocation()), chunk, r); - } - long l = System.nanoTime() - t; - - sender.sendMessage("Took " + ((double) l) / 1000000 + "ms"); - return true; - } - - @Override - public String getName() { - return chunk ? "chunk" : "full"; - } - - @Override - public List getSubCommands() { - return Collections.emptyList(); - } - - @Override - public int arguments() { - return 2; - } - - @Override - public List getTabCompletions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] args) { - World w = BukkitAdapter.adapt(((Player) commandSender).getWorld()); - if(!TerraWorld.isTerraWorld(w)) return Collections.emptyList(); - switch(args.length) { - case 1: - return getMain().getWorld(w).getConfig().getScriptRegistry().entries().stream().map(StructureScript::getId).filter(id -> id.startsWith(args[0])).sorted().collect(Collectors.toList()); - case 2: - return Stream.of("0", "90", "180", "270").filter(string -> string.toUpperCase().startsWith(args[1].toUpperCase())).collect(Collectors.toList()); - } - return Collections.emptyList(); - } -} From a584ac24012af8f3621749fd4c4d77a1315cd5a9 Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 10 Mar 2021 03:03:04 -0700 Subject: [PATCH 75/95] Bukkit command cleanup/fixes --- .../main/java/com/dfsek/terra/api/TerraPlugin.java | 11 +++++++++++ .../terra/commands/biome/BiomeLocateCommand.java | 2 +- .../com/dfsek/terra/bukkit/TerraBukkitPlugin.java | 5 +++++ .../terra/bukkit/command/BukkitCommandAdapter.java | 5 ++++- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/dfsek/terra/api/TerraPlugin.java b/common/src/main/java/com/dfsek/terra/api/TerraPlugin.java index 6bd141802..fb9f87613 100644 --- a/common/src/main/java/com/dfsek/terra/api/TerraPlugin.java +++ b/common/src/main/java/com/dfsek/terra/api/TerraPlugin.java @@ -53,4 +53,15 @@ public interface TerraPlugin extends LoaderRegistrar { default String getVersion() { return "@VERSION@"; } + + /** + * Runs a task that may or may not be thread safe, depending on platform. + *

+ * Allows platforms to define what code is safe to be run asynchronously. + * + * @param task Task to be run. + */ + default void runPossiblyUnsafeTask(Runnable task) { + task.run(); + } } diff --git a/common/src/main/java/com/dfsek/terra/commands/biome/BiomeLocateCommand.java b/common/src/main/java/com/dfsek/terra/commands/biome/BiomeLocateCommand.java index 09f20dde8..b6ef00483 100644 --- a/common/src/main/java/com/dfsek/terra/commands/biome/BiomeLocateCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/biome/BiomeLocateCommand.java @@ -69,7 +69,7 @@ public class BiomeLocateCommand implements CommandTemplate { if(location != null) { sender.sendMessage(String.format("The nearest %s is at [%d, ~, %d] (%.1f blocks away)", biome.getID().toLowerCase(Locale.ROOT), location.getBlockX(), location.getBlockZ(), location.add(new Vector3(0, player.getLocation().getY(), 0)).distance(player.getLocation().toVector()))); if(teleport) { - player.setLocation(new Location(player.getWorld(), location.getX(), player.getLocation().getY(), location.getZ())); + main.runPossiblyUnsafeTask(() -> player.setLocation(new Location(player.getWorld(), location.getX(), player.getLocation().getY(), location.getZ()))); } } else LangUtil.send("command.biome.unable-to-locate", sender); }, main), "Biome Location Thread").start(); diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java index 7a4a3ed5b..b5a68974a 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java @@ -134,6 +134,11 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { return eventManager; } + @Override + public void runPossiblyUnsafeTask(Runnable task) { + Bukkit.getScheduler().runTask(this, task); + } + @Override public void onDisable() { BukkitChunkGeneratorWrapper.saveAll(); diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/BukkitCommandAdapter.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/BukkitCommandAdapter.java index e31fc0d75..7a4d1227e 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/BukkitCommandAdapter.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/BukkitCommandAdapter.java @@ -14,6 +14,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Locale; +import java.util.stream.Collectors; public class BukkitCommandAdapter implements CommandExecutor, TabCompleter { private final CommandManager manager; @@ -42,7 +44,8 @@ public class BukkitCommandAdapter implements CommandExecutor, TabCompleter { List argList = new ArrayList<>(Arrays.asList(args)); try { - return manager.tabComplete(argList.remove(0), BukkitAdapter.adapt(sender), argList); + return manager.tabComplete(argList.remove(0), BukkitAdapter.adapt(sender), argList).stream() + .filter(s -> s.toLowerCase(Locale.ROOT).startsWith(args[args.length - 1].toLowerCase(Locale.ROOT))).sorted(String::compareTo).collect(Collectors.toList()); } catch(CommandException e) { e.printStackTrace(); return Collections.emptyList(); From 06956a7a2d049e56173a96be14c0794306959f91 Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 10 Mar 2021 03:20:34 -0700 Subject: [PATCH 76/95] fix command NPEs on invalid IDs --- .../java/com/dfsek/terra/api/command/TerraCommandManager.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java index 0a89fdd15..b12f4ea78 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java +++ b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java @@ -48,6 +48,7 @@ public class TerraCommandManager implements CommandManager { @Override public void execute(String commandName, CommandSender sender, List argsIn) throws CommandException { + if(!commands.containsKey(commandName)) throw new InvalidArgumentsException("No such command \"" + commandName + "\""); execute(commands.get(commandName), sender, new ArrayList<>(argsIn)); } @@ -190,6 +191,7 @@ public class TerraCommandManager implements CommandManager { @Override public List tabComplete(String command, CommandSender sender, List args) throws CommandException { if(args.isEmpty()) return new ArrayList<>(commands.keySet()).stream().sorted(String::compareTo).collect(Collectors.toList()); + if(!commands.containsKey(command)) return Collections.emptyList(); return tabComplete(commands.get(command), sender, new ArrayList<>(args)).stream().filter(s -> s.toLowerCase().startsWith(args.get(args.size() - 1).toLowerCase())).sorted(String::compareTo).collect(Collectors.toList()); } From bf5be91868927a5c096031d807eef25cf140ea9b Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 10 Mar 2021 15:20:17 -0700 Subject: [PATCH 77/95] clean up WorldHandle, add generic utility classes --- .../api/platform/handle/WorldHandle.java | 22 ++++---- .../terra/api/util/generic/either/Either.java | 52 +++++++++++++++++++ .../api/util/generic/pair/ImmutablePair.java | 27 ++++++++++ .../terra/api/util/generic/pair/Pair.java | 35 +++++++++++++ .../terra/world/population/CavePopulator.java | 11 ++-- .../population/items/flora/TerraFlora.java | 2 +- .../items/ores/DeformedSphereOre.java | 2 +- .../population/items/ores/VanillaOre.java | 2 +- .../bukkit/handles/BukkitWorldHandle.java | 21 ++++---- .../terra/bukkit/structure/WorldEditUtil.java | 6 +-- .../terra/fabric/world/FabricWorldHandle.java | 11 ---- .../dfsek/terra/platform/RawWorldHandle.java | 10 ---- 12 files changed, 148 insertions(+), 53 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/api/util/generic/either/Either.java create mode 100644 common/src/main/java/com/dfsek/terra/api/util/generic/pair/ImmutablePair.java create mode 100644 common/src/main/java/com/dfsek/terra/api/util/generic/pair/Pair.java diff --git a/common/src/main/java/com/dfsek/terra/api/platform/handle/WorldHandle.java b/common/src/main/java/com/dfsek/terra/api/platform/handle/WorldHandle.java index f4ce3096b..776b695a5 100644 --- a/common/src/main/java/com/dfsek/terra/api/platform/handle/WorldHandle.java +++ b/common/src/main/java/com/dfsek/terra/api/platform/handle/WorldHandle.java @@ -1,22 +1,26 @@ package com.dfsek.terra.api.platform.handle; -import com.dfsek.terra.api.platform.block.Block; +import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.entity.EntityType; +import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.api.util.generic.pair.Pair; /** * Interface to be implemented for world manipulation. */ public interface WorldHandle { - default void setBlockData(Block block, BlockData data, boolean physics) { - block.setBlockData(data, physics); - } - - default BlockData getBlockData(Block block) { - return block.getBlockData(); - } - BlockData createBlockData(String data); EntityType getEntity(String id); + + /** + * Get the locations selected by a player. (Usually via WorldEdit) + * + * @param player Player to get locations for + * @return Pair of locations. + */ + default Pair getSelectedLocation(Player player) { + throw new UnsupportedOperationException("Cannot get selection on this platform."); + } } diff --git a/common/src/main/java/com/dfsek/terra/api/util/generic/either/Either.java b/common/src/main/java/com/dfsek/terra/api/util/generic/either/Either.java new file mode 100644 index 000000000..cad5d93bf --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/util/generic/either/Either.java @@ -0,0 +1,52 @@ +package com.dfsek.terra.api.util.generic.either; + +import java.util.Optional; +import java.util.function.Consumer; + +public final class Either { + private final L left; + private final R right; + private final boolean leftPresent; + + private Either(L left, R right, boolean leftPresent) { + this.left = left; + this.right = right; + this.leftPresent = leftPresent; + } + + public static Either left(L1 left) { + return new Either<>(left, null, true); + } + + public static Either right(R1 right) { + return new Either<>(null, right, false); + } + + public Optional getLeft() { + if(leftPresent) return Optional.of(left); + return Optional.empty(); + } + + public Optional getRight() { + if(!leftPresent) return Optional.of(right); + return Optional.empty(); + } + + public Either ifLeft(Consumer action) { + if(leftPresent) action.accept(left); + return this; + } + + public Either ifRight(Consumer action) { + if(!leftPresent) action.accept(right); + return this; + } + + public boolean hasLeft() { + return leftPresent; + } + + public boolean hasRight() { + return !leftPresent; + } +} diff --git a/common/src/main/java/com/dfsek/terra/api/util/generic/pair/ImmutablePair.java b/common/src/main/java/com/dfsek/terra/api/util/generic/pair/ImmutablePair.java new file mode 100644 index 000000000..f58cbb52b --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/util/generic/pair/ImmutablePair.java @@ -0,0 +1,27 @@ +package com.dfsek.terra.api.util.generic.pair; + +public class ImmutablePair { + private final L left; + private final R right; + + public ImmutablePair(L left, R right) { + this.left = left; + this.right = right; + } + + public static ImmutablePair of(L1 left, R1 right) { + return new ImmutablePair<>(left, right); + } + + public R getRight() { + return right; + } + + public L getLeft() { + return left; + } + + public Pair mutable() { + return new Pair<>(left, right); + } +} diff --git a/common/src/main/java/com/dfsek/terra/api/util/generic/pair/Pair.java b/common/src/main/java/com/dfsek/terra/api/util/generic/pair/Pair.java new file mode 100644 index 000000000..dcb0be070 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/util/generic/pair/Pair.java @@ -0,0 +1,35 @@ +package com.dfsek.terra.api.util.generic.pair; + +public class Pair { + private L left; + private R right; + + public Pair(L left, R right) { + this.left = left; + this.right = right; + } + + public static Pair of(L1 left, R1 right) { + return new Pair<>(left, right); + } + + public L getLeft() { + return left; + } + + public void setLeft(L left) { + this.left = left; + } + + public R getRight() { + return right; + } + + public void setRight(R right) { + this.right = right; + } + + public ImmutablePair immutable() { + return new ImmutablePair<>(left, right); + } +} diff --git a/common/src/main/java/com/dfsek/terra/world/population/CavePopulator.java b/common/src/main/java/com/dfsek/terra/world/population/CavePopulator.java index 9767b0acc..15d386ca9 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/CavePopulator.java +++ b/common/src/main/java/com/dfsek/terra/world/population/CavePopulator.java @@ -11,7 +11,6 @@ import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.api.util.world.PopulationUtil; import com.dfsek.terra.api.world.generation.TerraBlockPopulator; import com.dfsek.terra.carving.UserDefinedCarver; -import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.config.pack.WorldConfig; import com.dfsek.terra.config.templates.CarverTemplate; import com.dfsek.terra.profiler.ProfileFuture; @@ -49,7 +48,7 @@ public class CavePopulator implements TerraBlockPopulator { Set updateNeeded = new HashSet<>(); c.carve(chunk.getX(), chunk.getZ(), world, (v, type) -> { Block b = chunk.getBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ()); - BlockData m = handle.getBlockData(b); + BlockData m = b.getBlockData(); BlockType re = m.getBlockType(); switch(type) { case CENTER: @@ -85,18 +84,18 @@ public class CavePopulator implements TerraBlockPopulator { for(Map.Entry entry : shiftCandidate.entrySet()) { Location l = entry.getKey(); Location mut = l.clone(); - BlockData orig = handle.getBlockData(l.getBlock()); + BlockData orig = l.getBlock().getBlockData(); do mut.subtract(0, 1, 0); - while(mut.getY() > 0 && handle.getBlockData(mut.getBlock()).matches(orig)); + while(mut.getY() > 0 && mut.getBlock().getBlockData().matches(orig)); try { if(template.getShift().get(entry.getValue().getBlockType()).contains(mut.getBlock().getBlockData().getBlockType())) { - handle.setBlockData(mut.getBlock(), shiftStorage.computeIfAbsent(entry.getValue().getBlockType(), BlockType::getDefaultData), false); + mut.getBlock().setBlockData(shiftStorage.computeIfAbsent(entry.getValue().getBlockType(), BlockType::getDefaultData), false); } } catch(NullPointerException ignore) { } } for(Block b : updateNeeded) { - BlockData orig = handle.getBlockData(b); + BlockData orig = b.getBlockData(); b.setBlockData(AIR, false); b.setBlockData(orig, true); } diff --git a/common/src/main/java/com/dfsek/terra/world/population/items/flora/TerraFlora.java b/common/src/main/java/com/dfsek/terra/world/population/items/flora/TerraFlora.java index 28ecac16d..0893d1c92 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/items/flora/TerraFlora.java +++ b/common/src/main/java/com/dfsek/terra/world/population/items/flora/TerraFlora.java @@ -118,7 +118,7 @@ public class TerraFlora implements Flora { ((Rotatable) data).setRotation(oneFace); } } - handle.setBlockData(location.clone().add(0, i + c, 0).getBlock(), data, physics); + location.clone().add(0, i + c, 0).getBlock().setBlockData(data, physics); } return true; } diff --git a/common/src/main/java/com/dfsek/terra/world/population/items/ores/DeformedSphereOre.java b/common/src/main/java/com/dfsek/terra/world/population/items/ores/DeformedSphereOre.java index 9df59e768..2b4ea13ee 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/items/ores/DeformedSphereOre.java +++ b/common/src/main/java/com/dfsek/terra/world/population/items/ores/DeformedSphereOre.java @@ -40,7 +40,7 @@ public class DeformedSphereOre extends Ore { if(oreLoc.distance(origin) < (rad + 0.5) * ((ore.getNoise(x, y, z) + 1) * deform)) { Block b = c.getBlock(oreLoc.getBlockX(), oreLoc.getBlockY(), oreLoc.getBlockZ()); if(getReplaceable().contains(b.getType()) && b.getLocation().getY() >= 0) - handle.setBlockData(b, getMaterial(), isApplyGravity()); + b.setBlockData(getMaterial(), isApplyGravity()); } } } diff --git a/common/src/main/java/com/dfsek/terra/world/population/items/ores/VanillaOre.java b/common/src/main/java/com/dfsek/terra/world/population/items/ores/VanillaOre.java index 798d7ff01..28f65d36f 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/items/ores/VanillaOre.java +++ b/common/src/main/java/com/dfsek/terra/world/population/items/ores/VanillaOre.java @@ -68,7 +68,7 @@ public class VanillaOre extends Ore { if(x > 15 || z > 15 || y > 255 || x < 0 || z < 0 || y < 0) continue; Block block = chunk.getBlock(x, y, z); if((d13 * d13 + d14 * d14 + d15 * d15 < 1.0D) && getReplaceable().contains(block.getType())) { - handle.setBlockData(block, getMaterial(), isApplyGravity()); + block.setBlockData(getMaterial(), isApplyGravity()); } } } diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/handles/BukkitWorldHandle.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/handles/BukkitWorldHandle.java index 8bf49a0d9..8f3736103 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/handles/BukkitWorldHandle.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/handles/BukkitWorldHandle.java @@ -1,23 +1,18 @@ package com.dfsek.terra.bukkit.handles; -import com.dfsek.terra.api.platform.block.Block; +import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.entity.EntityType; +import com.dfsek.terra.api.platform.entity.Player; import com.dfsek.terra.api.platform.handle.WorldHandle; +import com.dfsek.terra.api.util.generic.pair.Pair; +import com.dfsek.terra.bukkit.structure.WorldEditUtil; +import com.dfsek.terra.bukkit.world.BukkitAdapter; import com.dfsek.terra.bukkit.world.block.data.BukkitBlockData; import com.dfsek.terra.bukkit.world.entity.BukkitEntityType; import org.bukkit.Bukkit; public class BukkitWorldHandle implements WorldHandle { - @Override - public void setBlockData(Block block, BlockData data, boolean physics) { - block.setBlockData(data, physics); - } - - @Override - public BlockData getBlockData(Block block) { - return block.getBlockData(); - } @Override public BlockData createBlockData(String data) { @@ -29,4 +24,10 @@ public class BukkitWorldHandle implements WorldHandle { public EntityType getEntity(String id) { return new BukkitEntityType(org.bukkit.entity.EntityType.valueOf(id)); } + + @Override + public Pair getSelectedLocation(Player player) { + org.bukkit.Location[] locations = WorldEditUtil.getSelectionLocations(BukkitAdapter.adapt(player)); + return new Pair<>(BukkitAdapter.adapt(locations[0]), BukkitAdapter.adapt(locations[1])); + } } diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/structure/WorldEditUtil.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/structure/WorldEditUtil.java index e1a15dc4b..f7e5deb6c 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/structure/WorldEditUtil.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/structure/WorldEditUtil.java @@ -25,12 +25,10 @@ public final class WorldEditUtil { try { selection = we.getSession(sender).getSelection(BukkitAdapter.adapt(sender.getWorld())); } catch(IncompleteRegionException | ClassCastException e) { - sender.sendMessage("Invalid/incomplete selection!"); - return null; + throw new IllegalStateException("Invalid/incomplete selection!"); } if(selection == null) { - sender.sendMessage("Please make a selection before attempting to export!"); - return null; + throw new IllegalStateException("Please make a selection before attempting to export!"); } BlockVector3 min = selection.getMinimumPoint(); BlockVector3 max = selection.getMaximumPoint(); diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricWorldHandle.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricWorldHandle.java index cccdaa8ae..8d6919d56 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricWorldHandle.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricWorldHandle.java @@ -1,7 +1,5 @@ package com.dfsek.terra.fabric.world; -import com.dfsek.terra.api.platform.block.Block; -import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.entity.EntityType; import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.fabric.world.block.FabricBlockData; @@ -15,15 +13,6 @@ import net.minecraft.util.registry.Registry; import java.util.Locale; public class FabricWorldHandle implements WorldHandle { - @Override - public void setBlockData(Block block, BlockData data, boolean physics) { - block.setBlockData(data, physics); - } - - @Override - public BlockData getBlockData(Block block) { - return block.getBlockData(); - } @Override public FabricBlockData createBlockData(String data) { diff --git a/platforms/region/src/main/java/com/dfsek/terra/platform/RawWorldHandle.java b/platforms/region/src/main/java/com/dfsek/terra/platform/RawWorldHandle.java index dcf094708..2e2ce5b63 100644 --- a/platforms/region/src/main/java/com/dfsek/terra/platform/RawWorldHandle.java +++ b/platforms/region/src/main/java/com/dfsek/terra/platform/RawWorldHandle.java @@ -1,20 +1,10 @@ package com.dfsek.terra.platform; -import com.dfsek.terra.api.platform.block.Block; import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.entity.EntityType; import com.dfsek.terra.api.platform.handle.WorldHandle; public class RawWorldHandle implements WorldHandle { - @Override - public void setBlockData(Block block, BlockData data, boolean physics) { - - } - - @Override - public BlockData getBlockData(Block block) { - return null; - } @Override public BlockData createBlockData(String data) { From fdb2441b1a5a1134e670f4322fc3d5a25d4f6d00 Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 10 Mar 2021 15:28:50 -0700 Subject: [PATCH 78/95] export command --- .../api/command/TerraCommandManager.java | 2 +- .../terra/api/platform/block/BlockData.java | 2 + .../structure/StructureExportCommand.java | 98 ++++++++++++++++++- .../world/block/data/BukkitBlockData.java | 6 ++ .../fabric/world/block/FabricBlockData.java | 6 ++ .../java/com/dfsek/terra/platform/Data.java | 5 + .../world/block/data/SpongeBlockData.java | 5 + 7 files changed, 121 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java index b12f4ea78..d76c3a83f 100644 --- a/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java +++ b/common/src/main/java/com/dfsek/terra/api/command/TerraCommandManager.java @@ -176,7 +176,7 @@ public class TerraCommandManager implements CommandManager { try { template.execute(state.getSender()); } catch(Throwable e) { - throw new ExecutionException("Failed to execute command: ", e); + throw new ExecutionException("Failed to execute command: " + e.getMessage(), e); } } catch(InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | InjectionException e) { throw new MalformedCommandException("Unable to reflectively instantiate command: ", e); diff --git a/common/src/main/java/com/dfsek/terra/api/platform/block/BlockData.java b/common/src/main/java/com/dfsek/terra/api/platform/block/BlockData.java index fc7df1172..3082a2184 100644 --- a/common/src/main/java/com/dfsek/terra/api/platform/block/BlockData.java +++ b/common/src/main/java/com/dfsek/terra/api/platform/block/BlockData.java @@ -13,4 +13,6 @@ public interface BlockData extends Cloneable, Handle { String getAsString(); boolean isAir(); + + boolean isStructureVoid(); } diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/StructureExportCommand.java b/common/src/main/java/com/dfsek/terra/commands/structure/StructureExportCommand.java index 499493cb8..d596ff3dc 100644 --- a/common/src/main/java/com/dfsek/terra/commands/structure/StructureExportCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/structure/StructureExportCommand.java @@ -1,13 +1,107 @@ package com.dfsek.terra.commands.structure; +import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.annotation.Argument; import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.inject.ArgumentTarget; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.platform.block.Block; +import com.dfsek.terra.api.platform.block.BlockData; +import com.dfsek.terra.api.platform.block.state.BlockState; +import com.dfsek.terra.api.platform.block.state.Sign; +import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.api.util.generic.pair.Pair; -@Command +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +@Command( + arguments = { + @Argument( + value = "id" + ) + } +) public class StructureExportCommand implements CommandTemplate { + @Inject + private TerraPlugin main; + + @ArgumentTarget("id") + private String id; + @Override public void execute(CommandSender sender) { - System.out.println("export command"); + Player player = (Player) sender; + + Pair l = main.getWorldHandle().getSelectedLocation(player); + + Location l1 = l.getLeft(); + Location l2 = l.getRight(); + + StringBuilder scriptBuilder = new StringBuilder("id \"" + id + "\";\nnum y = 0;\n"); + + int centerX = 0; + int centerY = 0; + int centerZ = 0; + + for(int x = l1.getBlockX(); x <= l2.getBlockX(); x++) { + for(int y = l1.getBlockY(); y <= l2.getBlockY(); y++) { + for(int z = l1.getBlockZ(); z <= l2.getBlockZ(); z++) { + Block block = new Location(l1.getWorld(), x, y, z).getBlock(); + BlockState state = block.getState(); + if(state instanceof Sign) { + Sign sign = (Sign) state; + if(sign.getLine(0).equals("[TERRA]") && sign.getLine(1).equals("[CENTER]")) { + centerX = x - l1.getBlockX(); + centerY = y - l1.getBlockY(); + centerZ = z - l1.getBlockZ(); + } + } + } + } + } + + for(int x = l1.getBlockX(); x <= l2.getBlockX(); x++) { + for(int y = l1.getBlockY(); y <= l2.getBlockY(); y++) { + for(int z = l1.getBlockZ(); z <= l2.getBlockZ(); z++) { + + Block block = new Location(l1.getWorld(), x, y, z).getBlock(); + BlockData data = block.getBlockData(); + if(block.getBlockData().isStructureVoid()) continue; + BlockState state = block.getState(); + if(state instanceof Sign) { + Sign sign = (Sign) state; + if(sign.getLine(0).equals("[TERRA]")) { + data = main.getWorldHandle().createBlockData(sign.getLine(2) + sign.getLine(3)); + } + } + if(!data.isStructureVoid()) { + scriptBuilder.append("block(").append(x - l1.getBlockX() - centerX).append(", y + ").append(y - l1.getBlockY() - centerY).append(", ").append(z - l1.getBlockZ() - centerZ).append(", ") + .append("\""); + scriptBuilder.append(data.getAsString()).append("\");\n"); + } + } + } + } + + File file = new File(main.getDataFolder() + File.separator + "export" + File.separator + "structures", id + ".tesf"); + try { + file.getParentFile().mkdirs(); + file.createNewFile(); + } catch(IOException e) { + e.printStackTrace(); + } + try(BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { + writer.write(scriptBuilder.toString()); + } catch(IOException e) { + e.printStackTrace(); + } + + sender.sendMessage("Exported structure to " + file.getAbsolutePath()); } } diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/data/BukkitBlockData.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/data/BukkitBlockData.java index a742d0549..e0dffe72b 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/data/BukkitBlockData.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/world/block/data/BukkitBlockData.java @@ -4,6 +4,7 @@ import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.BlockType; import com.dfsek.terra.bukkit.TerraBukkitPlugin; import com.dfsek.terra.bukkit.world.BukkitAdapter; +import org.bukkit.Material; import org.bukkit.block.data.AnaloguePowerable; import org.bukkit.block.data.Directional; import org.bukkit.block.data.MultipleFacing; @@ -81,4 +82,9 @@ public class BukkitBlockData implements BlockData { public boolean isAir() { return delegate.getMaterial().isAir(); } + + @Override + public boolean isStructureVoid() { + return delegate.getMaterial() == Material.STRUCTURE_VOID; + } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlockData.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlockData.java index e2608cb2c..2467e992a 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlockData.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlockData.java @@ -4,6 +4,7 @@ import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.BlockType; import com.dfsek.terra.fabric.world.FabricAdapter; import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; import net.minecraft.state.State; import net.minecraft.util.registry.Registry; @@ -51,6 +52,11 @@ public class FabricBlockData implements BlockData { return delegate.isAir(); } + @Override + public boolean isStructureVoid() { + return delegate.getBlock() == Blocks.STRUCTURE_VOID; + } + @Override public BlockState getHandle() { return delegate; diff --git a/platforms/region/src/main/java/com/dfsek/terra/platform/Data.java b/platforms/region/src/main/java/com/dfsek/terra/platform/Data.java index 98c3ee0ec..f1c845ab0 100644 --- a/platforms/region/src/main/java/com/dfsek/terra/platform/Data.java +++ b/platforms/region/src/main/java/com/dfsek/terra/platform/Data.java @@ -52,6 +52,11 @@ public class Data implements BlockData, BlockType { return noProp.equals("minecraft:air"); } + @Override + public boolean isStructureVoid() { + return false; + } + @Override public BlockData clone() { diff --git a/platforms/sponge/src/main/java/com/dfsek/terra/sponge/world/block/data/SpongeBlockData.java b/platforms/sponge/src/main/java/com/dfsek/terra/sponge/world/block/data/SpongeBlockData.java index 9dc5dd3bd..eb68b9030 100644 --- a/platforms/sponge/src/main/java/com/dfsek/terra/sponge/world/block/data/SpongeBlockData.java +++ b/platforms/sponge/src/main/java/com/dfsek/terra/sponge/world/block/data/SpongeBlockData.java @@ -40,4 +40,9 @@ public class SpongeBlockData implements BlockData { public boolean isAir() { return false; } + + @Override + public boolean isStructureVoid() { + return false; + } } From bed8c561a4754ed7ba7a786abf1d4c6894cc57a0 Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 10 Mar 2021 15:33:38 -0700 Subject: [PATCH 79/95] add "usage" to all commands --- .../dfsek/terra/commands/AddonsCommand.java | 4 + .../dfsek/terra/commands/BiomeCommand.java | 3 +- .../dfsek/terra/commands/GetBlockCommand.java | 4 +- .../dfsek/terra/commands/PacksCommand.java | 4 +- .../dfsek/terra/commands/ReloadCommand.java | 4 +- .../terra/commands/StructureCommand.java | 3 +- .../dfsek/terra/commands/VersionCommand.java | 4 +- .../commands/structure/SpawnCommand.java | 4 +- .../structure/StructureExportCommand.java | 9 +- .../structure/StructureLoadCommand.java | 3 +- .../command/structure/ExportCommand.java | 121 ------------------ .../command/structure/LocateCommand.java | 102 --------------- .../command/structure/StructureCommand.java | 45 ------- 13 files changed, 33 insertions(+), 277 deletions(-) delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/ExportCommand.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/LocateCommand.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/StructureCommand.java diff --git a/common/src/main/java/com/dfsek/terra/commands/AddonsCommand.java b/common/src/main/java/com/dfsek/terra/commands/AddonsCommand.java index 26a69caf6..d775de66b 100644 --- a/common/src/main/java/com/dfsek/terra/commands/AddonsCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/AddonsCommand.java @@ -2,9 +2,13 @@ package com.dfsek.terra.commands; import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.annotation.Command; import com.dfsek.terra.api.injection.annotations.Inject; import com.dfsek.terra.api.platform.CommandSender; +@Command( + usage = "/terra addons" +) public class AddonsCommand implements CommandTemplate { @Inject private TerraPlugin main; diff --git a/common/src/main/java/com/dfsek/terra/commands/BiomeCommand.java b/common/src/main/java/com/dfsek/terra/commands/BiomeCommand.java index 91c97f2d5..1c813f3ab 100644 --- a/common/src/main/java/com/dfsek/terra/commands/BiomeCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/BiomeCommand.java @@ -27,7 +27,8 @@ import com.dfsek.terra.config.lang.LangUtil; aliases = {"l"}, clazz = BiomeLocateCommand.class ) - } + }, + usage = "/terra biome" ) @WorldCommand @PlayerCommand diff --git a/common/src/main/java/com/dfsek/terra/commands/GetBlockCommand.java b/common/src/main/java/com/dfsek/terra/commands/GetBlockCommand.java index 982ba3262..a57dd75f2 100644 --- a/common/src/main/java/com/dfsek/terra/commands/GetBlockCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/GetBlockCommand.java @@ -13,7 +13,9 @@ import com.dfsek.terra.api.platform.entity.Player; @WorldCommand @DebugCommand @PlayerCommand -@Command +@Command( + usage = "/terra getblock" +) public class GetBlockCommand implements CommandTemplate { @Inject private TerraPlugin main; diff --git a/common/src/main/java/com/dfsek/terra/commands/PacksCommand.java b/common/src/main/java/com/dfsek/terra/commands/PacksCommand.java index 4a92fa8fa..875ca8ea1 100644 --- a/common/src/main/java/com/dfsek/terra/commands/PacksCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/PacksCommand.java @@ -10,7 +10,9 @@ import com.dfsek.terra.config.lang.LangUtil; import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.config.pack.ConfigPackTemplate; -@Command +@Command( + usage = "/terra packs" +) public class PacksCommand implements CommandTemplate { @Inject private TerraPlugin main; diff --git a/common/src/main/java/com/dfsek/terra/commands/ReloadCommand.java b/common/src/main/java/com/dfsek/terra/commands/ReloadCommand.java index af95197da..e78909c04 100644 --- a/common/src/main/java/com/dfsek/terra/commands/ReloadCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/ReloadCommand.java @@ -7,7 +7,9 @@ import com.dfsek.terra.api.injection.annotations.Inject; import com.dfsek.terra.api.platform.CommandSender; import com.dfsek.terra.config.lang.LangUtil; -@Command() +@Command( + usage = "/terra reload" +) public class ReloadCommand implements CommandTemplate { @Inject private TerraPlugin main; diff --git a/common/src/main/java/com/dfsek/terra/commands/StructureCommand.java b/common/src/main/java/com/dfsek/terra/commands/StructureCommand.java index 1d5ca4044..63c191ea5 100644 --- a/common/src/main/java/com/dfsek/terra/commands/StructureCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/StructureCommand.java @@ -25,7 +25,8 @@ import com.dfsek.terra.commands.structure.StructureLoadCommand; value = "spawn", aliases = "s" ) - } + }, + usage = "/te structure" ) public class StructureCommand implements CommandTemplate { @Override diff --git a/common/src/main/java/com/dfsek/terra/commands/VersionCommand.java b/common/src/main/java/com/dfsek/terra/commands/VersionCommand.java index b03a3a9ba..7e8521b1c 100644 --- a/common/src/main/java/com/dfsek/terra/commands/VersionCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/VersionCommand.java @@ -7,7 +7,9 @@ import com.dfsek.terra.api.injection.annotations.Inject; import com.dfsek.terra.api.platform.CommandSender; import com.dfsek.terra.config.lang.LangUtil; -@Command +@Command( + usage = "/terra version" +) public class VersionCommand implements CommandTemplate { @Inject private TerraPlugin main; diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/SpawnCommand.java b/common/src/main/java/com/dfsek/terra/commands/structure/SpawnCommand.java index 629261288..490de66b4 100644 --- a/common/src/main/java/com/dfsek/terra/commands/structure/SpawnCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/structure/SpawnCommand.java @@ -23,7 +23,9 @@ import java.util.HashMap; @DebugCommand @PlayerCommand @WorldCommand -@Command +@Command( + usage = "/terra spawn" +) public class SpawnCommand implements CommandTemplate { @Inject private TerraPlugin main; diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/StructureExportCommand.java b/common/src/main/java/com/dfsek/terra/commands/structure/StructureExportCommand.java index d596ff3dc..47dd42a25 100644 --- a/common/src/main/java/com/dfsek/terra/commands/structure/StructureExportCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/structure/StructureExportCommand.java @@ -5,6 +5,9 @@ import com.dfsek.terra.api.command.CommandTemplate; import com.dfsek.terra.api.command.annotation.Argument; import com.dfsek.terra.api.command.annotation.Command; import com.dfsek.terra.api.command.annotation.inject.ArgumentTarget; +import com.dfsek.terra.api.command.annotation.type.DebugCommand; +import com.dfsek.terra.api.command.annotation.type.PlayerCommand; +import com.dfsek.terra.api.command.annotation.type.WorldCommand; import com.dfsek.terra.api.injection.annotations.Inject; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.platform.CommandSender; @@ -20,12 +23,16 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; +@PlayerCommand +@WorldCommand +@DebugCommand @Command( arguments = { @Argument( value = "id" ) - } + }, + usage = "/terra structure export " ) public class StructureExportCommand implements CommandTemplate { @Inject diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java b/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java index 62b172373..ae1327b11 100644 --- a/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/structure/StructureLoadCommand.java @@ -45,7 +45,8 @@ import java.util.concurrent.ThreadLocalRandom; @Switch(value = "chunk", aliases = "c" ) - } + }, + usage = "/terra structure load [ROTATION] [-c]" ) public class StructureLoadCommand implements CommandTemplate { @ArgumentTarget("rotation") diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/ExportCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/ExportCommand.java deleted file mode 100644 index 77ec5abef..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/ExportCommand.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.dfsek.terra.bukkit.command.command.structure; - -import com.dfsek.terra.bukkit.command.PlayerCommand; -import com.dfsek.terra.bukkit.structure.WorldEditUtil; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockState; -import org.bukkit.block.Sign; -import org.bukkit.block.data.BlockData; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.Collections; -import java.util.List; - -public class ExportCommand extends PlayerCommand { - public ExportCommand(com.dfsek.terra.bukkit.command.Command parent) { - super(parent); - } - - @Override - public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - Location[] l = WorldEditUtil.getSelectionLocations(sender); - if(l == null) return true; - - Location l1 = l[0]; - Location l2 = l[1]; - - StringBuilder scriptBuilder = new StringBuilder("id \"" + args[0] + "\";\nnum y = 0;\n"); - - int centerX = 0; - int centerY = 0; - int centerZ = 0; - - for(int x = l1.getBlockX(); x <= l2.getBlockX(); x++) { - for(int y = l1.getBlockY(); y <= l2.getBlockY(); y++) { - for(int z = l1.getBlockZ(); z <= l2.getBlockZ(); z++) { - Block block = new Location(l1.getWorld(), x, y, z).getBlock(); - BlockState state = block.getState(); - if(state instanceof Sign) { - Sign sign = (Sign) state; - if(sign.getLine(0).equals("[TERRA]") && sign.getLine(1).equals("[CENTER]")) { - centerX = x - l1.getBlockX(); - centerY = y - l1.getBlockY(); - centerZ = z - l1.getBlockZ(); - } - } - } - } - } - - for(int x = l1.getBlockX(); x <= l2.getBlockX(); x++) { - for(int y = l1.getBlockY(); y <= l2.getBlockY(); y++) { - for(int z = l1.getBlockZ(); z <= l2.getBlockZ(); z++) { - - Block block = new Location(l1.getWorld(), x, y, z).getBlock(); - BlockData data = block.getBlockData(); - if(block.getType().equals(Material.STRUCTURE_VOID)) continue; - BlockState state = block.getState(); - if(state instanceof Sign) { - Sign sign = (Sign) state; - if(sign.getLine(0).equals("[TERRA]")) { - data = Bukkit.createBlockData(sign.getLine(2) + sign.getLine(3)); - } - } - if(!data.getMaterial().equals(Material.STRUCTURE_VOID)) { - scriptBuilder.append("block(").append(x - l1.getBlockX() - centerX).append(", y + ").append(y - l1.getBlockY() - centerY).append(", ").append(z - l1.getBlockZ() - centerZ).append(", ") - .append("\""); - scriptBuilder.append(data.getAsString(false)).append("\");\n"); - } - } - } - } - - File file = new File(getMain().getDataFolder() + File.separator + "export" + File.separator + "structures", args[0] + ".tesf"); - try { - file.getParentFile().mkdirs(); - file.createNewFile(); - } catch(IOException e) { - e.printStackTrace(); - } - try(BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { - writer.write(scriptBuilder.toString()); - } catch(IOException e) { - e.printStackTrace(); - } - - - - sender.sendMessage("Exported structure to " + file.getAbsolutePath()); - return true; - } - - @Override - public String getName() { - return "export"; - } - - @Override - public List getSubCommands() { - return Collections.emptyList(); - } - - @Override - public int arguments() { - return 1; - } - - @Override - public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - return Collections.emptyList(); - } -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/LocateCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/LocateCommand.java deleted file mode 100644 index df8f86e83..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/LocateCommand.java +++ /dev/null @@ -1,102 +0,0 @@ -package com.dfsek.terra.bukkit.command.command.structure; - -import com.dfsek.terra.api.math.vector.Vector3; -import com.dfsek.terra.api.world.locate.AsyncStructureFinder; -import com.dfsek.terra.bukkit.TerraBukkitPlugin; -import com.dfsek.terra.bukkit.command.WorldCommand; -import com.dfsek.terra.bukkit.world.BukkitAdapter; -import com.dfsek.terra.config.lang.LangUtil; -import com.dfsek.terra.world.TerraWorld; -import com.dfsek.terra.world.population.items.TerraStructure; -import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -public class LocateCommand extends WorldCommand { - - public LocateCommand(com.dfsek.terra.bukkit.command.Command parent) { - super(parent); - } - - @SuppressWarnings({"DuplicatedCode", "deprecation"}) - @Override - public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) { - String id = args[0]; - int maxRadius; - - try { - maxRadius = Integer.parseInt(args[1]); - } catch(NumberFormatException e) { - LangUtil.send("command.structure.invalid-radius", BukkitAdapter.adapt(sender), args[1]); - return true; - } - TerraStructure s; - try { - s = Objects.requireNonNull(getMain().getWorld(BukkitAdapter.adapt(world)).getConfig().getStructureRegistry().get(id)); - } catch(IllegalArgumentException | NullPointerException e) { - LangUtil.send("command.structure.invalid", BukkitAdapter.adapt(sender), id); - return true; - } - Bukkit.getScheduler().runTaskAsynchronously((TerraBukkitPlugin) getMain(), new AsyncStructureFinder(getMain().getWorld(BukkitAdapter.adapt(world)).getBiomeProvider(), s, BukkitAdapter.adapt(sender.getLocation()), 0, maxRadius, (location) -> { - if(sender.isOnline()) { - if(location != null) { - ComponentBuilder cm = new ComponentBuilder(String.format("The nearest %s is at ", id.toLowerCase())) - .append(String.format("[%d, ~, %d]", location.getBlockX(), location.getBlockZ()), ComponentBuilder.FormatRetention.NONE) - .event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/minecraft:tp %s %d.0 %.2f %d.0", sender.getName(), location.getBlockX(), sender.getLocation().getY(), location.getBlockZ()))) - .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new BaseComponent[] {new TextComponent("Click to teleport")})) - .color(ChatColor.GREEN) - .append(String.format(" (%.1f blocks away)", location.add(new Vector3(0, sender.getLocation().getY(), 0)).distance( - BukkitAdapter.adapt(sender.getLocation().toVector()))), ComponentBuilder.FormatRetention.NONE); - sender.spigot().sendMessage(cm.create()); - } else - sender.sendMessage("Unable to locate structure. "); - } - }, getMain())); - - return true; - } - - @Override - public String getName() { - return "locate"; - } - - @Override - public List getSubCommands() { - return Collections.emptyList(); - } - - @Override - public int arguments() { - return 2; - } - - @Override - public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - if(!(sender instanceof Player) || !(TerraWorld.isTerraWorld(BukkitAdapter.adapt(((Player) sender).getWorld())))) - return Collections.emptyList(); - - List ids = new ArrayList<>(); - - getMain().getWorld(BukkitAdapter.adapt(((Player) sender).getWorld())).getConfig().getStructureRegistry().forEach((id, struct) -> ids.add(id)); - if(args.length == 1) - return ids.stream().filter(string -> string.toUpperCase().startsWith(args[0].toUpperCase())).collect(Collectors.toList()); - - return Collections.emptyList(); - } -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/StructureCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/StructureCommand.java deleted file mode 100644 index e722a6cc7..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/structure/StructureCommand.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.dfsek.terra.bukkit.command.command.structure; - -import com.dfsek.terra.bukkit.BukkitCommandSender; -import com.dfsek.terra.bukkit.command.PlayerCommand; -import com.dfsek.terra.config.lang.LangUtil; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -public class StructureCommand extends PlayerCommand { - public StructureCommand(com.dfsek.terra.bukkit.command.Command parent) { - super(parent); - } - - @Override - public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - LangUtil.send("command.structure.main-menu", new BukkitCommandSender(sender)); - return true; - } - - @Override - public String getName() { - return "structure"; - } - - @Override - public List getSubCommands() { - return Arrays.asList(new ExportCommand(this), new LocateCommand(this)); - } - - @Override - public int arguments() { - return 0; - } - - @Override - public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - return Collections.emptyList(); - } -} From 51fa58b4817717767ae3846f94cc5b510fa39b29 Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 10 Mar 2021 15:52:20 -0700 Subject: [PATCH 80/95] add command main-menu messages --- .../java/com/dfsek/terra/commands/CommandUtil.java | 2 ++ .../com/dfsek/terra/commands/GeometryCommand.java | 12 ++++++++++++ .../terra/commands/{ => biome}/BiomeCommand.java | 4 +--- .../terra/commands/profiler/ProfileCommand.java | 3 ++- .../commands/{ => structure}/StructureCommand.java | 8 +++----- 5 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/commands/GeometryCommand.java rename common/src/main/java/com/dfsek/terra/commands/{ => biome}/BiomeCommand.java (91%) rename common/src/main/java/com/dfsek/terra/commands/{ => structure}/StructureCommand.java (81%) diff --git a/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java b/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java index 75ea0fa03..3d2e3423a 100644 --- a/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java +++ b/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java @@ -2,7 +2,9 @@ package com.dfsek.terra.commands; import com.dfsek.terra.api.command.CommandManager; import com.dfsek.terra.api.command.exception.MalformedCommandException; +import com.dfsek.terra.commands.biome.BiomeCommand; import com.dfsek.terra.commands.profiler.ProfileCommand; +import com.dfsek.terra.commands.structure.StructureCommand; public final class CommandUtil { public static void registerAll(CommandManager manager) throws MalformedCommandException { diff --git a/common/src/main/java/com/dfsek/terra/commands/GeometryCommand.java b/common/src/main/java/com/dfsek/terra/commands/GeometryCommand.java new file mode 100644 index 000000000..574c1d2b7 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/GeometryCommand.java @@ -0,0 +1,12 @@ +package com.dfsek.terra.commands; + +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.config.lang.LangUtil; + +public class GeometryCommand implements CommandTemplate { + @Override + public void execute(CommandSender sender) { + LangUtil.send("command.geometry.main-menu", sender); + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/BiomeCommand.java b/common/src/main/java/com/dfsek/terra/commands/biome/BiomeCommand.java similarity index 91% rename from common/src/main/java/com/dfsek/terra/commands/BiomeCommand.java rename to common/src/main/java/com/dfsek/terra/commands/biome/BiomeCommand.java index 1c813f3ab..8871f736c 100644 --- a/common/src/main/java/com/dfsek/terra/commands/BiomeCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/biome/BiomeCommand.java @@ -1,4 +1,4 @@ -package com.dfsek.terra.commands; +package com.dfsek.terra.commands.biome; import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.command.CommandTemplate; @@ -11,8 +11,6 @@ import com.dfsek.terra.api.platform.CommandSender; import com.dfsek.terra.api.platform.entity.Player; import com.dfsek.terra.api.world.biome.UserDefinedBiome; import com.dfsek.terra.api.world.biome.provider.BiomeProvider; -import com.dfsek.terra.commands.biome.BiomeInfoCommand; -import com.dfsek.terra.commands.biome.BiomeLocateCommand; import com.dfsek.terra.config.lang.LangUtil; @Command( diff --git a/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileCommand.java b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileCommand.java index 4caad6957..c81164363 100644 --- a/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/profiler/ProfileCommand.java @@ -7,6 +7,7 @@ import com.dfsek.terra.api.command.annotation.type.DebugCommand; import com.dfsek.terra.api.command.annotation.type.PlayerCommand; import com.dfsek.terra.api.command.annotation.type.WorldCommand; import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.config.lang.LangUtil; @Command( subcommands = { @@ -23,6 +24,6 @@ import com.dfsek.terra.api.platform.CommandSender; public class ProfileCommand implements CommandTemplate { @Override public void execute(CommandSender sender) { - + LangUtil.send("command.profile.main-menu", sender); } } diff --git a/common/src/main/java/com/dfsek/terra/commands/StructureCommand.java b/common/src/main/java/com/dfsek/terra/commands/structure/StructureCommand.java similarity index 81% rename from common/src/main/java/com/dfsek/terra/commands/StructureCommand.java rename to common/src/main/java/com/dfsek/terra/commands/structure/StructureCommand.java index 63c191ea5..c12f021d2 100644 --- a/common/src/main/java/com/dfsek/terra/commands/StructureCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/structure/StructureCommand.java @@ -1,12 +1,10 @@ -package com.dfsek.terra.commands; +package com.dfsek.terra.commands.structure; import com.dfsek.terra.api.command.CommandTemplate; import com.dfsek.terra.api.command.annotation.Command; import com.dfsek.terra.api.command.annotation.Subcommand; import com.dfsek.terra.api.platform.CommandSender; -import com.dfsek.terra.commands.structure.SpawnCommand; -import com.dfsek.terra.commands.structure.StructureExportCommand; -import com.dfsek.terra.commands.structure.StructureLoadCommand; +import com.dfsek.terra.config.lang.LangUtil; @Command( subcommands = { @@ -31,6 +29,6 @@ import com.dfsek.terra.commands.structure.StructureLoadCommand; public class StructureCommand implements CommandTemplate { @Override public void execute(CommandSender sender) { - + LangUtil.send("command.structure.main-menu", sender); } } From 1f16a82a8d9f16ba8cc5e6ec977bb763b7a6963e Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 10 Mar 2021 16:02:25 -0700 Subject: [PATCH 81/95] implement GeometryCommands --- .../com/dfsek/terra/commands/CommandUtil.java | 2 + .../dfsek/terra/commands/GeometryCommand.java | 12 ---- .../geometry/DeformedSphereCommand.java | 65 +++++++++++++++++++ .../commands/geometry/GeometryCommand.java | 39 +++++++++++ .../commands/geometry/SphereCommand.java | 44 +++++++++++++ .../terra/commands/geometry/TubeCommand.java | 49 ++++++++++++++ 6 files changed, 199 insertions(+), 12 deletions(-) delete mode 100644 common/src/main/java/com/dfsek/terra/commands/GeometryCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/geometry/DeformedSphereCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/geometry/GeometryCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/geometry/SphereCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/geometry/TubeCommand.java diff --git a/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java b/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java index 3d2e3423a..a9e327d08 100644 --- a/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java +++ b/common/src/main/java/com/dfsek/terra/commands/CommandUtil.java @@ -3,6 +3,7 @@ package com.dfsek.terra.commands; import com.dfsek.terra.api.command.CommandManager; import com.dfsek.terra.api.command.exception.MalformedCommandException; import com.dfsek.terra.commands.biome.BiomeCommand; +import com.dfsek.terra.commands.geometry.GeometryCommand; import com.dfsek.terra.commands.profiler.ProfileCommand; import com.dfsek.terra.commands.structure.StructureCommand; @@ -16,5 +17,6 @@ public final class CommandUtil { manager.register("getblock", GetBlockCommand.class); manager.register("packs", PacksCommand.class); manager.register("biome", BiomeCommand.class); + manager.register("geometry", GeometryCommand.class); } } diff --git a/common/src/main/java/com/dfsek/terra/commands/GeometryCommand.java b/common/src/main/java/com/dfsek/terra/commands/GeometryCommand.java deleted file mode 100644 index 574c1d2b7..000000000 --- a/common/src/main/java/com/dfsek/terra/commands/GeometryCommand.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.dfsek.terra.commands; - -import com.dfsek.terra.api.command.CommandTemplate; -import com.dfsek.terra.api.platform.CommandSender; -import com.dfsek.terra.config.lang.LangUtil; - -public class GeometryCommand implements CommandTemplate { - @Override - public void execute(CommandSender sender) { - LangUtil.send("command.geometry.main-menu", sender); - } -} diff --git a/common/src/main/java/com/dfsek/terra/commands/geometry/DeformedSphereCommand.java b/common/src/main/java/com/dfsek/terra/commands/geometry/DeformedSphereCommand.java new file mode 100644 index 000000000..46ce84559 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/geometry/DeformedSphereCommand.java @@ -0,0 +1,65 @@ +package com.dfsek.terra.commands.geometry; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.annotation.Argument; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.inject.ArgumentTarget; +import com.dfsek.terra.api.command.annotation.type.DebugCommand; +import com.dfsek.terra.api.command.annotation.type.PlayerCommand; +import com.dfsek.terra.api.command.arg.DoubleArgumentParser; +import com.dfsek.terra.api.command.arg.IntegerArgumentParser; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.math.noise.samplers.noise.simplex.OpenSimplex2Sampler; +import com.dfsek.terra.api.math.vector.Vector3; +import com.dfsek.terra.api.math.voxel.DeformedSphere; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.platform.entity.Player; + +import java.util.concurrent.ThreadLocalRandom; + +@DebugCommand +@PlayerCommand +@Command( + arguments = { + @Argument( + value = "radius", + argumentParser = IntegerArgumentParser.class + ), + @Argument( + value = "deform", + argumentParser = DoubleArgumentParser.class + ), + @Argument( + value = "frequency", + argumentParser = DoubleArgumentParser.class + ) + }, + usage = "/terra geometry deformedsphere " +) +public class DeformedSphereCommand implements CommandTemplate { + @ArgumentTarget("radius") + private Integer radius; + + @ArgumentTarget("deform") + private Double deform; + + @ArgumentTarget("frequency") + private Double frequency; + + @Inject + private TerraPlugin main; + + @Override + public void execute(CommandSender sender) { + Player player = (Player) sender; + + OpenSimplex2Sampler noise = new OpenSimplex2Sampler(ThreadLocalRandom.current().nextInt()); + noise.setFrequency(frequency); + + DeformedSphere sphere = new DeformedSphere(player.getLocation().toVector(), radius, deform, noise); + for(Vector3 v : sphere.getGeometry()) { + v.toLocation(player.getWorld()).getBlock().setBlockData(main.getWorldHandle().createBlockData("minecraft:stone"), false); + } + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/geometry/GeometryCommand.java b/common/src/main/java/com/dfsek/terra/commands/geometry/GeometryCommand.java new file mode 100644 index 000000000..d41bc8506 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/geometry/GeometryCommand.java @@ -0,0 +1,39 @@ +package com.dfsek.terra.commands.geometry; + +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.Subcommand; +import com.dfsek.terra.api.command.annotation.type.DebugCommand; +import com.dfsek.terra.api.command.annotation.type.PlayerCommand; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.config.lang.LangUtil; + + +@DebugCommand +@PlayerCommand +@Command( + subcommands = { + @Subcommand( + value = "sphere", + clazz = SphereCommand.class, + aliases = {"s"} + ), + @Subcommand( + value = "deformedsphere", + clazz = DeformedSphereCommand.class, + aliases = {"df"} + ), + @Subcommand( + value = "tube", + clazz = TubeCommand.class, + aliases = {"t"} + ) + }, + usage = "/terra geometry" +) +public class GeometryCommand implements CommandTemplate { + @Override + public void execute(CommandSender sender) { + LangUtil.send("command.geometry.main-menu", sender); + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/geometry/SphereCommand.java b/common/src/main/java/com/dfsek/terra/commands/geometry/SphereCommand.java new file mode 100644 index 000000000..7d8586e6a --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/geometry/SphereCommand.java @@ -0,0 +1,44 @@ +package com.dfsek.terra.commands.geometry; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.annotation.Argument; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.inject.ArgumentTarget; +import com.dfsek.terra.api.command.annotation.type.DebugCommand; +import com.dfsek.terra.api.command.annotation.type.PlayerCommand; +import com.dfsek.terra.api.command.arg.IntegerArgumentParser; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.math.vector.Vector3; +import com.dfsek.terra.api.math.voxel.Sphere; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.platform.entity.Player; + +@DebugCommand +@PlayerCommand +@Command( + arguments = { + @Argument( + value = "radius", + argumentParser = IntegerArgumentParser.class + ) + }, + usage = "/terra geometry sphere " +) +public class SphereCommand implements CommandTemplate { + @ArgumentTarget("radius") + private Integer radius; + + @Inject + private TerraPlugin main; + + @Override + public void execute(CommandSender sender) { + Player player = (Player) sender; + + Sphere sphere = new Sphere(player.getLocation().toVector(), radius); + for(Vector3 v : sphere.getGeometry()) { + v.toLocation(player.getWorld()).getBlock().setBlockData(main.getWorldHandle().createBlockData("minecraft:stone"), false); + } + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/geometry/TubeCommand.java b/common/src/main/java/com/dfsek/terra/commands/geometry/TubeCommand.java new file mode 100644 index 000000000..b24694762 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/geometry/TubeCommand.java @@ -0,0 +1,49 @@ +package com.dfsek.terra.commands.geometry; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.annotation.Argument; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.inject.ArgumentTarget; +import com.dfsek.terra.api.command.annotation.type.DebugCommand; +import com.dfsek.terra.api.command.annotation.type.PlayerCommand; +import com.dfsek.terra.api.command.arg.IntegerArgumentParser; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.math.vector.Location; +import com.dfsek.terra.api.math.vector.Vector3; +import com.dfsek.terra.api.math.voxel.Tube; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.api.util.generic.pair.Pair; + +@DebugCommand +@PlayerCommand +@Command( + arguments = { + @Argument( + value = "radius", + argumentParser = IntegerArgumentParser.class + ) + }, + usage = "/terra geometry tube " +) +public class TubeCommand implements CommandTemplate { + @ArgumentTarget("radius") + private Integer radius; + + @Inject + private TerraPlugin main; + + @Override + public void execute(CommandSender sender) { + Player player = (Player) sender; + + Pair locations = main.getWorldHandle().getSelectedLocation(player); + + Tube tube = new Tube(locations.getLeft().toVector(), locations.getRight().toVector(), radius); + + for(Vector3 v : tube.getGeometry()) { + v.toLocation(player.getWorld()).getBlock().setBlockData(main.getWorldHandle().createBlockData("minecraft:stone"), false); + } + } +} From d6b5f60b1835d9acc74c9ca384cd53b3a0649615 Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 10 Mar 2021 16:08:25 -0700 Subject: [PATCH 82/95] implement Bukkit-specific commands --- common/src/main/resources/lang/en_us.yml | 2 +- .../dfsek/terra/bukkit/TerraBukkitPlugin.java | 4 + .../dfsek/terra/bukkit/command/Command.java | 113 ------------------ .../terra/bukkit/command/DebugCommand.java | 8 -- .../terra/bukkit/command/FixChunkCommand.java | 20 ++++ .../terra/bukkit/command/PlayerCommand.java | 51 -------- .../terra/bukkit/command/SaveDataCommand.java | 16 +++ .../terra/bukkit/command/WorldCommand.java | 53 -------- .../command/command/FixChunkCommand.java | 45 ------- .../command/command/SaveDataCommand.java | 47 -------- .../geometry/DeformedSphereCommand.java | 75 ------------ .../command/geometry/GeometryCommand.java | 46 ------- .../command/geometry/SphereCommand.java | 58 --------- .../command/command/geometry/TubeCommand.java | 61 ---------- 14 files changed, 41 insertions(+), 558 deletions(-) delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/Command.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/DebugCommand.java create mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/FixChunkCommand.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/PlayerCommand.java create mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/SaveDataCommand.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/WorldCommand.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/FixChunkCommand.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/SaveDataCommand.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/geometry/DeformedSphereCommand.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/geometry/GeometryCommand.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/geometry/SphereCommand.java delete mode 100644 platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/geometry/TubeCommand.java diff --git a/common/src/main/resources/lang/en_us.yml b/common/src/main/resources/lang/en_us.yml index 048e36e0f..cde2101d9 100644 --- a/common/src/main/resources/lang/en_us.yml +++ b/common/src/main/resources/lang/en_us.yml @@ -112,7 +112,7 @@ warning: error: severe-config: "A severe configuration error has prevented Terra from properly generating terrain at coordinates: %1$s, %2$s. Please check your configuration for errors. Any config errors will have been reported above." debug: - data-save: "Saved population data for world \"%s\"" + data-save : "Saved population data." use-paper: - "You appear to be using Spigot/CraftBukkit." - "While Terra &odoes&r work on Spigot, some functionality will be lost. (Terra is untested on CraftBukkit; no support will be given for CraftBukkit)." diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java index b5a68974a..bee93ee0e 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java @@ -23,6 +23,8 @@ import com.dfsek.terra.api.util.logging.JavaLogger; import com.dfsek.terra.api.util.logging.Logger; import com.dfsek.terra.api.world.generation.TerraChunkGenerator; import com.dfsek.terra.bukkit.command.BukkitCommandAdapter; +import com.dfsek.terra.bukkit.command.FixChunkCommand; +import com.dfsek.terra.bukkit.command.SaveDataCommand; import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper; import com.dfsek.terra.bukkit.handles.BukkitItemHandle; import com.dfsek.terra.bukkit.handles.BukkitWorldHandle; @@ -178,6 +180,8 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { try { CommandUtil.registerAll(manager); + manager.register("save-data", SaveDataCommand.class); + manager.register("fix-chunk", FixChunkCommand.class); } catch(MalformedCommandException e) { // This should never happen. logger().severe("Errors occurred while registering commands."); e.printStackTrace(); diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/Command.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/Command.java deleted file mode 100644 index 6fd8bbfee..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/Command.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.dfsek.terra.bukkit.command; - -import com.dfsek.terra.api.TerraPlugin; -import com.dfsek.terra.bukkit.BukkitCommandSender; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * Represents a command or subcommands, can be nested via getSubCommands. - */ -public abstract class Command implements CommandExecutor, TabCompleter { - private final TerraPlugin main; - public Command(TerraPlugin main) { - this.main = main; - } - public Command(Command parent) { - main = parent.getMain(); - } - - public TerraPlugin getMain() { - return main; - } - - /** - * Gets the name of the command/subcommands - * - * @return Name of command - */ - public abstract String getName(); - - /** - * Gets a list of subcommands - * @return List of subcommands - */ - public abstract List getSubCommands(); - - /** - * Executes the given command, returning its success. - *
- * If false is returned, then the "usage" plugin.yml entry for this command - * (if defined) will be sent to the player. - * - * @param sender Source of the command - * @param command CommandTemplate which was executed - * @param label Alias of the command which was used - * @param args Passed command arguments - * @return true if a valid command, otherwise false - */ - - public abstract boolean execute(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command command, @NotNull String label, @NotNull String[] args); - /** - * Gets the number of arguments - * @return Number of arguments - */ - public abstract int arguments(); - - /** - * Executes the given command, invoking subcommands if applicable and returning its success. - *
- * If false is returned, then the "usage" plugin.yml entry for this command - * (if defined) will be sent to the player. - * - * @param sender Source of the command - * @param command CommandTemplate which was executed - * @param label Alias of the command which was used - * @param args Passed command arguments - * @return true if a valid command, otherwise false - */ - @Override - public final boolean onCommand(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command command, @NotNull String label, @NotNull String[] args) { - if(this instanceof DebugCommand && ! main.isDebug()) { - main.getLanguage().send("command.debug-only", new BukkitCommandSender(sender)); - return true; - } - if(args.length > 0) { - for(Command c : getSubCommands()) { - if(c.getName().equals(args[0])) { - return c.onCommand(sender, command, label, Arrays.stream(args, 1, args.length).toArray(String[]::new)); - } - } - if(args.length != arguments()) { - main.getLanguage().send("command.invalid", new BukkitCommandSender(sender), String.valueOf(arguments()), String.valueOf(args.length)); - return true; - } - return execute(sender, command, label, args); - } - if(args.length != arguments()) { - main.getLanguage().send("command.invalid", new BukkitCommandSender(sender), String.valueOf(arguments()), String.valueOf(args.length)); - return true; - } - return execute(sender, command, label, new String[] {}); - } - - public abstract List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args); - - @Override - public final @Nullable List onTabComplete(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String alias, @NotNull String[] args) { - List complete = new ArrayList<>(); - if(args.length > 0) for(Command c : getSubCommands()) { - if(c.getName().startsWith(args[0])) complete.add(c.getName()); - if(c.getName().equals(args[0])) return c.onTabComplete(sender, command, alias, Arrays.stream(args, 1, args.length).toArray(String[]::new)); - } - complete.addAll(getTabCompletions(sender, alias, args)); - return complete; - } -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/DebugCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/DebugCommand.java deleted file mode 100644 index 738dde4fc..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/DebugCommand.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.dfsek.terra.bukkit.command; - -/** - * Implementing this interface marks a command as debug-only. - * If a parent command implements this interface, all child commands will be considered debug commands, regardless of whether they implement DebugCommand as well. - */ -public interface DebugCommand { -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/FixChunkCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/FixChunkCommand.java new file mode 100644 index 000000000..87d69c115 --- /dev/null +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/FixChunkCommand.java @@ -0,0 +1,20 @@ +package com.dfsek.terra.bukkit.command; + +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.type.PlayerCommand; +import com.dfsek.terra.api.command.annotation.type.WorldCommand; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper; + +@Command +@WorldCommand +@PlayerCommand +public class FixChunkCommand implements CommandTemplate { + @Override + public void execute(CommandSender sender) { + Player player = (Player) sender; + BukkitChunkGeneratorWrapper.fixChunk(player.getWorld().getChunkAt(player.getLocation())); + } +} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/PlayerCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/PlayerCommand.java deleted file mode 100644 index cf52d897d..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/PlayerCommand.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.dfsek.terra.bukkit.command; - -import com.dfsek.terra.bukkit.BukkitCommandSender; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -/** - * A command that may only be executed by a player. If executor is not a player, a message will be displayed and no action will be performed. - */ -public abstract class PlayerCommand extends Command { - public PlayerCommand(Command parent) { - super(parent); - } - - /** - * Executes the given command, returning its success. - *
- * If false is returned, then the "usage" plugin.yml entry for this command - * (if defined) will be sent to the player. - * - * @param sender Source of the command - * @param command CommandTemplate which was executed - * @param label Alias of the command which was used - * @param args Passed command arguments - * @return true if a valid command, otherwise false - */ - @Override - public final boolean execute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) { - if(!(sender instanceof Player)) { - getMain().getLanguage().send("command.players-only", new BukkitCommandSender(sender)); - return true; - } - Player p = (Player) sender; - return execute(p, command, label, args); - } - - /** - * Executes the given command, returning its success. - *
- * If false is returned, then the "usage" plugin.yml entry for this command - * (if defined) will be sent to the player. - * - * @param sender Player that executed command - * @param command CommandTemplate which was executed - * @param label Alias of the command which was used - * @param args Passed command arguments - * @return true if a valid command, otherwise false - */ - public abstract boolean execute(@NotNull Player sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args); -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/SaveDataCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/SaveDataCommand.java new file mode 100644 index 000000000..4648cb01e --- /dev/null +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/SaveDataCommand.java @@ -0,0 +1,16 @@ +package com.dfsek.terra.bukkit.command; + +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper; +import com.dfsek.terra.config.lang.LangUtil; + +@Command +public class SaveDataCommand implements CommandTemplate { + @Override + public void execute(CommandSender sender) { + BukkitChunkGeneratorWrapper.saveAll(); + LangUtil.send("debug.data-save", sender); + } +} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/WorldCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/WorldCommand.java deleted file mode 100644 index 65738d220..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/WorldCommand.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.dfsek.terra.bukkit.command; - -import com.dfsek.terra.bukkit.BukkitCommandSender; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.generator.ChunkGenerator; -import org.jetbrains.annotations.NotNull; - -/** - * A command that must be executed by a player, in a Terra world. - */ -public abstract class WorldCommand extends PlayerCommand { - public WorldCommand(Command parent) { - super(parent); - } - - /** - * Executes the given command, returning its success. - *
- * If false is returned, then the "usage" plugin.yml entry for this command - * (if defined) will be sent to the player. - * - * @param sender Source of the command - * @param command Command which was executed - * @param label Alias of the command which was used - * @param args Passed command arguments - * @return true if a valid command, otherwise false - */ - @Override - public boolean execute(@NotNull Player sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) { - if(sender.getWorld().getGenerator() instanceof ChunkGenerator) { // TODO: implementation - return execute(sender, command, label, args, sender.getWorld()); - } else { - getMain().getLanguage().send("command.world", new BukkitCommandSender(sender)); - } - return true; - } - - /** - * Executes the given command, returning its success. - *
- * If false is returned, then the "usage" plugin.yml entry for this command - * (if defined) will be sent to the player. - * - * @param sender Player that executed command - * @param command Command which was executed - * @param label Alias of the command which was used - * @param args Passed command arguments - * @param world World in which command was executed - * @return true if a valid command, otherwise false - */ - public abstract boolean execute(@NotNull Player sender, @NotNull org.bukkit.command.Command command, @NotNull String label, @NotNull String[] args, World world); -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/FixChunkCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/FixChunkCommand.java deleted file mode 100644 index 4b9d730d7..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/FixChunkCommand.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.dfsek.terra.bukkit.command.command; - -import com.dfsek.terra.bukkit.command.WorldCommand; -import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper; -import com.dfsek.terra.bukkit.world.BukkitAdapter; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; -import java.util.List; - -public class FixChunkCommand extends WorldCommand { - public FixChunkCommand(com.dfsek.terra.bukkit.command.Command parent) { - super(parent); - } - - @Override - public boolean execute(@NotNull Player player, @NotNull Command command, @NotNull String s, @NotNull String[] strings, World world) { - BukkitChunkGeneratorWrapper.fixChunk(BukkitAdapter.adapt(player.getLocation().getChunk())); - return true; - } - - @Override - public String getName() { - return "fixchunk"; - } - - @Override - public List getSubCommands() { - return Collections.emptyList(); - } - - @Override - public int arguments() { - return 0; - } - - @Override - public List getTabCompletions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) { - return Collections.emptyList(); - } -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/SaveDataCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/SaveDataCommand.java deleted file mode 100644 index 4cb09daba..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/SaveDataCommand.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.dfsek.terra.bukkit.command.command; - -import com.dfsek.terra.bukkit.BukkitCommandSender; -import com.dfsek.terra.bukkit.command.Command; -import com.dfsek.terra.bukkit.command.WorldCommand; -import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper; -import com.dfsek.terra.config.lang.LangUtil; -import org.bukkit.World; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; -import java.util.List; - -public class SaveDataCommand extends WorldCommand { - public SaveDataCommand(Command parent) { - super(parent); - } - - @Override - public String getName() { - return "save-data"; - } - - @Override - public List getSubCommands() { - return Collections.emptyList(); - } - - @Override - public int arguments() { - return 0; - } - - @Override - public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - return Collections.emptyList(); - } - - @Override - public boolean execute(@NotNull Player sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args, World w) { - BukkitChunkGeneratorWrapper.saveAll(); - LangUtil.send("debug.data-save", new BukkitCommandSender(sender), w.getName()); - return true; - } -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/geometry/DeformedSphereCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/geometry/DeformedSphereCommand.java deleted file mode 100644 index 716f28517..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/geometry/DeformedSphereCommand.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.dfsek.terra.bukkit.command.command.geometry; - -import com.dfsek.terra.api.math.noise.samplers.noise.simplex.OpenSimplex2Sampler; -import com.dfsek.terra.api.math.vector.Vector3; -import com.dfsek.terra.api.math.voxel.DeformedSphere; -import com.dfsek.terra.bukkit.BukkitCommandSender; -import com.dfsek.terra.bukkit.command.PlayerCommand; -import com.dfsek.terra.bukkit.world.BukkitAdapter; -import com.dfsek.terra.config.lang.LangUtil; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; -import java.util.List; - -public class DeformedSphereCommand extends PlayerCommand { - public DeformedSphereCommand(com.dfsek.terra.bukkit.command.Command parent) { - super(parent); - } - - @Override - public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - int radius; - try { - radius = Integer.parseInt(args[0]); - } catch(NumberFormatException e) { - LangUtil.send("command.geometry.deform.invalid-radius", new BukkitCommandSender(sender), args[0]); - return true; - } - double deform; - try { - deform = Double.parseDouble(args[1]); - } catch(NumberFormatException e) { - LangUtil.send("command.geometry.deform.invalid-deform", new BukkitCommandSender(sender), args[1]); - return true; - } - - double freq; - try { - freq = Float.parseFloat(args[2]); - } catch(NumberFormatException e) { - LangUtil.send("command.geometry.deform.invalid-frequency", new BukkitCommandSender(sender), args[2]); - return true; - } - OpenSimplex2Sampler n = new OpenSimplex2Sampler((int) sender.getWorld().getSeed()); - n.setFrequency(freq); - DeformedSphere sphere = new DeformedSphere(BukkitAdapter.adapt(sender).getLocation().toVector(), radius, deform, n); - for(Vector3 v : sphere.getGeometry()) { - v.toLocation(BukkitAdapter.adapt(sender.getWorld())).getBlock().setBlockData(getMain().getWorldHandle().createBlockData("minecraft:stone"), false); - } - return true; - } - - @Override - public String getName() { - return "deformedsphere"; - } - - @Override - public List getSubCommands() { - return Collections.emptyList(); - } - - @Override - public int arguments() { - return 3; - } - - @Override - public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - return Collections.emptyList(); - } -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/geometry/GeometryCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/geometry/GeometryCommand.java deleted file mode 100644 index 8e9b2d89e..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/geometry/GeometryCommand.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.dfsek.terra.bukkit.command.command.geometry; - -import com.dfsek.terra.bukkit.BukkitCommandSender; -import com.dfsek.terra.bukkit.command.DebugCommand; -import com.dfsek.terra.bukkit.command.PlayerCommand; -import com.dfsek.terra.config.lang.LangUtil; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -public class GeometryCommand extends PlayerCommand implements DebugCommand { - public GeometryCommand(com.dfsek.terra.bukkit.command.Command parent) { - super(parent); - } - - @Override - public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - LangUtil.send("command.geometry.main-menu", new BukkitCommandSender(sender)); - return true; - } - - @Override - public String getName() { - return "geometry"; - } - - @Override - public List getSubCommands() { - return Arrays.asList(new SphereCommand(this), new TubeCommand(this), new DeformedSphereCommand(this)); - } - - @Override - public int arguments() { - return 0; - } - - @Override - public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - return Collections.emptyList(); - } -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/geometry/SphereCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/geometry/SphereCommand.java deleted file mode 100644 index a726d7b02..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/geometry/SphereCommand.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.dfsek.terra.bukkit.command.command.geometry; - -import com.dfsek.terra.api.math.vector.Vector3; -import com.dfsek.terra.api.math.voxel.Sphere; -import com.dfsek.terra.bukkit.BukkitCommandSender; -import com.dfsek.terra.bukkit.BukkitPlayer; -import com.dfsek.terra.bukkit.command.PlayerCommand; -import com.dfsek.terra.bukkit.world.BukkitAdapter; -import com.dfsek.terra.config.lang.LangUtil; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; -import java.util.List; - -public class SphereCommand extends PlayerCommand { - public SphereCommand(com.dfsek.terra.bukkit.command.Command parent) { - super(parent); - } - - @Override - public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - int radius; - try { - radius = Integer.parseInt(args[0]); - } catch(NumberFormatException e) { - LangUtil.send("command.geometry.sphere.invalid-radius", new BukkitCommandSender(sender), args[0]); - return true; - } - Sphere sphere = new Sphere(new BukkitPlayer(sender).getLocation().toVector(), radius); - for(Vector3 v : sphere.getGeometry()) { - v.toLocation(BukkitAdapter.adapt(sender.getWorld())).getBlock().setBlockData(getMain().getWorldHandle().createBlockData("minecraft:stone"), false); - } - return true; - } - - @Override - public String getName() { - return "sphere"; - } - - @Override - public List getSubCommands() { - return Collections.emptyList(); - } - - @Override - public int arguments() { - return 1; - } - - @Override - public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - return Collections.emptyList(); - } -} diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/geometry/TubeCommand.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/geometry/TubeCommand.java deleted file mode 100644 index 33bd17ad5..000000000 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/command/command/geometry/TubeCommand.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.dfsek.terra.bukkit.command.command.geometry; - -import com.dfsek.terra.api.math.vector.Vector3; -import com.dfsek.terra.api.math.voxel.Tube; -import com.dfsek.terra.bukkit.BukkitCommandSender; -import com.dfsek.terra.bukkit.command.PlayerCommand; -import com.dfsek.terra.bukkit.structure.WorldEditUtil; -import com.dfsek.terra.bukkit.world.BukkitAdapter; -import com.dfsek.terra.config.lang.LangUtil; -import org.bukkit.Location; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; -import java.util.List; - -public class TubeCommand extends PlayerCommand { - public TubeCommand(com.dfsek.terra.bukkit.command.Command parent) { - super(parent); - } - - @Override - public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - Location[] l = WorldEditUtil.getSelectionPositions(sender); - if(l == null) return true; - int radius; - try { - radius = Integer.parseInt(args[0]); - } catch(NumberFormatException e) { - LangUtil.send("command.geometry.tube.invalid-radius", new BukkitCommandSender(sender), args[0]); - return true; - } - Tube tube = new Tube(BukkitAdapter.adapt(l[0].toVector()), BukkitAdapter.adapt(l[1].toVector()), radius); - for(Vector3 v : tube.getGeometry()) { - v.toLocation(BukkitAdapter.adapt(sender.getWorld())).getBlock().setBlockData(getMain().getWorldHandle().createBlockData("minecraft:stone"), false); - } - return true; - } - - @Override - public String getName() { - return "tube"; - } - - @Override - public List getSubCommands() { - return Collections.emptyList(); - } - - @Override - public int arguments() { - return 1; - } - - @Override - public List getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - return Collections.emptyList(); - } -} From 819d795c2336192ec0325d3d1ccc1f354062ea77 Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 10 Mar 2021 16:16:11 -0700 Subject: [PATCH 83/95] Fabric cleanup --- .../java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java | 1 - .../java/com/dfsek/terra/fabric/TerraFabricPlugin.java | 7 +++---- .../fabric/world/handles/world/FabricWorldAccess.java | 1 - 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java index bee93ee0e..e1254e51e 100644 --- a/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java +++ b/platforms/bukkit/src/main/java/com/dfsek/terra/bukkit/TerraBukkitPlugin.java @@ -173,7 +173,6 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin { registry.loadAll(this); // Load all config packs. PluginCommand c = Objects.requireNonNull(getCommand("terra")); - //TerraCommand command = new TerraCommand(this); // Set up main Terra command. CommandManager manager = new TerraCommandManager(this); diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java index c84a8b1b6..d34893776 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/TerraFabricPlugin.java @@ -359,8 +359,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { try { manager.execute(args.remove(0), FabricAdapter.adapt(context.getSource()), args); } catch(CommandException e) { - e.printStackTrace(); - return -1; + context.getSource().sendError(new LiteralText(e.getMessage())); } return 1; }); @@ -400,8 +399,8 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer { @Global public void injectTrees(ConfigPackPreLoadEvent event) { CheckedRegistry treeRegistry = event.getPack().getTreeRegistry(); - injectTree(treeRegistry, "BROWN_MUSHROOM", ConfiguredFeatures.BROWN_MUSHROOM_GIANT); - injectTree(treeRegistry, "RED_MUSHROOM", ConfiguredFeatures.RED_MUSHROOM_GIANT); + injectTree(treeRegistry, "BROWN_MUSHROOM", ConfiguredFeatures.HUGE_BROWN_MUSHROOM); + injectTree(treeRegistry, "RED_MUSHROOM", ConfiguredFeatures.HUGE_RED_MUSHROOM); injectTree(treeRegistry, "JUNGLE", ConfiguredFeatures.MEGA_JUNGLE_TREE); injectTree(treeRegistry, "JUNGLE_COCOA", ConfiguredFeatures.JUNGLE_TREE); injectTree(treeRegistry, "LARGE_OAK", ConfiguredFeatures.FANCY_OAK); diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java index a8dfe28b1..8cb464353 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/handles/world/FabricWorldAccess.java @@ -77,7 +77,6 @@ public class FabricWorldAccess implements World, FabricWorldHandle { net.minecraft.entity.Entity entity = FabricAdapter.adapt(entityType).create(((ServerWorldAccess) delegate).toServerWorld()); entity.setPos(location.getX(), location.getY(), location.getZ()); delegate.spawnEntity(entity); - System.out.println("Spawned " + entity); return new FabricEntity(entity); } From 58162027a9b433a8f7c46fb8b5738d6b98e07153 Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 10 Mar 2021 16:21:04 -0700 Subject: [PATCH 84/95] specify problematic addon class --- .../src/main/java/com/dfsek/terra/addon/AddonClassLoader.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/com/dfsek/terra/addon/AddonClassLoader.java b/common/src/main/java/com/dfsek/terra/addon/AddonClassLoader.java index cb749a3ef..6f09a5307 100644 --- a/common/src/main/java/com/dfsek/terra/addon/AddonClassLoader.java +++ b/common/src/main/java/com/dfsek/terra/addon/AddonClassLoader.java @@ -47,7 +47,8 @@ public class AddonClassLoader extends URLClassLoader { if(addon == null) continue; - if(!TerraAddon.class.isAssignableFrom(clazz)) throw new IllegalArgumentException("Addon class must extend TerraAddon."); + if(!TerraAddon.class.isAssignableFrom(clazz)) + throw new IllegalArgumentException("Addon class \"" + clazz + "\" must extend TerraAddon."); set.add((Class) clazz); } catch(ClassNotFoundException e) { From ce3c0f105e3070fde63fdc1b75aab75f7c656c65 Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 10 Mar 2021 16:26:15 -0700 Subject: [PATCH 85/95] more specific duplicate ID message --- .../main/java/com/dfsek/terra/addon/AddonPool.java | 14 ++++++++++++-- .../java/com/dfsek/terra/addon/PreLoadAddon.java | 9 ++++++++- .../dfsek/terra/registry/master/AddonRegistry.java | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/com/dfsek/terra/addon/AddonPool.java b/common/src/main/java/com/dfsek/terra/addon/AddonPool.java index 1fe0844dd..5636aa06b 100644 --- a/common/src/main/java/com/dfsek/terra/addon/AddonPool.java +++ b/common/src/main/java/com/dfsek/terra/addon/AddonPool.java @@ -11,8 +11,18 @@ public class AddonPool { private final Map pool = new HashMap<>(); public void add(PreLoadAddon addon) throws AddonLoadException { - if(pool.containsKey(addon.getId())) - throw new AddonLoadException("Duplicate addon ID: " + addon.getId()); + if(pool.containsKey(addon.getId())) { + String message = "Duplicate addon ID: " + + addon.getId() + "; original ID from file: " + + pool.get(addon.getId()).getFile().getAbsolutePath() + + ", class: " + + pool.get(addon.getId()).getAddonClass().getCanonicalName() + + "Duplicate ID from file: " + + addon.getFile().getAbsolutePath() + + ", class: " + + addon.getAddonClass().getCanonicalName(); + throw new AddonLoadException(message); + } pool.put(addon.getId(), addon); } diff --git a/common/src/main/java/com/dfsek/terra/addon/PreLoadAddon.java b/common/src/main/java/com/dfsek/terra/addon/PreLoadAddon.java index 4f54ebf10..7b21ecb40 100644 --- a/common/src/main/java/com/dfsek/terra/addon/PreLoadAddon.java +++ b/common/src/main/java/com/dfsek/terra/addon/PreLoadAddon.java @@ -7,6 +7,7 @@ import com.dfsek.terra.api.addons.TerraAddon; import com.dfsek.terra.api.addons.annotations.Addon; import com.dfsek.terra.api.addons.annotations.Depends; +import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -16,10 +17,12 @@ public class PreLoadAddon { private final Class addonClass; private final String id; private final String[] dependencies; + private final File file; - public PreLoadAddon(Class addonClass) { + public PreLoadAddon(Class addonClass, File file) { this.addonClass = addonClass; this.id = addonClass.getAnnotation(Addon.class).value(); + this.file = file; Depends depends = addonClass.getAnnotation(Depends.class); this.dependencies = depends == null ? new String[] {} : depends.value(); } @@ -48,4 +51,8 @@ public class PreLoadAddon { public Class getAddonClass() { return addonClass; } + + public File getFile() { + return file; + } } diff --git a/common/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java b/common/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java index 9ee605061..f2c50acfb 100644 --- a/common/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/master/AddonRegistry.java @@ -58,7 +58,7 @@ public class AddonRegistry extends OpenRegistry { for(File jar : addonsFolder.listFiles(file -> file.getName().endsWith(".jar"))) { main.logger().info("Loading Addon(s) from: " + jar.getName()); for(Class addonClass : AddonClassLoader.fetchAddonClasses(jar)) { - pool.add(new PreLoadAddon(addonClass)); + pool.add(new PreLoadAddon(addonClass, jar)); } } From 9a6c34a2d5a9bf35697c0c25cb79caf59fcdb572 Mon Sep 17 00:00:00 2001 From: dfsek Date: Wed, 10 Mar 2021 16:33:55 -0700 Subject: [PATCH 86/95] fix fabric teleportation issues --- .../java/com/dfsek/terra/fabric/world/entity/FabricPlayer.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricPlayer.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricPlayer.java index 25f3a4caa..143ad024c 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricPlayer.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/entity/FabricPlayer.java @@ -5,9 +5,7 @@ import com.dfsek.terra.api.platform.entity.Player; import com.dfsek.terra.api.platform.world.World; import com.dfsek.terra.fabric.world.FabricAdapter; import com.dfsek.terra.fabric.world.handles.world.FabricWorldAccess; -import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.server.world.ServerWorld; import net.minecraft.text.LiteralText; public class FabricPlayer implements Player { @@ -40,6 +38,5 @@ public class FabricPlayer implements Player { @Override public void setLocation(Location location) { delegate.teleport(location.getX(), location.getY(), location.getZ()); - delegate.moveToWorld((ServerWorld) ((FabricWorldHandle) location).getWorld()); } } From 074ad44bca36adae8b264eae2b7ea97e594a407e Mon Sep 17 00:00:00 2001 From: dfsek Date: Thu, 11 Mar 2021 19:03:57 -0700 Subject: [PATCH 87/95] add Gabor noise --- .../samplers/noise/GaborNoiseSampler.java | 105 ++++++++ .../noise/samplers/noise/NoiseFunction.java | 46 ++++ .../noise/random/WhiteNoiseSampler.java | 47 ++-- .../noise/simplex/SimplexSampler.java | 243 ++++++++++++++++++ .../dfsek/terra/config/GenericLoaders.java | 7 +- .../noise/CellularNoiseTemplate.java | 2 +- .../templates/noise/GaborNoiseTemplate.java | 40 +++ .../templates/noise/SimpleNoiseTemplate.java | 2 +- .../terra/registry/config/NoiseRegistry.java | 4 + 9 files changed, 470 insertions(+), 26 deletions(-) create mode 100644 common/src/main/java/com/dfsek/terra/api/math/noise/samplers/noise/GaborNoiseSampler.java create mode 100644 common/src/main/java/com/dfsek/terra/api/math/noise/samplers/noise/simplex/SimplexSampler.java create mode 100644 common/src/main/java/com/dfsek/terra/config/loaders/config/sampler/templates/noise/GaborNoiseTemplate.java diff --git a/common/src/main/java/com/dfsek/terra/api/math/noise/samplers/noise/GaborNoiseSampler.java b/common/src/main/java/com/dfsek/terra/api/math/noise/samplers/noise/GaborNoiseSampler.java new file mode 100644 index 000000000..93f006dc4 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/math/noise/samplers/noise/GaborNoiseSampler.java @@ -0,0 +1,105 @@ +package com.dfsek.terra.api.math.noise.samplers.noise; + +import com.dfsek.terra.api.math.noise.samplers.noise.random.WhiteNoiseSampler; +import net.jafama.FastMath; + +public class GaborNoiseSampler extends NoiseFunction { + private final WhiteNoiseSampler rand; + private double k = 1.0; + private double a = 0.1; + private double f0 = 0.625; + private double kernelRadius = (FastMath.sqrt(-FastMath.log(0.05) / Math.PI) / a); + private double omega0 = Math.PI * 0.25; + private boolean isotropic = true; + private double impulsesPerKernel = 64d; + private double impulseDensity = (impulsesPerKernel / (Math.PI * kernelRadius * kernelRadius)); + + private double impulsesPerCell = impulseDensity * kernelRadius * kernelRadius; + private double g = FastMath.exp(-impulsesPerCell); + + + public GaborNoiseSampler(int seed) { + super(seed); + rand = new WhiteNoiseSampler(seed); + } + + public void setIsotropic(boolean isotropic) { + this.isotropic = isotropic; + } + + public void setImpulsesPerKernel(double impulsesPerKernel) { + this.impulsesPerKernel = impulsesPerKernel; + recalculateRadiusAndDensity(); + } + + public void setA(double a) { + this.a = a; + recalculateRadiusAndDensity(); + } + + public void setFrequency0(double f0) { + this.f0 = f0; + } + + public void setRotation(double omega0) { + this.omega0 = Math.PI * omega0; + } + + public void setDeviation(double k) { + this.k = k; + } + + private void recalculateRadiusAndDensity() { + kernelRadius = (FastMath.sqrt(-FastMath.log(0.05) / Math.PI) / this.a); + impulseDensity = (impulsesPerKernel / (Math.PI * kernelRadius * kernelRadius)); + impulsesPerCell = impulseDensity * kernelRadius * kernelRadius; + g = FastMath.exp(-impulsesPerCell); + } + + @Override + public double getNoiseRaw(int seed, double x, double z) { + return gaborNoise(seed, x, z); + } + + @Override + public double getNoiseRaw(int seed, double x, double y, double z) { + return gaborNoise(seed, x, z); + } + + private double gaborNoise(int seed, double x, double y) { + x /= kernelRadius; + y /= kernelRadius; + int xi = fastFloor(x); + int yi = fastFloor(y); + double xf = x - xi; + double yf = y - yi; + double noise = 0; + for(int dx = -1; dx <= 1; dx++) { + for(int dz = -1; dz <= 1; dz++) { + noise += calculateCell(seed, xi + dx, yi + dz, xf - dx, yf - dz); + } + } + return noise; + } + + private double calculateCell(int seed, int xi, int yi, double x, double y) { + long mashedSeed = murmur64(31L * xi + yi) + seed; + + double gaussianSource = (rand.getNoiseRaw(mashedSeed++) + 1) / 2; + int impulses = 0; + while(gaussianSource > g) { + impulses++; + gaussianSource *= (rand.getNoiseRaw(mashedSeed++) + 1) / 2; + } + + double noise = 0; + for(int i = 0; i < impulses; i++) { + noise += rand.getNoiseRaw(mashedSeed++) * gabor(isotropic ? (rand.getNoiseRaw(mashedSeed++) + 1) * Math.PI : omega0, x * kernelRadius, y * kernelRadius); + } + return noise; + } + + private double gabor(double omega_0, double x, double y) { + return k * (FastMath.exp(-Math.PI * (a * a) * (x * x + y * y)) * fastCos(2 * Math.PI * f0 * (x * fastCos(omega_0) + y * fastSin(omega_0)))); + } +} diff --git a/common/src/main/java/com/dfsek/terra/api/math/noise/samplers/noise/NoiseFunction.java b/common/src/main/java/com/dfsek/terra/api/math/noise/samplers/noise/NoiseFunction.java index 6c5829f44..1266c3762 100644 --- a/common/src/main/java/com/dfsek/terra/api/math/noise/samplers/noise/NoiseFunction.java +++ b/common/src/main/java/com/dfsek/terra/api/math/noise/samplers/noise/NoiseFunction.java @@ -22,6 +22,8 @@ public abstract class NoiseFunction implements NoiseSampler { return f >= 0 ? (int) f : (int) f - 1; } + static final int precision = 100; + protected static int hash(int seed, int xPrimed, int yPrimed, int zPrimed) { int hash = seed ^ xPrimed ^ yPrimed ^ zPrimed; @@ -36,6 +38,8 @@ public abstract class NoiseFunction implements NoiseSampler { return hash; } + static final int modulus = 360 * precision; + protected static int fastRound(double f) { return f >= 0 ? (int) (f + 0.5f) : (int) (f - 0.5); } @@ -73,6 +77,48 @@ public abstract class NoiseFunction implements NoiseSampler { return FastMath.sqrt(f); } + static final double[] sin = new double[360 * 100]; // lookup table + + static { + for(int i = 0; i < sin.length; i++) { + sin[i] = (float) Math.sin((double) (i) / (precision)); + } + } + + protected static int fastCeil(double f) { + int i = (int) f; + if(i < f) i++; + return i; + } + + /** + * Murmur64 hashing function + * + * @param h Input value + * @return Hashed value + */ + protected static long murmur64(long h) { + h ^= h >>> 33; + h *= 0xff51afd7ed558ccdL; + h ^= h >>> 33; + h *= 0xc4ceb9fe1a85ec53L; + h ^= h >>> 33; + return h; + } + + private static double sinLookup(int a) { + return a >= 0 ? sin[a % (modulus)] : -sin[-a % (modulus)]; + } + + protected static double fastSin(double a) { + return sinLookup((int) (a * precision + 0.5f)); + } + + protected static double fastCos(double a) { + return sinLookup((int) ((a + Math.PI / 2) * precision + 0.5f)); + } + + public void setSeed(int seed) { this.seed = seed; } diff --git a/common/src/main/java/com/dfsek/terra/api/math/noise/samplers/noise/random/WhiteNoiseSampler.java b/common/src/main/java/com/dfsek/terra/api/math/noise/samplers/noise/random/WhiteNoiseSampler.java index 80660949f..962ca2486 100644 --- a/common/src/main/java/com/dfsek/terra/api/math/noise/samplers/noise/random/WhiteNoiseSampler.java +++ b/common/src/main/java/com/dfsek/terra/api/math/noise/samplers/noise/random/WhiteNoiseSampler.java @@ -12,38 +12,41 @@ public class WhiteNoiseSampler extends NoiseFunction { super(seed); } + public double getNoiseRaw(long seed) { + return (Double.longBitsToDouble((murmur64(seed) & 0x000fffffffffffffL) | POSITIVE_POW1) - 1.5) * 2; + } + @Override public double getNoiseRaw(int seed, double x, double y) { - long hashX = Double.doubleToRawLongBits(x) ^ seed; - long hashZ = Double.doubleToRawLongBits(y) ^ seed; - long hash = ((hashX ^ (hashX >>> 32)) + ((hashZ ^ (hashZ >>> 32)) << 32)) ^ seed; - long base = (murmur64(hash) & 0x000fffffffffffffL) - | POSITIVE_POW1; // Sign and exponent - return (Double.longBitsToDouble(base) - 1.5) * 2; + return (getNoiseUnmapped(seed, x, y) - 1.5) * 2; } @Override public double getNoiseRaw(int seed, double x, double y, double z) { + return (getNoiseUnmapped(seed, x, y, z) - 1.5) * 2; + } + + public double getNoiseUnmapped(int seed, double x, double y, double z) { + long base = ((randomBits(seed, x, y, z)) & 0x000fffffffffffffL) | POSITIVE_POW1; // Sign and exponent + return Double.longBitsToDouble(base); + } + + public double getNoiseUnmapped(int seed, double x, double y) { + long base = (randomBits(seed, x, y) & 0x000fffffffffffffL) | POSITIVE_POW1; // Sign and exponent + return Double.longBitsToDouble(base); + } + + public long randomBits(int seed, double x, double y, double z) { long hashX = Double.doubleToRawLongBits(x) ^ seed; long hashZ = Double.doubleToRawLongBits(y) ^ seed; long hash = (((hashX ^ (hashX >>> 32)) + ((hashZ ^ (hashZ >>> 32)) << 32)) ^ seed) + Double.doubleToRawLongBits(z); - long base = ((murmur64(hash)) & 0x000fffffffffffffL) - | POSITIVE_POW1; // Sign and exponent - return (Double.longBitsToDouble(base) - 1.5) * 2; + return murmur64(hash); } - /** - * Murmur64 hashing function - * - * @param h Input value - * @return Hashed value - */ - private static long murmur64(long h) { - h ^= h >>> 33; - h *= 0xff51afd7ed558ccdL; - h ^= h >>> 33; - h *= 0xc4ceb9fe1a85ec53L; - h ^= h >>> 33; - return h; + public long randomBits(int seed, double x, double y) { + long hashX = Double.doubleToRawLongBits(x) ^ seed; + long hashZ = Double.doubleToRawLongBits(y) ^ seed; + long hash = ((hashX ^ (hashX >>> 32)) + ((hashZ ^ (hashZ >>> 32)) << 32)) ^ seed; + return murmur64(hash); } } diff --git a/common/src/main/java/com/dfsek/terra/api/math/noise/samplers/noise/simplex/SimplexSampler.java b/common/src/main/java/com/dfsek/terra/api/math/noise/samplers/noise/simplex/SimplexSampler.java new file mode 100644 index 000000000..b12a75d21 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/api/math/noise/samplers/noise/simplex/SimplexSampler.java @@ -0,0 +1,243 @@ +package com.dfsek.terra.api.math.noise.samplers.noise.simplex; + +public class SimplexSampler extends SimplexStyleSampler { + private static final Double2[] GRAD_2D = { + new Double2(-1, -1), new Double2(1, -1), new Double2(-1, 1), new Double2(1, 1), + new Double2(0, -1), new Double2(-1, 0), new Double2(0, 1), new Double2(1, 0), + }; + private static final Double3[] GRAD_3D = { + new Double3(1, 1, 0), new Double3(-1, 1, 0), new Double3(1, -1, 0), new Double3(-1, -1, 0), + new Double3(1, 0, 1), new Double3(-1, 0, 1), new Double3(1, 0, -1), new Double3(-1, 0, -1), + new Double3(0, 1, 1), new Double3(0, -1, 1), new Double3(0, 1, -1), new Double3(0, -1, -1), + new Double3(1, 1, 0), new Double3(0, -1, 1), new Double3(-1, 1, 0), new Double3(0, -1, -1), + }; + + private static final double F2 = 1.0 / 2.0; + private static final double F3 = (1.0 / 3.0); + private static final double G2 = 1.0 / 4.0; + private static final double G3 = (1.0 / 6.0); + private static final double G33 = G3 * 3 - 1; + + private static final int X_PRIME = 1619; + private static final int Y_PRIME = 31337; + private static final int Z_PRIME = 6971; + + + public SimplexSampler(int seed) { + super(seed); + } + + private static double gradCoord3D(int seed, int x, int y, int z, double xd, double yd, double zd) { + int hash = seed; + hash ^= X_PRIME * x; + hash ^= Y_PRIME * y; + hash ^= Z_PRIME * z; + + hash = hash * hash * hash * 60493; + hash = (hash >> 13) ^ hash; + + Double3 g = GRAD_3D[hash & 15]; + + return xd * g.x + yd * g.y + zd * g.z; + } + + private static double gradCoord2D(int seed, int x, int y, double xd, double yd) { + int hash = seed; + hash ^= X_PRIME * x; + hash ^= Y_PRIME * y; + + hash = hash * hash * hash * 60493; + hash = (hash >> 13) ^ hash; + + Double2 g = GRAD_2D[hash & 7]; + + return xd * g.x + yd * g.y; + } + + @Override + public double getNoiseRaw(int seed, double x, double y) { + double t = (x + y) * F2; + int i = fastFloor(x + t); + int j = fastFloor(y + t); + + t = (i + j) * G2; + double X0 = i - t; + double Y0 = j - t; + + double x0 = x - X0; + double y0 = y - Y0; + + int i1, j1; + if(x0 > y0) { + i1 = 1; + j1 = 0; + } else { + i1 = 0; + j1 = 1; + } + + double x1 = x0 - i1 + G2; + double y1 = y0 - j1 + G2; + double x2 = x0 - 1 + F2; + double y2 = y0 - 1 + F2; + + double n0, n1, n2; + + t = 0.5 - x0 * x0 - y0 * y0; + if(t < 0) { + n0 = 0; + } else { + t *= t; + n0 = t * t * gradCoord2D(seed, i, j, x0, y0); + } + + t = 0.5 - x1 * x1 - y1 * y1; + if(t < 0) { + n1 = 0; + } else { + t *= t; + n1 = t * t * gradCoord2D(seed, i + i1, j + j1, x1, y1); + } + + t = 0.5 - x2 * x2 - y2 * y2; + if(t < 0) { + n2 = 0; + } else { + t *= t; + n2 = t * t * gradCoord2D(seed, i + 1, j + 1, x2, y2); + } + + return 50 * (n0 + n1 + n2); + } + + @Override + public double getNoiseRaw(int seed, double x, double y, double z) { + double t = (x + y + z) * F3; + int i = fastFloor(x + t); + int j = fastFloor(y + t); + int k = fastFloor(z + t); + + t = (i + j + k) * G3; + double x0 = x - (i - t); + double y0 = y - (j - t); + double z0 = z - (k - t); + + int i1, j1, k1; + int i2, j2, k2; + + if(x0 >= y0) { + if(y0 >= z0) { + i1 = 1; + j1 = 0; + k1 = 0; + i2 = 1; + j2 = 1; + k2 = 0; + } else if(x0 >= z0) { + i1 = 1; + j1 = 0; + k1 = 0; + i2 = 1; + j2 = 0; + k2 = 1; + } else // x0 < z0 + { + i1 = 0; + j1 = 0; + k1 = 1; + i2 = 1; + j2 = 0; + k2 = 1; + } + } else // x0 < y0 + { + if(y0 < z0) { + i1 = 0; + j1 = 0; + k1 = 1; + i2 = 0; + j2 = 1; + k2 = 1; + } else if(x0 < z0) { + i1 = 0; + j1 = 1; + k1 = 0; + i2 = 0; + j2 = 1; + k2 = 1; + } else // x0 >= z0 + { + i1 = 0; + j1 = 1; + k1 = 0; + i2 = 1; + j2 = 1; + k2 = 0; + } + } + + double x1 = x0 - i1 + G3; + double y1 = y0 - j1 + G3; + double z1 = z0 - k1 + G3; + double x2 = x0 - i2 + F3; + double y2 = y0 - j2 + F3; + double z2 = z0 - k2 + F3; + double x3 = x0 + G33; + double y3 = y0 + G33; + double z3 = z0 + G33; + + double n0, n1, n2, n3; + + t = 0.6 - x0 * x0 - y0 * y0 - z0 * z0; + if(t < 0) n0 = 0; + else { + t *= t; + n0 = t * t * gradCoord3D(seed, i, j, k, x0, y0, z0); + } + + t = 0.6 - x1 * x1 - y1 * y1 - z1 * z1; + if(t < 0) { + n1 = 0; + } else { + t *= t; + n1 = t * t * gradCoord3D(seed, i + i1, j + j1, k + k1, x1, y1, z1); + } + + t = 0.6 - x2 * x2 - y2 * y2 - z2 * z2; + if(t < 0) { + n2 = 0; + } else { + t *= t; + n2 = t * t * gradCoord3D(seed, i + i2, j + j2, k + k2, x2, y2, z2); + } + + t = 0.6 - x3 * x3 - y3 * y3 - z3 * z3; + if(t < 0) { + n3 = 0; + } else { + t *= t; + n3 = t * t * gradCoord3D(seed, i + 1, j + 1, k + 1, x3, y3, z3); + } + + return 32 * (n0 + n1 + n2 + n3); + } + + private static class Double2 { + public final double x, y; + + public Double2(double x, double y) { + this.x = x; + this.y = y; + } + } + + private static class Double3 { + public final double x, y, z; + + public Double3(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + } + } +} diff --git a/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java b/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java index 6eafad8d9..0726b8d97 100644 --- a/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java +++ b/common/src/main/java/com/dfsek/terra/config/GenericLoaders.java @@ -95,8 +95,6 @@ public class GenericLoaders implements LoaderRegistrar { .registerLoader(CarverPalette.class, new CarverPaletteLoader()) .registerLoader(SourceSeeded.class, new SourceBuilderLoader()) .registerLoader(StageSeeded.class, new StageBuilderLoader()) - .registerLoader(TerraAddon.class, main.getAddons()) - .registerLoader(BlockType.class, (t, object, cf) -> main.getWorldHandle().createBlockData((String) object).getBlockType()) .registerLoader(BiomeProvider.BiomeProviderBuilder.class, new BiomeProviderBuilderLoader()) .registerLoader(ImageSampler.Channel.class, (t, object, cf) -> ImageSampler.Channel.valueOf((String) object)) .registerLoader(BiomeProvider.Type.class, (t, object, cf) -> BiomeProvider.Type.valueOf((String) object)) @@ -107,5 +105,10 @@ public class GenericLoaders implements LoaderRegistrar { .registerLoader(CellularSampler.ReturnType.class, (t, object, cf) -> CellularSampler.ReturnType.valueOf((String) object)) .registerLoader(CellularSampler.DistanceFunction.class, (t, object, cf) -> CellularSampler.DistanceFunction.valueOf((String) object)) .registerLoader(TerraFlora.Search.class, (t, o, l) -> TerraFlora.Search.valueOf(o.toString())); + + if(main != null) { + registry.registerLoader(TerraAddon.class, main.getAddons()) + .registerLoader(BlockType.class, (t, object, cf) -> main.getWorldHandle().createBlockData((String) object).getBlockType()); + } } } diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/sampler/templates/noise/CellularNoiseTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/sampler/templates/noise/CellularNoiseTemplate.java index 3852742b9..90a53d277 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/sampler/templates/noise/CellularNoiseTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/sampler/templates/noise/CellularNoiseTemplate.java @@ -39,7 +39,7 @@ public class CellularNoiseTemplate extends NoiseTemplate { @Override public NoiseSampler apply(Long seed) { - CellularSampler sampler = new CellularSampler((int) (long) seed); + CellularSampler sampler = new CellularSampler((int) (long) seed + salt); sampler.setNoiseLookup(lookup.apply(seed)); sampler.setFrequency(frequency); sampler.setJitterModifier(cellularJitter); diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/sampler/templates/noise/GaborNoiseTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/sampler/templates/noise/GaborNoiseTemplate.java new file mode 100644 index 000000000..b15aa75cd --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/sampler/templates/noise/GaborNoiseTemplate.java @@ -0,0 +1,40 @@ +package com.dfsek.terra.config.loaders.config.sampler.templates.noise; + +import com.dfsek.tectonic.annotations.Default; +import com.dfsek.tectonic.annotations.Value; +import com.dfsek.terra.api.math.noise.NoiseSampler; +import com.dfsek.terra.api.math.noise.samplers.noise.GaborNoiseSampler; + +public class GaborNoiseTemplate extends NoiseTemplate { + @Value("rotation") + @Default + private double rotation = 0.25; + + @Value("isotropic") + @Default + private boolean isotropic = true; + + @Value("deviation") + @Default + private double deviation = 1.0; + + @Value("impulses") + @Default + private double impulses = 64d; + + @Value("frequency_0") + @Default + private double f0 = 0.625; + + @Override + public NoiseSampler apply(Long seed) { + GaborNoiseSampler gaborNoiseSampler = new GaborNoiseSampler((int) (long) seed + salt); + gaborNoiseSampler.setFrequency(frequency); + gaborNoiseSampler.setRotation(rotation); + gaborNoiseSampler.setIsotropic(isotropic); + gaborNoiseSampler.setDeviation(deviation); + gaborNoiseSampler.setImpulsesPerKernel(impulses); + gaborNoiseSampler.setFrequency0(f0); + return gaborNoiseSampler; + } +} diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/sampler/templates/noise/SimpleNoiseTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/sampler/templates/noise/SimpleNoiseTemplate.java index 731096c0f..9c1ab1cb2 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/sampler/templates/noise/SimpleNoiseTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/sampler/templates/noise/SimpleNoiseTemplate.java @@ -14,7 +14,7 @@ public class SimpleNoiseTemplate extends NoiseTemplate { @Override public NoiseSampler apply(Long seed) { - NoiseFunction sampler = samplerSupplier.apply((int) (long) seed); + NoiseFunction sampler = samplerSupplier.apply((int) (long) seed + salt); sampler.setFrequency(frequency); return sampler; } diff --git a/common/src/main/java/com/dfsek/terra/registry/config/NoiseRegistry.java b/common/src/main/java/com/dfsek/terra/registry/config/NoiseRegistry.java index d84227455..ccbfee9ca 100644 --- a/common/src/main/java/com/dfsek/terra/registry/config/NoiseRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/config/NoiseRegistry.java @@ -6,6 +6,7 @@ import com.dfsek.terra.api.math.noise.samplers.noise.random.WhiteNoiseSampler; import com.dfsek.terra.api.math.noise.samplers.noise.simplex.OpenSimplex2SSampler; import com.dfsek.terra.api.math.noise.samplers.noise.simplex.OpenSimplex2Sampler; import com.dfsek.terra.api.math.noise.samplers.noise.simplex.PerlinSampler; +import com.dfsek.terra.api.math.noise.samplers.noise.simplex.SimplexSampler; import com.dfsek.terra.api.math.noise.samplers.noise.value.ValueCubicSampler; import com.dfsek.terra.api.math.noise.samplers.noise.value.ValueSampler; import com.dfsek.terra.api.util.seeded.NoiseSeeded; @@ -15,6 +16,7 @@ import com.dfsek.terra.config.loaders.config.sampler.templates.KernelTemplate; import com.dfsek.terra.config.loaders.config.sampler.templates.noise.CellularNoiseTemplate; import com.dfsek.terra.config.loaders.config.sampler.templates.noise.ConstantNoiseTemplate; import com.dfsek.terra.config.loaders.config.sampler.templates.noise.ExpressionFunctionTemplate; +import com.dfsek.terra.config.loaders.config.sampler.templates.noise.GaborNoiseTemplate; import com.dfsek.terra.config.loaders.config.sampler.templates.noise.SimpleNoiseTemplate; import com.dfsek.terra.config.loaders.config.sampler.templates.noise.fractal.BrownianMotionTemplate; import com.dfsek.terra.config.loaders.config.sampler.templates.noise.fractal.PingPongTemplate; @@ -44,6 +46,8 @@ public class NoiseRegistry extends OpenRegistry new SimpleNoiseTemplate(OpenSimplex2Sampler::new)); add("OPENSIMPLEX2S", () -> new SimpleNoiseTemplate(OpenSimplex2SSampler::new)); add("PERLIN", () -> new SimpleNoiseTemplate(PerlinSampler::new)); + add("SIMPLEX", () -> new SimpleNoiseTemplate(SimplexSampler::new)); + add("GABOR", GaborNoiseTemplate::new); add("VALUE", () -> new SimpleNoiseTemplate(ValueSampler::new)); From ff8181bbfae55f201497125c43a279f5b0b81216 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sat, 13 Mar 2021 14:48:02 -0700 Subject: [PATCH 88/95] fix function loading issues --- .../com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java b/common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java index 34f356ece..9b16f19b6 100644 --- a/common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java +++ b/common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java @@ -42,7 +42,7 @@ public class UserDefinedBiomeBuilder implements BiomeBuilder { template.getVariables().forEach(varScope::create); Map noiseBuilderMap = pack.getTemplate().getNoiseBuilderMap(); - Map functionTemplateMap = new HashMap<>(template.getFunctions()); + Map functionTemplateMap = new HashMap<>(pack.getTemplate().getFunctions()); functionTemplateMap.putAll(template.getFunctions()); From b3868bd75072c4ddabaf97e812e7fddc6b701c5f Mon Sep 17 00:00:00 2001 From: dfsek Date: Sat, 13 Mar 2021 15:18:25 -0700 Subject: [PATCH 89/95] allow paralithic expressions to be defined in expression samplers --- .../noise/ExpressionFunctionTemplate.java | 45 ++++++++++++------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/sampler/templates/noise/ExpressionFunctionTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/sampler/templates/noise/ExpressionFunctionTemplate.java index 256106a99..ad85eda25 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/sampler/templates/noise/ExpressionFunctionTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/sampler/templates/noise/ExpressionFunctionTemplate.java @@ -1,5 +1,7 @@ package com.dfsek.terra.config.loaders.config.sampler.templates.noise; +import com.dfsek.paralithic.eval.parser.Parser; +import com.dfsek.paralithic.eval.parser.Scope; import com.dfsek.paralithic.eval.tokenizer.ParseException; import com.dfsek.paralithic.functions.Function; import com.dfsek.tectonic.annotations.Default; @@ -9,12 +11,13 @@ import com.dfsek.tectonic.exception.ValidationException; import com.dfsek.terra.api.math.noise.NoiseSampler; import com.dfsek.terra.api.math.noise.samplers.noise.ExpressionFunction; import com.dfsek.terra.api.math.paralithic.BlankFunction; -import com.dfsek.terra.api.math.paralithic.noise.NoiseFunction2; -import com.dfsek.terra.api.math.paralithic.noise.NoiseFunction3; +import com.dfsek.terra.api.math.paralithic.defined.UserDefinedFunction; import com.dfsek.terra.api.util.seeded.NoiseSeeded; +import com.dfsek.terra.config.loaders.config.function.FunctionTemplate; import com.dfsek.terra.config.loaders.config.sampler.templates.SamplerTemplate; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; @@ -31,17 +34,14 @@ public class ExpressionFunctionTemplate extends SamplerTemplate functions = new HashMap<>(); + @Value("expressions") + @Default + private LinkedHashMap expressions = new LinkedHashMap<>(); + @Override public NoiseSampler apply(Long seed) { try { - Map noiseFunctionMap = new HashMap<>(); - - functions.forEach((id, function) -> { - if(function.getDimensions() == 2) { - noiseFunctionMap.put(id, new NoiseFunction2(function.apply(seed))); - } else noiseFunctionMap.put(id, new NoiseFunction3(function.apply(seed))); - }); - + Map noiseFunctionMap = generateFunctions(); return new ExpressionFunction(noiseFunctionMap, equation, vars); } catch(ParseException e) { throw new IllegalStateException(e); @@ -51,17 +51,28 @@ public class ExpressionFunctionTemplate extends SamplerTemplate noiseFunctionMap = new HashMap<>(); - - functions.forEach((id, function) -> { - if(function.getDimensions() == 2) { - noiseFunctionMap.put(id, new BlankFunction(2)); - } else noiseFunctionMap.put(id, new BlankFunction(3)); - }); + Map noiseFunctionMap = generateFunctions(); new ExpressionFunction(noiseFunctionMap, equation, vars); } catch(ParseException e) { throw new ValidationException("Errors occurred while parsing noise equation: ", e); } return super.validate(); } + + private Map generateFunctions() throws ParseException { + Map noiseFunctionMap = new HashMap<>(); + + for(Map.Entry entry : expressions.entrySet()) { + System.out.println(entry); + noiseFunctionMap.put(entry.getKey(), UserDefinedFunction.newInstance(entry.getValue(), new Parser(), new Scope())); + } + + functions.forEach((id, function) -> { + if(function.getDimensions() == 2) { + noiseFunctionMap.put(id, new BlankFunction(2)); + } else noiseFunctionMap.put(id, new BlankFunction(3)); + }); + + return noiseFunctionMap; + } } From 6ab8cd5b5be100583c7d639294a3dbc39721d832 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 14 Mar 2021 16:30:27 -0700 Subject: [PATCH 90/95] fix mushrooms on fabric --- .../java/com/dfsek/terra/api/platform/block/Block.java | 8 ++++++-- .../java/com/dfsek/terra/fabric/world/FabricTree.java | 3 ++- .../com/dfsek/terra/fabric/world/block/FabricBlock.java | 5 ----- .../world/generator/FabricChunkGeneratorWrapper.java | 5 +++++ 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/com/dfsek/terra/api/platform/block/Block.java b/common/src/main/java/com/dfsek/terra/api/platform/block/Block.java index becb5d436..b6132ef0a 100644 --- a/common/src/main/java/com/dfsek/terra/api/platform/block/Block.java +++ b/common/src/main/java/com/dfsek/terra/api/platform/block/Block.java @@ -11,7 +11,9 @@ public interface Block extends Handle { BlockState getState(); - Block getRelative(BlockFace face); + default Block getRelative(BlockFace face) { + return getRelative(face, 1); + } Block getRelative(BlockFace face, int len); @@ -19,7 +21,9 @@ public interface Block extends Handle { Location getLocation(); - BlockType getType(); + default BlockType getType() { + return getBlockData().getBlockType(); + } int getX(); diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricTree.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricTree.java index f7480a57d..1055c0964 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricTree.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/FabricTree.java @@ -30,6 +30,7 @@ public class FabricTree implements Tree { @Override public MaterialSet getSpawnable() { return MaterialSet.get(TerraFabricPlugin.getInstance().getWorldHandle().createBlockData("minecraft:grass_block"), - TerraFabricPlugin.getInstance().getWorldHandle().createBlockData("minecraft:podzol")); + TerraFabricPlugin.getInstance().getWorldHandle().createBlockData("minecraft:podzol"), + TerraFabricPlugin.getInstance().getWorldHandle().createBlockData("minecraft:mycelium")); } } diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlock.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlock.java index a4d2d0017..9379380ca 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlock.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/block/FabricBlock.java @@ -34,11 +34,6 @@ public class FabricBlock implements Block { return FabricBlockState.newInstance(this); } - @Override - public Block getRelative(BlockFace face) { - return getRelative(face, 1); - } - @Override public Block getRelative(BlockFace face, int len) { BlockPos newPos = delegate.position.add(face.getModX() * len, face.getModY() * len, face.getModZ() * len); diff --git a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java index b1d769cef..cb7ebe8b8 100644 --- a/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java +++ b/platforms/fabric/src/main/java/com/dfsek/terra/fabric/world/generator/FabricChunkGeneratorWrapper.java @@ -103,6 +103,11 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener } + @Override + public void generateFeatures(ChunkRegion region, StructureAccessor accessor) { + super.generateFeatures(region, accessor); + } + @Override public void populateNoise(WorldAccess world, StructureAccessor accessor, Chunk chunk) { FabricSeededWorldAccess worldAccess = new FabricSeededWorldAccess(world, seed, this); From ec4e0694a43fe6bfc579bc6369e9e01927072aa5 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 14 Mar 2021 16:45:32 -0700 Subject: [PATCH 91/95] add structure locate command --- .../terra/api/registry/CheckedRegistry.java | 5 ++ .../terra/api/registry/LockedRegistry.java | 6 +- .../dfsek/terra/api/registry/Registry.java | 7 ++ .../commands/structure/StructureCommand.java | 5 ++ .../structure/StructureLocateCommand.java | 75 +++++++++++++++++++ .../argument/StructureArgumentParser.java | 18 +++++ .../completer/StructureCompleter.java | 21 ++++++ .../dfsek/terra/registry/OpenRegistry.java | 5 ++ 8 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 common/src/main/java/com/dfsek/terra/commands/structure/StructureLocateCommand.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/structure/argument/StructureArgumentParser.java create mode 100644 common/src/main/java/com/dfsek/terra/commands/structure/completer/StructureCompleter.java diff --git a/common/src/main/java/com/dfsek/terra/api/registry/CheckedRegistry.java b/common/src/main/java/com/dfsek/terra/api/registry/CheckedRegistry.java index d7900cee7..9934c767b 100644 --- a/common/src/main/java/com/dfsek/terra/api/registry/CheckedRegistry.java +++ b/common/src/main/java/com/dfsek/terra/api/registry/CheckedRegistry.java @@ -72,6 +72,11 @@ public class CheckedRegistry implements Registry { return registry.entries(); } + @Override + public Set keys() { + return registry.keys(); + } + @Override public T load(Type t, Object c, ConfigLoader loader) throws LoadException { return registry.load(t, c, loader); diff --git a/common/src/main/java/com/dfsek/terra/api/registry/LockedRegistry.java b/common/src/main/java/com/dfsek/terra/api/registry/LockedRegistry.java index 6c9525e98..227656c4d 100644 --- a/common/src/main/java/com/dfsek/terra/api/registry/LockedRegistry.java +++ b/common/src/main/java/com/dfsek/terra/api/registry/LockedRegistry.java @@ -2,7 +2,6 @@ package com.dfsek.terra.api.registry; import com.dfsek.tectonic.exception.LoadException; import com.dfsek.tectonic.loading.ConfigLoader; -import com.dfsek.terra.registry.OpenRegistry; import java.lang.reflect.Type; import java.util.Set; @@ -46,6 +45,11 @@ public class LockedRegistry implements Registry { return registry.entries(); } + @Override + public Set keys() { + return registry.keys(); + } + @Override public T load(Type t, Object c, ConfigLoader loader) throws LoadException { return registry.load(t, c, loader); diff --git a/common/src/main/java/com/dfsek/terra/api/registry/Registry.java b/common/src/main/java/com/dfsek/terra/api/registry/Registry.java index 41f10379b..773d784ca 100644 --- a/common/src/main/java/com/dfsek/terra/api/registry/Registry.java +++ b/common/src/main/java/com/dfsek/terra/api/registry/Registry.java @@ -43,4 +43,11 @@ public interface Registry extends TypeLoader { * @return Set containing all entries. */ Set entries(); + + /** + * Get all the keys in this registry. + * + * @return Keys in registry + */ + Set keys(); } diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/StructureCommand.java b/common/src/main/java/com/dfsek/terra/commands/structure/StructureCommand.java index c12f021d2..ad095ac70 100644 --- a/common/src/main/java/com/dfsek/terra/commands/structure/StructureCommand.java +++ b/common/src/main/java/com/dfsek/terra/commands/structure/StructureCommand.java @@ -22,6 +22,11 @@ import com.dfsek.terra.config.lang.LangUtil; clazz = SpawnCommand.class, value = "spawn", aliases = "s" + ), + @Subcommand( + clazz = StructureLocateCommand.class, + value = "locate", + aliases = "l" ) }, usage = "/te structure" diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/StructureLocateCommand.java b/common/src/main/java/com/dfsek/terra/commands/structure/StructureLocateCommand.java new file mode 100644 index 000000000..0e04c3ec4 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/structure/StructureLocateCommand.java @@ -0,0 +1,75 @@ +package com.dfsek.terra.commands.structure; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.CommandTemplate; +import com.dfsek.terra.api.command.annotation.Argument; +import com.dfsek.terra.api.command.annotation.Command; +import com.dfsek.terra.api.command.annotation.Switch; +import com.dfsek.terra.api.command.annotation.inject.ArgumentTarget; +import com.dfsek.terra.api.command.annotation.inject.SwitchTarget; +import com.dfsek.terra.api.command.annotation.type.PlayerCommand; +import com.dfsek.terra.api.command.annotation.type.WorldCommand; +import com.dfsek.terra.api.command.arg.IntegerArgumentParser; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.math.vector.Location; +import com.dfsek.terra.api.math.vector.Vector3; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.api.world.locate.AsyncStructureFinder; +import com.dfsek.terra.commands.structure.argument.StructureArgumentParser; +import com.dfsek.terra.commands.structure.completer.StructureCompleter; +import com.dfsek.terra.config.lang.LangUtil; +import com.dfsek.terra.world.population.items.TerraStructure; + +import java.util.Locale; + +@PlayerCommand +@WorldCommand +@Command( + arguments = { + @Argument( + value = "structure", + tabCompleter = StructureCompleter.class, + argumentParser = StructureArgumentParser.class + ), + @Argument( + value = "radius", + required = false, + defaultValue = "100", + argumentParser = IntegerArgumentParser.class + ) + }, + switches = { + @Switch( + value = "teleport", + aliases = {"t", "tp"} + ) + } +) +public class StructureLocateCommand implements CommandTemplate { + @Inject + private TerraPlugin main; + + @ArgumentTarget("structure") + private TerraStructure structure; + + @ArgumentTarget("radius") + private Integer radius; + + @SwitchTarget("teleport") + private boolean teleport; + + @Override + public void execute(CommandSender sender) { + Player player = (Player) sender; + + new Thread(new AsyncStructureFinder(main.getWorld(player.getWorld()).getBiomeProvider(), structure, player.getLocation().clone().multiply((1D / main.getTerraConfig().getBiomeSearchResolution())), 0, radius, location -> { + if(location != null) { + sender.sendMessage(String.format("The nearest %s is at [%d, ~, %d] (%.1f blocks away)", structure.getTemplate().getID().toLowerCase(Locale.ROOT), location.getBlockX(), location.getBlockZ(), location.add(new Vector3(0, player.getLocation().getY(), 0)).distance(player.getLocation().toVector()))); + if(teleport) { + main.runPossiblyUnsafeTask(() -> player.setLocation(new Location(player.getWorld(), location.getX(), player.getLocation().getY(), location.getZ()))); + } + } else LangUtil.send("command.biome.unable-to-locate", sender); + }, main), "Biome Location Thread").start(); + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/argument/StructureArgumentParser.java b/common/src/main/java/com/dfsek/terra/commands/structure/argument/StructureArgumentParser.java new file mode 100644 index 000000000..dce50ac65 --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/structure/argument/StructureArgumentParser.java @@ -0,0 +1,18 @@ +package com.dfsek.terra.commands.structure.argument; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.arg.ArgumentParser; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.platform.entity.Player; +import com.dfsek.terra.world.population.items.TerraStructure; + +public class StructureArgumentParser implements ArgumentParser { + @Inject + private TerraPlugin main; + + @Override + public TerraStructure parse(CommandSender sender, String arg) { + return main.getWorld(((Player) sender).getWorld()).getConfig().getStructureRegistry().get(arg); + } +} diff --git a/common/src/main/java/com/dfsek/terra/commands/structure/completer/StructureCompleter.java b/common/src/main/java/com/dfsek/terra/commands/structure/completer/StructureCompleter.java new file mode 100644 index 000000000..a2b5b1dad --- /dev/null +++ b/common/src/main/java/com/dfsek/terra/commands/structure/completer/StructureCompleter.java @@ -0,0 +1,21 @@ +package com.dfsek.terra.commands.structure.completer; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.tab.TabCompleter; +import com.dfsek.terra.api.injection.annotations.Inject; +import com.dfsek.terra.api.platform.CommandSender; +import com.dfsek.terra.api.platform.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public class StructureCompleter implements TabCompleter { + @Inject + private TerraPlugin main; + + @Override + public List complete(CommandSender sender) { + Player player = (Player) sender; + return new ArrayList<>(main.getWorld(player.getWorld()).getConfig().getStructureRegistry().keys()); + } +} diff --git a/common/src/main/java/com/dfsek/terra/registry/OpenRegistry.java b/common/src/main/java/com/dfsek/terra/registry/OpenRegistry.java index 5838a158c..1cd0b81f2 100644 --- a/common/src/main/java/com/dfsek/terra/registry/OpenRegistry.java +++ b/common/src/main/java/com/dfsek/terra/registry/OpenRegistry.java @@ -78,6 +78,11 @@ public class OpenRegistry implements Registry { return new HashSet<>(objects.values()); } + @Override + public Set keys() { + return objects.keySet(); + } + /** * Clears all entries from the registry. */ From 5ad349e35036538742457a6587816998362bfb5b Mon Sep 17 00:00:00 2001 From: dfsek Date: Sun, 14 Mar 2021 23:54:10 -0700 Subject: [PATCH 92/95] document event API --- .../dfsek/terra/api/addons/TerraAddon.java | 21 +++++++++++- .../dfsek/terra/api/event/EventListener.java | 8 +++++ .../dfsek/terra/api/event/EventManager.java | 10 ++++++ .../terra/api/event/annotations/Global.java | 5 ++- .../terra/api/event/events/Cancellable.java | 15 +++++++-- .../dfsek/terra/api/event/events/Event.java | 3 ++ .../terra/api/event/events/PackEvent.java | 12 +++++++ .../events/config/ConfigPackLoadEvent.java | 3 ++ .../dfsek/terra/api/injection/Injector.java | 33 +++++++++++++++++++ .../exception/InjectionException.java | 5 +++ 10 files changed, 111 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/com/dfsek/terra/api/addons/TerraAddon.java b/common/src/main/java/com/dfsek/terra/api/addons/TerraAddon.java index 6fd5e6f82..c202f9e39 100644 --- a/common/src/main/java/com/dfsek/terra/api/addons/TerraAddon.java +++ b/common/src/main/java/com/dfsek/terra/api/addons/TerraAddon.java @@ -6,20 +6,39 @@ import com.dfsek.terra.api.addons.annotations.Author; import com.dfsek.terra.api.addons.annotations.Version; import org.jetbrains.annotations.NotNull; +/** + * Represents an entry point for an addon. Implementations must be annotated with {@link Addon}. + */ public abstract class TerraAddon { + /** + * Gets the version of this addon. + * + * @return Addon version. + */ public final @NotNull String getVersion() { Version version = getClass().getAnnotation(Version.class); return version == null ? "0.1.0" : version.value(); } + /** + * Gets the author of this addon. + * + * @return Addon author. + */ public final @NotNull String getAuthor() { Author author = getClass().getAnnotation(Author.class); return author == null ? "Anon Y. Mous" : author.value(); } + /** + * Gets the name (ID) of this addon. + * + * @return Addon ID. + */ public final @NotNull String getName() { Addon addon = getClass().getAnnotation(Addon.class); - if(addon == null) throw new IllegalStateException("Addon annotation not present"); // This should never happen; the presence of this annotation is checked by the addon loader. + if(addon == null) + throw new IllegalStateException("Addon annotation not present"); // This should never happen; the presence of this annotation is checked by the addon loader. return addon.value(); } diff --git a/common/src/main/java/com/dfsek/terra/api/event/EventListener.java b/common/src/main/java/com/dfsek/terra/api/event/EventListener.java index f5d3dcf60..cde546369 100644 --- a/common/src/main/java/com/dfsek/terra/api/event/EventListener.java +++ b/common/src/main/java/com/dfsek/terra/api/event/EventListener.java @@ -1,4 +1,12 @@ package com.dfsek.terra.api.event; +import com.dfsek.terra.api.event.events.Event; + +/** + * Marker interface for a class that contains event listener methods. + * + * @see Event + * @see EventManager + */ public interface EventListener { } diff --git a/common/src/main/java/com/dfsek/terra/api/event/EventManager.java b/common/src/main/java/com/dfsek/terra/api/event/EventManager.java index 96378ede4..de6ba0e19 100644 --- a/common/src/main/java/com/dfsek/terra/api/event/EventManager.java +++ b/common/src/main/java/com/dfsek/terra/api/event/EventManager.java @@ -3,13 +3,23 @@ package com.dfsek.terra.api.event; import com.dfsek.terra.api.addons.TerraAddon; import com.dfsek.terra.api.event.events.Event; +/** + * Manages event registration and triggering. + */ public interface EventManager { /** * Call an event, and return the execution status. + * * @param event Event to pass to all registered EventListeners. * @return False if the event is cancellable and has been cancelled, otherwise true. */ boolean callEvent(Event event); + /** + * Register an {@link EventListener} under an {@link TerraAddon}. + * + * @param addon Addon to register listener for. + * @param listener Listener to register. + */ void registerListener(TerraAddon addon, EventListener listener); } diff --git a/common/src/main/java/com/dfsek/terra/api/event/annotations/Global.java b/common/src/main/java/com/dfsek/terra/api/event/annotations/Global.java index 5084f527a..d162c00d9 100644 --- a/common/src/main/java/com/dfsek/terra/api/event/annotations/Global.java +++ b/common/src/main/java/com/dfsek/terra/api/event/annotations/Global.java @@ -1,12 +1,15 @@ package com.dfsek.terra.api.event.annotations; +import com.dfsek.terra.api.event.events.PackEvent; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * Specifies that an event handler is to handle all events. + * Specifies that an event handler is to handle all {@link PackEvent}s, regardless of whether the pack + * depends on the addon's listener. */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) diff --git a/common/src/main/java/com/dfsek/terra/api/event/events/Cancellable.java b/common/src/main/java/com/dfsek/terra/api/event/events/Cancellable.java index bfac9adb2..ca7bccdf7 100644 --- a/common/src/main/java/com/dfsek/terra/api/event/events/Cancellable.java +++ b/common/src/main/java/com/dfsek/terra/api/event/events/Cancellable.java @@ -2,10 +2,21 @@ package com.dfsek.terra.api.event.events; /** * Events that implement this interface may be cancelled. - * + *

* Cancelling an event is assumed to stop the execution of whatever action triggered the event. */ public interface Cancellable extends Event { + /** + * Get the cancellation status of the event. + * + * @return Whether event is cancelled. + */ boolean isCancelled(); - void setCancelled(); + + /** + * Set the cancellation status of the event. + * + * @param cancelled Whether event is cancelled. + */ + void setCancelled(boolean cancelled); } diff --git a/common/src/main/java/com/dfsek/terra/api/event/events/Event.java b/common/src/main/java/com/dfsek/terra/api/event/events/Event.java index 2a65f4116..67d12a029 100644 --- a/common/src/main/java/com/dfsek/terra/api/event/events/Event.java +++ b/common/src/main/java/com/dfsek/terra/api/event/events/Event.java @@ -1,4 +1,7 @@ package com.dfsek.terra.api.event.events; +/** + * An event that addons may listen to. + */ public interface Event { } diff --git a/common/src/main/java/com/dfsek/terra/api/event/events/PackEvent.java b/common/src/main/java/com/dfsek/terra/api/event/events/PackEvent.java index adddf8b19..66f7b7d6c 100644 --- a/common/src/main/java/com/dfsek/terra/api/event/events/PackEvent.java +++ b/common/src/main/java/com/dfsek/terra/api/event/events/PackEvent.java @@ -1,8 +1,20 @@ package com.dfsek.terra.api.event.events; +import com.dfsek.terra.api.event.annotations.Global; import com.dfsek.terra.config.pack.ConfigPack; +/** + * An event with functionality directly linked to a {@link ConfigPack}. + *

+ * PackEvents are only invoked when the pack specifies the addon in its + * {@code addon} key (or when the listener is annotated {@link Global}). + */ @SuppressWarnings("InterfaceMayBeAnnotatedFunctional") public interface PackEvent extends Event { + /** + * Get the {@link ConfigPack} associated with this event. + * + * @return ConfigPack associated with the event. + */ ConfigPack getPack(); } diff --git a/common/src/main/java/com/dfsek/terra/api/event/events/config/ConfigPackLoadEvent.java b/common/src/main/java/com/dfsek/terra/api/event/events/config/ConfigPackLoadEvent.java index a6a4c5c12..7aa7ab8a4 100644 --- a/common/src/main/java/com/dfsek/terra/api/event/events/config/ConfigPackLoadEvent.java +++ b/common/src/main/java/com/dfsek/terra/api/event/events/config/ConfigPackLoadEvent.java @@ -3,6 +3,9 @@ package com.dfsek.terra.api.event.events.config; import com.dfsek.terra.api.event.events.PackEvent; import com.dfsek.terra.config.pack.ConfigPack; +/** + * An event related to the loading process of config packs. + */ public abstract class ConfigPackLoadEvent implements PackEvent { private final ConfigPack pack; diff --git a/common/src/main/java/com/dfsek/terra/api/injection/Injector.java b/common/src/main/java/com/dfsek/terra/api/injection/Injector.java index 8156ac142..c19a680fa 100644 --- a/common/src/main/java/com/dfsek/terra/api/injection/Injector.java +++ b/common/src/main/java/com/dfsek/terra/api/injection/Injector.java @@ -9,18 +9,51 @@ import java.lang.reflect.Modifier; import java.util.HashSet; import java.util.Set; +/** + * Dynamic dependency injector. + *

+ * Stores an object to inject, and injects it into objects passed to {@link #inject(Object)}. + * + * @param Type of object to inject. + */ public class Injector { private final T value; private final Set> targets = new HashSet<>(); + /** + * Instantiate an Injector with a value to inject + * + * @param value Value to inject + */ public Injector(T value) { this.value = value; } + /** + * Add an explicit class as a target. Useful for applications where subclasses may cause issues with DI. + * + * @param target Target class type. + */ public void addExplicitTarget(Class target) { targets.add(target); } + /** + * Inject the stored object into an object. + *

+ * Injects the stored object into any non-static, non-final fields + * annotated with {@link Inject}, + * with type matching the stored object or any explicit targets + * ({@link #addExplicitTarget(Class)}. + * + * @param object Object to inject into + * @throws InjectionException If: + *

    + *
  • Matching field annotated with {@link Inject} is final
  • + *
  • Matching field annotated with {@link Inject} is static
  • + *
  • A reflective access exception occurs
  • + *
+ */ public void inject(Object object) throws InjectionException { for(Field field : ReflectionUtil.getFields(object.getClass())) { Inject inject = field.getAnnotation(Inject.class); diff --git a/common/src/main/java/com/dfsek/terra/api/injection/exception/InjectionException.java b/common/src/main/java/com/dfsek/terra/api/injection/exception/InjectionException.java index 93e0d258c..314dd5e93 100644 --- a/common/src/main/java/com/dfsek/terra/api/injection/exception/InjectionException.java +++ b/common/src/main/java/com/dfsek/terra/api/injection/exception/InjectionException.java @@ -1,5 +1,10 @@ package com.dfsek.terra.api.injection.exception; +import com.dfsek.terra.api.injection.Injector; + +/** + * Thrown when dynamic dependency injection cannot be completed by an {@link Injector}. + */ public class InjectionException extends Exception { private static final long serialVersionUID = -6929631447064215387L; From 6f4251796eab6e8205fcf8618ad26b72571ddf92 Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 15 Mar 2021 21:10:52 -0700 Subject: [PATCH 93/95] optimize ores and sampling --- .../math/interpolation/ChunkInterpolator.java | 5 ++++ .../interpolation/ChunkInterpolator2D.java | 4 ++++ .../interpolation/ChunkInterpolator3D.java | 4 ++++ .../generation/math/samplers/Sampler.java | 4 ++++ .../generation/math/samplers/Sampler2D.java | 5 ++++ .../generation/math/samplers/Sampler3D.java | 5 ++++ .../population/items/ores/VanillaOre.java | 24 +++++++++---------- 7 files changed, 39 insertions(+), 12 deletions(-) diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator.java b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator.java index 5d91d43e4..a17757c9f 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator.java @@ -15,6 +15,11 @@ public interface ChunkInterpolator { */ double getNoise(double x, double y, double z); + default double getNoise(int x, int y, int z) { // Floating-point modulus operations are expensive. This allows implementations to optionally handle integers separately. + return getNoise((double) x, y, z); + } + + default double computeNoise(Map gens, double x, double y, double z) { double n = 0; double div = 0; diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator2D.java b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator2D.java index 81da092bc..27c0d42e7 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator2D.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator2D.java @@ -81,4 +81,8 @@ public class ChunkInterpolator2D implements ChunkInterpolator { public double getNoise(double x, double y, double z) { return interpGrid[reRange(((int) x) / 4, 3)][reRange(((int) z) / 4, 3)].bilerp((x % 4) / 4, (z % 4) / 4); } + + public double getNoise(int x, int y, int z) { + return interpGrid[x / 4][z / 4].bilerp((double) (x % 4) / 4, (double) (z % 4) / 4); + } } diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator3D.java b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator3D.java index e6e274465..727a8e25e 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator3D.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/interpolation/ChunkInterpolator3D.java @@ -100,4 +100,8 @@ public class ChunkInterpolator3D implements ChunkInterpolator { public double getNoise(double x, double y, double z) { return interpGrid[reRange(((int) x) / 4, 3)][FastMath.max(FastMath.min(((int) y), max), min) / 4][reRange(((int) z) / 4, 3)].trilerp((x % 4) / 4, (y % 4) / 4, (z % 4) / 4); } + + public double getNoise(int x, int y, int z) { + return interpGrid[x / 4][y / 4][z / 4].trilerp((double) (x % 4) / 4, (double) (y % 4) / 4, (double) (z % 4) / 4); + } } diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/samplers/Sampler.java b/common/src/main/java/com/dfsek/terra/world/generation/math/samplers/Sampler.java index 7e28c341d..d7dffcbe4 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/math/samplers/Sampler.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/samplers/Sampler.java @@ -3,4 +3,8 @@ package com.dfsek.terra.world.generation.math.samplers; @FunctionalInterface public interface Sampler { double sample(double x, double y, double z); + + default double sample(int x, int y, int z) { // Floating-point modulus operations are expensive. This allows implementations to optionally handle integers separately. + return sample((double) x, y, z); + } } diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/samplers/Sampler2D.java b/common/src/main/java/com/dfsek/terra/world/generation/math/samplers/Sampler2D.java index 9e901e92a..8b1b53bf7 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/math/samplers/Sampler2D.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/samplers/Sampler2D.java @@ -19,4 +19,9 @@ public class Sampler2D implements Sampler { public double sample(double x, double y, double z) { return interpolator.getNoise(x, 0, z) + elevationInterpolator.getElevation(FastMath.roundToInt(x), FastMath.roundToInt(z)); } + + @Override + public double sample(int x, int y, int z) { + return interpolator.getNoise(x, 0, z) + elevationInterpolator.getElevation(FastMath.roundToInt(x), FastMath.roundToInt(z)); + } } diff --git a/common/src/main/java/com/dfsek/terra/world/generation/math/samplers/Sampler3D.java b/common/src/main/java/com/dfsek/terra/world/generation/math/samplers/Sampler3D.java index bb07140a7..6a6c085b6 100644 --- a/common/src/main/java/com/dfsek/terra/world/generation/math/samplers/Sampler3D.java +++ b/common/src/main/java/com/dfsek/terra/world/generation/math/samplers/Sampler3D.java @@ -19,4 +19,9 @@ public class Sampler3D implements Sampler { public double sample(double x, double y, double z) { return interpolator.getNoise(x, y, z) + elevationInterpolator.getElevation(FastMath.roundToInt(x), FastMath.roundToInt(z)); } + + @Override + public double sample(int x, int y, int z) { + return interpolator.getNoise(x, y, z) + elevationInterpolator.getElevation(FastMath.roundToInt(x), FastMath.roundToInt(z)); + } } diff --git a/common/src/main/java/com/dfsek/terra/world/population/items/ores/VanillaOre.java b/common/src/main/java/com/dfsek/terra/world/population/items/ores/VanillaOre.java index 28f65d36f..549e1e378 100644 --- a/common/src/main/java/com/dfsek/terra/world/population/items/ores/VanillaOre.java +++ b/common/src/main/java/com/dfsek/terra/world/population/items/ores/VanillaOre.java @@ -5,7 +5,6 @@ import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.platform.block.Block; import com.dfsek.terra.api.platform.block.BlockData; -import com.dfsek.terra.api.platform.handle.WorldHandle; import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.util.collections.MaterialSet; import net.jafama.FastMath; @@ -23,7 +22,6 @@ public class VanillaOre extends Ore { @Override public void generate(Vector3 location, Chunk chunk, Random random) { - WorldHandle handle = main.getWorldHandle(); double size = sizeRange.get(random); int centerX = location.getBlockX(); @@ -31,29 +29,31 @@ public class VanillaOre extends Ore { int centerY = location.getBlockY(); - float f = random.nextFloat() * (float) Math.PI; + double f = random.nextFloat() * Math.PI; - double d1 = centerX + 8 + FastMath.sin(f) * size / 8.0F; - double d2 = centerX + 8 - FastMath.sin(f) * size / 8.0F; - double d3 = centerZ + 8 + FastMath.cos(f) * size / 8.0F; - double d4 = centerZ + 8 - FastMath.cos(f) * size / 8.0F; + double fS = FastMath.sin(f) * size / 8.0F; + double fC = FastMath.cos(f) * size / 8.0F; + + double d1 = centerX + 8 + fS; + double d2 = centerX + 8 - fS; + double d3 = centerZ + 8 + fC; + double d4 = centerZ + 8 - fC; double d5 = centerY + random.nextInt(3) - 2D; double d6 = centerY + random.nextInt(3) - 2D; for(int i = 0; i < size; i++) { - float iFactor = (float) i / (float) size; + double iFactor = i / size; double d10 = random.nextDouble() * size / 16.0D; double d11 = (FastMath.sin(Math.PI * iFactor) + 1.0) * d10 + 1.0; - double d12 = (FastMath.sin(Math.PI * iFactor) + 1.0) * d10 + 1.0; int xStart = FastMath.roundToInt(FastMath.floor(d1 + (d2 - d1) * iFactor - d11 / 2.0D)); - int yStart = FastMath.roundToInt(FastMath.floor(d5 + (d6 - d5) * iFactor - d12 / 2.0D)); + int yStart = FastMath.roundToInt(FastMath.floor(d5 + (d6 - d5) * iFactor - d11 / 2.0D)); int zStart = FastMath.roundToInt(FastMath.floor(d3 + (d4 - d3) * iFactor - d11 / 2.0D)); int xEnd = FastMath.roundToInt(FastMath.floor(d1 + (d2 - d1) * iFactor + d11 / 2.0D)); - int yEnd = FastMath.roundToInt(FastMath.floor(d5 + (d6 - d5) * iFactor + d12 / 2.0D)); + int yEnd = FastMath.roundToInt(FastMath.floor(d5 + (d6 - d5) * iFactor + d11 / 2.0D)); int zEnd = FastMath.roundToInt(FastMath.floor(d3 + (d4 - d3) * iFactor + d11 / 2.0D)); for(int x = xStart; x <= xEnd; x++) { @@ -61,7 +61,7 @@ public class VanillaOre extends Ore { if(d13 * d13 < 1.0D) { for(int y = yStart; y <= yEnd; y++) { - double d14 = (y + 0.5D - (d5 + (d6 - d5) * iFactor)) / (d12 / 2.0D); + double d14 = (y + 0.5D - (d5 + (d6 - d5) * iFactor)) / (d11 / 2.0D); if(d13 * d13 + d14 * d14 < 1.0D) { for(int z = zStart; z <= zEnd; z++) { double d15 = (z + 0.5D - (d3 + (d4 - d3) * iFactor)) / (d11 / 2.0D); From 6f287a1894a764df24d187a78f51c26b457f85d1 Mon Sep 17 00:00:00 2001 From: dfsek Date: Mon, 15 Mar 2021 23:24:49 -0700 Subject: [PATCH 94/95] use LinkedHashMap for loading functions to preserve order --- .../dfsek/terra/config/builder/UserDefinedBiomeBuilder.java | 4 ++-- .../java/com/dfsek/terra/config/pack/ConfigPackTemplate.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java b/common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java index 9b16f19b6..904a541c9 100644 --- a/common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java +++ b/common/src/main/java/com/dfsek/terra/config/builder/UserDefinedBiomeBuilder.java @@ -14,7 +14,7 @@ import com.dfsek.terra.config.pack.ConfigPack; import com.dfsek.terra.config.templates.BiomeTemplate; import com.dfsek.terra.world.generation.WorldGenerator; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -42,7 +42,7 @@ public class UserDefinedBiomeBuilder implements BiomeBuilder { template.getVariables().forEach(varScope::create); Map noiseBuilderMap = pack.getTemplate().getNoiseBuilderMap(); - Map functionTemplateMap = new HashMap<>(pack.getTemplate().getFunctions()); + Map functionTemplateMap = new LinkedHashMap<>(pack.getTemplate().getFunctions()); functionTemplateMap.putAll(template.getFunctions()); diff --git a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPackTemplate.java b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPackTemplate.java index 593d6e2d7..c49d2b667 100644 --- a/common/src/main/java/com/dfsek/terra/config/pack/ConfigPackTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/pack/ConfigPackTemplate.java @@ -73,7 +73,7 @@ public class ConfigPackTemplate implements ConfigTemplate { @Default private String version = "0.1.0"; - public Map getFunctions() { + public LinkedHashMap getFunctions() { return functions; } From f9ca8d139b04792e9c92dc98439cd02be8c0ebd5 Mon Sep 17 00:00:00 2001 From: dfsek Date: Tue, 16 Mar 2021 09:09:30 -0700 Subject: [PATCH 95/95] fix ExpressionFunction issue --- .../noise/ExpressionFunctionTemplate.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/com/dfsek/terra/config/loaders/config/sampler/templates/noise/ExpressionFunctionTemplate.java b/common/src/main/java/com/dfsek/terra/config/loaders/config/sampler/templates/noise/ExpressionFunctionTemplate.java index ad85eda25..79aa5a41a 100644 --- a/common/src/main/java/com/dfsek/terra/config/loaders/config/sampler/templates/noise/ExpressionFunctionTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/loaders/config/sampler/templates/noise/ExpressionFunctionTemplate.java @@ -12,6 +12,8 @@ import com.dfsek.terra.api.math.noise.NoiseSampler; import com.dfsek.terra.api.math.noise.samplers.noise.ExpressionFunction; import com.dfsek.terra.api.math.paralithic.BlankFunction; import com.dfsek.terra.api.math.paralithic.defined.UserDefinedFunction; +import com.dfsek.terra.api.math.paralithic.noise.NoiseFunction2; +import com.dfsek.terra.api.math.paralithic.noise.NoiseFunction3; import com.dfsek.terra.api.util.seeded.NoiseSeeded; import com.dfsek.terra.config.loaders.config.function.FunctionTemplate; import com.dfsek.terra.config.loaders.config.sampler.templates.SamplerTemplate; @@ -32,7 +34,7 @@ public class ExpressionFunctionTemplate extends SamplerTemplate functions = new HashMap<>(); + private LinkedHashMap functions = new LinkedHashMap<>(); @Value("expressions") @Default @@ -41,7 +43,7 @@ public class ExpressionFunctionTemplate extends SamplerTemplate noiseFunctionMap = generateFunctions(); + Map noiseFunctionMap = generateFunctions(seed); return new ExpressionFunction(noiseFunctionMap, equation, vars); } catch(ParseException e) { throw new IllegalStateException(e); @@ -51,7 +53,7 @@ public class ExpressionFunctionTemplate extends SamplerTemplate noiseFunctionMap = generateFunctions(); + Map noiseFunctionMap = generateFunctions(0L); new ExpressionFunction(noiseFunctionMap, equation, vars); } catch(ParseException e) { throw new ValidationException("Errors occurred while parsing noise equation: ", e); @@ -59,7 +61,7 @@ public class ExpressionFunctionTemplate extends SamplerTemplate generateFunctions() throws ParseException { + private Map generateFunctions(Long seed) throws ParseException { Map noiseFunctionMap = new HashMap<>(); for(Map.Entry entry : expressions.entrySet()) { @@ -69,8 +71,8 @@ public class ExpressionFunctionTemplate extends SamplerTemplate { if(function.getDimensions() == 2) { - noiseFunctionMap.put(id, new BlankFunction(2)); - } else noiseFunctionMap.put(id, new BlankFunction(3)); + noiseFunctionMap.put(id, new NoiseFunction2(function.apply(seed))); + } else noiseFunctionMap.put(id, new NoiseFunction3(function.apply(seed))); }); return noiseFunctionMap;