From e79eae78a7fed4df747d6202e501aa458ee4fc0f Mon Sep 17 00:00:00 2001 From: BallOfEnergy <66693744+ballofenergy1@users.noreply.github.com> Date: Thu, 27 Mar 2025 21:16:29 -0500 Subject: [PATCH 1/5] am I stupid? Fix a few issues related to naming. Fix toolboxes blocking all radiation. Add toolbox tooltip. Swap toolbox operations; clicking now swaps hotbars and shift-clicking opens the inventory for easier access (recommended by Mellow). --- .../HazardTransformerRadiationContainer.java | 40 ++++++++++++------- ...IItemInventory.java => ItemInventory.java} | 2 +- .../items/block/ItemBlockStorageCrate.java | 4 +- .../java/com/hbm/items/tool/ItemLeadBox.java | 4 +- .../java/com/hbm/items/tool/ItemToolBox.java | 12 ++++-- 5 files changed, 40 insertions(+), 22 deletions(-) rename src/main/java/com/hbm/items/{IItemInventory.java => ItemInventory.java} (98%) diff --git a/src/main/java/com/hbm/hazard/transformer/HazardTransformerRadiationContainer.java b/src/main/java/com/hbm/hazard/transformer/HazardTransformerRadiationContainer.java index 2f66ebcb1..7455e4382 100644 --- a/src/main/java/com/hbm/hazard/transformer/HazardTransformerRadiationContainer.java +++ b/src/main/java/com/hbm/hazard/transformer/HazardTransformerRadiationContainer.java @@ -20,55 +20,67 @@ public class HazardTransformerRadiationContainer extends HazardTransformerBase { @Override public void transformPost(ItemStack stack, List entries) { - + boolean isCrate = Block.getBlockFromItem(stack.getItem()) instanceof BlockStorageCrate; boolean isBox = stack.getItem() == ModItems.containment_box; boolean isBag = stack.getItem() == ModItems.plastic_bag; - - if(!isCrate && !isBox && !isBag) return; + + boolean isContainer = stack.getItem() == ModItems.toolbox; // For anything using the standard ItemInventory shit. + + if(!isCrate && !isBox && !isBag && !isContainer) return; if(!stack.hasTagCompound()) return; - + float radiation = 0; - + + if(isContainer) { + ItemStack[] items = ItemStackUtil.readStacksFromNBT(stack, 24); // Biggest container: toolbox; 24 slots. + + if(items != null) + for(ItemStack held : items) + if(held != null) + radiation += HazardSystem.getHazardLevelFromStack(held, HazardRegistry.RADIATION) * held.stackSize; + // this indentation is killing me man + } + if(isCrate) { - + for(int i = 0; i < 104; i++) { ItemStack held = ItemStack.loadItemStackFromNBT(stack.stackTagCompound.getCompoundTag("slot" + i)); - + if(held != null) { radiation += HazardSystem.getHazardLevelFromStack(held, HazardRegistry.RADIATION) * held.stackSize; } } } - + if(isBox) { ItemStack[] fromNBT = ItemStackUtil.readStacksFromNBT(stack, 20); if(fromNBT == null) return; - + for(ItemStack held : fromNBT) { if(held != null) { radiation += HazardSystem.getHazardLevelFromStack(held, HazardRegistry.RADIATION) * held.stackSize; } } - + radiation = (float) BobMathUtil.squirt(radiation); } - + if(isBag) { ItemStack[] fromNBT = ItemStackUtil.readStacksFromNBT(stack, 1); if(fromNBT == null) return; - + for(ItemStack held : fromNBT) { if(held != null) { radiation += HazardSystem.getHazardLevelFromStack(held, HazardRegistry.RADIATION) * held.stackSize; } } - + radiation *= 2F; } - + if(radiation > 0) { entries.add(new HazardEntry(HazardRegistry.RADIATION, radiation)); } diff --git a/src/main/java/com/hbm/items/IItemInventory.java b/src/main/java/com/hbm/items/ItemInventory.java similarity index 98% rename from src/main/java/com/hbm/items/IItemInventory.java rename to src/main/java/com/hbm/items/ItemInventory.java index 5efeef53d..e6d81ca8d 100644 --- a/src/main/java/com/hbm/items/IItemInventory.java +++ b/src/main/java/com/hbm/items/ItemInventory.java @@ -17,7 +17,7 @@ import java.util.Random; * Base class for items containing an inventory. This can be seen in crates, containment boxes, and the toolbox. * @author BallOfEnergy/Gammawave */ -public abstract class IItemInventory implements IInventory { +public abstract class ItemInventory implements IInventory { public EntityPlayer player; public ItemStack[] slots; diff --git a/src/main/java/com/hbm/items/block/ItemBlockStorageCrate.java b/src/main/java/com/hbm/items/block/ItemBlockStorageCrate.java index bad911b14..bcaa95e72 100644 --- a/src/main/java/com/hbm/items/block/ItemBlockStorageCrate.java +++ b/src/main/java/com/hbm/items/block/ItemBlockStorageCrate.java @@ -3,7 +3,7 @@ package com.hbm.items.block; import com.hbm.blocks.ModBlocks; import com.hbm.inventory.container.*; import com.hbm.inventory.gui.*; -import com.hbm.items.IItemInventory; +import com.hbm.items.ItemInventory; import com.hbm.items.tool.ItemKey; import com.hbm.main.MainRegistry; import com.hbm.tileentity.IGUIProvider; @@ -80,7 +80,7 @@ public class ItemBlockStorageCrate extends ItemBlockBase implements IGUIProvider throw new NullPointerException(); } - public static class InventoryCrate extends IItemInventory { + public static class InventoryCrate extends ItemInventory { public InventoryCrate(EntityPlayer player, ItemStack crate) { diff --git a/src/main/java/com/hbm/items/tool/ItemLeadBox.java b/src/main/java/com/hbm/items/tool/ItemLeadBox.java index 3959cb7e7..705768a26 100644 --- a/src/main/java/com/hbm/items/tool/ItemLeadBox.java +++ b/src/main/java/com/hbm/items/tool/ItemLeadBox.java @@ -2,7 +2,7 @@ package com.hbm.items.tool; import com.hbm.inventory.container.ContainerLeadBox; import com.hbm.inventory.gui.GUILeadBox; -import com.hbm.items.IItemInventory; +import com.hbm.items.ItemInventory; import com.hbm.main.MainRegistry; import com.hbm.tileentity.IGUIProvider; import com.hbm.util.ItemStackUtil; @@ -45,7 +45,7 @@ public class ItemLeadBox extends Item implements IGUIProvider { return new GUILeadBox(player.inventory, new InventoryLeadBox(player, player.getHeldItem())); } - public static class InventoryLeadBox extends IItemInventory { + public static class InventoryLeadBox extends ItemInventory { public InventoryLeadBox(EntityPlayer player, ItemStack box) { this.player = player; diff --git a/src/main/java/com/hbm/items/tool/ItemToolBox.java b/src/main/java/com/hbm/items/tool/ItemToolBox.java index e44cb5810..85387ae1f 100644 --- a/src/main/java/com/hbm/items/tool/ItemToolBox.java +++ b/src/main/java/com/hbm/items/tool/ItemToolBox.java @@ -2,7 +2,7 @@ package com.hbm.items.tool; import com.hbm.inventory.container.ContainerToolBox; import com.hbm.inventory.gui.GUIToolBox; -import com.hbm.items.IItemInventory; +import com.hbm.items.ItemInventory; import com.hbm.items.ModItems; import com.hbm.lib.RefStrings; import com.hbm.main.MainRegistry; @@ -53,6 +53,12 @@ public class ItemToolBox extends Item implements IGUIProvider { return renderPass == 1 ? this.iconClosed : getIconFromDamageForRenderPass(stack.getItemDamage(), renderPass); } + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool) { + list.add("Click with the toolbox to swap hotbars in/out of the toolbox."); + list.add("Shift-click with the toolbox to open the toolbox."); + } + // Finds active rows in the toolbox (rows with items inside them). public List getActiveRows(ItemStack box) { ItemStack[] stacks = ItemStackUtil.readStacksFromNBT(box, 24); @@ -166,7 +172,7 @@ public class ItemToolBox extends Item implements IGUIProvider { public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { if(!world.isRemote) { - if (player.isSneaking()) { + if (!player.isSneaking()) { moveRows(stack, player); player.inventoryContainer.detectAndSendChanges(); } else { @@ -190,7 +196,7 @@ public class ItemToolBox extends Item implements IGUIProvider { return new GUIToolBox(player.inventory, new InventoryToolBox(player, player.getHeldItem())); } - public static class InventoryToolBox extends IItemInventory { + public static class InventoryToolBox extends ItemInventory { public InventoryToolBox(EntityPlayer player, ItemStack box) { this.player = player; From e9376c788cbfd76d3756ea566f61c79c3009cc7c Mon Sep 17 00:00:00 2001 From: BallOfEnergy <66693744+ballofenergy1@users.noreply.github.com> Date: Thu, 27 Mar 2025 21:17:16 -0500 Subject: [PATCH 2/5] oh i kinda want this changed one less warning lmao --- src/main/java/com/hbm/items/tool/ItemLeadBox.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/hbm/items/tool/ItemLeadBox.java b/src/main/java/com/hbm/items/tool/ItemLeadBox.java index 705768a26..b57314db4 100644 --- a/src/main/java/com/hbm/items/tool/ItemLeadBox.java +++ b/src/main/java/com/hbm/items/tool/ItemLeadBox.java @@ -58,9 +58,7 @@ public class ItemLeadBox extends Item implements IGUIProvider { ItemStack[] fromNBT = ItemStackUtil.readStacksFromNBT(box, slots.length); if(fromNBT != null) { - for(int i = 0; i < slots.length; i++) { - slots[i] = fromNBT[i]; - } + System.arraycopy(fromNBT, 0, slots, 0, slots.length); } toMarkDirty = true; this.markDirty(); From fa6d2a4e568c7b3d5df0c4b72fe9e2ae6d9ed776 Mon Sep 17 00:00:00 2001 From: BallOfEnergy <66693744+ballofenergy1@users.noreply.github.com> Date: Fri, 28 Mar 2025 18:31:31 -0500 Subject: [PATCH 3/5] Fix rare crash related to toolboxing with a null NBT. Fix toolboxes not popping when swapping hotbars, even when >6KB limit. --- .../java/com/hbm/items/tool/ItemToolBox.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/main/java/com/hbm/items/tool/ItemToolBox.java b/src/main/java/com/hbm/items/tool/ItemToolBox.java index 85387ae1f..2d8b571c9 100644 --- a/src/main/java/com/hbm/items/tool/ItemToolBox.java +++ b/src/main/java/com/hbm/items/tool/ItemToolBox.java @@ -11,16 +11,20 @@ import com.hbm.util.ItemStackUtil; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.*; import net.minecraft.world.World; +import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Random; public class ItemToolBox extends Item implements IGUIProvider { @@ -157,6 +161,9 @@ public class ItemToolBox extends Item implements IGUIProvider { } } + if(stacks == null) + lowestInactiveIndex = 0; // Fix crash relating to a null NBT causing this value to be Integer.MAX_VALUE. + // Finally, move all temporary arrays into their respective locations. System.arraycopy(stacksToTransferToBox, 0, endingStacks, lowestInactiveIndex * 8, 8); @@ -166,6 +173,54 @@ public class ItemToolBox extends Item implements IGUIProvider { box.setTagCompound(new NBTTagCompound()); ItemStackUtil.addStacksToNBT(box, endingStacks); + + NBTTagCompound nbt = box.getTagCompound(); + + if(!nbt.hasNoTags()) { + Random random = new Random(); + + try { + byte[] abyte = CompressedStreamTools.compress(nbt); + + if (abyte.length > 6000) { + player.addChatComponentMessage(new ChatComponentText(EnumChatFormatting.RED + "Warning: Container NBT exceeds 6kB, contents will be ejected!")); + ItemStack[] stacks1 = ItemStackUtil.readStacksFromNBT(box, 24 /* Toolbox inv size. */); + if(stacks1 == null) + return; + for (ItemStack itemstack : stacks1) { + + if (itemstack != null) { + float f = random.nextFloat() * 0.8F + 0.1F; + float f1 = random.nextFloat() * 0.8F + 0.1F; + float f2 = random.nextFloat() * 0.8F + 0.1F; + + while (itemstack.stackSize > 0) { + int j1 = random.nextInt(21) + 10; + + if (j1 > itemstack.stackSize) { + j1 = itemstack.stackSize; + } + + itemstack.stackSize -= j1; + EntityItem entityitem = new EntityItem(player.worldObj, player.posX + f, player.posY + f1, player.posZ + f2, new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage())); + + if (itemstack.hasTagCompound()) { + entityitem.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy()); + } + + float f3 = 0.05F; + entityitem.motionX = (float) random.nextGaussian() * f3 + player.motionX; + entityitem.motionY = (float) random.nextGaussian() * f3 + 0.2F + player.motionY; + entityitem.motionZ = (float) random.nextGaussian() * f3 + player.motionZ; + player.worldObj.spawnEntityInWorld(entityitem); + } + } + } + + box.setTagCompound(new NBTTagCompound()); // Reset. + } + } catch (IOException ignored) {} + } } @Override From aaff6b9b704a2a9c3540e092631e9758252bc0a6 Mon Sep 17 00:00:00 2001 From: BallOfEnergy <66693744+ballofenergy1@users.noreply.github.com> Date: Fri, 28 Mar 2025 19:50:27 -0500 Subject: [PATCH 4/5] Dupe fix!!! --- .../com/hbm/inventory/SlotNonRetarded.java | 18 +++++++++++++++++- .../hbm/inventory/container/ContainerBase.java | 11 ++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/hbm/inventory/SlotNonRetarded.java b/src/main/java/com/hbm/inventory/SlotNonRetarded.java index 87c166277..61be0b9a1 100644 --- a/src/main/java/com/hbm/inventory/SlotNonRetarded.java +++ b/src/main/java/com/hbm/inventory/SlotNonRetarded.java @@ -2,6 +2,9 @@ package com.hbm.inventory; import com.hbm.interfaces.NotableComments; +import com.hbm.inventory.container.ContainerCrateBase; +import com.hbm.items.block.ItemBlockStorageCrate; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; @@ -24,7 +27,7 @@ public class SlotNonRetarded extends Slot { public boolean isItemValid(ItemStack stack) { return inventory.isItemValidForSlot(this.slotNumber, stack); } - + /** * Because if slots have higher stacksizes than the maximum allowed by the tile, the display just stops working. * Why was that necessary? Sure it's not intended but falsifying information isn't very cool. @@ -33,4 +36,17 @@ public class SlotNonRetarded extends Slot { public int getSlotStackLimit() { return Math.max(this.inventory.getInventoryStackLimit(), this.getHasStack() ? this.getStack().stackSize : 1); } + + /** + * This prevents the player from moving containers that are being held *at all*, fixing a decently big dupe. + * I hate that this has to be here but... It is what it is. + */ + @Override + public boolean canTakeStack(EntityPlayer player) { + if(player.inventory.currentItem == this.getSlotIndex() && // If this slot is the current held slot. + this.getStack() != null && this.getStack().getItem() instanceof ItemBlockStorageCrate && // If the slot contains a storage crate. + player.openContainer instanceof ContainerCrateBase) // If the player is currently inside a crate container. + return false; + return super.canTakeStack(player); + } } diff --git a/src/main/java/com/hbm/inventory/container/ContainerBase.java b/src/main/java/com/hbm/inventory/container/ContainerBase.java index 2dd45772b..bafd2442e 100644 --- a/src/main/java/com/hbm/inventory/container/ContainerBase.java +++ b/src/main/java/com/hbm/inventory/container/ContainerBase.java @@ -1,5 +1,6 @@ package com.hbm.inventory.container; +import com.hbm.inventory.SlotNonRetarded; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; @@ -12,7 +13,7 @@ import net.minecraft.item.ItemStack; * implementation, because I really needed to get the te from a container But * you should very much use this to kill the giant amount of boilerplate in * container classes - * + * * @author 70k **/ public class ContainerBase extends Container { @@ -61,12 +62,12 @@ public class ContainerBase extends Container { public void playerInv(InventoryPlayer invPlayer, int playerInvX, int playerInvY, int playerHotbarY) { for(int i = 0; i < 3; i++) { for(int j = 0; j < 9; j++) { - this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, playerInvX + j * 18, playerInvY + i * 18)); + this.addSlotToContainer(new SlotNonRetarded(invPlayer, j + i * 9 + 9, playerInvX + j * 18, playerInvY + i * 18)); } } for(int i = 0; i < 9; i++) { - this.addSlotToContainer(new Slot(invPlayer, i, playerInvX + i * 18, playerHotbarY)); + this.addSlotToContainer(new SlotNonRetarded(invPlayer, i, playerInvX + i * 18, playerHotbarY)); } } @@ -75,7 +76,7 @@ public class ContainerBase extends Container { // - Mellow, 1884 /** * Used to add several conventional inventory slots at a time - * + * * @param inv the inventory to add the slots to * @param from the slot index to start from */ @@ -83,7 +84,7 @@ public class ContainerBase extends Container { int slotSize = 18; for(int row = 0; row < rows; row++) { for(int col = 0; col < cols; col++) { - this.addSlotToContainer(new Slot(inv, col + row * cols + from, x + col * slotSize, y + row * slotSize)); + this.addSlotToContainer(new SlotNonRetarded(inv, col + row * cols + from, x + col * slotSize, y + row * slotSize)); } } } From 12af0abed94d016ce8a62ea0b0ba4f0c3099262e Mon Sep 17 00:00:00 2001 From: BallOfEnergy <66693744+ballofenergy1@users.noreply.github.com> Date: Sun, 30 Mar 2025 14:51:20 -0500 Subject: [PATCH 5/5] random fuckin fix apparently this fixes all those `ntm_null` component issues --- src/main/java/com/hbm/handler/CompatHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/hbm/handler/CompatHandler.java b/src/main/java/com/hbm/handler/CompatHandler.java index 2a59c92fe..62fc432c0 100644 --- a/src/main/java/com/hbm/handler/CompatHandler.java +++ b/src/main/java/com/hbm/handler/CompatHandler.java @@ -232,7 +232,7 @@ public class CompatHandler { @Override @Optional.Method(modid = "OpenComputers") default boolean canConnectNode(ForgeDirection side) { - return true; + return !this.getComponentName().equals(nullComponent); } /**