Fix Biome math on Forge and Fabric

This commit is contained in:
Octavia Togami 2020-05-18 16:19:11 -07:00
parent a2c541bdac
commit 6b918e671e
3 changed files with 14 additions and 9 deletions

View File

@ -41,9 +41,9 @@ private BiomeMath() {
* @return the index into the standard MC biome array
*/
public static int computeBiomeIndex(int x, int y, int z) {
int l = x & HORIZONTAL_BIT_MASK;
int m = MathHelper.clamp(y, 0, VERTICAL_BIT_MASK);
int n = z & HORIZONTAL_BIT_MASK;
int l = (x >> 2) & HORIZONTAL_BIT_MASK;
int m = MathHelper.clamp(y >> 2, 0, VERTICAL_BIT_MASK);
int n = (z >> 2) & HORIZONTAL_BIT_MASK;
return m << HORIZONTAL_SECTION_COUNT + HORIZONTAL_SECTION_COUNT
| n << HORIZONTAL_SECTION_COUNT
| l;

View File

@ -36,7 +36,6 @@
import com.sk89q.worldedit.fabric.internal.NBTConverter;
import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.internal.util.BiomeMath;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
@ -74,6 +73,7 @@
import net.minecraft.world.World;
import net.minecraft.world.WorldSaveHandler;
import net.minecraft.world.biome.DefaultBiomeFeatures;
import net.minecraft.world.biome.source.BiomeArray;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkManager;
import net.minecraft.world.chunk.ChunkStatus;
@ -204,7 +204,9 @@ public boolean clearContainerBlockContents(BlockVector3 position) {
@Override
public BiomeType getBiome(BlockVector2 position) {
checkNotNull(position);
return FabricAdapter.adapt(getWorld().getBiome(new BlockPos(position.getBlockX(), 0, position.getBlockZ())));
Chunk chunk = getWorld().getChunk(position.getX() >> 4, position.getZ() >> 4);
BiomeArray biomeArray = checkNotNull(chunk.getBiomeArray());
return FabricAdapter.adapt(biomeArray.getBiomeForNoiseGen(position.getX() >> 2, 0, position.getZ() >> 2));
}
@Override
@ -216,9 +218,9 @@ public boolean setBiome(BlockVector2 position, BiomeType biome) {
if (chunk == null) {
return false;
}
MutableBiomeArray biomeArray = MutableBiomeArray.inject(chunk.getBiomeArray());
MutableBiomeArray biomeArray = MutableBiomeArray.inject(checkNotNull(chunk.getBiomeArray()));
// Temporary, while biome setting is 2D only
for (int i = 0; i < BiomeMath.VERTICAL_BIT_MASK; i++) {
for (int i = 0; i <= getMaxY(); i++) {
biomeArray.setBiome(position.getX(), i, position.getZ(), FabricAdapter.adapt(biome));
}
chunk.setShouldSave(true);

View File

@ -203,7 +203,10 @@ public boolean clearContainerBlockContents(BlockVector3 position) {
@Override
public BiomeType getBiome(BlockVector2 position) {
checkNotNull(position);
return ForgeAdapter.adapt(getWorld().getBiome(new BlockPos(position.getBlockX(), 0, position.getBlockZ())));
IChunk chunk = getWorld().getChunk(position.getBlockX() >> 4, position.getBlockZ() >> 4);
BiomeContainer biomes = checkNotNull(chunk.getBiomes());
return ForgeAdapter.adapt(biomes.getNoiseBiome(position.getX() >> 2, 0, position.getZ() >> 2));
}
@Override
@ -217,7 +220,7 @@ public boolean setBiome(BlockVector2 position, BiomeType biome) {
return false;
}
// Temporary, while biome setting is 2D only
for (int i = 0; i < BiomeMath.VERTICAL_BIT_MASK; i++) {
for (int i = 0; i <= getMaxY(); i++) {
int idx = BiomeMath.computeBiomeIndex(position.getX(), i, position.getZ());
container.biomes[idx] = ForgeAdapter.adapt(biome);
}