Skip to content

Commit

Permalink
Adds dropping experiance when breaking blocks, example Coal and Lappis
Browse files Browse the repository at this point in the history
  • Loading branch information
Glassmaker committed Jul 27, 2014
1 parent efc9208 commit d76117d
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/main/java/tconstruct/items/tools/Battleaxe.java
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
Expand Down Expand Up @@ -251,6 +252,7 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
final Block wood = world.getBlock(x, y, z);
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
final int meta = world.getBlockMetadata(x, y, z);
final int fortune = EnchantmentHelper.getFortuneModifier(player);
for (int yPos = y + 1; yPos < y + 9; yPos++)
{
Block block = world.getBlock(x, yPos, z);
Expand Down Expand Up @@ -280,6 +282,11 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
{
block.onBlockDestroyedByPlayer(world, x, yPos, z, localMeta);
}

// Workaround for dropping experience
int exp = block.getExpDrop(world, localMeta, fortune);
block.dropXpOnBlockBreak(world, x, y, z, exp);

block.harvestBlock(world, player, x, yPos, z, localMeta);
block.onBlockHarvested(world, x, yPos, z, localMeta, player);
onBlockDestroyed(stack, world, block, x, yPos, z, player);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/tconstruct/items/tools/Excavator.java
Expand Up @@ -3,6 +3,7 @@
import mantle.world.WorldHelper;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -184,6 +185,7 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
break;
}
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
int fortune = EnchantmentHelper.getFortuneModifier(player);
for (int xPos = x - xRange; xPos <= x + xRange; xPos++)
{
for (int yPos = y - yRange; yPos <= y + yRange; yPos++)
Expand Down Expand Up @@ -221,6 +223,11 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
{
block.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, localMeta);
}

// Workaround for dropping experience
int exp = block.getExpDrop(world, localMeta, fortune);
block.dropXpOnBlockBreak(world, xPos, yPos, zPos, exp);

block.harvestBlock(world, player, xPos, yPos, zPos, localMeta);
block.onBlockHarvested(world, xPos, yPos, zPos, localMeta, player);
if (blockHardness > 0f)
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/tconstruct/items/tools/Hammer.java
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -283,6 +284,7 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl

NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
int toolLevel = tags.getInteger("HarvestLevel");
int fortune = EnchantmentHelper.getFortuneModifier(player);
for (int xPos = x - xRange; xPos <= x + xRange; xPos++)
{
for (int yPos = y - yRange; yPos <= y + yRange; yPos++)
Expand Down Expand Up @@ -321,6 +323,11 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
{
localBlock.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, localMeta);
}

// Workaround for dropping experience
int exp = localBlock.getExpDrop(world, localMeta, fortune);
localBlock.dropXpOnBlockBreak(world, xPos, yPos, zPos, exp);

localBlock.harvestBlock(world, player, xPos, yPos, zPos, localMeta);
localBlock.onBlockHarvested(world, xPos, yPos, zPos, localMeta, player);
if (blockHardness > 0f)
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/tconstruct/items/tools/LumberAxe.java
Expand Up @@ -3,6 +3,7 @@
import mantle.world.WorldHelper;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -198,6 +199,8 @@ else if (wood.getMaterial() == Material.wood)
void breakTree (World world, int x, int y, int z, ItemStack stack, NBTTagCompound tags, Block bID, int meta, EntityPlayer player)
{
Block block;
final int fortune = EnchantmentHelper.getFortuneModifier(player);

for (int xPos = x - 1; xPos <= x + 1; xPos++)
{
for (int yPos = y; yPos <= y + 1; yPos++)
Expand Down Expand Up @@ -246,6 +249,11 @@ void breakTree (World world, int x, int y, int z, ItemStack stack, NBTTagCompoun
{
block.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, meta);
}

// Workaround for dropping experience
int exp = localblock.getExpDrop(world, meta, fortune);
localblock.dropXpOnBlockBreak(world, xPos, yPos, zPos, exp);

block.harvestBlock(world, player, xPos, yPos, zPos, meta);
block.onBlockHarvested(world, xPos, yPos, zPos, meta, player);
onBlockDestroyed(stack, world, localblock, xPos, yPos, zPos, player);
Expand Down Expand Up @@ -280,6 +288,8 @@ void breakTree (World world, int x, int y, int z, ItemStack stack, NBTTagCompoun

void destroyWood (World world, int x, int y, int z, ItemStack stack, NBTTagCompound tags, EntityPlayer player)
{
final int fortune = EnchantmentHelper.getFortuneModifier(player);

for (int xPos = x - 1; xPos <= x + 1; xPos++)
{
for (int yPos = y - 1; yPos <= y + 1; yPos++)
Expand All @@ -305,13 +315,17 @@ void destroyWood (World world, int x, int y, int z, ItemStack stack, NBTTagCompo

if (!cancelHarvest)
{
WorldHelper.setBlockToAir(world, xPos, yPos, zPos);
if (!player.capabilities.isCreativeMode)
{
// TODO harvestBlock
int exp = block.getExpDrop(world, meta, fortune);
block.dropXpOnBlockBreak(world, xPos, yPos, zPos, exp);

block.harvestBlock(world, player, xPos, yPos, zPos, meta);
onBlockDestroyed(stack, world, block, xPos, yPos, zPos, player);
}
WorldHelper.setBlockToAir(world, xPos, yPos, zPos);
world.func_147479_m(xPos, yPos, zPos);
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/tconstruct/library/tools/DualHarvestTool.java
Expand Up @@ -3,6 +3,7 @@
import mantle.world.WorldHelper;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -50,7 +51,14 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
else
{
if (!player.capabilities.isCreativeMode)
{
// Workaround for dropping experience
int fortune = EnchantmentHelper.getFortuneModifier(player);
int exp = block.getExpDrop(world, meta, fortune);
block.dropXpOnBlockBreak(world, x, y, z, exp);

onBlockDestroyed(stack, world, block, x, y, z, player);
}
WorldHelper.setBlockToAir(world, x, y, z);
if (!world.isRemote)
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12));
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/tconstruct/library/tools/HarvestTool.java
Expand Up @@ -3,6 +3,7 @@
import mantle.world.WorldHelper;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -84,6 +85,12 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
{
localBlock.onBlockDestroyedByPlayer(world, x, y, z, localMeta);
}

// Workaround for dropping experience
int fortune = EnchantmentHelper.getFortuneModifier(player);
int exp = localBlock.getExpDrop(world, localMeta, fortune);
localBlock.dropXpOnBlockBreak(world, x, y, z, exp);

localBlock.harvestBlock(world, player, x, y, z, localMeta);
localBlock.onBlockHarvested(world, x, y, z, localMeta, player);
if (blockHardness > 0f)
Expand Down Expand Up @@ -288,4 +295,17 @@ public boolean onItemUse (ItemStack stack, EntityPlayer player, World world, int

return used;
}

@Override
public int getHarvestLevel (ItemStack stack, String toolClass)
{
if (!(stack.getItem() instanceof HarvestTool) || !getHarvestType().equals(toolClass))
{
return -1;
}

NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
int harvestLvl = tags.getInteger("HarvestLevel");
return harvestLvl;
}
}

0 comments on commit d76117d

Please sign in to comment.