Search in sources :

Example 1 with CapBankClientNetwork

use of crazypants.enderio.powertools.machine.capbank.network.CapBankClientNetwork in project EnderIO by SleepyTrousers.

the class GuiCapBank method updateState.

private boolean updateState() {
    if (!initState) {
        return false;
    }
    if (capBank.getNetwork() == null) {
        network = NULL_NETWORK;
        return true;
    }
    if (network == NULL_NETWORK) {
        network = NullHelper.first((CapBankClientNetwork) capBank.getNetwork(), NULL_NETWORK);
        initialStateCount = network.getStateUpdateCount();
        PacketHandler.INSTANCE.sendToServer(new PacketNetworkStateRequest(capBank));
        return true;
    }
    if (network.getStateUpdateCount() == initialStateCount) {
        PacketHandler.INSTANCE.sendToServer(new PacketNetworkStateRequest(capBank));
        return true;
    }
    if (network.getStateUpdateCount() > initialStateCount) {
        updateFieldsFromState();
        initState = false;
        return true;
    }
    return false;
}
Also used : CapBankClientNetwork(crazypants.enderio.powertools.machine.capbank.network.CapBankClientNetwork) PacketNetworkStateRequest(crazypants.enderio.powertools.machine.capbank.packet.PacketNetworkStateRequest)

Example 2 with CapBankClientNetwork

use of crazypants.enderio.powertools.machine.capbank.network.CapBankClientNetwork in project EnderIO by SleepyTrousers.

the class TileCapBank method getRenderBoundingBox.

@Override
@SideOnly(Side.CLIENT)
@Nonnull
public AxisAlignedBB getRenderBoundingBox() {
    if (!getType().isMultiblock() || !(network instanceof CapBankClientNetwork)) {
        return super.getRenderBoundingBox();
    }
    int xCoord = getPos().getX();
    int yCoord = getPos().getY();
    int zCoord = getPos().getZ();
    int minX = xCoord;
    int minY = yCoord;
    int minZ = zCoord;
    int maxX = minX + 1;
    int maxY = minY + 1;
    int maxZ = minZ + 1;
    if (faceDisplayTypes != null) {
        CapBankClientNetwork cn = (CapBankClientNetwork) network;
        if (faceDisplayTypes.get(EnumFacing.NORTH) == InfoDisplayType.IO) {
            CapBankClientNetwork.IOInfo info = cn.getIODisplayInfo(xCoord, yCoord, zCoord, EnumFacing.NORTH);
            maxX = Math.max(maxX, xCoord + info.width);
            minY = Math.min(minY, yCoord + 1 - info.height);
        }
        if (faceDisplayTypes.get(EnumFacing.SOUTH) == InfoDisplayType.IO) {
            CapBankClientNetwork.IOInfo info = cn.getIODisplayInfo(xCoord, yCoord, zCoord, EnumFacing.SOUTH);
            minX = Math.min(minX, xCoord + 1 - info.width);
            minY = Math.min(minY, yCoord + 1 - info.height);
        }
        if (faceDisplayTypes.get(EnumFacing.EAST) == InfoDisplayType.IO) {
            CapBankClientNetwork.IOInfo info = cn.getIODisplayInfo(xCoord, yCoord, zCoord, EnumFacing.EAST);
            maxZ = Math.max(maxZ, zCoord + info.width);
            minY = Math.min(minY, yCoord + 1 - info.height);
        }
        if (faceDisplayTypes.get(EnumFacing.WEST) == InfoDisplayType.IO) {
            CapBankClientNetwork.IOInfo info = cn.getIODisplayInfo(xCoord, yCoord, zCoord, EnumFacing.WEST);
            minZ = Math.min(minZ, zCoord + 1 - info.width);
            minY = Math.min(minY, yCoord + 1 - info.height);
        }
    }
    return new AxisAlignedBB(minX, minY, minZ, maxX, maxY, maxZ);
}
Also used : CapBankClientNetwork(crazypants.enderio.powertools.machine.capbank.network.CapBankClientNetwork) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Nonnull(javax.annotation.Nonnull) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with CapBankClientNetwork

use of crazypants.enderio.powertools.machine.capbank.network.CapBankClientNetwork in project EnderIO by SleepyTrousers.

the class FillGaugeBakery method calculateFillLevel.

private void calculateFillLevel() {
    if (world != null && pos != null) {
        TileEntity tileEntity = BlockEnder.getAnyTileEntitySafe(world, pos);
        if (!(tileEntity instanceof TileCapBank)) {
            localFillLevel = 0;
            return;
        }
        ICapBankNetwork network = ((TileCapBank) tileEntity).getNetwork();
        if (!(network instanceof CapBankClientNetwork)) {
            localFillLevel = 0;
            return;
        }
        ((CapBankClientNetwork) network).requestPowerUpdate(((TileCapBank) tileEntity), 20);
        double ratio = Math.min(((CapBankClientNetwork) network).getEnergyStoredRatio(), 1);
        localFillLevel = Math.max(0, Math.min(ratio * (height * 16 - 6) - myOffset * 16, 13) + 3);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileCapBank(crazypants.enderio.powertools.machine.capbank.TileCapBank) CapBankClientNetwork(crazypants.enderio.powertools.machine.capbank.network.CapBankClientNetwork) ICapBankNetwork(crazypants.enderio.powertools.machine.capbank.network.ICapBankNetwork)

Example 4 with CapBankClientNetwork

use of crazypants.enderio.powertools.machine.capbank.network.CapBankClientNetwork in project EnderIO by SleepyTrousers.

the class IoDisplay method render.

@Override
public void render(@Nonnull TileCapBank cb, @Nonnull EnumFacing dir, float partialTick) {
    if (dir.getFrontOffsetY() != 0) {
        return;
    }
    CapBankClientNetwork nw = (CapBankClientNetwork) cb.getNetwork();
    if (nw == null) {
        return;
    }
    CapBankClientNetwork.IOInfo info = nw.getIODisplayInfo(cb.getPos(), dir);
    if (info.isInside()) {
        return;
    }
    int i = cb.getWorld().getCombinedLight(cb.getPos().offset(dir), 0);
    int j = i % 65536;
    int k = i / 65536;
    OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, j / 1.0F, k / 1.0F);
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    GlStateManager.enablePolygonOffset();
    GlStateManager.doPolygonOffset(-1.0f, -1.0f);
    boolean drawBackground = true;
    if (drawBackground) {
        RenderUtil.bindBlockTexture();
        float scale = 0.85f;
        float offset = (1 - scale) / 2;
        TextureAtlasSprite icon = BlockCapBank.getInfoPanelIcon();
        float minU = icon.getMinU();
        float maxU = icon.getMaxU();
        float minV = icon.getMinV();
        float maxV = icon.getMaxV();
        List<Vertex> vertices = new ArrayList<Vertex>();
        switch(dir) {
            case NORTH:
                {
                    float y0 = offset - (info.height - 1);
                    float y1 = 1 - offset;
                    float x0 = offset;
                    float x1 = info.width - offset;
                    float z0 = 0;
                    vertices.add(new Vertex(x1, y0, z0, minU, minV, 0f, 0f, -1f));
                    vertices.add(new Vertex(x0, y0, z0, maxU, minV, 0f, 0f, -1f));
                    vertices.add(new Vertex(x0, y1, z0, maxU, maxV, 0f, 0f, -1f));
                    vertices.add(new Vertex(x1, y1, z0, minU, maxV, 0f, 0f, -1f));
                    break;
                }
            case SOUTH:
                {
                    float y0 = offset - (info.height - 1);
                    float y1 = 1 - offset;
                    float x0 = offset - (info.width - 1);
                    float x1 = 1 - offset;
                    float z1 = 1;
                    vertices.add(new Vertex(x0, y0, z1, maxU, minV, 0f, 0f, 1f));
                    vertices.add(new Vertex(x1, y0, z1, minU, minV, 0f, 0f, 1f));
                    vertices.add(new Vertex(x1, y1, z1, minU, maxV, 0f, 0f, 1f));
                    vertices.add(new Vertex(x0, y1, z1, maxU, maxV, 0f, 0f, 1f));
                    break;
                }
            case EAST:
                {
                    float y0 = offset - (info.height - 1);
                    float y1 = 1 - offset;
                    float z0 = offset;
                    float z1 = info.width - offset;
                    float x1 = 1;
                    vertices.add(new Vertex(x1, y1, z0, maxU, maxV, 1f, 0f, 0f));
                    vertices.add(new Vertex(x1, y1, z1, minU, maxV, 1f, 0f, 0f));
                    vertices.add(new Vertex(x1, y0, z1, minU, minV, 1f, 0f, 0f));
                    vertices.add(new Vertex(x1, y0, z0, maxU, minV, 1f, 0f, 0f));
                    break;
                }
            case WEST:
                {
                    float y0 = offset - (info.height - 1);
                    float y1 = 1 - offset;
                    float z0 = offset - (info.width - 1);
                    float z1 = 1 - offset;
                    float x0 = 0;
                    vertices.add(new Vertex(x0, y0, z0, maxU, minV, -1f, 0f, 0f));
                    vertices.add(new Vertex(x0, y0, z1, minU, minV, -1f, 0f, 0f));
                    vertices.add(new Vertex(x0, y1, z1, minU, maxV, -1f, 0f, 0f));
                    vertices.add(new Vertex(x0, y1, z0, maxU, maxV, -1f, 0f, 0f));
                    break;
                }
            default:
                throw new AssertionError();
        }
        GlStateManager.color(1, 1, 1);
        RenderUtil.addVerticesToTessellator(vertices, DefaultVertexFormats.POSITION_TEX_NORMAL, true);
        Tessellator.getInstance().draw();
    }
    nw.requestPowerUpdate(cb, 20);
    HeadingText heading1 = HeadingText.STABLE;
    HeadingText heading2 = null;
    String text1;
    String text2 = "";
    FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
    float size = 0.15f * Math.min(info.width, info.height);
    float scale = size / fr.FONT_HEIGHT;
    float offset;
    if (info.height * 3 >= info.width * 4) {
        heading1 = HeadingText.INPUT;
        heading2 = HeadingText.OUTPUT;
        text1 = getChangeText(nw.getAverageInputPerTick(), fr);
        text2 = getChangeText(nw.getAverageOutputPerTick(), fr);
        offset = -size * 2.5f;
    } else {
        int change = Math.round(nw.getAverageChangePerTick());
        if (change > 0) {
            heading1 = HeadingText.GAIN;
        } else if (change < 0) {
            heading1 = HeadingText.LOSS;
        }
        text1 = getChangeText(change, fr);
        offset = -size;
    }
    EnumFacing right = dir.rotateAround(EnumFacing.Axis.Y);
    GlStateManager.pushMatrix();
    GlStateManager.translate((dir.getFrontOffsetX() * 1.02f) / 2 + 0.5f + right.getFrontOffsetX() * (info.width - 1) * 0.5f, 1 + size * 0.5f - info.height * 0.5f, (dir.getFrontOffsetZ() * 1.02f) / 2 + 0.5f + right.getFrontOffsetZ() * (info.width - 1) * 0.5f);
    GlStateManager.rotate(-180, 1, 0, 0);
    if (dir == EnumFacing.NORTH) {
        GlStateManager.rotate(-180, 0, 1, 0);
    } else if (dir == EnumFacing.EAST) {
        GlStateManager.rotate(-90, 0, 1, 0);
    } else if (dir == EnumFacing.WEST) {
        GlStateManager.rotate(90, 0, 1, 0);
    }
    GlStateManager.enableLighting();
    GlStateManager.enableBlend();
    GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
    offset = drawText(heading1, text1, offset, scale, size, fr);
    if (heading2 != null) {
        drawText(heading2, text2, offset, scale, size, fr);
    }
    RenderUtil.bindBlockTexture();
    GlStateManager.disableBlend();
    GlStateManager.disablePolygonOffset();
    GlStateManager.popMatrix();
}
Also used : CapBankClientNetwork(crazypants.enderio.powertools.machine.capbank.network.CapBankClientNetwork) Vertex(com.enderio.core.common.vecmath.Vertex) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) FontRenderer(net.minecraft.client.gui.FontRenderer)

Aggregations

CapBankClientNetwork (crazypants.enderio.powertools.machine.capbank.network.CapBankClientNetwork)4 Vertex (com.enderio.core.common.vecmath.Vertex)1 TileCapBank (crazypants.enderio.powertools.machine.capbank.TileCapBank)1 ICapBankNetwork (crazypants.enderio.powertools.machine.capbank.network.ICapBankNetwork)1 PacketNetworkStateRequest (crazypants.enderio.powertools.machine.capbank.packet.PacketNetworkStateRequest)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1 FontRenderer (net.minecraft.client.gui.FontRenderer)1 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1