From 73a086f50cbbd2402af2638a2e8b1bf6456424d2 Mon Sep 17 00:00:00 2001 From: Dries007 Date: Tue, 19 Jan 2016 02:09:58 +0100 Subject: [PATCH] Fixed lilypad spawning --- .../d3core/util/FMLEventHandler.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/doubledoordev/d3core/util/FMLEventHandler.java b/src/main/java/net/doubledoordev/d3core/util/FMLEventHandler.java index 835e711..6cd479a 100644 --- a/src/main/java/net/doubledoordev/d3core/util/FMLEventHandler.java +++ b/src/main/java/net/doubledoordev/d3core/util/FMLEventHandler.java @@ -39,6 +39,7 @@ import cpw.mods.fml.relauncher.Side; import net.doubledoordev.d3core.D3Core; import net.minecraft.block.material.Material; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.util.ChatComponentText; import net.minecraft.util.IChatComponent; @@ -115,23 +116,32 @@ public void playerLoggedInEvent(PlayerEvent.PlayerLoggedInEvent event) e.printStackTrace(); } } + + if (lilypad) lilypad(event.player); } @SubscribeEvent public void playerRespawnEvent(PlayerEvent.PlayerRespawnEvent event) { - if (lilypad) - { - World world = event.player.worldObj; - int x = (int)(event.player.posX); - int y = (int)(event.player.posY); - int z = (int)(event.player.posZ); + if (lilypad) lilypad(event.player); + } - if (x < 0) x --; - if (z < 0) z --; + private void lilypad(EntityPlayer player) + { + World world = player.worldObj; + int x = (int)(player.posX); + int y = (int)(player.posY); + int z = (int)(player.posZ); + + if (x < 0) x --; + if (z < 0) z --; - while (world.getBlock(x, y, z).getMaterial() == Material.air) y--; - if (world.getBlock(x, y, z).getMaterial() == Material.water) world.setBlock(x, y + 1, z, Blocks.waterlily); + while (world.getBlock(x, y, z).getMaterial() == Material.water) y++; + while (world.getBlock(x, y, z).getMaterial() == Material.air) y--; + if (world.getBlock(x, y, z).getMaterial() == Material.water) + { + world.setBlock(x, y + 1, z, Blocks.waterlily); + player.setPositionAndUpdate(x + 0.5, y + 2, z + 0.5); } } }