From 518e3c19a7e7f81bd7446ce5d34da45af71672c2 Mon Sep 17 00:00:00 2001 From: Amnet Date: Tue, 9 Apr 2013 16:55:50 +0200 Subject: [PATCH] Fixed placing Moss, TreeMoss and Willow. TreeMoss and Willow are now using IShearable interface. --- .../tdwp_ftw/biomesop/blocks/BlockMoss.java | 25 ++++++++ .../biomesop/blocks/BlockTreeMoss.java | 63 +++++++++++++------ .../tdwp_ftw/biomesop/blocks/BlockWillow.java | 53 +++++++++++++--- 3 files changed, 113 insertions(+), 28 deletions(-) diff --git a/src/minecraft/tdwp_ftw/biomesop/blocks/BlockMoss.java b/src/minecraft/tdwp_ftw/biomesop/blocks/BlockMoss.java index 0526c2d9c..513fa4941 100644 --- a/src/minecraft/tdwp_ftw/biomesop/blocks/BlockMoss.java +++ b/src/minecraft/tdwp_ftw/biomesop/blocks/BlockMoss.java @@ -433,6 +433,31 @@ public class BlockMoss extends Block } } + /** + * Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY, hitZ, block metadata + */ + public int onBlockPlaced(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9) + { + byte b0 = 0; + + switch (par5) + { + case 2: + b0 = 1; + break; + case 3: + b0 = 4; + break; + case 4: + b0 = 8; + break; + case 5: + b0 = 2; + } + + return b0 != 0 ? b0 : par9; + } + /** * Returns the ID of the items to drop on destruction. */ diff --git a/src/minecraft/tdwp_ftw/biomesop/blocks/BlockTreeMoss.java b/src/minecraft/tdwp_ftw/biomesop/blocks/BlockTreeMoss.java index 683db5af3..11e2691b7 100644 --- a/src/minecraft/tdwp_ftw/biomesop/blocks/BlockTreeMoss.java +++ b/src/minecraft/tdwp_ftw/biomesop/blocks/BlockTreeMoss.java @@ -1,25 +1,21 @@ package tdwp_ftw.biomesop.blocks; +import java.util.ArrayList; import java.util.Random; -import tdwp_ftw.biomesop.mod_BiomesOPlenty; -import tdwp_ftw.biomesop.declarations.BOPBlocks; - import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.stats.StatList; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.Direction; -import net.minecraft.world.ColorizerFoliage; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import net.minecraftforge.common.IShearable; +import tdwp_ftw.biomesop.mod_BiomesOPlenty; -public class BlockTreeMoss extends Block +public class BlockTreeMoss extends Block implements IShearable { public BlockTreeMoss(int par1) { @@ -236,7 +232,7 @@ public class BlockTreeMoss extends Block if (!par1World.isRemote && !this.canVineStay(par1World, par2, par3, par4)) { this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0); - par1World.setBlock(par2, par3, par4, 0); + par1World.setBlockToAir(par2, par3, par4); } } @@ -278,6 +274,31 @@ public class BlockTreeMoss extends Block } } + /** + * Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY, hitZ, block metadata + */ + public int onBlockPlaced(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9) + { + byte b0 = 0; + + switch (par5) + { + case 2: + b0 = 1; + break; + case 3: + b0 = 4; + break; + case 4: + b0 = 8; + break; + case 5: + b0 = 2; + } + + return b0 != 0 ? b0 : par9; + } + /** * Returns the ID of the items to drop on destruction. */ @@ -300,14 +321,20 @@ public class BlockTreeMoss extends Block */ public void harvestBlock(World par1World, EntityPlayer par2EntityPlayer, int par3, int par4, int par5, int par6) { - if (!par1World.isRemote && par2EntityPlayer.getCurrentEquippedItem() != null && par2EntityPlayer.getCurrentEquippedItem().itemID == Item.shears.itemID) - { - par2EntityPlayer.addStat(StatList.mineBlockStatArray[this.blockID], 1); - this.dropBlockAsItem_do(par1World, par3, par4, par5, new ItemStack(BOPBlocks.treeMoss, 1, 0)); - } - else - { - super.harvestBlock(par1World, par2EntityPlayer, par3, par4, par5, par6); - } + super.harvestBlock(par1World, par2EntityPlayer, par3, par4, par5, par6); + } + + @Override + public boolean isShearable(ItemStack item, World world, int x, int y, int z) + { + return true; + } + + @Override + public ArrayList onSheared(ItemStack item, World world, int x, int y, int z, int fortune) + { + ArrayList ret = new ArrayList(); + ret.add(new ItemStack(this, 1, 0)); + return ret; } } diff --git a/src/minecraft/tdwp_ftw/biomesop/blocks/BlockWillow.java b/src/minecraft/tdwp_ftw/biomesop/blocks/BlockWillow.java index 4a5e1b8ce..1b28ca8b7 100644 --- a/src/minecraft/tdwp_ftw/biomesop/blocks/BlockWillow.java +++ b/src/minecraft/tdwp_ftw/biomesop/blocks/BlockWillow.java @@ -1,5 +1,6 @@ package tdwp_ftw.biomesop.blocks; +import java.util.ArrayList; import java.util.Random; import tdwp_ftw.biomesop.mod_BiomesOPlenty; @@ -18,8 +19,9 @@ import net.minecraft.util.Direction; import net.minecraft.world.ColorizerFoliage; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import net.minecraftforge.common.IShearable; -public class BlockWillow extends Block +public class BlockWillow extends Block implements IShearable { public BlockWillow(int par1) { @@ -299,6 +301,31 @@ public class BlockWillow extends Block } } + /** + * Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY, hitZ, block metadata + */ + public int onBlockPlaced(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9) + { + byte b0 = 0; + + switch (par5) + { + case 2: + b0 = 1; + break; + case 3: + b0 = 4; + break; + case 4: + b0 = 8; + break; + case 5: + b0 = 2; + } + + return b0 != 0 ? b0 : par9; + } + /** * Returns the ID of the items to drop on destruction. */ @@ -321,14 +348,20 @@ public class BlockWillow extends Block */ public void harvestBlock(World par1World, EntityPlayer par2EntityPlayer, int par3, int par4, int par5, int par6) { - if (!par1World.isRemote && par2EntityPlayer.getCurrentEquippedItem() != null && par2EntityPlayer.getCurrentEquippedItem().itemID == Item.shears.itemID) - { - par2EntityPlayer.addStat(StatList.mineBlockStatArray[this.blockID], 1); - this.dropBlockAsItem_do(par1World, par3, par4, par5, new ItemStack(BOPBlocks.willow, 1, 0)); - } - else - { - super.harvestBlock(par1World, par2EntityPlayer, par3, par4, par5, par6); - } + super.harvestBlock(par1World, par2EntityPlayer, par3, par4, par5, par6); + } + + @Override + public boolean isShearable(ItemStack item, World world, int x, int y, int z) + { + return true; + } + + @Override + public ArrayList onSheared(ItemStack item, World world, int x, int y, int z, int fortune) + { + ArrayList ret = new ArrayList(); + ret.add(new ItemStack(this, 1, 0)); + return ret; } }