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

View File

@@ -21,7 +21,6 @@ import com.dfsek.terra.api.handle.ItemHandle;
import com.dfsek.terra.api.handle.WorldHandle;
import com.dfsek.terra.api.world.biome.PlatformBiome;
/**
* @author daoge_cmd
*/
@@ -82,8 +81,8 @@ public class AllayPlatform extends AbstractPlatform {
@Override
public void register(TypeRegistry registry) {
super.register(registry);
registry.registerLoader(BlockState.class, ($, o, $$, $$$) -> ALLAY_WORLD_HANDLE.createBlockState((String) o));
registry.registerLoader(PlatformBiome.class, ($, o, $$, depthTracker) -> parseBiome((String) o, depthTracker));
registry.registerLoader(BlockState.class, ($, o, $$, $$$) -> ALLAY_WORLD_HANDLE.createBlockState((String) o))
.registerLoader(PlatformBiome.class, ($, o, $$, depthTracker) -> parseBiome((String) o, depthTracker));
}
protected AllayBiome parseBiome(String id, DepthTracker depthTracker) throws LoadException {

View File

@@ -14,25 +14,6 @@ public class JeBlockState {
protected final TreeMap<String, String> properties;
protected int hash = Integer.MAX_VALUE;
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++) {
final String tmp = strings[i];
final int index = tmp.indexOf("=");
properties.put(tmp.substring(0, index), tmp.substring(index + 1));
}
}
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);
}
@@ -41,6 +22,20 @@ public class JeBlockState {
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++) {
final String tmp = strings[i];
final int index = tmp.indexOf("=");
properties.put(tmp.substring(0, index), tmp.substring(index + 1));
}
}
completeMissingProperties();
}
public String getPropertyValue(String key) {
return properties.get(key);
}
@@ -50,24 +45,31 @@ public class JeBlockState {
if(properties.size() == defaultProperties.size()) {
return;
}
defaultProperties.entrySet().stream()
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;
}
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;

View File

@@ -4,7 +4,6 @@ import org.allaymc.api.world.biome.BiomeType;
import com.dfsek.terra.api.world.biome.PlatformBiome;
/**
* @author daoge_cmd
*/

View File

@@ -7,15 +7,13 @@ import com.dfsek.terra.allay.JeBlockState;
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;
@@ -68,15 +66,9 @@ public final class AllayBlockState implements com.dfsek.terra.api.block.state.Bl
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; }
}

View File

@@ -6,7 +6,6 @@ import org.allaymc.api.block.type.BlockType;
import com.dfsek.terra.allay.Mapping;
import com.dfsek.terra.api.block.state.BlockState;
/**
* @author daoge_cmd
*/

View File

@@ -10,20 +10,19 @@ import com.dfsek.terra.allay.Mapping;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.world.ServerWorld;
/**
* @author daoge_cmd
*/
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
public void setBlock(int x, int y, int z, BlockState data, boolean physics) {
AllayBlockState allayBlockState = (AllayBlockState) data;
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);
}
}

View File

@@ -6,19 +6,18 @@ import com.dfsek.terra.allay.Mapping;
import com.dfsek.terra.api.inventory.ItemStack;
import com.dfsek.terra.api.inventory.item.Enchantment;
/**
* @author daoge_cmd
*/
public record AllayEnchantment(EnchantmentType allayEnchantment) implements Enchantment {
@Override
public boolean canEnchantItem(ItemStack itemStack) {
return ((AllayItemStack) itemStack).allayItemStack().checkEnchantmentCompatibility(allayEnchantment);
return ((AllayItemStack)itemStack).allayItemStack().checkEnchantmentCompatibility(allayEnchantment);
}
@Override
public boolean conflictsWith(Enchantment other) {
return ((AllayEnchantment) other).allayEnchantment.isIncompatibleWith(allayEnchantment);
return ((AllayEnchantment)other).allayEnchantment.isIncompatibleWith(allayEnchantment);
}
@Override

View File

@@ -4,7 +4,6 @@ import com.dfsek.terra.api.entity.Entity;
import com.dfsek.terra.api.util.vector.Vector3;
import com.dfsek.terra.api.world.ServerWorld;
/**
* NOTICE: Entity is not supported currently, and this is a fake implementation.
*

View File

@@ -10,7 +10,6 @@ import java.util.Map;
import com.dfsek.terra.api.inventory.item.Enchantment;
import com.dfsek.terra.api.inventory.item.ItemMeta;
/**
* @author daoge_cmd
*/
@@ -24,7 +23,7 @@ public record AllayItemMeta(ItemStack allayItemStack) implements ItemMeta {
@Override
public Map<Enchantment, Integer> getEnchantments() {
Map<Enchantment, Integer> results = new HashMap<>();
for(EnchantmentInstance allayEnchantmentInstance : allayItemStack.getEnchantments()) {
for (EnchantmentInstance allayEnchantmentInstance : allayItemStack.getEnchantments()) {
results.put(new AllayEnchantment(allayEnchantmentInstance.getType()), allayEnchantmentInstance.getLevel());
}
return results;

View File

@@ -6,11 +6,10 @@ import org.allaymc.api.item.enchantment.EnchantmentInstance;
import com.dfsek.terra.api.inventory.Item;
import com.dfsek.terra.api.inventory.item.ItemMeta;
/**
* @author daoge_cmd
*/
public record AllayItemStack(ItemStack allayItemStack) implements com.dfsek.terra.api.inventory.ItemStack {
public record AllayItemStack(ItemStack allayItemStack) implements com.dfsek.terra.api.inventory.ItemStack{
@Override
public int getAmount() {
return allayItemStack.getCount();
@@ -35,7 +34,7 @@ public record AllayItemStack(ItemStack allayItemStack) implements com.dfsek.terr
public void setItemMeta(ItemMeta meta) {
ItemStack targetItem = ((AllayItemMeta) meta).allayItemStack();
allayItemStack.removeAllEnchantments();
for(EnchantmentInstance enchantment : targetItem.getEnchantments()) {
for (EnchantmentInstance enchantment : targetItem.getEnchantments()) {
allayItemStack.addEnchantment(enchantment.getType(), enchantment.getLevel());
}
allayItemStack.setLore(targetItem.getLore());

View File

@@ -10,14 +10,11 @@ import com.dfsek.terra.allay.Mapping;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.world.chunk.generation.ProtoChunk;
/**
* @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)
);
private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(BlockPropertyTypes.LIQUID_DEPTH.createValue(0));
@Override
public int getMaxHeight() {

View File

@@ -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.ProtoWorld;
/**
* @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)
);
private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(BlockPropertyTypes.LIQUID_DEPTH.createValue(0));
@Override
public int centerChunkX() {

View File

@@ -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.generation.ChunkGenerator;
/**
* @author daoge_cmd
*/

View File

@@ -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.info.WorldProperties;
/**
* @author daoge_cmd
*/
public class AllayGeneratorWrapper implements GeneratorWrapper {
protected static final String OPTION_PACK_NAME = "pack";
protected static final String OPTION_SEED = "seed";
@@ -46,7 +46,6 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
if(packName == null) {
throw new IllegalArgumentException("Missing config pack name");
}
this.seed = Long.parseLong(options.getOrDefault(OPTION_SEED, "0"));
this.configPack = getConfigPack(packName);
this.chunkGenerator = createGenerator(this.configPack);
@@ -60,6 +59,7 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
.onDimensionSet(dimension -> {
this.allayServerWorld = new AllayServerWorld(this, dimension);
this.worldProperties = new WorldProperties() {
private final Object fakeHandle = new Object();
@Override
@@ -82,19 +82,8 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
return fakeHandle;
}
};
}).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);
})
.build();
}
@Override
@@ -123,8 +112,8 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
return this.allayWorldGenerator;
}
protected class AllayNoiser implements Noiser {
@Override
public boolean apply(NoiseContext context) {
UnsafeChunk chunk = context.getCurrentChunk();
@@ -156,8 +145,8 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
}
}
protected class AllayPopulator implements Populator {
@Override
public boolean apply(PopulateContext context) {
AllayProtoWorld tmp = new AllayProtoWorld(allayServerWorld, context);
@@ -176,4 +165,16 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
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);
}
}

View File

@@ -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.Enchantment;
/**
* @author daoge_cmd
*/

View File

@@ -9,11 +9,11 @@ import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.terra.api.handle.WorldHandle;
/**
* @author daoge_cmd
*/
public class AllayWorldHandle implements WorldHandle {
@Override
public @NotNull BlockState createBlockState(@NotNull String data) {
JeBlockState jeBlockState = JeBlockState.fromString(data);
@@ -29,7 +29,6 @@ public class AllayWorldHandle implements WorldHandle {
public @NotNull EntityType getEntity(@NotNull String id) {
return new EntityType() {
private final Object fakeEntityType = new Object();
@Override
public Object getHandle() {
return fakeEntityType;