Small enhancements
This commit is contained in:
parent
015d60aee1
commit
97ad8b44aa
2 changed files with 29 additions and 13 deletions
|
@ -54,14 +54,14 @@ public class DataFixerAPI {
|
|||
}
|
||||
|
||||
private static boolean wrapCall(LevelStorageSource levelSource, String levelID, Function<LevelStorageAccess, Boolean> runWithLevel) {
|
||||
|
||||
LevelStorageSource.LevelStorageAccess levelStorageAccess;
|
||||
try {
|
||||
levelStorageAccess = levelSource.createAccess(levelID);
|
||||
} catch (IOException e) {
|
||||
BCLib.LOGGER.warning((String)"Failed to read level {} data", levelID, e);
|
||||
}
|
||||
catch (IOException e) {
|
||||
BCLib.LOGGER.warning("Failed to read level {} data", levelID, e);
|
||||
SystemToast.onWorldAccessFailure(Minecraft.getInstance(), levelID);
|
||||
Minecraft.getInstance().setScreen((Screen)null);
|
||||
Minecraft.getInstance().setScreen(null);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -69,8 +69,9 @@ public class DataFixerAPI {
|
|||
|
||||
try {
|
||||
levelStorageAccess.close();
|
||||
} catch (IOException e) {
|
||||
BCLib.LOGGER.warning((String)"Failed to unlock access to level {}", levelID, e);
|
||||
}
|
||||
catch (IOException e) {
|
||||
BCLib.LOGGER.warning("Failed to unlock access to level {}", levelID, e);
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
|
|
|
@ -5,35 +5,50 @@ import ru.bclib.world.biomes.BCLBiome;
|
|||
import java.util.Random;
|
||||
|
||||
public class BiomeChunk {
|
||||
protected static final int WIDTH = 16;
|
||||
private static final int BIT_OFFSET = 4;
|
||||
protected static final int WIDTH = 1 << BIT_OFFSET;
|
||||
private static final int SM_WIDTH = WIDTH >> 1;
|
||||
private static final int SM_BIT_OFFSET = BIT_OFFSET >> 1;
|
||||
private static final int MASK_OFFSET = SM_WIDTH - 1;
|
||||
protected static final int MASK_WIDTH = WIDTH - 1;
|
||||
|
||||
private final BCLBiome[][] biomes;
|
||||
private static final int SM_CAPACITY = SM_WIDTH * SM_WIDTH;
|
||||
private static final int CAPACITY = WIDTH * WIDTH;
|
||||
|
||||
private final BCLBiome[] biomes;
|
||||
|
||||
public BiomeChunk(BiomeMap map, Random random, BiomePicker picker) {
|
||||
BCLBiome[][] PreBio = new BCLBiome[SM_WIDTH][SM_WIDTH];
|
||||
biomes = new BCLBiome[WIDTH][WIDTH];
|
||||
BCLBiome[] PreBio = new BCLBiome[SM_CAPACITY];
|
||||
biomes = new BCLBiome[CAPACITY];
|
||||
|
||||
for (int x = 0; x < SM_WIDTH; x++) {
|
||||
int offset = x << SM_BIT_OFFSET;
|
||||
for (int z = 0; z < SM_WIDTH; z++) {
|
||||
PreBio[x][z] = picker.getBiome(random);
|
||||
PreBio[offset | z] = picker.getBiome(random);
|
||||
}
|
||||
}
|
||||
|
||||
for (int x = 0; x < WIDTH; x++) {
|
||||
int offset = x << BIT_OFFSET;
|
||||
for (int z = 0; z < WIDTH; z++) {
|
||||
biomes[x][z] = PreBio[offsetXZ(x, random)][offsetXZ(z, random)].getSubBiome(random);
|
||||
biomes[offset | z] = PreBio[getSmIndex(offsetXZ(x, random), offsetXZ(z, random))].getSubBiome(random);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BCLBiome getBiome(int x, int z) {
|
||||
return biomes[x & MASK_WIDTH][z & MASK_WIDTH];
|
||||
return biomes[getIndex(x & MASK_WIDTH, z & MASK_WIDTH)];
|
||||
}
|
||||
|
||||
private int offsetXZ(int x, Random random) {
|
||||
return ((x + random.nextInt(2)) >> 1) & MASK_OFFSET;
|
||||
}
|
||||
|
||||
private int getIndex(int x, int z) {
|
||||
return x << BIT_OFFSET | z;
|
||||
}
|
||||
|
||||
private int getSmIndex(int x, int z) {
|
||||
return x << SM_BIT_OFFSET | z;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue