Better sanity checks in ModelDataManager

This commit is contained in:
tterrag 2019-10-10 16:02:09 -04:00
parent 7070bd0340
commit 940bbc4e91
1 changed files with 4 additions and 3 deletions

View File

@ -53,6 +53,8 @@ public class ModelDataManager
private static void cleanCaches(World world) private static void cleanCaches(World world)
{ {
Preconditions.checkNotNull(world, "World must not be null");
Preconditions.checkArgument(world == Minecraft.getInstance().world, "Cannot use model data for a world other than the current client world");
if (world != currentWorld.get()) if (world != currentWorld.get())
{ {
currentWorld = new WeakReference<>(world); currentWorld = new WeakReference<>(world);
@ -63,9 +65,8 @@ public class ModelDataManager
public static void requestModelDataRefresh(TileEntity te) public static void requestModelDataRefresh(TileEntity te)
{ {
Preconditions.checkNotNull(te, "Tile entity must not be null");
World world = te.getWorld(); World world = te.getWorld();
Preconditions.checkNotNull(world, "Tile entity world must not be null");
Preconditions.checkArgument(world == Minecraft.getInstance().world, "Cannot request a model data refresh for a world other than the current client world");
cleanCaches(world); cleanCaches(world);
needModelDataRefresh.computeIfAbsent(new ChunkPos(te.getPos()), $ -> Collections.synchronizedSet(new HashSet<>())) needModelDataRefresh.computeIfAbsent(new ChunkPos(te.getPos()), $ -> Collections.synchronizedSet(new HashSet<>()))
@ -108,7 +109,7 @@ public class ModelDataManager
public static Map<BlockPos, IModelData> getModelData(World world, ChunkPos pos) public static Map<BlockPos, IModelData> getModelData(World world, ChunkPos pos)
{ {
Preconditions.checkArgument(world.isRemote, "Asked ModelDataManager from server world!"); Preconditions.checkArgument(world.isRemote, "Cannot request model data for server world");
refreshModelData(world, pos); refreshModelData(world, pos);
return modelDataCache.getOrDefault(pos, Collections.emptyMap()); return modelDataCache.getOrDefault(pos, Collections.emptyMap());
} }