package org.cyclops.integrateddynamics.client.render.valuetype;

import com.google.common.base.Optional;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import org.cyclops.cyclopscore.helper.Helpers;
import org.cyclops.cyclopscore.helper.RenderHelpers;
import org.cyclops.integrateddynamics.api.client.render.valuetype.IValueTypeWorldRenderer;
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue;
import org.cyclops.integrateddynamics.api.part.IPartContainer;
import org.cyclops.integrateddynamics.api.part.IPartType;
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueObjectTypeItemStack;

/**
 * A value type world renderer for items.
 * @author rubensworks
 */
public class ItemValueTypeWorldRenderer implements IValueTypeWorldRenderer {

    @Override
    public void renderValue(IPartContainer partContainer, double x, double y, double z, float partialTick,
                            int destroyStage, EnumFacing direction, IPartType partType, IValue value,
                            TileEntityRendererDispatcher rendererDispatcher, float alpha) {
        Optional<ItemStack> itemStackOptional = ((ValueObjectTypeItemStack.ValueItemStack) value).getRawValue();
        if(itemStackOptional.isPresent()) {
            // ItemStack
            renderItemStack(itemStackOptional.get(), alpha);

            // Stack size
            GlStateManager.pushMatrix();
            GlStateManager.translate(7F, 8.5F, 0.1F);
            String stackSize = String.valueOf(itemStackOptional.get().stackSize);
            float scale = 1F / ((float) stackSize.length() + 1F);
            GlStateManager.scale(scale, scale, 1F);
            rendererDispatcher.getFontRenderer().drawString(stackSize,
                    0, 0, Helpers.RGBAToInt(200, 200, 200, (int) (alpha * 255F)));
            GlStateManager.popMatrix();
        }
    }

    public static void renderItemStack(ItemStack itemStack, float alpha) {
        // ItemStack
        RenderHelper.enableGUIStandardItemLighting();
        GlStateManager.pushMatrix();
        GlStateManager.translate(3F, 3F, 0);
        GlStateManager.scale(0.4, 0.4, 0.01);
        RenderHelpers.renderItem(itemStack, ItemCameraTransforms.TransformType.NONE);
        GlStateManager.popMatrix();
        RenderHelper.disableStandardItemLighting();
    }
}

@@ -98,16 +98,55 @@
 tional;%0A
+import net.minecraft.client.Minecraft;%0A
 import n
@@ -282,40 +282,18 @@
 rer.
-block.model.ItemCameraTransforms
+RenderItem
 ;%0Aim
@@ -494,61 +494,8 @@
 rs;%0A
-import org.cyclops.cyclopscore.helper.RenderHelpers;%0A
 impo
@@ -1684,17 +1684,17 @@
 8.5F, 0.
-1
+3
 F);%0A    
@@ -2324,17 +2324,17 @@
 ate(
-3F, 3F, 0
+0, 0, -1F
 );%0A 
@@ -2367,14 +2367,16 @@
 e(0.
-4
+78
 , 0.
-4
+78
 , 0.
@@ -2380,16 +2380,17 @@
  0.01);%0A
+%0A
         
@@ -2399,80 +2399,872 @@
 nder
-Helpers.renderItem(itemStack, ItemCameraTransforms.TransformType.NONE
+Item renderItem = Minecraft.getMinecraft().getRenderItem();%0A        GlStateManager.pushMatrix();%0A        GlStateManager.rotate(40f, 0.0F, 1.0F, 0.0F);%0A        GlStateManager.rotate(95F, 1.0F, 0.0F, 0.0F);%0A        RenderHelper.enableGUIStandardItemLighting();%0A        GlStateManager.popMatrix();%0A%0A        // Inspired by: https://github.com/jaquadro/StorageDrawers/blob/1.10/src/com/jaquadro/minecraft/storagedrawers/client/renderer/TileEntityDrawersRenderer.java#L180%0A%0A        GlStateManager.enablePolygonOffset();%0A        GlStateManager.doPolygonOffset(-1, -1);%0A%0A        GlStateManager.pushAttrib();%0A        GlStateManager.enableRescaleNormal();%0A        GlStateManager.popAttrib();%0A%0A        renderItem.renderItemIntoGUI(itemStack, 0, 0);%0A        GlStateManager.disableBlend();%0A        GlStateManager.enableAlpha();%0A%0A        GlStateManager.disablePolygonOffset(
 );%0A
+%0A
     

Improve block and item value type rendering in world