Add missing level wrapper argument (and a bunch of null checks)
This commit is contained in:
+25
-56
@@ -59,8 +59,6 @@ import net.minecraft.core.registries.Registries;
|
||||
/** This class wraps the minecraft BlockPos.Mutable (and BlockPos) class */
|
||||
public class BiomeWrapper implements IBiomeWrapper
|
||||
{
|
||||
public static final String THE_VOID = ModInfo.ID + ":the_void";
|
||||
public static final String PLAINS = "minecraft:plains";
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
#if PRE_MC_1_18_2
|
||||
@@ -84,6 +82,7 @@ public class BiomeWrapper implements IBiomeWrapper
|
||||
//==============//
|
||||
|
||||
static public IBiomeWrapper getBiomeWrapper(#if PRE_MC_1_18_2 Biome #else Holder<Biome> #endif biome, ILevelWrapper levelWrapper) {
|
||||
Objects.requireNonNull(#if PRE_MC_1_18_2 biome #else biome.value() #endif);
|
||||
return biomeWrapperMap.computeIfAbsent(biome, biomeHolder -> new BiomeWrapper(biomeHolder, levelWrapper));
|
||||
}
|
||||
|
||||
@@ -115,52 +114,34 @@ public class BiomeWrapper implements IBiomeWrapper
|
||||
|
||||
BiomeWrapper that = (BiomeWrapper) obj;
|
||||
// the serialized value is used so we can test the contents instead of the references
|
||||
return Objects.equals(this.serialize(this.getLevelWrapper()), that.serialize(that.getLevelWrapper()));
|
||||
return Objects.equals(this.serialize(), that.serialize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.serialize(this.getLevelWrapper()));
|
||||
return Objects.hash(this.serialize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize(ILevelWrapper levelWrapper) {
|
||||
if (this.serializationResult == null) {
|
||||
// FIXME: Workaround for serverside support
|
||||
RegistryAccess registryAccess;
|
||||
try {
|
||||
registryAccess = ((Level) levelWrapper.getWrappedMcObject()).registryAccess();
|
||||
} catch (Exception ignored) {
|
||||
// Shouldn't normally happen, but just in case
|
||||
this.serializationResult = THE_VOID;
|
||||
return this.serializationResult;
|
||||
}
|
||||
|
||||
ResourceLocation resourceLocation;
|
||||
#if MC_1_16_5 || MC_1_17_1
|
||||
resourceLocation = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY).getKey(this.biome);
|
||||
#elif MC_1_18_2 || MC_1_19_2
|
||||
resourceLocation = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY).getKey(this.biome.value());
|
||||
#else
|
||||
resourceLocation = registryAccess.registryOrThrow(Registries.BIOME).getKey(this.biome.value());
|
||||
#endif
|
||||
|
||||
if (resourceLocation == null) {
|
||||
String biomeName;
|
||||
#if MC_1_16_5 || MC_1_17_1
|
||||
biomeName = this.biome.toString();
|
||||
#else
|
||||
biomeName = this.biome.value().toString();
|
||||
#endif
|
||||
|
||||
LOGGER.warn("unable to serialize (resourceLocation is null): {}", biomeName);
|
||||
// Shouldn't normally happen, but just in case
|
||||
this.serializationResult = THE_VOID;
|
||||
} else {
|
||||
this.serializationResult = resourceLocation.getNamespace() + ":" + resourceLocation.getPath();
|
||||
}
|
||||
}
|
||||
|
||||
public String serialize()
|
||||
{
|
||||
// the result can be quickly used as a semi-stable hashing method, so it's going to be cached
|
||||
if (this.serializationResult != null)
|
||||
return this.serializationResult;
|
||||
|
||||
RegistryAccess registryAccess = ((Level) levelWrapper.getWrappedMcObject()).registryAccess();
|
||||
|
||||
ResourceLocation resourceLocation;
|
||||
#if MC_1_16_5 || MC_1_17_1
|
||||
resourceLocation = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY).getKey(this.biome);
|
||||
#elif MC_1_18_2 || MC_1_19_2
|
||||
resourceLocation = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY).getKey(this.biome.value());
|
||||
#else
|
||||
resourceLocation = registryAccess.registryOrThrow(Registries.BIOME).getKey(this.biome.value());
|
||||
#endif
|
||||
Objects.requireNonNull(resourceLocation);
|
||||
|
||||
this.serializationResult = resourceLocation.getNamespace() + ":" + resourceLocation.getPath();
|
||||
return this.serializationResult;
|
||||
}
|
||||
|
||||
@@ -170,16 +151,6 @@ public class BiomeWrapper implements IBiomeWrapper
|
||||
}
|
||||
|
||||
public static IBiomeWrapper deserialize(String resourceLocationString, ILevelWrapper levelWrapper) throws IOException {
|
||||
if (resourceLocationString.trim().isEmpty() || resourceLocationString.equals("") || resourceLocationString.equals(THE_VOID)) {
|
||||
if (Config.Client.Advanced.Logging.logWorldGenEvent.get().levelForFile == org.apache.logging.log4j.Level.WARN) {
|
||||
LOGGER.warn("null biome string deserialized");
|
||||
}
|
||||
|
||||
// Shouldn't normally happen, but just in case
|
||||
// Deserialize to minecraft:plains, otherwise the FullDataPointIdMap.Entry#deserialize function errors out
|
||||
resourceLocationString = PLAINS;
|
||||
}
|
||||
|
||||
// parse the resource location
|
||||
int separatorIndex = resourceLocationString.indexOf(":");
|
||||
if (separatorIndex == -1) {
|
||||
@@ -198,10 +169,8 @@ public class BiomeWrapper implements IBiomeWrapper
|
||||
Holder<Biome> biome = new Holder.Direct<>(unwrappedBiome);
|
||||
#else
|
||||
Biome unwrappedBiome = registryAccess.registryOrThrow(Registries.BIOME).get(resourceLocation);
|
||||
if (unwrappedBiome == null)
|
||||
{
|
||||
LOGGER.warn("null biome string deserialized from string: " + resourceLocationString);
|
||||
}
|
||||
assert unwrappedBiome != null;
|
||||
|
||||
Holder<Biome> biome = new Holder.Direct<>(unwrappedBiome);
|
||||
#endif
|
||||
|
||||
@@ -219,7 +188,7 @@ public class BiomeWrapper implements IBiomeWrapper
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.serialize(this.getLevelWrapper());
|
||||
return this.serialize();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+49
-60
@@ -5,6 +5,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrappe
|
||||
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
@@ -26,21 +27,25 @@ import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.level.EmptyBlockGetter;
|
||||
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.annotation.Nullable;
|
||||
#endif
|
||||
|
||||
public class BlockStateWrapper implements IBlockStateWrapper
|
||||
{
|
||||
/** example "minecraft:plains" */
|
||||
public static final String RESOURCE_LOCATION_SEPARATOR = ":";
|
||||
/** example "minecraft:water_state_{level:0}" */
|
||||
/** example "minecraft:water_STATE_{level:0}" */
|
||||
public static final String STATE_STRING_SEPARATOR = "_STATE_";
|
||||
|
||||
|
||||
// must be defined before AIR, otherwise a null pointer will be thrown
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
|
||||
public static final BlockStateWrapper AIR = new BlockStateWrapper(null, null);
|
||||
public static final ConcurrentHashMap<BlockState, BlockStateWrapper> cache = new ConcurrentHashMap<>();
|
||||
public static final BlockStateWrapper AIR = fromBlockState(BuiltInRegistries.BLOCK.get(ResourceLocation.tryParse("minecraft:air")).defaultBlockState(), null);
|
||||
public static final String AIR_SERIALIZATION_RESULT = "AIR";
|
||||
|
||||
/**
|
||||
* Cached so it can be quickly used as a semi-stable hashing method. <br>
|
||||
@@ -53,23 +58,25 @@ public class BlockStateWrapper implements IBlockStateWrapper
|
||||
// constructors //
|
||||
//==============//
|
||||
|
||||
public static BlockStateWrapper fromBlockState(BlockState blockState, ILevelWrapper levelWrapper)
|
||||
public static BlockStateWrapper fromBlockState(BlockState blockState, @Nullable ILevelWrapper levelWrapper)
|
||||
{
|
||||
if (blockState == null || blockState.isAir())
|
||||
{
|
||||
if (Objects.requireNonNull(blockState).isAir() && AIR != null)
|
||||
return AIR;
|
||||
}
|
||||
|
||||
return cache.computeIfAbsent(blockState, blockState1 -> new BlockStateWrapper(blockState1, levelWrapper));
|
||||
}
|
||||
|
||||
public final BlockState blockState;
|
||||
@CheckForNull
|
||||
public final ILevelWrapper levelWrapper;
|
||||
|
||||
BlockStateWrapper(BlockState blockState, ILevelWrapper levelWrapper)
|
||||
BlockStateWrapper(BlockState blockState, @Nullable ILevelWrapper levelWrapper)
|
||||
{
|
||||
this.blockState = blockState;
|
||||
this.levelWrapper = levelWrapper;
|
||||
this.levelWrapper = blockState.isAir()
|
||||
? null
|
||||
: Objects.requireNonNull(levelWrapper);
|
||||
|
||||
LOGGER.trace("Created BlockStateWrapper for ["+blockState+"]");
|
||||
}
|
||||
|
||||
@@ -99,60 +106,47 @@ public class BlockStateWrapper implements IBlockStateWrapper
|
||||
public int getLightEmission() { return (this.blockState != null) ? this.blockState.getLightEmission() : 0; }
|
||||
|
||||
@Override
|
||||
public String serialize(ILevelWrapper levelWrapper)
|
||||
public String serialize()
|
||||
{
|
||||
// cache the serialization result so it can be quickly used as a semi-stable hashing method
|
||||
if (this.serializationResult == null)
|
||||
{
|
||||
if (this.blockState == null)
|
||||
{
|
||||
return "AIR";
|
||||
}
|
||||
|
||||
// FIXME: Workaround for serverside support
|
||||
RegistryAccess registryAccess;
|
||||
try {
|
||||
registryAccess = ((Level) levelWrapper.getWrappedMcObject()).registryAccess();
|
||||
} catch (Exception ignored) {
|
||||
// Shouldn't normally happen, but just in case
|
||||
this.serializationResult = "AIR";
|
||||
return this.serializationResult;
|
||||
}
|
||||
|
||||
ResourceLocation resourceLocation;
|
||||
#if MC_1_16_5 || MC_1_17_1
|
||||
resourceLocation = Registry.BLOCK.getKey(this.blockState.getBlock());
|
||||
#elif MC_1_18_2 || MC_1_19_2
|
||||
resourceLocation = registryAccess.registryOrThrow(Registry.BLOCK_REGISTRY).getKey(this.blockState.getBlock());
|
||||
#else
|
||||
resourceLocation = registryAccess.registryOrThrow(Registries.BLOCK).getKey(this.blockState.getBlock());
|
||||
#endif
|
||||
|
||||
if (resourceLocation == null)
|
||||
{
|
||||
LOGGER.warn("unable to serialize (resourceLocation is null): {}", this.blockState);
|
||||
// Shouldn't normally happen, but just in case
|
||||
this.serializationResult = "AIR";
|
||||
} else {
|
||||
this.serializationResult = resourceLocation.getNamespace() + RESOURCE_LOCATION_SEPARATOR + resourceLocation.getPath()
|
||||
+ STATE_STRING_SEPARATOR + serializeBlockStateProperties(this.blockState);
|
||||
}
|
||||
}
|
||||
// the result can be quickly used as a semi-stable hashing method, so it's going to be cached
|
||||
if (this.serializationResult != null)
|
||||
return this.serializationResult;
|
||||
|
||||
if (this.blockState.isAir())
|
||||
return this.serializationResult = AIR_SERIALIZATION_RESULT;
|
||||
|
||||
Objects.requireNonNull(levelWrapper);
|
||||
RegistryAccess registryAccess = ((Level) levelWrapper.getWrappedMcObject()).registryAccess();
|
||||
|
||||
ResourceLocation resourceLocation;
|
||||
#if MC_1_16_5 || MC_1_17_1
|
||||
resourceLocation = Registry.BLOCK.getKey(this.blockState.getBlock());
|
||||
#elif MC_1_18_2 || MC_1_19_2
|
||||
resourceLocation = registryAccess.registryOrThrow(Registry.BLOCK_REGISTRY).getKey(this.blockState.getBlock());
|
||||
#else
|
||||
resourceLocation = registryAccess.registryOrThrow(Registries.BLOCK).getKey(this.blockState.getBlock());
|
||||
#endif
|
||||
Objects.requireNonNull(resourceLocation);
|
||||
|
||||
this.serializationResult = resourceLocation.getNamespace() + RESOURCE_LOCATION_SEPARATOR + resourceLocation.getPath()
|
||||
+ STATE_STRING_SEPARATOR + serializeBlockStateProperties(this.blockState);
|
||||
|
||||
return this.serializationResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ILevelWrapper getLevelWrapper() {
|
||||
return levelWrapper;
|
||||
}
|
||||
|
||||
public static BlockStateWrapper deserialize(String resourceStateString, ILevelWrapper levelWrapper) throws IOException
|
||||
{
|
||||
if (resourceStateString.equals("AIR") || resourceStateString.equals("")) // The empty string shouldn't normally happen, but just in case
|
||||
{
|
||||
if (resourceStateString.isEmpty())
|
||||
throw new IOException("resourceStateString is empty");
|
||||
|
||||
if (resourceStateString.equals(AIR_SERIALIZATION_RESULT))
|
||||
return AIR;
|
||||
}
|
||||
|
||||
// Parse the BlockState
|
||||
int stateSeparatorIndex = resourceStateString.indexOf(STATE_STRING_SEPARATOR);
|
||||
@@ -201,12 +195,7 @@ public class BlockStateWrapper implements IBlockStateWrapper
|
||||
}
|
||||
}
|
||||
|
||||
// use the default if no state was found
|
||||
if (foundState == null)
|
||||
{
|
||||
LOGGER.warn("Unable to find BlockState for Block [" + resourceLocation + "] with properties: [" + blockStatePropertiesString + "].");
|
||||
foundState = block.defaultBlockState();
|
||||
}
|
||||
Objects.requireNonNull(foundState);
|
||||
return new BlockStateWrapper(foundState, levelWrapper);
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -221,7 +210,7 @@ public class BlockStateWrapper implements IBlockStateWrapper
|
||||
// get the property list for this block (doesn't contain this block state's values, just the names and possible values)
|
||||
java.util.Collection<net.minecraft.world.level.block.state.properties.Property<?>> blockPropertyCollection = blockState.getProperties();
|
||||
|
||||
// alphabetically sort the list so they are always in the same order
|
||||
// alphabetically sort the list, so they are always in the same order
|
||||
List<net.minecraft.world.level.block.state.properties.Property<?>> sortedBlockPropteryList = new ArrayList<>(blockPropertyCollection);
|
||||
sortedBlockPropteryList.sort((a, b) -> a.getName().compareTo(b.getName()));
|
||||
|
||||
@@ -260,13 +249,13 @@ public class BlockStateWrapper implements IBlockStateWrapper
|
||||
}
|
||||
|
||||
BlockStateWrapper that = (BlockStateWrapper) obj;
|
||||
// the serialized value is used so we can test the contents instead of the references
|
||||
return Objects.equals(this.serialize(this.getLevelWrapper()), that.serialize(that.getLevelWrapper()));
|
||||
// the serialized value is used, so we can test the contents instead of the references
|
||||
return Objects.equals(this.serialize(), that.serialize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.serialize(this.getLevelWrapper()));
|
||||
return Objects.hash(this.serialize());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -303,7 +292,7 @@ public class BlockStateWrapper implements IBlockStateWrapper
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.serialize(this.getLevelWrapper());
|
||||
return this.serialize();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -93,7 +93,7 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
//=============//
|
||||
// constructor //
|
||||
//=============//
|
||||
|
||||
private String stackTraceElements = Arrays.toString(Thread.currentThread().getStackTrace());
|
||||
public ChunkWrapper(ChunkAccess chunk, LevelReader lightSource, @Nullable ILevelWrapper wrappedLevel)
|
||||
{
|
||||
this.chunk = chunk;
|
||||
|
||||
+1
-1
@@ -489,7 +489,7 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
|
||||
ChunkAccess chunk = totalChunks.get(x, z);
|
||||
if (chunk != null)
|
||||
{
|
||||
chunkWrapperList.set(x, z, new ChunkWrapper(chunk, region, null));
|
||||
chunkWrapperList.set(x, z, new ChunkWrapper(chunk, region, this.serverlevel.getServerLevelWrapper()));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+1
-1
Submodule coreSubProjects updated: 47aef1f349...42a84a54e1
@@ -12,6 +12,7 @@ loom {
|
||||
setConfigName("Fabric Client")
|
||||
ideConfigGenerated(true)
|
||||
runDir("run/client")
|
||||
programArgs("--username", "TTLLILLI") // DO NOT CHECKOUT
|
||||
}
|
||||
server {
|
||||
server()
|
||||
|
||||
Reference in New Issue
Block a user