mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
New GUI, also some index fixes.
This commit is contained in:
parent
b139e084fb
commit
9839107c4e
@ -1,5 +1,6 @@
|
||||
package com.hbm.inventory.container;
|
||||
|
||||
import com.hbm.inventory.SlotNonRetarded;
|
||||
import com.hbm.util.InventoryUtil;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
@ -11,7 +12,7 @@ import static com.hbm.items.tool.ItemToolBox.*;
|
||||
|
||||
public class ContainerToolBox extends Container {
|
||||
|
||||
private InventoryToolBox box;
|
||||
private final InventoryToolBox box;
|
||||
|
||||
public ContainerToolBox(InventoryPlayer invPlayer, InventoryToolBox box) {
|
||||
this.box = box;
|
||||
@ -19,18 +20,18 @@ public class ContainerToolBox extends Container {
|
||||
|
||||
for(int i = 0; i < 3; i++) {
|
||||
for(int j = 0; j < 8; j++) {
|
||||
this.addSlotToContainer(new Slot(box, j + i * 8, 17 + j * 18, 18 + i * 18));
|
||||
this.addSlotToContainer(new SlotNonRetarded(box, j + i * 8, 17 + j * 18, 49 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < 3; i++) {
|
||||
for(int j = 0; j < 9; j++) {
|
||||
this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 98 + i * 18));
|
||||
this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 129 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < 9; i++) {
|
||||
this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 156));
|
||||
this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 187));
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,7 +53,7 @@ public class ContainerToolBox extends Container {
|
||||
}
|
||||
|
||||
if(var5.stackSize == 0) {
|
||||
var4.putStack((ItemStack) null);
|
||||
var4.putStack(null);
|
||||
} else {
|
||||
var4.onSlotChanged();
|
||||
}
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
package com.hbm.inventory.gui;
|
||||
|
||||
import com.hbm.inventory.container.ContainerLeadBox;
|
||||
import com.hbm.inventory.container.ContainerToolBox;
|
||||
import com.hbm.items.tool.ItemLeadBox.InventoryLeadBox;
|
||||
import com.hbm.lib.RefStrings;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
@ -16,7 +14,7 @@ import static com.hbm.items.tool.ItemToolBox.*;
|
||||
|
||||
public class GUIToolBox extends GuiContainer {
|
||||
|
||||
private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/gui_toolbox.png");
|
||||
private final static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/gui_toolbox.png");
|
||||
private final InventoryToolBox inventory;
|
||||
private ItemStack firstHeld;
|
||||
|
||||
@ -25,7 +23,7 @@ public class GUIToolBox extends GuiContainer {
|
||||
this.inventory = box;
|
||||
|
||||
this.xSize = 176;
|
||||
this.ySize = 186;
|
||||
this.ySize = 211;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,8 +50,8 @@ public class GUIToolBox extends GuiContainer {
|
||||
name = inventory.target.getDisplayName();
|
||||
}
|
||||
|
||||
this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752);
|
||||
this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 102 + 2, 4210752);
|
||||
this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 37, 4210752);
|
||||
this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -7,12 +7,10 @@ import com.hbm.items.ModItems;
|
||||
import com.hbm.lib.RefStrings;
|
||||
import com.hbm.main.MainRegistry;
|
||||
import com.hbm.tileentity.IGUIProvider;
|
||||
import com.hbm.util.ChatBuilder;
|
||||
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;
|
||||
@ -23,7 +21,6 @@ import net.minecraft.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class ItemToolBox extends Item implements IGUIProvider {
|
||||
|
||||
@ -56,6 +53,7 @@ public class ItemToolBox extends Item implements IGUIProvider {
|
||||
return renderPass == 1 ? this.iconClosed : getIconFromDamageForRenderPass(stack.getItemDamage(), renderPass);
|
||||
}
|
||||
|
||||
// Finds active rows in the toolbox (rows with items inside them).
|
||||
public List<Integer> getActiveRows(ItemStack box) {
|
||||
ItemStack[] stacks = ItemStackUtil.readStacksFromNBT(box, 24);
|
||||
if(stacks == null)
|
||||
@ -110,14 +108,24 @@ public class ItemToolBox extends Item implements IGUIProvider {
|
||||
ItemStack[] stacks = ItemStackUtil.readStacksFromNBT(box, 24);
|
||||
ItemStack[] endingStacks = new ItemStack[24];
|
||||
|
||||
int lowestActiveIndex = Integer.MAX_VALUE; // Lowest active index to find which row to move *to* the hotbar.
|
||||
int lowestInactiveIndex = Integer.MAX_VALUE; // Lowest *inactive* index to find which row to move the hotbar to.
|
||||
|
||||
if(stacks != null) {
|
||||
List<Integer> activeRows = getActiveRows(box);
|
||||
|
||||
int lowestIndex = Integer.MAX_VALUE;
|
||||
{ // Finding the lowest active row to decide what row to move to the hotbar.
|
||||
for (Integer activeRowIndex : activeRows) {
|
||||
lowestIndex = Math.min(activeRowIndex, lowestIndex);
|
||||
{ // despair
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if(activeRows.contains(i))
|
||||
lowestActiveIndex = Math.min(i, lowestActiveIndex);
|
||||
else
|
||||
lowestInactiveIndex = Math.min(i, lowestInactiveIndex);
|
||||
}
|
||||
|
||||
if(lowestInactiveIndex > 2) // No inactive rows...
|
||||
lowestInactiveIndex = 2; // Set to the last possible row; the items will be moved out of the way in time.
|
||||
else
|
||||
lowestInactiveIndex = Math.max(0, lowestInactiveIndex - 1); // A little shittery to make items pop into the row that's *going* to be empty.
|
||||
}
|
||||
|
||||
// This entire section sucks, but honestly it's not actually that bad; it works so....
|
||||
@ -125,7 +133,7 @@ public class ItemToolBox extends Item implements IGUIProvider {
|
||||
|
||||
int activeIndex = 8 * activeRowIndex;
|
||||
|
||||
if (activeRowIndex == lowestIndex) { // Items to "flow" to the hotbar.
|
||||
if (activeRowIndex == lowestActiveIndex) { // Items to "flow" to the hotbar.
|
||||
hasToolbox = false;
|
||||
for (int i = 0; i < 9; i++) {
|
||||
if(i == player.inventory.currentItem) {
|
||||
@ -144,7 +152,7 @@ public class ItemToolBox extends Item implements IGUIProvider {
|
||||
}
|
||||
|
||||
// Finally, move all temporary arrays into their respective locations.
|
||||
System.arraycopy(stacksToTransferToBox, 0, endingStacks, 16, 8);
|
||||
System.arraycopy(stacksToTransferToBox, 0, endingStacks, lowestInactiveIndex * 8, 8);
|
||||
|
||||
for (int i = 0; i < endingHotBar.length; i++) {
|
||||
player.inventory.setInventorySlotContents(i, endingHotBar[i]);
|
||||
@ -223,5 +231,10 @@ public class ItemToolBox extends Item implements IGUIProvider {
|
||||
this.player.inventory.setInventorySlotContents(this.player.inventory.currentItem, this.target);
|
||||
super.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
return stack.getItem() != ModItems.toolbox;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 2.0 KiB |
Loading…
x
Reference in New Issue
Block a user