If this serializer stuff works first try than I'm surprised

This commit is contained in:
TomTheFurry
2022-06-23 22:46:13 +08:00
parent 30248dcaac
commit 13b820e17a
5 changed files with 30 additions and 2 deletions
@@ -1,13 +1,19 @@
package com.seibel.lod.core.a7.datatype.full;
import com.seibel.lod.core.handlers.dependencyInjection.SingletonHandler;
import com.seibel.lod.core.wrapperInterfaces.IWrapperFactory;
import com.seibel.lod.core.wrapperInterfaces.block.IBlockStateWrapper;
import com.seibel.lod.core.wrapperInterfaces.world.IBiomeWrapper;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Objects;
// WARNING: This is not THREAD-SAFE!
public class IdBiomeBlockStateMap {
public static final IWrapperFactory FACTORY = SingletonHandler.get(IWrapperFactory.class);
public static final class Entry {
public final IBiomeWrapper biome;
public final IBlockStateWrapper blockState;
@@ -25,6 +31,18 @@ public class IdBiomeBlockStateMap {
if (!(other instanceof Entry)) return false;
return ((Entry) other).biome.equals(biome) && ((Entry) other).blockState.equals(blockState);
}
public String serialize() {
return biome.serialize() + " " + blockState.serialize();
}
public static Entry deserialize(String str) throws IOException {
String[] strs = str.split(" ");
if (strs.length != 2) throw new IOException("Failed to deserialize BiomeBlockStateEntry");
IBiomeWrapper biome = FACTORY.deserializeBiomeWrapper(strs[0]);
IBlockStateWrapper blockState = FACTORY.deserializeBlockStateWrapper(strs[1]);
return new Entry(biome, blockState);
}
}
@@ -22,6 +22,8 @@ package com.seibel.lod.core.wrapperInterfaces;
import com.seibel.lod.core.builders.lodBuilding.LodBuilder;
import com.seibel.lod.core.handlers.dependencyInjection.IBindable;
import com.seibel.lod.core.objects.lod.LodDimension;
import com.seibel.lod.core.wrapperInterfaces.block.IBlockStateWrapper;
import com.seibel.lod.core.wrapperInterfaces.world.IBiomeWrapper;
import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper;
import com.seibel.lod.core.wrapperInterfaces.worldGeneration.AbstractBatchGenerationEnvionmentWrapper;
@@ -35,4 +37,7 @@ public interface IWrapperFactory extends IBindable
{
AbstractBatchGenerationEnvionmentWrapper createBatchGenerator(LodBuilder newLodBuilder,
LodDimension newLodDimension, ILevelWrapper worldWrapper);
IBiomeWrapper deserializeBiomeWrapper(String str);
IBlockStateWrapper deserializeBlockStateWrapper(String str);
}
@@ -2,4 +2,6 @@ package com.seibel.lod.core.wrapperInterfaces.block;
public interface IBlockStateWrapper {
IBlockStateWrapper AIR = null;
String serialize();
}
@@ -41,10 +41,12 @@ public interface IChunkWrapper extends IBindable
int getHeightMapValue(int xRel, int zRel);
IBiomeWrapper getBiome(int x, int y, int z);
@Deprecated
IBlockDetailWrapper getBlockDetail(int x, int y, int z);
// Returns null if block doesn't exist. Note that this can cross chunk boundaries.
@Deprecated
IBlockDetailWrapper getBlockDetailAtFace(int x, int y, int z, ELodDirection dir);
@Deprecated
@@ -37,5 +37,6 @@ public interface IBiomeWrapper extends IBindable
int getFolliageTint();
int getWaterTint();
String serialize();
}