2012-11-25 16:45:00 +01:00
|
|
|
package mekanism.tools.common;
|
2012-08-15 22:41:41 +02:00
|
|
|
|
2012-11-25 16:45:00 +01:00
|
|
|
import mekanism.common.ItemMekanism;
|
2012-12-20 22:53:39 +01:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.EnumToolMaterial;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.world.World;
|
2012-11-21 17:38:37 +01:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.event.Event.Result;
|
|
|
|
import net.minecraftforge.event.entity.player.UseHoeEvent;
|
2012-12-20 22:53:39 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2012-08-15 22:41:41 +02:00
|
|
|
|
2012-11-05 20:29:04 +01:00
|
|
|
public class ItemMekanismHoe extends ItemMekanism
|
2012-08-15 22:41:41 +02:00
|
|
|
{
|
2012-11-29 02:03:55 +01:00
|
|
|
protected EnumToolMaterial toolMaterial;
|
2012-11-21 17:38:37 +01:00
|
|
|
|
2012-11-29 02:03:55 +01:00
|
|
|
public ItemMekanismHoe(int id, EnumToolMaterial enumtoolmaterial)
|
2012-08-15 22:41:41 +02:00
|
|
|
{
|
2012-11-21 17:38:37 +01:00
|
|
|
super(id);
|
2012-11-29 02:03:55 +01:00
|
|
|
toolMaterial = enumtoolmaterial;
|
2012-08-15 22:41:41 +02:00
|
|
|
maxStackSize = 1;
|
2012-11-29 02:03:55 +01:00
|
|
|
setMaxDamage(enumtoolmaterial.getMaxUses());
|
2012-11-21 17:38:37 +01:00
|
|
|
setCreativeTab(CreativeTabs.tabTools);
|
2012-08-15 22:41:41 +02:00
|
|
|
}
|
|
|
|
|
2012-11-25 16:45:00 +01:00
|
|
|
@Override
|
2012-11-29 02:03:55 +01:00
|
|
|
public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int x, int y, int z, int side, float entityX, float entityY, float entityZ)
|
2012-08-15 22:41:41 +02:00
|
|
|
{
|
2012-11-29 02:03:55 +01:00
|
|
|
if (!entityplayer.canPlayerEdit(x, y, z, side, itemstack))
|
2012-08-15 22:41:41 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-21 17:38:37 +01:00
|
|
|
else
|
2012-08-15 22:41:41 +02:00
|
|
|
{
|
2012-11-29 02:03:55 +01:00
|
|
|
UseHoeEvent event = new UseHoeEvent(entityplayer, itemstack, world, x, y, z);
|
2012-11-21 17:38:37 +01:00
|
|
|
if (MinecraftForge.EVENT_BUS.post(event))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-15 22:41:41 +02:00
|
|
|
|
2012-11-21 17:38:37 +01:00
|
|
|
if (event.getResult() == Result.ALLOW)
|
2012-08-15 22:41:41 +02:00
|
|
|
{
|
2012-11-29 02:03:55 +01:00
|
|
|
itemstack.damageItem(1, entityplayer);
|
2012-08-15 22:41:41 +02:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-21 17:38:37 +01:00
|
|
|
|
2012-11-29 02:03:55 +01:00
|
|
|
int blockID = world.getBlockId(x, y, z);
|
|
|
|
int aboveBlockID = world.getBlockId(x, y + 1, z);
|
2012-11-21 17:38:37 +01:00
|
|
|
|
2012-11-29 02:03:55 +01:00
|
|
|
if ((side == 0 || aboveBlockID != 0 || blockID != Block.grass.blockID) && blockID != Block.dirt.blockID)
|
2012-11-21 17:38:37 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-15 22:41:41 +02:00
|
|
|
else
|
|
|
|
{
|
2012-11-29 02:03:55 +01:00
|
|
|
Block block = Block.tilledField;
|
|
|
|
world.playSoundEffect(x + 0.5F, y + 0.5F, z + 0.5F, block.stepSound.getStepSound(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
|
2012-11-21 17:38:37 +01:00
|
|
|
|
2012-11-29 02:03:55 +01:00
|
|
|
if (world.isRemote)
|
2012-11-21 17:38:37 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-29 02:03:55 +01:00
|
|
|
world.setBlockWithNotify(x, y, z, block.blockID);
|
|
|
|
itemstack.damageItem(1, entityplayer);
|
2012-11-21 17:38:37 +01:00
|
|
|
return true;
|
|
|
|
}
|
2012-08-15 22:41:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-21 17:38:37 +01:00
|
|
|
|
2012-11-25 16:45:00 +01:00
|
|
|
@Override
|
2012-11-29 02:03:55 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2012-08-15 22:41:41 +02:00
|
|
|
public boolean isFull3D()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|