Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Recipe book dupe(s) and Block break dupes #89

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ public interface InventoryGUI {
*/
void show(Player player);

/**
* Hides this GUI from all players
*/
void hideForAll();

/**
* Hide this GUI from the given player (pop it down)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,10 @@ public void onBlockRegistered(Location location, boolean isPlacing) {

@Override
public void onBlockUnregistered(Location loc) {
// Machines broken while viewed allow items to be taken out.
// We need to close the inventories if opened.
getGUI().hideForAll();

getGUI().ejectItems(getInputSlots());
getGUI().ejectItems(getOutputSlots());
getGUI().ejectItems(getUpgradeSlots());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import me.desht.dhutils.Debugger;
import me.desht.dhutils.text.LogUtils;

import javax.annotation.Nonnull;

public class STBInventoryGUI implements InventoryGUI {

// some handy stock textures
Expand Down Expand Up @@ -103,6 +105,10 @@ private static void setOpenGUI(Player player, InventoryGUI gui) {
}
}

private boolean hasOpenGUI(@Nonnull Player player) {
return getOpenGUI(player) == null;
}

@Override
public void addGadget(ClickableGadget gadget) {
int slot = gadget.getSlot();
Expand Down Expand Up @@ -197,10 +203,19 @@ public void show(Player player) {
monitor.doRepaint();
}
}
Debugger.getInstance().debug(player.getName() + " opened GUI for " + getOwningItem());
setOpenGUI(player, this);
listener.onGUIOpened(player);
player.openInventory(inventory);
if (hasOpenGUI(player)) {
Debugger.getInstance().debug(player.getName() + " opened GUI for " + getOwningItem());
setOpenGUI(player, this);
listener.onGUIOpened(player);
player.openInventory(inventory);
Comment on lines +206 to +210
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shit is horrible

Why don't we have a method to do the whole setOpenGUI, onGUIOpened and openInv.... out of scope here but fuck meeeeeeee

}
}

@Override
public void hideForAll() {
for (HumanEntity player : new ArrayList<>(inventory.getViewers())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getViewers already a List...

hide((Player) player);
}
}

@Override
Expand Down