From fb7348128f2dfe553edef4d78338f7184f7b0498 Mon Sep 17 00:00:00 2001 From: HbmMods Date: Mon, 18 Mar 2019 20:02:50 +0100 Subject: [PATCH] new locksmith table textures, fruitless attempts to finish lead box --- .../blocks/machine_keyforge_bottom.png | Bin 0 -> 385 bytes .../textures/blocks/machine_keyforge_side.png | Bin 605 -> 568 bytes .../blocks/machine_keyforge_side_side.png | Bin 0 -> 605 bytes .../textures/blocks/machine_keyforge_top.png | Bin 552 -> 595 bytes .../blocks/machine_keyforge_top_alt.png | Bin 0 -> 552 bytes com/hbm/blocks/machine/MachineKeyForge.java | 9 +- com/hbm/handler/GUIHandler.java | 8 +- .../inventory/container/ContainerLeadBox.java | 205 +++++++++++++++--- com/hbm/inventory/gui/GUILeadBox.java | 11 +- com/hbm/inventory/inv/InventoryLeadBox.java | 204 +++++++++++++++++ com/hbm/items/tool/ItemLeadBox.java | 6 + com/hbm/items/weapon/GunZOMG.java | 16 +- com/hbm/main/CraftingManager.java | 2 +- 13 files changed, 414 insertions(+), 47 deletions(-) create mode 100644 assets/hbm/textures/blocks/machine_keyforge_bottom.png create mode 100644 assets/hbm/textures/blocks/machine_keyforge_side_side.png create mode 100644 assets/hbm/textures/blocks/machine_keyforge_top_alt.png create mode 100644 com/hbm/inventory/inv/InventoryLeadBox.java diff --git a/assets/hbm/textures/blocks/machine_keyforge_bottom.png b/assets/hbm/textures/blocks/machine_keyforge_bottom.png new file mode 100644 index 0000000000000000000000000000000000000000..28b0a53f1039ec1c281ac70a69b30b6405c7d62c GIT binary patch literal 385 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucL5ULAh?3y^w370~qEv>0#LT=By}Z;C1rt3( zJ<}BT2#__OJY5_^Ec|OH9n5kv6mb2lo)`PwaY5*=m)E$GboIO(HFj0lKiKs9Ux~lP zL$e5hzRzlttJ6Qt)0EHO{r&B;)UQAOM%L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a}fN5AtNw?GDq+CJQb=vJVcc;_onGgcwxWeURLUi?WZ>v%YDJ1~E z*E*40ko&XPUJz&C*j92u8cu7qTG8#aaBK@r(>OmrN7UeF$FVIO+e)_IhF7Z<04L=Nj&0p!Fq_TJgb+|Daep$Nk15;HG)7-@f$Q;N=T~AV9 diff --git a/assets/hbm/textures/blocks/machine_keyforge_top_alt.png b/assets/hbm/textures/blocks/machine_keyforge_top_alt.png new file mode 100644 index 0000000000000000000000000000000000000000..6f02e9b0839cd03db1a4d7dc27f037826b05b545 GIT binary patch literal 552 zcmV+@0@wYCP)v%YDJ1~E*E*40ko&XPUJz&C*j92u8cu7qTG8#aaBK@r(>OmrN7UeF$FVIO+e)_IhF7Z<04L=Nj&0p!Fq_TJgb+|DaW$V4 z{`!#wwqCDy;3$eXIxh3|+jowH+Rfm!X5!dZ0>@w)25@YPZl{%Gkm>b$n_Mo({l+8U zrg^a6zVzGRIt^U!sjTCMh9FQwdO qV45aUN`}KBK@d=_RuA%?=kXV?12Aev_F`cG0000= 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(player, 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/com/hbm/inventory/gui/GUILeadBox.java b/com/hbm/inventory/gui/GUILeadBox.java index 466e41a5c..c336bb9be 100644 --- a/com/hbm/inventory/gui/GUILeadBox.java +++ b/com/hbm/inventory/gui/GUILeadBox.java @@ -4,6 +4,7 @@ import org.lwjgl.opengl.GL11; import com.hbm.inventory.container.ContainerLeadBox; import com.hbm.inventory.container.ContainerWasteDrum; +import com.hbm.inventory.inv.InventoryLeadBox; import com.hbm.items.ModItems; import com.hbm.items.tool.ItemLeadBox; import com.hbm.lib.RefStrings; @@ -19,9 +20,11 @@ import net.minecraft.util.ResourceLocation; public class GUILeadBox extends GuiContainer { private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/gui_containment.png"); - - public GUILeadBox(InventoryPlayer invPlayer) { - super(new ContainerLeadBox(invPlayer)); + private final InventoryLeadBox inventory; + + public GUILeadBox(ContainerLeadBox container) { + super(container); + this.inventory = container.inventory; this.xSize = 176; this.ySize = 186; @@ -29,7 +32,7 @@ public class GUILeadBox extends GuiContainer { @Override protected void drawGuiContainerForegroundLayer(int i, int j) { - String name = "";//ItemLeadBox.getGuiName(); + String name = this.inventory.getInventoryName(); this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752); this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752); diff --git a/com/hbm/inventory/inv/InventoryLeadBox.java b/com/hbm/inventory/inv/InventoryLeadBox.java new file mode 100644 index 000000000..df265dcd0 --- /dev/null +++ b/com/hbm/inventory/inv/InventoryLeadBox.java @@ -0,0 +1,204 @@ +package com.hbm.inventory.inv; + +import com.hbm.items.special.ItemRadioactive; +import com.hbm.items.tool.ItemLeadBox; + +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 InventoryLeadBox 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 = 20; + + /** + * Inventory's size must be same as number of slots you add to the Container + * class + */ + private ItemStack[] inventory = new ItemStack[INV_SIZE]; + + /** + * @param itemstack - the ItemStack to which this inventory belongs + */ + public InventoryLeadBox(ItemStack stack) + { + invItem = stack; + + // 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 onInventoryChanged, 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 ItemRadioactive); + } + + /** + * 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); + + 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); + } + } + // Add the TagList to the ItemStack's Tag Compound with the name + // "ItemInventory" + tagcompound.setTag("ItemInventory", items); + } +} diff --git a/com/hbm/items/tool/ItemLeadBox.java b/com/hbm/items/tool/ItemLeadBox.java index 879f02cea..d8eeca383 100644 --- a/com/hbm/items/tool/ItemLeadBox.java +++ b/com/hbm/items/tool/ItemLeadBox.java @@ -12,6 +12,12 @@ import net.minecraft.world.World; public class ItemLeadBox extends Item { + // 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 stack, World world, EntityPlayer player) { diff --git a/com/hbm/items/weapon/GunZOMG.java b/com/hbm/items/weapon/GunZOMG.java index 2854a69fb..88f1fe660 100644 --- a/com/hbm/items/weapon/GunZOMG.java +++ b/com/hbm/items/weapon/GunZOMG.java @@ -61,44 +61,44 @@ public class GunZOMG extends Item { if (!player.inventory.hasItem(ModItems.nugget_euphemium) && !player.inventory.hasItem(ModItems.ingot_euphemium)) { stack.stackTagCompound.setBoolean("valid", false); - if (world.isRemote) { + if (!world.isRemote) { player.addChatMessage(new ChatComponentText("[ZOMG] Validation lost!")); player.addChatMessage(new ChatComponentText("[ZOMG] Request new validation!")); } } } } else { - if (world.isRemote) { + if (!world.isRemote) { player.addChatMessage(new ChatComponentText("[ZOMG] Gun not validated!")); player.addChatMessage(new ChatComponentText("[ZOMG] Validate your gun with shift right-click.")); } } } else { if (stack.stackTagCompound.getBoolean("valid")) { - if (world.isRemote) { + if (!world.isRemote) { player.addChatMessage(new ChatComponentText("[ZOMG] Gun has already been validated.")); } } else { if (player.inventory.hasItem(ModItems.nugget_euphemium) || player.inventory.hasItem(ModItems.ingot_euphemium)) { stack.stackTagCompound.setBoolean("valid", true); - if (world.isRemote) { + if (!world.isRemote) { player.addChatMessage(new ChatComponentText("[ZOMG] Gun has been validated!")); } //if(Library.superuser.contains(player.getUniqueID().toString())) { if(player.inventory.hasItem(ModItems.polaroid)) { - if (world.isRemote) { + if (!world.isRemote) { player.addChatMessage(new ChatComponentText("[ZOMG] Welcome, superuser!")); } stack.stackTagCompound.setBoolean("superuser", true); } else { - if (world.isRemote) { + if (!world.isRemote) { player.addChatMessage(new ChatComponentText("[ZOMG] Welcome, user!")); } stack.stackTagCompound.setBoolean("superuser", false); } } else { - if (world.isRemote) { + if (!world.isRemote) { player.addChatMessage(new ChatComponentText("[ZOMG] Validation failed!")); player.addChatMessage(new ChatComponentText("[ZOMG] No external negative gravity well found!")); } @@ -176,7 +176,7 @@ public class GunZOMG extends Item { if (!player.inventory.hasItem(ModItems.nugget_euphemium) && !player.inventory.hasItem(ModItems.ingot_euphemium)) { stack.stackTagCompound.setBoolean("valid", false); - if (world.isRemote) { + if (!world.isRemote) { player.addChatMessage(new ChatComponentText("[ZOMG] Validation lost!")); player.addChatMessage(new ChatComponentText("[ZOMG] Request new validation!")); } diff --git a/com/hbm/main/CraftingManager.java b/com/hbm/main/CraftingManager.java index 3738faa14..1a5bc48a0 100644 --- a/com/hbm/main/CraftingManager.java +++ b/com/hbm/main/CraftingManager.java @@ -1455,7 +1455,7 @@ public class CraftingManager { GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModItems.photo_panel), new Object[] { " G ", "IPI", " C ", 'G', "paneGlass", 'I', ModItems.plate_polymer, 'P', "dustNetherQuartz", 'C', ModItems.circuit_aluminium })); GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModBlocks.machine_satlinker), new Object[] { "PSP", "SCS", "PSP", 'P', "plateSteel", 'S', ModItems.ingot_starmetal, 'C', ModItems.sat_chip })); GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModBlocks.machine_telelinker), new Object[] { "PSP", "SCS", "PSP", 'P', "plateSteel", 'S', "ingotAdvanced", 'C', ModItems.turret_biometry })); - GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModBlocks.machine_keyforge), new Object[] { "PSP", "SCS", "PSP", 'P', "plateSteel", 'S', "ingotTungsten", 'C', ModItems.padlock })); + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModBlocks.machine_keyforge), new Object[] { "PCP", "WSW", "WSW", 'P', "plateSteel", 'S', "ingotTungsten", 'C', ModItems.padlock, 'W', "plankWood" })); GameRegistry.addRecipe(new ItemStack(ModItems.sat_chip), new Object[] { "WWW", "CIC", "WWW", 'W', ModItems.wire_red_copper, 'C', ModItems.circuit_red_copper, 'I', ModItems.ingot_polymer }); GameRegistry.addRecipe(new ItemStack(ModItems.sat_mapper), new Object[] { "H", "B", 'H', ModItems.sat_head_mapper, 'B', ModItems.sat_base }); GameRegistry.addRecipe(new ItemStack(ModItems.sat_scanner), new Object[] { "H", "B", 'H', ModItems.sat_head_scanner, 'B', ModItems.sat_base });