From 00ac4146bca6c7d0380cecc48f354343bc860ddf Mon Sep 17 00:00:00 2001 From: Sen Date: Sun, 7 Sep 2025 12:47:07 +0200 Subject: [PATCH] misc fixes --- client/src/main/java/client/Client.java | 9 +- .../client/gui/container/GuiContainer.java | 18 +- .../java/client/gui/options/GuiStyle.java | 1 + .../java/common/entity/npc/EntityNPC.java | 12 +- .../main/java/common/inventory/Container.java | 29 +++- .../java/common/inventory/ContainerChest.java | 2 +- .../common/inventory/ContainerPlayer.java | 162 +++++++----------- .../src/main/java/common/util/Equipment.java | 2 +- 8 files changed, 119 insertions(+), 116 deletions(-) diff --git a/client/src/main/java/client/Client.java b/client/src/main/java/client/Client.java index c7b1aee0..af4715fd 100755 --- a/client/src/main/java/client/Client.java +++ b/client/src/main/java/client/Client.java @@ -581,7 +581,7 @@ public class Client implements IThreadListener { @Variable(name = "chunk_build_time", category = CVarCategory.RENDER, min = 1, max = 100, display = "Zeit für Chunk-Bau", unit = "ms") public int maxBuildTime = 8; @Variable(name = "chunk_light_updates", category = CVarCategory.RENDER, min = 0, max = 10000, display = "Licht-Updates / Frame") - private int lightUpdates = 150; + private int lightUpdates = 300; @Variable(name = "chunk_light_range", category = CVarCategory.RENDER, min = 5, max = 512, display = "Radius Licht-Updates") private int lightRange = 32; @Variable(name = "draw_fov", category = CVarCategory.RENDER, min = 20.0f, max = 160.0f, display = "Sichtfeld (FOV)", unit = "°", precision = 1) @@ -610,6 +610,8 @@ public class Client implements IThreadListener { private int scaleVar = 1; @Variable(name = "gui_scale_items", category = CVarCategory.GUI, display = "Gegenstände vergrößern", callback = ItemRedrawFunction.class) public boolean scaleItems = true; + @Variable(name = "gui_scale_items_always", category = CVarCategory.GUI, display = "Immer vergrößern", callback = ItemRedrawFunction.class) + public boolean scaleItemsAlways = false; @Variable(name = "gui_scale_hotbar", category = CVarCategory.GUI, display = "Leiste vergrößern") public boolean scaleHotbar = true; @Variable(name = "hud_margin", category = CVarCategory.GUI, min = 0, max = 120, unit = "px", display = "Seitenabstand der HUD") @@ -2512,6 +2514,7 @@ public class Client implements IThreadListener { PerfSection.TICK.enter(); this.doTicks(); PerfSection.UPDATE.enter(); + this.update(); PerfSection.RENDER.enter(); this.render(); PerfSection.GUI.enter(); @@ -2700,7 +2703,9 @@ public class Client implements IThreadListener { this.tickFraction = ((double)this.tick_torun) / 1000000.0; this.tick_ttime += this.tick_ftime; this.tick_time = this.tickFrame != 0 ? (this.tick_ftime / (long)this.tickFrame) : 0L; - + } + + private void update() { if(this.player != null) { int radius = Math.min(this.renderDistance * 16, this.lightRange); for(int n = 0; n < this.lightUpdates; n++) { diff --git a/client/src/main/java/client/gui/container/GuiContainer.java b/client/src/main/java/client/gui/container/GuiContainer.java index a3811230..c21efce2 100755 --- a/client/src/main/java/client/gui/container/GuiContainer.java +++ b/client/src/main/java/client/gui/container/GuiContainer.java @@ -97,6 +97,7 @@ public abstract class GuiContainer extends Gui private Label cheatLabel; private Field cheatSearch; private String cheatLast; + private Label inventoryLabel; public static String formatAmount(int amount) { if(amount < 0) @@ -260,21 +261,22 @@ public abstract class GuiContainer extends Gui { this.inventorySlots = container; this.ignoreMouseUp = true; - this.xSize = (container.getInventoryOffsetX() - 1) * 2 + 18 * 12; - this.ySize = container.getInventoryOffsetY() + 6 + 18 * ((Equipment.INVENTORY_SLOTS + 11) / 12); + this.xSize = (container.getInventoryOffsetX() - 1) * 2 + 18 * Container.INVENTORY_WIDTH; + this.ySize = container.getInventoryOffsetY() + 26 + 18 * ((Equipment.INVENTORY_SLOTS + Container.INVENTORY_WIDTH - 1) / Container.INVENTORY_WIDTH); } public void init(int width, int height) { this.itemRender = this.gm.getRenderItem(); this.tooltip = null; this.cheatStack = null; - this.container_scale = this.gm.scaleItems && this.xSize * 2 <= Client.MIN_WIDTH && this.ySize * 2 <= Client.MIN_HEIGHT ? 2 : 1; + this.container_scale = this.gm.scaleItems && (this.gm.scaleItemsAlways || (this.xSize * 2 <= Client.MIN_WIDTH && this.ySize * 2 <= Client.MIN_HEIGHT)) ? 2 : 1; this.container_x = (width - (this.container_w = (this.xSize * this.container_scale))) / 2; this.container_y = (height - (this.container_h = (this.ySize * this.container_scale))) / 2; this.initGui(); this.addButtons(); this.addElements(); this.label("Inventar", this.inventorySlots.getInventoryOffsetX(), this.inventorySlots.getInventoryOffsetY() - 2); + this.inventoryLabel = this.label("", this.inventorySlots.getInventoryOffsetX() + 18 * Container.INVENTORY_WIDTH - 90, this.inventorySlots.getInventoryOffsetY() - 2); } public void hover(String text, int x, int y) { @@ -767,14 +769,18 @@ public abstract class GuiContainer extends Gui public void updateScreen() { - if (this.gm != null && this.gm.player != null && (!this.gm.player.isEntityAlive() || this.gm.player.dead)) - { + if(this.gm != null && this.gm.player != null && (!this.gm.player.isEntityAlive() || this.gm.player.dead)) { this.gm.show(null); + return; } - else if(this.gm.itemCheat && !this.cheatSearch.getText().equals(this.cheatLast)) { + + if(this.gm.itemCheat && !this.cheatSearch.getText().equals(this.cheatLast)) { this.cheatLast = this.cheatSearch.getText(); this.setCurrentTab(selectedTab); } + + if(this.gm != null && this.gm.player != null) + this.inventoryLabel.setText((this.gm.player.getInventoryWeight() > this.gm.player.getInventoryCapacity() ? Color.RED : Color.NEON) + String.format("% 5d / % 5d", this.gm.player.getInventoryWeight(), this.gm.player.getInventoryCapacity())); } public void renderItemOverlayIntoGUI(ItemStack stack, int xPosition, int yPosition, String text) diff --git a/client/src/main/java/client/gui/options/GuiStyle.java b/client/src/main/java/client/gui/options/GuiStyle.java index ce3bec46..069b5c82 100644 --- a/client/src/main/java/client/gui/options/GuiStyle.java +++ b/client/src/main/java/client/gui/options/GuiStyle.java @@ -77,6 +77,7 @@ public class GuiStyle extends GuiOptions { this.addSelector("gui_font", H_SHIFT, y, 0, 0); this.addSelector("gui_scale_items", 0, y += BASE_SHIFT, 0, 0); + this.addSelector("gui_scale_items_always", H_SHIFT, y, 0, 0); super.init(width, height); } diff --git a/common/src/main/java/common/entity/npc/EntityNPC.java b/common/src/main/java/common/entity/npc/EntityNPC.java index e56f3f90..2c6f649e 100755 --- a/common/src/main/java/common/entity/npc/EntityNPC.java +++ b/common/src/main/java/common/entity/npc/EntityNPC.java @@ -2484,7 +2484,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory } } - public int getHotbarSize() { + public final int getHotbarSize() { return Equipment.INVENTORY_SLOTS; } @@ -2760,6 +2760,16 @@ public abstract class EntityNPC extends EntityLiving implements IInventory public int getInventoryCapacity() { return 36; } + + public int getInventoryWeight() { + int total = 0; + for(int z = 0; z < Equipment.INVENTORY_SLOTS; z++) { + ItemStack stack = this.getInventory()[z]; + if(stack != null) + total += stack.getSize() * stack.getItem().getWeight(); + } + return total; + } public boolean hasArmorSlot(Equipment slot) { return true; diff --git a/common/src/main/java/common/inventory/Container.java b/common/src/main/java/common/inventory/Container.java index d30d8de7..0301f255 100755 --- a/common/src/main/java/common/inventory/Container.java +++ b/common/src/main/java/common/inventory/Container.java @@ -8,11 +8,14 @@ import common.collect.Sets; import common.entity.npc.EntityNPC; import common.item.Item; import common.item.ItemStack; +import common.item.material.ItemArmor; import common.network.IPlayer; import common.util.Equipment; public abstract class Container { + public static final int INVENTORY_WIDTH = 16; + public List inventoryItemStacks = Lists.newArrayList(); public List inventorySlots = Lists.newArrayList(); public int windowId; @@ -33,13 +36,33 @@ public abstract class Container return this.offset; } - protected void addPlayerSlots(EntityNPC player) { - this.offset = this.inventorySlots.size(); + protected void addPlayerSlots(final EntityNPC player) { int x = this.getInventoryOffsetX(); int y = this.getInventoryOffsetY(); + for(Equipment slot : Equipment.ARMOR) { + final Equipment type = slot; + this.addSlotToContainer(new Slot(player, Equipment.INVENTORY_SLOTS + slot.getIndex(), x + slot.getIndex() * 18, y) { + public boolean canStackItems() { + return false; + } + + public boolean isItemValid(ItemStack stack) { + return stack != null && stack.getItem() instanceof ItemArmor armor && armor.getArmorType().canUseInSlot(player, type); + } + + public String getTexture() { + return type.isRing() ? "ring" : type.getName(); + } + + public boolean canDraw() { + return player.hasArmorSlot(type); + } + }); + } + this.offset = this.inventorySlots.size(); List list = Lists.newArrayList(); for(int z = 0; z < Equipment.INVENTORY_SLOTS; ++z) { - this.addSlotToContainer(new SlotCommon(list, player, z, x + (z % 12) * 18, y + (z / 12) * 18)); + this.addSlotToContainer(new SlotCommon(list, player, z, x + (z % INVENTORY_WIDTH) * 18, y + 20 + (z / INVENTORY_WIDTH) * 18)); } } diff --git a/common/src/main/java/common/inventory/ContainerChest.java b/common/src/main/java/common/inventory/ContainerChest.java index de857329..f5d95f0c 100755 --- a/common/src/main/java/common/inventory/ContainerChest.java +++ b/common/src/main/java/common/inventory/ContainerChest.java @@ -36,7 +36,7 @@ public class ContainerChest extends Container } public int getInventoryOffsetX() { - return 8 + (this.width < 12 ? 0 : (this.width - 12) * 18 / 2); + return 8 + (this.width < INVENTORY_WIDTH ? 0 : (this.width - INVENTORY_WIDTH) * 18 / 2); } public int getInventoryOffsetY() { diff --git a/common/src/main/java/common/inventory/ContainerPlayer.java b/common/src/main/java/common/inventory/ContainerPlayer.java index f51b48bd..4df8e500 100755 --- a/common/src/main/java/common/inventory/ContainerPlayer.java +++ b/common/src/main/java/common/inventory/ContainerPlayer.java @@ -1,129 +1,87 @@ package common.inventory; -import java.util.List; - -import common.collect.Lists; import common.entity.npc.EntityNPC; import common.item.ItemStack; import common.item.material.ItemArmor; import common.util.Equipment; public class ContainerPlayer extends Container { - private final EntityNPC thePlayer; - - public ContainerPlayer(EntityNPC player) - { - this.thePlayer = player; - - for (Equipment slot : Equipment.ARMOR) - { - final Equipment type = slot; - this.addSlotToContainer(new Slot(player, Equipment.INVENTORY_SLOTS + slot.getIndex(), 8 + (slot.getIndex() / 4) * 18, 8 + (slot.getIndex() % 4) * 18) - { - public boolean canStackItems() - { - return false; - } - public boolean isItemValid(ItemStack stack) - { - return stack != null && stack.getItem() instanceof ItemArmor armor && armor.getArmorType().canUseInSlot(ContainerPlayer.this.thePlayer, type); - } - public String getTexture() { - return type.isRing() ? "ring" : type.getName(); - } - public boolean canDraw() { - return ContainerPlayer.this.thePlayer.hasArmorSlot(type); - } - }); - } - - this.addPlayerSlots(player); - } - - public int getInventoryOffsetY() { - return 92; + public ContainerPlayer(EntityNPC player) { + this.addPlayerSlots(player); } - public ItemStack getSingleRecipe(ItemStack stack) { - return null; + public int getInventoryOffsetY() { + return 16; + } + + public ItemStack getSingleRecipe(ItemStack stack) { + return null; // this.baseCrafting.setInventorySlotContents(0, stack); // stack = CraftingRegistry.getMatching(this.baseCrafting); // this.baseCrafting.setInventorySlotContents(0, null); // return stack; - } - - public ItemStack craftSingleRecipe(ItemStack stack) { + } + + public ItemStack craftSingleRecipe(ItemStack stack) { // this.baseCrafting.setInventorySlotContents(0, stack); // SlotCrafting.handleRemaining(this.baseCrafting, this.thePlayer); // stack = this.baseCrafting.getStackInSlot(0); // this.baseCrafting.setInventorySlotContents(0, null); - return stack; - } + return stack; + } - public boolean canInteractWith(EntityNPC playerIn) - { - return true; - } - - private int getFreeSlotFor(Equipment type) { - for(Equipment slot : type.getPossibleSlots(this.thePlayer)) { - if(!this.inventorySlots.get(slot.getIndex()).getHasStack()) - return slot.getIndex(); - } - return -1; - } + public boolean canInteractWith(EntityNPC playerIn) { + return true; + } - public ItemStack transferStackInSlot(EntityNPC playerIn, int index) - { - ItemStack itemstack = null; - Slot slot = (Slot)this.inventorySlots.get(index); - int idx; + private int getFreeSlotFor(EntityNPC player, Equipment type) { + for(Equipment slot : type.getPossibleSlots(player)) { + if(!this.inventorySlots.get(slot.getIndex()).getHasStack()) + return slot.getIndex(); + } + return -1; + } - if (slot != null && slot.getHasStack()) - { - ItemStack itemstack1 = slot.getStack(); - itemstack = itemstack1.copy(); + public ItemStack transferStackInSlot(EntityNPC playerIn, int index) { + ItemStack itemstack = null; + Slot slot = this.inventorySlots.get(index); + int idx; - if (index >= 0 && index < Equipment.ARMOR_SLOTS) - { - if (!this.mergeItemStack(itemstack1, Equipment.ARMOR_SLOTS, Equipment.ARMOR_SLOTS + Equipment.INVENTORY_SLOTS)) - { - return null; - } - } - else if (itemstack.getItem() instanceof ItemArmor armor && (idx = this.getFreeSlotFor(armor.getArmorType())) >= 0) - { - if (!this.mergeItemStack(itemstack1, idx, idx + 1)) - { - return null; - } - } - else if (index >= Equipment.ARMOR_SLOTS && index < Equipment.ARMOR_SLOTS + Equipment.INVENTORY_SLOTS) - { - return null; - } - else if (!this.mergeItemStack(itemstack1, Equipment.ARMOR_SLOTS, Equipment.ARMOR_SLOTS + Equipment.INVENTORY_SLOTS)) - { - return null; - } + if(slot != null && slot.getHasStack()) { + ItemStack itemstack1 = slot.getStack(); + itemstack = itemstack1.copy(); - if (itemstack1.isEmpty()) - { - slot.putStack((ItemStack)null); - } - else - { - slot.onSlotChanged(); - } + if(index >= 0 && index < Equipment.ARMOR_SLOTS) { + if(!this.mergeItemStack(itemstack1, Equipment.ARMOR_SLOTS, Equipment.ARMOR_SLOTS + Equipment.INVENTORY_SLOTS)) { + return null; + } + } + else if(itemstack.getItem() instanceof ItemArmor armor && (idx = this.getFreeSlotFor(playerIn, armor.getArmorType())) >= 0) { + if(!this.mergeItemStack(itemstack1, idx, idx + 1)) { + return null; + } + } + else if(index >= Equipment.ARMOR_SLOTS && index < Equipment.ARMOR_SLOTS + Equipment.INVENTORY_SLOTS) { + return null; + } + else if(!this.mergeItemStack(itemstack1, Equipment.ARMOR_SLOTS, Equipment.ARMOR_SLOTS + Equipment.INVENTORY_SLOTS)) { + return null; + } - if (itemstack1.getSize() == itemstack.getSize()) - { - return null; - } + if(itemstack1.isEmpty()) { + slot.putStack((ItemStack)null); + } + else { + slot.onSlotChanged(); + } - slot.onPickupFromSlot(playerIn, itemstack1); - } + if(itemstack1.getSize() == itemstack.getSize()) { + return null; + } - return itemstack; - } + slot.onPickupFromSlot(playerIn, itemstack1); + } + + return itemstack; + } } diff --git a/common/src/main/java/common/util/Equipment.java b/common/src/main/java/common/util/Equipment.java index 320d02d5..00428ea1 100644 --- a/common/src/main/java/common/util/Equipment.java +++ b/common/src/main/java/common/util/Equipment.java @@ -30,7 +30,7 @@ public enum Equipment implements Identifyable, Displayable { HORSE_ARMOR("horse_armor", "Pferderüstung", EntityHorse.class, 8, 0); - public static final int INVENTORY_SLOTS = 64; + public static final int INVENTORY_SLOTS = 256; public static final int ARMOR_SLOTS; public static final Equipment[] ARMOR;