diff options
author | Mike Primm <mike@primmhome.com> | 2012-03-04 10:41:06 -0600 |
---|---|---|
committer | EvilSeph <evilseph@gmail.com> | 2012-03-08 01:53:06 -0500 |
commit | a029f32ccd78ce427781fcb81310590f0fca7e09 (patch) | |
tree | 5d8b93552a1907f1a26eb7e623473460cda0e190 | |
parent | b5e92871eb5b2195c187e0082fe22d9e3eb3b7e4 (diff) | |
download | craftbukkit-a029f32ccd78ce427781fcb81310590f0fca7e09.tar craftbukkit-a029f32ccd78ce427781fcb81310590f0fca7e09.tar.gz craftbukkit-a029f32ccd78ce427781fcb81310590f0fca7e09.tar.lz craftbukkit-a029f32ccd78ce427781fcb81310590f0fca7e09.tar.xz craftbukkit-a029f32ccd78ce427781fcb81310590f0fca7e09.zip |
[Bleeding] Add APIs for editing biome data, fix existing code to use persistent biome data. Addresses BUKKIT-1075
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/CraftChunk.java | 8 | ||||
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/CraftWorld.java | 16 | ||||
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java | 16 |
3 files changed, 34 insertions, 6 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java index 1634072c..0038c565 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java @@ -216,7 +216,9 @@ public class CraftChunk implements Chunk { if (includeBiome) { biome = new BiomeBase[256]; - wcm.getBiomeBlock(biome, x << 4, z << 4, 16, 16); + for (int i = 0; i < 256; i++) { + biome[i] = chunk.a(i & 0xF, i >> 4, wcm); + } } if (includeBiomeTempRain) { @@ -250,7 +252,9 @@ public class CraftChunk implements Chunk { if (includeBiome) { biome = new BiomeBase[256]; - wcm.getBiomeBlock(biome, x << 4, z << 4, 16, 16); + for (int i = 0; i < 256; i++) { + biome[i] = world.getHandle().getBiome((x << 4) + (i & 0xF), (z << 4) + (i >> 4)); + } } if (includeBiomeTempRain) { diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 6b9553eb..94f38747 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -39,7 +39,6 @@ import org.bukkit.Bukkit; import org.bukkit.generator.ChunkGenerator; import org.bukkit.ChunkSnapshot; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.TreeType; import org.bukkit.World; import org.bukkit.block.Biome; @@ -48,7 +47,6 @@ import org.bukkit.Difficulty; import org.bukkit.craftbukkit.block.CraftBlock; import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.plugin.messaging.StandardMessenger; -import org.bukkit.potion.Potion; public class CraftWorld implements World { private final WorldServer world; @@ -491,9 +489,19 @@ public class CraftWorld implements World { } public Biome getBiome(int x, int z) { - BiomeBase base = getHandle().getWorldChunkManager().getBiome(x, z); + return CraftBlock.biomeBaseToBiome(this.world.getBiome(x, z)); + } + + public void setBiome(int x, int z, Biome bio) { + BiomeBase bb = CraftBlock.biomeToBiomeBase(bio); + if (this.world.isLoaded(x, 0, z)) { + net.minecraft.server.Chunk chunk = this.world.getChunkAtWorldCoords(x, z); - return CraftBlock.biomeBaseToBiome(base); + if (chunk != null) { + byte[] biomevals = chunk.l(); + biomevals[((z & 0xF) << 4) | (x & 0xF)] = (byte)bb.id; + } + } } public double getTemperature(int x, int z) { diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java index ec8d156a..368cea99 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java @@ -31,6 +31,7 @@ public class CraftBlock implements Block { private final int y; private final int z; private static final Biome BIOME_MAPPING[]; + private static final BiomeBase BIOMEBASE_MAPPING[]; public CraftBlock(CraftChunk chunk, int x, int y, int z) { this.x = x; @@ -248,6 +249,10 @@ public class CraftBlock implements Block { return getWorld().getBiome(x, z); } + public void setBiome(Biome bio) { + getWorld().setBiome(x, z, bio); + } + public static Biome biomeBaseToBiome(BiomeBase base) { if (base == null) { return null; @@ -256,6 +261,13 @@ public class CraftBlock implements Block { return BIOME_MAPPING[base.id]; } + public static BiomeBase biomeToBiomeBase(Biome bio) { + if (bio == null) { + return null; + } + return BIOMEBASE_MAPPING[bio.ordinal()]; + } + public double getTemperature() { return getWorld().getTemperature(x, z); } @@ -378,6 +390,7 @@ public class CraftBlock implements Block { /* Build biome index based lookup table for BiomeBase to Biome mapping */ static { BIOME_MAPPING = new Biome[BiomeBase.biomes.length]; + BIOMEBASE_MAPPING = new BiomeBase[Biome.values().length]; BIOME_MAPPING[BiomeBase.SWAMPLAND.id] = Biome.SWAMPLAND; BIOME_MAPPING[BiomeBase.FOREST.id] = Biome.FOREST; BIOME_MAPPING[BiomeBase.TAIGA.id] = Biome.TAIGA; @@ -407,6 +420,9 @@ public class CraftBlock implements Block { if ((BiomeBase.biomes[i] != null) && (BIOME_MAPPING[i] == null)) { throw new IllegalArgumentException("Missing Biome mapping for BiomeBase[" + i + "]"); } + if (BIOME_MAPPING[i] != null) { /* Build reverse mapping for setBiome */ + BIOMEBASE_MAPPING[BIOME_MAPPING[i].ordinal()] = BiomeBase.biomes[i]; + } } } |