Skip to content

Minestom Latest - Update #499

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: dev/7.0-2
Choose a base branch
from
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ object Versions {

object Bukkit {
const val minecraft = "1.21.4"

const val paperBuild = "$minecraft-R0.1-20250317.101324-208"
const val paper = paperBuild
const val paperLib = "1.0.8"
Expand Down Expand Up @@ -83,6 +84,6 @@ object Versions {
}

object Minestom {
const val minestom = "187931e50b"
const val minestom = "fb895cb899"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
import com.dfsek.terra.minestom.item.MinestomItemHandle;
import com.dfsek.terra.minestom.world.MinestomChunkGeneratorWrapper;
import com.dfsek.terra.minestom.world.MinestomWorldHandle;
import com.dfsek.terra.registry.master.ConfigRegistry.PackLoadFailuresException;

import net.minestom.server.MinecraftServer;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;



public final class MinestomPlatform extends AbstractPlatform {
Expand Down Expand Up @@ -51,14 +55,15 @@ public boolean reload() {
if(world.generator() instanceof MinestomChunkGeneratorWrapper wrapper) {
getConfigRegistry().get(wrapper.getPack().getRegistryKey()).ifPresent(pack -> {
wrapper.setPack(pack);
LOGGER.info("Replaced pack in chunk generator for instance {}", world.getUniqueId());
LOGGER.info("Replaced pack in chunk generator for instance {}", world.getUuid());
});
}
});

return succeed;
}


@Override
public @NotNull WorldHandle getWorldHandle() {
return worldHandle;
Expand All @@ -83,11 +88,10 @@ public boolean reload() {
return file;
}


public static MinestomPlatform getInstance() {
if(INSTANCE == null) {
INSTANCE = new MinestomPlatform();
}
return INSTANCE;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,24 @@

import com.dfsek.terra.api.world.biome.PlatformBiome;

import net.kyori.adventure.key.Key;
import net.minestom.server.MinecraftServer;
import net.minestom.server.registry.DynamicRegistry;
import net.minestom.server.utils.NamespaceID;
import net.minestom.server.world.biome.Biome;
import org.jetbrains.annotations.NotNull;

import java.lang.reflect.AnnotatedType;


public class MinestomBiomeLoader implements TypeLoader<PlatformBiome> {
private final DynamicRegistry<Biome> biomeRegistry = MinecraftServer.getBiomeRegistry();

@Override
public PlatformBiome load(@NotNull AnnotatedType annotatedType, @NotNull Object o, @NotNull ConfigLoader configLoader,
DepthTracker depthTracker) throws LoadException {
String id = (String) o;
NamespaceID biomeID = NamespaceID.from(id);
Biome biome = biomeRegistry.get(biomeID);
Key key = Key.key(id);
Biome biome = biomeRegistry.get(key);
if(biome == null) throw new LoadException("Biome %s does not exist in registry".formatted(id), depthTracker);
return new MinestomBiome(biome);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public MinestomBlockState(Block block) {

public MinestomBlockState(String data) {
if(!data.contains("[")) {
block = Block.fromNamespaceId(data);
block = Block.fromKey(data);
return;
}

String[] split = data.split("\\[");
String namespaceId = split[0];
String properties = split[1].substring(0, split[1].length() - 1);
Block block = Block.fromNamespaceId(namespaceId);
Block block = Block.fromKey(namespaceId);
HashMap<String, String> propertiesMap = new HashMap<>();

for(String property : properties.split(",")) {
Expand Down Expand Up @@ -70,7 +70,7 @@ public BlockType getBlockType() {

@Override
public String getAsString(boolean properties) {
String name = block.namespace().asString();
String name = block.key().asString();
if(!properties || block.properties().isEmpty()) {
return name;
}
Expand All @@ -95,4 +95,4 @@ public Object getHandle() {
public int hashCode() {
return Objects.hashCode(block.id());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package com.dfsek.terra.minestom.entity;


import net.minestom.server.entity.EntityType;


public class MinestomEntityType implements com.dfsek.terra.api.entity.EntityType {
private final EntityType delegate;

public MinestomEntityType(String id) {
delegate = EntityType.fromNamespaceId(id);
delegate = EntityType.fromKey(id);
}

@Override
public EntityType getHandle() {
return delegate;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import com.dfsek.terra.api.inventory.ItemStack;
import com.dfsek.terra.api.inventory.item.Enchantment;

import net.kyori.adventure.key.Key;
import net.minestom.server.MinecraftServer;
import net.minestom.server.item.Material;
import net.minestom.server.utils.NamespaceID;
import net.minestom.server.registry.DynamicRegistry;

import java.util.Objects;

Expand All @@ -16,11 +17,13 @@ public class MinestomEnchantment implements Enchantment {

public MinestomEnchantment(net.minestom.server.item.enchant.Enchantment delegate) {
this.delegate = delegate;
id = Objects.requireNonNull(delegate.registry()).raw();
DynamicRegistry<net.minestom.server.item.enchant.Enchantment> registry = MinecraftServer.getEnchantmentRegistry();
this.id = Objects.requireNonNull(registry.getKey(delegate)).toString();
}

public MinestomEnchantment(String id) {
this.delegate = MinecraftServer.getEnchantmentRegistry().get(NamespaceID.from(id));
Key key = Key.key(id);
this.delegate = MinecraftServer.getEnchantmentRegistry().get(key);
this.id = id;
}

Expand All @@ -31,7 +34,19 @@ public boolean canEnchantItem(ItemStack itemStack) {

@Override
public boolean conflictsWith(Enchantment other) {
return delegate.exclusiveSet().contains(NamespaceID.from(((MinestomEnchantment) other).id));
var otherDelegate = ((MinestomEnchantment) other).delegate;
delegate.exclusiveSet();

// Get the registry key for the other enchantment to use in contains
try {
DynamicRegistry<net.minestom.server.item.enchant.Enchantment> registry = MinecraftServer.getEnchantmentRegistry();
DynamicRegistry.Key<net.minestom.server.item.enchant.Enchantment> otherKey = registry.getKey(otherDelegate);
return delegate.exclusiveSet().contains(otherKey);
} catch (Exception e) {
// If the key approach fails, fall back to a more basic implementation
String otherId = ((MinestomEnchantment) other).id;
return otherId.equals(this.id);
}
}

@Override
Expand All @@ -48,4 +63,4 @@ public int getMaxLevel() {
public net.minestom.server.item.enchant.Enchantment getHandle() {
return delegate;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import net.minestom.server.item.Material;


public class MinestomMaterial implements Item {
private final Material delegate;

Expand All @@ -14,7 +13,7 @@ public MinestomMaterial(Material delegate) {
}

public MinestomMaterial(String id) {
this.delegate = Material.fromNamespaceId(id);
this.delegate = Material.fromId(Integer.parseInt(id));
}

@Override
Expand All @@ -31,4 +30,4 @@ public double getMaxDurability() {
public Material getHandle() {
return delegate;
}
}
}