Skip to content

Commit

Permalink
Update ContainerDisplay.java
Browse files Browse the repository at this point in the history
* The order of the inventories was changed, now the player's inventory will be on the left, and the chest will be on the right
  • Loading branch information
TheBigEye authored and Makkkkus committed Jul 20, 2023
1 parent fcc44be commit c4688ad
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/client/java/minicraft/screen/ContainerDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,52 @@ public class ContainerDisplay extends Display {
private Chest chest;

public ContainerDisplay(Player player, Chest chest) {
super(new InventoryMenu(chest, chest.getInventory(), chest.name, RelPos.LEFT), new InventoryMenu(player, player.getInventory(), "minicraft.display.menus.inventory", RelPos.RIGHT));
super(
new InventoryMenu(player, player.getInventory(), "minicraft.display.menus.inventory", RelPos.LEFT),
new InventoryMenu(chest, chest.getInventory(), chest.name, RelPos.RIGHT)
);

//pInv = player.getInventory();
//cInv = chest.getInventory();
this.player = player;
this.chest = chest;

onScreenKeyboardMenu = OnScreenKeyboardMenu.checkAndCreateMenu();
if (onScreenKeyboardMenu != null)
if (onScreenKeyboardMenu != null) {
onScreenKeyboardMenu.setVisible(false);
}

menus[1].translate(menus[0].getBounds().getWidth() + padding, 0);

if(menus[0].getNumOptions() == 0) onSelectionChange(0, 1);
if (menus[1].getNumOptions() == 0) onSelectionChange(1, 0);
}

OnScreenKeyboardMenu onScreenKeyboardMenu;

@Override
protected void onSelectionChange(int oldSel, int newSel) {
super.onSelectionChange(oldSel, newSel);
if(oldSel == newSel) return; // this also serves as a protection against access to menus[0] when such may not exist.

if (oldSel == newSel) return; // this also serves as a protection against access to menus[0] when such may not exist.

int shift = 0;
if(newSel == 0) shift = padding - menus[0].getBounds().getLeft();
if(newSel == 1) shift = (Screen.w - padding) - menus[1].getBounds().getRight();
for(Menu m: menus)

if (newSel == 0) shift = padding - menus[0].getBounds().getLeft();
if (newSel == 1) shift = (Screen.w - padding) - menus[1].getBounds().getRight();

for (Menu m: menus) {
m.translate(shift, 0);
}
}

private int getOtherIdx() { return selection ^ 1; }

@Override
public void render(Screen screen) {
super.render(screen);
if (onScreenKeyboardMenu != null)
if (onScreenKeyboardMenu != null) {
onScreenKeyboardMenu.render(screen);
}
}

@Override
Expand Down Expand Up @@ -101,14 +112,15 @@ public void tick(InputHandler input) {
if (mainMethod || !onScreenKeyboardMenu.isVisible())
if (input.inputPressed("attack") || input.getKey("shift-enter").clicked) {
if (curMenu.getEntries().length == 0) return;

// switch inventories
Inventory from, to;
if(selection == 0) {
from = chest.getInventory();
to = player.getInventory();
} else {
if (selection == 0) {
from = player.getInventory();
to = chest.getInventory();
} else {
from = chest.getInventory();
to = player.getInventory();
}

int toSel = menus[otherIdx].getSelection();
Expand Down Expand Up @@ -148,8 +160,9 @@ public void tick(InputHandler input) {
}

public void onInvUpdate(ItemHolder holder) {
if(holder == player || holder == chest)
if (holder == player || holder == chest) {
update();
}
}

private void update() {
Expand Down

0 comments on commit c4688ad

Please sign in to comment.