Search in sources :

Example 1 with TileEntityBase

use of com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntityBase in project artisan-worktables by codetaylor.

the class BlockBase method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (worldIn.isRemote) {
        GuiElementTabs.RECALCULATE_TAB_OFFSETS = true;
        return true;
    }
    TileEntity tileEntity = worldIn.getTileEntity(pos);
    if (tileEntity instanceof TileEntityBase) {
        FluidTank tank = ((TileEntityBase) tileEntity).getTank();
        if (FluidHelper.drainWaterFromBottle(playerIn, tank) || FluidHelper.drainWaterIntoBottle(playerIn, tank) || FluidUtil.interactWithFluidHandler(playerIn, hand, tank)) {
            return true;
        }
        playerIn.openGui(ModuleWorktables.MOD_INSTANCE, 1, worldIn, pos.getX(), pos.getY(), pos.getZ());
        return true;
    }
    return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidTank(net.minecraftforge.fluids.FluidTank) TileEntityBase(com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntityBase)

Example 2 with TileEntityBase

use of com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntityBase 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)

Example 3 with TileEntityBase

use of com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntityBase in project artisan-worktables by codetaylor.

the class GuiElementTabs method drawBackgroundLayer.

@Override
public void drawBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    int x = this.elementXModifiedGet();
    int y = this.elementYModifiedGet();
    int tabX = x + TAB_LEFT_OFFSET;
    int tabY = y;
    List<TileEntityBase> actualJoinedTables = this.worktable.getJoinedTables(new ArrayList<>(), Minecraft.getMinecraft().player);
    List<TileEntityBase> joinedTables = this.getJoinedTableOffsetView(actualJoinedTables, GUI_TAB_OFFSET.getOffset(), this.worktable.getMaximumDisplayedTabCount());
    this.textureBind(ReferenceTexture.RESOURCE_LOCATION_GUI_ELEMENTS);
    if (GUI_TAB_OFFSET.getOffset() > 0) {
        // draw left button
        Gui.drawModalRectWithCustomSizedTexture(this.elementXModifiedGet() + TAB_LEFT_OFFSET + TAB_ITEM_HORIZONTAL_OFFSET - 18, tabY, TAB_WIDTH, this.worktable.getWorktableGuiTabTextureYOffset() * TAB_HEIGHT, 8, TAB_HEIGHT, ReferenceTexture.TEXTURE_GUI_ELEMENTS_WIDTH, ReferenceTexture.TEXTURE_GUI_ELEMENTS_HEIGHT);
    }
    int maximumDisplayedTabCount = this.worktable.getMaximumDisplayedTabCount();
    if (GUI_TAB_OFFSET.getOffset() + maximumDisplayedTabCount < actualJoinedTables.size()) {
        // draw right button
        Gui.drawModalRectWithCustomSizedTexture(this.elementXModifiedGet() + this.elementWidthModifiedGet() - 12, tabY, TAB_WIDTH + 8, this.worktable.getWorktableGuiTabTextureYOffset() * TAB_HEIGHT, 8, TAB_HEIGHT, ReferenceTexture.TEXTURE_GUI_ELEMENTS_WIDTH, ReferenceTexture.TEXTURE_GUI_ELEMENTS_HEIGHT);
    }
    for (TileEntityBase joinedTable : joinedTables) {
        int textureY = joinedTable.getWorktableGuiTabTextureYOffset() * TAB_HEIGHT;
        if (joinedTable == this.worktable) {
            // this.drawTexturedModalRect(tabX, tabY + TAB_CURRENT_OFFSET, 0, textureY, TAB_WIDTH, TAB_HEIGHT);
            Gui.drawModalRectWithCustomSizedTexture(tabX, tabY + TAB_CURRENT_OFFSET, 0, textureY, TAB_WIDTH, TAB_HEIGHT, ReferenceTexture.TEXTURE_GUI_ELEMENTS_WIDTH, ReferenceTexture.TEXTURE_GUI_ELEMENTS_HEIGHT);
        } else {
            // this.drawTexturedModalRect(tabX, tabY, 0, textureY, TAB_WIDTH, 21);
            Gui.drawModalRectWithCustomSizedTexture(tabX, tabY, 0, textureY, TAB_WIDTH, TAB_HEIGHT, ReferenceTexture.TEXTURE_GUI_ELEMENTS_WIDTH, ReferenceTexture.TEXTURE_GUI_ELEMENTS_HEIGHT);
        }
        tabX += TAB_WIDTH + TAB_SPACING;
    }
    // draw tab icons
    tabX = x + TAB_LEFT_OFFSET + TAB_ITEM_HORIZONTAL_OFFSET;
    tabY = y + TAB_ITEM_VERTICAL_OFFSET;
    RenderHelper.enableGUIStandardItemLighting();
    for (TileEntityBase joinedTable : joinedTables) {
        IBlockState blockState = joinedTable.getWorld().getBlockState(joinedTable.getPos());
        blockState = blockState.getBlock().getActualState(blockState, this.worktable.getWorld(), joinedTable.getPos());
        ItemStack itemStack = joinedTable.getItemStackForTabDisplay(blockState);
        if (joinedTable == this.worktable) {
            this.guiBase.getItemRender().renderItemAndEffectIntoGUI(itemStack, tabX, tabY + TAB_CURRENT_OFFSET);
        } else {
            this.guiBase.getItemRender().renderItemAndEffectIntoGUI(itemStack, tabX, tabY);
        }
        tabX += TAB_WIDTH + TAB_SPACING;
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) TileEntityBase(com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntityBase) ItemStack(net.minecraft.item.ItemStack)

Example 4 with TileEntityBase

use of com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntityBase in project artisan-worktables by codetaylor.

the class GuiElementTabs method calculateInitialTabOffset.

/**
 * Sets the initial tab offset when the gui is opened.
 *
 * @param worktableBase the worktable
 * @param guiTabOffset  the offset
 */
private void calculateInitialTabOffset(TileEntityBase worktableBase, GuiTabOffset guiTabOffset) {
    int maximumDisplayedTabCount = worktableBase.getMaximumDisplayedTabCount();
    guiTabOffset.setOffset(0);
    List<TileEntityBase> actualJoinedTables = worktableBase.getJoinedTables(new ArrayList<>(), Minecraft.getMinecraft().player);
    boolean tabInView = false;
    while (!tabInView && !actualJoinedTables.isEmpty()) {
        List<TileEntityBase> joinedTables = this.getJoinedTableOffsetView(actualJoinedTables, guiTabOffset.getOffset(), worktableBase.getMaximumDisplayedTabCount());
        for (TileEntityBase joinedTable : joinedTables) {
            if (joinedTable == worktableBase) {
                tabInView = true;
                break;
            }
        }
        if (!tabInView) {
            guiTabOffset.setOffset(Math.min(actualJoinedTables.size() - maximumDisplayedTabCount, guiTabOffset.getOffset() + maximumDisplayedTabCount));
        }
    }
}
Also used : TileEntityBase(com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntityBase)

Example 5 with TileEntityBase

use of com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntityBase in project artisan-worktables by codetaylor.

the class CPacketWorktableFluidUpdate method onMessage.

@Override
public IMessage onMessage(CPacketWorktableFluidUpdate message, MessageContext ctx, TileEntity tileEntity) {
    if (tileEntity != null) {
        TileEntityBase tileEntityBase = (TileEntityBase) tileEntity;
        tileEntityBase.getTank().setFluid(message.fluidTank.getFluid());
    // We don't force a container recipe update here because it's triggered
    // when the tank's onContentsChanged() method is called.
    }
    return null;
}
Also used : TileEntityBase(com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntityBase) CPacketTileEntityBase(com.codetaylor.mc.athenaeum.spi.packet.CPacketTileEntityBase)

Aggregations

TileEntityBase (com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntityBase)7 SPacketTileEntityBase (com.codetaylor.mc.athenaeum.spi.packet.SPacketTileEntityBase)2 ItemStack (net.minecraft.item.ItemStack)2 FluidTank (net.minecraftforge.fluids.FluidTank)2 SPacketWorktableTab (com.codetaylor.mc.artisanworktables.modules.worktables.network.SPacketWorktableTab)1 CPacketTileEntityBase (com.codetaylor.mc.athenaeum.spi.packet.CPacketTileEntityBase)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 NetHandlerPlayServer (net.minecraft.network.NetHandlerPlayServer)1 SPacketSetSlot (net.minecraft.network.play.server.SPacketSetSlot)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1