Added an extra function to axes for chopping down huge trees

This commit is contained in:
Adubbz 2013-07-12 12:06:14 +10:00
parent c46a238d61
commit 3aed010100
2 changed files with 70 additions and 2 deletions

View file

@ -8,15 +8,16 @@ import biomesoplenty.configuration.BOPBlocks;
import biomesoplenty.configuration.BOPConfiguration; import biomesoplenty.configuration.BOPConfiguration;
import biomesoplenty.configuration.BOPCrafting; import biomesoplenty.configuration.BOPCrafting;
import biomesoplenty.configuration.BOPEntities; import biomesoplenty.configuration.BOPEntities;
import biomesoplenty.configuration.BOPItems;
import biomesoplenty.configuration.BOPFluids; import biomesoplenty.configuration.BOPFluids;
import biomesoplenty.configuration.BOPItems;
import biomesoplenty.configuration.BOPPotions; import biomesoplenty.configuration.BOPPotions;
import biomesoplenty.configuration.BOPVanillaCompat; import biomesoplenty.configuration.BOPVanillaCompat;
import biomesoplenty.handlers.AxeChopHandler;
import biomesoplenty.handlers.BOPCraftHandler; import biomesoplenty.handlers.BOPCraftHandler;
import biomesoplenty.handlers.FluidEventHandler;
import biomesoplenty.handlers.BonemealHandler; import biomesoplenty.handlers.BonemealHandler;
import biomesoplenty.handlers.BreakSpeedHandler; import biomesoplenty.handlers.BreakSpeedHandler;
import biomesoplenty.handlers.EntityEventHandler; import biomesoplenty.handlers.EntityEventHandler;
import biomesoplenty.handlers.FluidEventHandler;
import biomesoplenty.handlers.MovementHandler; import biomesoplenty.handlers.MovementHandler;
import biomesoplenty.handlers.SoundHandler; import biomesoplenty.handlers.SoundHandler;
import biomesoplenty.handlers.TickHandlerClient; import biomesoplenty.handlers.TickHandlerClient;
@ -103,6 +104,7 @@ public class BiomesOPlenty
MinecraftForge.EVENT_BUS.register(new FluidEventHandler()); MinecraftForge.EVENT_BUS.register(new FluidEventHandler());
MinecraftForge.EVENT_BUS.register(new BreakSpeedHandler()); MinecraftForge.EVENT_BUS.register(new BreakSpeedHandler());
MinecraftForge.EVENT_BUS.register(new MovementHandler()); MinecraftForge.EVENT_BUS.register(new MovementHandler());
MinecraftForge.EVENT_BUS.register(new AxeChopHandler());
proxy.registerRenderers(); proxy.registerRenderers();

View file

@ -0,0 +1,66 @@
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)
{
itemstack.damageItem(4, player);
if (world.rand.nextInt(30) == 0)
{
int firstBlockId = world.getBlockId(event.x, event.y, event.z);
for (int i = 0; world.getBlockId(event.x, event.y + i, event.z) == firstBlockId; i++)
{
if (!world.isRemote)
{
world.destroyBlock(event.x, event.y + i, event.z, true);
System.out.println(i);
}
}
}
}
else
{
itemstack.damageItem(7, player);
}
}
}
}
}
}
}