Skip to content

Commit

Permalink
map the data directly in the synchronized method
Browse files Browse the repository at this point in the history
  • Loading branch information
burgerindividual committed Sep 22, 2020
1 parent 1297afa commit b57979d
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ public synchronized MinecraftInterface.WorldConfig createWorldConfig() throws Mi
}

// Only one thread can manipulate the Minecraft int cache at a time
private synchronized int[] getBiomeData(int x, int y, int width, int height, Object biomeGenerator)
private synchronized<T> T getBiomeData(int x, int y, int width, int height, Object biomeGenerator, Function<int[], T> biomeDataMapper)
throws MinecraftInterfaceException {
try {
resetIntCacheMethod.invokeExact();
int[] biomeInts = (int[]) getIntsMethod.invokeExact(biomeGenerator, x, y, width, height);
// we have to clone the array so we aren't using a reference to an array that's still in the IntCache
return biomeInts.clone();
// we have to map the array inside the synchronized method so we don't
// using a reference to an array that's still in the IntCache
return biomeDataMapper.apply(biomeInts);
} catch (Throwable e) {
throw new MinecraftInterfaceException("unable to get biome data", e);
}
Expand Down Expand Up @@ -188,8 +189,7 @@ public<T> T getBiomeData(Dimension dimension,
throw new UnsupportedDimensionException(dimension);

Object biomeGenerator = useQuarterResolution ? quarterResolutionBiomeGenerator : fullResolutionBiomeGenerator;
int[] data = LegacyMinecraftInterface.this.getBiomeData(x, y, width, height, biomeGenerator);
return biomeDataMapper.apply(data);
return LegacyMinecraftInterface.this.getBiomeData(x, y, width, height, biomeGenerator, biomeDataMapper);
}
}
}

0 comments on commit b57979d

Please sign in to comment.