fixed pipe tabs not updating occasionally

This commit is contained in:
Ellpeck 2020-05-02 19:37:11 +02:00
parent d46858507f
commit c0c69807c0

View file

@ -23,6 +23,7 @@ public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extend
private static final ResourceLocation TEXTURE = new ResourceLocation(PrettyPipes.ID, "textures/gui/pipe.png");
private final List<Tab> tabs = new ArrayList<>();
private final ItemStack[] lastItems = new ItemStack[this.container.tile.modules.getSlots()];
public AbstractPipeGui(T screenContainer, PlayerInventory inv, ITextComponent titleIn) {
super(screenContainer, inv, titleIn);
@ -36,6 +37,22 @@ public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extend
this.initTabs();
}
@Override
public void tick() {
super.tick();
boolean changed = false;
for (int i = 0; i < this.container.tile.modules.getSlots(); i++) {
ItemStack stack = this.container.tile.modules.getStackInSlot(i);
if (stack != this.lastItems[i]) {
this.lastItems[i] = stack;
changed = true;
}
}
if (changed)
this.initTabs();
}
@Override
public void render(int mouseX, int mouseY, float partialTicks) {
this.renderBackground();
@ -71,15 +88,6 @@ public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extend
}
}
@Override
protected void handleMouseClick(Slot slotIn, int slotId, int mouseButton, ClickType type) {
super.handleMouseClick(slotIn, slotId, mouseButton, type);
// this might cause unnecessary tab initializations, but
// it's a pretty cheap operation so it should be fine
if (slotIn != null)
this.initTabs();
}
@Override
public boolean mouseClicked(double x, double y, int button) {
for (Tab tab : this.tabs) {