Fix resource locations in biome/block wrappers

This commit is contained in:
James Seibel
2024-05-15 07:24:08 -04:00
parent 6b5bae9bee
commit da18469fd4
2 changed files with 15 additions and 9 deletions
@@ -254,6 +254,9 @@ public class BiomeWrapper implements IBiomeWrapper
// TODO would it be worth while to cache these objects in a ConcurrentHashMap<string, IBiomeWrapper>?
public static IBiomeWrapper deserialize(String resourceLocationString, ILevelWrapper levelWrapper) throws IOException
{
// we need the final string for the concurrent hash map later
final String finalResourceStateString = resourceLocationString;
if (resourceLocationString.equals(EMPTY_BIOME_STRING))
{
if (!emptyStringWarningLogged)
@@ -269,9 +272,9 @@ public class BiomeWrapper implements IBiomeWrapper
return EMPTY_WRAPPER;
}
if (WRAPPER_BY_RESOURCE_LOCATION.containsKey(resourceLocationString))
if (WRAPPER_BY_RESOURCE_LOCATION.containsKey(finalResourceStateString))
{
return WRAPPER_BY_RESOURCE_LOCATION.get(resourceLocationString);
return WRAPPER_BY_RESOURCE_LOCATION.get(finalResourceStateString);
}
@@ -335,12 +338,12 @@ public class BiomeWrapper implements IBiomeWrapper
}
catch (Exception e)
{
throw new IOException("Failed to deserialize the string [" + resourceLocationString + "] into a BiomeWrapper: " + e.getMessage(), e);
throw new IOException("Failed to deserialize the string [" + finalResourceStateString + "] into a BiomeWrapper: " + e.getMessage(), e);
}
}
finally
{
WRAPPER_BY_RESOURCE_LOCATION.putIfAbsent(resourceLocationString, foundWrapper);
WRAPPER_BY_RESOURCE_LOCATION.putIfAbsent(finalResourceStateString, foundWrapper);
}
}
@@ -340,15 +340,18 @@ public class BlockStateWrapper implements IBlockStateWrapper
/** will only work if a level is currently loaded */
public static IBlockStateWrapper deserialize(String resourceStateString, ILevelWrapper levelWrapper) throws IOException
{
if (resourceStateString.equals(AIR_STRING) || resourceStateString.equals("")) // the empty string shouldn't normally happen, but just in case
// we need the final string for the concurrent hash map later
final String finalResourceStateString = resourceStateString;
if (finalResourceStateString.equals(AIR_STRING) || finalResourceStateString.equals("")) // the empty string shouldn't normally happen, but just in case
{
return AIR;
}
// attempt to use the existing wrapper
if (WRAPPER_BY_RESOURCE_LOCATION.containsKey(resourceStateString))
if (WRAPPER_BY_RESOURCE_LOCATION.containsKey(finalResourceStateString))
{
return WRAPPER_BY_RESOURCE_LOCATION.get(resourceStateString);
return WRAPPER_BY_RESOURCE_LOCATION.get(finalResourceStateString);
}
@@ -458,14 +461,14 @@ public class BlockStateWrapper implements IBlockStateWrapper
}
catch (Exception e)
{
throw new IOException("Failed to deserialize the string [" + resourceStateString + "] into a BlockStateWrapper: " + e.getMessage(), e);
throw new IOException("Failed to deserialize the string [" + finalResourceStateString + "] into a BlockStateWrapper: " + e.getMessage(), e);
}
}
finally
{
// put if absent in case two threads deserialize at the same time
// unfortunately we can't put everything in a computeIfAbsent() since we also throw exceptions
WRAPPER_BY_RESOURCE_LOCATION.putIfAbsent(resourceStateString, foundWrapper);
WRAPPER_BY_RESOURCE_LOCATION.putIfAbsent(finalResourceStateString, foundWrapper);
}
}