Skip to content

Commit

Permalink
chores: remove unrelated code reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Dec 17, 2024
1 parent 6badce6 commit 0885232
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @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 Down Expand Up @@ -81,14 +82,12 @@ public void runPossiblyUnsafeTask(@NotNull Runnable task) {
@Override
public void register(TypeRegistry registry) {
super.register(registry);
registry.registerLoader(BlockState.class, ($, o, $$, $$$) -> ALLAY_WORLD_HANDLE.createBlockState((String) o))
.registerLoader(PlatformBiome.class, ($, o, $$, depthTracker) -> parseBiome((String) o, depthTracker));
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));
}

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 @@ -45,11 +45,8 @@ 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()));
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) {
Expand Down
22 changes: 7 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 @@ -25,6 +25,7 @@
* @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 @@ -89,10 +90,7 @@ private static boolean initBiomeMapping() {
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 @@ -107,10 +105,7 @@ private static boolean initItemMapping() {
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 @@ -132,10 +127,7 @@ private static boolean initBlockStateMapping() {
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 Down Expand Up @@ -167,7 +159,8 @@ private static boolean initJeBlockDefaultProperties() {
}

private static BlockState createBeBlockState(Map<String, Object> data) {
Getter getter = BlockStateSafeGetter.name("minecraft:" + data.get("bedrock_identifier"));
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 @@ -190,7 +183,6 @@ 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 @@ -70,8 +70,6 @@ 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 @@ -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 @@ -14,6 +14,7 @@
* @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));

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @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));

@Override
Expand Down

0 comments on commit 0885232

Please sign in to comment.