mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-24 09:06:39 +00:00
Merge branch 'master' into dev/1.21.11
This commit is contained in:
@@ -19,7 +19,7 @@ public class JeBlockState {
|
||||
private JeBlockState(String data) {
|
||||
// TODO: support block state with nbt (identifier[properties]{nbt}), for now we just ignore it
|
||||
int braceIndex = data.indexOf('{');
|
||||
if (braceIndex != -1) {
|
||||
if(braceIndex != -1) {
|
||||
data = data.substring(0, braceIndex);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import org.allaymc.api.block.type.BlockStateGetter;
|
||||
import org.allaymc.api.block.type.BlockTypes;
|
||||
import org.allaymc.api.item.type.ItemType;
|
||||
import org.allaymc.api.item.type.ItemTypeGetter;
|
||||
import org.allaymc.api.world.data.DimensionInfo;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -83,7 +82,7 @@ public final class Mapping {
|
||||
}
|
||||
|
||||
public static String dimensionIdBeToJe(String beDimensionId) {
|
||||
return switch (beDimensionId) {
|
||||
return switch(beDimensionId) {
|
||||
case "overworld" -> "minecraft:overworld";
|
||||
case "nether" -> "minecraft:the_nether";
|
||||
case "the_end" -> "minecraft:the_end";
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package com.dfsek.terra.allay.delegate;
|
||||
|
||||
import com.dfsek.seismic.type.vector.Vector3;
|
||||
import org.allaymc.api.blockentity.BlockEntity;
|
||||
|
||||
import com.dfsek.terra.allay.Mapping;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
|
||||
import org.allaymc.api.blockentity.BlockEntity;
|
||||
|
||||
|
||||
/**
|
||||
* @author daoge_cmd
|
||||
|
||||
@@ -22,9 +22,9 @@ public record AllayChunk(ServerWorld world, Chunk allayChunk) implements com.dfs
|
||||
@Override
|
||||
public void setBlock(int x, int y, int z, BlockState data, boolean physics) {
|
||||
var dimensionInfo = allayChunk.getDimensionInfo();
|
||||
if (x < 0 || x > 15 ||
|
||||
z < 0 || z > 15 ||
|
||||
y < dimensionInfo.minHeight() || y > dimensionInfo.maxHeight()) {
|
||||
if(x < 0 || x > 15 ||
|
||||
z < 0 || z > 15 ||
|
||||
y < dimensionInfo.minHeight() || y > dimensionInfo.maxHeight()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.dfsek.terra.allay.delegate;
|
||||
|
||||
import org.allaymc.api.block.property.type.BlockPropertyTypes;
|
||||
import org.allaymc.api.block.data.BlockTags;
|
||||
import org.allaymc.api.block.property.type.BlockPropertyTypes;
|
||||
import org.allaymc.api.block.type.BlockTypes;
|
||||
import org.allaymc.api.world.chunk.UnsafeChunk;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -27,9 +27,9 @@ public record AllayProtoChunk(UnsafeChunk allayChunk) implements ProtoChunk {
|
||||
@Override
|
||||
public void setBlock(int x, int y, int z, @NotNull BlockState blockState) {
|
||||
var dimensionInfo = allayChunk.getDimensionInfo();
|
||||
if (x < 0 || x > 15 ||
|
||||
z < 0 || z > 15 ||
|
||||
y < dimensionInfo.minHeight() || y > dimensionInfo.maxHeight()) {
|
||||
if(x < 0 || x > 15 ||
|
||||
z < 0 || z > 15 ||
|
||||
y < dimensionInfo.minHeight() || y > dimensionInfo.maxHeight()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.dfsek.terra.allay.delegate;
|
||||
|
||||
import com.dfsek.seismic.type.vector.Vector3;
|
||||
import org.allaymc.api.block.property.type.BlockPropertyTypes;
|
||||
import org.allaymc.api.block.data.BlockTags;
|
||||
import org.allaymc.api.block.property.type.BlockPropertyTypes;
|
||||
import org.allaymc.api.block.type.BlockTypes;
|
||||
import org.allaymc.api.world.generator.context.OtherChunkAccessibleContext;
|
||||
|
||||
@@ -26,6 +26,23 @@ public record AllayProtoWorld(AllayServerWorld allayServerWorld, OtherChunkAcces
|
||||
private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(
|
||||
BlockPropertyTypes.LIQUID_DEPTH.createValue(0));
|
||||
|
||||
// TODO: use method in OtherChunkAccessibleContext directly after bumped allay-api version to 0.14.0
|
||||
private static org.allaymc.api.blockentity.BlockEntity getBlockEntity(OtherChunkAccessibleContext context, int x, int y, int z) {
|
||||
var currentChunk = context.getCurrentChunk();
|
||||
var currentChunkX = currentChunk.getX();
|
||||
var currentChunkZ = currentChunk.getZ();
|
||||
var dimInfo = currentChunk.getDimensionInfo();
|
||||
|
||||
if(x >= currentChunkX * 16 && x < currentChunkX * 16 + 16 &&
|
||||
z >= currentChunkZ * 16 && z < currentChunkZ * 16 + 16 &&
|
||||
y >= dimInfo.minHeight() && y <= dimInfo.maxHeight()) {
|
||||
return currentChunk.getBlockEntity(x & 15, y, z & 15);
|
||||
} else {
|
||||
var chunk = context.getChunkSource().getChunk(x >> 4, z >> 4);
|
||||
return chunk == null ? null : chunk.getBlockEntity(x & 15, y, z & 15);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int centerChunkX() {
|
||||
return context.getCurrentChunk().getX();
|
||||
@@ -44,7 +61,7 @@ public record AllayProtoWorld(AllayServerWorld allayServerWorld, OtherChunkAcces
|
||||
@Override
|
||||
public void setBlockState(int x, int y, int z, BlockState data, boolean physics) {
|
||||
var dimensionInfo = allayServerWorld.allayDimension().getDimensionInfo();
|
||||
if (y < dimensionInfo.minHeight() || y > dimensionInfo.maxHeight()) {
|
||||
if(y < dimensionInfo.minHeight() || y > dimensionInfo.maxHeight()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -71,23 +88,6 @@ public record AllayProtoWorld(AllayServerWorld allayServerWorld, OtherChunkAcces
|
||||
return new AllayBlockEntity(getBlockEntity(context, x, y, z));
|
||||
}
|
||||
|
||||
// TODO: use method in OtherChunkAccessibleContext directly after bumped allay-api version to 0.14.0
|
||||
private static org.allaymc.api.blockentity.BlockEntity getBlockEntity(OtherChunkAccessibleContext context, int x, int y, int z) {
|
||||
var currentChunk = context.getCurrentChunk();
|
||||
var currentChunkX = currentChunk.getX();
|
||||
var currentChunkZ = currentChunk.getZ();
|
||||
var dimInfo = currentChunk.getDimensionInfo();
|
||||
|
||||
if (x >= currentChunkX * 16 && x < currentChunkX * 16 + 16 &&
|
||||
z >= currentChunkZ * 16 && z < currentChunkZ * 16 + 16 &&
|
||||
y >= dimInfo.minHeight() && y <= dimInfo.maxHeight()) {
|
||||
return currentChunk.getBlockEntity(x & 15, y, z & 15);
|
||||
} else {
|
||||
var chunk = context.getChunkSource().getChunk(x >> 4, z >> 4);
|
||||
return chunk == null ? null : chunk.getBlockEntity(x & 15, y, z & 15);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkGenerator getGenerator() {
|
||||
return allayServerWorld.getGenerator();
|
||||
|
||||
@@ -28,7 +28,7 @@ public record AllayServerWorld(AllayGeneratorWrapper allayGeneratorWrapper, Dime
|
||||
@Override
|
||||
public void setBlockState(int x, int y, int z, BlockState data, boolean physics) {
|
||||
var dimensionInfo = allayDimension.getDimensionInfo();
|
||||
if (y < dimensionInfo.minHeight() || y > dimensionInfo.maxHeight()) {
|
||||
if(y < dimensionInfo.minHeight() || y > dimensionInfo.maxHeight()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.dfsek.terra.allay.delegate;
|
||||
|
||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
|
||||
import org.allaymc.api.world.data.DimensionInfo;
|
||||
|
||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
|
||||
|
||||
/**
|
||||
* @author daoge_cmd
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
package com.dfsek.terra.allay.generator;
|
||||
|
||||
import com.dfsek.terra.allay.Mapping;
|
||||
import com.dfsek.terra.allay.delegate.AllayWorldProperties;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.allaymc.api.utils.AllayStringUtils;
|
||||
import org.allaymc.api.world.biome.BiomeType;
|
||||
@@ -14,10 +11,12 @@ import org.allaymc.api.world.generator.context.PopulateContext;
|
||||
import org.allaymc.api.world.generator.function.Noiser;
|
||||
import org.allaymc.api.world.generator.function.Populator;
|
||||
|
||||
import com.dfsek.terra.allay.Mapping;
|
||||
import com.dfsek.terra.allay.TerraAllayPlugin;
|
||||
import com.dfsek.terra.allay.delegate.AllayProtoChunk;
|
||||
import com.dfsek.terra.allay.delegate.AllayProtoWorld;
|
||||
import com.dfsek.terra.allay.delegate.AllayServerWorld;
|
||||
import com.dfsek.terra.allay.delegate.AllayWorldProperties;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||
@@ -59,7 +58,7 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
|
||||
this.worldProperties = new AllayWorldProperties(this.seed, dimension.getDimensionInfo());
|
||||
|
||||
var metaPackName = options.get(OPTION_META_PACK_NAME);
|
||||
if (metaPackName != null) {
|
||||
if(metaPackName != null) {
|
||||
setConfigPack(getConfigPackByMeta(metaPackName, dimension.getDimensionInfo()));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.allay.handle;
|
||||
|
||||
import org.allaymc.api.registry.Registries;
|
||||
import org.allaymc.api.utils.identifier.Identifier;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -12,8 +13,6 @@ import com.dfsek.terra.api.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.inventory.Item;
|
||||
import com.dfsek.terra.api.inventory.item.Enchantment;
|
||||
|
||||
import org.allaymc.api.utils.identifier.Identifier;
|
||||
|
||||
|
||||
/**
|
||||
* @author daoge_cmd
|
||||
|
||||
@@ -3,10 +3,10 @@ package com.dfsek.terra.bukkit;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.bukkit.util.VersionUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.bukkit.util.VersionUtil;
|
||||
|
||||
|
||||
public interface NMSInitializer {
|
||||
List<String> SUPPORTED_VERSIONS = List.of("v1.21.11");
|
||||
@@ -16,8 +16,9 @@ public interface NMSInitializer {
|
||||
static PlatformImpl init(TerraBukkitPlugin plugin) {
|
||||
Logger logger = LoggerFactory.getLogger(NMSInitializer.class);
|
||||
|
||||
if (!SUPPORTED_VERSIONS.contains(MINECRAFT_VERSION)) {
|
||||
logger.error("You are running your server on Minecraft version {} which is not supported by this version of Terra.", MINECRAFT_VERSION);
|
||||
if(!SUPPORTED_VERSIONS.contains(MINECRAFT_VERSION)) {
|
||||
logger.error("You are running your server on Minecraft version {} which is not supported by this version of Terra.",
|
||||
MINECRAFT_VERSION);
|
||||
|
||||
String bypassKey = "IKnowThereAreNoNMSBindingsFor" + MINECRAFT_VERSION.replace(".", "_") + "ButIWillProceedAnyway";
|
||||
if(System.getProperty(bypassKey) == null) {
|
||||
|
||||
@@ -93,7 +93,7 @@ public class TerraBukkitPlugin extends JavaPlugin {
|
||||
BukkitAdapter::adapt,
|
||||
BukkitAdapter::adapt
|
||||
))
|
||||
.executionCoordinator(ExecutionCoordinator.simpleCoordinator())
|
||||
.executionCoordinator(ExecutionCoordinator.asyncCoordinator())
|
||||
.buildOnEnable(this);
|
||||
|
||||
commandManager.brigadierManager().setNativeNumberSuggestions(false);
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
|
||||
package com.dfsek.terra.bukkit.util;
|
||||
|
||||
import com.dfsek.terra.bukkit.TerraBukkitPlugin;
|
||||
|
||||
import io.papermc.lib.PaperLib;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.dfsek.terra.bukkit.TerraBukkitPlugin;
|
||||
|
||||
import static io.papermc.lib.PaperLib.suggestPaper;
|
||||
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ public class TerraMinestomExample {
|
||||
private TerraMinestomWorld world;
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("minestom.registry.unsafe-ops", "true");
|
||||
|
||||
TerraMinestomExample example = new TerraMinestomExample();
|
||||
example.createNewInstance();
|
||||
example.attachTerra();
|
||||
|
||||
@@ -2,12 +2,6 @@ package com.dfsek.terra.minestom;
|
||||
|
||||
import com.dfsek.tectonic.api.TypeRegistry;
|
||||
import com.dfsek.tectonic.api.loader.type.TypeLoader;
|
||||
|
||||
import com.dfsek.terra.minestom.api.BiomeFactory;
|
||||
import com.dfsek.terra.minestom.biome.MinestomUserDefinedBiomeFactory;
|
||||
|
||||
import com.dfsek.terra.minestom.biome.MinestomUserDefinedBiomePool;
|
||||
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.util.RGBLike;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
@@ -32,8 +26,11 @@ import com.dfsek.terra.api.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||
import com.dfsek.terra.minestom.addon.MinestomAddon;
|
||||
import com.dfsek.terra.minestom.api.BiomeFactory;
|
||||
import com.dfsek.terra.minestom.api.TerraMinestomWorldBuilder;
|
||||
import com.dfsek.terra.minestom.biome.MinestomBiomeLoader;
|
||||
import com.dfsek.terra.minestom.biome.MinestomUserDefinedBiomeFactory;
|
||||
import com.dfsek.terra.minestom.biome.MinestomUserDefinedBiomePool;
|
||||
import com.dfsek.terra.minestom.config.BiomeAdditionsSoundTemplate;
|
||||
import com.dfsek.terra.minestom.config.BiomeMoodSoundTemplate;
|
||||
import com.dfsek.terra.minestom.config.BiomeParticleConfigTemplate;
|
||||
@@ -70,6 +67,10 @@ public final class TerraMinestomPlatform extends AbstractPlatform {
|
||||
this(new MinestomWorldHandle(), new MinestomItemHandle(), new MinestomBiomeLoader(), new MinestomUserDefinedBiomeFactory());
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(TypeRegistry registry) {
|
||||
super.register(registry);
|
||||
@@ -146,16 +147,13 @@ public final class TerraMinestomPlatform extends AbstractPlatform {
|
||||
return worldBuilder(MinecraftServer.getInstanceManager().createInstanceContainer());
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final List<BaseAddon> platformAddons = new ArrayList<>();
|
||||
private @Nullable WorldHandle worldHandle;
|
||||
private @Nullable ItemHandle itemHandle;
|
||||
private @Nullable TypeLoader<PlatformBiome> biomeTypeLoader;
|
||||
private @Nullable BiomeFactory biomeFactory;
|
||||
private final List<BaseAddon> platformAddons = new ArrayList<>();
|
||||
|
||||
public Builder worldHandle(@Nullable WorldHandle worldHandle) {
|
||||
this.worldHandle = worldHandle;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.minestom.api;
|
||||
|
||||
|
||||
import net.kyori.adventure.nbt.CompoundBinaryTag;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
|
||||
@@ -9,5 +10,22 @@ import net.minestom.server.entity.EntityType;
|
||||
* Allows adding AI to generated entities using custom entity types
|
||||
*/
|
||||
public interface EntityFactory {
|
||||
/**
|
||||
* Creates a new entity of the specified type.
|
||||
*
|
||||
* @param type the type of the entity to be created
|
||||
* @return the created entity instance
|
||||
*/
|
||||
Entity createEntity(EntityType type);
|
||||
|
||||
/**
|
||||
* Creates a new entity of the specified type with additional data.
|
||||
*
|
||||
* @param type the type of the entity to be created
|
||||
* @param data the additional data for the entity, represented as a CompoundBinaryTag
|
||||
* @return the created entity instance
|
||||
*/
|
||||
default Entity createEntity(EntityType type, CompoundBinaryTag data) {
|
||||
return createEntity(type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.dfsek.terra.minestom.api;
|
||||
|
||||
import com.dfsek.terra.minestom.biome.MinestomUserDefinedBiomePool;
|
||||
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.registry.RegistryKey;
|
||||
import net.minestom.server.world.DimensionType;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.function.Function;
|
||||
@@ -10,14 +11,11 @@ import java.util.function.Function;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.minestom.TerraMinestomPlatform;
|
||||
import com.dfsek.terra.minestom.biome.MinestomUserDefinedBiomePool;
|
||||
import com.dfsek.terra.minestom.block.DefaultBlockEntityFactory;
|
||||
import com.dfsek.terra.minestom.entity.DefaultEntityFactory;
|
||||
import com.dfsek.terra.minestom.world.TerraMinestomWorld;
|
||||
|
||||
import net.minestom.server.registry.RegistryKey;
|
||||
import net.minestom.server.world.DimensionType;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
|
||||
|
||||
public class TerraMinestomWorldBuilder {
|
||||
private final TerraMinestomPlatform platform;
|
||||
|
||||
@@ -4,9 +4,6 @@ import com.dfsek.tectonic.api.depth.DepthTracker;
|
||||
import com.dfsek.tectonic.api.exception.LoadException;
|
||||
import com.dfsek.tectonic.api.loader.ConfigLoader;
|
||||
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.registry.RegistryKey;
|
||||
import org.intellij.lang.annotations.Subst;
|
||||
@@ -14,6 +11,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.AnnotatedType;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||
|
||||
|
||||
public class MinestomBiomeLoader implements TypeLoader<PlatformBiome> {
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.dfsek.terra.minestom.block;
|
||||
|
||||
import net.kyori.adventure.nbt.CompoundBinaryTag;
|
||||
import net.kyori.adventure.nbt.TagStringIO;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -10,38 +13,84 @@ 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 org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class MinestomBlockState implements BlockState {
|
||||
private final Block block;
|
||||
|
||||
public record MinestomBlockState(Block block) implements BlockState {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MinestomBlockState.class);
|
||||
public static final MinestomBlockState AIR = new MinestomBlockState(Block.AIR);
|
||||
private static final TagStringIO tagStringIO = TagStringIO.tagStringIO();
|
||||
|
||||
public MinestomBlockState(Block block) {
|
||||
if(block == null) {
|
||||
this.block = Block.AIR;
|
||||
} else {
|
||||
this.block = block;
|
||||
}
|
||||
public MinestomBlockState {
|
||||
block = Objects.requireNonNullElse(block, Block.AIR);
|
||||
}
|
||||
|
||||
public MinestomBlockState(String data) {
|
||||
if(!data.contains("[")) {
|
||||
block = Block.fromKey(data);
|
||||
return;
|
||||
public static MinestomBlockState fromStateId(String data) {
|
||||
CompoundBinaryTag nbt = CompoundBinaryTag.empty();
|
||||
int splitIndex = data.indexOf('{');
|
||||
if(splitIndex != -1) {
|
||||
String fullId = data;
|
||||
data = data.substring(0, splitIndex);
|
||||
String dataString = fullId.substring(splitIndex);
|
||||
try {
|
||||
nbt = tagStringIO.asCompound(dataString);
|
||||
} catch(IOException exception) {
|
||||
LOGGER.warn("Invalid entity data, will be ignored: {}", dataString);
|
||||
}
|
||||
}
|
||||
|
||||
String[] split = data.split("\\[");
|
||||
String namespaceId = split[0];
|
||||
String properties = split[1].substring(0, split[1].length() - 1);
|
||||
int openBracketIndex = data.indexOf('[');
|
||||
int closeBracketIndex = data.indexOf(']');
|
||||
|
||||
if(openBracketIndex == -1 || closeBracketIndex == -1 || closeBracketIndex < openBracketIndex) {
|
||||
// no or invalid properties
|
||||
Block block = Block.fromKey(data);
|
||||
if(block != null && !nbt.isEmpty()) {
|
||||
block = block.withNbt(nbt);
|
||||
}
|
||||
return new MinestomBlockState(block);
|
||||
}
|
||||
|
||||
String namespaceId = data.substring(0, openBracketIndex);
|
||||
String propertiesContent = data.substring(openBracketIndex + 1, closeBracketIndex);
|
||||
Block block = Block.fromKey(namespaceId);
|
||||
HashMap<String, String> propertiesMap = new HashMap<>();
|
||||
|
||||
for(String property : properties.split(",")) {
|
||||
String[] kv = property.split("=");
|
||||
propertiesMap.put(kv[0].strip(), kv[1].strip());
|
||||
if (block == null) {
|
||||
LOGGER.error("Invalid block ID found during parsing: {}", namespaceId);
|
||||
return new MinestomBlockState(Block.AIR);
|
||||
}
|
||||
|
||||
assert block != null;
|
||||
this.block = block.withProperties(propertiesMap);
|
||||
HashMap<String, String> propertiesMap = new HashMap<>();
|
||||
int current = 0;
|
||||
while (current < propertiesContent.length()) {
|
||||
int nextComma = propertiesContent.indexOf(',', current);
|
||||
String property;
|
||||
|
||||
if (nextComma == -1) {
|
||||
property = propertiesContent.substring(current);
|
||||
current = propertiesContent.length();
|
||||
} else {
|
||||
property = propertiesContent.substring(current, nextComma);
|
||||
current = nextComma + 1;
|
||||
}
|
||||
|
||||
int equalsIndex = property.indexOf('=');
|
||||
|
||||
if (equalsIndex == -1) {
|
||||
LOGGER.warn("Invalid block property syntax (missing '=') in string: {}", property);
|
||||
continue;
|
||||
}
|
||||
|
||||
String key = property.substring(0, equalsIndex).strip();
|
||||
String value = property.substring(equalsIndex + 1).strip();
|
||||
propertiesMap.put(key, value);
|
||||
}
|
||||
|
||||
if(!nbt.isEmpty()) {
|
||||
block = block.withNbt(nbt);
|
||||
}
|
||||
|
||||
return new MinestomBlockState(block.withProperties(propertiesMap));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,26 +15,27 @@ import com.dfsek.terra.minestom.block.MinestomBlockState;
|
||||
public class CachedChunk implements ProtoChunk {
|
||||
private final int minHeight;
|
||||
private final int maxHeight;
|
||||
private final Block[] blocks;
|
||||
private final MinestomBlockState[] blocks;
|
||||
|
||||
public CachedChunk(int minHeight, int maxHeight) {
|
||||
this.minHeight = minHeight;
|
||||
this.maxHeight = maxHeight;
|
||||
this.blocks = new Block[16 * (maxHeight - minHeight + 1) * 16];
|
||||
Arrays.fill(blocks, Block.AIR);
|
||||
this.blocks = new MinestomBlockState[16 * (maxHeight - minHeight + 1) * 16];
|
||||
Arrays.fill(blocks, MinestomBlockState.AIR);
|
||||
}
|
||||
|
||||
public void writeRelative(UnitModifier modifier) {
|
||||
modifier.setAllRelative((x, y, z) -> blocks[getIndex(x, y + minHeight, z)]);
|
||||
modifier.setAllRelative((x, y, z) -> blocks[getIndex(x, y + minHeight, z)].block());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(int x, int y, int z, @NotNull BlockState blockState) {
|
||||
Block block = (Block) blockState.getHandle();
|
||||
MinestomBlockState minestomBlockState = (MinestomBlockState) blockState;
|
||||
Block block = minestomBlockState.block();
|
||||
if(block == null) return;
|
||||
int index = getIndex(x, y, z);
|
||||
if (index > blocks.length || index < 0) return;
|
||||
blocks[index] = block;
|
||||
if(index > blocks.length || index < 0) return;
|
||||
blocks[index] = minestomBlockState;
|
||||
}
|
||||
|
||||
private int getIndex(int x, int y, int z) {
|
||||
@@ -45,8 +46,8 @@ public class CachedChunk implements ProtoChunk {
|
||||
@Override
|
||||
public @NotNull BlockState getBlock(int x, int y, int z) {
|
||||
int index = getIndex(x, y, z);
|
||||
if (index > blocks.length || index < 0) return MinestomBlockState.AIR;
|
||||
return new MinestomBlockState(blocks[index]);
|
||||
if(index > blocks.length || index < 0) return MinestomBlockState.AIR;
|
||||
return blocks[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.github.benmanes.caffeine.cache.stats.CacheStats;
|
||||
import net.minestom.server.world.DimensionType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -15,7 +16,7 @@ import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||
|
||||
public class GeneratedChunkCache {
|
||||
private static final Logger log = LoggerFactory.getLogger(GeneratedChunkCache.class);
|
||||
private final LoadingCache<Pair<Integer, Integer>, CachedChunk> cache;
|
||||
private final LoadingCache<@NotNull Long, CachedChunk> cache;
|
||||
private final DimensionType dimensionType;
|
||||
private final ChunkGenerator generator;
|
||||
private final ServerWorld world;
|
||||
@@ -29,7 +30,7 @@ public class GeneratedChunkCache {
|
||||
this.cache = Caffeine.newBuilder()
|
||||
.maximumSize(128)
|
||||
.recordStats()
|
||||
.build((Pair<Integer, Integer> key) -> generateChunk(key.getLeft(), key.getRight()));
|
||||
.build((Long key) -> generateChunk(unpackX(key), unpackZ(key)));
|
||||
}
|
||||
|
||||
private CachedChunk generateChunk(int x, int z) {
|
||||
@@ -50,6 +51,18 @@ public class GeneratedChunkCache {
|
||||
}
|
||||
|
||||
public CachedChunk at(int x, int z) {
|
||||
return cache.get(Pair.of(x, z));
|
||||
return cache.get(pack(x, z));
|
||||
}
|
||||
|
||||
private long pack(final int x, final int z) {
|
||||
return ((long) x) << 32 | z & 0xFFFFFFFFL;
|
||||
}
|
||||
|
||||
private int unpackX(long key) {
|
||||
return (int) (key >>> 32);
|
||||
}
|
||||
|
||||
private int unpackZ(long key) {
|
||||
return (int) key;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,19 +3,10 @@ package com.dfsek.terra.minestom.config;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
import net.kyori.adventure.nbt.BinaryTagIO;
|
||||
import net.kyori.adventure.nbt.CompoundBinaryTag;
|
||||
import net.kyori.adventure.nbt.TagStringIO;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
import net.minestom.server.command.builder.arguments.minecraft.registry.ArgumentParticle;
|
||||
import net.minestom.server.particle.Particle;
|
||||
import net.minestom.server.world.biome.BiomeEffects;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class BiomeParticleConfigTemplate implements ObjectTemplate<BiomeEffects.Particle> {
|
||||
@Value("particle")
|
||||
@@ -34,8 +25,9 @@ public class BiomeParticleConfigTemplate implements ObjectTemplate<BiomeEffects.
|
||||
|
||||
String[] parts = particle.split("\\{");
|
||||
Particle parsedParticle = Particle.fromKey(parts[0]);
|
||||
if (parts.length > 1) {
|
||||
LoggerFactory.getLogger(BiomeParticleConfigTemplate.class).warn("Particle {} has additional data, particle will be ignored.", particle);
|
||||
if(parts.length > 1) {
|
||||
LoggerFactory.getLogger(BiomeParticleConfigTemplate.class).warn("Particle {} has additional data, particle will be ignored.",
|
||||
particle);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.dfsek.terra.minestom.entity;
|
||||
|
||||
import com.dfsek.terra.minestom.api.EntityFactory;
|
||||
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
|
||||
import com.dfsek.terra.minestom.api.EntityFactory;
|
||||
|
||||
|
||||
public class DefaultEntityFactory implements EntityFactory {
|
||||
@Override
|
||||
|
||||
@@ -22,7 +22,8 @@ public class MinestomEntity implements com.dfsek.terra.api.entity.Entity {
|
||||
|
||||
public static MinestomEntity spawn(double x, double y, double z, EntityType type, TerraMinestomWorld world) {
|
||||
Instance instance = world.getHandle();
|
||||
Entity entity = world.getEntityFactory().createEntity(((MinestomEntityType) type).getHandle());
|
||||
MinestomEntityType entityType = (MinestomEntityType) type;
|
||||
Entity entity = world.getEntityFactory().createEntity(entityType.getHandle(), entityType.getData());
|
||||
entity.setInstance(instance, new Pos(x, y, z));
|
||||
return new MinestomEntity(entity, world);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,38 @@
|
||||
package com.dfsek.terra.minestom.entity;
|
||||
|
||||
import net.kyori.adventure.nbt.CompoundBinaryTag;
|
||||
import net.kyori.adventure.nbt.TagStringIO;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class MinestomEntityType implements com.dfsek.terra.api.entity.EntityType {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MinestomEntityType.class);
|
||||
private static final TagStringIO tagStringIO = TagStringIO.tagStringIO();
|
||||
private final EntityType delegate;
|
||||
private final CompoundBinaryTag data;
|
||||
|
||||
public MinestomEntityType(String id) {
|
||||
int splitIndex = id.indexOf('{');
|
||||
if(splitIndex != -1) {
|
||||
String fullId = id;
|
||||
id = id.substring(0, splitIndex);
|
||||
String dataString = fullId.substring(splitIndex);
|
||||
CompoundBinaryTag data;
|
||||
try {
|
||||
data = tagStringIO.asCompound(dataString);
|
||||
} catch(IOException exception) {
|
||||
LOGGER.warn("Invalid entity data, will be ignored: {}", dataString);
|
||||
data = CompoundBinaryTag.empty();
|
||||
}
|
||||
this.data = data;
|
||||
} else {
|
||||
this.data = CompoundBinaryTag.empty();
|
||||
}
|
||||
|
||||
delegate = EntityType.fromKey(id);
|
||||
}
|
||||
|
||||
@@ -14,4 +40,8 @@ public class MinestomEntityType implements com.dfsek.terra.api.entity.EntityType
|
||||
public EntityType getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
public CompoundBinaryTag getData() {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ public class MinestomWorldHandle implements WorldHandle {
|
||||
|
||||
@Override
|
||||
public @NotNull BlockState createBlockState(@NotNull String data) {
|
||||
return new MinestomBlockState(data);
|
||||
return MinestomBlockState.fromStateId(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.dfsek.terra.api.world.chunk.Chunk;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
import com.dfsek.terra.minestom.TerraMinestomPlatform;
|
||||
import com.dfsek.terra.minestom.api.BiomeFactory;
|
||||
import com.dfsek.terra.minestom.api.BlockEntityFactory;
|
||||
import com.dfsek.terra.minestom.api.EntityFactory;
|
||||
import com.dfsek.terra.minestom.biome.MinestomUserDefinedBiomePool;
|
||||
|
||||
@@ -18,7 +18,7 @@ public final class LifecycleEntryPoint {
|
||||
logger.info("Initializing Terra {} mod...", modName);
|
||||
|
||||
FabricServerCommandManager<CommandSender> manager = new FabricServerCommandManager<>(
|
||||
ExecutionCoordinator.simpleCoordinator(),
|
||||
ExecutionCoordinator.asyncCoordinator(),
|
||||
SenderMapper.create(
|
||||
serverCommandSource -> (CommandSender) serverCommandSource,
|
||||
commandSender -> (ServerCommandSource) commandSender)
|
||||
|
||||
Reference in New Issue
Block a user