ironbarrels/IronChests2/common/cpw/mods/ironchest/ItemChestChanger.java

65 lines
1.9 KiB
Java
Raw Normal View History

/*******************************************************************************
* 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
******************************************************************************/
2012-02-02 05:24:31 +01:00
package cpw.mods.ironchest;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;
import net.minecraft.src.forge.ITextureProvider;
public class ItemChestChanger extends Item implements ITextureProvider {
private ChestChangerType type;
public ItemChestChanger(int id, ChestChangerType type) {
super(id);
setMaxStackSize(1);
this.type=type;
setIconIndex(type.ordinal());
2012-02-02 05:24:31 +01:00
setItemName(type.itemName);
}
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int X, int Y, int Z, int side) {
TileEntity te=world.getBlockTileEntity(X,Y,Z);
if (te!=null && te instanceof TileEntityIronChest) {
TileEntityIronChest ironchest=(TileEntityIronChest)te;
TileEntityIronChest newchest=ironchest.applyUpgradeItem(this);
if (newchest==null) {
return false;
}
world.setBlockTileEntity(X, Y, Z, newchest);
world.setBlockMetadataWithNotify(X, Y, Z, newchest.getType().ordinal());
2012-02-02 05:24:31 +01:00
world.notifyBlocksOfNeighborChange(X, Y, Z, world.getBlockId(X, Y, Z));
world.markBlockNeedsUpdate(X, Y, Z);
2012-02-02 05:24:31 +01:00
stack.stackSize=0;
return true;
} else {
return false;
}
}
@Override
public String getTextureFile() {
2012-02-07 03:29:48 +01:00
return "/cpw/mods/ironchest/sprites/item_textures.png";
2012-02-02 05:24:31 +01:00
}
public int getTargetChestOrdinal(int sourceOrdinal) {
return type.getTarget();
}
public ChestChangerType getType() {
return type;
}
}