1
0
Fork 0

improve inventory code

This commit is contained in:
Sen 2025-09-07 11:51:01 +02:00
parent c374f35393
commit cfcb590574
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
25 changed files with 144 additions and 184 deletions

View file

@ -11,13 +11,9 @@ public class GuiChest extends GuiContainer {
public GuiChest(EntityNPC player, IInventory chest, Block block) {
super(new ContainerChest(player, chest));
this.block = block;
if(((ContainerChest)this.inventorySlots).getWidth() > 12)
this.xSize += (((ContainerChest)this.inventorySlots).getWidth() - 12) * 18;
this.ySize = 37 + 18 * ((player.getInventoryCapacity() + 11) / 12) + ((ContainerChest)this.inventorySlots).getHeight() * 18;
}
public void addElements() {
this.label(this.block.getDisplay(), 8, 16);
this.label("Inventar", 8, 37 - 8 + ((ContainerChest)this.inventorySlots).getHeight() * 18);
}
}

View file

@ -29,9 +29,9 @@ import client.window.Button;
import common.collect.Lists;
import common.enchantment.Enchantment;
import common.entity.npc.Attribute;
import common.entity.npc.EntityNPC;
import common.init.ItemRegistry;
import common.inventory.Container;
import common.inventory.ContainerChest;
import common.inventory.Slot;
import common.item.CheatTab;
import common.item.ItemStack;
@ -40,6 +40,7 @@ import common.packet.CPacketCheat;
import common.util.ExtMath;
import common.util.Util;
import common.util.Color;
import common.util.Equipment;
public abstract class GuiContainer extends Gui
{
@ -63,8 +64,8 @@ public abstract class GuiContainer extends Gui
private static CheatTab selectedTab = CheatTab.ALL;
protected RenderItem itemRender;
protected int xSize = 14 + 18 * 12;
protected int ySize = 166;
protected final int xSize;
protected final int ySize;
public Container inventorySlots;
private Slot theSlot;
protected final List<Overlay> drawnOverlays = Lists.<Overlay>newArrayList();
@ -259,12 +260,8 @@ public abstract class GuiContainer extends Gui
{
this.inventorySlots = container;
this.ignoreMouseUp = true;
}
public GuiContainer(Container container, EntityNPC player)
{
this(container);
this.ySize = 90 + 18 * ((player.getInventoryCapacity() + 11) / 12);
this.xSize = (container.getInventoryOffsetX() - 1) * 2 + 18 * 12;
this.ySize = container.getInventoryOffsetY() + 6 + 18 * ((Equipment.INVENTORY_SLOTS + 11) / 12);
}
public void init(int width, int height) {
@ -277,6 +274,7 @@ public abstract class GuiContainer extends Gui
this.initGui();
this.addButtons();
this.addElements();
this.label("Inventar", this.inventorySlots.getInventoryOffsetX(), this.inventorySlots.getInventoryOffsetY() - 2);
}
public void hover(String text, int x, int y) {

View file

@ -12,11 +12,9 @@ public class GuiCrafting extends GuiContainer {
public GuiCrafting(EntityNPC inv, World world, BlockWorkbench type) {
super(new ContainerWorkbench(inv, world, LocalPos.ORIGIN, type));
this.type = type;
this.ySize = 36 + 18 * ((inv.getInventoryCapacity() + 11) / 12) + 18 * 3;
}
public void addElements() {
this.label(this.type.getDisplay(), 8, 16);
this.label("Inventar", 8, 36 - 8 + 18 * 3);
}
}

View file

@ -24,7 +24,6 @@ public class GuiDevice extends GuiContainer {
super(new ContainerTile(player, tile, inv));
this.playerInv = player;
this.tileInv = tile;
this.ySize = 118 + 18 * ((player.getInventoryCapacity() + 11) / 12);
this.tile = tile;
}
@ -49,7 +48,6 @@ public class GuiDevice extends GuiContainer {
public void addElements() {
this.header = this.label("", 8, 16);
this.label("Inventar", 8, 118 - 8);
this.desc = this.display("", 8, 18, 160, 4);
this.progress = this.tile.hasProgress() ? this.bar(7, 70, 162, 9) : null;
this.temperature = this.tile.hasTemperature() ? this.bar(7, this.progress == null ? 70 : 60, 162, 9) : null;

View file

@ -26,7 +26,7 @@ public class GuiEnchant extends GuiContainer implements ButtonCallback {
private final Label[] mana = new Label[3];
public GuiEnchant(EntityNPC inv, World world) {
super(new ContainerEnchantment(inv, world), inv);
super(new ContainerEnchantment(inv, world));
this.enchantment = (ContainerEnchantment)this.inventorySlots;
}
@ -60,7 +60,6 @@ public class GuiEnchant extends GuiContainer implements ButtonCallback {
public void addElements() {
this.label(Blocks.enchanting_table.getDisplay(), 8, 16);
this.label("Inventar", 8, 90 - 8);
for(int l = 0; l < 3; ++l) {
int i1 = 60;
int j1 = i1 + 2;

View file

@ -9,12 +9,11 @@ public class GuiEntity extends GuiContainer {
private final String title;
public GuiEntity(EntityNPC player, IInventory entityInv, Entity entity) {
super(new ContainerEntityInventory(player, entityInv, entity), player);
super(new ContainerEntityInventory(player, entityInv, entity));
this.title = entity.getName();
}
public void addElements() {
this.label(this.title, 8, 16);
this.label("Inventar", 8, 90 - 8);
}
}

View file

@ -4,7 +4,7 @@ import common.entity.npc.EntityNPC;
public class GuiInventory extends GuiContainer {
public GuiInventory(EntityNPC player) {
super(player.inventoryContainer, player);
super(player.inventoryContainer);
}
public void addElements() {

View file

@ -24,7 +24,7 @@ public class GuiMerchant extends GuiContainer implements ButtonCallback {
private ActButton nextBtn;
public GuiMerchant(EntityNPC inv, Entity entity, World world) {
super(new ContainerMerchant(inv, null, world), inv);
super(new ContainerMerchant(inv, null, world));
this.title = entity.getName();
}
@ -41,7 +41,6 @@ public class GuiMerchant extends GuiContainer implements ButtonCallback {
public void addElements() {
this.label(this.title, 8, 16);
this.label("Inventar", 8, 90 - 8);
}
public void drawOverlays() {

View file

@ -12,7 +12,7 @@ public class GuiRepair extends GuiContainer {
private EntityNPC playerInv;
public GuiRepair(EntityNPC inv, World world) {
super(new ContainerRepair(inv, world), inv);
super(new ContainerRepair(inv, world));
this.playerInv = inv;
this.anvil = (ContainerRepair)this.inventorySlots;
}
@ -32,6 +32,5 @@ public class GuiRepair extends GuiContainer {
public void addElements() {
this.label("Amboss", 8, 16);
this.info = this.label("", 60, 77);
this.label("Inventar", 8, 90 - 8);
}
}

View file

@ -1132,7 +1132,7 @@ public class ClientPlayer implements IClientPlayer
// flag = true; // guicontainercreative.getSelectedTabIndex() != CheatTab.tabInventory.getIndex();
// }
if (packetIn.getWindowId() == 0 && packetIn.getSlot() >= Equipment.ARMOR_SLOTS && packetIn.getSlot() < Equipment.ARMOR_SLOTS + entityplayer.getInventoryCapacity())
if (packetIn.getWindowId() == 0 && packetIn.getSlot() >= Equipment.ARMOR_SLOTS && packetIn.getSlot() < Equipment.ARMOR_SLOTS + Equipment.INVENTORY_SLOTS)
{
ItemStack itemstack = entityplayer.inventoryContainer.getSlot(packetIn.getSlot()).getStack();