diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/util/BiomeMath.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/util/BiomeMath.java index a8e4a9518..f5ff7f22e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/util/BiomeMath.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/util/BiomeMath.java @@ -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; diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorld.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorld.java index e5dc9253e..9204d55ab 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorld.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorld.java @@ -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); diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java index 63737c65b..dba0d45c5 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java @@ -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); }