Fix compiling for 1.20.1

This commit is contained in:
James Seibel
2023-08-05 21:21:32 -05:00
parent cfb0dd4096
commit 739947e008
3 changed files with 48 additions and 8 deletions
@@ -45,7 +45,8 @@ import net.minecraft.data.BuiltinRegistries;
import net.minecraft.resources.RegistryReadOps;
import net.minecraft.resources.RegistryWriteOps;
#else
import net.minecraft.resources.RegistryReadOps;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
#endif
import net.minecraft.resources.ResourceLocation;
@@ -103,8 +104,16 @@ public class BiomeWrapper implements IBiomeWrapper
@Override
public String serialize() // FIXME pass in level to prevent null pointers (or maybe just RegistryAccess?)
{
net.minecraft.core.RegistryAccess registryAccess = Minecraft.getInstance().level.registryAccess();
ResourceLocation resourceLocation = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY).getKey(this.biome);
ResourceLocation resourceLocation;
#if MC_1_16_5
resourceLocation = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY).getKey(this.biome);
#else
resourceLocation = registryAccess.registryOrThrow(Registries.BIOME).getKey(this.biome.value());
#endif
if (resourceLocation == null)
{
// shouldn't normally happen, but just in case
@@ -138,7 +147,14 @@ public class BiomeWrapper implements IBiomeWrapper
try
{
net.minecraft.core.RegistryAccess registryAccess = Minecraft.getInstance().level.registryAccess();
#if MC_1_16_5
Biome biome = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY).get(resourceLocation);
#else
Biome unwrappedBiome = registryAccess.registryOrThrow(Registries.BIOME).get(resourceLocation);
Holder<Biome> biome = new Holder.Direct<>(unwrappedBiome);
#endif
return getBiomeWrapper(biome);
}
catch (Exception e)
@@ -2,7 +2,7 @@ package com.seibel.distanthorizons.common.wrappers.block;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
@@ -14,6 +14,15 @@ import java.util.List;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
#if MC_1_16_5
import net.minecraft.core.Registry;
#else
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.level.EmptyBlockGetter;
#endif
public class BlockStateWrapper implements IBlockStateWrapper
{
/** example "minecraft:plains" */
@@ -80,20 +89,27 @@ public class BlockStateWrapper implements IBlockStateWrapper
@Override
public String serialize()
public String serialize() // FIXME pass in level to prevent null pointers (or maybe just RegistryAccess?)
{
if (this.blockState == null)
{
return "AIR";
}
ResourceLocation resourceLocation = Registry.BLOCK.getKey(this.blockState.getBlock());
ResourceLocation resourceLocation;
#if MC_1_16_5
resourceLocation = Registry.BLOCK.getKey(this.blockState.getBlock());
#else
net.minecraft.core.RegistryAccess registryAccess = Minecraft.getInstance().level.registryAccess();
resourceLocation = registryAccess.registryOrThrow(Registries.BLOCK).getKey(this.blockState.getBlock());
#endif
String resourceStateString = resourceLocation.getNamespace() + RESOURCE_LOCATION_SEPARATOR + resourceLocation.getPath()
+ STATE_STRING_SEPARATOR + serializeBlockStateProperties(this.blockState);
return resourceStateString;
}
public static BlockStateWrapper deserialize(String resourceStateString) throws IOException
public static BlockStateWrapper deserialize(String resourceStateString) throws IOException // FIXME pass in level to prevent null pointers (or maybe just RegistryAccess?)
{
if (resourceStateString.equals("AIR") || resourceStateString.equals("")) // the empty string shouldn't normally happen, but just in case
{
@@ -124,7 +140,15 @@ public class BlockStateWrapper implements IBlockStateWrapper
// attempt to get the BlockState from all possible BlockStates
try
{
Block block = Registry.BLOCK.get(resourceLocation);
Block block;
#if MC_1_16_5
block = Registry.BLOCK.get(resourceLocation);
#else
net.minecraft.core.RegistryAccess registryAccess = Minecraft.getInstance().level.registryAccess();
block = registryAccess.registryOrThrow(Registries.BLOCK).get(resourceLocation);
#endif
BlockState foundState = null;
List<BlockState> possibleStateList = block.getStateDefinition().getPossibleStates();
@@ -88,7 +88,7 @@ public final class ThreadedParameters
}
#if POST_MC_1_18_2
#if POST_MC_1_18_2 && PRE_MC_1_19_2
public void recreateStructureCheck()
{
if (previousGlobalParameters != null)