mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-05 07:16:10 +00:00
sort of working Minestom implementation
This commit is contained in:
@@ -36,7 +36,7 @@ public class NoiseFunction2 implements NoiseFunction {
|
||||
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);
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.dfsek.terra.world.generation.math;
|
||||
|
||||
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 com.google.common.cache.LoadingCache;
|
||||
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<Long, Sampler> cache;
|
||||
|
||||
|
||||
@@ -21,6 +21,12 @@ public class FloraLayer extends PlaceableLayer<Flora> {
|
||||
@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();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import com.dfsek.terra.api.platform.block.BlockFace;
|
||||
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 @@ public class TerraFlora implements Flora {
|
||||
|
||||
@Override
|
||||
public boolean plant(Location location) {
|
||||
WorldHandle handle = main.getWorldHandle();
|
||||
|
||||
boolean doRotation = testRotation.size() > 0;
|
||||
int size = floraPalette.getSize();
|
||||
|
||||
@@ -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<JavaExec>(name = "runPaper") {
|
||||
classpath = files("$testDir/paper/paperclip.jar")
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
task<JavaExec>(name = "runPurpur") {
|
||||
group = "bukkit"
|
||||
standardInput = System.`in`
|
||||
|
||||
@@ -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>("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 {
|
||||
|
||||
42
platforms/minestom/build.gradle.kts
Normal file
42
platforms/minestom/build.gradle.kts
Normal file
@@ -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"
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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<Enchantment> getEnchantments() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
@@ -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<Instance, TerraWorld> 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<ConfigPack> getConfigRegistry() {
|
||||
return new CheckedRegistry<>(configRegistry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LockedRegistry<TerraAddon> 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<Tree> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Double> x = ArgumentType.Double("x");
|
||||
Argument<Double> y = ArgumentType.Double("y");
|
||||
Argument<Double> z = ArgumentType.Double("z");
|
||||
|
||||
addSyntax((sender, context) -> ((Entity) sender).teleport(new Position(context.get(x), context.get(y), context.get(z))), x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -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<String> args = Arrays.asList(context.get(argument));
|
||||
try {
|
||||
manager.execute(args.remove(0), null, args);
|
||||
} catch(CommandException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}), argument);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<ChunkPopulator> 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<ChunkPopulator> getPopulators() {
|
||||
return populators;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<MinestomChunkAccess, MinestomWorld> world;
|
||||
|
||||
public MinestomBlock(net.minestom.server.instance.block.Block delegate, BlockPosition position, Either<MinestomChunkAccess, MinestomWorld> 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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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)));
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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<Long, MinestomBlockData> 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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<String, Block> 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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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"))
|
||||
|
||||
@@ -13,6 +13,7 @@ include("platforms:bukkit")
|
||||
include("platforms:fabric")
|
||||
include("platforms:region")
|
||||
include("platforms:sponge")
|
||||
include("platforms:minestom")
|
||||
|
||||
pluginManagement {
|
||||
repositories {
|
||||
|
||||
Reference in New Issue
Block a user