Updating some broken bag code

This commit is contained in:
pahimar 2014-02-10 20:02:38 -05:00
parent a3b0758b9f
commit ffc5a204f1
19 changed files with 274 additions and 69 deletions

View file

@ -22,18 +22,43 @@ import org.lwjgl.opengl.GL11;
@SideOnly(Side.CLIENT)
public class GuiAlchemicalBag extends GuiContainer
{
public GuiAlchemicalBag(InventoryPlayer inventoryPlayer)
private ItemStack alchemicalBag;
public GuiAlchemicalBag(InventoryPlayer inventoryPlayer, ItemStack alchemicalBag)
{
super(new ContainerAlchemicalBag(inventoryPlayer));
xSize = 248;
ySize = 186;
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;
}
}
@Override
protected void drawGuiContainerForegroundLayer(int x, int y)
{
fontRenderer.drawString(StatCollector.translateToLocal(Strings.CONTAINER_ALCHEMICAL_BAG_NAME), 8, 6, 4210752);
fontRenderer.drawString(StatCollector.translateToLocal(Strings.CONTAINER_INVENTORY), 44, ySize - 96 + 2, 4210752);
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
@ -41,8 +66,18 @@ public class GuiAlchemicalBag extends GuiContainer
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
// this.mc.getTextureManager().bindTexture(...)
this.mc.getTextureManager().bindTexture(Textures.GUI_ALCHEMICAL_STORAGE_SMALL);
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;

View file

@ -62,15 +62,15 @@ public class GuiAlchemicalChest extends GuiContainer
if (tileAlchemicalChest.getState() == 0)
{
this.mc.getTextureManager().bindTexture(Textures.GUI_ALCHEMICAL_STORAGE_SMALL);
this.mc.getTextureManager().bindTexture(Textures.GUI_ALCHEMICAL_CHEST_SMALL);
}
else if (tileAlchemicalChest.getState() == 1)
{
this.mc.getTextureManager().bindTexture(Textures.GUI_ALCHEMICAL_STORAGE_MEDIUM);
this.mc.getTextureManager().bindTexture(Textures.GUI_ALCHEMICAL_CHEST_MEDIUM);
}
else if (tileAlchemicalChest.getState() == 2)
{
this.mc.getTextureManager().bindTexture(Textures.GUI_ALCHEMICAL_STORAGE_LARGE);
this.mc.getTextureManager().bindTexture(Textures.GUI_ALCHEMICAL_CHEST_LARGE);
}
int xStart = (width - xSize) / 2;

View file

@ -2,6 +2,7 @@ package com.pahimar.ee3.handler;
import com.pahimar.ee3.configuration.ConfigurationSettings;
import com.pahimar.ee3.helper.ItemStackNBTHelper;
import com.pahimar.ee3.item.ItemAlchemicalBag;
import com.pahimar.ee3.item.crafting.RecipesAlchemicalBagDyes;
import com.pahimar.ee3.item.crafting.RecipesTransmutationStones;
import com.pahimar.ee3.item.crafting.RecipesVanilla;
@ -14,6 +15,8 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import java.util.UUID;
/**
* Equivalent-Exchange-3
* <p/>
@ -38,16 +41,27 @@ public class CraftingHandler implements ICraftingHandler
}
@Override
public void onCrafting(EntityPlayer player, ItemStack item, IInventory craftMatrix)
public void onCrafting(EntityPlayer player, ItemStack itemStack, IInventory craftMatrix)
{
if (player.worldObj.isRemote)
{
doPortableCrafting(player, craftMatrix);
}
if (!player.worldObj.isRemote)
{
// Set the UUID on an Alchemical Bag when picked up from crafting
if (itemStack.getItem() instanceof ItemAlchemicalBag)
{
UUID itemUUID = UUID.randomUUID();
ItemStackNBTHelper.setLong(itemStack, Strings.NBT_ITEM_UUID_MOST_SIG, itemUUID.getMostSignificantBits());
ItemStackNBTHelper.setLong(itemStack, Strings.NBT_ITEM_UUID_LEAST_SIG, itemUUID.getLeastSignificantBits());
}
}
}
@Override
public void onSmelting(EntityPlayer player, ItemStack item)
public void onSmelting(EntityPlayer player, ItemStack itemStack)
{
}

View file

@ -16,7 +16,6 @@ public class GuiHandler implements IGuiHandler
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
if (ID == GuiIds.PORTABLE_CRAFTING)
{
return new ContainerPortableCrafting(player.inventory, world, x, y, z);
@ -32,9 +31,8 @@ public class GuiHandler implements IGuiHandler
return new ContainerAlchemicalChest(player.inventory, tileAlchemicalChest);
}
else if (ID == GuiIds.ALCHEMICAL_BAG)
// TODO Alchemical Bag inventory work is incomplete
{
return new ContainerAlchemicalBag(player.inventory);
return new ContainerAlchemicalBag(player.inventory, player.getHeldItem());
}
else if (ID == GuiIds.ALUDEL)
{
@ -53,7 +51,6 @@ public class GuiHandler implements IGuiHandler
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
if (ID == GuiIds.PORTABLE_CRAFTING)
{
return new GuiPortableCrafting(player, world, x, y, z);
@ -69,9 +66,8 @@ public class GuiHandler implements IGuiHandler
return new GuiAlchemicalChest(player.inventory, tileAlchemicalChest);
}
else if (ID == GuiIds.ALCHEMICAL_BAG)
// TODO Alchemical Bag inventory work is incomplete
{
return new GuiAlchemicalBag(player.inventory);
return new GuiAlchemicalBag(player.inventory, player.getHeldItem());
}
else if (ID == GuiIds.ALUDEL)
{

View file

@ -155,7 +155,6 @@ public class ItemStackNBTHelper
// long
public static long getLong(ItemStack itemStack, String keyName)
{
initNBTTagCompound(itemStack);
if (!itemStack.stackTagCompound.hasKey(keyName))
@ -168,7 +167,6 @@ public class ItemStackNBTHelper
public static void setLong(ItemStack itemStack, String keyName, long keyValue)
{
initNBTTagCompound(itemStack);
itemStack.stackTagCompound.setLong(keyName, keyValue);
@ -177,7 +175,6 @@ public class ItemStackNBTHelper
// float
public static float getFloat(ItemStack itemStack, String keyName)
{
initNBTTagCompound(itemStack);
if (!itemStack.stackTagCompound.hasKey(keyName))

View file

@ -17,41 +17,110 @@ import net.minecraft.item.ItemStack;
*/
public class ContainerAlchemicalBag extends Container
{
private final int BAG_INVENTORY_ROWS = 9;
private final int BAG_INVENTORY_COLUMNS = 13;
private int bagInventoryRows;
private int bagInventoryColumns;
// Small Bag
public static final int SMALL_BAG_INVENTORY_ROWS = 4;
public static final int SMALL_BAG_INVENTORY_COLUMNS = 12;
// Medium Bag
public static final int MEDIUM_BAG_INVENTORY_ROWS = 7;
public static final int MEDIUM_BAG_INVENTORY_COLUMNS = 12;
// Large Bag
public static final int LARGE_BAG_INVENTORY_ROWS = 9;
public static final int LARGE_BAG_INVENTORY_COLUMNS = 13;
// Player Inventory
private final int PLAYER_INVENTORY_ROWS = 3;
private final int PLAYER_INVENTORY_COLUMNS = 9;
public ContainerAlchemicalBag(InventoryPlayer inventoryPlayer)
public ContainerAlchemicalBag(InventoryPlayer inventoryPlayer, ItemStack alchemicalBag)
{
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)
{
this.addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * PLAYER_INVENTORY_COLUMNS + PLAYER_INVENTORY_COLUMNS, 44 + inventoryColumnIndex * 18, 104 + inventoryRowIndex * 18));
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)
{
this.addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 44 + actionBarSlotIndex * 18, 162));
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
public boolean canInteractWith(EntityPlayer var1)
{
return true;
}
@Override
public void onContainerClosed(EntityPlayer player)
{
super.onContainerClosed(player);
if (!player.worldObj.isRemote)
@ -73,37 +142,7 @@ public class ContainerAlchemicalBag extends Container
@Override
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex)
{
ItemStack newItemStack = null;
Slot slot = (Slot) inventorySlots.get(slotIndex);
if (slot != null && slot.getHasStack())
{
ItemStack itemStack = slot.getStack();
newItemStack = itemStack.copy();
if (slotIndex < BAG_INVENTORY_ROWS * BAG_INVENTORY_COLUMNS)
{
if (!this.mergeItemStack(itemStack, BAG_INVENTORY_ROWS * BAG_INVENTORY_COLUMNS, inventorySlots.size(), false))
{
return null;
}
}
else if (!this.mergeItemStack(itemStack, 0, BAG_INVENTORY_ROWS * BAG_INVENTORY_COLUMNS, false))
{
return null;
}
if (itemStack.stackSize == 0)
{
slot.putStack(null);
}
else
{
slot.onSlotChanged();
}
}
return newItemStack;
// TODO
return null;
}
}

View file

@ -35,7 +35,7 @@ public class ContainerAludel extends Container
this.addSlotToContainer(new Slot(tileAludel, TileAludel.FUEL_INVENTORY_INDEX, 44, 74));
this.addSlotToContainer(new Slot(tileAludel, TileAludel.INPUT_INVENTORY_INDEX, 44, 18));
this.addSlotToContainer(new Slot(tileAludel, TileAludel.DUST_INVENTORY_INDEX, 44, 39));
this.addSlotToContainer(new Slot(tileAludel, TileAludel.OUTPUT_INVENTORY_INDEX, 120, 39));
this.addSlotToContainer(new SlotAludelOutput(tileAludel, TileAludel.OUTPUT_INVENTORY_INDEX, 120, 39));
// Add the player's inventory slots to the container
for (int inventoryRowIndex = 0; inventoryRowIndex < PLAYER_INVENTORY_ROWS; ++inventoryRowIndex)

View file

@ -17,24 +17,20 @@ import net.minecraft.world.World;
*/
public class ContainerPortableCrafting extends ContainerWorkbench
{
public ContainerPortableCrafting(InventoryPlayer inventoryPlayer, World world, int x, int y, int z)
{
super(inventoryPlayer, world, x, y, z);
}
@Override
public boolean canInteractWith(EntityPlayer var1)
{
return true;
}
@Override
public void onContainerClosed(EntityPlayer player)
{
super.onContainerClosed(player);
if (!player.worldObj.isRemote)

View file

@ -0,0 +1,86 @@
package com.pahimar.ee3.inventory;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
public class InventoryAlchemicalBag implements IInventory
{
@Override
public int getSizeInventory()
{
return 0;
}
@Override
public ItemStack getStackInSlot(int i)
{
return null;
}
@Override
public ItemStack decrStackSize(int i, int j)
{
return null;
}
@Override
public ItemStack getStackInSlotOnClosing(int i)
{
return null;
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack)
{
}
@Override
public String getInvName()
{
return null;
}
@Override
public boolean isInvNameLocalized()
{
return false;
}
@Override
public int getInventoryStackLimit()
{
return 0;
}
@Override
public void onInventoryChanged()
{
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer)
{
return false;
}
@Override
public void openChest()
{
}
@Override
public void closeChest()
{
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack)
{
return false;
}
}

View file

@ -0,0 +1,28 @@
package com.pahimar.ee3.inventory;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class SlotAludelOutput extends Slot
{
public SlotAludelOutput(IInventory inventory, int x, int y, int z)
{
super(inventory, x, y, z);
}
@Override
public boolean isItemValid(ItemStack par1ItemStack)
{
return false;
}
@Override
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack)
{
super.onPickupFromSlot(entityPlayer, itemStack);
GameRegistry.onItemCrafted(entityPlayer, itemStack, inventory);
}
}

View file

@ -1,5 +1,7 @@
package com.pahimar.ee3.inventory;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
@ -23,4 +25,11 @@ public class SlotCalcinator extends Slot
{
return false;
}
@Override
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack)
{
super.onPickupFromSlot(entityPlayer, itemStack);
GameRegistry.onItemCrafted(entityPlayer, itemStack, inventory);
}
}

View file

@ -34,6 +34,8 @@ public class Strings
public static final String NBT_ITEM_CRAFTING_GUI_OPEN = "itemCraftingGuiOpen";
public static final String NBT_ITEM_TRANSMUTATION_GUI_OPEN = "itemTransmutationGuiOpen";
public static final String NBT_ITEM_ALCHEMICAL_BAG_GUI_OPEN = "itemAlchemicalBagGuiOpen";
public static final String NBT_ITEM_UUID_MOST_SIG = "itemUUIDMostSig";
public static final String NBT_ITEM_UUID_LEAST_SIG = "itemUUIDLeastSig";
public static final String NBT_ITEM_DISPLAY = "display";
public static final String NBT_ITEM_COLOR = "color";
public static final String NBT_TE_STATE_KEY = "teState";

View file

@ -29,9 +29,12 @@ public class Textures
// GUI textures
public static final ResourceLocation GUI_CALCINATOR = ResourceLocationHelper.getResourceLocation(GUI_SHEET_LOCATION + "calcinator.png");
public static final ResourceLocation GUI_ALUDEL = ResourceLocationHelper.getResourceLocation(GUI_SHEET_LOCATION + "aludel.png");
public static final ResourceLocation GUI_ALCHEMICAL_STORAGE_SMALL = ResourceLocationHelper.getResourceLocation(GUI_SHEET_LOCATION + "alchemicalStorage_small.png");
public static final ResourceLocation GUI_ALCHEMICAL_STORAGE_MEDIUM = ResourceLocationHelper.getResourceLocation(GUI_SHEET_LOCATION + "alchemicalStorage_medium.png");
public static final ResourceLocation GUI_ALCHEMICAL_STORAGE_LARGE = ResourceLocationHelper.getResourceLocation(GUI_SHEET_LOCATION + "alchemicalStorage_large.png");
public static final ResourceLocation GUI_ALCHEMICAL_BAG_SMALL = ResourceLocationHelper.getResourceLocation(GUI_SHEET_LOCATION + "alchemicalBag_small.png");
public static final ResourceLocation GUI_ALCHEMICAL_BAG_MEDIUM = ResourceLocationHelper.getResourceLocation(GUI_SHEET_LOCATION + "alchemicalBag_medium.png");
public static final ResourceLocation GUI_ALCHEMICAL_BAG_LARGE = ResourceLocationHelper.getResourceLocation(GUI_SHEET_LOCATION + "alchemicalBag_large.png");
public static final ResourceLocation GUI_ALCHEMICAL_CHEST_SMALL = ResourceLocationHelper.getResourceLocation(GUI_SHEET_LOCATION + "alchemicalChest_small.png");
public static final ResourceLocation GUI_ALCHEMICAL_CHEST_MEDIUM = ResourceLocationHelper.getResourceLocation(GUI_SHEET_LOCATION + "alchemicalChest_medium.png");
public static final ResourceLocation GUI_ALCHEMICAL_CHEST_LARGE = ResourceLocationHelper.getResourceLocation(GUI_SHEET_LOCATION + "alchemicalChest_large.png");
public static final ResourceLocation GUI_PORTABLE_CRAFTING = new ResourceLocation("textures/gui/container/crafting_table.png");
public static final ResourceLocation GUI_GLASS_BELL = ResourceLocationHelper.getResourceLocation(GUI_SHEET_LOCATION + "glassBell.png");

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB