/******************************************************************************* * Copyright (c) 2012 cpw. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html *
* Contributors:
* cpw - initial API and implementation
******************************************************************************/
package cpw.mods.ironchest;
import net.minecraft.block.BlockChest;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class ItemChestChanger extends Item
{
public final ChestChangerType type;
public ItemChestChanger(ChestChangerType type)
{
this.type = type;
this.setMaxStackSize(1);
this.setUnlocalizedName("ironchest:" + type.name());
this.setCreativeTab(CreativeTabs.MISC);
}
@Override
//@formatter:off
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand)
//public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, EnumHand hand)
//@formatter:on
{
if (world.isRemote)
{
return EnumActionResult.PASS;
}
if (this.type.canUpgrade(IronChestType.WOOD))
{
if (!(world.getBlockState(pos).getBlock() instanceof BlockChest))
{
return EnumActionResult.PASS;
}
}
else
{
//@formatter:off
if (world.getBlockState(pos) != IronChest.ironChestBlock.getStateFromMeta(IronChestType.valueOf(this.type.source.getName().toUpperCase()).ordinal()))
//@formatter:on
{
return EnumActionResult.PASS;
}
}
TileEntity te = world.getTileEntity(pos);
TileEntityIronChest newchest = new TileEntityIronChest();
NonNullList