diff --git a/src/minecraft/biomesoplenty/blocks/BlockBOPFlower.java b/src/minecraft/biomesoplenty/blocks/BlockBOPFlower.java index 2f572ba23..dfa6c1a4a 100644 --- a/src/minecraft/biomesoplenty/blocks/BlockBOPFlower.java +++ b/src/minecraft/biomesoplenty/blocks/BlockBOPFlower.java @@ -3,6 +3,7 @@ package biomesoplenty.blocks; import java.util.List; import biomesoplenty.BiomesOPlenty; +import biomesoplenty.api.Blocks; import biomesoplenty.blocks.renderers.FoliageRenderer; import net.minecraft.block.Block; @@ -105,6 +106,50 @@ public class BlockBOPFlower extends BlockFlower list.add(new ItemStack(blockID, 1, i)); } + protected boolean canThisPlantGrowOnThisBlockID(int id, int meta) + { + switch (meta) + { + case 10: // Toadstool + return id == Block.grass.blockID || id == Block.dirt.blockID || id == Block.mycelium.blockID; + + case 11: // Cactus + return id == Block.sand.blockID; + + default: + return id == Block.grass.blockID || id == Block.dirt.blockID || id == Block.tilledField.blockID; + } + } + + @Override + public boolean canPlaceBlockOnSide(World world, int x, int y, int z, int side, ItemStack itemStack) + { + int id = world.getBlockId(x, y - 1, z); + int meta = itemStack.getItemDamage(); + + if (itemStack.itemID == this.blockID) + switch (meta) + { + case 10: // Toadstool + return id == Block.grass.blockID || id == Block.dirt.blockID || id == Block.mycelium.blockID; + + case 11: // Cactus + return id == Block.sand.blockID; + + default: + return id == Block.grass.blockID || id == Block.dirt.blockID || id == Block.tilledField.blockID; + } + else + return this.canPlaceBlockOnSide(world, x, y, z, side); + } + + @Override + public boolean canBlockStay(World world, int x, int y, int z) + { + return (world.getFullBlockLightValue(x, y, z) >= 8 || world.canBlockSeeTheSky(x, y, z)) + && this.canThisPlantGrowOnThisBlockID(world.getBlockId(x, y - 1, z), world.getBlockMetadata(x, y, z)); + } + @Override public int damageDropped(int meta) { diff --git a/src/minecraft/biomesoplenty/blocks/BlockBOPFoliage.java b/src/minecraft/biomesoplenty/blocks/BlockBOPFoliage.java index 7a0a03a44..213359e60 100644 --- a/src/minecraft/biomesoplenty/blocks/BlockBOPFoliage.java +++ b/src/minecraft/biomesoplenty/blocks/BlockBOPFoliage.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Random; import biomesoplenty.BiomesOPlenty; +import biomesoplenty.api.Blocks; import biomesoplenty.blocks.renderers.FoliageRenderer; import net.minecraft.block.Block; @@ -74,15 +75,30 @@ public class BlockBOPFoliage extends BlockFlower implements IShearable } @Override - public boolean canPlaceBlockAt(World world, int x, int y, int z) + public boolean canPlaceBlockOnSide(World world, int x, int y, int z, int side, ItemStack itemStack) { - return super.canPlaceBlockAt(world, x, y, z) && this.canThisPlantGrowOnThisBlockID(world.getBlockId(x, y - 1, z), world.getBlockMetadata(x, y, z)); - } + int id = world.getBlockId(x, y - 1, z); + int meta = itemStack.getItemDamage(); + + if (itemStack.itemID == this.blockID) + switch (meta) + { + case ALGAE: // Dead Grass + return id == Block.waterStill.blockID; + default: + return id == Block.grass.blockID || id == Block.dirt.blockID || id == Block.tilledField.blockID; + } + else + return this.canPlaceBlockOnSide(world, x, y, z, side); + } + protected boolean canThisPlantGrowOnThisBlockID(int blockID, int metadata) { if (metadata == GRASSTOP) return blockID == this.blockID; + else if (metadata == ALGAE) + return blockID == Block.waterStill.blockID; else return blockID == Block.grass.blockID || blockID == Block.dirt.blockID || blockID == Block.tilledField.blockID; } @@ -90,7 +106,8 @@ public class BlockBOPFoliage extends BlockFlower implements IShearable @Override public boolean canBlockStay(World world, int x, int y, int z) { - return (world.getFullBlockLightValue(x, y, z) >= 8 || world.canBlockSeeTheSky(x, y, z)) && this.canThisPlantGrowOnThisBlockID(world.getBlockId(x, y - 1, z), world.getBlockMetadata(x, y, z)); + return (world.getFullBlockLightValue(x, y, z) >= 8 || world.canBlockSeeTheSky(x, y, z)) + && this.canThisPlantGrowOnThisBlockID(world.getBlockId(x, y - 1, z), world.getBlockMetadata(x, y, z)); } @Override @@ -98,6 +115,10 @@ public class BlockBOPFoliage extends BlockFlower implements IShearable { super.onNeighborBlockChange(world, x, y, z, neighborID); this.checkFlowerChange(world, x, y, z); + if (world.getBlockMetadata(x, y, z) == GRASSTOP && world.getBlockId(x, y - 1, z) == this.blockID && world.getBlockMetadata(x, y - 1, z) != GRASSBOTTOM) + world.setBlockToAir(x, y, z); + if (world.getBlockMetadata(x, y, z) == GRASSBOTTOM && world.getBlockId(x, y + 1, z) != this.blockID) + world.setBlockToAir(x, y, z); } @Override diff --git a/src/minecraft/biomesoplenty/blocks/BlockBOPPlant.java b/src/minecraft/biomesoplenty/blocks/BlockBOPPlant.java index d51d17a09..4c21031d2 100644 --- a/src/minecraft/biomesoplenty/blocks/BlockBOPPlant.java +++ b/src/minecraft/biomesoplenty/blocks/BlockBOPPlant.java @@ -91,15 +91,8 @@ public class BlockBOPPlant extends BlockFlower implements IShearable list.add(new ItemStack(blockID, 1, i)); } -// @Override -// public boolean canPlaceBlockAt(World world, int x, int y, int z) -// { -// return true;//super.canPlaceBlockAt(world, x, y, z) && this.canThisPlantGrowOnThisBlockID(world.getBlockId(x, y - 1, z), world.getBlockMetadata(x, y, z)); -// } - protected boolean canThisPlantGrowOnThisBlockID(int id, int meta) { - // TODO switch (meta) { case 0: // Dead Grass diff --git a/src/minecraft/biomesoplenty/items/ItemBOPFlower.java b/src/minecraft/biomesoplenty/items/ItemBOPFlower.java index d492c488d..8504809a8 100644 --- a/src/minecraft/biomesoplenty/items/ItemBOPFlower.java +++ b/src/minecraft/biomesoplenty/items/ItemBOPFlower.java @@ -1,9 +1,12 @@ package biomesoplenty.items; import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.util.Icon; +import net.minecraft.world.World; public class ItemBOPFlower extends ItemBlock { @@ -33,4 +36,64 @@ public class ItemBOPFlower extends ItemBlock { return Block.blocksList[this.itemID].getIcon(0, meta); } + + @Override + public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) + { + int id = world.getBlockId(x, y, z); + + if (id == Block.snow.blockID && (world.getBlockMetadata(x, y, z) & 7) < 1) + side = 1; + else if (!Block.blocksList[id].isBlockReplaceable(world, x, y, z)) + { + if (side == 0) + --y; + + if (side == 1) + ++y; + + if (side == 2) + --z; + + if (side == 3) + ++z; + + if (side == 4) + --x; + + if (side == 5) + ++x; + } + + if (!player.canPlayerEdit(x, y, z, side, itemStack)) + { + return false; + } + else if (itemStack.stackSize == 0) + { + return false; + } + else + { + if (world.canPlaceEntityOnSide(this.getBlockID(), x, y, z, false, side, (Entity)null, itemStack)) + { + Block block = Block.blocksList[this.getBlockID()]; + int j1 = block.onBlockPlaced(world, x, y, z, side, hitX, hitY, hitZ, 0); + + if (world.setBlock(x, y, z, this.getBlockID(), itemStack.getItemDamage(), 3)) + { + if (world.getBlockId(x, y, z) == this.getBlockID()) + { + Block.blocksList[this.getBlockID()].onBlockPlacedBy(world, x, y, z, player, itemStack); + Block.blocksList[this.getBlockID()].onPostBlockPlaced(world, x, y, z, j1); + } + + world.playSoundEffect((double)((float)x + 0.5F), (double)((float)y + 0.5F), (double)((float)z + 0.5F), block.stepSound.getPlaceSound(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F); + --itemStack.stackSize; + } + } + + return true; + } + } } diff --git a/src/minecraft/biomesoplenty/items/ItemBOPFoliage.java b/src/minecraft/biomesoplenty/items/ItemBOPFoliage.java index 05333c4c0..23e578a04 100644 --- a/src/minecraft/biomesoplenty/items/ItemBOPFoliage.java +++ b/src/minecraft/biomesoplenty/items/ItemBOPFoliage.java @@ -1,11 +1,15 @@ package biomesoplenty.items; import net.minecraft.block.Block; +import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumMovingObjectType; import net.minecraft.util.Icon; +import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -52,29 +56,105 @@ public class ItemBOPFoliage extends ItemBlock return textures[meta]; } + public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) + { + if (itemStack.getItemDamage() != 0) + return super.onItemRightClick(itemStack, world, player); + + MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(world, player, true); + + if (movingobjectposition == null) + return itemStack; + else + { + if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE) + { + int i = movingobjectposition.blockX; + int j = movingobjectposition.blockY; + int k = movingobjectposition.blockZ; + + if (!world.canMineBlock(player, i, j, k)) + return itemStack; + + if (!player.canPlayerEdit(i, j, k, movingobjectposition.sideHit, itemStack)) + return itemStack; + + if (world.getBlockMaterial(i, j, k) == Material.water && world.getBlockMetadata(i, j, k) == 0 && world.isAirBlock(i, j + 1, k)) + { + world.setBlock(i, j + 1, k, itemStack.itemID, 0, 2); + + if (!player.capabilities.isCreativeMode) + { + --itemStack.stackSize; + } + } + } + + return itemStack; + } + } + public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { - - if (itemStack.getItemDamage() != 3) - { + if (itemStack.getItemDamage() == 0) return super.onItemUse(itemStack, player, world, x, y, z, side, hitX, hitY, hitZ); - } - else + + int id = world.getBlockId(x, y, z); + + if (id == Block.snow.blockID && (world.getBlockMetadata(x, y, z) & 7) < 1) + side = 1; + else if (!Block.blocksList[id].isBlockReplaceable(world, x, y, z)) { - ++y; - - if (!(player.canPlayerEdit(x, y, z, side, itemStack) || player.canPlayerEdit(x, y + 1, z, side, itemStack))) - return false; - else if (world.getBlockMaterial(x, y, z).isReplaceable() && world.getBlockMaterial(x, y + 1, z).isReplaceable()) + if (side == 0) + --y; + + if (side == 1) + ++y; + + if (side == 2) + --z; + + if (side == 3) + ++z; + + if (side == 4) + --x; + + if (side == 5) + ++x; + } + + if (!player.canPlayerEdit(x, y, z, side, itemStack)) + { + return false; + } + else if (itemStack.stackSize == 0) + { + return false; + } + else + { + if (world.canPlaceEntityOnSide(this.getBlockID(), x, y, z, false, side, (Entity)null, itemStack)) { - world.setBlock(x, y, z, itemStack.itemID, 3, 2); - world.setBlock(x, y + 1, z, itemStack.itemID, 6, 2); - world.notifyBlocksOfNeighborChange(x, y, z, itemStack.itemID); - world.notifyBlocksOfNeighborChange(x, y + 1, z, itemStack.itemID); - Block block = Block.blocksList[itemStack.itemID]; - world.playSoundEffect((double)((float)x + 0.5F), (double)((float)y + 0.5F), (double)((float)z + 0.5F), block.stepSound.getPlaceSound(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F); - --itemStack.stackSize; + Block block = Block.blocksList[this.getBlockID()]; + int j1 = block.onBlockPlaced(world, x, y, z, side, hitX, hitY, hitZ, 0); + + if (world.setBlock(x, y, z, this.getBlockID(), itemStack.getItemDamage(), 3)) + { + if (itemStack.getItemDamage() == 3 && world.getBlockMaterial(x, y + 1, z).isReplaceable()) + world.setBlock(x, y + 1, z, this.getBlockID(), 6, 2); + + if (world.getBlockId(x, y, z) == this.getBlockID()) + { + Block.blocksList[this.getBlockID()].onBlockPlacedBy(world, x, y, z, player, itemStack); + Block.blocksList[this.getBlockID()].onPostBlockPlaced(world, x, y, z, j1); + } + + world.playSoundEffect((double)((float)x + 0.5F), (double)((float)y + 0.5F), (double)((float)z + 0.5F), block.stepSound.getPlaceSound(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F); + --itemStack.stackSize; + } } + return true; } } diff --git a/src/minecraft/biomesoplenty/items/ItemBOPPlant.java b/src/minecraft/biomesoplenty/items/ItemBOPPlant.java index 839b449ef..afaa473ca 100644 --- a/src/minecraft/biomesoplenty/items/ItemBOPPlant.java +++ b/src/minecraft/biomesoplenty/items/ItemBOPPlant.java @@ -56,6 +56,7 @@ public class ItemBOPPlant extends ItemBlock return Block.blocksList[this.itemID].getIcon(0, meta); } + @Override public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { int id = world.getBlockId(x, y, z);