If this serializer stuff works first try than I'm surprised
This commit is contained in:
@@ -19,9 +19,13 @@
|
||||
|
||||
package com.seibel.lod.common.wrappers;
|
||||
|
||||
import com.seibel.lod.common.wrappers.block.BlockStateWrapper;
|
||||
import com.seibel.lod.common.wrappers.world.BiomeWrapper;
|
||||
import com.seibel.lod.core.builders.lodBuilding.LodBuilder;
|
||||
import com.seibel.lod.core.objects.lod.LodDimension;
|
||||
import com.seibel.lod.core.wrapperInterfaces.IWrapperFactory;
|
||||
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;
|
||||
import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment;
|
||||
@@ -41,4 +45,14 @@ public class WrapperFactory implements IWrapperFactory
|
||||
{
|
||||
return new BatchGenerationEnvironment(worldWrapper, newLodBuilder, newLodDimension);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBiomeWrapper deserializeBiomeWrapper(String str) {
|
||||
return BiomeWrapper.deserialize(str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockStateWrapper deserializeBlockStateWrapper(String str) {
|
||||
return BlockStateWrapper.deserialize(str);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.seibel.lod.common.wrappers.block;
|
||||
|
||||
import com.google.gson.JsonParser;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import com.seibel.lod.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class BlockStateWrapper implements IBlockStateWrapper {
|
||||
public final BlockState blockState;
|
||||
public BlockStateWrapper(BlockState blockState) {
|
||||
this.blockState = blockState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() {
|
||||
return BlockState.CODEC.encodeStart(JsonOps.COMPRESSED, blockState).get().orThrow().toString();
|
||||
}
|
||||
|
||||
public static BlockStateWrapper deserialize(String str) {
|
||||
return new BlockStateWrapper(
|
||||
BlockState.CODEC.decode(JsonOps.COMPRESSED, JsonParser.parseString(str)).get().orThrow().getFirst()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
BlockStateWrapper that = (BlockStateWrapper) o;
|
||||
return Objects.equals(blockState, that.blockState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(blockState);
|
||||
}
|
||||
}
|
||||
@@ -20,10 +20,12 @@
|
||||
package com.seibel.lod.common.wrappers.chunk;
|
||||
|
||||
import com.seibel.lod.common.wrappers.block.BlockDetailWrapper;
|
||||
import com.seibel.lod.common.wrappers.block.BlockStateWrapper;
|
||||
import com.seibel.lod.core.enums.ELodDirection;
|
||||
import com.seibel.lod.core.util.LevelPosUtil;
|
||||
import com.seibel.lod.core.util.LodUtil;
|
||||
import com.seibel.lod.core.wrapperInterfaces.block.IBlockDetailWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IBiomeWrapper;
|
||||
|
||||
@@ -106,13 +108,14 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
#elif PRE_MC_1_18_2
|
||||
return BiomeWrapper.getBiomeWrapper(chunk.getNoiseBiome(
|
||||
QuartPos.fromBlock(x), QuartPos.fromBlock(y), QuartPos.fromBlock(z)));
|
||||
#else
|
||||
#else //Now returns a Holder<Biome> instead of Biome
|
||||
return BiomeWrapper.getBiomeWrapper(chunk.getNoiseBiome(
|
||||
QuartPos.fromBlock(x), QuartPos.fromBlock(y), QuartPos.fromBlock(z)).value());
|
||||
QuartPos.fromBlock(x), QuartPos.fromBlock(y), QuartPos.fromBlock(z)));
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public IBlockDetailWrapper getBlockDetail(int x, int y, int z) {
|
||||
BlockPos pos = new BlockPos(x,y,z);
|
||||
BlockState blockState = chunk.getBlockState(pos);
|
||||
@@ -121,6 +124,7 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public IBlockDetailWrapper getBlockDetailAtFace(int x, int y, int z, ELodDirection dir) {
|
||||
int fy = y+dir.getNormal().y;
|
||||
if (fy < getMinBuildHeight() || fy > getMaxBuildHeight()) return null;
|
||||
@@ -247,5 +251,9 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
public String toString() {
|
||||
return chunk.getClass().getSimpleName() + chunk.getPos();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockStateWrapper getBlockState(int x, int y, int z) {
|
||||
return new BlockStateWrapper(chunk.getBlockState(new BlockPos(x,y,z)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,9 +29,12 @@ import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import com.seibel.lod.core.util.LodUtil;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IBiomeWrapper;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
#if POST_MC_1_19
|
||||
import net.minecraft.data.worldgen.biome.EndBiomes;
|
||||
@@ -47,22 +50,25 @@ import net.minecraft.world.level.material.MaterialColor;
|
||||
//This class wraps the minecraft BlockPos.Mutable (and BlockPos) class
|
||||
public class BiomeWrapper implements IBiomeWrapper
|
||||
{
|
||||
|
||||
#if PRE_MC_1_18_2
|
||||
public static final ConcurrentMap<Biome, BiomeWrapper> biomeWrapperMap = new ConcurrentHashMap<>();
|
||||
private final Biome biome;
|
||||
#else
|
||||
public static final ConcurrentMap<Holder<Biome>, BiomeWrapper> biomeWrapperMap = new ConcurrentHashMap<>();
|
||||
private final Holder<Biome> biome;
|
||||
#endif
|
||||
|
||||
public BiomeWrapper(Biome biome)
|
||||
public BiomeWrapper(#if PRE_MC_1_18_2 Biome #else Holder<Biome> #endif biome)
|
||||
{
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
static public IBiomeWrapper getBiomeWrapper(Biome biome)
|
||||
static public IBiomeWrapper getBiomeWrapper(#if PRE_MC_1_18_2 Biome #else Holder<Biome> #endif biome)
|
||||
{
|
||||
//first we check if the biome has already been wrapped
|
||||
if(biomeWrapperMap.containsKey(biome) && biomeWrapperMap.get(biome) != null)
|
||||
return biomeWrapperMap.get(biome);
|
||||
|
||||
|
||||
//if it hasn't been created yet, we create it and save it in the map
|
||||
BiomeWrapper biomeWrapper = new BiomeWrapper(biome);
|
||||
biomeWrapperMap.put(biome, biomeWrapper);
|
||||
@@ -71,9 +77,12 @@ public class BiomeWrapper implements IBiomeWrapper
|
||||
return biomeWrapper;
|
||||
}
|
||||
|
||||
private Biome _biome() {
|
||||
return #if PRE_MC_1_18_2 biome #else biome.value() #endif;
|
||||
}
|
||||
|
||||
/** Returns a color int for the given biome. */
|
||||
#if PRE_MC_1_19
|
||||
#if PRE_MC_1_18_2
|
||||
@Override
|
||||
public int getColorForBiome(int x, int z)
|
||||
{
|
||||
@@ -157,9 +166,6 @@ public class BiomeWrapper implements IBiomeWrapper
|
||||
private static int _colorMoss(Biome b) {
|
||||
return Blocks.MOSS_BLOCK.defaultMaterialColor().col;
|
||||
}
|
||||
private static int _colorSculk(Biome b) {
|
||||
return Blocks.SCULK.defaultMaterialColor().col;
|
||||
}
|
||||
private static int _colorMushoom(Biome b) {
|
||||
return Blocks.MYCELIUM.defaultMaterialColor().col;
|
||||
}
|
||||
@@ -187,6 +193,11 @@ public class BiomeWrapper implements IBiomeWrapper
|
||||
private static int _colorFoliage(Biome b) {
|
||||
return b.getFoliageColor();
|
||||
}
|
||||
#if POST_MC_1_19
|
||||
private static int _colorSculk(Biome b) {
|
||||
return Blocks.SCULK.defaultMaterialColor().col;
|
||||
}
|
||||
#endif
|
||||
|
||||
private static Biome _get(ResourceKey<Biome> r) {
|
||||
return BuiltinRegistries.BIOME.getOrThrow(r);
|
||||
@@ -199,7 +210,6 @@ public class BiomeWrapper implements IBiomeWrapper
|
||||
.put(_get(Biomes.ICE_SPIKES), BiomeWrapper::_colorIce)
|
||||
.put(_get(Biomes.DESERT), BiomeWrapper::_colorSand)
|
||||
.put(_get(Biomes.SWAMP), BiomeWrapper::_colorWater)
|
||||
.put(_get(Biomes.MANGROVE_SWAMP), BiomeWrapper::_colorWater)
|
||||
.put(_get(Biomes.FOREST), BiomeWrapper::_colorFoliage)
|
||||
.put(_get(Biomes.FLOWER_FOREST), BiomeWrapper::_colorFoliage)
|
||||
.put(_get(Biomes.BIRCH_FOREST), BiomeWrapper::_colorFoliage)
|
||||
@@ -238,7 +248,6 @@ public class BiomeWrapper implements IBiomeWrapper
|
||||
.put(_get(Biomes.MUSHROOM_FIELDS), BiomeWrapper::_colorMushoom)
|
||||
.put(_get(Biomes.DRIPSTONE_CAVES), BiomeWrapper::_colorDripStone)
|
||||
.put(_get(Biomes.LUSH_CAVES), BiomeWrapper::_colorMoss)
|
||||
.put(_get(Biomes.DEEP_DARK), BiomeWrapper::_colorSculk)
|
||||
.put(_get(Biomes.NETHER_WASTES), BiomeWrapper::_colorNether)
|
||||
.put(_get(Biomes.WARPED_FOREST), BiomeWrapper::_colorNether)
|
||||
.put(_get(Biomes.CRIMSON_FOREST), BiomeWrapper::_colorNether)
|
||||
@@ -249,62 +258,78 @@ public class BiomeWrapper implements IBiomeWrapper
|
||||
.put(_get(Biomes.END_MIDLANDS), BiomeWrapper::_colorEnd)
|
||||
.put(_get(Biomes.SMALL_END_ISLANDS), BiomeWrapper::_colorEnd)
|
||||
.put(_get(Biomes.END_BARRENS), BiomeWrapper::_colorEnd)
|
||||
#if MC_1_19
|
||||
.put(_get(Biomes.MANGROVE_SWAMP), BiomeWrapper::_colorWater)
|
||||
.put(_get(Biomes.DEEP_DARK), BiomeWrapper::_colorSculk)
|
||||
#endif
|
||||
.build();
|
||||
|
||||
@Override
|
||||
public int getColorForBiome(int x, int z)
|
||||
{
|
||||
int colorInt;
|
||||
Function<Biome, Integer> colorFunction = BIOME_COLOR_MAP.get(biome);
|
||||
Function<Biome, Integer> colorFunction = BIOME_COLOR_MAP.get(biome.value());
|
||||
if (colorFunction != null)
|
||||
{
|
||||
colorInt = colorFunction.apply(biome);
|
||||
colorInt = colorFunction.apply(biome.value());
|
||||
}
|
||||
else
|
||||
{
|
||||
colorInt = biome.getGrassColor(x, z);
|
||||
colorInt = biome.value().getGrassColor(x, z);
|
||||
}
|
||||
return colorInt;
|
||||
}
|
||||
#endif
|
||||
|
||||
@Override public String getName()
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
#if PRE_MC_1_18_2
|
||||
return biome.toString();
|
||||
#else
|
||||
return biome.unwrapKey().orElse(Biomes.THE_VOID).registry().toString();
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGrassTint(int x, int z)
|
||||
{
|
||||
return biome.getGrassColor(x, z);
|
||||
return _biome().getGrassColor(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFolliageTint()
|
||||
{
|
||||
return biome.getFoliageColor();
|
||||
return _biome().getFoliageColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWaterTint()
|
||||
{
|
||||
return biome.getWaterColor();
|
||||
return _biome().getWaterColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() {
|
||||
return Biome.CODEC.encodeStart(JsonOps.COMPRESSED, biome).get().orThrow().toString();
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!(obj instanceof BiomeWrapper))
|
||||
return false;
|
||||
BiomeWrapper that = (BiomeWrapper) obj;
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
BiomeWrapper that = (BiomeWrapper) o;
|
||||
return Objects.equals(biome, that.biome);
|
||||
}
|
||||
|
||||
@Override public int hashCode()
|
||||
{
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(biome);
|
||||
}
|
||||
|
||||
public static IBiomeWrapper deserialize(String str) {
|
||||
#if PRE_MC_1_18_2 Biome #else Holder<Biome> #endif
|
||||
biome = Biome.CODEC.decode(JsonOps.COMPRESSED, JsonParser.parseString(str)).get().orThrow().getFirst();
|
||||
return getBiomeWrapper(biome);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
Submodule core updated: 1d4c292e06...fce82c331b
Reference in New Issue
Block a user