Search in sources :

Example 1 with GenericCableBlock

use of mcjty.xnet.blocks.generic.GenericCableBlock in project XNet by McJty.

the class RenderWorldLastEventHandler method renderCablesInt.

private static void renderCablesInt(RenderWorldLastEvent evt, Minecraft mc) {
    EntityPlayerSP p = mc.player;
    WorldClient world = mc.world;
    double doubleX = p.lastTickPosX + (p.posX - p.lastTickPosX) * evt.getPartialTicks();
    double doubleY = p.lastTickPosY + (p.posY - p.lastTickPosY) * evt.getPartialTicks();
    double doubleZ = p.lastTickPosZ + (p.posZ - p.lastTickPosZ) * evt.getPartialTicks();
    GlStateManager.pushMatrix();
    GlStateManager.color(1.0f, 0, 0);
    GlStateManager.glLineWidth(2);
    GlStateManager.translate(-doubleX, -doubleY, -doubleZ);
    GlStateManager.disableDepth();
    GlStateManager.disableTexture2D();
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder buffer = tessellator.getBuffer();
    buffer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);
    for (int dx = -20; dx <= 20; dx++) {
        for (int dy = -20; dy <= 20; dy++) {
            for (int dz = -20; dz <= 20; dz++) {
                BlockPos c = p.getPosition().add(dx, dy, dz);
                IBlockState state = world.getBlockState(c);
                Block block = state.getBlock();
                if (block instanceof FacadeBlock || block instanceof ConnectorBlock || block instanceof GenericCableBlock) {
                    IExtendedBlockState extendedBlockState;
                    if (state.getBlock() instanceof FacadeBlock) {
                        extendedBlockState = (IExtendedBlockState) ((FacadeBlock) state.getBlock()).getStateInternal(state, world, c);
                    } else {
                        extendedBlockState = (IExtendedBlockState) state.getBlock().getExtendedState(state, world, c);
                    }
                    FacadeBlockId facadeId = extendedBlockState.getValue(GenericCableBlock.FACADEID);
                    if (((!GeneralConfiguration.showNonFacadedCablesWhileSneaking) || (!p.isSneaking())) && facadeId == null && !(block instanceof FacadeBlock)) {
                        continue;
                    }
                    CableColor color = extendedBlockState.getValue(GenericCableBlock.COLOR);
                    float r = 0;
                    float g = 0;
                    float b = 0;
                    switch(color) {
                        case BLUE:
                            r = .4f;
                            g = .4f;
                            b = 1f;
                            break;
                        case RED:
                            r = 1f;
                            g = .4f;
                            b = .4f;
                            break;
                        case YELLOW:
                            r = 1f;
                            g = 1f;
                            b = .4f;
                            break;
                        case GREEN:
                            r = .4f;
                            g = 1f;
                            b = .4f;
                            break;
                        case ROUTING:
                            r = .7f;
                            g = .7f;
                            b = .7f;
                            break;
                    }
                    List<Rect> quads = getQuads(extendedBlockState);
                    for (Rect quad : quads) {
                        renderRect(buffer, quad, c, r, g, b, 0.5f);
                    }
                }
            }
        }
    }
    tessellator.draw();
    GlStateManager.enableTexture2D();
    GlStateManager.popMatrix();
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) IBlockState(net.minecraft.block.state.IBlockState) FacadeBlockId(mcjty.xnet.blocks.facade.FacadeBlockId) GenericCableBlock(mcjty.xnet.blocks.generic.GenericCableBlock) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) WorldClient(net.minecraft.client.multiplayer.WorldClient) FacadeBlock(mcjty.xnet.blocks.facade.FacadeBlock) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) FacadeBlock(mcjty.xnet.blocks.facade.FacadeBlock) GenericCableBlock(mcjty.xnet.blocks.generic.GenericCableBlock) Block(net.minecraft.block.Block) ConnectorBlock(mcjty.xnet.blocks.cables.ConnectorBlock) ItemBlock(net.minecraft.item.ItemBlock) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) CableColor(mcjty.xnet.blocks.generic.CableColor) ConnectorBlock(mcjty.xnet.blocks.cables.ConnectorBlock)

Example 2 with GenericCableBlock

use of mcjty.xnet.blocks.generic.GenericCableBlock in project XNet by McJty.

the class RenderWorldLastEventHandler method renderCables.

private static void renderCables(RenderWorldLastEvent evt) {
    Minecraft mc = Minecraft.getMinecraft();
    EntityPlayerSP p = mc.player;
    ItemStack heldItem = p.getHeldItem(EnumHand.MAIN_HAND);
    if (!heldItem.isEmpty()) {
        if (heldItem.getItem() instanceof ItemBlock) {
            if (((ItemBlock) heldItem.getItem()).getBlock() instanceof GenericCableBlock) {
                renderCablesInt(evt, mc);
            }
        }
    }
}
Also used : GenericCableBlock(mcjty.xnet.blocks.generic.GenericCableBlock) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock) Minecraft(net.minecraft.client.Minecraft)

Aggregations

GenericCableBlock (mcjty.xnet.blocks.generic.GenericCableBlock)2 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)2 ItemBlock (net.minecraft.item.ItemBlock)2 ConnectorBlock (mcjty.xnet.blocks.cables.ConnectorBlock)1 FacadeBlock (mcjty.xnet.blocks.facade.FacadeBlock)1 FacadeBlockId (mcjty.xnet.blocks.facade.FacadeBlockId)1 CableColor (mcjty.xnet.blocks.generic.CableColor)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 Minecraft (net.minecraft.client.Minecraft)1 WorldClient (net.minecraft.client.multiplayer.WorldClient)1 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 ItemStack (net.minecraft.item.ItemStack)1 BlockPos (net.minecraft.util.math.BlockPos)1 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)1