Added a GUI to the Alchemical Tome (still a WIP), got the functionality of the Research Station working, and with the help of KingLemming we have a more intelligent shift click method for our containers

This commit is contained in:
Pahimar 2014-07-31 15:38:23 -04:00
parent b49df1901f
commit faa1e45997
17 changed files with 370 additions and 9 deletions

View file

@ -0,0 +1,40 @@
package com.pahimar.ee3.client.gui.inventory;
import com.pahimar.ee3.inventory.ContainerAlchemicalTome;
import com.pahimar.ee3.inventory.InventoryAlchemicalTome;
import com.pahimar.ee3.reference.Textures;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
@SideOnly(Side.CLIENT)
public class GuiAlchemicalTome extends GuiContainer
{
private InventoryAlchemicalTome inventoryAlchemicalTome;
public GuiAlchemicalTome(InventoryAlchemicalTome inventoryAlchemicalTome)
{
super(new ContainerAlchemicalTome(inventoryAlchemicalTome));
this.inventoryAlchemicalTome = inventoryAlchemicalTome;
ySize = 209;
}
@Override
protected void drawGuiContainerForegroundLayer(int x, int y)
{
String containerName = StatCollector.translateToLocal(inventoryAlchemicalTome.getInventoryName());
fontRendererObj.drawString(containerName, xSize / 2 - fontRendererObj.getStringWidth(containerName) / 2, 6, 4210752);
}
@Override
protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(Textures.Gui.ALCHEMICAL_TOME);
int xStart = (width - xSize) / 2;
int yStart = (height - ySize) / 2;
this.drawTexturedModalRect(xStart, yStart, 0, 0, xSize, ySize);
}
}

View file

@ -35,7 +35,6 @@ public class GuiGlassBell extends GuiContainer
@Override @Override
protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3)
{ {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(Textures.Gui.GLASS_BELL); this.mc.getTextureManager().bindTexture(Textures.Gui.GLASS_BELL);
int xStart = (width - xSize) / 2; int xStart = (width - xSize) / 2;

View file

@ -27,6 +27,10 @@ public class GuiHandler implements IGuiHandler
{ {
return new ContainerAlchemicalBag(entityPlayer, new InventoryAlchemicalBag(entityPlayer.getHeldItem())); return new ContainerAlchemicalBag(entityPlayer, new InventoryAlchemicalBag(entityPlayer.getHeldItem()));
} }
else if (id == GuiId.ALCHEMICAL_TOME.ordinal())
{
return new ContainerAlchemicalTome(new InventoryAlchemicalTome(entityPlayer.getHeldItem()));
}
else if (id == GuiId.CALCINATOR.ordinal()) else if (id == GuiId.CALCINATOR.ordinal())
{ {
TileEntityCalcinator tileEntityCalcinator = (TileEntityCalcinator) world.getTileEntity(x, y, z); TileEntityCalcinator tileEntityCalcinator = (TileEntityCalcinator) world.getTileEntity(x, y, z);
@ -68,6 +72,10 @@ public class GuiHandler implements IGuiHandler
{ {
return new GuiAlchemicalBag(entityPlayer, new InventoryAlchemicalBag(entityPlayer.getHeldItem())); return new GuiAlchemicalBag(entityPlayer, new InventoryAlchemicalBag(entityPlayer.getHeldItem()));
} }
else if (id == GuiId.ALCHEMICAL_TOME.ordinal())
{
return new GuiAlchemicalTome(new InventoryAlchemicalTome(entityPlayer.getHeldItem()));
}
else if (id == GuiId.CALCINATOR.ordinal()) else if (id == GuiId.CALCINATOR.ordinal())
{ {
TileEntityCalcinator tileEntityCalcinator = (TileEntityCalcinator) world.getTileEntity(x, y, z); TileEntityCalcinator tileEntityCalcinator = (TileEntityCalcinator) world.getTileEntity(x, y, z);

View file

@ -0,0 +1,31 @@
package com.pahimar.ee3.inventory;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
public class ContainerAlchemicalTome extends ContainerEE
{
private InventoryAlchemicalTome inventoryAlchemicalTome;
public ContainerAlchemicalTome(InventoryAlchemicalTome inventoryAlchemicalTome)
{
this.inventoryAlchemicalTome = inventoryAlchemicalTome;
for (int x = 0; x < 9; ++x)
{
for (int y = 0; y < 9; ++y)
{
if (y + x * 9 < inventoryAlchemicalTome.getSizeInventory())
{
this.addSlotToContainer(new Slot(inventoryAlchemicalTome, y + x * 9, 8 + y * 18, 18 + x * 18)
{
public boolean canTakeStack(EntityPlayer entityPlayer)
{
return false;
}
});
}
}
}
}
}

View file

@ -1,7 +1,10 @@
package com.pahimar.ee3.inventory; package com.pahimar.ee3.inventory;
import com.pahimar.ee3.util.ItemHelper;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public abstract class ContainerEE extends Container public abstract class ContainerEE extends Container
{ {
@ -13,4 +16,75 @@ public abstract class ContainerEE extends Container
{ {
return true; return true;
} }
@Override
protected boolean mergeItemStack(ItemStack itemStack, int slotMin, int slotMax, boolean ascending)
{
boolean slotFound = false;
int currentSlotIndex = ascending ? slotMax - 1 : slotMin;
Slot slot;
ItemStack stackInSlot;
if (itemStack.isStackable())
{
while (itemStack.stackSize > 0 && (!ascending && currentSlotIndex < slotMax || ascending && currentSlotIndex >= slotMin))
{
slot = (Slot) this.inventorySlots.get(currentSlotIndex);
stackInSlot = slot.getStack();
if (slot.isItemValid(itemStack) && ItemHelper.equalsIgnoreStackSize(itemStack, stackInSlot))
{
int combinedStackSize = stackInSlot.stackSize + itemStack.stackSize;
int slotStackSizeLimit = Math.min(stackInSlot.getMaxStackSize(), slot.getSlotStackLimit());
if (combinedStackSize <= slotStackSizeLimit)
{
itemStack.stackSize = 0;
stackInSlot.stackSize = combinedStackSize;
slot.onSlotChanged();
slotFound = true;
}
else if (stackInSlot.stackSize < slotStackSizeLimit)
{
itemStack.stackSize -= slotStackSizeLimit - stackInSlot.stackSize;
stackInSlot.stackSize = slotStackSizeLimit;
slot.onSlotChanged();
slotFound = true;
}
}
currentSlotIndex += ascending ? -1 : 1;
}
}
if (itemStack.stackSize > 0)
{
currentSlotIndex = ascending ? slotMax - 1 : slotMin;
while (!ascending && currentSlotIndex < slotMax || ascending && currentSlotIndex >= slotMin)
{
slot = (Slot) this.inventorySlots.get(currentSlotIndex);
stackInSlot = slot.getStack();
if (slot.isItemValid(itemStack) && stackInSlot == null)
{
slot.putStack(ItemHelper.cloneItemStack(itemStack, Math.min(itemStack.stackSize, slot.getSlotStackLimit())));
slot.onSlotChanged();
if (slot.getStack() != null)
{
itemStack.stackSize -= slot.getStack().stackSize;
slotFound = true;
}
break;
}
currentSlotIndex += ascending ? -1 : 1;
}
}
return slotFound;
}
} }

View file

@ -19,7 +19,14 @@ public class ContainerResearchStation extends ContainerEE
{ {
this.tileEntityResearchStation = tileEntityResearchStation; this.tileEntityResearchStation = tileEntityResearchStation;
this.addSlotToContainer(new Slot(tileEntityResearchStation, TileEntityResearchStation.ITEM_SLOT_INVENTORY_INDEX, 35, 41)); this.addSlotToContainer(new Slot(tileEntityResearchStation, TileEntityResearchStation.ITEM_SLOT_INVENTORY_INDEX, 35, 41)
{
@Override
public int getSlotStackLimit()
{
return 1;
}
});
this.addSlotToContainer(new SlotResearchStation(tileEntityResearchStation, TileEntityResearchStation.TOME_SLOT_INVENTORY_INDEX, 125, 41)); this.addSlotToContainer(new SlotResearchStation(tileEntityResearchStation, TileEntityResearchStation.TOME_SLOT_INVENTORY_INDEX, 125, 41));
// Add the player's inventory slots to the container // Add the player's inventory slots to the container

View file

@ -0,0 +1,139 @@
package com.pahimar.ee3.inventory;
import com.pahimar.ee3.reference.Names;
import com.pahimar.ee3.skill.PlayerKnowledge;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
public class InventoryAlchemicalTome implements IInventory
{
public PlayerKnowledge playerKnowledge;
protected ItemStack[] inventory;
protected String customName;
public InventoryAlchemicalTome(ItemStack itemStack)
{
this(PlayerKnowledge.readPlayerKnowledgeFromNBT(itemStack.getTagCompound()));
}
public InventoryAlchemicalTome(PlayerKnowledge playerKnowledge)
{
this.playerKnowledge = playerKnowledge;
inventory = playerKnowledge.getKnownItemStacks().toArray(new ItemStack[0]);
}
@Override
public int getSizeInventory()
{
return inventory.length;
}
@Override
public ItemStack getStackInSlot(int slotIndex)
{
return inventory[slotIndex];
}
@Override
public ItemStack decrStackSize(int slotIndex, int decrementAmount)
{
ItemStack itemStack = getStackInSlot(slotIndex);
if (itemStack != null)
{
if (itemStack.stackSize <= decrementAmount)
{
setInventorySlotContents(slotIndex, null);
}
else
{
itemStack = itemStack.splitStack(decrementAmount);
if (itemStack.stackSize == 0)
{
setInventorySlotContents(slotIndex, null);
}
}
}
return itemStack;
}
@Override
public ItemStack getStackInSlotOnClosing(int slotIndex)
{
if (inventory[slotIndex] != null)
{
ItemStack itemStack = inventory[slotIndex];
inventory[slotIndex] = null;
return itemStack;
}
else
{
return null;
}
}
@Override
public void setInventorySlotContents(int slotIndex, ItemStack itemStack)
{
inventory[slotIndex] = itemStack;
}
@Override
public String getInventoryName()
{
return this.hasCustomName() ? this.getCustomName() : Names.Containers.ALCHEMICAL_TOME;
}
@Override
public boolean hasCustomInventoryName()
{
return false;
}
@Override
public int getInventoryStackLimit()
{
return 1;
}
@Override
public void markDirty()
{
// NOOP
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityPlayer)
{
return true;
}
@Override
public void openInventory()
{
// NOOP
}
@Override
public void closeInventory()
{
// NOOP
}
@Override
public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack)
{
return false;
}
public boolean hasCustomName()
{
return customName != null && customName.length() > 0;
}
public String getCustomName()
{
return customName;
}
}

View file

@ -1,5 +1,7 @@
package com.pahimar.ee3.item; package com.pahimar.ee3.item;
import com.pahimar.ee3.EquivalentExchange3;
import com.pahimar.ee3.reference.GuiId;
import com.pahimar.ee3.reference.Names; import com.pahimar.ee3.reference.Names;
import com.pahimar.ee3.skill.PlayerKnowledge; import com.pahimar.ee3.skill.PlayerKnowledge;
import com.pahimar.ee3.util.IOwnable; import com.pahimar.ee3.util.IOwnable;
@ -31,6 +33,8 @@ public class ItemAlchemicalTome extends ItemEE implements IOwnable
{ {
// Set the owner // Set the owner
ItemHelper.setOwner(itemStack, entityPlayer); ItemHelper.setOwner(itemStack, entityPlayer);
entityPlayer.openGui(EquivalentExchange3.instance, GuiId.ALCHEMICAL_TOME.ordinal(), entityPlayer.worldObj, (int) entityPlayer.posX, (int) entityPlayer.posY, (int) entityPlayer.posZ);
} }
return itemStack; return itemStack;

View file

@ -9,5 +9,6 @@ public enum GuiId
ALCHEMICAL_BAG, ALCHEMICAL_BAG,
GLASS_BELL, GLASS_BELL,
RESEARCH_STATION, RESEARCH_STATION,
AUGMENTATION_TABLE; AUGMENTATION_TABLE,
ALCHEMICAL_TOME;
} }

View file

@ -107,6 +107,7 @@ public class Names
public static final String RESEARCH_STATION = "container.ee3:" + Blocks.RESEARCH_STATION; public static final String RESEARCH_STATION = "container.ee3:" + Blocks.RESEARCH_STATION;
public static final String GLASS_BELL = "container.ee3:" + Blocks.GLASS_BELL; public static final String GLASS_BELL = "container.ee3:" + Blocks.GLASS_BELL;
public static final String AUGMENTATION_TABLE = "container.ee3:" + Blocks.AUGMENTATION_TABLE; public static final String AUGMENTATION_TABLE = "container.ee3:" + Blocks.AUGMENTATION_TABLE;
public static final String ALCHEMICAL_TOME = "container.ee3:" + Items.ALCHEMICAL_TOME;
} }
public static final class Keys public static final class Keys

View file

@ -41,6 +41,7 @@ public final class Textures
public static final ResourceLocation RESEARCH_STATION = ResourceLocationHelper.getResourceLocation(GUI_SHEET_LOCATION + "researchStation.png"); public static final ResourceLocation RESEARCH_STATION = ResourceLocationHelper.getResourceLocation(GUI_SHEET_LOCATION + "researchStation.png");
public static final ResourceLocation AUGMENTATION_TABLE = ResourceLocationHelper.getResourceLocation(GUI_SHEET_LOCATION + "augmentationTable.png"); public static final ResourceLocation AUGMENTATION_TABLE = ResourceLocationHelper.getResourceLocation(GUI_SHEET_LOCATION + "augmentationTable.png");
public static final ResourceLocation PORTABLE_CRAFTING = new ResourceLocation("textures/gui/container/crafting_table.png"); public static final ResourceLocation PORTABLE_CRAFTING = new ResourceLocation("textures/gui/container/crafting_table.png");
public static final ResourceLocation ALCHEMICAL_TOME = ResourceLocationHelper.getResourceLocation(GUI_SHEET_LOCATION + "alchemicalTome.png");
} }
public static final class Effect public static final class Effect

View file

@ -41,7 +41,7 @@ public class PlayerKnowledge implements INBTTaggable
public boolean isItemStackKnown(ItemStack itemStack) public boolean isItemStackKnown(ItemStack itemStack)
{ {
ItemStack unitItemStack = itemStack.copy(); ItemStack unitItemStack = itemStack.copy();
itemStack.stackSize = 1; unitItemStack.stackSize = 1;
return this.knownItemStacks.contains(unitItemStack); return this.knownItemStacks.contains(unitItemStack);
} }
@ -53,7 +53,7 @@ public class PlayerKnowledge implements INBTTaggable
public boolean learnItemStack(ItemStack itemStack) public boolean learnItemStack(ItemStack itemStack)
{ {
ItemStack unitItemStack = itemStack.copy(); ItemStack unitItemStack = itemStack.copy();
itemStack.stackSize = 1; unitItemStack.stackSize = 1;
if (!this.knownItemStacks.contains(unitItemStack)) if (!this.knownItemStacks.contains(unitItemStack))
{ {
@ -66,7 +66,7 @@ public class PlayerKnowledge implements INBTTaggable
public boolean forgetItemStack(ItemStack itemStack) public boolean forgetItemStack(ItemStack itemStack)
{ {
ItemStack unitItemStack = itemStack.copy(); ItemStack unitItemStack = itemStack.copy();
itemStack.stackSize = 1; unitItemStack.stackSize = 1;
if (this.knownItemStacks.contains(unitItemStack)) if (this.knownItemStacks.contains(unitItemStack))
{ {
@ -123,4 +123,19 @@ public class PlayerKnowledge implements INBTTaggable
return playerKnowledge; return playerKnowledge;
} }
@Override
public String toString()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("[");
for (ItemStack itemStack : knownItemStacks)
{
stringBuilder.append(ItemHelper.toString(itemStack) + ", ");
}
stringBuilder.append("]");
return stringBuilder.toString();
}
} }

View file

@ -1,6 +1,7 @@
package com.pahimar.ee3.tileentity; package com.pahimar.ee3.tileentity;
import com.pahimar.ee3.reference.Names; import com.pahimar.ee3.reference.Names;
import com.pahimar.ee3.skill.PlayerKnowledge;
import com.pahimar.ee3.util.PlayerKnowledgeHelper; import com.pahimar.ee3.util.PlayerKnowledgeHelper;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@ -205,7 +206,9 @@ public class TileEntityResearchStation extends TileEntityEE implements IInventor
{ {
if (this.canLearnItemStack()) if (this.canLearnItemStack())
{ {
// TODO Add the input item to the books knowledge PlayerKnowledge playerKnowledge = PlayerKnowledge.readPlayerKnowledgeFromNBT(this.inventory[TOME_SLOT_INVENTORY_INDEX].getTagCompound());
playerKnowledge.learnItemStack(this.inventory[ITEM_SLOT_INVENTORY_INDEX]);
playerKnowledge.writeToNBT(this.inventory[TOME_SLOT_INVENTORY_INDEX].getTagCompound());
this.inventory[ITEM_SLOT_INVENTORY_INDEX].stackSize--; this.inventory[ITEM_SLOT_INVENTORY_INDEX].stackSize--;

View file

@ -12,6 +12,13 @@ import java.util.UUID;
public class ItemHelper public class ItemHelper
{ {
public static ItemStack cloneItemStack(ItemStack itemStack, int stackSize)
{
ItemStack clonedItemStack = itemStack.copy();
clonedItemStack.stackSize = stackSize;
return clonedItemStack;
}
public static Comparator<ItemStack> comparator = new Comparator<ItemStack>() public static Comparator<ItemStack> comparator = new Comparator<ItemStack>()
{ {
public int compare(ItemStack itemStack1, ItemStack itemStack2) public int compare(ItemStack itemStack1, ItemStack itemStack2)
@ -88,6 +95,36 @@ public class ItemHelper
return (comparator.compare(first, second) == 0); return (comparator.compare(first, second) == 0);
} }
public static boolean equalsIgnoreStackSize(ItemStack itemStack1, ItemStack itemStack2)
{
if (itemStack1 != null && itemStack2 != null)
{
// Sort on itemID
if (Item.getIdFromItem(itemStack1.getItem()) - Item.getIdFromItem(itemStack2.getItem()) == 0)
{
// Then sort on meta
if (itemStack1.getItemDamage() == itemStack2.getItemDamage())
{
// Then sort on NBT
if (itemStack1.hasTagCompound() && itemStack2.hasTagCompound())
{
// Then sort on stack size
if (itemStack1.getTagCompound().equals(itemStack2.getTagCompound()))
{
return true;
}
}
else
{
return true;
}
}
}
}
return false;
}
public static int compare(ItemStack itemStack1, ItemStack itemStack2) public static int compare(ItemStack itemStack1, ItemStack itemStack2)
{ {
return comparator.compare(itemStack1, itemStack2); return comparator.compare(itemStack1, itemStack2);

View file

@ -85,7 +85,7 @@ tile.ee3:aludel.name=Aludel Base
tile.ee3:calcinator.name=Calcinator tile.ee3:calcinator.name=Calcinator
tile.ee3:chalk.name=Chalk tile.ee3:chalk.name=Chalk
tile.ee3:glassBell.name=Glass Bell tile.ee3:glassBell.name=Glass Bell
tile.ee3:researchStation.name=Research Station [WIP] tile.ee3:researchStation.name=Research Station
tile.ee3:augmentationTable.name=Augmentation Table [WIP] tile.ee3:augmentationTable.name=Augmentation Table [WIP]
# GUIs # GUIs
@ -94,8 +94,9 @@ container.ee3:alchemicalChest=Alchemical Chest
container.ee3:aludel=Aludel container.ee3:aludel=Aludel
container.ee3:calcinator=Calcinator container.ee3:calcinator=Calcinator
container.ee3:glassBell=Glass Bell container.ee3:glassBell=Glass Bell
container.ee3:researchStation=Research Station [WIP] container.ee3:researchStation=Research Station
container.ee3:augmentationTable=Augmentation Table [WIP] container.ee3:augmentationTable=Augmentation Table [WIP]
container.ee3:alchemicalTome=Tome of Alchemical Knowledge [WIP]
# Tooltips # Tooltips
tooltip.ee3:upgradesPrefix=Upgrades (Alchemical) Chests tooltip.ee3:upgradesPrefix=Upgrades (Alchemical) Chests

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB