Skip to content
Merged
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
8 changes: 4 additions & 4 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ object Versions {
}

object Allay {
const val api = "0.12.0"
const val api = "0.13.0"
const val gson = "2.13.2"

const val mappings = "8002ed6"
const val mappingsGenerator = "fd83f41"
const val mappings = "15398c1"
const val mappingsGenerator = "8fa6058"

const val mcmeta = "b758592"
const val mcmeta = "e85a17c"
}

object Minestom {
Expand Down
4 changes: 2 additions & 2 deletions platforms/allay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

## Resource files

Current mapping version: je 1.21.7 to be 1.21.93
Current mapping version: je 1.21.9 to be 1.21.111

- `mapping/biomes.json` and `mapping/items.json` are obtained from [GeyserMC/mappings](https://github.com/GeyserMC/mappings).
- `mapping/blocks.json` is obtained from [GeyserMC/mappings-generator](https://github.com/GeyserMC/mappings-generator) (path: `https://github.com/GeyserMC/mappings-generator/blob/master/new_generator_blocks.json`).
- `mapping/blocks.json` is obtained from [GeyserMC/mappings-generator](https://github.com/GeyserMC/mappings-generator) (path: `https://github.com/GeyserMC/mappings-generator/blob/master/generator_blocks.json`).
- `je_blocks.json` is obtained from [misode/mcmeta](https://github.com/misode/mcmeta) (path: `https://github.com/misode/mcmeta/blob/<version>-summary/blocks/data.json`).
4 changes: 2 additions & 2 deletions platforms/allay/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies {

geyserMappings("GeyserMC.mappings", "items", Versions.Allay.mappings, ext = "json")
geyserMappings("GeyserMC.mappings", "biomes", Versions.Allay.mappings, ext = "json")
geyserMappings("GeyserMC.mappings-generator", "new_generator_blocks", Versions.Allay.mappingsGenerator, ext = "json")
geyserMappings("GeyserMC.mappings-generator", "generator_blocks", Versions.Allay.mappingsGenerator, ext = "json")

mcmeta("misode.mcmeta", "blocks/data", Versions.Allay.mcmeta, ext = "json")
}
Expand All @@ -38,7 +38,7 @@ tasks.processResources {
into("mapping")

// rather jank, but whatever
rename("(?:new_generator_)?([^-]+)-(.*)\\.json", "$1.json")
rename("(?:generator_)?([^-]+)-(.*)\\.json", "$1.json")
}
from(mcmeta) {
rename("data-(.*)\\.json", "je_blocks.json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public boolean reload() {
getConfigRegistry().get(wrapper.getConfigPack().getRegistryKey()).ifPresent(pack -> {
wrapper.setConfigPack(pack);
var dimension = wrapper.getAllayWorldGenerator().getDimension();
TerraAllayPlugin.INSTANCE.getPluginLogger().info(
TerraAllayPlugin.instance.getPluginLogger().info(
"Replaced pack in chunk generator for world {}",
dimension.getWorld().getWorldData().getDisplayName() + ":" + dimension.getDimensionInfo().dimensionId()
);
Expand All @@ -72,7 +72,7 @@ public boolean reload() {

@Override
public @NotNull File getDataFolder() {
return TerraAllayPlugin.INSTANCE.getPluginContainer().dataFolder().toFile();
return TerraAllayPlugin.instance.getPluginContainer().dataFolder().toFile();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,25 @@
* @author daoge_cmd
*/
public class JeBlockState {

protected final String identifier;
protected final TreeMap<String, String> properties;

protected int hash = Integer.MAX_VALUE;

private JeBlockState(String data) {
String[] strings = data.replace("[", ",").replace("]", ",").replace(" ", "").split(",");
// TODO: support block state with nbt (identifier[properties]{nbt}), for now we just ignore it
int braceIndex = data.indexOf('{');
if (braceIndex != -1) {
data = data.substring(0, braceIndex);
}

String[] strings = data
.replace("[", ",")
.replace("]", ",")
.replace(" ", "")
.split(",");

this.identifier = strings[0];
this.properties = new TreeMap<>();
if(strings.length > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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;
Expand Down Expand Up @@ -57,7 +58,7 @@ public static JeBlockState blockStateBeToJe(BlockState beBlockState) {
public static BlockState blockStateJeToBe(JeBlockState jeBlockState) {
BlockState result = JE_BLOCK_STATE_HASH_TO_BE.get(jeBlockState.getHash());
if(result == null) {
TerraAllayPlugin.INSTANCE.getPluginLogger().warn("Failed to find be block state for {}", jeBlockState);
TerraAllayPlugin.instance.getPluginLogger().warn("Failed to find be block state for {}", jeBlockState);
return BE_AIR_STATE;
}
return result;
Expand All @@ -81,10 +82,19 @@ public static int biomeIdJeToBe(String jeBiomeId) {
return JE_BIOME_ID_TO_BE.get(jeBiomeId);
}

public static String dimensionIdBeToJe(String beDimensionId) {
return switch (beDimensionId) {
case "overworld" -> "minecraft:overworld";
case "nether" -> "minecraft:the_nether";
case "the_end" -> "minecraft:the_end";
default -> beDimensionId;
};
}

public static Map<String, String> getJeBlockDefaultProperties(String jeBlockIdentifier) {
var defaultProperties = JE_BLOCK_DEFAULT_PROPERTIES.get(jeBlockIdentifier);
if(defaultProperties == null) {
TerraAllayPlugin.INSTANCE.getPluginLogger().warn("Failed to find default properties for {}", jeBlockIdentifier);
TerraAllayPlugin.instance.getPluginLogger().warn("Failed to find default properties for {}", jeBlockIdentifier);
return Map.of();
}

Expand All @@ -98,15 +108,15 @@ private static void error() {
private static boolean initBiomeMapping() {
try(InputStream stream = Mapping.class.getClassLoader().getResourceAsStream("mapping/biomes.json")) {
if(stream == null) {
TerraAllayPlugin.INSTANCE.getPluginLogger().error("biomes mapping not found");
TerraAllayPlugin.instance.getPluginLogger().error("biomes mapping not found");
return false;
}

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);
TerraAllayPlugin.instance.getPluginLogger().error("Failed to load biomes mapping", e);
return false;
}
return true;
Expand All @@ -115,7 +125,7 @@ private static boolean initBiomeMapping() {
private static boolean initItemMapping() {
try(InputStream stream = Mapping.class.getClassLoader().getResourceAsStream("mapping/items.json")) {
if(stream == null) {
TerraAllayPlugin.INSTANCE.getPluginLogger().error("items mapping not found");
TerraAllayPlugin.instance.getPluginLogger().error("items mapping not found");
return false;
}

Expand All @@ -129,7 +139,7 @@ private static boolean initItemMapping() {
JE_ITEM_ID_TO_BE.put(javaId, itemType);
});
} catch(IOException e) {
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Failed to load items mapping", e);
TerraAllayPlugin.instance.getPluginLogger().error("Failed to load items mapping", e);
return false;
}
return true;
Expand All @@ -138,7 +148,7 @@ private static boolean initItemMapping() {
private static boolean initBlockStateMapping() {
try(InputStream stream = Mapping.class.getClassLoader().getResourceAsStream("mapping/blocks.json")) {
if(stream == null) {
TerraAllayPlugin.INSTANCE.getPluginLogger().error("blocks mapping not found");
TerraAllayPlugin.instance.getPluginLogger().error("blocks mapping not found");
return false;
}

Expand All @@ -152,7 +162,7 @@ private static boolean initBlockStateMapping() {
JE_BLOCK_STATE_HASH_TO_BE.put(jeState.getHash(), beState);
});
} catch(IOException e) {
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Failed to load blocks mapping", e);
TerraAllayPlugin.instance.getPluginLogger().error("Failed to load blocks mapping", e);
return false;
}
return true;
Expand All @@ -162,7 +172,7 @@ private static boolean initBlockStateMapping() {
private static boolean initJeBlockDefaultProperties() {
try(InputStream stream = Mapping.class.getClassLoader().getResourceAsStream("je_blocks.json")) {
if(stream == null) {
TerraAllayPlugin.INSTANCE.getPluginLogger().error("je_block_default_states.json not found");
TerraAllayPlugin.instance.getPluginLogger().error("je_block_default_states.json not found");
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,38 @@
*/
public class TerraAllayPlugin extends Plugin {

public static TerraAllayPlugin INSTANCE;
public static AllayPlatform PLATFORM;
public static TerraAllayPlugin instance;
public static AllayPlatform platform;

{
INSTANCE = this;
TerraAllayPlugin.instance = this;
}

@Override
public void onLoad() {
pluginLogger.info("Starting Terra...");
this.pluginLogger.info("Starting Terra...");

pluginLogger.info("Loading mapping...");
this.pluginLogger.info("Loading mapping...");
Mapping.init();

pluginLogger.info("Initializing allay platform...");
PLATFORM = new AllayPlatform();
PLATFORM.getEventManager().callEvent(new PlatformInitializationEvent());
this.pluginLogger.info("Initializing allay platform...");
TerraAllayPlugin.platform = new AllayPlatform();
TerraAllayPlugin.platform.getEventManager().callEvent(new PlatformInitializationEvent());
// TODO: adapt command manager

pluginLogger.info("Registering generator...");
this.pluginLogger.info("Registering generator...");
Registries.WORLD_GENERATOR_FACTORIES.register("TERRA", preset -> {
try {
AllayGeneratorWrapper wrapper = new AllayGeneratorWrapper(preset);
AllayPlatform.GENERATOR_WRAPPERS.add(wrapper);
return wrapper.getAllayWorldGenerator();
} catch(IllegalArgumentException e) {
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Fail to create world generator with preset: {}", preset, e);
TerraAllayPlugin.instance.getPluginLogger().error("Fail to create world generator with preset: {}", preset, e);
return Registries.WORLD_GENERATOR_FACTORIES.get("FLAT").apply("");
}
});

pluginLogger.info("Terra started");
this.pluginLogger.info("Terra started");
}

@Override
Expand All @@ -61,10 +61,10 @@ public boolean isReloadable() {

@Override
public void reload() {
if(PLATFORM.reload()) {
pluginLogger.info("Terra reloaded successfully.");
if(TerraAllayPlugin.platform.reload()) {
this.pluginLogger.info("Terra reloaded successfully.");
} else {
pluginLogger.error("Terra failed to reload.");
this.pluginLogger.error("Terra failed to reload.");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.dfsek.terra.allay.delegate;

import com.dfsek.seismic.type.vector.Vector3;

import com.dfsek.terra.allay.Mapping;
import com.dfsek.terra.api.block.state.BlockState;

import org.allaymc.api.blockentity.BlockEntity;


/**
* @author daoge_cmd
*/
public record AllayBlockEntity(BlockEntity allayBlockEntity) implements com.dfsek.terra.api.block.entity.BlockEntity {

@Override
public boolean update(boolean applyPhysics) {
return false;
}

@Override
public Vector3 getPosition() {
var pos = this.allayBlockEntity.getPosition();
return Vector3.of(pos.x(), pos.y(), pos.z());
}

@Override
public int getX() {
return this.allayBlockEntity.getPosition().x();
}

@Override
public int getY() {
return this.allayBlockEntity.getPosition().y();
}

@Override
public int getZ() {
return this.allayBlockEntity.getPosition().z();
}

@Override
public BlockState getBlockState() {
var allayBlockState = this.allayBlockEntity.getBlockState();
return new AllayBlockState(allayBlockState, Mapping.blockStateBeToJe(this.allayBlockEntity.getBlockState()));
}

@Override
public Object getHandle() {
return this.allayBlockEntity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ 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()) {
return;
}

AllayBlockState allayBlockState = (AllayBlockState) data;
allayChunk.setBlockState(x, y, z, allayBlockState.allayBlockState());
if(allayBlockState.containsWater() || allayChunk.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


/**
* NOTICE: Entity is not supported currently, and this is a fake implementation.
* TODO: Entity is not supported currently, and this is a fake implementation.
*
* @author daoge_cmd
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ public int getMaxHeight() {

@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()) {
return;
}

AllayBlockState allayBlockState = (AllayBlockState) blockState;
allayChunk.setBlockState(x, y, z, allayBlockState.allayBlockState());
if(allayBlockState.containsWater() || allayChunk.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public ServerWorld getWorld() {

@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()) {
return;
}

AllayBlockState allayBlockState = (AllayBlockState) data;
context.setBlockState(x, y, z, allayBlockState.allayBlockState());
if(allayBlockState.containsWater() || context.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER)) {
Expand All @@ -63,7 +68,24 @@ public Entity spawnEntity(double x, double y, double z, EntityType entityType) {

@Override
public BlockEntity getBlockEntity(int x, int y, int z) {
return null;
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
Expand Down
Loading
Loading