Search in sources :

Example 1 with ConduitDisplayMode

use of crazypants.enderio.base.conduit.ConduitDisplayMode in project EnderIO by SleepyTrousers.

the class ToolTickHandler method changeDisplayMode.

private void changeDisplayMode(@Nonnull ItemStack stack, @Nonnull EntityPlayer player, int dWheel) {
    if (!((IConduitControl) stack.getItem()).showOverlay(stack, player)) {
        return;
    }
    ConduitDisplayMode mode = ConduitDisplayMode.getDisplayMode(stack);
    mode = dWheel < 0 ? mode.next() : mode.previous();
    ConduitDisplayMode.setDisplayMode(stack, mode);
    PacketHandler.INSTANCE.sendToServer(new YetaWrenchPacketProcessor(player.inventory.currentItem, mode));
}
Also used : ConduitDisplayMode(crazypants.enderio.base.conduit.ConduitDisplayMode)

Example 2 with ConduitDisplayMode

use of crazypants.enderio.base.conduit.ConduitDisplayMode in project EnderIO by SleepyTrousers.

the class YetaWrenchOverlayRenderer method doRenderOverlay.

private void doRenderOverlay(@Nonnull RenderGameOverlayEvent event, @Nonnull ItemStack equippedWrench) {
    ConduitDisplayMode mode = ConduitDisplayMode.getDisplayMode(equippedWrench);
    if (mode != cachedMode) {
        cachedMode = mode;
        displayTickCount = 20;
        lastTick = ClientHandler.getTicksElapsed();
    }
    ScaledResolution res = event.getResolution();
    int modeCount = ConduitDisplayMode.registrySize();
    Iterable<ConduitDisplayMode> renderable = ConduitDisplayMode.getRenderableModes();
    switch(PersonalConfig.yetaOverlayMode.get()) {
        case 0:
            if (displayTickCount > 0) {
                if (lastTick < ClientHandler.getTicksElapsed()) {
                    lastTick++;
                    displayTickCount--;
                }
                int x = res.getScaledWidth() / 2 - 8;
                int y = res.getScaledHeight() / 2 - 24;
                IWidgetIcon widget = mode.getWidgetSelected();
                RenderUtil.bindTexture(widget.getMap().getTexture());
                widget.getMap().render(widget, x, y, true);
                int size = 12;
                widget = mode.previous().getWidgetSelected();
                RenderUtil.bindTexture(widget.getMap().getTexture());
                widget.getMap().render(widget, x - 18 + (16 - size), y + (16 - size), size, size, 0, true);
                widget = mode.next().getWidgetSelected();
                RenderUtil.bindTexture(widget.getMap().getTexture());
                widget.getMap().render(widget, x + 18, y + (16 - size), size, size, 0, true);
            } else {
                int x = res.getScaledWidth() - 20;
                int y = res.getScaledHeight() - 20;
                IWidgetIcon widget = mode.getWidgetSelected();
                RenderUtil.bindTexture(widget.getMap().getTexture());
                widget.getMap().render(widget, x, y, true);
            }
            break;
        case 1:
            int size = 16;
            int padding = 2;
            int inset = (int) (size / 1.5);
            int offsetX = res.getScaledWidth() - inset - 1;
            int offsetY = res.getScaledHeight() - modeCount * (size + padding) - padding;
            inset = size - inset;
            int x = offsetX + 2;
            int y = offsetY - (padding * 2);
            int height = (modeCount * (size + padding)) + (padding * 3);
            // FIXME
            GL11.glDisable(GL11.GL_TEXTURE_2D);
            GL11.glShadeModel(GL11.GL_SMOOTH);
            VertexFormat vf = DefaultVertexFormats.POSITION_COLOR;
            Tessellator tess = Tessellator.getInstance();
            BufferBuilder wr = tess.getBuffer();
            wr.begin(GL11.GL_QUADS, vf);
            wr.pos(x, y, -5).color(0, 0, 0, 0.2f).endVertex();
            ;
            wr.pos(x, y + height, -5).color(0, 0, 0, 0.2f).endVertex();
            ;
            Vector4f color = new Vector4f(0, 0, 0, 1);
            wr.pos(x + size, y + height, -5).color(color.x, color.y, color.z, color.w).endVertex();
            wr.pos(x + size, y, -5).color(color.x, color.y, color.z, color.w).endVertex();
            tess.draw();
            GlStateManager.color(1, 1, 1);
            GL11.glShadeModel(GL11.GL_FLAT);
            y += padding * 2;
            x -= 2;
            if (mode == ConduitDisplayMode.ALL) {
                x -= inset;
            }
            GL11.glEnable(GL11.GL_TEXTURE_2D);
            for (ConduitDisplayMode toRender : renderable) {
                IWidgetIcon widget = mode == ConduitDisplayMode.ALL ? toRender.getWidgetSelected() : toRender.getWidgetUnselected();
                RenderUtil.bindTexture(widget.getMap().getTexture());
                if (toRender == mode) {
                    widget = toRender.getWidgetSelected();
                    widget.getMap().render(widget, x - inset, y, true);
                } else {
                    widget.getMap().render(widget, x, y, true);
                }
                y += size + padding;
            }
            break;
        case 2:
            offsetX = res.getScaledWidth() - (modeCount * 8) - 16;
            y = res.getScaledHeight() - 40;
            x = offsetX;
            if (modeCount % 2 == 1) {
                x += 8;
            }
            int count = 0;
            for (ConduitDisplayMode toRender : renderable) {
                IWidgetIcon widget = mode == ConduitDisplayMode.ALL || toRender == mode ? toRender.getWidgetSelected() : toRender.getWidgetUnselected();
                RenderUtil.bindTexture(widget.getMap().getTexture());
                widget.getMap().render(widget, x, y, true);
                x += 16;
                if (count == modeCount / 2 - 1) {
                    x = offsetX;
                    y += 16;
                }
                count++;
            }
    }
}
Also used : ConduitDisplayMode(crazypants.enderio.base.conduit.ConduitDisplayMode) ScaledResolution(net.minecraft.client.gui.ScaledResolution) IWidgetIcon(com.enderio.core.api.client.render.IWidgetIcon) Tessellator(net.minecraft.client.renderer.Tessellator) Vector4f(com.enderio.core.common.vecmath.Vector4f) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat)

Example 3 with ConduitDisplayMode

use of crazypants.enderio.base.conduit.ConduitDisplayMode in project EnderIO by SleepyTrousers.

the class ToolTickHandler method changeDisplayMode.

private static void changeDisplayMode(@Nonnull ItemStack stack, @Nonnull EntityPlayer player, int dWheel) {
    if (!((IConduitControl) stack.getItem()).showOverlay(stack, player)) {
        return;
    }
    ConduitDisplayMode mode = ConduitDisplayMode.getDisplayMode(stack);
    mode = dWheel < 0 ? mode.next() : mode.previous();
    ConduitDisplayMode.setDisplayMode(stack, mode);
    PacketHandler.INSTANCE.sendToServer(new YetaWrenchPacketProcessor(player.inventory.currentItem, mode));
}
Also used : ConduitDisplayMode(crazypants.enderio.base.conduit.ConduitDisplayMode) YetaWrenchPacketProcessor(crazypants.enderio.base.item.yetawrench.YetaWrenchPacketProcessor)

Example 4 with ConduitDisplayMode

use of crazypants.enderio.base.conduit.ConduitDisplayMode in project EnderIO by SleepyTrousers.

the class ItemYetaWrench method onItemRightClick.

@Override
@Nonnull
public ActionResult<ItemStack> onItemRightClick(@Nonnull World world, @Nonnull EntityPlayer player, @Nonnull EnumHand hand) {
    ItemStack equipped = player.getHeldItem(hand);
    if (!PersonalConfig.yetaUseSneakRightClick.get() || !player.isSneaking()) {
        return new ActionResult<ItemStack>(EnumActionResult.PASS, equipped);
    }
    ConduitDisplayMode curMode = ConduitDisplayMode.getDisplayMode(equipped);
    ConduitDisplayMode newMode = curMode.next();
    ConduitDisplayMode.setDisplayMode(equipped, newMode);
    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, equipped);
}
Also used : ConduitDisplayMode(crazypants.enderio.base.conduit.ConduitDisplayMode) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 5 with ConduitDisplayMode

use of crazypants.enderio.base.conduit.ConduitDisplayMode in project EnderIO by SleepyTrousers.

the class BlockConduitBundle method doRayTraceAll.

@Nonnull
protected NNList<RaytraceResult> doRayTraceAll(@Nonnull IBlockState bs, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Vec3d origin, @Nonnull Vec3d direction, EntityPlayer player) {
    TileEntity te = world.getTileEntity(pos);
    if (!(te instanceof IConduitBundle)) {
        return NNList.emptyList();
    }
    IConduitBundle bundle = (IConduitBundle) te;
    NNList<RaytraceResult> hits = new NNList<RaytraceResult>();
    if (YetaUtil.isSolidFacadeRendered(bundle, player)) {
        setBlockBounds(0, 0, 0, 1, 1, 1);
        RayTraceResult hitPos = super.collisionRayTrace(bs, world, pos, origin, direction);
        if (hitPos != null) {
            hits.add(new RaytraceResult(new CollidableComponent(null, BoundingBox.UNIT_CUBE, hitPos.sideHit, null), hitPos));
        }
    } else {
        ConduitDisplayMode mode = YetaUtil.getDisplayMode(player);
        for (CollidableComponent component : new ArrayList<CollidableComponent>(bundle.getCollidableComponents())) {
            if (mode.isAll() || component.conduitType == null || YetaUtil.renderConduit(player, component.conduitType)) {
                setBlockBounds(component.bound.minX, component.bound.minY, component.bound.minZ, component.bound.maxX, component.bound.maxY, component.bound.maxZ);
                RayTraceResult hitPos = super.collisionRayTrace(bs, world, pos, origin, direction);
                if (hitPos != null) {
                    hits.add(new RaytraceResult(component, hitPos));
                }
            }
        }
        // safety to prevent unbreakable empty bundles in case of a bug
        if (bundle.getConduits().isEmpty() && !YetaUtil.isFacadeHidden(bundle, player)) {
            setBlockBounds(0, 0, 0, 1, 1, 1);
            RayTraceResult hitPos = super.collisionRayTrace(bs, world, pos, origin, direction);
            if (hitPos != null) {
                hits.add(new RaytraceResult(null, hitPos));
            }
        }
    }
    setBlockBounds(0, 0, 0, 1, 1, 1);
    return hits;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ConduitDisplayMode(crazypants.enderio.base.conduit.ConduitDisplayMode) CollidableComponent(crazypants.enderio.base.conduit.geom.CollidableComponent) NNList(com.enderio.core.common.util.NNList) RayTraceResult(net.minecraft.util.math.RayTraceResult) ArrayList(java.util.ArrayList) IConduitBundle(crazypants.enderio.base.conduit.IConduitBundle) RaytraceResult(crazypants.enderio.base.conduit.RaytraceResult) Nonnull(javax.annotation.Nonnull)

Aggregations

ConduitDisplayMode (crazypants.enderio.base.conduit.ConduitDisplayMode)6 Nonnull (javax.annotation.Nonnull)2 IWidgetIcon (com.enderio.core.api.client.render.IWidgetIcon)1 NNList (com.enderio.core.common.util.NNList)1 Vector4f (com.enderio.core.common.vecmath.Vector4f)1 IConduitBundle (crazypants.enderio.base.conduit.IConduitBundle)1 RaytraceResult (crazypants.enderio.base.conduit.RaytraceResult)1 CollidableComponent (crazypants.enderio.base.conduit.geom.CollidableComponent)1 YetaWrenchPacketProcessor (crazypants.enderio.base.item.yetawrench.YetaWrenchPacketProcessor)1 ArrayList (java.util.ArrayList)1 ScaledResolution (net.minecraft.client.gui.ScaledResolution)1 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 VertexFormat (net.minecraft.client.renderer.vertex.VertexFormat)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 ActionResult (net.minecraft.util.ActionResult)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1