Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adapt allay update #484

Open
wants to merge 8 commits into
base: ver/6.6.0
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ object Versions {
}

object Allay {
const val api = "0114e0b290"
const val api = "0.1.2"
}
}
}
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 @@ -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
30 changes: 15 additions & 15 deletions platforms/allay/src/main/java/com/dfsek/terra/allay/Mapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,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,8 +85,8 @@ 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")) {
solonovamax marked this conversation as resolved.
Show resolved Hide resolved
if(stream == null) {
TerraAllayPlugin.INSTANCE.getPluginLogger().error("biomes mapping not found");
return false;
}
Expand All @@ -100,12 +100,12 @@ 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 +121,13 @@ 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 +141,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<>() {});
solonovamax marked this conversation as resolved.
Show resolved Hide resolved
for(Entry<String, Map<String, String>> entry : states.entrySet()) {
String identifier = entry.getKey();
Map<String, String> properties = entry.getValue();
Expand All @@ -161,7 +161,7 @@ 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")) {
if(data.containsKey("state")) {
// noinspection unchecked
convertValueType((Map<String, Object>) data.get("state")).forEach(getter::property);
}
Expand All @@ -170,8 +170,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 Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public BlockState getDefaultState() {

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public record AllayChunk(ServerWorld world, Chunk allayChunk) implements com.dfs
public void setBlock(int x, int y, int z, BlockState data, boolean physics) {
AllayBlockState allayBlockState = (AllayBlockState) data;
allayChunk.setBlockState(x, y, z, allayBlockState.allayBlockState());
boolean containsWater = allayBlockState.containsWater() || allayChunk.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER);
if (containsWater) {
if (allayBlockState.containsWater() || allayChunk.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER)) {
allayChunk.setBlockState(x, y, z, WATER, 1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public int getMaxHeight() {
public void setBlock(int x, int y, int z, @NotNull BlockState blockState) {
AllayBlockState allayBlockState = (AllayBlockState) blockState;
allayChunk.setBlockState(x, y, z, allayBlockState.allayBlockState());
boolean containsWater = allayBlockState.containsWater() || allayChunk.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER);
if (containsWater) {
if(allayBlockState.containsWater() || allayChunk.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER)) {
allayChunk.setBlockState(x, y, z, WATER, 1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ public ServerWorld getWorld() {

@Override
public void setBlockState(int x, int y, int z, BlockState data, boolean physics) {
AllayBlockState allayBlockState = (AllayBlockState)data;
boolean containsWater = allayBlockState.containsWater() || context.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER);
AllayBlockState allayBlockState = (AllayBlockState) data;
context.setBlockState(x, y, z, allayBlockState.allayBlockState());
if (containsWater) context.setBlockState(x, y, z, WATER, 1);
if(allayBlockState.containsWater() || context.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER)) {
context.setBlockState(x, y, z, WATER, 1);
}
}

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

import org.allaymc.api.block.property.type.BlockPropertyTypes;
import org.allaymc.api.block.type.BlockTypes;
import org.allaymc.api.world.Dimension;

import com.dfsek.terra.allay.Mapping;
Expand All @@ -21,12 +19,9 @@
* @author daoge_cmd
*/
public record AllayServerWorld(AllayGeneratorWrapper allayGeneratorWrapper, Dimension allayDimension) implements ServerWorld {

private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(BlockPropertyTypes.LIQUID_DEPTH.createValue(0));

@Override
public Chunk getChunkAt(int x, int z) {
return new AllayChunk(this, allayDimension.getChunkService().getChunk(x ,z));
return new AllayChunk(this, allayDimension.getChunkService().getChunk(x, z));
}

@Override
Expand Down
Loading