Search in sources :

Example 1 with IItemCustomPipeRender

use of buildcraft.api.items.IItemCustomPipeRender in project BuildCraft by BuildCraft.

the class PipeTransportRendererItems method doRenderItem.

public static void doRenderItem(TravelingItem travellingItem, double x, double y, double z, float light, EnumDyeColor color) {
    if (travellingItem == null || travellingItem.getItemStack() == null) {
        return;
    }
    float renderScale = 0.9f;
    ItemStack itemstack = travellingItem.getItemStack();
    int val = (travellingItem.id * 191) ^ 0x8d35;
    x += 0.004f * (4 - ((val % 9)));
    y += 0.004f * (4 - ((val / 9) % 9));
    z += 0.004f * (4 - ((val / 81) % 9));
    GL11.glPushMatrix();
    GL11.glTranslatef((float) x, (float) y + 0.05f, (float) z);
    GL11.glPushMatrix();
    GlStateManager.color(1, 1, 1, 1);
    if (!travellingItem.hasDisplayList) {
        travellingItem.displayList = GLAllocation.generateDisplayLists(1);
        travellingItem.hasDisplayList = true;
        GL11.glNewList(travellingItem.displayList, GL11.GL_COMPILE);
        if (itemstack.getItem() instanceof IItemCustomPipeRender) {
            IItemCustomPipeRender render = (IItemCustomPipeRender) itemstack.getItem();
            float itemScale = render.getPipeRenderScale(itemstack);
            GL11.glScalef(renderScale * itemScale, renderScale * itemScale, renderScale * itemScale);
            itemScale = 1 / itemScale;
            if (!render.renderItemInPipe(itemstack, x, y, z)) {
                dummyEntityItem.setEntityItemStack(itemstack);
                customRenderItem.doRender(dummyEntityItem, 0, 0, 0, 0, 0);
            }
            GL11.glScalef(itemScale, itemScale, itemScale);
        } else {
            GL11.glScalef(renderScale, renderScale, renderScale);
            dummyEntityItem.setEntityItemStack(itemstack);
            customRenderItem.doRender(dummyEntityItem, 0, 0, 0, 0, 0);
        }
        GL11.glEndList();
    }
    GL11.glCallList(travellingItem.displayList);
    // Some items don't reset their colour properly, so lets just kick both the state manager AND OpenGL to the same
    // state
    GL11.glColor4f(1, 1, 1, 1);
    GlStateManager.color(1, 1, 1, 1);
    GL11.glPopMatrix();
    if (color != null) {
        // The box around an item that decides what colour lenses it can go through
        Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
        EntityResizableCuboid erc = new EntityResizableCuboid(null);
        erc.texture = BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.ItemBox.ordinal());
        erc.xSize = 1;
        erc.ySize = 1;
        erc.zSize = 1;
        GL11.glPushMatrix();
        renderScale /= 2f;
        GL11.glTranslatef(0, 0.2f, 0);
        GL11.glScalef(renderScale, renderScale, renderScale);
        GL11.glTranslatef(-0.5f, -0.5f, -0.5f);
        RenderUtil.setGLColorFromInt(ColorUtils.getLightHex(color));
        RenderResizableCuboid.INSTANCE.renderCube(erc);
        GlStateManager.color(1, 1, 1, 1);
        GL11.glPopMatrix();
    }
    GL11.glPopMatrix();
}
Also used : IItemCustomPipeRender(buildcraft.api.items.IItemCustomPipeRender) EntityResizableCuboid(buildcraft.core.lib.EntityResizableCuboid) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IItemCustomPipeRender (buildcraft.api.items.IItemCustomPipeRender)1 EntityResizableCuboid (buildcraft.core.lib.EntityResizableCuboid)1 ItemStack (net.minecraft.item.ItemStack)1