Search in sources :

Example 1 with SPacketWorktableTab

use of com.codetaylor.mc.artisanworktables.modules.worktables.network.SPacketWorktableTab in project artisan-worktables by codetaylor.

the class GuiElementTabs method mouseClicked.

@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
    if (mouseButton != 0) {
        return;
    }
    List<TileEntityBase> actualJoinedTables = this.worktable.getJoinedTables(new ArrayList<>(), Minecraft.getMinecraft().player);
    List<TileEntityBase> joinedTables = this.getJoinedTableOffsetView(actualJoinedTables, GUI_TAB_OFFSET.getOffset(), this.worktable.getMaximumDisplayedTabCount());
    int yMin = this.elementYModifiedGet();
    int yMax = yMin + TAB_HEIGHT;
    for (int i = 0; i < joinedTables.size(); i++) {
        int xMin = this.elementXModifiedGet() + TAB_ITEM_HORIZONTAL_OFFSET + (TAB_WIDTH + TAB_SPACING) * i;
        int xMax = xMin + TAB_WIDTH;
        if (mouseX <= xMax && mouseX >= xMin && mouseY <= yMax && mouseY >= yMin) {
            TileEntityBase table = joinedTables.get(i);
            BlockPos pos = table.getPos();
            ModuleWorktables.PACKET_SERVICE.sendToServer(new SPacketWorktableTab(pos));
            Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.UI_BUTTON_CLICK, 1));
        }
    }
    int maximumDisplayedTabCount = this.worktable.getMaximumDisplayedTabCount();
    if (GUI_TAB_OFFSET.getOffset() > 0) {
        // check for left button click
        int xMin = this.elementXModifiedGet() + TAB_LEFT_OFFSET + TAB_ITEM_HORIZONTAL_OFFSET - 18;
        int xMax = xMin + 8;
        if (mouseX <= xMax && mouseX >= xMin && mouseY <= yMax && mouseY >= yMin) {
            int tabOffset = GUI_TAB_OFFSET.getOffset() - maximumDisplayedTabCount;
            GUI_TAB_OFFSET.setOffset(Math.max(0, tabOffset));
            Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.UI_BUTTON_CLICK, 1));
        }
    }
    if (GUI_TAB_OFFSET.getOffset() + maximumDisplayedTabCount < actualJoinedTables.size()) {
        // check for right button click
        int xMin = this.elementXModifiedGet() + this.elementWidthModifiedGet() - 12;
        int xMax = xMin + 8;
        if (mouseX <= xMax && mouseX >= xMin && mouseY <= yMax && mouseY >= yMin) {
            GUI_TAB_OFFSET.setOffset(Math.min(actualJoinedTables.size() - maximumDisplayedTabCount, GUI_TAB_OFFSET.getOffset() + maximumDisplayedTabCount));
            Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.UI_BUTTON_CLICK, 1));
        }
    }
}
Also used : SPacketWorktableTab(com.codetaylor.mc.artisanworktables.modules.worktables.network.SPacketWorktableTab) TileEntityBase(com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntityBase) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

SPacketWorktableTab (com.codetaylor.mc.artisanworktables.modules.worktables.network.SPacketWorktableTab)1 TileEntityBase (com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntityBase)1 BlockPos (net.minecraft.util.math.BlockPos)1