New chest, with new capabilities

This commit is contained in:
Christian 2013-09-16 13:43:32 -04:00
parent 021d97d333
commit 3df6d36373
10 changed files with 99 additions and 32 deletions

View File

@ -83,30 +83,6 @@ public class BlockIronChest extends BlockContainer {
return IronChestType.makeEntity(metadata); return IronChestType.makeEntity(metadata);
} }
// public Icon getBlockTexture(IBlockAccess worldAccess, int i, int j, int k, int l)
// {
// int meta = worldAccess.getBlockMetadata(i, j, k);
// IronChestType type = IronChestType.values()[meta];
// TileEntity te = worldAccess.getBlockTileEntity(i, j, k);
// TileEntityIronChest icte = null;
// if (te != null && te instanceof TileEntityIronChest)
// {
// icte = (TileEntityIronChest) te;
// }
// if (l == 0 || l == 1)
// { // Top and Bottom
// return type.getTextureRow() * 16 + 1;
// }
// else if (icte != null && l == icte.getFacing())
// { // Front
// return type.getTextureRow() * 16 + 2;
// }
// else
// { // Back and Sides
// return type.getTextureRow() * 16;
// }
// }
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
@Override @Override
public Icon getIcon(int i, int j) public Icon getIcon(int i, int j)

View File

@ -53,6 +53,10 @@ public class ContainerIronChestBase extends Container {
return null; return null;
} }
} }
else if (!type.acceptsStack(itemstack1))
{
return null;
}
else if (!mergeItemStack(itemstack1, 0, type.size, false)) else if (!mergeItemStack(itemstack1, 0, type.size, false))
{ {
return null; return null;
@ -78,13 +82,16 @@ public class ContainerIronChestBase extends Container {
protected void layoutContainer(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize) protected void layoutContainer(IInventory playerInventory, IInventory chestInventory, IronChestType type, int xSize, int ySize)
{ {
if (type == IronChestType.DIRTCHEST9000) {
addSlotToContainer(type.makeSlot(chestInventory, 0, 12 + 4 * 18, 8 + 2 * 18));
} else {
for (int chestRow = 0; chestRow < type.getRowCount(); chestRow++) for (int chestRow = 0; chestRow < type.getRowCount(); chestRow++)
{ {
for (int chestCol = 0; chestCol < type.getRowLength(); chestCol++) for (int chestCol = 0; chestCol < type.getRowLength(); chestCol++)
{ {
addSlotToContainer(new Slot(chestInventory, chestCol + chestRow * type.getRowLength(), 12 + chestCol * 18, 8 + chestRow * 18)); addSlotToContainer(type.makeSlot(chestInventory, chestCol + chestRow * type.getRowLength(), 12 + chestCol * 18, 8 + chestRow * 18));
}
} }
} }
int leftCol = (xSize - 162) / 2 + 1; int leftCol = (xSize - 162) / 2 + 1;

View File

@ -16,6 +16,8 @@ import java.util.List;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon; import net.minecraft.util.Icon;
@ -32,6 +34,7 @@ public enum IronChestType {
SILVER(72, 9, false, "Silver Chest", "silverchest.png", 4, Arrays.asList("ingotSilver"), TileEntitySilverChest.class, "mmmm3mmmm", "mGmG0GmGm"), SILVER(72, 9, false, "Silver Chest", "silverchest.png", 4, Arrays.asList("ingotSilver"), TileEntitySilverChest.class, "mmmm3mmmm", "mGmG0GmGm"),
CRYSTAL(108, 12, true, "Crystal Chest", "crystalchest.png", 5, Arrays.asList("blockGlass"), TileEntityCrystalChest.class, "GGGGPGGGG"), CRYSTAL(108, 12, true, "Crystal Chest", "crystalchest.png", 5, Arrays.asList("blockGlass"), TileEntityCrystalChest.class, "GGGGPGGGG"),
OBSIDIAN(108, 12, false, "Obsidian Chest", "obsidianchest.png", 6, Arrays.asList("obsidian"), TileEntityObsidianChest.class, "mmmm2mmmm"), OBSIDIAN(108, 12, false, "Obsidian Chest", "obsidianchest.png", 6, Arrays.asList("obsidian"), TileEntityObsidianChest.class, "mmmm2mmmm"),
DIRTCHEST9000(1, 1, false, "Dirt Chest 9000", "dirtchest.png",7,Arrays.asList("dirt"), TileEntityDirtChest.class,Item.itemsList[Block.dirt.blockID],"mmmmCmmmm"),
WOOD(0, 0, false, "", "", -1, Arrays.asList("plankWood"), null); WOOD(0, 0, false, "", "", -1, Arrays.asList("plankWood"), null);
int size; int size;
private int rowLength; private int rowLength;
@ -42,9 +45,15 @@ public enum IronChestType {
public Class<? extends TileEntityIronChest> clazz; public Class<? extends TileEntityIronChest> clazz;
private String[] recipes; private String[] recipes;
private ArrayList<String> matList; private ArrayList<String> matList;
private Item itemFilter;
IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List<String> mats, IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List<String> mats,
Class<? extends TileEntityIronChest> clazz, String... recipes) Class<? extends TileEntityIronChest> clazz, String... recipes)
{
this(size, rowLength, tieredChest, friendlyName, modelTexture, textureRow, mats, clazz, (Item)null, recipes);
}
IronChestType(int size, int rowLength, boolean tieredChest, String friendlyName, String modelTexture, int textureRow, List<String> mats,
Class<? extends TileEntityIronChest> clazz, Item itemFilter, String... recipes)
{ {
this.size = size; this.size = size;
this.rowLength = rowLength; this.rowLength = rowLength;
@ -53,6 +62,7 @@ public enum IronChestType {
this.modelTexture = modelTexture; this.modelTexture = modelTexture;
this.textureRow = textureRow; this.textureRow = textureRow;
this.clazz = clazz; this.clazz = clazz;
this.itemFilter = itemFilter;
this.recipes = recipes; this.recipes = recipes;
this.matList = new ArrayList<String>(); this.matList = new ArrayList<String>();
matList.addAll(mats); matList.addAll(mats);
@ -153,6 +163,10 @@ public enum IronChestType {
{ {
return Block.obsidian; return Block.obsidian;
} }
else if (mat == "dirt")
{
return Block.dirt;
}
return mat; return mat;
} }
@ -230,4 +244,14 @@ public enum IronChestType {
private static String[] sideNames = { "top", "front", "side" }; private static String[] sideNames = { "top", "front", "side" };
private static int[] sideMapping = { 0, 0, 2, 1, 2, 2, 2 }; private static int[] sideMapping = { 0, 0, 2, 1, 2, 2, 2 };
public Slot makeSlot(IInventory chestInventory, int index, int x, int y)
{
return new ValidatingSlot(chestInventory, index, x, y, this);
}
public boolean acceptsStack(ItemStack itemstack)
{
return itemFilter == null || itemstack == null || itemstack.getItem() == itemFilter;
}
} }

View File

@ -0,0 +1,29 @@
package cpw.mods.ironchest;
import cpw.mods.fml.common.registry.LanguageRegistry;
import net.minecraft.block.Block;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.StatCollector;
public class TileEntityDirtChest extends TileEntityIronChest {
private static ItemStack dirtChest9000GuideBook = new ItemStack(Item.writtenBook);
static {
dirtChest9000GuideBook.setTagInfo("author", new NBTTagString("author", "cpw"));
dirtChest9000GuideBook.setTagInfo("title", new NBTTagString("title", StatCollector.translateToLocal("book.ironchest:dirtchest9000.title")));
NBTTagList pages = new NBTTagList();
pages.appendTag(new NBTTagString("1", StatCollector.translateToLocal("book.ironchest:dirtchest9000.page1")));
pages.appendTag(new NBTTagString("2", StatCollector.translateToLocal("book.ironchest:dirtchest9000.page2")));
pages.appendTag(new NBTTagString("3", StatCollector.translateToLocal("book.ironchest:dirtchest9000.page3")));
pages.appendTag(new NBTTagString("4", StatCollector.translateToLocal("book.ironchest:dirtchest9000.page4")));
pages.appendTag(new NBTTagString("5", StatCollector.translateToLocal("book.ironchest:dirtchest9000.page5")));
dirtChest9000GuideBook.setTagInfo("pages", pages);
}
public TileEntityDirtChest() {
super(IronChestType.DIRTCHEST9000);
setInventorySlotContents(0, dirtChest9000GuideBook.copy());
}
}

View File

@ -500,7 +500,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
@Override @Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) public boolean isItemValidForSlot(int i, ItemStack itemstack)
{ {
return true; return type.acceptsStack(itemstack);
} }
@Override @Override

View File

@ -0,0 +1,21 @@
package cpw.mods.ironchest;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ValidatingSlot extends Slot {
private IronChestType type;
public ValidatingSlot(IInventory par1iInventory, int par2, int par3, int par4, IronChestType type)
{
super(par1iInventory, par2, par3, par4);
this.type = type;
}
@Override
public boolean isItemValid(ItemStack par1ItemStack)
{
return type.acceptsStack(par1ItemStack);
}
}

View File

@ -27,7 +27,8 @@ public class GUIChest extends GuiContainer {
COPPER(new ResourceLocation("ironchest", "textures/gui/coppercontainer.png")), COPPER(new ResourceLocation("ironchest", "textures/gui/coppercontainer.png")),
SILVER(new ResourceLocation("ironchest", "textures/gui/silvercontainer.png")), SILVER(new ResourceLocation("ironchest", "textures/gui/silvercontainer.png")),
GOLD(new ResourceLocation("ironchest", "textures/gui/goldcontainer.png")), GOLD(new ResourceLocation("ironchest", "textures/gui/goldcontainer.png")),
DIAMOND(new ResourceLocation("ironchest", "textures/gui/diamondcontainer.png")); DIAMOND(new ResourceLocation("ironchest", "textures/gui/diamondcontainer.png")),
DIRT(new ResourceLocation("ironchest", "textures/gui/dirtcontainer.png"));
public final ResourceLocation location; public final ResourceLocation location;
private ResourceList(ResourceLocation loc) { private ResourceList(ResourceLocation loc) {
this.location = loc; this.location = loc;
@ -40,7 +41,8 @@ public class GUIChest extends GuiContainer {
COPPER(184, 184, ResourceList.COPPER, IronChestType.COPPER), COPPER(184, 184, ResourceList.COPPER, IronChestType.COPPER),
SILVER(184, 238, ResourceList.SILVER, IronChestType.SILVER), SILVER(184, 238, ResourceList.SILVER, IronChestType.SILVER),
CRYSTAL(238, 256, ResourceList.DIAMOND, IronChestType.CRYSTAL), CRYSTAL(238, 256, ResourceList.DIAMOND, IronChestType.CRYSTAL),
OBSIDIAN(238, 256, ResourceList.DIAMOND, IronChestType.OBSIDIAN); OBSIDIAN(238, 256, ResourceList.DIAMOND, IronChestType.OBSIDIAN),
DIRTCHEST9000(184, 184, ResourceList.DIRT, IronChestType.DIRTCHEST9000);
private int xSize; private int xSize;
private int ySize; private int ySize;

View File

@ -5,6 +5,7 @@ tile.ironchest:COPPER.name=Copper Chest
tile.ironchest:SILVER.name=Silver Chest tile.ironchest:SILVER.name=Silver Chest
tile.ironchest:CRYSTAL.name=Crystal Chest tile.ironchest:CRYSTAL.name=Crystal Chest
tile.ironchest:OBSIDIAN.name=Obsidian Chest tile.ironchest:OBSIDIAN.name=Obsidian Chest
tile.ironchest:DIRTCHEST9000.name=DirtChest 9000!
item.ironchest:IRONGOLD.name=Iron to Gold Chest Upgrade item.ironchest:IRONGOLD.name=Iron to Gold Chest Upgrade
item.ironchest:GOLDDIAMOND.name=Gold to Diamond Chest Upgrade item.ironchest:GOLDDIAMOND.name=Gold to Diamond Chest Upgrade
@ -15,3 +16,10 @@ item.ironchest:DIAMONDCRYSTAL.name=Diamond to Crystal Chest Upgrade
item.ironchest:WOODIRON.name=Wood to Iron Chest Upgrade item.ironchest:WOODIRON.name=Wood to Iron Chest Upgrade
item.ironchest:WOODCOPPER.name=Wood to Copper Chest Upgrade item.ironchest:WOODCOPPER.name=Wood to Copper Chest Upgrade
item.ironchest:DIAMONDOBSIDIAN.name=Diamond to Obsidian Chest Upgrade item.ironchest:DIAMONDOBSIDIAN.name=Diamond to Obsidian Chest Upgrade
book.ironchest:dirtchest9000.title=How to use your DirtChest 9000!
book.ironchest:dirtchest9000.page1=Welcome to your new DirtChest 9000! We hope you will enjoy many happy years of storing your stack of dirt in our storage utility.
book.ironchest:dirtchest9000.page2=Usage: simply insert the stack of dirt of your choice into the highly receptive slot and enjoy the great convenience of having that dirt available to you, any time you pass by this chest!
book.ironchest:dirtchest9000.page3=We hope you have enjoyed reviewing this instruction manual, and hope you will consider using our products in future! Kind regards, The DirtChest 9000 manual writers incorporated.
book.ironchest:dirtchest9000.page4=Warranty: This product has no warranty of any kind. Your dirt may not be stored, it may slowly leech into the environment, or alternatively, it may not do anything at all.
book.ironchest:dirtchest9000.page5=DirtChest 9000 is kind to the environment. Please dispose of this guide book responsibly, and do not whatever you do just chuck it into some lava. We would be very sad.

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB