Skip to content

Commit 3cf11a9

Browse files
authored
Merge pull request #534 from AllayMC/feat/meta-pack
feat: add support for meta pack in allay platform
2 parents 9f766b0 + 8fa3978 commit 3cf11a9

15 files changed

Lines changed: 250 additions & 81 deletions

buildSrc/src/main/kotlin/Versions.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ object Versions {
8686
}
8787

8888
object Allay {
89-
const val api = "0.12.0"
89+
const val api = "0.13.0"
9090
const val gson = "2.13.2"
9191

92-
const val mappings = "8002ed6"
93-
const val mappingsGenerator = "fd83f41"
92+
const val mappings = "15398c1"
93+
const val mappingsGenerator = "8fa6058"
9494

95-
const val mcmeta = "b758592"
95+
const val mcmeta = "e85a17c"
9696
}
9797

9898
object Minestom {

platforms/allay/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
## Resource files
44

5-
Current mapping version: je 1.21.7 to be 1.21.93
5+
Current mapping version: je 1.21.9 to be 1.21.111
66

77
- `mapping/biomes.json` and `mapping/items.json` are obtained from [GeyserMC/mappings](https://github.com/GeyserMC/mappings).
8-
- `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`).
8+
- `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`).
99
- `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`).

platforms/allay/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dependencies {
2828

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

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

4040
// rather jank, but whatever
41-
rename("(?:new_generator_)?([^-]+)-(.*)\\.json", "$1.json")
41+
rename("(?:generator_)?([^-]+)-(.*)\\.json", "$1.json")
4242
}
4343
from(mcmeta) {
4444
rename("data-(.*)\\.json", "je_blocks.json")

platforms/allay/src/main/java/com/dfsek/terra/allay/AllayPlatform.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public boolean reload() {
4545
getConfigRegistry().get(wrapper.getConfigPack().getRegistryKey()).ifPresent(pack -> {
4646
wrapper.setConfigPack(pack);
4747
var dimension = wrapper.getAllayWorldGenerator().getDimension();
48-
TerraAllayPlugin.INSTANCE.getPluginLogger().info(
48+
TerraAllayPlugin.instance.getPluginLogger().info(
4949
"Replaced pack in chunk generator for world {}",
5050
dimension.getWorld().getWorldData().getDisplayName() + ":" + dimension.getDimensionInfo().dimensionId()
5151
);
@@ -72,7 +72,7 @@ public boolean reload() {
7272

7373
@Override
7474
public @NotNull File getDataFolder() {
75-
return TerraAllayPlugin.INSTANCE.getPluginContainer().dataFolder().toFile();
75+
return TerraAllayPlugin.instance.getPluginContainer().dataFolder().toFile();
7676
}
7777

7878
@Override

platforms/allay/src/main/java/com/dfsek/terra/allay/JeBlockState.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,25 @@
1010
* @author daoge_cmd
1111
*/
1212
public class JeBlockState {
13+
1314
protected final String identifier;
1415
protected final TreeMap<String, String> properties;
16+
1517
protected int hash = Integer.MAX_VALUE;
1618

1719
private JeBlockState(String data) {
18-
String[] strings = data.replace("[", ",").replace("]", ",").replace(" ", "").split(",");
20+
// TODO: support block state with nbt (identifier[properties]{nbt}), for now we just ignore it
21+
int braceIndex = data.indexOf('{');
22+
if (braceIndex != -1) {
23+
data = data.substring(0, braceIndex);
24+
}
25+
26+
String[] strings = data
27+
.replace("[", ",")
28+
.replace("]", ",")
29+
.replace(" ", "")
30+
.split(",");
31+
1932
this.identifier = strings[0];
2033
this.properties = new TreeMap<>();
2134
if(strings.length > 1) {

platforms/allay/src/main/java/com/dfsek/terra/allay/Mapping.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.allaymc.api.block.type.BlockTypes;
1414
import org.allaymc.api.item.type.ItemType;
1515
import org.allaymc.api.item.type.ItemTypeGetter;
16+
import org.allaymc.api.world.data.DimensionInfo;
1617
import org.jetbrains.annotations.Nullable;
1718

1819
import java.io.IOException;
@@ -57,7 +58,7 @@ public static JeBlockState blockStateBeToJe(BlockState beBlockState) {
5758
public static BlockState blockStateJeToBe(JeBlockState jeBlockState) {
5859
BlockState result = JE_BLOCK_STATE_HASH_TO_BE.get(jeBlockState.getHash());
5960
if(result == null) {
60-
TerraAllayPlugin.INSTANCE.getPluginLogger().warn("Failed to find be block state for {}", jeBlockState);
61+
TerraAllayPlugin.instance.getPluginLogger().warn("Failed to find be block state for {}", jeBlockState);
6162
return BE_AIR_STATE;
6263
}
6364
return result;
@@ -81,10 +82,19 @@ public static int biomeIdJeToBe(String jeBiomeId) {
8182
return JE_BIOME_ID_TO_BE.get(jeBiomeId);
8283
}
8384

85+
public static String dimensionIdBeToJe(String beDimensionId) {
86+
return switch (beDimensionId) {
87+
case "overworld" -> "minecraft:overworld";
88+
case "nether" -> "minecraft:the_nether";
89+
case "the_end" -> "minecraft:the_end";
90+
default -> beDimensionId;
91+
};
92+
}
93+
8494
public static Map<String, String> getJeBlockDefaultProperties(String jeBlockIdentifier) {
8595
var defaultProperties = JE_BLOCK_DEFAULT_PROPERTIES.get(jeBlockIdentifier);
8696
if(defaultProperties == null) {
87-
TerraAllayPlugin.INSTANCE.getPluginLogger().warn("Failed to find default properties for {}", jeBlockIdentifier);
97+
TerraAllayPlugin.instance.getPluginLogger().warn("Failed to find default properties for {}", jeBlockIdentifier);
8898
return Map.of();
8999
}
90100

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

105115
Map<String, BiomeMapping> mappings = from(stream, new TypeToken<>() {
106116
});
107117
mappings.forEach((javaId, mapping) -> JE_BIOME_ID_TO_BE.put(javaId, mapping.bedrockId()));
108118
} catch(IOException e) {
109-
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Failed to load biomes mapping", e);
119+
TerraAllayPlugin.instance.getPluginLogger().error("Failed to load biomes mapping", e);
110120
return false;
111121
}
112122
return true;
@@ -115,7 +125,7 @@ private static boolean initBiomeMapping() {
115125
private static boolean initItemMapping() {
116126
try(InputStream stream = Mapping.class.getClassLoader().getResourceAsStream("mapping/items.json")) {
117127
if(stream == null) {
118-
TerraAllayPlugin.INSTANCE.getPluginLogger().error("items mapping not found");
128+
TerraAllayPlugin.instance.getPluginLogger().error("items mapping not found");
119129
return false;
120130
}
121131

@@ -129,7 +139,7 @@ private static boolean initItemMapping() {
129139
JE_ITEM_ID_TO_BE.put(javaId, itemType);
130140
});
131141
} catch(IOException e) {
132-
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Failed to load items mapping", e);
142+
TerraAllayPlugin.instance.getPluginLogger().error("Failed to load items mapping", e);
133143
return false;
134144
}
135145
return true;
@@ -138,7 +148,7 @@ private static boolean initItemMapping() {
138148
private static boolean initBlockStateMapping() {
139149
try(InputStream stream = Mapping.class.getClassLoader().getResourceAsStream("mapping/blocks.json")) {
140150
if(stream == null) {
141-
TerraAllayPlugin.INSTANCE.getPluginLogger().error("blocks mapping not found");
151+
TerraAllayPlugin.instance.getPluginLogger().error("blocks mapping not found");
142152
return false;
143153
}
144154

@@ -152,7 +162,7 @@ private static boolean initBlockStateMapping() {
152162
JE_BLOCK_STATE_HASH_TO_BE.put(jeState.getHash(), beState);
153163
});
154164
} catch(IOException e) {
155-
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Failed to load blocks mapping", e);
165+
TerraAllayPlugin.instance.getPluginLogger().error("Failed to load blocks mapping", e);
156166
return false;
157167
}
158168
return true;
@@ -162,7 +172,7 @@ private static boolean initBlockStateMapping() {
162172
private static boolean initJeBlockDefaultProperties() {
163173
try(InputStream stream = Mapping.class.getClassLoader().getResourceAsStream("je_blocks.json")) {
164174
if(stream == null) {
165-
TerraAllayPlugin.INSTANCE.getPluginLogger().error("je_block_default_states.json not found");
175+
TerraAllayPlugin.instance.getPluginLogger().error("je_block_default_states.json not found");
166176
return false;
167177
}
168178

platforms/allay/src/main/java/com/dfsek/terra/allay/TerraAllayPlugin.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,38 @@
1515
*/
1616
public class TerraAllayPlugin extends Plugin {
1717

18-
public static TerraAllayPlugin INSTANCE;
19-
public static AllayPlatform PLATFORM;
18+
public static TerraAllayPlugin instance;
19+
public static AllayPlatform platform;
2020

2121
{
22-
INSTANCE = this;
22+
TerraAllayPlugin.instance = this;
2323
}
2424

2525
@Override
2626
public void onLoad() {
27-
pluginLogger.info("Starting Terra...");
27+
this.pluginLogger.info("Starting Terra...");
2828

29-
pluginLogger.info("Loading mapping...");
29+
this.pluginLogger.info("Loading mapping...");
3030
Mapping.init();
3131

32-
pluginLogger.info("Initializing allay platform...");
33-
PLATFORM = new AllayPlatform();
34-
PLATFORM.getEventManager().callEvent(new PlatformInitializationEvent());
32+
this.pluginLogger.info("Initializing allay platform...");
33+
TerraAllayPlugin.platform = new AllayPlatform();
34+
TerraAllayPlugin.platform.getEventManager().callEvent(new PlatformInitializationEvent());
3535
// TODO: adapt command manager
3636

37-
pluginLogger.info("Registering generator...");
37+
this.pluginLogger.info("Registering generator...");
3838
Registries.WORLD_GENERATOR_FACTORIES.register("TERRA", preset -> {
3939
try {
4040
AllayGeneratorWrapper wrapper = new AllayGeneratorWrapper(preset);
4141
AllayPlatform.GENERATOR_WRAPPERS.add(wrapper);
4242
return wrapper.getAllayWorldGenerator();
4343
} catch(IllegalArgumentException e) {
44-
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Fail to create world generator with preset: {}", preset, e);
44+
TerraAllayPlugin.instance.getPluginLogger().error("Fail to create world generator with preset: {}", preset, e);
4545
return Registries.WORLD_GENERATOR_FACTORIES.get("FLAT").apply("");
4646
}
4747
});
4848

49-
pluginLogger.info("Terra started");
49+
this.pluginLogger.info("Terra started");
5050
}
5151

5252
@Override
@@ -61,10 +61,10 @@ public boolean isReloadable() {
6161

6262
@Override
6363
public void reload() {
64-
if(PLATFORM.reload()) {
65-
pluginLogger.info("Terra reloaded successfully.");
64+
if(TerraAllayPlugin.platform.reload()) {
65+
this.pluginLogger.info("Terra reloaded successfully.");
6666
} else {
67-
pluginLogger.error("Terra failed to reload.");
67+
this.pluginLogger.error("Terra failed to reload.");
6868
}
6969
}
7070

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.dfsek.terra.allay.delegate;
2+
3+
import com.dfsek.seismic.type.vector.Vector3;
4+
5+
import com.dfsek.terra.allay.Mapping;
6+
import com.dfsek.terra.api.block.state.BlockState;
7+
8+
import org.allaymc.api.blockentity.BlockEntity;
9+
10+
11+
/**
12+
* @author daoge_cmd
13+
*/
14+
public record AllayBlockEntity(BlockEntity allayBlockEntity) implements com.dfsek.terra.api.block.entity.BlockEntity {
15+
16+
@Override
17+
public boolean update(boolean applyPhysics) {
18+
return false;
19+
}
20+
21+
@Override
22+
public Vector3 getPosition() {
23+
var pos = this.allayBlockEntity.getPosition();
24+
return Vector3.of(pos.x(), pos.y(), pos.z());
25+
}
26+
27+
@Override
28+
public int getX() {
29+
return this.allayBlockEntity.getPosition().x();
30+
}
31+
32+
@Override
33+
public int getY() {
34+
return this.allayBlockEntity.getPosition().y();
35+
}
36+
37+
@Override
38+
public int getZ() {
39+
return this.allayBlockEntity.getPosition().z();
40+
}
41+
42+
@Override
43+
public BlockState getBlockState() {
44+
var allayBlockState = this.allayBlockEntity.getBlockState();
45+
return new AllayBlockState(allayBlockState, Mapping.blockStateBeToJe(this.allayBlockEntity.getBlockState()));
46+
}
47+
48+
@Override
49+
public Object getHandle() {
50+
return this.allayBlockEntity;
51+
}
52+
}

platforms/allay/src/main/java/com/dfsek/terra/allay/delegate/AllayChunk.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ public record AllayChunk(ServerWorld world, Chunk allayChunk) implements com.dfs
2121

2222
@Override
2323
public void setBlock(int x, int y, int z, BlockState data, boolean physics) {
24+
var dimensionInfo = allayChunk.getDimensionInfo();
25+
if (x < 0 || x > 15 ||
26+
z < 0 || z > 15 ||
27+
y < dimensionInfo.minHeight() || y > dimensionInfo.maxHeight()) {
28+
return;
29+
}
30+
2431
AllayBlockState allayBlockState = (AllayBlockState) data;
2532
allayChunk.setBlockState(x, y, z, allayBlockState.allayBlockState());
2633
if(allayBlockState.containsWater() || allayChunk.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER)) {

platforms/allay/src/main/java/com/dfsek/terra/allay/delegate/AllayFakeEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
/**
10-
* NOTICE: Entity is not supported currently, and this is a fake implementation.
10+
* TODO: Entity is not supported currently, and this is a fake implementation.
1111
*
1212
* @author daoge_cmd
1313
*/

0 commit comments

Comments
 (0)