From c3d99eb6d983310bd95e5404872428132ea951e9 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sat, 3 Apr 2021 16:51:55 -0700 Subject: [PATCH 1/3] sort of working Minestom implementation --- .../math/paralithic/noise/NoiseFunction2.java | 2 +- .../world/generation/math/SamplerCache.java | 5 - .../population/items/flora/FloraLayer.java | 8 +- .../population/items/flora/TerraFlora.java | 2 - platforms/bukkit/build.gradle.kts | 7 +- platforms/fabric/build.gradle.kts | 6 +- platforms/minestom/build.gradle.kts | 42 ++++ .../dfsek/terra/minestom/MinestomAdapter.java | 10 + .../dfsek/terra/minestom/MinestomEntry.java | 45 ++++ .../terra/minestom/MinestomItemHandle.java | 25 +++ .../terra/minestom/TerraMinestomPlugin.java | 193 ++++++++++++++++++ .../minestom/commands/TeleportCommand.java | 19 ++ .../terra/minestom/commands/TerraCommand.java | 31 +++ .../generator/MinestomChunkGenerator.java | 16 ++ .../MinestomChunkGeneratorWrapper.java | 52 +++++ .../terra/minestom/world/MinestomBiome.java | 16 ++ .../terra/minestom/world/MinestomBlock.java | 82 ++++++++ .../minestom/world/MinestomBlockData.java | 81 ++++++++ .../world/MinestomBlockPopulatorWrapper.java | 24 +++ .../terra/minestom/world/MinestomChunk.java | 57 ++++++ .../minestom/world/MinestomChunkAccess.java | 17 ++ .../minestom/world/MinestomChunkData.java | 43 ++++ .../minestom/world/MinestomChunkWorld.java | 109 ++++++++++ .../terra/minestom/world/MinestomTree.java | 19 ++ .../terra/minestom/world/MinestomWorld.java | 84 ++++++++ .../minestom/world/MinestomWorldHandle.java | 38 ++++ platforms/region/build.gradle.kts | 6 +- platforms/sponge/build.gradle.kts | 7 +- settings.gradle.kts | 1 + 29 files changed, 1032 insertions(+), 15 deletions(-) create mode 100644 platforms/minestom/build.gradle.kts create mode 100644 platforms/minestom/src/main/java/com/dfsek/terra/minestom/MinestomAdapter.java create mode 100644 platforms/minestom/src/main/java/com/dfsek/terra/minestom/MinestomEntry.java create mode 100644 platforms/minestom/src/main/java/com/dfsek/terra/minestom/MinestomItemHandle.java create mode 100644 platforms/minestom/src/main/java/com/dfsek/terra/minestom/TerraMinestomPlugin.java create mode 100644 platforms/minestom/src/main/java/com/dfsek/terra/minestom/commands/TeleportCommand.java create mode 100644 platforms/minestom/src/main/java/com/dfsek/terra/minestom/commands/TerraCommand.java create mode 100644 platforms/minestom/src/main/java/com/dfsek/terra/minestom/generator/MinestomChunkGenerator.java create mode 100644 platforms/minestom/src/main/java/com/dfsek/terra/minestom/generator/MinestomChunkGeneratorWrapper.java create mode 100644 platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBiome.java create mode 100644 platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBlock.java create mode 100644 platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBlockData.java create mode 100644 platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBlockPopulatorWrapper.java create mode 100644 platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomChunk.java create mode 100644 platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomChunkAccess.java create mode 100644 platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomChunkData.java create mode 100644 platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomChunkWorld.java create mode 100644 platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomTree.java create mode 100644 platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomWorld.java create mode 100644 platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomWorldHandle.java 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 f4a516375..d5fb5cdc8 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 @@ -36,7 +36,7 @@ public Cache() { super(cacheSize); } - public double get(NoiseSampler noise, double x, double z) { + public synchronized double get(NoiseSampler noise, double x, double z) { double xx = x >= 0 ? x * 2 : x * -2 - 1; double zz = z >= 0 ? z * 2 : z * -2 - 1; double key = (xx >= zz) ? (xx * xx + xx + zz) : (zz * zz + xx); 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 64d4577b1..50e552649 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 @@ -2,7 +2,6 @@ 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; import com.dfsek.terra.world.generation.math.samplers.Sampler; import com.google.common.cache.CacheBuilder; @@ -11,10 +10,6 @@ import net.jafama.FastMath; import org.jetbrains.annotations.NotNull; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - public class SamplerCache { private final LoadingCache cache; 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 579b70035..0cc37e126 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 @@ -21,6 +21,12 @@ public double getDensity() { @Override public void place(Chunk chunk, Vector2 coords) { Flora item = layer.get(noise, (chunk.getX() << 4) + coords.getX(), (chunk.getZ() << 4) + coords.getZ()); - item.getValidSpawnsAt(chunk, (int) coords.getX(), (int) coords.getZ(), level).forEach(block -> item.plant(block.getLocation())); + item.getValidSpawnsAt(chunk, (int) coords.getX(), (int) coords.getZ(), level).forEach(block -> { + try { + item.plant(block.getLocation()); + } catch(Exception e) { + e.printStackTrace(); + } + }); } } 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 0893d1c92..fcd642d3e 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 @@ -9,7 +9,6 @@ import com.dfsek.terra.api.platform.block.data.Directional; import com.dfsek.terra.api.platform.block.data.MultipleFacing; import com.dfsek.terra.api.platform.block.data.Rotatable; -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; @@ -94,7 +93,6 @@ private boolean isIrrigated(Block b) { @Override public boolean plant(Location location) { - WorldHandle handle = main.getWorldHandle(); boolean doRotation = testRotation.size() > 0; int size = floraPalette.getSize(); diff --git a/platforms/bukkit/build.gradle.kts b/platforms/bukkit/build.gradle.kts index e9dac10e5..f92fcac04 100644 --- a/platforms/bukkit/build.gradle.kts +++ b/platforms/bukkit/build.gradle.kts @@ -1,5 +1,3 @@ -import com.dfsek.terra.configureCommon -import com.dfsek.terra.gitClone import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import java.net.URL import java.nio.channels.Channels @@ -168,6 +166,11 @@ task(name = "runPaper") { classpath = files("$testDir/paper/paperclip.jar") } +java { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_1_8 +} + task(name = "runPurpur") { group = "bukkit" standardInput = System.`in` diff --git a/platforms/fabric/build.gradle.kts b/platforms/fabric/build.gradle.kts index bde8a8d1a..8652de4aa 100644 --- a/platforms/fabric/build.gradle.kts +++ b/platforms/fabric/build.gradle.kts @@ -1,4 +1,3 @@ -import com.dfsek.terra.configureCommon import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import com.modrinth.minotaur.TaskModrinthUpload import net.fabricmc.loom.LoomGradleExtension @@ -17,6 +16,11 @@ tasks.named("shadowJar") { relocate("org.yaml", "com.dfsek.terra.lib.yaml") } +java { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_1_8 +} + group = "com.dfsek.terra.fabric" dependencies { diff --git a/platforms/minestom/build.gradle.kts b/platforms/minestom/build.gradle.kts new file mode 100644 index 000000000..1f0b38e37 --- /dev/null +++ b/platforms/minestom/build.gradle.kts @@ -0,0 +1,42 @@ +plugins { + java +} + +group = "com.dfsek.terra.minestom" + +configureCommon() + +repositories { + mavenCentral() + maven { url = uri("https://repo.spongepowered.org/maven") } + maven { url = uri("https://repo.velocitypowered.com/snapshots/") } + maven { url = uri("https://libraries.minecraft.net") } + maven { url = uri("https://jitpack.io") } + maven { url = uri("https://repo.codemc.org/repository/maven-public") } +} + +dependencies { + testCompile("junit", "junit", "4.12") + + "shadedImplementation"("com.googlecode.json-simple:json-simple:1.1.1") + + "shadedImplementation"("org.apache.logging.log4j:log4j-core:2.14.1") + "shadedImplementation"("org.apache.logging.log4j:log4j-api:2.14.1") + + "shadedImplementation"("com.github.Minestom:Minestom:4cf66fde08") + "shadedApi"(project(":common")) +} + +java { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 +} + +tasks.jar { + manifest { + attributes( + "Main-Class" to "com.dfsek.terra.minestom.MinestomEntry", + "Multi-Release" to "true" + ) + } +} \ No newline at end of file diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/MinestomAdapter.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/MinestomAdapter.java new file mode 100644 index 000000000..d67868553 --- /dev/null +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/MinestomAdapter.java @@ -0,0 +1,10 @@ +package com.dfsek.terra.minestom; + +import com.dfsek.terra.api.platform.block.Block; +import com.dfsek.terra.minestom.world.MinestomBlock; + +public final class MinestomAdapter { + public static net.minestom.server.instance.block.Block adapt(Block block) { + return ((MinestomBlock) block).getHandle(); + } +} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/MinestomEntry.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/MinestomEntry.java new file mode 100644 index 000000000..518058f86 --- /dev/null +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/MinestomEntry.java @@ -0,0 +1,45 @@ +package com.dfsek.terra.minestom; + + +import com.dfsek.terra.minestom.commands.TeleportCommand; +import com.dfsek.terra.minestom.generator.MinestomChunkGeneratorWrapper; +import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D; +import net.minestom.server.MinecraftServer; +import net.minestom.server.entity.GameMode; +import net.minestom.server.entity.Player; +import net.minestom.server.event.GlobalEventHandler; +import net.minestom.server.event.player.PlayerLoginEvent; +import net.minestom.server.event.player.PlayerSpawnEvent; +import net.minestom.server.instance.InstanceContainer; +import net.minestom.server.instance.InstanceManager; +import net.minestom.server.utils.Position; + +public final class MinestomEntry { + public static void main(String... args) { + MinecraftServer server = MinecraftServer.init(); + + InstanceManager instanceManager = MinecraftServer.getInstanceManager(); + + InstanceContainer container = instanceManager.createInstanceContainer(); + + TerraMinestomPlugin plugin = new TerraMinestomPlugin(); + + DefaultChunkGenerator3D chunkGenerator3D = new DefaultChunkGenerator3D(plugin.getConfigRegistry().get("DEFAULT"), plugin); + + container.setChunkGenerator(new MinestomChunkGeneratorWrapper(chunkGenerator3D, container)); + + GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler(); + globalEventHandler.addEventCallback(PlayerLoginEvent.class, event -> { + Player player = event.getPlayer(); + event.setSpawningInstance(container); + player.setRespawnPoint(new Position(0, 64, 0)); + }); + + MinecraftServer.getCommandManager().register(new TeleportCommand()); + + + globalEventHandler.addEventCallback(PlayerSpawnEvent.class, event -> event.getPlayer().setGameMode(GameMode.SPECTATOR)); + + server.start("0.0.0.0", 25565); + } +} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/MinestomItemHandle.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/MinestomItemHandle.java new file mode 100644 index 000000000..bb4c68ff4 --- /dev/null +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/MinestomItemHandle.java @@ -0,0 +1,25 @@ +package com.dfsek.terra.minestom; + +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 java.util.Collections; +import java.util.Set; + +public class MinestomItemHandle implements ItemHandle { + @Override + public Item createItem(String data) { + return null; + } + + @Override + public Enchantment getEnchantment(String id) { + return null; + } + + @Override + public Set getEnchantments() { + return Collections.emptySet(); + } +} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/TerraMinestomPlugin.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/TerraMinestomPlugin.java new file mode 100644 index 000000000..0e942bda0 --- /dev/null +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/TerraMinestomPlugin.java @@ -0,0 +1,193 @@ +package com.dfsek.terra.minestom; + +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.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.Biome; +import com.dfsek.terra.api.platform.world.Tree; +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.api.util.logging.Logger; +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.minestom.world.MinestomBiome; +import com.dfsek.terra.minestom.world.MinestomChunkAccess; +import com.dfsek.terra.minestom.world.MinestomTree; +import com.dfsek.terra.minestom.world.MinestomWorld; +import com.dfsek.terra.minestom.world.MinestomWorldHandle; +import com.dfsek.terra.registry.master.AddonRegistry; +import com.dfsek.terra.registry.master.ConfigRegistry; +import com.dfsek.terra.world.TerraWorld; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import net.minestom.server.instance.Instance; +import org.apache.logging.log4j.LogManager; + +import java.io.File; +import java.util.Map; + +public class TerraMinestomPlugin implements TerraPlugin { + private final org.apache.logging.log4j.Logger logger = LogManager.getLogger(); + private final MinestomWorldHandle worldHandle = new MinestomWorldHandle(); + private final PluginConfig config = new PluginConfig(); + private final EventManager eventManager = new TerraEventManager(this); + private final ConfigRegistry configRegistry = new ConfigRegistry(); + private final AddonRegistry addonRegistry = new AddonRegistry(new MinestomPlugin(this), this); + private final GenericLoaders genericLoaders = new GenericLoaders(this); + private final MinestomItemHandle itemHandle = new MinestomItemHandle(); + private final Map instanceTerraWorldMap = new Object2ObjectOpenHashMap<>(); + + public TerraMinestomPlugin() { + if(!getDataFolder().exists()) { + getDataFolder().mkdirs(); + } + LangUtil.load(config.getLanguage(), this); + configRegistry.loadAll(this); + addonRegistry.loadAll(); + } + + @Override + public void register(TypeRegistry registry) { + registry + .registerLoader(BlockData.class, (t, o, l) -> worldHandle.createBlockData((String) o)) + .registerLoader(Biome.class, (t, o, l) -> new MinestomBiome(net.minestom.server.world.biomes.Biome.PLAINS)); + genericLoaders.register(registry); + } + + @Override + public WorldHandle getWorldHandle() { + return worldHandle; + } + + @Override + public TerraWorld getWorld(World world) { + if(world instanceof MinestomWorld) { + return instanceTerraWorldMap.computeIfAbsent(((MinestomWorld) world).getHandle(), instance -> new TerraWorld(new MinestomWorld(instance), configRegistry.get("DEFAULT"), this)); + } else { + return instanceTerraWorldMap.computeIfAbsent(((MinestomWorld) ((MinestomChunkAccess) world).getWorld()).getHandle(), instance -> new TerraWorld(new MinestomWorld(instance), configRegistry.get("DEFAULT"), this)); + } + } + + @Override + public Logger logger() { + return new Logger() { + @Override + public void info(String message) { + System.out.println(message); + } + + @Override + public void warning(String message) { + System.out.println(message); + } + + @Override + public void severe(String message) { + System.err.println(message); + } + }; + } + + @Override + public PluginConfig getTerraConfig() { + return config; + } + + @Override + public File getDataFolder() { + return new File("Terra"); + } + + @Override + public boolean isDebug() { + return true; + } + + @Override + public Language getLanguage() { + return LangUtil.getLanguage(); + } + + @Override + public CheckedRegistry getConfigRegistry() { + return new CheckedRegistry<>(configRegistry); + } + + @Override + public LockedRegistry getAddons() { + return new LockedRegistry<>(addonRegistry); + } + + @Override + public boolean reload() { + return true; + } + + @Override + public ItemHandle getItemHandle() { + return itemHandle; + } + + @Override + public void saveDefaultConfig() { + + } + + @Override + public String platformName() { + return "Minestom"; + } + + @Override + public DebugLogger getDebugLogger() { + return new DebugLogger(logger()); + } + + @Override + public EventManager getEventManager() { + return eventManager; + } + + @Addon("Terra-Minestom") + @Author("Terra") + @Version("1.0.0") + private static final class MinestomPlugin extends TerraAddon implements EventListener { + private final TerraPlugin main; + + private MinestomPlugin(TerraPlugin main) { + this.main = main; + } + + @Override + public void initialize() { + main.getEventManager().registerListener(this, this); + } + + @Global + public void registerTrees(ConfigPackPreLoadEvent event) { + CheckedRegistry treeCheckedRegistry = event.getPack().getTreeRegistry(); + + treeCheckedRegistry.addUnchecked("BIRCH", new MinestomTree()); + treeCheckedRegistry.addUnchecked("JUNGLE_BUSH", new MinestomTree()); + treeCheckedRegistry.addUnchecked("SWAMP_OAK", new MinestomTree()); + treeCheckedRegistry.addUnchecked("JUNGLE_COCOA", new MinestomTree()); + treeCheckedRegistry.addUnchecked("RED_MUSHROOM", new MinestomTree()); + treeCheckedRegistry.addUnchecked("BROWN_MUSHROOM", new MinestomTree()); + } + } +} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/commands/TeleportCommand.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/commands/TeleportCommand.java new file mode 100644 index 000000000..c68db1bab --- /dev/null +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/commands/TeleportCommand.java @@ -0,0 +1,19 @@ +package com.dfsek.terra.minestom.commands; + +import net.minestom.server.command.builder.Command; +import net.minestom.server.command.builder.arguments.Argument; +import net.minestom.server.command.builder.arguments.ArgumentType; +import net.minestom.server.entity.Entity; +import net.minestom.server.utils.Position; + +public class TeleportCommand extends Command { + public TeleportCommand() { + super("teleport", "tp"); + + Argument x = ArgumentType.Double("x"); + Argument y = ArgumentType.Double("y"); + Argument z = ArgumentType.Double("z"); + + addSyntax((sender, context) -> ((Entity) sender).teleport(new Position(context.get(x), context.get(y), context.get(z))), x, y, z); + } +} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/commands/TerraCommand.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/commands/TerraCommand.java new file mode 100644 index 000000000..947635e05 --- /dev/null +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/commands/TerraCommand.java @@ -0,0 +1,31 @@ +package com.dfsek.terra.minestom.commands; + +import com.dfsek.terra.api.TerraPlugin; +import com.dfsek.terra.api.command.CommandManager; +import com.dfsek.terra.api.command.TerraCommandManager; +import com.dfsek.terra.api.command.exception.CommandException; +import net.minestom.server.command.builder.Command; +import net.minestom.server.command.builder.arguments.ArgumentStringArray; +import net.minestom.server.command.builder.arguments.ArgumentType; + +import java.util.Arrays; +import java.util.List; + +public class TerraCommand extends Command { + public TerraCommand(TerraPlugin main) { + super("terra", "te"); + + CommandManager manager = new TerraCommandManager(main); + + ArgumentStringArray argument = ArgumentType.StringArray("args"); + + addSyntax(((sender, context) -> { + List args = Arrays.asList(context.get(argument)); + try { + manager.execute(args.remove(0), null, args); + } catch(CommandException e) { + e.printStackTrace(); + } + }), argument); + } +} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/generator/MinestomChunkGenerator.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/generator/MinestomChunkGenerator.java new file mode 100644 index 000000000..e4d0f7f39 --- /dev/null +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/generator/MinestomChunkGenerator.java @@ -0,0 +1,16 @@ +package com.dfsek.terra.minestom.generator; + +import com.dfsek.terra.api.platform.world.generator.ChunkGenerator; + +public class MinestomChunkGenerator implements ChunkGenerator { + private final net.minestom.server.instance.ChunkGenerator delegate; + + public MinestomChunkGenerator(net.minestom.server.instance.ChunkGenerator delegate) { + this.delegate = delegate; + } + + @Override + public net.minestom.server.instance.ChunkGenerator getHandle() { + return delegate; + } +} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/generator/MinestomChunkGeneratorWrapper.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/generator/MinestomChunkGeneratorWrapper.java new file mode 100644 index 000000000..fc45412c1 --- /dev/null +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/generator/MinestomChunkGeneratorWrapper.java @@ -0,0 +1,52 @@ +package com.dfsek.terra.minestom.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.minestom.world.MinestomBlockPopulatorWrapper; +import com.dfsek.terra.minestom.world.MinestomChunkData; +import com.dfsek.terra.minestom.world.MinestomWorld; +import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D; +import net.minestom.server.instance.ChunkGenerator; +import net.minestom.server.instance.ChunkPopulator; +import net.minestom.server.instance.Instance; +import net.minestom.server.instance.batch.ChunkBatch; +import net.minestom.server.world.biomes.Biome; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class MinestomChunkGeneratorWrapper implements GeneratorWrapper, ChunkGenerator { + private final DefaultChunkGenerator3D chunkGenerator3D; + private final Instance instance; + private final List populators = new ArrayList<>(); + + public MinestomChunkGeneratorWrapper(DefaultChunkGenerator3D chunkGenerator3D, Instance instance) { + this.chunkGenerator3D = chunkGenerator3D; + this.instance = instance; + chunkGenerator3D.getPopulators().forEach(terraBlockPopulator -> populators.add(new MinestomBlockPopulatorWrapper(terraBlockPopulator, instance))); + } + + @Override + public TerraChunkGenerator getHandle() { + return chunkGenerator3D; + } + + @Override + public void generateChunkData(@NotNull ChunkBatch batch, int chunkX, int chunkZ) { + chunkGenerator3D.generateChunkData(new MinestomWorld(instance), new FastRandom(), chunkX, chunkZ, new MinestomChunkData(batch)); + } + + @Override + public void fillBiomes(@NotNull Biome[] biomes, int chunkX, int chunkZ) { + Arrays.fill(biomes, Biome.PLAINS); + } + + @Override + public @Nullable List getPopulators() { + return populators; + } +} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBiome.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBiome.java new file mode 100644 index 000000000..e5947baf4 --- /dev/null +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBiome.java @@ -0,0 +1,16 @@ +package com.dfsek.terra.minestom.world; + +import com.dfsek.terra.api.platform.world.Biome; + +public class MinestomBiome implements Biome { + private final net.minestom.server.world.biomes.Biome delegate; + + public MinestomBiome(net.minestom.server.world.biomes.Biome delegate) { + this.delegate = delegate; + } + + @Override + public Object getHandle() { + return delegate; + } +} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBlock.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBlock.java new file mode 100644 index 000000000..bf36e90ff --- /dev/null +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBlock.java @@ -0,0 +1,82 @@ +package com.dfsek.terra.minestom.world; + +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.state.BlockState; +import com.dfsek.terra.api.util.generic.either.Either; +import net.minestom.server.utils.BlockPosition; + +public class MinestomBlock implements Block { + private final net.minestom.server.instance.block.Block delegate; + private final BlockPosition position; + private final Either world; + + public MinestomBlock(net.minestom.server.instance.block.Block delegate, BlockPosition position, Either world) { + this.delegate = delegate; + this.position = position; + this.world = world; + } + + @Override + public net.minestom.server.instance.block.Block getHandle() { + return delegate; + } + + @Override + public void setBlockData(BlockData data, boolean physics) { + world.ifLeft(chunk -> chunk.getHandle().setBlock(position.getX() - (chunk.getX() << 4), position.getY(), position.getZ() - (chunk.getZ() << 4), ((MinestomBlockData) data).getHandle())); + world.ifRight(world -> { + //world.getHandle().setBlock(position.getX(), position.getY(), position.getZ(), delegate); + }); + } + + @Override + public BlockData getBlockData() { + return new MinestomBlockData(delegate); + } + + @Override + public BlockState getState() { + return null; + } + + @Override + public Block getRelative(BlockFace face, int len) { + BlockPosition newLoc = position.clone().add(face.getModX(), face.getModY(), face.getModZ()); + if(world.hasLeft()) return world.getLeft().get().getBlock(newLoc.getX(), newLoc.getY(), newLoc.getZ()); + else return world.getRight().get().getBlockAt(newLoc.getX(), newLoc.getY(), newLoc.getZ()); + } + + @Override + public boolean isEmpty() { + return delegate.isAir(); + } + + @Override + public Location getLocation() { + if(world.hasLeft()) return new Location(world.getLeft().get().getWorld(), position.getX(), position.getY(), position.getZ()); + return new Location(world.getRight().get(), position.getX(), position.getY(), position.getZ()); + } + + @Override + public int getX() { + return position.getX(); + } + + @Override + public int getZ() { + return position.getZ(); + } + + @Override + public int getY() { + return position.getY(); + } + + @Override + public boolean isPassable() { + return !delegate.isSolid(); + } +} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBlockData.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBlockData.java new file mode 100644 index 000000000..b82ae3937 --- /dev/null +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBlockData.java @@ -0,0 +1,81 @@ +package com.dfsek.terra.minestom.world; + +import com.dfsek.terra.api.platform.block.BlockData; +import com.dfsek.terra.api.platform.block.BlockType; +import net.minestom.server.instance.block.Block; + +public class MinestomBlockData implements BlockData, BlockType { + private final Block delegate; + + public MinestomBlockData(Block delegate) { + if(delegate == null) throw new NullPointerException("Delegate must not be null"); + this.delegate = delegate; + } + + @Override + public Block getHandle() { + return delegate; + } + + @Override + public BlockType getBlockType() { + return this; + } + + @Override + public boolean matches(BlockData other) { + return delegate == ((MinestomBlockData) other).delegate; + } + + @Override + public BlockData clone() { + BlockData clone; + try { + clone = (BlockData) super.clone(); + } catch(CloneNotSupportedException e) { + throw new Error(e); + } + return clone; + } + + @Override + public String getAsString() { + return delegate.getName(); + } + + @Override + public boolean isAir() { + return delegate.isAir(); + } + + @Override + public boolean isStructureVoid() { + return delegate == Block.STRUCTURE_VOID; + } + + @Override + public BlockData getDefaultData() { + return this; + } + + @Override + public boolean isSolid() { + return delegate.isSolid(); + } + + @Override + public boolean isWater() { + return delegate == Block.WATER; + } + + @Override + public int hashCode() { + return delegate.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if(!(obj instanceof MinestomBlockData)) return false; + return ((MinestomBlockData) obj).delegate == delegate; + } +} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBlockPopulatorWrapper.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBlockPopulatorWrapper.java new file mode 100644 index 000000000..a00ec27c7 --- /dev/null +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBlockPopulatorWrapper.java @@ -0,0 +1,24 @@ +package com.dfsek.terra.minestom.world; + +import com.dfsek.terra.api.platform.world.World; +import com.dfsek.terra.api.world.generation.TerraBlockPopulator; +import net.minestom.server.instance.Chunk; +import net.minestom.server.instance.ChunkPopulator; +import net.minestom.server.instance.Instance; +import net.minestom.server.instance.batch.ChunkBatch; + +public class MinestomBlockPopulatorWrapper implements ChunkPopulator { + private final TerraBlockPopulator populator; + private final Instance world; + + public MinestomBlockPopulatorWrapper(TerraBlockPopulator populator, Instance world) { + this.populator = populator; + this.world = world; + } + + @Override + public void populateChunk(ChunkBatch batch, Chunk chunk) { + World minestom = new MinestomChunkWorld(batch, chunk, world); + populator.populate(minestom, new MinestomChunk(chunk, batch, new MinestomWorld(world))); + } +} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomChunk.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomChunk.java new file mode 100644 index 000000000..657d60b29 --- /dev/null +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomChunk.java @@ -0,0 +1,57 @@ +package com.dfsek.terra.minestom.world; + +import com.dfsek.terra.api.platform.block.Block; +import com.dfsek.terra.api.platform.block.BlockData; +import com.dfsek.terra.api.platform.world.Chunk; +import com.dfsek.terra.api.platform.world.World; +import com.dfsek.terra.api.util.generic.either.Either; +import net.minestom.server.instance.batch.ChunkBatch; +import net.minestom.server.utils.BlockPosition; +import org.jetbrains.annotations.NotNull; + +public class MinestomChunk implements Chunk, MinestomChunkAccess { + private final net.minestom.server.instance.Chunk chunk; + private final ChunkBatch batch; + private final MinestomWorld world; + + public MinestomChunk(net.minestom.server.instance.Chunk chunk, ChunkBatch batch, MinestomWorld world) { + this.chunk = chunk; + this.batch = batch; + this.world = world; + } + + @Override + public ChunkBatch getHandle() { + return batch; + } + + @Override + public int getX() { + return chunk.getChunkX(); + } + + @Override + public int getZ() { + return chunk.getChunkZ(); + } + + @Override + public World getWorld() { + return new MinestomChunkWorld(batch, chunk, world.getHandle()); + } + + @Override + public Block getBlock(int x, int y, int z) { + return new MinestomBlock(net.minestom.server.instance.block.Block.fromStateId(chunk.getBlockStateId(x, y, z)), new BlockPosition((getX() << 4) + x, y, (getZ() << 4) + z), Either.left(this)); + } + + @Override + public void setBlock(int x, int y, int z, @NotNull BlockData blockData) { + batch.setBlock(x, y, z, ((MinestomBlockData) blockData).getHandle()); + } + + @Override + public @NotNull BlockData getBlockData(int x, int y, int z) { + return getBlock(x, y, z).getBlockData(); + } +} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomChunkAccess.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomChunkAccess.java new file mode 100644 index 000000000..fe89cf949 --- /dev/null +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomChunkAccess.java @@ -0,0 +1,17 @@ +package com.dfsek.terra.minestom.world; + +import com.dfsek.terra.api.platform.block.Block; +import com.dfsek.terra.api.platform.world.World; +import net.minestom.server.instance.batch.ChunkBatch; + +public interface MinestomChunkAccess { + ChunkBatch getHandle(); + + int getX(); + + int getZ(); + + Block getBlock(int x, int y, int z); + + World getWorld(); +} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomChunkData.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomChunkData.java new file mode 100644 index 000000000..3de2c4d79 --- /dev/null +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomChunkData.java @@ -0,0 +1,43 @@ +package com.dfsek.terra.minestom.world; + +import com.dfsek.terra.api.platform.block.BlockData; +import com.dfsek.terra.api.platform.world.generator.ChunkData; +import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; +import net.minestom.server.instance.batch.ChunkBatch; +import net.minestom.server.instance.block.Block; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +public class MinestomChunkData implements ChunkData { + private static final BlockData AIR = new MinestomBlockData(Block.AIR); + private final ChunkBatch batch; + private final Map dataMap = new Long2ObjectOpenHashMap<>(); + + public MinestomChunkData(ChunkBatch batch) { + this.batch = batch; + } + + @Override + public Object getHandle() { + return batch; + } + + @Override + public void setBlock(int x, int y, int z, @NotNull BlockData blockData) { + MinestomBlockData d = ((MinestomBlockData) blockData); + dataMap.put(((long) y << 12) + ((long) x << 4) + y, d); + batch.setBlock(x, y, z, d.getHandle()); + } + + @Override + public @NotNull BlockData getBlockData(int x, int y, int z) { + BlockData data = dataMap.get(((long) y << 12) + ((long) x << 4) + y); + return data == null ? AIR : data; + } + + @Override + public int getMaxHeight() { + return 255; + } +} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomChunkWorld.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomChunkWorld.java new file mode 100644 index 000000000..76ce57425 --- /dev/null +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomChunkWorld.java @@ -0,0 +1,109 @@ +package com.dfsek.terra.minestom.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.api.util.generic.either.Either; +import com.dfsek.terra.minestom.generator.MinestomChunkGenerator; +import net.minestom.server.instance.Instance; +import net.minestom.server.instance.batch.ChunkBatch; +import net.minestom.server.utils.BlockPosition; + +import java.io.File; +import java.util.UUID; + +public class MinestomChunkWorld implements World, MinestomChunkAccess { + private final ChunkBatch batch; + private final net.minestom.server.instance.Chunk chunk; + private final Instance world; + + public MinestomChunkWorld(ChunkBatch batch, net.minestom.server.instance.Chunk chunk, Instance world) { + this.batch = batch; + this.chunk = chunk; + this.world = world; + } + + @Override + public ChunkBatch getHandle() { + return batch; + } + + @Override + public int getX() { + return chunk.getChunkX(); + } + + @Override + public int getZ() { + return chunk.getChunkZ(); + } + + @Override + public Block getBlock(int x, int y, int z) { + return new MinestomBlock(net.minestom.server.instance.block.Block.fromStateId(chunk.getBlockStateId(x, y, z)), new BlockPosition((chunk.getChunkX() << 4) + x, y, (chunk.getChunkZ() << 4) + z), Either.left(this)); + } + + @Override + public World getWorld() { + return new MinestomWorld(world); + } + + @Override + public long getSeed() { + return 0; + } + + @Override + public int getMaxHeight() { + return 255; + } + + @Override + public ChunkGenerator getGenerator() { + return new MinestomChunkGenerator(world.getChunkGenerator()); + } + + @Override + public String getName() { + return null; + } + + @Override + public UUID getUID() { + return world.getUniqueId(); + } + + @Override + public boolean isChunkGenerated(int x, int z) { + return false; + } + + @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) { + return new MinestomBlock(net.minestom.server.instance.block.Block.fromStateId(chunk.getBlockStateId(x - (getX() << 4), y, z - (getZ() << 4))), new BlockPosition(x, y, z), Either.left(this)); + } + + @Override + public Entity spawnEntity(Location location, EntityType entityType) { + return null; + } + + @Override + public int getMinHeight() { + return 0; + } +} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomTree.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomTree.java new file mode 100644 index 000000000..5c2b2fa88 --- /dev/null +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomTree.java @@ -0,0 +1,19 @@ +package com.dfsek.terra.minestom.world; + +import com.dfsek.terra.api.math.vector.Location; +import com.dfsek.terra.api.platform.world.Tree; +import com.dfsek.terra.api.util.collections.MaterialSet; + +import java.util.Random; + +public class MinestomTree implements Tree { + @Override + public boolean plant(Location l, Random r) { + return true; + } + + @Override + public MaterialSet getSpawnable() { + return MaterialSet.empty(); + } +} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomWorld.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomWorld.java new file mode 100644 index 000000000..d97417a4c --- /dev/null +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomWorld.java @@ -0,0 +1,84 @@ +package com.dfsek.terra.minestom.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.api.util.generic.either.Either; +import com.dfsek.terra.minestom.generator.MinestomChunkGenerator; +import net.minestom.server.instance.Instance; +import net.minestom.server.utils.BlockPosition; + +import java.io.File; +import java.util.UUID; + +public class MinestomWorld implements World { + private final Instance instance; + + public MinestomWorld(Instance instance) { + this.instance = instance; + } + + @Override + public Instance getHandle() { + return instance; + } + + @Override + public long getSeed() { + return 2403; + } + + @Override + public int getMaxHeight() { + return 255; + } + + @Override + public ChunkGenerator getGenerator() { + return new MinestomChunkGenerator(instance.getChunkGenerator()); + } + + @Override + public String getName() { + return null; + } + + @Override + public UUID getUID() { + return instance.getUniqueId(); + } + + @Override + public boolean isChunkGenerated(int x, int z) { + return false; + } + + @Override + public Chunk getChunkAt(int x, int z) { + return null; //instance.getChunk(x, z); + } + + @Override + public File getWorldFolder() { + return null; + } + + @Override + public Block getBlockAt(int x, int y, int z) { + return new MinestomBlock(instance.getBlock(x, y, z), new BlockPosition(x, y, z), Either.right(this)); + } + + @Override + public Entity spawnEntity(Location location, EntityType entityType) { + return null; + } + + @Override + public int getMinHeight() { + return 0; + } +} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomWorldHandle.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomWorldHandle.java new file mode 100644 index 000000000..1827a5df0 --- /dev/null +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomWorldHandle.java @@ -0,0 +1,38 @@ +package com.dfsek.terra.minestom.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 net.minestom.server.instance.block.Block; + +import java.util.HashMap; +import java.util.Map; + +public class MinestomWorldHandle implements WorldHandle { + private static final Map BLOCKS = new HashMap<>(); + + static { + for(Block value : Block.values()) { + BLOCKS.put(value.getName(), value); + } + } + + @Override + public BlockData createBlockData(String data) { + String baseData = data.contains("[") ? data.substring(0, data.indexOf('[')) : data; + + Block minestomBlock = BLOCKS.get(baseData); + if(data.contains("[")) { + String properties = data.substring(data.indexOf('['), data.indexOf(']')); + String[] propArray = properties.split(","); + minestomBlock = Block.fromStateId(minestomBlock.withProperties(propArray)); + } + + return new MinestomBlockData(minestomBlock); + } + + @Override + public EntityType getEntity(String id) { + return null; + } +} diff --git a/platforms/region/build.gradle.kts b/platforms/region/build.gradle.kts index 3d467c794..f697784d4 100644 --- a/platforms/region/build.gradle.kts +++ b/platforms/region/build.gradle.kts @@ -1,4 +1,3 @@ -import com.dfsek.terra.configureCommon import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar plugins { @@ -14,6 +13,11 @@ repositories { maven { url = uri("https://jitpack.io/") } } +java { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 +} + dependencies { "shadedApi"(project(":common")) "shadedImplementation"("com.github.Querz:NBT:5.2") // Standalone NBT API diff --git a/platforms/sponge/build.gradle.kts b/platforms/sponge/build.gradle.kts index 9880b8c93..c700b0158 100644 --- a/platforms/sponge/build.gradle.kts +++ b/platforms/sponge/build.gradle.kts @@ -1,5 +1,3 @@ -import com.dfsek.terra.configureCommon - plugins { java id("org.spongepowered.plugin").version("0.9.0") @@ -14,6 +12,11 @@ repositories { jcenter() } +java { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_1_8 +} + dependencies { "compileOnly"("org.spongepowered:spongeapi:7.2.0") "shadedApi"(project(":common")) diff --git a/settings.gradle.kts b/settings.gradle.kts index 303d70045..b2dc3cd76 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -13,6 +13,7 @@ include("platforms:bukkit") include("platforms:fabric") include("platforms:region") include("platforms:sponge") +include("platforms:minestom") pluginManagement { repositories { From 468bee27ab957190051c1fb051f6f49743ae3ed6 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sat, 3 Apr 2021 16:59:46 -0700 Subject: [PATCH 2/3] fix buildscripts --- platforms/bukkit/build.gradle.kts | 2 ++ platforms/fabric/build.gradle.kts | 1 + platforms/minestom/build.gradle.kts | 2 ++ platforms/region/build.gradle.kts | 1 + platforms/sponge/build.gradle.kts | 2 ++ 5 files changed, 8 insertions(+) diff --git a/platforms/bukkit/build.gradle.kts b/platforms/bukkit/build.gradle.kts index f92fcac04..204d42536 100644 --- a/platforms/bukkit/build.gradle.kts +++ b/platforms/bukkit/build.gradle.kts @@ -1,3 +1,5 @@ +import com.dfsek.terra.configureCommon +import com.dfsek.terra.gitClone import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import java.net.URL import java.nio.channels.Channels diff --git a/platforms/fabric/build.gradle.kts b/platforms/fabric/build.gradle.kts index 8652de4aa..04a4bd057 100644 --- a/platforms/fabric/build.gradle.kts +++ b/platforms/fabric/build.gradle.kts @@ -1,3 +1,4 @@ +import com.dfsek.terra.configureCommon import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import com.modrinth.minotaur.TaskModrinthUpload import net.fabricmc.loom.LoomGradleExtension diff --git a/platforms/minestom/build.gradle.kts b/platforms/minestom/build.gradle.kts index 1f0b38e37..1f997b73e 100644 --- a/platforms/minestom/build.gradle.kts +++ b/platforms/minestom/build.gradle.kts @@ -1,3 +1,5 @@ +import com.dfsek.terra.configureCommon + plugins { java } diff --git a/platforms/region/build.gradle.kts b/platforms/region/build.gradle.kts index f697784d4..257ff8cbd 100644 --- a/platforms/region/build.gradle.kts +++ b/platforms/region/build.gradle.kts @@ -1,3 +1,4 @@ +import com.dfsek.terra.configureCommon import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar plugins { diff --git a/platforms/sponge/build.gradle.kts b/platforms/sponge/build.gradle.kts index c700b0158..b2f063227 100644 --- a/platforms/sponge/build.gradle.kts +++ b/platforms/sponge/build.gradle.kts @@ -1,3 +1,5 @@ +import com.dfsek.terra.configureCommon + plugins { java id("org.spongepowered.plugin").version("0.9.0") From 952c3cf0869baaddfc31c803d151c996e8fac4e2 Mon Sep 17 00:00:00 2001 From: dfsek Date: Sat, 3 Apr 2021 18:30:03 -0700 Subject: [PATCH 3/3] implement MinestomBiomeGrid --- .../dfsek/terra/minestom/MinestomEntry.java | 2 + .../MinestomChunkGeneratorWrapper.java | 4 +- .../terra/minestom/world/MinestomBiome.java | 2 +- .../minestom/world/MinestomBiomeGrid.java | 52 +++++++++++++++++++ 4 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBiomeGrid.java diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/MinestomEntry.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/MinestomEntry.java index 518058f86..4baf46106 100644 --- a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/MinestomEntry.java +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/MinestomEntry.java @@ -28,6 +28,8 @@ public static void main(String... args) { container.setChunkGenerator(new MinestomChunkGeneratorWrapper(chunkGenerator3D, container)); + MinecraftServer.getBiomeManager().unmodifiableCollection().forEach(biome -> System.out.println(biome.getId() + ": " + biome.toNbt())); + GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler(); globalEventHandler.addEventCallback(PlayerLoginEvent.class, event -> { Player player = event.getPlayer(); diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/generator/MinestomChunkGeneratorWrapper.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/generator/MinestomChunkGeneratorWrapper.java index fc45412c1..f6a20283f 100644 --- a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/generator/MinestomChunkGeneratorWrapper.java +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/generator/MinestomChunkGeneratorWrapper.java @@ -3,6 +3,7 @@ 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.minestom.world.MinestomBiomeGrid; import com.dfsek.terra.minestom.world.MinestomBlockPopulatorWrapper; import com.dfsek.terra.minestom.world.MinestomChunkData; import com.dfsek.terra.minestom.world.MinestomWorld; @@ -16,7 +17,6 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; public class MinestomChunkGeneratorWrapper implements GeneratorWrapper, ChunkGenerator { @@ -42,7 +42,7 @@ public void generateChunkData(@NotNull ChunkBatch batch, int chunkX, int chunkZ) @Override public void fillBiomes(@NotNull Biome[] biomes, int chunkX, int chunkZ) { - Arrays.fill(biomes, Biome.PLAINS); + chunkGenerator3D.generateBiomes(new MinestomWorld(instance), new FastRandom(), chunkX, chunkZ, new MinestomBiomeGrid(biomes, chunkX, chunkZ)); } @Override diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBiome.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBiome.java index e5947baf4..fe4112d5b 100644 --- a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBiome.java +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBiome.java @@ -10,7 +10,7 @@ public MinestomBiome(net.minestom.server.world.biomes.Biome delegate) { } @Override - public Object getHandle() { + public net.minestom.server.world.biomes.Biome getHandle() { return delegate; } } diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBiomeGrid.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBiomeGrid.java new file mode 100644 index 000000000..e54d33ac2 --- /dev/null +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomBiomeGrid.java @@ -0,0 +1,52 @@ +package com.dfsek.terra.minestom.world; + +import com.dfsek.terra.api.platform.world.Biome; +import com.dfsek.terra.api.platform.world.BiomeGrid; +import org.jetbrains.annotations.NotNull; + +public class MinestomBiomeGrid implements BiomeGrid { + private final net.minestom.server.world.biomes.Biome[] biomes; + private final int chunkX; + private final int chunkZ; + + public MinestomBiomeGrid(net.minestom.server.world.biomes.Biome[] biomes, int chunkX, int chunkZ) { + this.biomes = biomes; + this.chunkX = chunkX; + this.chunkZ = chunkZ; + } + + @Override + public Object getHandle() { + return null; + } + + @Override + public @NotNull Biome getBiome(int x, int z) { + return getBiome(x, 0, z); + } + + @Override + public @NotNull Biome getBiome(int x, int y, int z) { + x -= (chunkX << 4); + z -= (chunkZ << 4); + x >>= 2; + y >>= 2; + z >>= 2; + return new MinestomBiome(biomes[(x << 8) + (y << 2) + z]); + } + + @Override + public void setBiome(int x, int z, @NotNull Biome bio) { + for(int y = 0; y < 64; y++) setBiome(x, y << 2, z, bio); + } + + @Override + public void setBiome(int x, int y, int z, @NotNull Biome bio) { + x -= (chunkX << 4); + z -= (chunkZ << 4); + x >>= 2; + y >>= 2; + z >>= 2; + biomes[(x << 8) + (y << 2) + z] = ((MinestomBiome) bio).getHandle(); + } +}