revert: revert code format related changes

This commit is contained in:
daoge_cmd
2024-12-17 12:43:46 +08:00
parent 4222eef531
commit 92a5134458
16 changed files with 62 additions and 84 deletions
@@ -21,7 +21,6 @@ import com.dfsek.terra.api.handle.ItemHandle;
import com.dfsek.terra.api.handle.WorldHandle; import com.dfsek.terra.api.handle.WorldHandle;
import com.dfsek.terra.api.world.biome.PlatformBiome; import com.dfsek.terra.api.world.biome.PlatformBiome;
/** /**
* @author daoge_cmd * @author daoge_cmd
*/ */
@@ -82,8 +81,8 @@ public class AllayPlatform extends AbstractPlatform {
@Override @Override
public void register(TypeRegistry registry) { public void register(TypeRegistry registry) {
super.register(registry); super.register(registry);
registry.registerLoader(BlockState.class, ($, o, $$, $$$) -> ALLAY_WORLD_HANDLE.createBlockState((String) o)); registry.registerLoader(BlockState.class, ($, o, $$, $$$) -> ALLAY_WORLD_HANDLE.createBlockState((String) o))
registry.registerLoader(PlatformBiome.class, ($, o, $$, depthTracker) -> parseBiome((String) o, depthTracker)); .registerLoader(PlatformBiome.class, ($, o, $$, depthTracker) -> parseBiome((String) o, depthTracker));
} }
protected AllayBiome parseBiome(String id, DepthTracker depthTracker) throws LoadException { protected AllayBiome parseBiome(String id, DepthTracker depthTracker) throws LoadException {
@@ -14,6 +14,14 @@ public class JeBlockState {
protected final TreeMap<String, String> properties; protected final TreeMap<String, String> properties;
protected int hash = Integer.MAX_VALUE; 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) { private JeBlockState(String data) {
String[] strings = data.replace("[", ",").replace("]", ",").replace(" ", "").split(","); String[] strings = data.replace("[", ",").replace("]", ",").replace(" ", "").split(",");
this.identifier = strings[0]; this.identifier = strings[0];
@@ -28,19 +36,6 @@ public class JeBlockState {
completeMissingProperties(); 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) { public String getPropertyValue(String key) {
return properties.get(key); return properties.get(key);
} }
@@ -50,11 +45,18 @@ public class JeBlockState {
if(properties.size() == defaultProperties.size()) { if(properties.size() == defaultProperties.size()) {
return; return;
} }
defaultProperties.entrySet().stream() defaultProperties
.entrySet()
.stream()
.filter(entry -> !properties.containsKey(entry.getKey())) .filter(entry -> !properties.containsKey(entry.getKey()))
.forEach(entry -> properties.put(entry.getKey(), entry.getValue())); .forEach(entry -> properties.put(entry.getKey(), entry.getValue()));
} }
private JeBlockState(String identifier, TreeMap<String, String> properties) {
this.identifier = identifier;
this.properties = properties;
}
public String toString(boolean includeProperties) { public String toString(boolean includeProperties) {
if(!includeProperties) return identifier; if(!includeProperties) return identifier;
StringBuilder builder = new StringBuilder(identifier).append(";"); StringBuilder builder = new StringBuilder(identifier).append(";");
@@ -4,7 +4,6 @@ import org.allaymc.api.world.biome.BiomeType;
import com.dfsek.terra.api.world.biome.PlatformBiome; import com.dfsek.terra.api.world.biome.PlatformBiome;
/** /**
* @author daoge_cmd * @author daoge_cmd
*/ */
@@ -7,15 +7,13 @@ import com.dfsek.terra.allay.JeBlockState;
import com.dfsek.terra.api.block.BlockType; import com.dfsek.terra.api.block.BlockType;
import com.dfsek.terra.api.block.state.properties.Property; import com.dfsek.terra.api.block.state.properties.Property;
/** /**
* @author daoge_cmd * @author daoge_cmd
*/ */
public final class AllayBlockState implements com.dfsek.terra.api.block.state.BlockState { public final class AllayBlockState implements com.dfsek.terra.api.block.state.BlockState {
public static final AllayBlockState AIR = new AllayBlockState(
BlockTypes.AIR.getDefaultState(), public static final AllayBlockState AIR = new AllayBlockState(BlockTypes.AIR.getDefaultState(),
JeBlockState.fromString("minecraft:air") JeBlockState.fromString("minecraft:air"));
);
private final BlockState allayBlockState; private final BlockState allayBlockState;
private final JeBlockState jeBlockState; private final JeBlockState jeBlockState;
@@ -68,15 +66,9 @@ public final class AllayBlockState implements com.dfsek.terra.api.block.state.Bl
return allayBlockState; return allayBlockState;
} }
public BlockState allayBlockState() { public BlockState allayBlockState() { return allayBlockState; }
return allayBlockState;
}
public boolean containsWater() { public boolean containsWater() { return containsWater; }
return containsWater;
}
public JeBlockState jeBlockState() { public JeBlockState jeBlockState() { return jeBlockState; }
return jeBlockState;
}
} }
@@ -6,7 +6,6 @@ import org.allaymc.api.block.type.BlockType;
import com.dfsek.terra.allay.Mapping; import com.dfsek.terra.allay.Mapping;
import com.dfsek.terra.api.block.state.BlockState; import com.dfsek.terra.api.block.state.BlockState;
/** /**
* @author daoge_cmd * @author daoge_cmd
*/ */
@@ -10,20 +10,19 @@ import com.dfsek.terra.allay.Mapping;
import com.dfsek.terra.api.block.state.BlockState; import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.world.ServerWorld; import com.dfsek.terra.api.world.ServerWorld;
/** /**
* @author daoge_cmd * @author daoge_cmd
*/ */
public record AllayChunk(ServerWorld world, Chunk allayChunk) implements com.dfsek.terra.api.world.chunk.Chunk { public record AllayChunk(ServerWorld world, Chunk allayChunk) implements com.dfsek.terra.api.world.chunk.Chunk {
private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(
BlockPropertyTypes.LIQUID_DEPTH.createValue(0) private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(BlockPropertyTypes.LIQUID_DEPTH.createValue(0));
);
@Override @Override
public void setBlock(int x, int y, int z, BlockState data, boolean physics) { public void setBlock(int x, int y, int z, BlockState data, boolean physics) {
AllayBlockState allayBlockState = (AllayBlockState) data; AllayBlockState allayBlockState = (AllayBlockState) data;
allayChunk.setBlockState(x, y, z, allayBlockState.allayBlockState()); allayChunk.setBlockState(x, y, z, allayBlockState.allayBlockState());
if(allayBlockState.containsWater() || allayChunk.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER)) { boolean containsWater = allayBlockState.containsWater() || allayChunk.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER);
if (containsWater) {
allayChunk.setBlockState(x, y, z, WATER, 1); allayChunk.setBlockState(x, y, z, WATER, 1);
} }
} }
@@ -6,7 +6,6 @@ import com.dfsek.terra.allay.Mapping;
import com.dfsek.terra.api.inventory.ItemStack; import com.dfsek.terra.api.inventory.ItemStack;
import com.dfsek.terra.api.inventory.item.Enchantment; import com.dfsek.terra.api.inventory.item.Enchantment;
/** /**
* @author daoge_cmd * @author daoge_cmd
*/ */
@@ -4,7 +4,6 @@ import com.dfsek.terra.api.entity.Entity;
import com.dfsek.terra.api.util.vector.Vector3; import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.world.ServerWorld; import com.dfsek.terra.api.world.ServerWorld;
/** /**
* NOTICE: Entity is not supported currently, and this is a fake implementation. * NOTICE: Entity is not supported currently, and this is a fake implementation.
* *
@@ -10,7 +10,6 @@ import java.util.Map;
import com.dfsek.terra.api.inventory.item.Enchantment; import com.dfsek.terra.api.inventory.item.Enchantment;
import com.dfsek.terra.api.inventory.item.ItemMeta; import com.dfsek.terra.api.inventory.item.ItemMeta;
/** /**
* @author daoge_cmd * @author daoge_cmd
*/ */
@@ -6,7 +6,6 @@ import org.allaymc.api.item.enchantment.EnchantmentInstance;
import com.dfsek.terra.api.inventory.Item; import com.dfsek.terra.api.inventory.Item;
import com.dfsek.terra.api.inventory.item.ItemMeta; import com.dfsek.terra.api.inventory.item.ItemMeta;
/** /**
* @author daoge_cmd * @author daoge_cmd
*/ */
@@ -10,14 +10,11 @@ import com.dfsek.terra.allay.Mapping;
import com.dfsek.terra.api.block.state.BlockState; import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.world.chunk.generation.ProtoChunk; import com.dfsek.terra.api.world.chunk.generation.ProtoChunk;
/** /**
* @author daoge_cmd * @author daoge_cmd
*/ */
public record AllayProtoChunk(UnsafeChunk allayChunk) implements ProtoChunk { public record AllayProtoChunk(UnsafeChunk allayChunk) implements ProtoChunk {
private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState( private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(BlockPropertyTypes.LIQUID_DEPTH.createValue(0));
BlockPropertyTypes.LIQUID_DEPTH.createValue(0)
);
@Override @Override
public int getMaxHeight() { public int getMaxHeight() {
@@ -17,14 +17,11 @@ import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator; import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
import com.dfsek.terra.api.world.chunk.generation.ProtoWorld; import com.dfsek.terra.api.world.chunk.generation.ProtoWorld;
/** /**
* @author daoge_cmd * @author daoge_cmd
*/ */
public record AllayProtoWorld(AllayServerWorld allayServerWorld, OtherChunkAccessibleContext context) implements ProtoWorld { public record AllayProtoWorld(AllayServerWorld allayServerWorld, OtherChunkAccessibleContext context) implements ProtoWorld {
private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState( private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(BlockPropertyTypes.LIQUID_DEPTH.createValue(0));
BlockPropertyTypes.LIQUID_DEPTH.createValue(0)
);
@Override @Override
public int centerChunkX() { public int centerChunkX() {
@@ -15,7 +15,6 @@ import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
import com.dfsek.terra.api.world.chunk.Chunk; import com.dfsek.terra.api.world.chunk.Chunk;
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator; import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
/** /**
* @author daoge_cmd * @author daoge_cmd
*/ */
@@ -24,11 +24,11 @@ import com.dfsek.terra.api.world.chunk.generation.stage.GenerationStage;
import com.dfsek.terra.api.world.chunk.generation.util.GeneratorWrapper; import com.dfsek.terra.api.world.chunk.generation.util.GeneratorWrapper;
import com.dfsek.terra.api.world.info.WorldProperties; import com.dfsek.terra.api.world.info.WorldProperties;
/** /**
* @author daoge_cmd * @author daoge_cmd
*/ */
public class AllayGeneratorWrapper implements GeneratorWrapper { public class AllayGeneratorWrapper implements GeneratorWrapper {
protected static final String OPTION_PACK_NAME = "pack"; protected static final String OPTION_PACK_NAME = "pack";
protected static final String OPTION_SEED = "seed"; protected static final String OPTION_SEED = "seed";
@@ -46,7 +46,6 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
if(packName == null) { if(packName == null) {
throw new IllegalArgumentException("Missing config pack name"); throw new IllegalArgumentException("Missing config pack name");
} }
this.seed = Long.parseLong(options.getOrDefault(OPTION_SEED, "0")); this.seed = Long.parseLong(options.getOrDefault(OPTION_SEED, "0"));
this.configPack = getConfigPack(packName); this.configPack = getConfigPack(packName);
this.chunkGenerator = createGenerator(this.configPack); this.chunkGenerator = createGenerator(this.configPack);
@@ -60,6 +59,7 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
.onDimensionSet(dimension -> { .onDimensionSet(dimension -> {
this.allayServerWorld = new AllayServerWorld(this, dimension); this.allayServerWorld = new AllayServerWorld(this, dimension);
this.worldProperties = new WorldProperties() { this.worldProperties = new WorldProperties() {
private final Object fakeHandle = new Object(); private final Object fakeHandle = new Object();
@Override @Override
@@ -82,19 +82,8 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
return fakeHandle; return fakeHandle;
} }
}; };
}).build(); })
} .build();
protected static ConfigPack getConfigPack(String packName) {
Optional<ConfigPack> byId = TerraAllayPlugin.PLATFORM.getConfigRegistry().getByID(packName);
return byId.orElseGet(
() -> TerraAllayPlugin.PLATFORM.getConfigRegistry().getByID(packName.toUpperCase(Locale.ENGLISH))
.orElseThrow(() -> new IllegalArgumentException("Cant find terra config pack named " + packName))
);
}
protected static ChunkGenerator createGenerator(ConfigPack configPack) {
return configPack.getGeneratorProvider().newInstance(configPack);
} }
@Override @Override
@@ -123,8 +112,8 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
return this.allayWorldGenerator; return this.allayWorldGenerator;
} }
protected class AllayNoiser implements Noiser { protected class AllayNoiser implements Noiser {
@Override @Override
public boolean apply(NoiseContext context) { public boolean apply(NoiseContext context) {
UnsafeChunk chunk = context.getCurrentChunk(); UnsafeChunk chunk = context.getCurrentChunk();
@@ -156,8 +145,8 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
} }
} }
protected class AllayPopulator implements Populator { protected class AllayPopulator implements Populator {
@Override @Override
public boolean apply(PopulateContext context) { public boolean apply(PopulateContext context) {
AllayProtoWorld tmp = new AllayProtoWorld(allayServerWorld, context); AllayProtoWorld tmp = new AllayProtoWorld(allayServerWorld, context);
@@ -176,4 +165,16 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
return "TERRA_POPULATOR"; return "TERRA_POPULATOR";
} }
} }
protected static ConfigPack getConfigPack(String packName) {
Optional<ConfigPack> byId = TerraAllayPlugin.PLATFORM.getConfigRegistry().getByID(packName);
return byId.orElseGet(
() -> TerraAllayPlugin.PLATFORM.getConfigRegistry().getByID(packName.toUpperCase(Locale.ENGLISH))
.orElseThrow(() -> new IllegalArgumentException("Cant find terra config pack named " + packName))
);
}
protected static ChunkGenerator createGenerator(ConfigPack configPack) {
return configPack.getGeneratorProvider().newInstance(configPack);
}
} }
@@ -13,7 +13,6 @@ import com.dfsek.terra.api.handle.ItemHandle;
import com.dfsek.terra.api.inventory.Item; import com.dfsek.terra.api.inventory.Item;
import com.dfsek.terra.api.inventory.item.Enchantment; import com.dfsek.terra.api.inventory.item.Enchantment;
/** /**
* @author daoge_cmd * @author daoge_cmd
*/ */
@@ -9,11 +9,11 @@ import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.entity.EntityType; import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.terra.api.handle.WorldHandle; import com.dfsek.terra.api.handle.WorldHandle;
/** /**
* @author daoge_cmd * @author daoge_cmd
*/ */
public class AllayWorldHandle implements WorldHandle { public class AllayWorldHandle implements WorldHandle {
@Override @Override
public @NotNull BlockState createBlockState(@NotNull String data) { public @NotNull BlockState createBlockState(@NotNull String data) {
JeBlockState jeBlockState = JeBlockState.fromString(data); JeBlockState jeBlockState = JeBlockState.fromString(data);
@@ -29,7 +29,6 @@ public class AllayWorldHandle implements WorldHandle {
public @NotNull EntityType getEntity(@NotNull String id) { public @NotNull EntityType getEntity(@NotNull String id) {
return new EntityType() { return new EntityType() {
private final Object fakeEntityType = new Object(); private final Object fakeEntityType = new Object();
@Override @Override
public Object getHandle() { public Object getHandle() {
return fakeEntityType; return fakeEntityType;