Skip to content

Commit

Permalink
Fixed scythes losing their smithing bonus when used to break leaves o…
Browse files Browse the repository at this point in the history
…r crops.
  • Loading branch information
Kittychanley committed May 19, 2016
1 parent 1bce3d0 commit 83c3e2a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 55 deletions.
47 changes: 25 additions & 22 deletions src/Common/com/bioxx/tfc/Blocks/BlockCrop.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import net.minecraftforge.oredict.OreDictionary;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

Expand All @@ -26,7 +28,6 @@
import com.bioxx.tfc.Core.TFC_Core;
import com.bioxx.tfc.Food.CropIndex;
import com.bioxx.tfc.Food.CropManager;
import com.bioxx.tfc.Items.Tools.ItemCustomScythe;
import com.bioxx.tfc.TileEntities.TECrop;
import com.bioxx.tfc.api.TFCBlocks;
import com.bioxx.tfc.api.TFCOptions;
Expand Down Expand Up @@ -185,32 +186,34 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer e
@Override
public void onBlockHarvested(World world, int i, int j, int k, int l, EntityPlayer player)
{
ItemStack itemstack = player.inventory.getCurrentItem();
TECrop te = (TECrop) world.getTileEntity(i, j, k);

//Handle Scythe
if(!world.isRemote && itemstack != null && itemstack.getItem() instanceof ItemCustomScythe)
if (!world.isRemote)
{
for(int x = -1; x < 2; x++)
ItemStack itemstack = player.inventory.getCurrentItem();
int[] equipIDs = OreDictionary.getOreIDs(itemstack);

for (int id : equipIDs)
{
for(int z = -1; z < 2; z++)
String name = OreDictionary.getOreName(id);
if (name.startsWith("itemScythe"))
{
if(world.getBlock( i+x, j, k+z) == this && player.inventory.getStackInSlot(player.inventory.currentItem) != null)
for (int x = -1; x < 2; x++)
{
player.addStat(StatList.mineBlockStatArray[getIdFromBlock(this)], 1);
TECrop teX = (TECrop) world.getTileEntity(i + x, j, k + z);
teX.onHarvest(world, player, true);

//breakBlock(world, i + x, j, k + z, l, 0);
world.setBlockToAir(i + x, j, k + z);

int ss = itemstack.stackSize;
int dam = itemstack.getItemDamage() + 2;

if(dam >= itemstack.getItem().getMaxDamage())
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
else
player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(itemstack.getItem(), ss, dam));
for (int z = -1; z < 2; z++)
{
if (world.getBlock(i + x, j, k + z) == this && player.inventory.getStackInSlot(player.inventory.currentItem) != null)
{
player.addStat(StatList.mineBlockStatArray[getIdFromBlock(this)], 1);
TECrop teX = (TECrop) world.getTileEntity(i + x, j, k + z);
teX.onHarvest(world, player, true);

world.setBlockToAir(i + x, j, k + z);

itemstack.damageItem(1, player);
if (itemstack.stackSize == 0)
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
}
}
}
}
}
Expand Down
72 changes: 39 additions & 33 deletions src/Common/com/bioxx/tfc/Blocks/Vanilla/BlockCustomLeaves.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
import net.minecraft.world.World;

import net.minecraftforge.common.IShearable;
import net.minecraftforge.oredict.OreDictionary;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

import com.bioxx.tfc.Reference;
import com.bioxx.tfc.TerraFirmaCraft;
import com.bioxx.tfc.Items.Tools.ItemCustomScythe;
import com.bioxx.tfc.api.TFCBlocks;
import com.bioxx.tfc.api.TFCItems;
import com.bioxx.tfc.api.TFCOptions;
Expand Down Expand Up @@ -232,49 +232,55 @@ public void dropBlockAsItemWithChance(World world, int x, int y, int z, int meta
@Override
public void harvestBlock(World world, EntityPlayer entityplayer, int i, int j, int k, int meta)
{
ItemStack itemstack = entityplayer.inventory.getCurrentItem();
if (!world.isRemote && itemstack != null && itemstack.getItem() instanceof ItemCustomScythe)
if (!world.isRemote)
{
for(int x = -1; x < 2; x++)
ItemStack itemstack = entityplayer.inventory.getCurrentItem();
boolean foundScythe = false;
int[] equipIDs = OreDictionary.getOreIDs(itemstack);
for (int id : equipIDs)
{
for(int z = -1; z < 2; z++)
String name = OreDictionary.getOreName(id);
if (name.startsWith("itemScythe"))
{
for(int y = -1; y < 2; y++)
foundScythe = true;
for (int x = -1; x < 2; x++)
{
if(world.getBlock( i + x, j + y, k + z).getMaterial() == Material.leaves &&
entityplayer.inventory.getStackInSlot(entityplayer.inventory.currentItem) != null)
for (int z = -1; z < 2; z++)
{
entityplayer.addStat(StatList.mineBlockStatArray[getIdFromBlock(this)], 1);
entityplayer.addExhaustion(0.045F);
if(world.rand.nextInt(100) < 11)
dropBlockAsItem(world, i + x, j + y, k + z, new ItemStack(TFCItems.stick, 1));
else if (world.rand.nextInt(100) < 4 && TFCOptions.enableSaplingDrops)
dropSapling(world, i + x, j + y, k + z, meta);
removeLeaves(world, i + x, j + y, k + z);
super.harvestBlock(world, entityplayer, i + x, j + y, k + z, meta);

int ss = itemstack.stackSize;
int dam = itemstack.getItemDamage() + 2;

if(dam >= itemstack.getItem().getMaxDamage())
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, null);
else
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, new ItemStack(itemstack.getItem(), ss, dam));
for (int y = -1; y < 2; y++)
{
if (world.getBlock(i + x, j + y, k + z).getMaterial() == Material.leaves &&
entityplayer.inventory.getStackInSlot(entityplayer.inventory.currentItem) != null)
{
entityplayer.addStat(StatList.mineBlockStatArray[getIdFromBlock(this)], 1);
entityplayer.addExhaustion(0.045F);
if (world.rand.nextInt(100) < 11)
dropBlockAsItem(world, i + x, j + y, k + z, new ItemStack(TFCItems.stick, 1));
else if (world.rand.nextInt(100) < 4 && TFCOptions.enableSaplingDrops)
dropSapling(world, i + x, j + y, k + z, meta);
removeLeaves(world, i + x, j + y, k + z);
super.harvestBlock(world, entityplayer, i + x, j + y, k + z, meta);

itemstack.damageItem(1, entityplayer);
if (itemstack.stackSize == 0)
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, null);
}
}
}
}
}
}
}
else if(!world.isRemote)
{
entityplayer.addStat(StatList.mineBlockStatArray[getIdFromBlock(this)], 1);
entityplayer.addExhaustion(0.025F);
if(world.rand.nextInt(100) < 28)
dropBlockAsItem(world, i, j, k, new ItemStack(TFCItems.stick, 1));
else if (world.rand.nextInt(100) < 6 && TFCOptions.enableSaplingDrops)
dropSapling(world, i, j, k, meta);
if (!foundScythe)
{
entityplayer.addStat(StatList.mineBlockStatArray[getIdFromBlock(this)], 1);
entityplayer.addExhaustion(0.025F);
if (world.rand.nextInt(100) < 28)
dropBlockAsItem(world, i, j, k, new ItemStack(TFCItems.stick, 1));
else if (world.rand.nextInt(100) < 6 && TFCOptions.enableSaplingDrops)
dropSapling(world, i, j, k, meta);

super.harvestBlock(world, entityplayer, i, j, k, meta);
}
}
}

Expand Down

0 comments on commit 83c3e2a

Please sign in to comment.