Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Minestom Implementation #113

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Long, Sampler> cache;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions platforms/bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,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`
Expand Down
5 changes: 5 additions & 0 deletions platforms/fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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 {
Expand Down
44 changes: 44 additions & 0 deletions platforms/minestom/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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"
)
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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);
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Loading