Add chest upgrading item

This commit is contained in:
Christian Weeks 2012-02-01 23:24:31 -05:00
parent fae10df314
commit 3d8a9b80d5
8 changed files with 217 additions and 33 deletions

View File

@ -13,7 +13,7 @@
</description>
<property name="modname" value="mod_ironchests" />
<property name="version" value="2.1" />
<property name="version" value="2.2" />
<property name="mcp.home" location="/home/cpw/minecraft1dev/forge1.31" />
<property name="mcp.obfoutput" location="${mcp.home}/reobf" />
<property name="client.mcp.obfoutput" location="${mcp.obfoutput}/minecraft" />

View File

@ -12,6 +12,7 @@ import net.minecraft.src.ModLoader;
import net.minecraft.src.ModLoaderMp;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.forge.MinecraftForgeClient;
import cpw.mods.ironchest.ChestChangerType;
import cpw.mods.ironchest.IProxy;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.TileEntityIronChest;
@ -21,6 +22,7 @@ public class ClientProxy extends BaseModMp implements IProxy {
public void registerRenderInformation() {
ChestItemRenderHelper.instance=new IronChestRenderHelper();
MinecraftForgeClient.preloadTexture("cpw/mods/ironchest/sprites/block_textures.png");
MinecraftForgeClient.preloadTexture("cpw/mods/ironchest/sprites/item_textures.png");
}
@Override
@ -35,6 +37,9 @@ public class ClientProxy extends BaseModMp implements IProxy {
for (IronChestType typ : IronChestType.values()) {
ModLoader.AddLocalization(typ.name() + ".name", typ.friendlyName);
}
for (ChestChangerType typ : ChestChangerType.values()) {
ModLoader.AddLocalization("item."+typ.itemName+".name", typ.descriptiveName);
}
}
@Override

View File

@ -142,9 +142,15 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider {
TileEntityIronChest tileentitychest = (TileEntityIronChest)world.getBlockTileEntity(i, j, k);
if (tileentitychest != null)
{
for (int l = 0; l < tileentitychest.getSizeInventory(); l++)
dropContent(0, tileentitychest, world);
}
super.onBlockRemoval(world, i, j, k);
}
public void dropContent(int newSize, TileEntityIronChest chest, World world) {
for (int l = newSize; l < chest.getSizeInventory(); l++)
{
ItemStack itemstack = tileentitychest.getStackInSlot(l);
ItemStack itemstack = chest.getStackInSlot(l);
if (itemstack == null)
{
continue;
@ -160,7 +166,7 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider {
i1 = itemstack.stackSize;
}
itemstack.stackSize -= i1;
EntityItem entityitem = new EntityItem(world, (float)i + f, (float)j + f1, (float)k + f2, new ItemStack(itemstack.itemID, i1, itemstack.getItemDamage()));
EntityItem entityitem = new EntityItem(world, (float)chest.xCoord + f, (float)chest.yCoord + (newSize>0 ? 1 : 0) + f1, (float)chest.zCoord + f2, new ItemStack(itemstack.itemID, i1, itemstack.getItemDamage()));
float f3 = 0.05F;
entityitem.motionX = (float)random.nextGaussian() * f3;
entityitem.motionY = (float)random.nextGaussian() * f3 + 0.2F;
@ -173,6 +179,4 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider {
}
}
}
super.onBlockRemoval(world, i, j, k);
}
}

View File

@ -0,0 +1,70 @@
package cpw.mods.ironchest;
import static cpw.mods.ironchest.IronChestType.COPPER;
import static cpw.mods.ironchest.IronChestType.DIAMOND;
import static cpw.mods.ironchest.IronChestType.GOLD;
import static cpw.mods.ironchest.IronChestType.IRON;
import static cpw.mods.ironchest.IronChestType.SILVER;
import net.minecraft.src.Block;
import net.minecraft.src.ItemStack;
import net.minecraft.src.forge.Configuration;
import net.minecraft.src.forge.MinecraftForge;
public enum ChestChangerType {
IRONGOLD(IRON,GOLD,"ironGoldUpgrade","Iron to Gold Chest Upgrade","mmm","msm","mmm"),
GOLDDIAMOND(GOLD,DIAMOND,"goldDiamondUpgrade","Gold to Diamond Chest Upgrade","GGG","msm","GGG"),
COPPERSILVER(COPPER,SILVER,"copperSilverUpgrade","Copper to Silver Chest Upgrade","mmm","msm","mmm"),
SILVERGOLD(SILVER,GOLD,"silverGoldUpgrade","Silver to Gold Chest Upgrade","mGm","GsG","mGm");
private IronChestType source;
private IronChestType target;
public String itemName;
public String descriptiveName;
private ItemChestChanger item;
private String[] recipe;
private ChestChangerType(IronChestType source, IronChestType target, String itemName, String descriptiveName, String... recipe) {
this.source=source;
this.target=target;
this.itemName=itemName;
this.descriptiveName=descriptiveName;
this.recipe=recipe;
}
public boolean canUpgrade(IronChestType from) {
return from==this.source;
}
public int getTarget() {
return this.target.ordinal();
}
public ItemChestChanger buildItem(Configuration cfg, int id) {
int itemId=Integer.parseInt(cfg.getOrCreateIntProperty(itemName, Configuration.ITEM_PROPERTY, id).value);
item=new ItemChestChanger(itemId,this);
return item;
}
public void addRecipe() {
IronChestType.addRecipe(new ItemStack(item), recipe, 'm', target.mat,'s',source.mat,'G',Block.glass);
}
public static void buildItems(Configuration cfg, int defaultId) {
for (ChestChangerType type: values()) {
type.buildItem(cfg, defaultId++);
}
}
public static void generateRecipe(IronChestType type) {
for (ChestChangerType item: values()) {
if (item.source==type || item.target==type) {
for (Object[] recipe : MinecraftForge.generateRecipes(item.recipe[0],item.recipe[1],item.recipe[2],'s',item.source.getMatList(),'m',item.target.getMatList(),'G',Block.glass)) {
if (recipe[4]==null || recipe[6]==null) {
continue;
}
IronChestType.addRecipe(new ItemStack(item.item), recipe);
}
}
}
}
}

View File

@ -1,5 +1,8 @@
package cpw.mods.ironchest;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.src.Block;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
@ -21,9 +24,10 @@ public enum IronChestType {
private String guiName;
private int textureRow;
public Class<? extends TileEntityIronChest> clazz;
private Item mat;
Item mat;
private String[] recipes;
public int guiId;
private ArrayList<ItemStack> matList;
IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String guiName, String modelTexture, int textureRow, Item mat,
Class<? extends TileEntityIronChest> clazz, String... recipes) {
@ -37,6 +41,10 @@ public enum IronChestType {
this.clazz = clazz;
this.mat = mat;
this.recipes = recipes;
this.matList=new ArrayList<ItemStack>();
if (mat!=null) {
matList.add(new ItemStack(mat));
}
}
public String getModelTexture() {
@ -85,7 +93,7 @@ public enum IronChestType {
}
}
private static void addRecipe(ItemStack is, Object... parts) {
public static void addRecipe(ItemStack is, Object... parts) {
ModLoader.AddRecipe(is, parts);
}
@ -113,4 +121,12 @@ public enum IronChestType {
return rowLength;
}
public void addMat(ItemStack ore) {
this.matList.add(ore);
}
public List<ItemStack> getMatList() {
return matList;
}
}

View File

@ -0,0 +1,54 @@
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);
setIconIndex(0);
this.type=type;
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.setBlockMetadata(X, Y, Z, newchest.getType().ordinal());
world.markBlockNeedsUpdate(X, Y, Z);
world.notifyBlocksOfNeighborChange(X, Y, Z, world.getBlockId(X, Y, Z));
stack.stackSize=0;
return true;
} else {
return false;
}
}
@Override
public String getTextureFile() {
return "cpw/mods/ironchest/sprites/item_textures.png";
}
public int getTargetChestOrdinal(int sourceOrdinal) {
return type.getTarget();
}
public ChestChangerType getType() {
return type;
}
}

View File

@ -1,11 +1,13 @@
package cpw.mods.ironchest;
import net.minecraft.src.Block;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.IInventory;
import net.minecraft.src.ItemStack;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.NBTTagList;
import net.minecraft.src.TileEntity;
import net.minecraft.src.mod_IronChest;
public class TileEntityIronChest extends TileEntity implements IInventory {
private int ticksSinceSync;
@ -208,4 +210,20 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
this.facing=chestFacing;
}
public TileEntityIronChest applyUpgradeItem(ItemChestChanger itemChestChanger) {
if (numUsingPlayers>0) {
return null;
}
if (!itemChestChanger.getType().canUpgrade(this.getType())) {
return null;
}
TileEntityIronChest newEntity=IronChestType.makeEntity(itemChestChanger.getTargetChestOrdinal(getType().ordinal()));
int newSize=newEntity.chestContents.length;
System.arraycopy(chestContents, 0, newEntity.chestContents, 0, Math.min(newSize,chestContents.length));
BlockIronChest block=mod_IronChest.ironChestBlock;
block.dropContent(newSize,this,this.worldObj);
newEntity.setFacing(facing);
return newEntity;
}
}

View File

@ -6,8 +6,10 @@ import net.minecraft.src.forge.Configuration;
import net.minecraft.src.forge.IOreHandler;
import net.minecraft.src.forge.MinecraftForge;
import cpw.mods.ironchest.BlockIronChest;
import cpw.mods.ironchest.ChestChangerType;
import cpw.mods.ironchest.IProxy;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.ItemChestChanger;
import cpw.mods.ironchest.ItemIronChest;
import cpw.mods.ironchest.ServerClientProxy;
import cpw.mods.ironchest.TileEntityIronChest;
@ -15,6 +17,7 @@ import cpw.mods.ironchest.TileEntityIronChest;
public class mod_IronChest extends BaseModMp {
public static BlockIronChest ironChestBlock;
public static ItemChestChanger itemChestChanger;
public static IProxy proxy;
@Override
@ -31,6 +34,7 @@ public class mod_IronChest extends BaseModMp {
try {
cfg.load();
ironChestBlock = new BlockIronChest(Integer.parseInt(cfg.getOrCreateBlockIdProperty("ironChests", 181).value));
ChestChangerType.buildItems(cfg, 19501);
IronChestType.initGUIs(cfg);
} catch (Exception e) {
ModLoader.getLogger().severe("IronChest was unable to load it's configuration successfully");
@ -45,24 +49,37 @@ public class mod_IronChest extends BaseModMp {
@Override
public void registerOre(String oreClass, ItemStack ore) {
if ("ingotCopper".equals(oreClass)) {
IronChestType.COPPER.addMat(ore);
IronChestType.generateRecipesForType(ironChestBlock, Block.chest, IronChestType.COPPER, ore);
ChestChangerType.generateRecipe(IronChestType.COPPER);
}
if ("ingotSilver".equals(oreClass)) {
IronChestType.SILVER.addMat(ore);
IronChestType.generateRecipesForType(ironChestBlock, ironChestBlock, IronChestType.SILVER, ore);
ChestChangerType.generateRecipe(IronChestType.SILVER);
}
if ("ingotRefinedIron".equals(oreClass)) {
IronChestType.IRON.addMat(ore);
IronChestType.generateRecipesForType(ironChestBlock, Block.chest, IronChestType.IRON, ore);
ChestChangerType.generateRecipe(IronChestType.IRON);
}
}
});
proxy.registerTranslations();
proxy.registerTileEntities();
ChestChangerType.generateRecipe(IronChestType.IRON);
ChestChangerType.generateRecipe(IronChestType.GOLD);
IronChestType.generateTieredRecipies(ironChestBlock);
proxy.registerRenderInformation();
}
@Override
public void ModsLoaded() {
}
public static void openGUI(EntityPlayer player, TileEntityIronChest te) {
proxy.showGUI(te,player);
}