Bit more work on the bag inventory, should be done tomorrow
This commit is contained in:
parent
0980cf9101
commit
f5d2e4dbd0
4 changed files with 139 additions and 128 deletions
|
@ -2,14 +2,13 @@ package com.pahimar.ee3.client.gui.inventory;
|
|||
|
||||
import com.pahimar.ee3.helper.ItemStackNBTHelper;
|
||||
import com.pahimar.ee3.inventory.ContainerAlchemicalBag;
|
||||
import com.pahimar.ee3.inventory.InventoryAlchemicalBag;
|
||||
import com.pahimar.ee3.lib.Strings;
|
||||
import com.pahimar.ee3.lib.Textures;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
/**
|
||||
|
@ -22,43 +21,16 @@ import org.lwjgl.opengl.GL11;
|
|||
@SideOnly(Side.CLIENT)
|
||||
public class GuiAlchemicalBag extends GuiContainer
|
||||
{
|
||||
private ItemStack alchemicalBag;
|
||||
|
||||
public GuiAlchemicalBag(InventoryPlayer inventoryPlayer, ItemStack alchemicalBag)
|
||||
public GuiAlchemicalBag(InventoryPlayer inventoryPlayer, InventoryAlchemicalBag inventoryAlchemicalBag)
|
||||
{
|
||||
super(new ContainerAlchemicalBag(inventoryPlayer, alchemicalBag));
|
||||
this.alchemicalBag = alchemicalBag;
|
||||
|
||||
if (this.alchemicalBag.getItemDamage() == 0)
|
||||
{
|
||||
xSize = 230;
|
||||
ySize = 186;
|
||||
}
|
||||
else if (this.alchemicalBag.getItemDamage() == 1)
|
||||
{
|
||||
xSize = 230;
|
||||
ySize = 240;
|
||||
}
|
||||
else if (this.alchemicalBag.getItemDamage() == 2)
|
||||
{
|
||||
xSize = 248;
|
||||
ySize = 256;
|
||||
}
|
||||
super(new ContainerAlchemicalBag(inventoryPlayer, inventoryAlchemicalBag));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int x, int y)
|
||||
{
|
||||
if (this.alchemicalBag.getItemDamage() == 0 || alchemicalBag.getItemDamage() == 1)
|
||||
{
|
||||
fontRenderer.drawString(StatCollector.translateToLocal(Strings.CONTAINER_ALCHEMICAL_BAG_NAME), 8, 8, 4210752);
|
||||
fontRenderer.drawString(StatCollector.translateToLocal(Strings.CONTAINER_INVENTORY), 35, ySize - 94 + 2, 4210752);
|
||||
}
|
||||
else
|
||||
{
|
||||
fontRenderer.drawString(StatCollector.translateToLocal(Strings.CONTAINER_ALCHEMICAL_BAG_NAME), 8, 8, 4210752);
|
||||
fontRenderer.drawString(StatCollector.translateToLocal(Strings.CONTAINER_INVENTORY), 44, ySize - 94 + 2, 4210752);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -66,19 +38,6 @@ public class GuiAlchemicalBag extends GuiContainer
|
|||
{
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
if (this.alchemicalBag.getItemDamage() == 0)
|
||||
{
|
||||
this.mc.getTextureManager().bindTexture(Textures.GUI_ALCHEMICAL_BAG_SMALL);
|
||||
}
|
||||
else if (this.alchemicalBag.getItemDamage() == 1)
|
||||
{
|
||||
this.mc.getTextureManager().bindTexture(Textures.GUI_ALCHEMICAL_BAG_MEDIUM);
|
||||
}
|
||||
else if (this.alchemicalBag.getItemDamage() == 2)
|
||||
{
|
||||
this.mc.getTextureManager().bindTexture(Textures.GUI_ALCHEMICAL_BAG_LARGE);
|
||||
}
|
||||
|
||||
int xStart = (width - xSize) / 2;
|
||||
int yStart = (height - ySize) / 2;
|
||||
this.drawTexturedModalRect(xStart, yStart, 0, 0, xSize, ySize);
|
||||
|
|
|
@ -32,7 +32,7 @@ public class GuiHandler implements IGuiHandler
|
|||
}
|
||||
else if (ID == GuiIds.ALCHEMICAL_BAG)
|
||||
{
|
||||
return new ContainerAlchemicalBag(player.inventory, player.getHeldItem());
|
||||
// return new ContainerAlchemicalBag(player.inventory, player.getHeldItem());
|
||||
}
|
||||
else if (ID == GuiIds.ALUDEL)
|
||||
{
|
||||
|
@ -67,7 +67,7 @@ public class GuiHandler implements IGuiHandler
|
|||
}
|
||||
else if (ID == GuiIds.ALCHEMICAL_BAG)
|
||||
{
|
||||
return new GuiAlchemicalBag(player.inventory, player.getHeldItem());
|
||||
// return new GuiAlchemicalBag(player.inventory, player.getHeldItem());
|
||||
}
|
||||
else if (ID == GuiIds.ALUDEL)
|
||||
{
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.pahimar.ee3.lib.Strings;
|
|||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
|
@ -36,80 +35,80 @@ public class ContainerAlchemicalBag extends Container
|
|||
private final int PLAYER_INVENTORY_ROWS = 3;
|
||||
private final int PLAYER_INVENTORY_COLUMNS = 9;
|
||||
|
||||
public ContainerAlchemicalBag(InventoryPlayer inventoryPlayer, ItemStack alchemicalBag)
|
||||
public ContainerAlchemicalBag(InventoryPlayer inventoryPlayer, InventoryAlchemicalBag inventoryAlchemicalBag)
|
||||
{
|
||||
if (alchemicalBag.getItemDamage() == 0)
|
||||
{
|
||||
bagInventoryRows = SMALL_BAG_INVENTORY_ROWS;
|
||||
bagInventoryColumns = SMALL_BAG_INVENTORY_COLUMNS;
|
||||
}
|
||||
else if (alchemicalBag.getItemDamage() == 1)
|
||||
{
|
||||
bagInventoryRows = MEDIUM_BAG_INVENTORY_ROWS;
|
||||
bagInventoryColumns = MEDIUM_BAG_INVENTORY_COLUMNS;
|
||||
}
|
||||
else if (alchemicalBag.getItemDamage() == 2)
|
||||
{
|
||||
bagInventoryRows = LARGE_BAG_INVENTORY_ROWS;
|
||||
bagInventoryColumns = LARGE_BAG_INVENTORY_COLUMNS;
|
||||
}
|
||||
|
||||
// Add the Alchemical Chest slots to the container
|
||||
for (int bagRowIndex = 0; bagRowIndex < bagInventoryRows; ++bagRowIndex)
|
||||
{
|
||||
for (int bagColumnIndex = 0; bagColumnIndex < bagInventoryColumns; ++bagColumnIndex)
|
||||
{
|
||||
if (alchemicalBag.getItemDamage() == 0)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(inventoryPlayer, bagColumnIndex + bagRowIndex * bagInventoryColumns, 8 + bagColumnIndex * 18, 18 + bagRowIndex * 18));
|
||||
}
|
||||
else if (alchemicalBag.getItemDamage() == 1)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(inventoryPlayer, bagColumnIndex + bagRowIndex * bagInventoryColumns, 8 + bagColumnIndex * 18, 18 + bagRowIndex * 18));
|
||||
}
|
||||
else if (alchemicalBag.getItemDamage() == 2)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(inventoryPlayer, bagColumnIndex + bagRowIndex * bagInventoryColumns, 8 + bagColumnIndex * 18, 8 + bagRowIndex * 18));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add the player's inventory slots to the container
|
||||
for (int inventoryRowIndex = 0; inventoryRowIndex < PLAYER_INVENTORY_ROWS; ++inventoryRowIndex)
|
||||
{
|
||||
for (int inventoryColumnIndex = 0; inventoryColumnIndex < PLAYER_INVENTORY_COLUMNS; ++inventoryColumnIndex)
|
||||
{
|
||||
if (alchemicalBag.getItemDamage() == 0)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 35 + inventoryColumnIndex * 18, 104 + inventoryRowIndex * 18));
|
||||
}
|
||||
else if (alchemicalBag.getItemDamage() == 1)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 35 + inventoryColumnIndex * 18, 158 + inventoryRowIndex * 18));
|
||||
}
|
||||
else if (alchemicalBag.getItemDamage() == 2)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 44 + inventoryColumnIndex * 18, 174 + inventoryRowIndex * 18));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add the player's action bar slots to the container
|
||||
for (int actionBarSlotIndex = 0; actionBarSlotIndex < PLAYER_INVENTORY_COLUMNS; ++actionBarSlotIndex)
|
||||
{
|
||||
if (alchemicalBag.getItemDamage() == 0)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 35 + actionBarSlotIndex * 18, 162));
|
||||
}
|
||||
else if (alchemicalBag.getItemDamage() == 1)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 35 + actionBarSlotIndex * 18, 216));
|
||||
}
|
||||
else if (alchemicalBag.getItemDamage() == 2)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 44 + actionBarSlotIndex * 18, 232));
|
||||
}
|
||||
}
|
||||
// if (alchemicalBag.getItemDamage() == 0)
|
||||
// {
|
||||
// bagInventoryRows = SMALL_BAG_INVENTORY_ROWS;
|
||||
// bagInventoryColumns = SMALL_BAG_INVENTORY_COLUMNS;
|
||||
// }
|
||||
// else if (alchemicalBag.getItemDamage() == 1)
|
||||
// {
|
||||
// bagInventoryRows = MEDIUM_BAG_INVENTORY_ROWS;
|
||||
// bagInventoryColumns = MEDIUM_BAG_INVENTORY_COLUMNS;
|
||||
// }
|
||||
// else if (alchemicalBag.getItemDamage() == 2)
|
||||
// {
|
||||
// bagInventoryRows = LARGE_BAG_INVENTORY_ROWS;
|
||||
// bagInventoryColumns = LARGE_BAG_INVENTORY_COLUMNS;
|
||||
// }
|
||||
//
|
||||
// // Add the Alchemical Chest slots to the container
|
||||
// for (int bagRowIndex = 0; bagRowIndex < bagInventoryRows; ++bagRowIndex)
|
||||
// {
|
||||
// for (int bagColumnIndex = 0; bagColumnIndex < bagInventoryColumns; ++bagColumnIndex)
|
||||
// {
|
||||
// if (alchemicalBag.getItemDamage() == 0)
|
||||
// {
|
||||
// this.addSlotToContainer(new Slot(inventoryPlayer, bagColumnIndex + bagRowIndex * bagInventoryColumns, 8 + bagColumnIndex * 18, 18 + bagRowIndex * 18));
|
||||
// }
|
||||
// else if (alchemicalBag.getItemDamage() == 1)
|
||||
// {
|
||||
// this.addSlotToContainer(new Slot(inventoryPlayer, bagColumnIndex + bagRowIndex * bagInventoryColumns, 8 + bagColumnIndex * 18, 18 + bagRowIndex * 18));
|
||||
// }
|
||||
// else if (alchemicalBag.getItemDamage() == 2)
|
||||
// {
|
||||
// this.addSlotToContainer(new Slot(inventoryPlayer, bagColumnIndex + bagRowIndex * bagInventoryColumns, 8 + bagColumnIndex * 18, 8 + bagRowIndex * 18));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Add the player's inventory slots to the container
|
||||
// for (int inventoryRowIndex = 0; inventoryRowIndex < PLAYER_INVENTORY_ROWS; ++inventoryRowIndex)
|
||||
// {
|
||||
// for (int inventoryColumnIndex = 0; inventoryColumnIndex < PLAYER_INVENTORY_COLUMNS; ++inventoryColumnIndex)
|
||||
// {
|
||||
// if (alchemicalBag.getItemDamage() == 0)
|
||||
// {
|
||||
// this.addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 35 + inventoryColumnIndex * 18, 104 + inventoryRowIndex * 18));
|
||||
// }
|
||||
// else if (alchemicalBag.getItemDamage() == 1)
|
||||
// {
|
||||
// this.addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 35 + inventoryColumnIndex * 18, 158 + inventoryRowIndex * 18));
|
||||
// }
|
||||
// else if (alchemicalBag.getItemDamage() == 2)
|
||||
// {
|
||||
// this.addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 44 + inventoryColumnIndex * 18, 174 + inventoryRowIndex * 18));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Add the player's action bar slots to the container
|
||||
// for (int actionBarSlotIndex = 0; actionBarSlotIndex < PLAYER_INVENTORY_COLUMNS; ++actionBarSlotIndex)
|
||||
// {
|
||||
// if (alchemicalBag.getItemDamage() == 0)
|
||||
// {
|
||||
// this.addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 35 + actionBarSlotIndex * 18, 162));
|
||||
// }
|
||||
// else if (alchemicalBag.getItemDamage() == 1)
|
||||
// {
|
||||
// this.addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 35 + actionBarSlotIndex * 18, 216));
|
||||
// }
|
||||
// else if (alchemicalBag.getItemDamage() == 2)
|
||||
// {
|
||||
// this.addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 44 + actionBarSlotIndex * 18, 232));
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package com.pahimar.ee3.inventory;
|
||||
|
||||
import com.pahimar.ee3.item.ItemAlchemicalBag;
|
||||
import com.pahimar.ee3.lib.Strings;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
public class InventoryAlchemicalBag implements IInventory, INBTTaggable
|
||||
{
|
||||
|
@ -13,6 +13,25 @@ public class InventoryAlchemicalBag implements IInventory, INBTTaggable
|
|||
protected ItemStack[] inventory;
|
||||
protected String customName;
|
||||
|
||||
public InventoryAlchemicalBag(ItemStack itemStack, int size)
|
||||
{
|
||||
parentItemStack = itemStack;
|
||||
inventory = new ItemStack[size];
|
||||
|
||||
readFromNBT(itemStack.getTagCompound());
|
||||
}
|
||||
|
||||
public void save()
|
||||
{
|
||||
NBTTagCompound nbtTagCompound = parentItemStack.getTagCompound();
|
||||
if (nbtTagCompound == null)
|
||||
{
|
||||
nbtTagCompound = new NBTTagCompound();
|
||||
}
|
||||
writeToNBT(nbtTagCompound);
|
||||
parentItemStack.setTagCompound(nbtTagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
|
@ -114,23 +133,57 @@ public class InventoryAlchemicalBag implements IInventory, INBTTaggable
|
|||
@Override
|
||||
public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack)
|
||||
{
|
||||
if (itemStack.getItem() instanceof ItemAlchemicalBag)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbtTagCompound)
|
||||
{
|
||||
// TODO
|
||||
if (nbtTagCompound != null && nbtTagCompound.hasKey("Items"))
|
||||
{
|
||||
// Read in the ItemStacks in the inventory from NBT
|
||||
if (nbtTagCompound.hasKey("Items"))
|
||||
{
|
||||
NBTTagList tagList = nbtTagCompound.getTagList("Items");
|
||||
inventory = new ItemStack[this.getSizeInventory()];
|
||||
for (int i = 0; i < tagList.tagCount(); ++i)
|
||||
{
|
||||
NBTTagCompound tagCompound = (NBTTagCompound) tagList.tagAt(i);
|
||||
byte slotIndex = tagCompound.getByte("Slot");
|
||||
if (slotIndex >= 0 && slotIndex < inventory.length)
|
||||
{
|
||||
inventory[slotIndex] = ItemStack.loadItemStackFromNBT(tagCompound);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read in any custom name for the inventory
|
||||
if (nbtTagCompound.hasKey("display") && nbtTagCompound.getTag("display").getClass().equals(NBTTagCompound.class))
|
||||
{
|
||||
if (nbtTagCompound.getCompoundTag("display").hasKey("Name"))
|
||||
{
|
||||
customName = nbtTagCompound.getCompoundTag("display").getString("Name");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbtTagCompound)
|
||||
{
|
||||
// TODO
|
||||
// Write the ItemStacks in the inventory to NBT
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
for (int currentIndex = 0; currentIndex < inventory.length; ++currentIndex)
|
||||
{
|
||||
if (inventory[currentIndex] != null)
|
||||
{
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
tagCompound.setByte("Slot", (byte) currentIndex);
|
||||
inventory[currentIndex].writeToNBT(tagCompound);
|
||||
tagList.appendTag(tagCompound);
|
||||
}
|
||||
}
|
||||
nbtTagCompound.setTag("Items", tagList);
|
||||
}
|
||||
|
||||
public boolean hasCustomName()
|
||||
|
|
Loading…
Reference in a new issue