Skip to content

Commit

Permalink
fix: adapt allay update
Browse files Browse the repository at this point in the history
* feat: update mapping files to latest
  • Loading branch information
IWareQ committed Dec 16, 2024
1 parent 1d3c380 commit 9b6a503
Show file tree
Hide file tree
Showing 25 changed files with 148 additions and 3,573 deletions.
14 changes: 6 additions & 8 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object Versions {
const val caffeine = "3.1.8"

const val slf4j = "2.0.16"

object Internal {
const val shadow = "8.3.3"
const val apacheText = "1.12.0"
Expand All @@ -31,7 +31,7 @@ object Versions {
const val fabricAPI = "0.106.1+${Mod.minecraft}"
const val cloud = "2.0.0-beta.9"
}
//

// object Quilt {
// const val quiltLoader = "0.20.2"
// const val fabricApi = "7.3.1+0.89.3-1.20.1"
Expand All @@ -46,9 +46,8 @@ object Versions {

const val architecuryLoom = "1.7.413"
const val architecturyPlugin = "3.4.159"

}
//

// object Forge {
// const val forge = "${Mod.minecraft}-48.0.13"
// const val burningwave = "12.63.0"
Expand All @@ -65,20 +64,19 @@ object Versions {
const val paperWeight = "1.7.2"
const val cloud = "2.0.0-beta.10"
}

//

// object Sponge {
// const val sponge = "9.0.0-SNAPSHOT"
// const val mixin = "0.8.2"
// const val minecraft = "1.17.1"
// }
//
object CLI {
const val logback = "1.5.8"
const val picocli = "4.7.6"
}

object Allay {
const val api = "0114e0b290"
const val api = "master-SNAPSHOT"
}
}
2 changes: 1 addition & 1 deletion platforms/allay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Resource files

Current mapping version: je 1.21 to be 1.21.30
Current mapping version: je 1.21.4 to be 1.21.50

- `mapping/biomes.json` obtain from GeyserMC/mappings.
- `mapping/items.json` obtain from GeyserMC/mappings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import com.dfsek.terra.api.handle.WorldHandle;
import com.dfsek.terra.api.world.biome.PlatformBiome;


/**
* @author daoge_cmd
*/
public class AllayPlatform extends AbstractPlatform {

public static final Set<AllayGeneratorWrapper> GENERATOR_WRAPPERS = new HashSet<>();

protected static final AllayWorldHandle ALLAY_WORLD_HANDLE = new AllayWorldHandle();
Expand All @@ -47,7 +47,7 @@ public boolean reload() {
var dimension = wrapper.getAllayWorldGenerator().getDimension();
TerraAllayPlugin.INSTANCE.getPluginLogger().info(
"Replaced pack in chunk generator for world {}",
dimension.getWorld().getWorldData().getName() + ":" + dimension.getDimensionInfo().dimensionId()
dimension.getWorld().getWorldData().getDisplayName() + ":" + dimension.getDimensionInfo().dimensionId()
);
});
});
Expand Down Expand Up @@ -82,12 +82,14 @@ public void runPossiblyUnsafeTask(@NotNull Runnable task) {
@Override
public void register(TypeRegistry registry) {
super.register(registry);
registry.registerLoader(BlockState.class, (type, o, loader, depthTracker) -> ALLAY_WORLD_HANDLE.createBlockState((String) o))
.registerLoader(PlatformBiome.class, (type, o, loader, depthTracker) -> parseBiome((String) o, depthTracker));
registry.registerLoader(BlockState.class, ($, o, $$, $$$) -> ALLAY_WORLD_HANDLE.createBlockState((String) o));
registry.registerLoader(PlatformBiome.class, ($, o, $$, depthTracker) -> parseBiome((String) o, depthTracker));
}

protected AllayBiome parseBiome(String id, DepthTracker depthTracker) throws LoadException {
if(!id.startsWith("minecraft:")) throw new LoadException("Invalid biome identifier " + id, depthTracker);
if(!id.startsWith("minecraft:")) {
throw new LoadException("Invalid biome identifier " + id, depthTracker);
}
return new AllayBiome(BiomeId.fromId(Mapping.biomeIdJeToBe(id)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -36,6 +28,19 @@ private JeBlockState(String data) {
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);
}
Expand All @@ -45,28 +50,24 @@ private void completeMissingProperties() {
if(properties.size() == defaultProperties.size()) {
return;
}
defaultProperties.entrySet().stream().filter(entry -> !properties.containsKey(entry.getKey())).forEach(
entry -> properties.put(entry.getKey(), entry.getValue()));
}

private JeBlockState(String identifier, TreeMap<String, String> properties) {
this.identifier = identifier;
this.properties = properties;
defaultProperties.entrySet().stream()
.filter(entry -> !properties.containsKey(entry.getKey()))
.forEach(entry -> properties.put(entry.getKey(), entry.getValue()));
}

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;
Expand Down
48 changes: 28 additions & 20 deletions platforms/allay/src/main/java/com/dfsek/terra/allay/Mapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
* @author daoge_cmd
*/
public final class Mapping {

private static final Map<String, Map<String, String>> JE_BLOCK_DEFAULT_PROPERTIES = new Object2ObjectOpenHashMap<>();
private static final Map<BlockState, JeBlockState> BLOCK_STATE_BE_TO_JE = new Object2ObjectOpenHashMap<>();
private static final Map<Integer, BlockState> BLOCK_STATE_JE_HASH_TO_BE = new Int2ObjectOpenHashMap<>();
Expand Down Expand Up @@ -73,7 +72,7 @@ public static int biomeIdJeToBe(String jeBiomeId) {

public static Map<String, String> getJeBlockDefaultProperties(String jeBlockIdentifier) {
Map<String, String> defaultProperties = JE_BLOCK_DEFAULT_PROPERTIES.get(jeBlockIdentifier);
if( defaultProperties == null) {
if(defaultProperties == null) {
TerraAllayPlugin.INSTANCE.getPluginLogger().warn("Failed to find default properties for {}", jeBlockIdentifier);
return Map.of();
}
Expand All @@ -85,12 +84,15 @@ private static void error() {
}

private static boolean initBiomeMapping() {
try (InputStream stream = Mapping.class.getClassLoader().getResourceAsStream("mapping/biomes.json")) {
if (stream == null) {
try(InputStream stream = Mapping.class.getClassLoader().getResourceAsStream("mapping/biomes.json")) {
if(stream == null) {
TerraAllayPlugin.INSTANCE.getPluginLogger().error("biomes mapping not found");
return false;
}
Set<Entry<String, Map<String, Integer>>> mappings = JSONUtils.from(stream, new TypeToken<Map<String, Map<String, Integer>>>(){}).entrySet();
Set<Entry<String, Map<String, Integer>>> mappings = JSONUtils.from(
stream,
new TypeToken<Map<String, Map<String, Integer>>>() {}
).entrySet();
mappings.forEach(mapping -> BIOME_ID_JE_TO_BE.put(mapping.getKey(), mapping.getValue().get("bedrock_id")));
} catch(IOException e) {
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Failed to load biomes mapping", e);
Expand All @@ -100,12 +102,15 @@ private static boolean initBiomeMapping() {
}

private static boolean initItemMapping() {
try (InputStream stream = Mapping.class.getClassLoader().getResourceAsStream("mapping/items.json")) {
if (stream == null) {
try(InputStream stream = Mapping.class.getClassLoader().getResourceAsStream("mapping/items.json")) {
if(stream == null) {
TerraAllayPlugin.INSTANCE.getPluginLogger().error("items mapping not found");
return false;
}
Set<Entry<String, Map<String, Object>>> mappings = JSONUtils.from(stream, new TypeToken<Map<String, Map<String, Object>>>(){}).entrySet();
Set<Entry<String, Map<String, Object>>> mappings = JSONUtils.from(
stream,
new TypeToken<Map<String, Map<String, Object>>>() {}
).entrySet();
mappings.forEach(mapping -> {
ItemType<?> item = ItemTypeSafeGetter
.name((String) mapping.getValue().get("bedrock_identifier"))
Expand All @@ -121,13 +126,16 @@ private static boolean initItemMapping() {
}

private static boolean initBlockStateMapping() {
try (InputStream stream = Mapping.class.getClassLoader().getResourceAsStream("mapping/blocks.json")) {
if (stream == null) {
try(InputStream stream = Mapping.class.getClassLoader().getResourceAsStream("mapping/blocks.json")) {
if(stream == null) {
TerraAllayPlugin.INSTANCE.getPluginLogger().error("blocks mapping not found");
return false;
}
// noinspection unchecked
List<Map<String, Map<String, Object>>> mappings = (List<Map<String, Map<String, Object>>>) JSONUtils.from(stream, new TypeToken<Map<String, Object>>(){}).get("mappings");
List<Map<String, Map<String, Object>>> mappings = (List<Map<String, Map<String, Object>>>) JSONUtils.from(
stream,
new TypeToken<Map<String, Object>>() {}
).get("mappings");
mappings.forEach(mapping -> {
JeBlockState jeState = createJeBlockState(mapping.get("java_state"));
BlockState beState = createBeBlockState(mapping.get("bedrock_state"));
Expand All @@ -141,12 +149,12 @@ private static boolean initBlockStateMapping() {
}

private static boolean initJeBlockDefaultProperties() {
try (InputStream stream = Mapping.class.getClassLoader().getResourceAsStream("je_block_default_states.json")) {
if (stream == null) {
try(InputStream stream = Mapping.class.getClassLoader().getResourceAsStream("je_block_default_states.json")) {
if(stream == null) {
TerraAllayPlugin.INSTANCE.getPluginLogger().error("je_block_default_states.json not found");
return false;
}
Map<String, Map<String, String>> states = JSONUtils.from(stream, new TypeToken<Map<String, Map<String, String>>>(){});
Map<String, Map<String, String>> states = JSONUtils.from(stream, new TypeToken<>() {});
for(Entry<String, Map<String, String>> entry : states.entrySet()) {
String identifier = entry.getKey();
Map<String, String> properties = entry.getValue();
Expand All @@ -159,9 +167,8 @@ private static boolean initJeBlockDefaultProperties() {
}

private static BlockState createBeBlockState(Map<String, Object> data) {
Getter getter = BlockStateSafeGetter
.name("minecraft:" + data.get("bedrock_identifier"));
if (data.containsKey("state")) {
Getter getter = BlockStateSafeGetter.name("minecraft:" + data.get("bedrock_identifier"));
if(data.containsKey("state")) {
// noinspection unchecked
convertValueType((Map<String, Object>) data.get("state")).forEach(getter::property);
}
Expand All @@ -170,8 +177,8 @@ private static BlockState createBeBlockState(Map<String, Object> data) {

private static Map<String, Object> convertValueType(Map<String, Object> data) {
TreeMap<String, Object> result = new TreeMap<>();
for (Entry<String, Object> entry : data.entrySet()) {
if (entry.getValue() instanceof Number number) {
for(Entry<String, Object> entry : data.entrySet()) {
if(entry.getValue() instanceof Number number) {
// Convert double to int because the number in json is double
result.put(entry.getKey(), number.intValue());
} else {
Expand All @@ -183,6 +190,7 @@ private static Map<String, Object> convertValueType(Map<String, Object> data) {

private static JeBlockState createJeBlockState(Map<String, Object> data) {
// noinspection unchecked
return JeBlockState.create((String) data.get("Name"), new TreeMap<>((Map<String, String>) data.getOrDefault("Properties", Map.of())));
return JeBlockState.create((String) data.get("Name"),
new TreeMap<>((Map<String, String>) data.getOrDefault("Properties", Map.of())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ public void onLoad() {
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);
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Reason: {}", e.getMessage());
} catch(IllegalArgumentException e) {
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Fail to create world generator with preset: {}", preset, e);
return Registries.WORLD_GENERATOR_FACTORIES.get("FLAT").apply("");
}
});
Expand Down Expand Up @@ -71,6 +70,8 @@ public void reload() {

@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()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.dfsek.terra.api.world.biome.PlatformBiome;


/**
* @author daoge_cmd
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import com.dfsek.terra.api.block.BlockType;
import com.dfsek.terra.api.block.state.properties.Property;


/**
* @author daoge_cmd
*/
public final class AllayBlockState implements com.dfsek.terra.api.block.state.BlockState {

public static final AllayBlockState AIR = new AllayBlockState(BlockTypes.AIR.getDefaultState(),
JeBlockState.fromString("minecraft:air"));
public static final AllayBlockState AIR = new AllayBlockState(
BlockTypes.AIR.getDefaultState(),
JeBlockState.fromString("minecraft:air")
);

private final BlockState allayBlockState;
private final JeBlockState jeBlockState;
Expand Down Expand Up @@ -66,9 +68,15 @@ public BlockState getHandle() {
return allayBlockState;
}

public BlockState allayBlockState() { return allayBlockState; }
public BlockState allayBlockState() {
return allayBlockState;
}

public boolean containsWater() { return containsWater; }
public boolean containsWater() {
return containsWater;
}

public JeBlockState jeBlockState() { return jeBlockState; }
public JeBlockState jeBlockState() {
return jeBlockState;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.dfsek.terra.allay.Mapping;
import com.dfsek.terra.api.block.state.BlockState;


/**
* @author daoge_cmd
*/
Expand All @@ -17,7 +18,7 @@ public BlockState getDefaultState() {

@Override
public boolean isSolid() {
return allayBlockType.getMaterial().isSolid();
return allayBlockType.getDefaultState().getBlockStateData().isSolid();
}

@Override
Expand Down
Loading

0 comments on commit 9b6a503

Please sign in to comment.