Compare commits

..

2 Commits

Author SHA1 Message Date
dfsek 3f3ce89b1f update readme to reflect licensing change 2021-04-02 23:58:55 -07:00
dfsek 1bf95eee36 relicense API under LGPLv3 2021-04-02 23:57:11 -07:00
32 changed files with 179 additions and 1088 deletions
+5
View File
@@ -8,6 +8,11 @@ to your specifications, with no knowledge of Java required.
* Paper+ servers (Paper, Tuinity, Purpur, etc): [SpigotMC](https://www.spigotmc.org/resources/85151/)
* Fabric: [Modrinth](https://modrinth.com/mod/terra) / [CurseForge](https://www.curseforge.com/minecraft/mc-mods/terra-world-generator)
## Licensing
Terra as a whole is licensed under the GNU General Public License, version 3.0. Terra's API is licensed under the GNU Lesser General Public
License, version 3.0, in order to allow linking to the API without GPL infection.
## Building and running Terra
To build, simply run `./gradlew build` (`gradlew.bat build` on Windows). This will produce a jar in `build/libs`
@@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
@@ -36,7 +36,7 @@ public class NoiseFunction2 implements NoiseFunction {
super(cacheSize);
}
public synchronized double get(NoiseSampler noise, double x, double z) {
public 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,6 +2,7 @@ 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;
@@ -10,6 +11,10 @@ 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,12 +21,6 @@ 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 -> {
try {
item.plant(block.getLocation());
} catch(Exception e) {
e.printStackTrace();
}
});
item.getValidSpawnsAt(chunk, (int) coords.getX(), (int) coords.getZ(), level).forEach(block -> item.plant(block.getLocation()));
}
}
@@ -9,6 +9,7 @@ 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;
@@ -93,6 +94,7 @@ public class TerraFlora implements Flora {
@Override
public boolean plant(Location location) {
WorldHandle handle = main.getWorldHandle();
boolean doRotation = testRotation.size() > 0;
int size = floraPalette.getSize();
-5
View File
@@ -168,11 +168,6 @@ 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`
-5
View File
@@ -17,11 +17,6 @@ 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 {
-44
View File
@@ -1,44 +0,0 @@
import com.dfsek.terra.configureCommon
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"
)
}
}
@@ -1,10 +0,0 @@
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();
}
}
@@ -1,47 +0,0 @@
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));
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();
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);
}
}
@@ -1,25 +0,0 @@
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();
}
}
@@ -1,193 +0,0 @@
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());
}
}
}
@@ -1,19 +0,0 @@
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);
}
}
@@ -1,31 +0,0 @@
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);
}
}
@@ -1,16 +0,0 @@
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;
}
}
@@ -1,52 +0,0 @@
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.MinestomBiomeGrid;
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.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) {
chunkGenerator3D.generateBiomes(new MinestomWorld(instance), new FastRandom(), chunkX, chunkZ, new MinestomBiomeGrid(biomes, chunkX, chunkZ));
}
@Override
public @Nullable List<ChunkPopulator> getPopulators() {
return populators;
}
}
@@ -1,16 +0,0 @@
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 net.minestom.server.world.biomes.Biome getHandle() {
return delegate;
}
}
@@ -1,52 +0,0 @@
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();
}
}
@@ -1,82 +0,0 @@
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();
}
}
@@ -1,81 +0,0 @@
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;
}
}
@@ -1,24 +0,0 @@
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)));
}
}
@@ -1,57 +0,0 @@
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();
}
}
@@ -1,17 +0,0 @@
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();
}
@@ -1,43 +0,0 @@
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;
}
}
@@ -1,109 +0,0 @@
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;
}
}
@@ -1,19 +0,0 @@
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();
}
}
@@ -1,84 +0,0 @@
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;
}
}
@@ -1,38 +0,0 @@
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;
}
}
-5
View File
@@ -14,11 +14,6 @@ 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
-5
View File
@@ -14,11 +14,6 @@ repositories {
jcenter()
}
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_1_8
}
dependencies {
"compileOnly"("org.spongepowered:spongeapi:7.2.0")
"shadedApi"(project(":common"))
-1
View File
@@ -13,7 +13,6 @@ include("platforms:bukkit")
include("platforms:fabric")
include("platforms:region")
include("platforms:sponge")
include("platforms:minestom")
pluginManagement {
repositories {