This commit is contained in:
Zoë Gidiere
2025-06-18 11:43:35 -06:00
parent 3f77b4a975
commit 46e603d681
233 changed files with 824 additions and 818 deletions

View File

@@ -21,6 +21,7 @@ import com.dfsek.terra.api.handle.ItemHandle;
import com.dfsek.terra.api.handle.WorldHandle;
import com.dfsek.terra.api.world.biome.PlatformBiome;
/**
* @author daoge_cmd
*/

View File

@@ -14,20 +14,12 @@ public class JeBlockState {
protected final TreeMap<String, String> properties;
protected int hash = Integer.MAX_VALUE;
public static JeBlockState fromString(String data) {
return new JeBlockState(data);
}
public static JeBlockState create(String identifier, TreeMap<String, String> properties) {
return new JeBlockState(identifier, properties);
}
private JeBlockState(String data) {
String[] strings = data.replace("[", ",").replace("]", ",").replace(" ", "").split(",");
this.identifier = strings[0];
this.properties = new TreeMap<>();
if (strings.length > 1) {
for (int i = 1; i < strings.length; i++) {
if(strings.length > 1) {
for(int i = 1; i < strings.length; i++) {
final String tmp = strings[i];
final int index = tmp.indexOf("=");
properties.put(tmp.substring(0, index), tmp.substring(index + 1));
@@ -36,6 +28,19 @@ public class JeBlockState {
completeMissingProperties();
}
private JeBlockState(String identifier, TreeMap<String, String> properties) {
this.identifier = identifier;
this.properties = properties;
}
public static JeBlockState fromString(String data) {
return new JeBlockState(data);
}
public static JeBlockState create(String identifier, TreeMap<String, String> properties) {
return new JeBlockState(identifier, properties);
}
public String getPropertyValue(String key) {
return properties.get(key);
}
@@ -49,24 +54,19 @@ public class JeBlockState {
entry -> properties.put(entry.getKey(), entry.getValue()));
}
private JeBlockState(String identifier, TreeMap<String, String> properties) {
this.identifier = identifier;
this.properties = properties;
}
public String toString(boolean includeProperties) {
if(!includeProperties) return identifier;
StringBuilder builder = new StringBuilder(identifier).append(";");
properties.forEach((k, v) -> builder.append(k).append("=").append(v).append(";"));
String str = builder.toString();
if (hash == Integer.MAX_VALUE) {
if(hash == Integer.MAX_VALUE) {
hash = HashUtils.fnv1a_32(str.getBytes());
}
return str;
}
public int getHash() {
if (hash == Integer.MAX_VALUE) {
if(hash == Integer.MAX_VALUE) {
hash = HashUtils.fnv1a_32(toString(true).getBytes());
}
return hash;

View File

@@ -104,7 +104,8 @@ public final class Mapping {
return false;
}
Map<String, BiomeMapping> mappings = from(stream, new TypeToken<>() {});
Map<String, BiomeMapping> mappings = from(stream, new TypeToken<>() {
});
mappings.forEach((javaId, mapping) -> JE_BIOME_ID_TO_BE.put(javaId, mapping.bedrockId()));
} catch(IOException e) {
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Failed to load biomes mapping", e);
@@ -120,7 +121,8 @@ public final class Mapping {
return false;
}
Map<String, ItemMapping> mappings = from(stream, new TypeToken<>() {});
Map<String, ItemMapping> mappings = from(stream, new TypeToken<>() {
});
mappings.forEach((javaId, mapping) -> {
ItemType<?> itemType = ItemTypeSafeGetter
.name(mapping.bedrockId())
@@ -142,7 +144,8 @@ public final class Mapping {
return false;
}
Map<String, List<BlockMapping>> root = from(stream, new TypeToken<>() {});
Map<String, List<BlockMapping>> root = from(stream, new TypeToken<>() {
});
List<BlockMapping> mappings = root.get("mappings");
mappings.forEach(mapping -> {
JeBlockState jeState = createJeBlockState(mapping.javaState());
@@ -164,7 +167,8 @@ public final class Mapping {
return false;
}
Map<String, Map<String, String>> states = from(stream, new TypeToken<>() {});
Map<String, Map<String, String>> states = from(stream, new TypeToken<>() {
});
JE_BLOCK_DEFAULT_PROPERTIES.putAll(states);
} catch(IOException e) {
throw new RuntimeException(e);

View File

@@ -70,6 +70,7 @@ public class TerraAllayPlugin extends Plugin {
@EventHandler
private void onWorldUnload(WorldUnloadEvent event) {
AllayPlatform.GENERATOR_WRAPPERS.removeIf(wrapper -> wrapper.getAllayWorldGenerator().getDimension().getWorld() == event.getWorld());
AllayPlatform.GENERATOR_WRAPPERS.removeIf(
wrapper -> wrapper.getAllayWorldGenerator().getDimension().getWorld() == event.getWorld());
}
}

View File

@@ -4,6 +4,7 @@ import org.allaymc.api.world.biome.BiomeType;
import com.dfsek.terra.api.world.biome.PlatformBiome;
/**
* @author daoge_cmd
*/

View File

@@ -7,6 +7,7 @@ import com.dfsek.terra.allay.JeBlockState;
import com.dfsek.terra.api.block.BlockType;
import com.dfsek.terra.api.block.state.properties.Property;
/**
* @author daoge_cmd
*/
@@ -68,7 +69,7 @@ public final class AllayBlockState implements com.dfsek.terra.api.block.state.Bl
public BlockState allayBlockState() { return allayBlockState; }
public boolean containsWater() { return containsWater; }
public boolean containsWater() { return containsWater; }
public JeBlockState jeBlockState() { return jeBlockState; }
}

View File

@@ -6,6 +6,7 @@ import org.allaymc.api.block.type.BlockType;
import com.dfsek.terra.allay.Mapping;
import com.dfsek.terra.api.block.state.BlockState;
/**
* @author daoge_cmd
*/

View File

@@ -10,18 +10,20 @@ import com.dfsek.terra.allay.Mapping;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.world.ServerWorld;
/**
* @author daoge_cmd
*/
public record AllayChunk(ServerWorld world, Chunk allayChunk) implements com.dfsek.terra.api.world.chunk.Chunk {
private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(BlockPropertyTypes.LIQUID_DEPTH.createValue(0));
private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(
BlockPropertyTypes.LIQUID_DEPTH.createValue(0));
@Override
public void setBlock(int x, int y, int z, BlockState data, boolean physics) {
AllayBlockState allayBlockState = (AllayBlockState) data;
allayChunk.setBlockState(x, y, z, allayBlockState.allayBlockState());
if (allayBlockState.containsWater() || allayChunk.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER)) {
if(allayBlockState.containsWater() || allayChunk.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER)) {
allayChunk.setBlockState(x, y, z, WATER, 1);
}
}

View File

@@ -6,18 +6,19 @@ import com.dfsek.terra.allay.Mapping;
import com.dfsek.terra.api.inventory.ItemStack;
import com.dfsek.terra.api.inventory.item.Enchantment;
/**
* @author daoge_cmd
*/
public record AllayEnchantment(EnchantmentType allayEnchantment) implements Enchantment {
@Override
public boolean canEnchantItem(ItemStack itemStack) {
return ((AllayItemStack)itemStack).allayItemStack().checkEnchantmentCompatibility(allayEnchantment);
return ((AllayItemStack) itemStack).allayItemStack().checkEnchantmentCompatibility(allayEnchantment);
}
@Override
public boolean conflictsWith(Enchantment other) {
return ((AllayEnchantment)other).allayEnchantment.isIncompatibleWith(allayEnchantment);
return ((AllayEnchantment) other).allayEnchantment.isIncompatibleWith(allayEnchantment);
}
@Override

View File

@@ -1,9 +1,11 @@
package com.dfsek.terra.allay.delegate;
import com.dfsek.terra.api.entity.Entity;
import com.dfsek.seismic.type.vector.Vector3;
import com.dfsek.terra.api.entity.Entity;
import com.dfsek.terra.api.world.ServerWorld;
/**
* NOTICE: Entity is not supported currently, and this is a fake implementation.
*

View File

@@ -10,6 +10,7 @@ import java.util.Map;
import com.dfsek.terra.api.inventory.item.Enchantment;
import com.dfsek.terra.api.inventory.item.ItemMeta;
/**
* @author daoge_cmd
*/
@@ -23,7 +24,7 @@ public record AllayItemMeta(ItemStack allayItemStack) implements ItemMeta {
@Override
public Map<Enchantment, Integer> getEnchantments() {
Map<Enchantment, Integer> results = new HashMap<>();
for (EnchantmentInstance allayEnchantmentInstance : allayItemStack.getEnchantments()) {
for(EnchantmentInstance allayEnchantmentInstance : allayItemStack.getEnchantments()) {
results.put(new AllayEnchantment(allayEnchantmentInstance.getType()), allayEnchantmentInstance.getLevel());
}
return results;

View File

@@ -6,10 +6,11 @@ import org.allaymc.api.item.enchantment.EnchantmentInstance;
import com.dfsek.terra.api.inventory.Item;
import com.dfsek.terra.api.inventory.item.ItemMeta;
/**
* @author daoge_cmd
*/
public record AllayItemStack(ItemStack allayItemStack) implements com.dfsek.terra.api.inventory.ItemStack{
public record AllayItemStack(ItemStack allayItemStack) implements com.dfsek.terra.api.inventory.ItemStack {
@Override
public int getAmount() {
return allayItemStack.getCount();
@@ -34,7 +35,7 @@ public record AllayItemStack(ItemStack allayItemStack) implements com.dfsek.terr
public void setItemMeta(ItemMeta meta) {
ItemStack targetItem = ((AllayItemMeta) meta).allayItemStack();
allayItemStack.removeAllEnchantments();
for (EnchantmentInstance enchantment : targetItem.getEnchantments()) {
for(EnchantmentInstance enchantment : targetItem.getEnchantments()) {
allayItemStack.addEnchantment(enchantment.getType(), enchantment.getLevel());
}
allayItemStack.setLore(targetItem.getLore());

View File

@@ -10,12 +10,14 @@ import com.dfsek.terra.allay.Mapping;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.world.chunk.generation.ProtoChunk;
/**
* @author daoge_cmd
*/
public record AllayProtoChunk(UnsafeChunk allayChunk) implements ProtoChunk {
private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(BlockPropertyTypes.LIQUID_DEPTH.createValue(0));
private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(
BlockPropertyTypes.LIQUID_DEPTH.createValue(0));
@Override
public int getMaxHeight() {

View File

@@ -1,5 +1,6 @@
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.tag.BlockTags;
import org.allaymc.api.block.type.BlockTypes;
@@ -11,18 +12,19 @@ import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.entity.Entity;
import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.seismic.type.vector.Vector3;
import com.dfsek.terra.api.world.ServerWorld;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
import com.dfsek.terra.api.world.chunk.generation.ProtoWorld;
/**
* @author daoge_cmd
*/
public record AllayProtoWorld(AllayServerWorld allayServerWorld, OtherChunkAccessibleContext context) implements ProtoWorld {
private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(BlockPropertyTypes.LIQUID_DEPTH.createValue(0));
private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(
BlockPropertyTypes.LIQUID_DEPTH.createValue(0));
@Override
public int centerChunkX() {

View File

@@ -1,5 +1,6 @@
package com.dfsek.terra.allay.delegate;
import com.dfsek.seismic.type.vector.Vector3;
import org.allaymc.api.world.Dimension;
import com.dfsek.terra.allay.Mapping;
@@ -9,12 +10,12 @@ import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.entity.Entity;
import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.seismic.type.vector.Vector3;
import com.dfsek.terra.api.world.ServerWorld;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.api.world.chunk.Chunk;
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
/**
* @author daoge_cmd
*/

View File

@@ -24,6 +24,7 @@ import com.dfsek.terra.api.world.chunk.generation.stage.GenerationStage;
import com.dfsek.terra.api.world.chunk.generation.util.GeneratorWrapper;
import com.dfsek.terra.api.world.info.WorldProperties;
/**
* @author daoge_cmd
*/
@@ -86,6 +87,18 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
.build();
}
protected static ConfigPack getConfigPack(String packName) {
Optional<ConfigPack> byId = TerraAllayPlugin.PLATFORM.getConfigRegistry().getByID(packName);
return byId.orElseGet(
() -> TerraAllayPlugin.PLATFORM.getConfigRegistry().getByID(packName.toUpperCase(Locale.ENGLISH))
.orElseThrow(() -> new IllegalArgumentException("Cant find terra config pack named " + packName))
);
}
protected static ChunkGenerator createGenerator(ConfigPack configPack) {
return configPack.getGeneratorProvider().newInstance(configPack);
}
@Override
public ChunkGenerator getHandle() {
return chunkGenerator;
@@ -112,6 +125,7 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
return this.allayWorldGenerator;
}
protected class AllayNoiser implements Noiser {
@Override
@@ -145,6 +159,7 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
}
}
protected class AllayPopulator implements Populator {
@Override
@@ -165,16 +180,4 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
return "TERRA_POPULATOR";
}
}
protected static ConfigPack getConfigPack(String packName) {
Optional<ConfigPack> byId = TerraAllayPlugin.PLATFORM.getConfigRegistry().getByID(packName);
return byId.orElseGet(
() -> TerraAllayPlugin.PLATFORM.getConfigRegistry().getByID(packName.toUpperCase(Locale.ENGLISH))
.orElseThrow(() -> new IllegalArgumentException("Cant find terra config pack named " + packName))
);
}
protected static ChunkGenerator createGenerator(ConfigPack configPack) {
return configPack.getGeneratorProvider().newInstance(configPack);
}
}

View File

@@ -13,6 +13,7 @@ import com.dfsek.terra.api.handle.ItemHandle;
import com.dfsek.terra.api.inventory.Item;
import com.dfsek.terra.api.inventory.item.Enchantment;
/**
* @author daoge_cmd
*/

View File

@@ -9,6 +9,7 @@ import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.terra.api.handle.WorldHandle;
/**
* @author daoge_cmd
*/
@@ -29,6 +30,7 @@ public class AllayWorldHandle implements WorldHandle {
public @NotNull EntityType getEntity(@NotNull String id) {
return new EntityType() {
private final Object fakeEntityType = new Object();
@Override
public Object getHandle() {
return fakeEntityType;