2013-07-12 02:06:14 +00:00
|
|
|
package biomesoplenty.handlers;
|
|
|
|
|
|
|
|
import biomesoplenty.configuration.BOPItems;
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.EnumToolMaterial;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemAxe;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.event.ForgeSubscribe;
|
|
|
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
|
|
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
|
|
|
|
|
|
|
|
public class AxeChopHandler
|
|
|
|
{
|
|
|
|
@ForgeSubscribe
|
|
|
|
public void chopTree(PlayerInteractEvent event)
|
|
|
|
{
|
|
|
|
ItemStack itemstack = event.entityPlayer.getCurrentEquippedItem();
|
|
|
|
EntityPlayer player = event.entityPlayer;
|
|
|
|
World world = player.worldObj;
|
|
|
|
|
|
|
|
if (event.action == Action.RIGHT_CLICK_BLOCK)
|
|
|
|
{
|
|
|
|
if (itemstack != null)
|
|
|
|
{
|
|
|
|
Item item = Item.itemsList[itemstack.itemID];
|
|
|
|
|
|
|
|
if (item instanceof ItemAxe)
|
|
|
|
{
|
|
|
|
if (Block.blocksList[world.getBlockId(event.x, event.y, event.z)].isWood(world, event.x, event.y, event.z))
|
|
|
|
{
|
|
|
|
EnumToolMaterial toolMaterial = EnumToolMaterial.valueOf(((ItemAxe)item).getToolMaterialName());
|
|
|
|
|
|
|
|
player.swingItem();
|
|
|
|
player.playSound("dig.wood", 1.0F, 0.25F);
|
|
|
|
|
|
|
|
if (toolMaterial != EnumToolMaterial.WOOD && toolMaterial != EnumToolMaterial.STONE && toolMaterial != BOPItems.EnumToolMaterialMud)
|
|
|
|
{
|
2013-07-12 02:34:25 +00:00
|
|
|
int firstBlockId = world.getBlockId(event.x, event.y, event.z);
|
|
|
|
int logNo = 0;
|
|
|
|
|
2013-07-12 02:06:14 +00:00
|
|
|
itemstack.damageItem(4, player);
|
2013-07-12 02:34:25 +00:00
|
|
|
|
|
|
|
for (int l = 0; world.getBlockId(event.x, event.y + l, event.z) == firstBlockId; l++)
|
2013-07-12 02:06:14 +00:00
|
|
|
{
|
2013-07-12 02:34:25 +00:00
|
|
|
if (!world.isRemote)
|
|
|
|
{
|
|
|
|
logNo += l * 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-12 06:03:52 +00:00
|
|
|
if (world.rand.nextInt(15 + logNo) == 0)
|
2013-07-12 02:34:25 +00:00
|
|
|
{
|
2013-07-12 02:06:14 +00:00
|
|
|
for (int i = 0; world.getBlockId(event.x, event.y + i, event.z) == firstBlockId; i++)
|
|
|
|
{
|
|
|
|
if (!world.isRemote)
|
|
|
|
{
|
2013-07-12 02:08:22 +00:00
|
|
|
itemstack.damageItem(2, player);
|
2013-07-12 02:06:14 +00:00
|
|
|
world.destroyBlock(event.x, event.y + i, event.z, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
itemstack.damageItem(7, player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|