Skip to content

Commit

Permalink
Adding Key Ring item.
Browse files Browse the repository at this point in the history
  • Loading branch information
gottsch committed Mar 13, 2018
1 parent 1d360b6 commit 3deabda
Show file tree
Hide file tree
Showing 10 changed files with 616 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@
package com.someguyssoftware.treasure2.client.gui;

import com.someguyssoftware.treasure2.Treasure;
import com.someguyssoftware.treasure2.client.gui.inventory.KeyRingGui;
import com.someguyssoftware.treasure2.client.gui.inventory.StandardChestGui;
import com.someguyssoftware.treasure2.client.gui.inventory.StrongboxChestGui;
import com.someguyssoftware.treasure2.inventory.KeyRingInventory;
import com.someguyssoftware.treasure2.inventory.KeyRingContainer;
import com.someguyssoftware.treasure2.inventory.StandardChestContainer;
import com.someguyssoftware.treasure2.inventory.StrongboxChestContainer;
import com.someguyssoftware.treasure2.item.KeyRingItem;
import com.someguyssoftware.treasure2.tileentity.AbstractTreasureChestTileEntity;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;
Expand All @@ -29,6 +37,7 @@
public class GuiHandler implements IGuiHandler {
public static final int STANDARD_CHEST_GUIID = 1;
public static final int STRONGBOX_CHEST_GUIID = 2;
public static final int KEY_RING_GUIID = 3;


/* (non-Javadoc)
Expand All @@ -51,6 +60,19 @@ public Object getServerGuiElement(int ID, EntityPlayer player, World world, int
return new StrongboxChestContainer(player.inventory, ((AbstractTreasureChestTileEntity)tileEntity).getInventoryProxy());
}
break;
case KEY_RING_GUIID:
// get the held item
ItemStack keyRingItem = player.getHeldItemMainhand();
if (keyRingItem == null || !(keyRingItem.getItem() instanceof KeyRingItem)) {
keyRingItem = player.getHeldItemOffhand();
if (keyRingItem == null || !(keyRingItem.getItem() instanceof KeyRingItem)) return null;
}

// create inventory from item
IInventory inventory = new KeyRingInventory(keyRingItem);
// open the container
return new KeyRingContainer(player.inventory, inventory);

default: return null;
}
return null;
Expand All @@ -72,6 +94,7 @@ public Object getClientGuiElement(int ID, EntityPlayer player, World world, int
else {
Treasure.logger.warn("Umm, GUI handler error - wrong tile entity.");
}
break;
case STRONGBOX_CHEST_GUIID:
if (tileEntity instanceof AbstractTreasureChestTileEntity) {
return new StrongboxChestGui(player.inventory, (AbstractTreasureChestTileEntity) tileEntity);
Expand All @@ -80,6 +103,18 @@ public Object getClientGuiElement(int ID, EntityPlayer player, World world, int
Treasure.logger.warn("Umm, GUI handler error - wrong tile entity.");
}
break;
case KEY_RING_GUIID:
// get the held item
ItemStack keyRingItem = player.getHeldItemMainhand();
if (keyRingItem == null || !(keyRingItem.getItem() instanceof KeyRingItem)) {
keyRingItem = player.getHeldItemOffhand();
if (keyRingItem == null || !(keyRingItem.getItem() instanceof KeyRingItem)) return null;
}

// create inventory from item
IInventory inventory = new KeyRingInventory(keyRingItem);
// open the container
return new KeyRingGui(player.inventory, inventory);
default: return null;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.awt.Color;

import com.someguyssoftware.treasure2.Treasure;
import com.someguyssoftware.treasure2.inventory.KeyRingContainer;
import com.someguyssoftware.treasure2.inventory.StrongboxChestContainer;
import com.someguyssoftware.treasure2.tileentity.AbstractTreasureChestTileEntity;

Expand All @@ -23,22 +24,20 @@
public class KeyRingGui extends GuiContainer {

// This is the resource location for the background image for the GUI
private static final ResourceLocation texture = new ResourceLocation(Treasure.MODID, "textures/gui/container/king_ring.png");
private AbstractTreasureChestTileEntity tileEntity;
private static final ResourceLocation texture = new ResourceLocation(Treasure.MODID, "textures/gui/container/key_ring.png");
private static final String KEY_RING_LABEL = "Key Ring";

/**
* NOTE can pass anything into the ChestGui (GuiContainer) as long as the player's inventory and the container's inventory is present.
* NOTE both can be IInventory - doesn't have to be TileEntity
*
* @param invPlayer
* @param tileEntity
* @param inventory
*/
public KeyRingGui(InventoryPlayer invPlayer, AbstractTreasureChestTileEntity tileEntity) {
super(new StrongboxChestContainer(invPlayer, (IInventory) tileEntity.getInventoryProxy()));
this.tileEntity = tileEntity;
public KeyRingGui(InventoryPlayer invPlayer, IInventory inventory) {
super(new KeyRingContainer(invPlayer, inventory));

// Set the width and height of the gui. Should match the size of the texture!
xSize = 176;
ySize = 167;
ySize = 182;
}

/* (non-Javadoc)
Expand All @@ -59,6 +58,6 @@ protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, i
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
final int LABEL_XPOS = 5;
final int LABEL_YPOS = 5;
fontRenderer.drawString(tileEntity.getDisplayName().getUnformattedText(), LABEL_XPOS, LABEL_YPOS, Color.darkGray.getRGB());
fontRenderer.drawString(KEY_RING_LABEL, LABEL_XPOS, LABEL_YPOS, Color.darkGray.getRGB());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
package com.someguyssoftware.treasure2.inventory;

import com.someguyssoftware.treasure2.Treasure;
import com.someguyssoftware.treasure2.block.TreasureChestBlock;
import com.someguyssoftware.treasure2.tileentity.AbstractTreasureChestTileEntity;

Expand Down Expand Up @@ -177,6 +178,7 @@ public void closeInventory(EntityPlayer player) {
*/
@Override
public boolean isItemValidForSlot(int index, ItemStack stack) {
Treasure.logger.debug("Proxy.isItemValid() being called @ {} : {}", index, stack);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,83 @@
import net.minecraft.inventory.Slot;

/**
* This is the base/standard container for chests that is similar configuration to that of a vanilla container.
* This is a special container for the Key Ring
* @author Mark Gottschling on Mar 9, 2018
*
*/
public class KeyRingContainer extends AbstractChestContainer {
class Point {
public int x;
public int y;
public Point(int x, int y) { this.x = x; this.y = y;}
}

/**
*
* @param invPlayer
* @param inventory
*/
public KeyRingContainer(InventoryPlayer invPlayer, IInventory inventory) {
super(invPlayer, inventory);

// TODO column count and xpos doen't work for key ring where each slot is determined from a pre-made array
// set the dimensions
setContainerInventoryColumnCount(5);
//key ring only has 15 slots, arranged in a circle
setContainerInventoryXPos(8 + getSlotXSpacing() + getSlotXSpacing());
setContainerInventoryXPos(64);

// build the container
buildContainer(invPlayer, inventory);
}

/**
* TODO set this up from an array
*
*/
@Override
public void buildContainerInventory() {
/*
* Add the tile inventory container to the gui
*/
for (int y = 0; y < getContainerInventoryRowCount(); y++) {
for (int x = 0; x < getContainerInventoryColumnCount(); x++) {
int slotNumber = y * getContainerInventoryColumnCount() + x;
int xpos = getContainerInventoryXPos() + x * getSlotXSpacing();
int ypos = getContainerInventoryYPos() + y * getSlotYSpacing();
addSlotToContainer(new Slot(inventory, slotNumber, xpos, ypos));
public void buildContainerInventory() {
Point[][] points = {
{
new Point(28, 38),
new Point(28 + getSlotXSpacing(), 38),
new Point(118, 38),
new Point(118 + getSlotXSpacing(), 38)
},
{
new Point(28, 56),
new Point(28 + getSlotXSpacing(), 56),
new Point(118, 56),
new Point(118 + getSlotXSpacing(), 56)
}
};

// add top row
for (int x = 0; x < 3; x++) {
int slotNumber = x;
int xpos = getContainerInventoryXPos() + x * getSlotXSpacing();
int ypos = 18;
addSlotToContainer(new KeyRingSlot(inventory, slotNumber, xpos, ypos));
}

// middle rows
for (int y = 0; y < 2; y++) {
for (int x = 0; x < 4; x++) {
int slotNumber = (y * 4 + x) + 3;
addSlotToContainer(new KeyRingSlot(inventory, slotNumber, points[y][x].x, points[y][x].y));
}
}

// add bottom row
for (int x = 0; x < 3; x++) {
int slotNumber = x + 11;
int xpos = getContainerInventoryXPos() + x * getSlotXSpacing();
int ypos = 76;
addSlotToContainer(new KeyRingSlot(inventory, slotNumber, xpos, ypos));
}
}

@Override
public int getHotbarYPos() {
return 158;
}

@Override
public int getPlayerInventoryYPos() {
return 100;
}
}
Loading

0 comments on commit 3deabda

Please sign in to comment.