mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-01 07:26:09 +00:00
feat: backport latest minestom support from 7.0 branch
This commit is contained in:
parent
68d5b22ca4
commit
81eab13ce1
@ -88,6 +88,6 @@ object Versions {
|
||||
}
|
||||
|
||||
object Minestom {
|
||||
const val minestom = "187931e50b"
|
||||
const val minestom = "1_21_6-c3ccee696b"
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public final class MinestomPlatform extends AbstractPlatform {
|
||||
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());
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -7,9 +7,9 @@ import com.dfsek.tectonic.api.loader.type.TypeLoader;
|
||||
|
||||
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;
|
||||
|
||||
@ -23,7 +23,7 @@ public class MinestomBiomeLoader implements TypeLoader<PlatformBiome> {
|
||||
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);
|
||||
Key biomeID = Key.key(id);
|
||||
Biome biome = biomeRegistry.get(biomeID);
|
||||
if(biome == null) throw new LoadException("Biome %s does not exist in registry".formatted(id), depthTracker);
|
||||
return new MinestomBiome(biome);
|
||||
|
@ -4,11 +4,17 @@ import com.dfsek.terra.api.block.entity.BlockEntity;
|
||||
import com.dfsek.terra.minestom.api.BlockEntityFactory;
|
||||
|
||||
import net.minestom.server.coordinate.BlockVec;
|
||||
import net.minestom.server.instance.Instance;
|
||||
|
||||
|
||||
public class DefaultBlockEntityFactory implements BlockEntityFactory {
|
||||
private final Instance instance;
|
||||
public DefaultBlockEntityFactory(Instance instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity createBlockEntity(BlockVec position) {
|
||||
return null;
|
||||
return new MinestomBlockEntity(instance, position);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,57 @@
|
||||
package com.dfsek.terra.minestom.block;
|
||||
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
|
||||
import net.minestom.server.coordinate.BlockVec;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
|
||||
import com.dfsek.terra.api.block.entity.BlockEntity;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
|
||||
public class MinestomBlockEntity implements BlockEntity {
|
||||
private final Instance instance;
|
||||
private final BlockVec position;
|
||||
private final Vector3 positionVec;
|
||||
|
||||
public MinestomBlockEntity(Instance instance, BlockVec position) {
|
||||
this.instance = instance;
|
||||
this.position = position;
|
||||
this.positionVec = Vector3.of(position.blockX(), position.blockY(), position.blockZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(boolean applyPhysics) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3 getPosition() {
|
||||
return positionVec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return position.blockX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getY() {
|
||||
return position.blockY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZ() {
|
||||
return position.blockZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlockState() {
|
||||
return new MinestomBlockState(instance.getBlock(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getHandle() {
|
||||
return instance.getBlock(position);
|
||||
}
|
||||
}
|
@ -1,15 +1,14 @@
|
||||
package com.dfsek.terra.minestom.block;
|
||||
|
||||
import net.minestom.server.instance.block.Block;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.state.properties.Property;
|
||||
|
||||
import net.minestom.server.instance.block.Block;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class MinestomBlockState implements BlockState {
|
||||
private final Block block;
|
||||
@ -23,24 +22,10 @@ public class MinestomBlockState implements BlockState {
|
||||
}
|
||||
|
||||
public MinestomBlockState(String data) {
|
||||
if(!data.contains("[")) {
|
||||
block = Block.fromNamespaceId(data);
|
||||
return;
|
||||
block = Block.fromState(data);
|
||||
if (block == null) {
|
||||
throw new IllegalArgumentException("Invalid block state: " + data);
|
||||
}
|
||||
|
||||
String[] split = data.split("\\[");
|
||||
String namespaceId = split[0];
|
||||
String properties = split[1].substring(0, split[1].length() - 1);
|
||||
Block block = Block.fromNamespaceId(namespaceId);
|
||||
HashMap<String, String> propertiesMap = new HashMap<>();
|
||||
|
||||
for(String property : properties.split(",")) {
|
||||
String[] kv = property.split("=");
|
||||
propertiesMap.put(kv[0].strip(), kv[1].strip());
|
||||
}
|
||||
|
||||
assert block != null;
|
||||
this.block = block.withProperties(propertiesMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -70,7 +55,7 @@ public class MinestomBlockState implements BlockState {
|
||||
|
||||
@Override
|
||||
public String getAsString(boolean properties) {
|
||||
String name = block.namespace().asString();
|
||||
String name = block.key().asString();
|
||||
if(!properties || block.properties().isEmpty()) {
|
||||
return name;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ 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
|
||||
|
@ -5,47 +5,47 @@ import com.dfsek.terra.api.inventory.item.Enchantment;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.item.Material;
|
||||
import net.minestom.server.utils.NamespaceID;
|
||||
|
||||
import java.util.Objects;
|
||||
import net.minestom.server.registry.DynamicRegistry;
|
||||
import net.minestom.server.registry.RegistryKey;
|
||||
|
||||
|
||||
public class MinestomEnchantment implements Enchantment {
|
||||
private final net.minestom.server.item.enchant.Enchantment delegate;
|
||||
private final String id;
|
||||
private final net.minestom.server.item.enchant.Enchantment registryItem;
|
||||
private final RegistryKey<net.minestom.server.item.enchant.Enchantment> id;
|
||||
private static final DynamicRegistry<net.minestom.server.item.enchant.Enchantment> enchantmentRegistry =
|
||||
MinecraftServer.getEnchantmentRegistry();
|
||||
|
||||
public MinestomEnchantment(net.minestom.server.item.enchant.Enchantment delegate) {
|
||||
this.delegate = delegate;
|
||||
id = Objects.requireNonNull(delegate.registry()).raw();
|
||||
public MinestomEnchantment(RegistryKey<net.minestom.server.item.enchant.Enchantment> id) {
|
||||
this.id = id;
|
||||
this.registryItem = enchantmentRegistry.get(id);
|
||||
}
|
||||
|
||||
public MinestomEnchantment(String id) {
|
||||
this.delegate = MinecraftServer.getEnchantmentRegistry().get(NamespaceID.from(id));
|
||||
this.id = id;
|
||||
this(RegistryKey.unsafeOf(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEnchantItem(ItemStack itemStack) {
|
||||
return delegate.supportedItems().contains((Material) itemStack.getType().getHandle());
|
||||
return registryItem.supportedItems().contains((Material) itemStack.getType().getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean conflictsWith(Enchantment other) {
|
||||
return delegate.exclusiveSet().contains(NamespaceID.from(((MinestomEnchantment) other).id));
|
||||
return registryItem.exclusiveSet().contains(((MinestomEnchantment) other).id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return id;
|
||||
return id.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return delegate.maxLevel();
|
||||
return registryItem.maxLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minestom.server.item.enchant.Enchantment getHandle() {
|
||||
return delegate;
|
||||
return registryItem;
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,6 @@ public class MinestomItemHandle implements ItemHandle {
|
||||
|
||||
@Override
|
||||
public Set<Enchantment> getEnchantments() {
|
||||
return MinecraftServer.getEnchantmentRegistry().values().stream().map(MinestomEnchantment::new).collect(Collectors.toSet());
|
||||
return MinecraftServer.getEnchantmentRegistry().keys().stream().map(MinestomEnchantment::new).collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
|
@ -6,11 +6,11 @@ import com.dfsek.terra.api.inventory.item.Enchantment;
|
||||
import com.dfsek.terra.api.inventory.item.ItemMeta;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.item.ItemComponent;
|
||||
import net.minestom.server.component.DataComponents;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.component.EnchantmentList;
|
||||
import net.minestom.server.registry.DynamicRegistry;
|
||||
import net.minestom.server.registry.DynamicRegistry.Key;
|
||||
import net.minestom.server.registry.RegistryKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -47,11 +47,10 @@ public class MinestomItemStack implements com.dfsek.terra.api.inventory.ItemStac
|
||||
@Override
|
||||
public ItemMeta getItemMeta() {
|
||||
HashMap<Enchantment, Integer> enchantments = new HashMap<>();
|
||||
EnchantmentList enchantmentList = base.get(ItemComponent.ENCHANTMENTS);
|
||||
EnchantmentList enchantmentList = base.get(DataComponents.ENCHANTMENTS);
|
||||
if(enchantmentList != null) {
|
||||
enchantmentList.enchantments().forEach((enchantmentKey, integer) -> {
|
||||
enchantments.put(
|
||||
new MinestomEnchantment(Objects.requireNonNull(MinecraftServer.getEnchantmentRegistry().get(enchantmentKey))), integer);
|
||||
enchantments.put(new MinestomEnchantment(enchantmentKey), integer);
|
||||
});
|
||||
}
|
||||
return new MinestomItemMeta(enchantments);
|
||||
@ -59,7 +58,7 @@ public class MinestomItemStack implements com.dfsek.terra.api.inventory.ItemStac
|
||||
|
||||
@Override
|
||||
public void setItemMeta(ItemMeta meta) {
|
||||
HashMap<Key<net.minestom.server.item.enchant.Enchantment>, Integer> enchantments = new HashMap<>();
|
||||
HashMap<RegistryKey<net.minestom.server.item.enchant.Enchantment>, Integer> enchantments = new HashMap<>();
|
||||
DynamicRegistry<net.minestom.server.item.enchant.Enchantment> registry = MinecraftServer.getEnchantmentRegistry();
|
||||
meta.getEnchantments().forEach((key, value) -> {
|
||||
MinestomEnchantment enchantment = (MinestomEnchantment) key;
|
||||
@ -67,6 +66,6 @@ public class MinestomItemStack implements com.dfsek.terra.api.inventory.ItemStac
|
||||
});
|
||||
|
||||
EnchantmentList list = new EnchantmentList(enchantments);
|
||||
base = base.with(ItemComponent.ENCHANTMENTS, list);
|
||||
base = base.with(DataComponents.ENCHANTMENTS, list);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public class MinestomMaterial implements Item {
|
||||
}
|
||||
|
||||
public MinestomMaterial(String id) {
|
||||
this.delegate = Material.fromNamespaceId(id);
|
||||
this.delegate = Material.fromKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -22,9 +22,12 @@ public class TerraMinestomWorldBuilder {
|
||||
private ConfigPack pack;
|
||||
private long seed = new Random().nextLong();
|
||||
private EntityFactory entityFactory = new DefaultEntityFactory();
|
||||
private BlockEntityFactory blockEntityFactory = new DefaultBlockEntityFactory();
|
||||
private BlockEntityFactory blockEntityFactory;
|
||||
|
||||
private TerraMinestomWorldBuilder(Instance instance) { this.instance = instance; }
|
||||
private TerraMinestomWorldBuilder(Instance instance) {
|
||||
this.instance = instance;
|
||||
this.blockEntityFactory = new DefaultBlockEntityFactory(instance);
|
||||
}
|
||||
|
||||
public static TerraMinestomWorldBuilder from(Instance instance) {
|
||||
return new TerraMinestomWorldBuilder(instance);
|
||||
|
Loading…
x
Reference in New Issue
Block a user