aboutsummaryrefslogtreecommitdiff
path: root/src/Java/miscutil
diff options
context:
space:
mode:
authorDraknyte1 <Draknyte1@hotmail.com>2016-08-29 18:33:37 +1000
committerDraknyte1 <Draknyte1@hotmail.com>2016-08-29 18:33:37 +1000
commitb0ae00d54790023197a7df31199cdbfd3e54ec10 (patch)
treee3e4bf0363c10c94dec3f5446f0ef4f5d8b9d9e2 /src/Java/miscutil
parent059d00c29b765fd6b5937e9686dda3cd03af08e4 (diff)
downloadGT5-Unofficial-b0ae00d54790023197a7df31199cdbfd3e54ec10.tar.gz
GT5-Unofficial-b0ae00d54790023197a7df31199cdbfd3e54ec10.tar.bz2
GT5-Unofficial-b0ae00d54790023197a7df31199cdbfd3e54ec10.zip
+ Added Custom Backpacks.
- Removed some old blocks which were statically generated. They still exist, now just are created using the dynamic block creation system.
Diffstat (limited to 'src/Java/miscutil')
-rw-r--r--src/Java/miscutil/core/block/ModBlocks.java9
-rw-r--r--src/Java/miscutil/core/container/Container_BackpackBase.java206
-rw-r--r--src/Java/miscutil/core/creative/AddToCreativeTab.java3
-rw-r--r--src/Java/miscutil/core/creative/tabs/MiscUtilCreativeTabBlock.java2
-rw-r--r--src/Java/miscutil/core/creative/tabs/MiscUtilCreativeTabOther.java2
-rw-r--r--src/Java/miscutil/core/gui/item/GuiBaseBackpack.java122
-rw-r--r--src/Java/miscutil/core/handler/COMPAT_HANDLER.java7
-rw-r--r--src/Java/miscutil/core/handler/GuiHandler.java28
-rw-r--r--src/Java/miscutil/core/inventories/BaseInventoryBackpack.java240
-rw-r--r--src/Java/miscutil/core/item/ModItems.java17
-rw-r--r--src/Java/miscutil/core/item/base/BaseItemBackpack.java85
-rw-r--r--src/Java/miscutil/core/slots/SlotItemBackpackInv.java28
12 files changed, 733 insertions, 16 deletions
diff --git a/src/Java/miscutil/core/block/ModBlocks.java b/src/Java/miscutil/core/block/ModBlocks.java
index ce4ad6c19e..cf36ecea0a 100644
--- a/src/Java/miscutil/core/block/ModBlocks.java
+++ b/src/Java/miscutil/core/block/ModBlocks.java
@@ -1,6 +1,5 @@
package miscutil.core.block;
-import miscutil.core.block.base.BasicBlock;
import miscutil.core.block.general.LightGlass;
import miscutil.core.block.general.fluids.FluidRegistryHandler;
import miscutil.core.lib.CORE;
@@ -14,8 +13,8 @@ import cpw.mods.fml.common.registry.GameRegistry;
public final class ModBlocks {
//Blocks
- public static Block blockBloodSteel;
- public static Block blockStaballoy;
+ //public static Block blockBloodSteel;
+ //public static Block blockStaballoy;
// WIP TODO public static Block blockToolBuilder;
public static Block blockGriefSaver;
public static Block blockCasingsMisc;
@@ -45,10 +44,10 @@ public final class ModBlocks {
Utils.LOG_INFO("Registering Blocks.");
//Blood Steel Block
- GameRegistry.registerBlock(blockBloodSteel = new BasicBlock("blockBloodSteel", Material.iron), "blockBloodSteel");
+ //GameRegistry.registerBlock(blockBloodSteel = new BasicBlock("blockBloodSteel", Material.iron), "blockBloodSteel");
//Staballoy Block
- GameRegistry.registerBlock(blockStaballoy = new BasicBlock("blockStaballoy", Material.iron), "blockStaballoy");
+ //GameRegistry.registerBlock(blockStaballoy = new BasicBlock("blockStaballoy", Material.iron), "blockStaballoy");
//GameRegistry.registerBlock(MatterFabricatorEffectBlock = new MatterFabricatorEffectBlock(), "blockMF_Effect");
diff --git a/src/Java/miscutil/core/container/Container_BackpackBase.java b/src/Java/miscutil/core/container/Container_BackpackBase.java
new file mode 100644
index 0000000000..7d997b92ed
--- /dev/null
+++ b/src/Java/miscutil/core/container/Container_BackpackBase.java
@@ -0,0 +1,206 @@
+package miscutil.core.container;
+
+import miscutil.core.inventories.BaseInventoryBackpack;
+import miscutil.core.slots.SlotItemBackpackInv;
+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;
+
+public class Container_BackpackBase extends Container
+{
+ /** The Item Inventory for this Container, only needed if you want to reference isUseableByPlayer */
+ public final BaseInventoryBackpack inventory;
+
+ /** Using these will make transferStackInSlot easier to understand and implement
+ * INV_START is the index of the first slot in the Player's Inventory, so our
+ * BaseInventoryBackpack's number of slots (e.g. 5 slots is array indices 0-4, so start at 5)
+ * Notice how we don't have to remember how many slots we made? We can just use
+ * BaseInventoryBackpack.INV_SIZE and if we ever change it, the Container updates automatically. */
+ private static final int INV_START = BaseInventoryBackpack.INV_SIZE, INV_END = INV_START+26,
+ HOTBAR_START = INV_END+1, HOTBAR_END = HOTBAR_START+8;
+
+ // If you're planning to add armor slots, put those first like this:
+ // ARMOR_START = BaseInventoryBackpack.INV_SIZE, ARMOR_END = ARMOR_START+3,
+ // INV_START = ARMOR_END+1, and then carry on like above.
+
+ public Container_BackpackBase(EntityPlayer par1Player, InventoryPlayer inventoryPlayer, BaseInventoryBackpack inventoryItem)
+ {
+ this.inventory = inventoryItem;
+
+ int i;
+
+ // ITEM INVENTORY - you'll need to adjust the slot locations to match your texture file
+ // I have them set vertically in columns of 4 to the right of the player model
+ for (i = 0; i < BaseInventoryBackpack.INV_SIZE; ++i)
+ {
+ // You can make a custom Slot if you need different behavior,
+ // such as only certain item types can be put into this slot
+ // We made a custom slot to prevent our inventory-storing item
+ // from being stored within itself, but if you want to allow that and
+ // you followed my advice at the end of the above step, then you
+ // could get away with using the vanilla Slot class
+ this.addSlotToContainer(new SlotItemBackpackInv(this.inventory, i, 80 + (18 * (int)(i/4)), 8 + (18*(i%4))));
+ }
+
+ // If you want, you can add ARMOR SLOTS here as well, but you need to
+ // make a public version of SlotArmor. I won't be doing that in this tutorial.
+ /*
+ for (i = 0; i < 4; ++i)
+ {
+ // These are the standard positions for survival inventory layout
+ this.addSlotToContainer(new SlotArmor(this.player, inventoryPlayer, inventoryPlayer.getSizeInventory() - 1 - i, 8, 8 + i * 18, i));
+ }
+ */
+
+ // PLAYER INVENTORY - uses default locations for standard inventory texture file
+ for (i = 0; i < 3; ++i)
+ {
+ for (int j = 0; j < 9; ++j)
+ {
+ this.addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
+ }
+ }
+
+ // PLAYER ACTION BAR - uses default locations for standard action bar texture file
+ for (i = 0; i < 9; ++i)
+ {
+ this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142));
+ }
+ }
+
+ @Override
+ public boolean canInteractWith(EntityPlayer entityplayer)
+ {
+ // be sure to return the inventory's isUseableByPlayer method
+ // if you defined special behavior there:
+ return inventory.isUseableByPlayer(entityplayer);
+ }
+
+ /**
+ * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
+ */
+ public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int index)
+ {
+ ItemStack itemstack = null;
+ Slot slot = (Slot) this.inventorySlots.get(index);
+
+ if (slot != null && slot.getHasStack())
+ {
+ ItemStack itemstack1 = slot.getStack();
+ itemstack = itemstack1.copy();
+
+ // If item is in our custom Inventory or armor slot
+ if (index < INV_START)
+ {
+ // try to place in player inventory / action bar
+ if (!this.mergeItemStack(itemstack1, INV_START, HOTBAR_END+1, true))
+ {
+ return null;
+ }
+
+ slot.onSlotChange(itemstack1, itemstack);
+ }
+ // Item is in inventory / hotbar, try to place in custom inventory or armor slots
+ else
+ {
+ /*
+ If your inventory only stores certain instances of Items,
+ you can implement shift-clicking to your inventory like this:
+
+ // Check that the item is the right type
+ if (itemstack1.getItem() instanceof ItemCustom)
+ {
+ // Try to merge into your custom inventory slots
+ // We use 'BaseInventoryBackpack.INV_SIZE' instead of INV_START just in case
+ // you also add armor or other custom slots
+ if (!this.mergeItemStack(itemstack1, 0, BaseInventoryBackpack.INV_SIZE, false))
+ {
+ return null;
+ }
+ }
+ // If you added armor slots, check them here as well:
+ // Item being shift-clicked is armor - try to put in armor slot
+ if (itemstack1.getItem() instanceof ItemArmor)
+ {
+ int type = ((ItemArmor) itemstack1.getItem()).armorType;
+ if (!this.mergeItemStack(itemstack1, ARMOR_START + type, ARMOR_START + type + 1, false))
+ {
+ return null;
+ }
+ }
+ Otherwise, you have basically 2 choices:
+ 1. shift-clicking between player inventory and custom inventory
+ 2. shift-clicking between action bar and inventory
+
+ Be sure to choose only ONE of the following implementations!!!
+ */
+ /**
+ * Implementation number 1: Shift-click into your custom inventory
+ */
+ if (index >= INV_START)
+ {
+ // place in custom inventory
+ if (!this.mergeItemStack(itemstack1, 0, INV_START, false))
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Implementation number 2: Shift-click items between action bar and inventory
+ */
+ // item is in player's inventory, but not in action bar
+ if (index >= INV_START && index < HOTBAR_START)
+ {
+ // place in action bar
+ if (!this.mergeItemStack(itemstack1, HOTBAR_START, HOTBAR_END+1, false))
+ {
+ return null;
+ }
+ }
+ // item in action bar - place in player inventory
+ else if (index >= HOTBAR_START && index < HOTBAR_END+1)
+ {
+ if (!this.mergeItemStack(itemstack1, INV_START, INV_END+1, false))
+ {
+ return null;
+ }
+ }
+ }
+
+ if (itemstack1.stackSize == 0)
+ {
+ slot.putStack((ItemStack) null);
+ }
+ else
+ {
+ slot.onSlotChanged();
+ }
+
+ if (itemstack1.stackSize == itemstack.stackSize)
+ {
+ return null;
+ }
+
+ slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
+ }
+
+ return itemstack;
+ }
+
+ /**
+ * You should override this method to prevent the player from moving the stack that
+ * opened the inventory, otherwise if the player moves it, the inventory will not
+ * be able to save properly
+ */
+ @Override
+ public ItemStack slotClick(int slot, int button, int flag, EntityPlayer player) {
+ // this will prevent the player from interacting with the item that opened the inventory:
+ if (slot >= 0 && getSlot(slot) != null && getSlot(slot).getStack() == player.getHeldItem()) {
+ return null;
+ }
+ return super.slotClick(slot, button, flag, player);
+ }
+}
diff --git a/src/Java/miscutil/core/creative/AddToCreativeTab.java b/src/Java/miscutil/core/creative/AddToCreativeTab.java
index f71de821dc..7655a639ad 100644
--- a/src/Java/miscutil/core/creative/AddToCreativeTab.java
+++ b/src/Java/miscutil/core/creative/AddToCreativeTab.java
@@ -3,6 +3,7 @@ package miscutil.core.creative;
import miscutil.core.creative.tabs.MiscUtilCreativeTabBlock;
import miscutil.core.creative.tabs.MiscUtilCreativeTabMachines;
import miscutil.core.creative.tabs.MiscUtilCreativeTabMisc;
+import miscutil.core.creative.tabs.MiscUtilCreativeTabOther;
import miscutil.core.creative.tabs.MiscUtilCreativeTabTools;
import miscutil.core.lib.CORE;
import net.minecraft.creativetab.CreativeTabs;
@@ -21,7 +22,7 @@ public class AddToCreativeTab {
tabMisc = new MiscUtilCreativeTabMisc("MiscUtilMiscTab");
tabTools = new MiscUtilCreativeTabTools("MiscUtilToolsTab");
tabMachines = new MiscUtilCreativeTabMachines("MiscUtilMachineTab");
- //tabOther = new MiscUtilCreativeTabOther("MiscUtilOtherTab");
+ tabOther = new MiscUtilCreativeTabOther("MiscUtilOtherTab");
if (CORE.DEBUG){
//tabCombat = new MiscUtilCreativeTabCombat("MiscUtilCombatTab");
diff --git a/src/Java/miscutil/core/creative/tabs/MiscUtilCreativeTabBlock.java b/src/Java/miscutil/core/creative/tabs/MiscUtilCreativeTabBlock.java
index 343eb2f341..21782a2ad5 100644
--- a/src/Java/miscutil/core/creative/tabs/MiscUtilCreativeTabBlock.java
+++ b/src/Java/miscutil/core/creative/tabs/MiscUtilCreativeTabBlock.java
@@ -12,7 +12,7 @@ public class MiscUtilCreativeTabBlock extends CreativeTabs {
@Override
public Item getTabIconItem() {
- return Item.getItemFromBlock(ModBlocks.blockStaballoy);
+ return Item.getItemFromBlock(ModBlocks.MatterFabricatorEffectBlock);
}
}
diff --git a/src/Java/miscutil/core/creative/tabs/MiscUtilCreativeTabOther.java b/src/Java/miscutil/core/creative/tabs/MiscUtilCreativeTabOther.java
index 02f1ecb15e..aeae534413 100644
--- a/src/Java/miscutil/core/creative/tabs/MiscUtilCreativeTabOther.java
+++ b/src/Java/miscutil/core/creative/tabs/MiscUtilCreativeTabOther.java
@@ -12,7 +12,7 @@ public class MiscUtilCreativeTabOther extends CreativeTabs {
@Override
public Item getTabIconItem() {
- return ModItems.itemHeliumBlob;
+ return ModItems.backpack_Green;
}
}
diff --git a/src/Java/miscutil/core/gui/item/GuiBaseBackpack.java b/src/Java/miscutil/core/gui/item/GuiBaseBackpack.java
new file mode 100644
index 0000000000..180f0c50eb
--- /dev/null
+++ b/src/Java/miscutil/core/gui/item/GuiBaseBackpack.java
@@ -0,0 +1,122 @@
+package miscutil.core.gui.item;
+
+import miscutil.core.container.Container_BackpackBase;
+import miscutil.core.inventories.BaseInventoryBackpack;
+import miscutil.core.lib.CORE;
+import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.client.gui.inventory.GuiContainer;
+import net.minecraft.client.renderer.OpenGlHelper;
+import net.minecraft.client.renderer.RenderHelper;
+import net.minecraft.client.renderer.entity.RenderManager;
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.util.ResourceLocation;
+
+import org.lwjgl.opengl.GL11;
+import org.lwjgl.opengl.GL12;
+
+import com.sun.org.apache.xml.internal.security.utils.I18n;
+
+public class GuiBaseBackpack extends GuiContainer
+{
+ /** x and y size of the inventory window in pixels. Defined as float, passed as int
+ * These are used for drawing the player model. */
+ private float xSize_lo;
+ private float ySize_lo;
+
+ /** The FontRenderer used by GuiScreen */
+ protected FontRenderer fontRenderer;
+
+ /** ResourceLocation takes 2 parameters: ModId, path to texture at the location:
+ * "src/minecraft/assets/modid/"
+ *
+ * I have provided a sample texture file that works with this tutorial. Download it
+ * from Forge_Tutorials/textures/gui/
+ */
+ private static final ResourceLocation iconLocation = new ResourceLocation(CORE.MODID, "textures/gui/itemBackpack.png");
+
+ /** The inventory to render on screen */
+ private final BaseInventoryBackpack inventory;
+
+ public GuiBaseBackpack(Container_BackpackBase containerItem)
+ {
+ super(containerItem);
+ this.inventory = containerItem.inventory;
+ }
+
+ /**
+ * Draws the screen and all the components in it.
+ */
+ @Override
+ public void drawScreen(int par1, int par2, float par3)
+ {
+ super.drawScreen(par1, par2, par3);
+ this.xSize_lo = (float)par1;
+ this.ySize_lo = (float)par2;
+ }
+
+ /**
+ * Draw the foreground layer for the GuiContainer (everything in front of the items)
+ */
+ @Override
+ protected void drawGuiContainerForegroundLayer(int par1, int par2)
+ {
+ String s = this.inventory.hasCustomInventoryName() ? this.inventory.getInventoryName() : I18n.translate(this.inventory.getInventoryName());
+ //this.fontRenderer.drawString(s, this.xSize / 2 - this.fontRenderer.getStringWidth(s) / 2, 0, 4210752);
+ //this.fontRenderer.drawString(I18n.translate("container.inventory"), 26, this.ySize - 96 + 4, 4210752);
+ }
+
+ /**
+ * Draw the background layer for the GuiContainer (everything behind the items)
+ */
+ @Override
+ protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
+ {
+ GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
+ this.mc.getTextureManager().bindTexture(iconLocation);
+ int k = (this.width - this.xSize) / 2;
+ int l = (this.height - this.ySize) / 2;
+ this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
+ int i1;
+ drawPlayerModel(k + 51, l + 75, 30, (float)(k + 51) - this.xSize_lo, (float)(l + 75 - 50) - this.ySize_lo, this.mc.thePlayer);
+ }
+
+ /**
+ * This renders the player model in standard inventory position (in later versions of Minecraft / Forge, you can
+ * simply call GuiInventory.drawEntityOnScreen directly instead of copying this code)
+ */
+ public static void drawPlayerModel(int x, int y, int scale, float yaw, float pitch, EntityLivingBase entity) {
+ GL11.glEnable(GL11.GL_COLOR_MATERIAL);
+ GL11.glPushMatrix();
+ GL11.glTranslatef(x, y, 50.0F);
+ GL11.glScalef(-scale, scale, scale);
+ GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
+ float f2 = entity.renderYawOffset;
+ float f3 = entity.rotationYaw;
+ float f4 = entity.rotationPitch;
+ float f5 = entity.prevRotationYawHead;
+ float f6 = entity.rotationYawHead;
+ GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F);
+ RenderHelper.enableStandardItemLighting();
+ GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F);
+ GL11.glRotatef(-((float) Math.atan(pitch / 40.0F)) * 20.0F, 1.0F, 0.0F, 0.0F);
+ entity.renderYawOffset = (float) Math.atan(yaw / 40.0F) * 20.0F;
+ entity.rotationYaw = (float) Math.atan(yaw / 40.0F) * 40.0F;
+ entity.rotationPitch = -((float) Math.atan(pitch / 40.0F)) * 20.0F;
+ entity.rotationYawHead = entity.rotationYaw;
+ entity.prevRotationYawHead = entity.rotationYaw;
+ GL11.glTranslatef(0.0F, entity.yOffset, 0.0F);
+ RenderManager.instance.playerViewY = 180.0F;
+ RenderManager.instance.renderEntityWithPosYaw(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);
+ entity.renderYawOffset = f2;
+ entity.rotationYaw = f3;
+ entity.rotationPitch = f4;
+ entity.prevRotationYawHead = f5;
+ entity.rotationYawHead = f6;
+ GL11.glPopMatrix();
+ RenderHelper.disableStandardItemLighting();
+ GL11.glDisable(GL12.GL_RESCALE_NORMAL);
+ OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
+ GL11.glDisable(GL11.GL_TEXTURE_2D);
+ OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
+ }
+}
diff --git a/src/Java/miscutil/core/handler/COMPAT_HANDLER.java b/src/Java/miscutil/core/handler/COMPAT_HANDLER.java
index 8c408bdd4f..4875ad5a08 100644
--- a/src/Java/miscutil/core/handler/COMPAT_HANDLER.java
+++ b/src/Java/miscutil/core/handler/COMPAT_HANDLER.java
@@ -6,7 +6,6 @@ import gregtech.api.util.GT_OreDictUnificator;
import java.util.LinkedList;
import java.util.Queue;
-import miscutil.core.block.ModBlocks;
import miscutil.core.common.compat.COMPAT_BigReactors;
import miscutil.core.common.compat.COMPAT_CompactWindmills;
import miscutil.core.common.compat.COMPAT_EnderIO;
@@ -43,9 +42,7 @@ import miscutil.core.recipe.ShapedRecipeObject;
import miscutil.core.util.Utils;
import miscutil.core.util.item.UtilsItems;
import miscutil.core.util.recipe.UtilsRecipe;
-import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
-import net.minecraftforge.oredict.OreDictionary;
public class COMPAT_HANDLER {
@@ -69,8 +66,8 @@ public class COMPAT_HANDLER {
GT_OreDictUnificator.registerOre("plateStaballoy", new ItemStack(ModItems.itemPlateStaballoy));
//Blocks
- GT_OreDictUnificator.registerOre("blockStaballoy", new ItemStack(Item.getItemFromBlock(ModBlocks.blockStaballoy)));
- OreDictionary.registerOre("blockBloodSteel", new ItemStack(ModBlocks.blockBloodSteel));
+ //GT_OreDictUnificator.registerOre("blockStaballoy", new ItemStack(Item.getItemFromBlock(ModBlocks.blockStaballoy)));
+ //OreDictionary.registerOre("blockBloodSteel", new ItemStack(ModBlocks.blockBloodSteel));
for(int i=1; i<=10; i++){
diff --git a/src/Java/miscutil/core/handler/GuiHandler.java b/src/Java/miscutil/core/handler/GuiHandler.java
index 340bd5f4a1..13693e2ffc 100644
--- a/src/Java/miscutil/core/handler/GuiHandler.java
+++ b/src/Java/miscutil/core/handler/GuiHandler.java
@@ -1,9 +1,12 @@
package miscutil.core.handler;
import miscutil.MiscUtils;
+import miscutil.core.container.Container_BackpackBase;
import miscutil.core.gui.beta.Gui_ID_Registry;
import miscutil.core.gui.beta.MU_GuiId;
+import miscutil.core.gui.item.GuiBaseBackpack;
import miscutil.core.interfaces.IGuiManager;
+import miscutil.core.inventories.BaseInventoryBackpack;
import miscutil.core.lib.CORE;
import miscutil.core.util.Utils;
import miscutil.xmod.forestry.bees.alveary.TileAlvearyFrameHousing;
@@ -18,8 +21,14 @@ import cpw.mods.fml.common.network.NetworkRegistry;
public class GuiHandler implements IGuiHandler {
- private static final int GUI1 = 0; //Frame Alveary
- private static final int GUI2 = 1; //RTG
+ public static final int GUI1 = 0; //Frame Alveary
+ public static final int GUI2 = 1; //RTG
+ public static final int GUI3 = 2; //BackpackHandler
+ public static final int GUI4 = 3; //
+ public static final int GUI5 = 4; //
+ public static final int GUI6 = 5; //
+ public static final int GUI7 = 6; //
+ public static final int GUI8 = 7; //
@@ -47,7 +56,12 @@ public class GuiHandler implements IGuiHandler {
}
-
+ }
+
+ if (ID == GUI3)
+ {
+ // Use the player's held item to create the inventory
+ return new Container_BackpackBase(player, player.inventory, new BaseInventoryBackpack(player.getHeldItem()));
}
return null;
}
@@ -68,6 +82,14 @@ public class GuiHandler implements IGuiHandler {
//return new GUI_RTG((TileEntityRTG) te.);
}
}
+
+ if (ID == GUI3)
+ {
+ // We have to cast the new container as our custom class
+ // and pass in currently held item for the inventory
+ return new GuiBaseBackpack((Container_BackpackBase) new Container_BackpackBase(player, player.inventory, new BaseInventoryBackpack(player.getHeldItem())));
+ }
+
return null;
}
diff --git a/src/Java/miscutil/core/inventories/BaseInventoryBackpack.java b/src/Java/miscutil/core/inventories/BaseInventoryBackpack.java
new file mode 100644
index 0000000000..ba3acbc79e
--- /dev/null
+++ b/src/Java/miscutil/core/inventories/BaseInventoryBackpack.java
@@ -0,0 +1,240 @@
+package miscutil.core.inventories;
+
+import java.util.UUID;
+
+import miscutil.core.item.base.BaseItemBackpack;
+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;
+import net.minecraftforge.common.util.Constants;
+
+public class BaseInventoryBackpack implements IInventory{
+
+ private String name = "Inventory Item";
+
+ /** Provides NBT Tag Compound to reference */
+ private final ItemStack invItem;
+
+ /** Defining your inventory size this way is handy */
+ public static final int INV_SIZE = 8;
+
+ /** Inventory's size must be same as number of slots you add to the Container class */
+ private ItemStack[] inventory = new ItemStack[INV_SIZE];
+
+ // declaration of variable:
+ protected String uniqueID;
+
+ /**
+ * @param itemstack - the ItemStack to which this inventory belongs
+ */
+ public BaseInventoryBackpack(ItemStack stack)
+ {
+ invItem = stack;
+
+ /** initialize variable within the constructor: */
+ uniqueID = "";
+
+ if (!stack.hasTagCompound())
+ {
+ stack.setTagCompound(new NBTTagCompound());
+ // no tag compound means the itemstack does not yet have a UUID, so assign one:
+ uniqueID = UUID.randomUUID().toString();
+ }
+
+ // Create a new NBT Tag Compound if one doesn't already exist, or you will crash
+ if (!stack.hasTagCompound()) {
+ stack.setTagCompound(new NBTTagCompound());
+ }
+ // note that it's okay to use stack instead of invItem right there
+ // both reference the same memory location, so whatever you change using
+ // either reference will change in the other
+
+ // Read the inventory contents from NBT
+ readFromNBT(stack.getTagCompound());
+ }
+ @Override
+ public int getSizeInventory()
+ {
+ return inventory.length;
+ }
+
+ @Override
+ public ItemStack getStackInSlot(int slot)
+ {
+ return inventory[slot];
+ }
+
+ @Override
+ public ItemStack decrStackSize(int slot, int amount)
+ {
+ ItemStack stack = getStackInSlot(slot);
+ if(stack != null)
+ {
+ if(stack.stackSize > amount)
+ {
+ stack = stack.splitStack(amount);
+ // Don't forget this line or your inventory will not be saved!
+ markDirty();
+ }
+ else
+ {
+ // this method also calls markDirty, so we don't need to call it again
+ setInventorySlotContents(slot, null);
+ }
+ }
+ return stack;
+ }
+
+ @Override
+ public ItemStack getStackInSlotOnClosing(int slot)
+ {
+ ItemStack stack = getStackInSlot(slot);
+ setInventorySlotContents(slot, null);
+ return stack;
+ }
+
+ @Override
+ public void setInventorySlotContents(int slot, ItemStack stack)
+ {
+ inventory[slot] = stack;
+
+ if (stack != null && stack.stackSize > getInventoryStackLimit())
+ {
+ stack.stackSize = getInventoryStackLimit();
+ }
+
+ // Don't forget this line or your inventory will not be saved!
+ markDirty();
+ }
+
+ // 1.7.2+ renamed to getInventoryName
+ @Override
+ public String getInventoryName()
+ {
+ return name;
+ }
+
+ // 1.7.2+ renamed to hasCustomInventoryName
+ @Override
+ public boolean hasCustomInventoryName()
+ {
+ return name.length() > 0;
+ }
+
+ @Override
+ public int getInventoryStackLimit()
+ {
+ return 64;
+ }
+
+ /**
+ * This is the method that will handle saving the inventory contents, as it is called (or should be called!)
+ * anytime the inventory changes. Perfect. Much better than using onUpdate in an Item, as this will also
+ * let you change things in your inventory without ever opening a Gui, if you want.
+ */
+ // 1.7.2+ renamed to markDirty
+ @Override
+ public void markDirty()
+ {
+ for (int i = 0; i < getSizeInventory(); ++i)
+ {
+ if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0) {
+ inventory[i] = null;
+ }
+ }
+
+ // This line here does the work:
+ writeToNBT(invItem.getTagCompound());
+ }
+
+ @Override
+ public boolean isUseableByPlayer(EntityPlayer entityplayer)
+ {
+ return true;
+ }
+
+ // 1.7.2+ renamed to openInventory(EntityPlayer player)
+ @Override
+ public void openInventory() {}
+
+ // 1.7.2+ renamed to closeInventory(EntityPlayer player)
+ @Override
+ public void closeInventory() {}
+
+ /**
+ * This method doesn't seem to do what it claims to do, as
+ * items can still be left-clicked and placed in the inventory
+ * even when this returns false
+ */
+ @Override
+ public boolean isItemValidForSlot(int slot, ItemStack itemstack)
+ {
+ // Don't want to be able to store the inventory item within itself
+ // Bad things will happen, like losing your inventory
+ // Actually, this needs a custom Slot to work
+ return !(itemstack.getItem() instanceof BaseItemBackpack);
+ }
+
+ /**
+ * A custom method to read our inventory from an ItemStack's NBT compound
+ */
+ public void readFromNBT(NBTTagCompound compound)
+ {
+ // Gets the custom taglist we wrote to this compound, if any
+ // 1.7.2+ change to compound.getTagList("ItemInventory", Constants.NBT.TAG_COMPOUND);
+ NBTTagList items = compound.getTagList("ItemInventory", Constants.NBT.TAG_COMPOUND);
+
+ if ("".equals(uniqueID))
+ {
+ // try to read unique ID from NBT
+ uniqueID = compound.getString("uniqueID");
+ // if it's still "", assign a new one:
+ if ("".equals(uniqueID))
+ {
+ uniqueID = UUID.randomUUID().toString();
+ }
+ }
+
+ for (int i = 0; i < items.tagCount(); ++i)
+ {
+ // 1.7.2+ change to items.getCompoundTagAt(i)
+ NBTTagCompound item = (NBTTagCompound) items.getCompoundTagAt(i);
+ int slot = item.getInteger("Slot");
+
+ // Just double-checking that the saved slot index is within our inventory array bounds
+ if (slot >= 0 && slot < getSizeInventory()) {
+ inventory[slot] = ItemStack.loadItemStackFromNBT(item);
+ }
+ }
+ }
+
+ /**
+ * A custom method to write our inventory to an ItemStack's NBT compound
+ */
+ public void writeToNBT(NBTTagCompound tagcompound)
+ {
+ // Create a new NBT Tag List to store itemstacks as NBT Tags
+ NBTTagList items = new NBTTagList();
+
+ for (int i = 0; i < getSizeInventory(); ++i)
+ {
+ // Only write stacks that contain items
+ if (getStackInSlot(i) != null)
+ {
+ // Make a new NBT Tag Compound to write the itemstack and slot index to
+ NBTTagCompound item = new NBTTagCompound();
+ item.setInteger("Slot", i);
+ // Writes the itemstack in slot(i) to the Tag Compound we just made
+ getStackInSlot(i).writeToNBT(item);
+
+ // add the tag compound to our tag list
+ items.appendTag(item);
+ }
+ }
+ tagcompound.setString("uniqueID", this.uniqueID);
+ // Add the TagList to the ItemStack's Tag Compound with the name "ItemInventory"
+ tagcompound.setTag("ItemInventory", items);
+ }
+} \ No newline at end of file
diff --git a/src/Java/miscutil/core/item/ModItems.java b/src/Java/miscutil/core/item/ModItems.java
index ef5dc581a7..f5ffc86e89 100644
--- a/src/Java/miscutil/core/item/ModItems.java
+++ b/src/Java/miscutil/core/item/ModItems.java
@@ -4,6 +4,7 @@ import static miscutil.core.creative.AddToCreativeTab.tabMisc;
import static miscutil.core.lib.CORE.LOAD_ALL_CONTENT;
import gregtech.api.util.GT_OreDictUnificator;
import miscutil.core.creative.AddToCreativeTab;
+import miscutil.core.item.base.BaseItemBackpack;
import miscutil.core.item.base.CoreItem;
import miscutil.core.item.base.bolts.BaseItemBolt;
import miscutil.core.item.base.foods.BaseItemFood;
@@ -168,6 +169,13 @@ public final class ModItems {
public static Item itemPersonalCloakingDevice;
public static Item itemPersonalCloakingDeviceCharged;
public static Item itemPersonalHealingDevice;
+
+ public static BaseItemBackpack backpack_Red;
+ public static BaseItemBackpack backpack_Green;
+ public static BaseItemBackpack backpack_Blue;
+ public static BaseItemBackpack backpack_Yellow;
+ public static BaseItemBackpack backpack_Purple;
+ public static BaseItemBackpack backpack_Cyan;
//@SuppressWarnings("unused")
@@ -179,6 +187,15 @@ public final class ModItems {
if (CORE.DEBUG){
DEBUG_INIT.registerItems();
}
+
+
+ //Make some backpacks
+ backpack_Red = new BaseItemBackpack("backpackRed", Utils.rgbtoHexValue(255, 0, 0));
+ backpack_Green = new BaseItemBackpack("backpackGreen", Utils.rgbtoHexValue(0, 255, 0));
+ backpack_Blue = new BaseItemBackpack("backpackBlue", Utils.rgbtoHexValue(0, 0, 255));
+ backpack_Yellow = new BaseItemBackpack("backpackYellow", Utils.rgbtoHexValue(255, 255, 0));
+ backpack_Purple = new BaseItemBackpack("backpackPurple", Utils.rgbtoHexValue(255, 0, 255));
+ backpack_Cyan = new BaseItemBackpack("backpackCyan", Utils.rgbtoHexValue(0, 255, 255));
/*ItemsIngots.load();
diff --git a/src/Java/miscutil/core/item/base/BaseItemBackpack.java b/src/Java/miscutil/core/item/base/BaseItemBackpack.java
new file mode 100644
index 0000000000..2b65c4ec03
--- /dev/null
+++ b/src/Java/miscutil/core/item/base/BaseItemBackpack.java
@@ -0,0 +1,85 @@
+package miscutil.core.item.base;
+
+import gregtech.api.util.GT_OreDictUnificator;
+import miscutil.MiscUtils;
+import miscutil.core.creative.AddToCreativeTab;
+import miscutil.core.handler.GuiHandler;
+import miscutil.core.lib.CORE;
+import miscutil.core.util.Utils;
+import miscutil.core.util.item.UtilsItems;
+import miscutil.core.util.math.MathUtils;
+import net.minecraft.client.renderer.texture.IIconRegister;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.world.World;
+import cpw.mods.fml.common.registry.GameRegistry;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+
+public class BaseItemBackpack extends Item{
+
+ protected final int colourValue;
+
+
+ public BaseItemBackpack(String unlocalizedName, int colour){
+
+ this.setUnlocalizedName(unlocalizedName);
+ this.setTextureName(CORE.MODID + ":" + "itemBackpack");
+ this.colourValue = colour;
+ GameRegistry.registerItem(this, unlocalizedName);
+ GT_OreDictUnificator.registerOre(unlocalizedName.replace("itemB", "b"), UtilsItems.getSimpleStack(this));
+ setMaxStackSize(1);
+ setCreativeTab(AddToCreativeTab.tabOther);
+ }
+
+ // Without this method, your inventory will NOT work!!!
+ @Override
+ public int getMaxItemUseDuration(ItemStack stack) {
+ return 1; // return any value greater than zero
+ }
+
+ @Override
+ public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player)
+ {
+ if (!world.isRemote)
+ {
+ Utils.LOG_INFO("Tried to use a Backpack.");
+ // If player not sneaking, open the inventory gui
+ if (!player.isSneaking()) {
+ Utils.LOG_INFO("Player is not sneaking.");
+ player.openGui(MiscUtils.instance, GuiHandler.GUI3, world, 0, 0, 0);
+ }
+
+ // Otherwise, stealthily place some diamonds in there for a nice surprise next time you open it up :)
+ else {
+ // Utils.LOG_INFO("Player is Sneaking, giving them sneaky diamonds.");
+ // new BaseInventoryBackpack(player.getHeldItem()).setInventorySlotContents(0, new ItemStack(Items.diamond,4));
+ }
+ }
+
+ return itemstack;
+ }
+
+ @Override
+ public int getColorFromItemStack(ItemStack stack, int HEX_OxFFFFFF) {
+ if (colourValue == 0){
+ return MathUtils.generateSingularRandomHexValue();
+ }
+ return colourValue;
+
+ }
+
+ @Override
+ public String getItemStackDisplayName(ItemStack p_77653_1_) {
+
+ return ("Backpack");
+ }
+
+ @Override
+ @SideOnly(Side.CLIENT)
+ public void registerIcons(IIconRegister iconRegister)
+ {
+ this.itemIcon = iconRegister.registerIcon(CORE.MODID + ":" + "itemBackpack");
+ }
+}
diff --git a/src/Java/miscutil/core/slots/SlotItemBackpackInv.java b/src/Java/miscutil/core/slots/SlotItemBackpackInv.java
new file mode 100644
index 0000000000..534230ba59
--- /dev/null
+++ b/src/Java/miscutil/core/slots/SlotItemBackpackInv.java
@@ -0,0 +1,28 @@
+package miscutil.core.slots;
+
+import miscutil.core.item.base.BaseItemBackpack;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.inventory.Slot;
+import net.minecraft.item.ItemStack;
+
+public class SlotItemBackpackInv extends Slot
+{
+ public SlotItemBackpackInv(IInventory inv, int index, int xPos, int yPos)
+ {
+ super(inv, index, xPos, yPos);
+ }
+
+ // This is the only method we need to override so that
+ // we can't place our inventory-storing Item within
+ // its own inventory (thus making it permanently inaccessible)
+ // as well as preventing abuse of storing backpacks within backpacks
+ /**
+ * Check if the stack is a valid item for this slot.
+ */
+ @Override
+ public boolean isItemValid(ItemStack itemstack)
+ {
+ // Everything returns true except an instance of our Item
+ return !(itemstack.getItem() instanceof BaseItemBackpack);
+ }
+} \ No newline at end of file