From 7b7c21f16199423141341f7d5c16b22809a44a93 Mon Sep 17 00:00:00 2001 From: Adubbz Date: Thu, 16 Jan 2014 08:43:13 +1100 Subject: [PATCH] Added checks to ensure that the player is on land when spawning (sometimes they would spawn in the ocean directly next to a beach) --- .../common/world/WorldProviderSurfaceBOP.java | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/main/java/biomesoplenty/common/world/WorldProviderSurfaceBOP.java b/src/main/java/biomesoplenty/common/world/WorldProviderSurfaceBOP.java index a0f0b0301..54584d149 100644 --- a/src/main/java/biomesoplenty/common/world/WorldProviderSurfaceBOP.java +++ b/src/main/java/biomesoplenty/common/world/WorldProviderSurfaceBOP.java @@ -1,7 +1,9 @@ package biomesoplenty.common.world; import net.minecraft.block.Block; +import net.minecraft.block.material.Material; import net.minecraft.init.Blocks; +import net.minecraft.world.World; import net.minecraft.world.WorldProviderSurface; public class WorldProviderSurfaceBOP extends WorldProviderSurface @@ -9,9 +11,39 @@ public class WorldProviderSurfaceBOP extends WorldProviderSurface @Override public boolean canCoordinateBeSpawn(int x, int z) { - //TODO: getTopBlock() - Block topBlock = this.worldObj.func_147474_b(x, z); + int y = getTopBlockCoord(this.worldObj, x, z); + //TODO: getBlock() + Block topBlock = this.worldObj.func_147439_a(x, y, z); + boolean flag = topBlock == Blocks.sand || topBlock == Blocks.stone || topBlock == Blocks.snow_layer && this.worldChunkMgr.getBiomesToSpawnIn().contains(this.worldObj.getBiomeGenForCoordsBody(x, z)); + boolean isClear = true; - return topBlock == Blocks.sand || topBlock == Blocks.stone || topBlock == Blocks.snow_layer && this.worldChunkMgr.getBiomesToSpawnIn().contains(this.worldObj.getBiomeGenForCoordsBody(x, z)); + for (int ix = -1; ix <= 1; ix++) + { + for (int iy = -2; iy <= 2; iy++) + { + for (int iz = -1; iz <= 1; iz++) + { + if (this.worldObj.func_147439_a(x, y, z).func_149688_o() == Material.field_151586_h) + { + isClear = false; + break; + } + } + } + } + + return flag && isClear; + } + + public int getTopBlockCoord(World world, int x, int z) + { + int y; + + for (y = 63; !world.func_147437_c(x, y + 1, z); ++y) + { + ; + } + + return y; } }