1
0
Fork 0

improve container gui

This commit is contained in:
Sen 2025-09-07 18:17:13 +02:00
parent 448d54c441
commit c8d4b8a48e
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
21 changed files with 226 additions and 296 deletions

View file

@ -47,15 +47,6 @@ public abstract class Gui {
}
public void onGuiClosed() {
}
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
}
public void mouseReleased(int mouseX, int mouseY, int state) {
}
public void mouseDragged(int mouseX, int mouseY) {
}
public void drawPost() {
@ -71,10 +62,6 @@ public abstract class Gui {
}
public void renameItem() {
}
public void drawBackground() {
}
public Element clicked(int x, int y) {
@ -235,7 +222,6 @@ public abstract class Gui {
public void render() {
this.drawMainBackground();
this.drawBackground();
if(this.gm.fbX != 0 && this.gm.fbY != 0)
this.draw();
GlState.bindTexture(0);

View file

@ -31,6 +31,7 @@ import common.entity.npc.Attribute;
import common.init.ItemRegistry;
import common.inventory.Container;
import common.inventory.Slot;
import common.inventory.SlotCommon;
import common.item.CheatTab;
import common.item.ItemStack;
import common.packet.CPacketAction;
@ -62,11 +63,10 @@ public abstract class GuiContainer extends Gui
private static CheatTab selectedTab = CheatTab.ALL;
protected RenderItem itemRender;
protected final int xSize;
protected final int ySize;
public Container inventorySlots;
private Slot theSlot;
protected final List<Overlay> drawnOverlays = Lists.<Overlay>newArrayList();
private final InventoryButton[] invButtons;
private boolean ignoreMouseUp;
private long lastClickTime;
private Slot lastClickSlot;
@ -74,9 +74,6 @@ public abstract class GuiContainer extends Gui
private boolean doubleClick;
private ItemStack shiftClickedSlot;
protected int container_x;
protected int container_y;
private int hover_x;
private int hover_y;
private String tooltip;
@ -195,110 +192,178 @@ public abstract class GuiContainer extends Gui
}
public Label label(String text, int x, int y) {
return this.add(new FontLabel(x + this.container_x, y + this.container_y, 300, Font.LARGE, text, true));
return this.add(new FontLabel(x, y, 300, Font.LARGE, text, true));
}
public DisplayLabel display(String text, int x, int y, int w, int lines) {
return this.add(new DisplayLabel(x + this.container_x, y + this.container_y, w, lines, Font.LARGE, text));
return this.add(new DisplayLabel(x, y, w, lines, Font.LARGE, text));
}
public Bar bar(int x, int y, int w, int h) {
return this.add(new Bar(x + this.container_x, y + this.container_y, w, h, Font.LARGE));
}
public void rect(int x, int y, int width, int height, int color) {
Drawing.drawRect(this.container_x + x, this.container_y + y, width, height, 0xff000000 | color);
}
public void grad(int x, int y, int width, int height, int top, int bottom, int topleft, int btmright) {
Drawing.drawGradient(this.container_x + x, this.container_y + y, width, height, 0xff000000 | top, 0xff000000 | bottom, 0xff000000 | topleft, 0xff000000 | btmright);
}
public InventoryButton slot(int x, int y, int w, int h, Slot slot) {
return this.add(new InventoryButton(this.container_x + x, this.container_y + y, w, h, slot));
return this.add(new Bar(x, y, w, h, Font.LARGE));
}
public InventoryButton slot(int x, int y, int w, int h) {
return this.slot(x, y, w, h, null);
return this.add(new InventoryButton(x, y, w, h, null, 1, 1));
}
public ActButton button(int x, int y, int w, int h, ButtonCallback callback, String text) {
return this.add(new ActButton(this.container_x + x, this.container_y + y, w, h, callback, text));
return this.add(new ActButton(x, y, w, h, callback, text));
}
public void mouse(Button btn, int x, int y, boolean ctrl, boolean shift) {
super.mouse(btn, x, y, ctrl, shift);
this.mouseClicked(x - this.container_x, y - this.container_y, btn.ordinal()); //TODO: enum
this.mouseClicked(x, y, btn.ordinal()); //TODO: enum
}
public void mouserel(Button btn, int x, int y) {
super.mouserel(btn, x, y);
this.mouseReleased(x - this.container_x, y - this.container_y, btn.ordinal()); //TODO: enum
}
public void drag(int x, int y) {
super.drag(x, y);
if(Button.MOUSE_LEFT.isDown() || Button.MOUSE_RIGHT.isDown() || Button.MOUSE_MIDDLE.isDown())
this.mouseDragged(x - this.container_x, y - this.container_y);
this.mouseReleased(x, y, btn.ordinal()); //TODO: enum
}
public GuiContainer(Container container)
{
this.inventorySlots = container;
this.ignoreMouseUp = true;
this.xSize = (container.getInventoryOffsetX() - 2) * 2 + 36 * Container.INVENTORY_WIDTH;
this.ySize = container.getInventoryOffsetY() + 52 + 36 * ((Equipment.INVENTORY_SLOTS + Container.INVENTORY_WIDTH - 1) / Container.INVENTORY_WIDTH);
this.invButtons = new InventoryButton[container.inventorySlots.size()];
}
public int getControlAreaWidth() {
return 0;
}
public void init(int width, int height) {
this.itemRender = this.gm.getRenderItem();
this.tooltip = null;
this.cheatStack = null;
this.container_x = (width - this.xSize) / 2;
this.container_y = (height - this.ySize) / 2;
this.initGui();
this.gm.player.openContainer = this.inventorySlots;
boolean invLeft = false;
boolean invRight = false;
int leftSlots = 0;
int rightSlots = 0;
for(int z = 0; z < this.inventorySlots.getPlayerInventoryOffset() - Equipment.ARMOR_SLOTS; z++) {
Slot slot = this.inventorySlots.inventorySlots.get(z);
if(slot.slotRight)
++rightSlots;
else
++leftSlots;
if(slot instanceof SlotCommon) {
if(slot.slotRight)
invRight = true;
else
invLeft = true;
}
}
boolean center = leftSlots == 0 || rightSlots == 0;
int area = this.getControlAreaWidth();
int side = this.gm.itemCheat ? 450 : 0;
int gap = 2;
int border = 2;
int frame = 16;
int header = 20;
int invWidth = (this.gm.fbX - frame - border - border - side - frame) / 32;
int invHeight = ((Equipment.INVENTORY_SLOTS + invWidth - 1) / invWidth);
int playerWidth = border + invWidth * 32 + border;
int playerHeight = header + border + 32 + border + gap + border + invHeight * 32 + border;
int playerX = frame;
int playerY = this.gm.fbY - frame - playerHeight;
int playerX2 = playerX + playerWidth;
int playerY2 = playerY + playerHeight;
int slotsWidth = center ? (this.gm.fbX - frame - border - (invLeft ? border : 0) - area - side - frame) / (invLeft ? 32 : border + 32 + border + gap) : (this.gm.fbX - frame - border - (invLeft ? border : 0) - area - border - (invRight ? border : 0) - side - frame) / ((invLeft ? 32 : border + 32 + border + gap) + (invRight ? 32 : border + 32 + border + gap));
int leftSlotsHeight = ((leftSlots + slotsWidth - 1) / slotsWidth);
int leftWidth = border + slotsWidth * (invLeft ? 32 : border + 32 + border) + (invLeft ? 0 : (slotsWidth - 1) * gap) + (invLeft ? border : 0);
int leftHeight = header + border + leftSlotsHeight * (invLeft ? 32 : border + 32 + border) + (invLeft ? 0 : (leftSlotsHeight - 1) * gap) + (invLeft ? border : 0);
int leftX = frame;
int leftY = frame;
int leftX2 = leftX + leftWidth;
int leftY2 = leftY + leftHeight;
int rightSlotsHeight = ((rightSlots + slotsWidth - 1) / slotsWidth);
int rightWidth = border + slotsWidth * (invRight ? 32 : border + 32 + border) + (invRight ? 0 : (slotsWidth - 1) * gap) + (invRight ? border : 0);
int rightHeight = header + border + rightSlotsHeight * (invRight ? 32 : border + 32 + border) + (invRight ? 0 : (rightSlotsHeight - 1) * gap) + (invRight ? border : 0);
int rightX = this.gm.fbX - frame - side - rightWidth;
int rightY = frame;
int rightX2 = rightX + rightWidth;
int rightY2 = rightY + rightHeight;
int leftIndex = 0;
int rightIndex = 0;
for(int z = 0; z < this.invButtons.length; z++) {
Slot slot = this.inventorySlots.inventorySlots.get(z);
int x;
int y;
int w = 1;
int h = 1;
if(slot.slotNumber >= this.inventorySlots.getPlayerInventoryOffset()) {
int n = slot.slotNumber - this.inventorySlots.getPlayerInventoryOffset();
x = playerX + border + (n % invWidth) * 32;
y = playerY + header + border + 32 + border + gap + border + (n / invWidth) * 32;
w = invWidth;
h = invHeight;
}
else if(slot.slotNumber >= this.inventorySlots.getPlayerInventoryOffset() - Equipment.ARMOR_SLOTS) {
int n = slot.slotNumber - (this.inventorySlots.getPlayerInventoryOffset() - Equipment.ARMOR_SLOTS);
x = playerX + border + n * (32 + border + gap + border);
y = playerY + header + border;
}
else if(slot.slotRight) {
int n = rightIndex++;
x = rightX + border + ((rightSlots < slotsWidth ? n + slotsWidth - rightSlots : n) % slotsWidth) * (32 + (invRight ? 0 : border + gap + border));
y = rightY + header + border + (n / slotsWidth) * (32 + (invRight ? 0 : border + gap + border));
if(invRight) {
w = slotsWidth;
h = rightSlotsHeight;
}
}
else {
int n = leftIndex++;
x = leftX + border + (n % slotsWidth) * (32 + (invLeft ? 0 : border + gap + border));
y = leftY + header + border + (n / slotsWidth) * (32 + (invLeft ? 0 : border + gap + border));
if(invLeft) {
w = slotsWidth;
h = leftSlotsHeight;
}
}
this.invButtons[z] = this.add(new InventoryButton(x, y, 32, 32, slot, w, h));
}
if(this.gm.itemCheat) {
int x2 = Math.max(playerX2, rightX2);
this.cheatX = x2 + 4;
this.cheatY = 32;
this.cheatWidth = Math.max((this.gm.fbX - x2 - 32) / 36, 1);
this.cheatHeight = Math.max((this.gm.fbY - 40 * ((CheatTab.values().length + (this.cheatWidth - 1)) / this.cheatWidth) - 92) / 36, 1);
}
this.addButtons();
this.addElements();
this.label("Inventar", this.inventorySlots.getInventoryOffsetX(), this.inventorySlots.getInventoryOffsetY() - 4);
this.inventoryLabel = this.label("", this.inventorySlots.getInventoryOffsetX() + 36 * Container.INVENTORY_WIDTH - 180, this.inventorySlots.getInventoryOffsetY() - 4);
this.label("Inventar", playerX, playerY + 18);
this.inventoryLabel = this.label("", playerX2 - 180, playerY + 18);
}
public void hover(String text, int x, int y) {
this.tooltip = text;
this.hover_x = x + this.container_x + 16;
this.hover_y = y + this.container_y + 16;
this.hover_x = x + 16;
this.hover_y = y + 16;
}
public String getTitle() {
return "Inventar";
}
public void initGui()
{
this.gm.player.openContainer = this.inventorySlots;
if(this.gm.itemCheat) {
this.cheatX = this.container_x + this.xSize + 4;
this.cheatY = 32;
this.cheatWidth = Math.max((this.gm.fbX - this.container_x - this.xSize - 32) / 36, 1);
this.cheatHeight = Math.max((this.gm.fbY - 40 * ((CheatTab.values().length + (this.cheatWidth - 1)) / this.cheatWidth) - 92) / 36, 1);
}
}
public void addButtons() {
if(this.inventorySlots != null) {
for (int i1 = 0; i1 < this.inventorySlots.inventorySlots.size(); ++i1) {
Slot slot = this.inventorySlots.inventorySlots.get(i1);
if(slot.canDraw())
this.slot(slot.xDisplayPosition - 2, slot.yDisplayPosition - 2, 36, 36, slot);
}
}
if(this.gm.itemCheat) {
this.cheatLabel = this.add(new FontLabel(this.cheatX, this.cheatY, this.cheatWidth * 36, Font.SMALL, "", true));
// this.cheatDesc = this.add(new DisplayLabel(this.cheatX, this.cheatY + this.cheatHeight * 18 + 20 * ((CheatTab.values().length + (this.cheatWidth - 1)) / this.cheatWidth) + 4 + 18, this.cheatWidth * 18, 4, Font.SMALL, "Vorsicht: Schummeln\nwird mit Keule bestraft!!\n(Halte Strg beim Klick\nfür vollen Stapel)"));
this.cheatSearch = this.add(new Field(this.cheatX, this.cheatY + this.cheatHeight * 36 + 40 * ((CheatTab.values().length + (this.cheatWidth - 1)) / this.cheatWidth) + 8, this.cheatWidth * 36 + 20, 0, 128, null, ""));
this.cheatLast = "";
for(CheatTab tab : CheatTab.values()) {
this.add(new InventoryButton(this.cheatX + 36 * (tab.getIndex() % this.cheatWidth), this.cheatY + this.cheatHeight * 36 + 8 + 40 * (tab.getIndex() / this.cheatWidth), 36, 36, null));
this.add(new InventoryButton(this.cheatX + 36 * (tab.getIndex() % this.cheatWidth), this.cheatY + this.cheatHeight * 36 + 8 + 40 * (tab.getIndex() / this.cheatWidth), 36, 36, null, 1, 1));
}
this.setCurrentTab(selectedTab);
}
@ -307,14 +372,14 @@ public abstract class GuiContainer extends Gui
public abstract void addElements();
protected void drawSlots(int mouseX, int mouseY) {
for (int i1 = 0; i1 < this.inventorySlots.inventorySlots.size(); ++i1)
for (int i1 = 0; i1 < this.invButtons.length; ++i1)
{
Slot slot = (Slot)this.inventorySlots.inventorySlots.get(i1);
InventoryButton slot = this.invButtons[i1];
this.drawSlot(slot);
if (this.isMouseOverSlot(slot, mouseX, mouseY) && slot.canHover())
if (this.isMouseOverSlot(slot, mouseX, mouseY) && slot.getSlot().canHover())
{
this.theSlot = slot;
this.theSlot = slot.getSlot();
}
}
@ -462,11 +527,13 @@ public abstract class GuiContainer extends Gui
private void drawItemStack(ItemStack stack, int x, int y, String altText)
{
GL15.glPushMatrix();
GL15.glTranslatef(0.0F, 0.0F, 32.0F);
this.itemRender.zLevel = 200.0F;
this.itemRender.renderItemAndEffectIntoGUI(stack, this.container_x + x, this.container_y + y);
this.itemRender.renderItemAndEffectIntoGUI(stack, x, y);
this.drawnOverlays.add(new Overlay(stack, x, y, altText));
this.itemRender.zLevel = 0.0F;
GL15.glPopMatrix();
}
protected void renderToolTip(ItemStack stack, int x, int y) {
@ -501,19 +568,15 @@ public abstract class GuiContainer extends Gui
}
public void drawPost() {
GL15.glPushMatrix();
// GL15.glTranslatef((float)((this.gm.fbX - this.xSize * SCALE) / 2), (float)((this.gm.fbY - this.ySize * SCALE) / 2), 0.0f);
// GL15.glScalef(2.0f, 2.0f, 2.0f);
this.drawScreen(this.gm.mouseX - this.container_x, this.gm.mouseY - this.container_y);
GL15.glPopMatrix();
this.drawScreen(this.gm.mouseX, this.gm.mouseY);
ItemRenderer.disableStandardItemLighting();
}
private void drawSlot(Slot slotIn)
private void drawSlot(InventoryButton btn)
{
int i = slotIn.xDisplayPosition;
int j = slotIn.yDisplayPosition;
ItemStack itemstack = slotIn.getStack();
int i = btn.getX();
int j = btn.getY();
ItemStack itemstack = btn.getSlot().getStack();
boolean flag = false;
ItemStack itemstack1 = this.gm.player.getMouseItem();
String s = null;
@ -521,7 +584,7 @@ public abstract class GuiContainer extends Gui
this.itemRender.zLevel = 100.0F;
GlState.enableDepth();
this.itemRender.renderItemAndEffectIntoGUI(itemstack, this.container_x + i, this.container_y + j);
this.itemRender.renderItemAndEffectIntoGUI(itemstack, i, j);
this.drawnOverlays.add(new Overlay(itemstack, i, j, s));
this.itemRender.zLevel = 0.0F;
@ -529,20 +592,20 @@ public abstract class GuiContainer extends Gui
private Slot getSlotAtPosition(int x, int y)
{
for (int i = 0; i < this.inventorySlots.inventorySlots.size(); ++i)
for (int i = 0; i < this.invButtons.length; ++i)
{
Slot slot = (Slot)this.inventorySlots.inventorySlots.get(i);
InventoryButton btn = this.invButtons[i];
if (this.isMouseOverSlot(slot, x, y))
if (this.isMouseOverSlot(btn, x, y))
{
return slot;
return btn.getSlot();
}
}
return null;
}
public void mouseClicked(int mouseX, int mouseY, int mouseButton)
private void mouseClicked(int mouseX, int mouseY, int mouseButton)
{
if(this.gm == null)
return;
@ -580,24 +643,11 @@ public abstract class GuiContainer extends Gui
if (mouseButton == 0 || mouseButton == 1)
{
boolean flag1 = mouseX < 0 || mouseY < 0 || mouseX >= this.xSize || mouseY >= this.ySize;
int l = -1;
if (slot != null)
{
l = slot.slotNumber;
}
if (flag1)
{
l = -999;
}
if (l != -1)
{
if (this.gm.player.getMouseItem() == null)
{
boolean flag2 = l != -999 && this.gm.shift();
boolean flag2 = this.gm.shift();
int i1 = 0;
if (flag2)
@ -605,12 +655,8 @@ public abstract class GuiContainer extends Gui
this.shiftClickedSlot = slot != null && slot.getHasStack() ? slot.getStack() : null;
i1 = 1;
}
else if (l == -999)
{
i1 = 4;
}
this.handleMouseClick(slot, l, mouseButton, i1);
this.handleMouseClick(slot, slot.slotNumber, mouseButton, i1);
this.ignoreMouseUp = true;
}
@ -626,27 +672,11 @@ public abstract class GuiContainer extends Gui
this.lastClickButton = mouseButton;
}
public void mouseDragged(int mouseX, int mouseY)
{
}
public void mouseReleased(int mouseX, int mouseY, int state)
private void mouseReleased(int mouseX, int mouseY, int state)
{
if(this.gm == null || this.cheatStack != null)
return;
Slot slot = this.getSlotAtPosition(mouseX, mouseY);
boolean flag = mouseX < 0 || mouseY < 0 || mouseX >= this.xSize || mouseY >= this.ySize;
int k = -1;
if (slot != null)
{
k = slot.slotNumber;
}
if (flag)
{
k = -999;
}
if (this.doubleClick && slot != null && state == 0 && this.inventorySlots.canMergeSlot((ItemStack)null, slot))
{
@ -665,7 +695,7 @@ public abstract class GuiContainer extends Gui
}
else
{
this.handleMouseClick(slot, k, state, 6);
this.handleMouseClick(slot, slot.slotNumber, state, 6);
}
this.doubleClick = false;
@ -681,14 +711,14 @@ public abstract class GuiContainer extends Gui
if (this.gm.player.getMouseItem() != null)
{
boolean flag1 = k != -999 && this.gm.shift();
boolean flag1 = this.gm.shift();
if (flag1)
{
this.shiftClickedSlot = slot != null && slot.getHasStack() ? slot.getStack() : null;
}
this.handleMouseClick(slot, k, state, flag1 ? 1 : 0);
this.handleMouseClick(slot, slot != null ? slot.slotNumber : -1, state, flag1 ? 1 : 0);
}
}
@ -698,9 +728,9 @@ public abstract class GuiContainer extends Gui
}
}
private boolean isMouseOverSlot(Slot slotIn, int mouseX, int mouseY)
private boolean isMouseOverSlot(InventoryButton btn, int mouseX, int mouseY)
{
return this.isPointInRegion(slotIn.xDisplayPosition, slotIn.yDisplayPosition, 32, 32, mouseX, mouseY);
return this.isPointInRegion(btn.getX() + 2, btn.getY() + 2, 32, 32, mouseX, mouseY);
}
protected boolean isPointInRegion(int left, int top, int right, int bottom, int pointX, int pointY)
@ -766,7 +796,7 @@ public abstract class GuiContainer extends Gui
public void renderItemOverlayIntoGUI(ItemStack stack, int xPosition, int yPosition, String text)
{
renderItemOverlay(stack, this.container_x + xPosition, this.container_y + yPosition, text, 0, 0);
renderItemOverlay(stack, xPosition, yPosition, text, 0, 0);
}
public static void renderItemOverlay(ItemStack stack, int xPosition, int yPosition, String text, int bar2, int bar2max)
@ -811,8 +841,9 @@ public abstract class GuiContainer extends Gui
Drawing.drawRect(x, y, width, height, 0xff000000 | (red << 16) | (green << 8) | blue);
}
public void drawBackground() {
Drawing.drawGradientBorder(this.container_x, this.container_y, this.xSize, this.ySize, Util.mulColor(this.gm.style.fill_top, 0.8f), Util.mulColor(this.gm.style.fill_btm, 0.8f), 0xff000000, Util.mulColor(this.gm.style.brdr_top, 0.8f), Util.mulColor(this.gm.style.brdr_btm, 0.8f));
public void drawMainBackground() {
super.drawMainBackground();
Drawing.drawGradientBorder(0, 0, this.gm.fbX, this.gm.fbY, Util.mulColor(this.gm.style.fill_top, 0.8f), Util.mulColor(this.gm.style.fill_btm, 0.8f), 0xff000000, Util.mulColor(this.gm.style.brdr_top, 0.8f), Util.mulColor(this.gm.style.brdr_btm, 0.8f));
}

View file

@ -17,4 +17,8 @@ public class GuiCrafting extends GuiContainer {
public void addElements() {
this.label(this.type.getDisplay(), 16, 32);
}
public int getControlAreaWidth() {
return 300;
}
}

View file

@ -26,6 +26,10 @@ public class GuiDevice extends GuiContainer {
this.tileInv = tile;
this.tile = tile;
}
public int getControlAreaWidth() {
return 350;
}
public void updateScreen() {
super.updateScreen();

View file

@ -29,6 +29,10 @@ public class GuiEnchant extends GuiContainer implements ButtonCallback {
super(new ContainerEnchantment(inv, world));
this.enchantment = (ContainerEnchantment)this.inventorySlots;
}
public int getControlAreaWidth() {
return 250;
}
public void updateScreen() {
super.updateScreen();

View file

@ -12,6 +12,10 @@ public class GuiEntity extends GuiContainer {
super(new ContainerEntityInventory(player, entityInv, entity));
this.title = entity.getName();
}
public int getControlAreaWidth() {
return 16;
}
public void addElements() {
this.label(this.title, 16, 32);

View file

@ -27,6 +27,10 @@ public class GuiMerchant extends GuiContainer implements ButtonCallback {
super(new ContainerMerchant(inv, null, world));
this.title = entity.getName();
}
public int getControlAreaWidth() {
return 380;
}
public void addButtons() {
super.addButtons();

View file

@ -16,6 +16,10 @@ public class GuiRepair extends GuiContainer {
this.playerInv = inv;
this.anvil = (ContainerRepair)this.inventorySlots;
}
public int getControlAreaWidth() {
return 250;
}
public void updateScreen() {
super.updateScreen();

View file

@ -130,7 +130,7 @@ public abstract class GuiList<T extends ListEntry> extends Gui
int mouseYIn = this.gm.mouseY;
this.mouseX = mouseXIn;
this.mouseY = mouseYIn;
this.drawBackground();
// this.drawBackground();
this.bindAmountScrolled();
Drawing.drawScaled(this.gm, Gui.BACKGROUND, 0, this.top, this.gm.fbX, this.bottom - this.top, 0xff7f7f7f);

View file

@ -1,7 +1,6 @@
package client.gui.element;
import client.Client;
import client.gui.Gui;
import client.gui.container.GuiContainer;
import client.renderer.Drawing;
import common.inventory.Slot;
@ -11,23 +10,34 @@ public class InventoryButton extends Element {
private final Slot slot;
private final String texture;
private final boolean background;
private final boolean hoverable;
private final int bgX;
private final int bgY;
private final int bgW;
private final int bgH;
public InventoryButton(int x, int y, int w, int h, Slot slot) {
public InventoryButton(int x, int y, int w, int h, Slot slot, int slotsX, int slotsY) {
super(x, y, w, h, null);
this.texture = slot == null || slot.getTexture() == null || slot.getTexture().isEmpty() ? null : "textures/items/icon_" + slot.getTexture() + ".png";
this.background = slot == null || slot.getTexture() != null;
this.background = slot == null || (slot.getTexture() != null && slot.canDraw());
this.hoverable = slot == null || slot.canDraw();
this.slot = slot;
this.bgW = slot == null ? w : slot.getBackgroundWidth() * 36;
this.bgH = slot == null ? h : slot.getBackgroundHeight() * 36;
this.bgX = slot == null ? 0 : -2;
this.bgY = slot == null ? 0 : -2;
this.bgW = slot == null ? w : 2 + slotsX * 32 + 2;
this.bgH = slot == null ? h : 2 + slotsY * 32 + 2;
}
public Slot getSlot() {
return this.slot;
}
protected void drawBackground() {
if(this.background)
drawButton(this.gm, this.pos_x, this.pos_y, this.bgW, this.bgH);
if(this.texture != null && !this.slot.getHasStack())
Drawing.drawTexturedRect(this.gm, this.texture, 32, 32, this.pos_x + 2, this.pos_y + 2, 0, 0, this.size_x - 4, this.size_y - 4);
if(this.background) {
drawButton(this.gm, this.pos_x + this.bgX, this.pos_y + this.bgY, this.bgW, this.bgH);
if(this.texture != null && !this.slot.getHasStack())
Drawing.drawTexturedRect(this.gm, this.texture, 32, 32, this.pos_x, this.pos_y, 0, 0, this.size_x, this.size_y);
}
}
protected void drawForeground(int x1, int y1, int x2, int y2) {
@ -38,14 +48,13 @@ public class InventoryButton extends Element {
}
public boolean canHover() {
if(this.slot == null)
return true;
ItemStack hover = ((GuiContainer)this.gui).getHoverItem(this.slot);
return hover == null ? this.slot.getHasStack() : this.slot.isItemValid(hover);
}
public void drawHover() {
Drawing.drawRect(this.pos_x + 2, this.pos_y + 2, 32, 32, Gui.HOVER_COLOR);
if(this.hoverable) {
if(this.slot == null)
return true;
ItemStack hover = ((GuiContainer)this.gui).getHoverItem(this.slot);
return hover == null ? this.slot.getHasStack() : this.slot.isItemValid(hover);
}
return false;
}
public boolean canClick() {

View file

@ -1124,23 +1124,8 @@ public class ClientPlayer implements IClientPlayer
}
else
{
// boolean flag = false;
//
// if (this.gameController.openGui instanceof GuiCheat)
// {
//// GuiCheat guicontainercreative = (GuiCheat)this.gameController.openGui;
// flag = true; // guicontainercreative.getSelectedTabIndex() != CheatTab.tabInventory.getIndex();
// }
if (packetIn.getWindowId() == 0 && packetIn.getSlot() >= Equipment.ARMOR_SLOTS && packetIn.getSlot() < Equipment.ARMOR_SLOTS + Equipment.INVENTORY_SLOTS)
if (packetIn.getWindowId() == 0 && packetIn.getSlot() >= 0 && packetIn.getSlot() < Equipment.ARMOR_SLOTS + Equipment.INVENTORY_SLOTS)
{
ItemStack itemstack = entityplayer.inventoryContainer.getSlot(packetIn.getSlot()).getStack();
// if (packetIn.getStack() != null && (itemstack == null || itemstack.stackSize < packetIn.getStack().stackSize))
// {
// packetIn.getStack().animationsToGo = 5;
// }
entityplayer.inventoryContainer.putStackInSlot(packetIn.getSlot(), packetIn.getStack());
}
else if (packetIn.getWindowId() == entityplayer.openContainer.windowId) // && (packetIn.getWindowId() != 0 || !flag))

View file

@ -14,8 +14,6 @@ import common.util.Equipment;
public abstract class Container
{
public static final int INVENTORY_WIDTH = 16;
public List<ItemStack> inventoryItemStacks = Lists.<ItemStack>newArrayList();
public List<Slot> inventorySlots = Lists.<Slot>newArrayList();
public int windowId;
@ -23,25 +21,15 @@ public abstract class Container
protected int offset;
protected List<IPlayer> crafters = Lists.<IPlayer>newArrayList();
private Set<EntityNPC> playerList = Sets.<EntityNPC>newHashSet();
public int getInventoryOffsetX() {
return 16;
}
public int getInventoryOffsetY() {
return 168;
}
public final int getPlayerInventoryOffset() {
return this.offset;
}
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() * 36, y) {
this.addSlotToContainer(new Slot(player, Equipment.INVENTORY_SLOTS + slot.getIndex(), false) {
public boolean canStackItems() {
return false;
}
@ -62,7 +50,7 @@ public abstract class Container
this.offset = this.inventorySlots.size();
List<SlotCommon> list = Lists.newArrayList();
for(int z = 0; z < Equipment.INVENTORY_SLOTS; ++z) {
this.addSlotToContainer(new SlotCommon(list, player, z, x + (z % INVENTORY_WIDTH) * 36, y + 40 + (z / INVENTORY_WIDTH) * 36));
this.addSlotToContainer(new SlotCommon(list, player, z, true));
}
}

View file

@ -28,20 +28,12 @@ public class ContainerChest extends Container
{
for (int k = 0; k < this.width; ++k)
{
this.addSlotToContainer(new SlotCommon(list, chest, k + j * this.width, 16 + k * 36, 36 + j * 36));
this.addSlotToContainer(new SlotCommon(list, chest, k + j * this.width, false));
}
}
this.addPlayerSlots(player);
}
public int getInventoryOffsetX() {
return super.getInventoryOffsetX() + (this.width < INVENTORY_WIDTH ? 0 : (this.width - INVENTORY_WIDTH) * 36 / 2);
}
public int getInventoryOffsetY() {
return 170 + (this.height - 3) * 36;
}
protected boolean canMergeStacks() {
return true;

View file

@ -47,7 +47,7 @@ public class ContainerEnchantment extends Container
this.world = worldIn;
this.position = pos;
this.seed = playerInv.getEnchSeed();
this.addSlotToContainer(new Slot(this.table, 0, 50, 94)
this.addSlotToContainer(new Slot(this.table, 0, false)
{
public boolean isItemValid(ItemStack stack)
{

View file

@ -20,14 +20,14 @@ public class ContainerEntityInventory extends Container
this.entity = entity;
if(this.entity instanceof EntityHorse) {
final EntityHorse horse = (EntityHorse)this.entity;
this.addSlotToContainer(new Slot(entityInv, 0, 16, 36)
this.addSlotToContainer(new Slot(entityInv, 0, false)
{
public boolean isItemValid(ItemStack stack)
{
return super.isItemValid(stack) && stack.getItem() == Items.saddle && !this.getHasStack();
}
});
this.addSlotToContainer(new Slot(entityInv, 1, 16, 72)
this.addSlotToContainer(new Slot(entityInv, 1, false)
{
public boolean isItemValid(ItemStack stack)
{
@ -45,7 +45,7 @@ public class ContainerEntityInventory extends Container
{
for (int l = 0; l < 5; ++l)
{
this.addSlotToContainer(new SlotCommon(list, entityInv, 2 + l + k * 5, 160 + l * 36, 36 + k * 36));
this.addSlotToContainer(new SlotCommon(list, entityInv, 2 + l + k * 5, true));
}
}
}

View file

@ -15,9 +15,9 @@ public class ContainerMerchant extends Container
private int traded;
// private final EntityVillager theMerchant;
public SlotMerchantResult(EntityNPC player, InventoryMerchant merchantInventory, int slotIndex, int xPosition, int yPosition)
public SlotMerchantResult(EntityNPC player, InventoryMerchant merchantInventory, int slotIndex)
{
super(merchantInventory, slotIndex, xPosition, yPosition);
super(merchantInventory, slotIndex, true);
this.thePlayer = player;
// this.theMerchant = merchant;
this.theMerchantInventory = merchantInventory;
@ -134,17 +134,17 @@ public class ContainerMerchant extends Container
this.theMerchant = merchant;
this.theWorld = worldIn;
this.merchantInventory = new InventoryMerchant(playerInventory, merchant);
this.addSlotToContainer(new Slot(this.merchantInventory, 0, 72, 106) {
this.addSlotToContainer(new Slot(this.merchantInventory, 0, false) {
public boolean canEditItem() {
return false;
}
});
this.addSlotToContainer(new Slot(this.merchantInventory, 1, 124, 106) {
this.addSlotToContainer(new Slot(this.merchantInventory, 1, false) {
public boolean canEditItem() {
return false;
}
});
this.addSlotToContainer(new SlotMerchantResult(playerInventory, this.merchantInventory, 2, 240, 106));
this.addSlotToContainer(new SlotMerchantResult(playerInventory, this.merchantInventory, 2));
this.addPlayerSlots(playerInventory);
}

View file

@ -10,10 +10,6 @@ public class ContainerPlayer extends Container {
this.addPlayerSlots(player);
}
public int getInventoryOffsetY() {
return 32;
}
public ItemStack getSingleRecipe(ItemStack stack) {
return null;
// this.baseCrafting.setInventorySlotContents(0, stack);

View file

@ -114,17 +114,17 @@ public class ContainerRepair extends Container
};
this.selfPosition = blockPosIn;
this.theWorld = worldIn;
this.addSlotToContainer(new Slot(this.inputSlots, 0, 54, 94) {
this.addSlotToContainer(new Slot(this.inputSlots, 0, false) {
public boolean canEditItem() {
return false;
}
});
this.addSlotToContainer(new Slot(this.inputSlots, 1, 152, 94) {
this.addSlotToContainer(new Slot(this.inputSlots, 1, false) {
public boolean canEditItem() {
return false;
}
});
this.addSlotToContainer(new Slot(this.outputSlot, 2, 268, 94)
this.addSlotToContainer(new Slot(this.outputSlot, 2, true)
{
public boolean isItemValid(ItemStack stack)
{

View file

@ -35,7 +35,7 @@ public class ContainerTile extends Container
for (int idx = 0; idx < tileInv.getSizeInventory(); ++idx)
{
final int index = idx;
this.addSlotToContainer(new Slot(tileInv, idx, 16 + (this.tile.isInput(index) ? input : 8 - output) * 36, 162) {
this.addSlotToContainer(new Slot(tileInv, idx, !this.tile.isInput(index)) {
public boolean isItemValid(ItemStack stack)
{
return ContainerTile.this.tile.isItemValidForSlot(index, stack);
@ -53,10 +53,6 @@ public class ContainerTile extends Container
this.addPlayerSlots(player);
}
public int getInventoryOffsetY() {
return 224;
}
public boolean canInteractWith(EntityNPC playerIn)
{

View file

@ -5,32 +5,19 @@ import common.item.ItemStack;
public class Slot
{
/** The index of the slot in the inventory. */
private final int slotIndex;
/** The inventory we want to extract a slot from. */
public final IInventory inventory;
public final boolean slotRight;
/** the id of the slot(also the index in the inventory arraylist) */
public int slotNumber;
/** display position of the inventory slot on the screen x axis */
public int xDisplayPosition;
/** display position of the inventory slot on the screen y axis */
public int yDisplayPosition;
public Slot(IInventory inventoryIn, int index, int xPosition, int yPosition)
public Slot(IInventory inventoryIn, int index, boolean right)
{
this.inventory = inventoryIn;
this.slotIndex = index;
this.xDisplayPosition = xPosition;
this.yDisplayPosition = yPosition;
this.slotRight = right;
}
/**
* if par2 has more items than par1, onCrafting(item,countIncrease) is called
*/
public void onSlotChange(ItemStack p_75220_1_, ItemStack p_75220_2_)
{
if (p_75220_1_ != null && p_75220_2_ != null)
@ -47,17 +34,10 @@ public class Slot
}
}
/**
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an
* internal count then calls onCrafting(item).
*/
protected void onCrafting(ItemStack stack, int amount)
{
}
/**
* the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood.
*/
protected void onCrafting(ItemStack stack)
{
}
@ -67,42 +47,27 @@ public class Slot
this.onSlotChanged();
}
/**
* Check if the stack is a valid item for this slot. Always true beside for the armor slots.
*/
public boolean isItemValid(ItemStack stack)
{
return true;
}
/**
* Helper fnct to get the stack in the slot.
*/
public ItemStack getStack()
{
return this.inventory.getStackInSlot(this.slotIndex);
}
/**
* Returns if this slot contains a stack.
*/
public final boolean getHasStack()
{
return this.getStack() != null;
}
/**
* Helper method to put a stack in the slot.
*/
public void putStack(ItemStack stack)
{
this.inventory.setInventorySlotContents(this.slotIndex, stack);
this.onSlotChanged();
}
/**
* Called when the stack in a Slot changes
*/
public void onSlotChanged()
{
this.inventory.markDirty();
@ -118,26 +83,16 @@ public class Slot
return this.canStackItems() ? 1000000000 : 1;
}
/**
* Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new
* stack.
*/
public ItemStack decrStackSize(int amount)
{
return this.inventory.decrStackSize(this.slotIndex, amount);
}
/**
* returns true if the slot exists in the given inventory and location
*/
public boolean isHere(IInventory inv, int slotIn)
{
return inv == this.inventory && slotIn == this.slotIndex;
}
/**
* Return whether this slot's stack can be taken from this slot.
*/
public boolean canTakeStack(EntityNPC playerIn)
{
return true;

View file

@ -6,11 +6,8 @@ public class SlotCommon extends Slot {
private final List<SlotCommon> list;
private final SlotCommon draw;
private int w;
private int h;
public SlotCommon(List<SlotCommon> list, IInventory inventoryIn, int index, int xPosition, int yPosition) {
super(inventoryIn, index, xPosition, yPosition);
public SlotCommon(List<SlotCommon> list, IInventory inventoryIn, int index, boolean right) {
super(inventoryIn, index, right);
this.list = list;
this.draw = list.isEmpty() ? null : list.getFirst();
list.add(this);
@ -19,33 +16,4 @@ public class SlotCommon extends Slot {
public String getTexture() {
return this.draw == null ? super.getTexture() : null;
}
private void init() {
int x1 = Integer.MAX_VALUE;
int y1 = Integer.MAX_VALUE;
int x2 = Integer.MIN_VALUE;
int y2 = Integer.MIN_VALUE;
for(SlotCommon slot : this.list) {
x1 = Math.min(x1, slot.xDisplayPosition);
y1 = Math.min(y1, slot.yDisplayPosition);
x2 = Math.max(x2, slot.xDisplayPosition + 36);
y2 = Math.max(y2, slot.yDisplayPosition + 36);
}
this.w = (x2 - x1) / 36;
this.h = (y2 - y1) / 36;
}
public int getBackgroundWidth() {
if(this.draw != null)
return this.draw.getBackgroundWidth();
this.init();
return this.w;
}
public int getBackgroundHeight() {
if(this.draw != null)
return this.draw.getBackgroundHeight();
this.init();
return this.h;
}
}