Advertisement
Guest User

LogisticsRenderPipe.java

a guest
Jun 26th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 25.87 KB | None | 0 0
  1. package logisticspipes.renderer;
  2.  
  3. import java.util.*;
  4.  
  5. import logisticspipes.LPConstants;
  6. import logisticspipes.LogisticsPipes;
  7. import logisticspipes.config.PlayerConfig;
  8. import logisticspipes.pipes.basic.CoreRoutedPipe;
  9. import logisticspipes.pipes.basic.CoreUnroutedPipe;
  10. import logisticspipes.pipes.basic.LogisticsTileGenericPipe;
  11. import logisticspipes.pipes.signs.IPipeSign;
  12. import logisticspipes.pipes.signs.IPipeSignData;
  13. import logisticspipes.proxy.SimpleServiceLocator;
  14. import logisticspipes.proxy.buildcraft.subproxies.IBCRenderTESR;
  15. import logisticspipes.renderer.CustomBlockRenderer.RenderInfo;
  16. import logisticspipes.renderer.newpipe.GLRenderList;
  17. import logisticspipes.renderer.newpipe.LogisticsNewPipeItemBoxRenderer;
  18. import logisticspipes.renderer.newpipe.LogisticsNewRenderPipe;
  19. import logisticspipes.renderer.state.PipeRenderState;
  20. import logisticspipes.transport.LPTravelingItem;
  21. import logisticspipes.transport.PipeFluidTransportLogistics;
  22. import logisticspipes.transport.PipeTransportLogistics;
  23. import logisticspipes.utils.item.ItemIdentifierStack;
  24. import logisticspipes.utils.item.ItemStackRenderer;
  25. import logisticspipes.utils.tuples.LPPosition;
  26. import logisticspipes.utils.tuples.Pair;
  27.  
  28. import net.minecraft.block.Block;
  29. import net.minecraft.client.Minecraft;
  30. import net.minecraft.client.gui.FontRenderer;
  31. import net.minecraft.client.model.ModelSign;
  32. import net.minecraft.client.renderer.GLAllocation;
  33. import net.minecraft.client.renderer.RenderBlocks;
  34. import net.minecraft.client.renderer.Tessellator;
  35. import net.minecraft.client.renderer.entity.RenderItem;
  36. import net.minecraft.client.renderer.entity.RenderManager;
  37. import net.minecraft.client.renderer.texture.TextureMap;
  38. import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
  39. import net.minecraft.init.Blocks;
  40. import net.minecraft.item.Item;
  41. import net.minecraft.item.ItemBlock;
  42. import net.minecraft.item.ItemStack;
  43. import net.minecraft.tileentity.TileEntity;
  44. import net.minecraft.util.IIcon;
  45. import net.minecraft.util.IntHashMap;
  46. import net.minecraft.util.ResourceLocation;
  47. import net.minecraft.world.EnumSkyBlock;
  48. import net.minecraft.world.World;
  49.  
  50. import net.minecraftforge.client.IItemRenderer;
  51. import net.minecraftforge.client.IItemRenderer.ItemRenderType;
  52. import net.minecraftforge.client.IItemRenderer.ItemRendererHelper;
  53. import net.minecraftforge.client.MinecraftForgeClient;
  54. import net.minecraftforge.common.util.ForgeDirection;
  55. import net.minecraftforge.fluids.Fluid;
  56. import net.minecraftforge.fluids.FluidRegistry;
  57. import net.minecraftforge.fluids.FluidStack;
  58.  
  59. import org.lwjgl.opengl.GL11;
  60. import org.lwjgl.opengl.GL12;
  61.  
  62. public class LogisticsRenderPipe extends TileEntitySpecialRenderer {
  63.  
  64.     private static final int LIQUID_STAGES = 40;
  65.     private static final int MAX_ITEMS_TO_RENDER = 10;
  66.     private static final ResourceLocation SIGN = new ResourceLocation("textures/entity/sign.png");
  67.  
  68.     public static LogisticsNewRenderPipe secondRenderer = new LogisticsNewRenderPipe();
  69.     public static LogisticsNewPipeItemBoxRenderer boxRenderer = new LogisticsNewPipeItemBoxRenderer();
  70.     public static PlayerConfig config;
  71.     private static ItemStackRenderer itemRenderer = new ItemStackRenderer(0, 0, 0, false, false, false);
  72.     private static Map<IPipeSignData, GLRenderList> pipeSignRenderListMap = new HashMap<IPipeSignData, GLRenderList>();
  73.     private static int localItemTestRenderList = -1;
  74.  
  75.     private final int[] angleY = { 0, 0, 270, 90, 0, 180 };
  76.     private final int[] angleZ = { 90, 270, 0, 0, 0, 0 };
  77.     private static final IntHashMap displayFluidLists = new IntHashMap();
  78.     private ModelSign modelSign;
  79.     private RenderBlocks renderBlocks = new RenderBlocks();
  80.     private IBCRenderTESR bcRenderer = SimpleServiceLocator.buildCraftProxy.getBCRenderTESR();
  81.  
  82.     public LogisticsRenderPipe() {
  83.         super();
  84.         modelSign = new ModelSign();
  85.         modelSign.signStick.showModel = false;
  86.  
  87.         LogisticsRenderPipe.config = LogisticsPipes.getClientPlayerConfig();
  88.         RenderItem customRenderItem = new RenderItem() {
  89.  
  90.             @Override
  91.             public boolean shouldBob() {
  92.                 return false;
  93.             }
  94.  
  95.             @Override
  96.             public boolean shouldSpreadItems() {
  97.                 return false;
  98.             }
  99.         };
  100.         customRenderItem.setRenderManager(RenderManager.instance);
  101.         itemRenderer.setRenderItem(customRenderItem);
  102.     }
  103.  
  104.     @Override
  105.     public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float partialTickTime) {
  106.         if (!(tileentity instanceof LogisticsTileGenericPipe)) {
  107.             return;
  108.         }
  109.         LogisticsTileGenericPipe pipe = ((LogisticsTileGenericPipe) tileentity);
  110.         if (pipe.pipe == null) {
  111.             return;
  112.         }
  113.  
  114.         if (pipe.pipe instanceof CoreRoutedPipe) {
  115.             renderPipeSigns((CoreRoutedPipe) pipe.pipe, x, y, z, partialTickTime);
  116.         }
  117.  
  118.         double distance = Math.pow(Minecraft.getMinecraft().thePlayer.lastTickPosX - tileentity.xCoord, 2) + Math.pow(Minecraft.getMinecraft().thePlayer.lastTickPosY - tileentity.yCoord, 2) + Math.pow(Minecraft.getMinecraft().thePlayer.lastTickPosZ - tileentity.zCoord, 2);
  119.         if (LogisticsRenderPipe.config.isUseNewRenderer()) {
  120.             LogisticsRenderPipe.secondRenderer.renderTileEntityAt((LogisticsTileGenericPipe) tileentity, x, y, z, partialTickTime, distance);
  121.         }
  122.         if (LogisticsRenderPipe.config.getRenderPipeContentDistance() * LogisticsRenderPipe.config.getRenderPipeContentDistance() < distance) {
  123.             return;
  124.         }
  125.  
  126.         bcRenderer.renderWires(pipe, x, y, z);
  127.  
  128.         // dynamically render pluggables (like gates)
  129.         bcRenderer.dynamicRenderPluggables(pipe, x, y, z);
  130.  
  131.         if (!pipe.isOpaque()) {
  132.             if (pipe.pipe.transport instanceof PipeFluidTransportLogistics) {
  133.                 renderFluids(pipe.pipe, x, y, z);
  134.             }
  135.             if (pipe.pipe.transport instanceof PipeTransportLogistics) {
  136.                 renderSolids(pipe.pipe, x, y, z, partialTickTime);
  137.             }
  138.         }
  139.     }
  140.  
  141.     private void renderSolids(CoreUnroutedPipe pipe, double x, double y, double z, float partialTickTime) {
  142.         GL11.glPushMatrix();
  143.  
  144.         float light = pipe.container.getWorldObj().getLightBrightness(pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord);
  145.  
  146.         int count = 0;
  147.         for (LPTravelingItem item : pipe.transport.items) {
  148.             if (count >= LogisticsRenderPipe.MAX_ITEMS_TO_RENDER) {
  149.                 break;
  150.             }
  151.  
  152.             LPPosition pos = new LPPosition(0.5D, 0.5D, 0.5D);
  153.  
  154.             if (item.getPosition() > 1 || item.getPosition() < 0) {
  155.                 continue;
  156.             }
  157.  
  158.             float fPos = item.getPosition() + item.getSpeed() * partialTickTime;
  159.             double boxScale = 1;
  160.  
  161.             if (fPos < 0.5) {
  162.                 if (item.input == ForgeDirection.UNKNOWN) {
  163.                     continue;
  164.                 }
  165.                 if (!pipe.container.renderState.pipeConnectionMatrix.isConnected(item.input.getOpposite())) {
  166.                     continue;
  167.                 }
  168.                 pos.moveForward(item.input.getOpposite(), 0.5F - fPos);
  169.             } else {
  170.                 if (item.output == ForgeDirection.UNKNOWN) {
  171.                     continue;
  172.                 }
  173.                 if (!pipe.container.renderState.pipeConnectionMatrix.isConnected(item.output)) {
  174.                     continue;
  175.                 }
  176.                 pos.moveForward(item.output, fPos - 0.5F);
  177.             }
  178.             if (pipe.container.renderState.pipeConnectionMatrix.isTDConnected(item.input.getOpposite())) {
  179.                 boxScale = (fPos * (1 - 0.65)) + 0.65;
  180.             }
  181.             if (pipe.container.renderState.pipeConnectionMatrix.isTDConnected(item.output)) {
  182.                 boxScale = ((1 - fPos) * (1 - 0.65)) + 0.65;
  183.             }
  184.             if (pipe.container.renderState.pipeConnectionMatrix.isTDConnected(item.input.getOpposite()) && pipe.container.renderState.pipeConnectionMatrix.isTDConnected(item.output)) {
  185.                 boxScale = 0.65;
  186.             }
  187.  
  188.             if (item.getItemIdentifierStack() == null) {
  189.                 continue;
  190.             }
  191.             if (item.getContainer().xCoord != pipe.container.xCoord || item.getContainer().yCoord != pipe.container.yCoord || item.getContainer().zCoord != pipe.container.zCoord) {
  192.                 continue;
  193.             }
  194.             ItemStack itemstack = item.getItemIdentifierStack().makeNormalStack();
  195.             doRenderItem(itemstack, pipe.container.getWorldObj(), x + pos.getXD(), y + pos.getYD(), z + pos.getZD(), light, 0.75F, boxScale, partialTickTime);
  196.             count++;
  197.         }
  198.         count = 0;
  199.         float dist = 0.135F;
  200.         LPPosition pos = new LPPosition(0.5D, 0.5D, 0.5D);
  201.         pos.moveForward(ForgeDirection.SOUTH, dist);
  202.         pos.moveForward(ForgeDirection.EAST, dist);
  203.         pos.moveForward(ForgeDirection.UP, dist);
  204.         for (Pair<ItemIdentifierStack, Pair<Integer, Integer>> item : pipe.transport._itemBuffer) {
  205.             if (item == null || item.getValue1() == null) {
  206.                 continue;
  207.             }
  208.             ItemStack itemstack = item.getValue1().makeNormalStack();
  209.             doRenderItem(itemstack, pipe.container.getWorldObj(), x + pos.getXD(), y + pos.getYD(), z + pos.getZD(), light, 0.25F, 0, partialTickTime);
  210.             count++;
  211.             if (count >= 27) {
  212.                 break;
  213.             } else if (count % 9 == 0) {
  214.                 pos.moveForward(ForgeDirection.SOUTH, dist * 2);
  215.                 pos.moveForward(ForgeDirection.EAST, dist * 2);
  216.                 pos.moveForward(ForgeDirection.DOWN, dist);
  217.             } else if (count % 3 == 0) {
  218.                 pos.moveForward(ForgeDirection.SOUTH, dist * 2);
  219.                 pos.moveForward(ForgeDirection.WEST, dist);
  220.             } else {
  221.                 pos.moveForward(ForgeDirection.NORTH, dist);
  222.             }
  223.         }
  224.  
  225.         GL11.glPopMatrix();
  226.     }
  227.  
  228.     public void doRenderItem(ItemStack itemstack, World worldObj, double x, double y, double z, float light, float renderScale, double boxScale, float partialTickTime) {
  229.         if (LogisticsRenderPipe.config.isUseNewRenderer() && boxScale != 0) {
  230.             LogisticsRenderPipe.boxRenderer.doRenderItem(itemstack, light, x, y, z, boxScale);
  231.         }
  232.  
  233.         GL11.glPushMatrix();
  234.         GL11.glTranslated(x, y, z);
  235.         GL11.glScalef(renderScale, renderScale, renderScale);
  236.         GL11.glTranslatef(0.0F, -0.1F, 0.0F);
  237.         itemRenderer.setItemstack(itemstack).setWorldObj(worldObj).setPartialTickTime(partialTickTime);
  238.         itemRenderer.renderInWorld();
  239.         GL11.glPopMatrix();
  240.     }
  241.  
  242.     private boolean needDistance(List<Pair<ForgeDirection, IPipeSign>> list) {
  243.         List<Pair<ForgeDirection, IPipeSign>> copy = new ArrayList<Pair<ForgeDirection, IPipeSign>>(list);
  244.         Iterator<Pair<ForgeDirection, IPipeSign>> iter = copy.iterator();
  245.         boolean north = false, south = false, east = false, west = false;
  246.         while (iter.hasNext()) {
  247.             Pair<ForgeDirection, IPipeSign> pair = iter.next();
  248.             if (pair.getValue1() == ForgeDirection.UP || pair.getValue1() == ForgeDirection.DOWN || pair.getValue1() == ForgeDirection.UNKNOWN) {
  249.                 iter.remove();
  250.             }
  251.             if (pair.getValue1() == ForgeDirection.NORTH) {
  252.                 north = true;
  253.             }
  254.             if (pair.getValue1() == ForgeDirection.SOUTH) {
  255.                 south = true;
  256.             }
  257.             if (pair.getValue1() == ForgeDirection.EAST) {
  258.                 east = true;
  259.             }
  260.             if (pair.getValue1() == ForgeDirection.WEST) {
  261.                 west = true;
  262.             }
  263.         }
  264.         boolean result = copy.size() > 1;
  265.         if (copy.size() == 2) {
  266.             if (north && south) {
  267.                 result = false;
  268.             }
  269.             if (east && west) {
  270.                 result = false;
  271.             }
  272.         }
  273.         return result;
  274.     }
  275.  
  276.     private void renderPipeSigns(CoreRoutedPipe pipe, double x, double y, double z, float partialTickTime) {
  277.         if (!pipe.getPipeSigns().isEmpty()) {
  278.             List<Pair<ForgeDirection, IPipeSign>> list = pipe.getPipeSigns();
  279.             for (Pair<ForgeDirection, IPipeSign> pair : list) {
  280.                 if (pipe.container.renderState.pipeConnectionMatrix.isConnected(pair.getValue1())) {
  281.                     continue;
  282.                 }
  283.                 GL11.glPushMatrix();
  284.                 GL11.glTranslatef((float) x + 0.5F, (float) y + 0.5F, (float) z + 0.5F);
  285.                 switch (pair.getValue1()) {
  286.                     case UP:
  287.                         GL11.glRotatef(90, 1.0F, 0.0F, 0.0F);
  288.                         break;
  289.                     case DOWN:
  290.                         GL11.glRotatef(-90, 1.0F, 0.0F, 0.0F);
  291.                         break;
  292.                     case NORTH:
  293.                         GL11.glRotatef(0, 0.0F, 1.0F, 0.0F);
  294.                         if (needDistance(list)) {
  295.                             GL11.glTranslatef(0.0F, 0.0F, -0.15F);
  296.                         }
  297.                         break;
  298.                     case SOUTH:
  299.                         GL11.glRotatef(-180, 0.0F, 1.0F, 0.0F);
  300.                         if (needDistance(list)) {
  301.                             GL11.glTranslatef(0.0F, 0.0F, -0.15F);
  302.                         }
  303.                         break;
  304.                     case EAST:
  305.                         GL11.glRotatef(-90, 0.0F, 1.0F, 0.0F);
  306.                         if (needDistance(list)) {
  307.                             GL11.glTranslatef(0.0F, 0.0F, -0.15F);
  308.                         }
  309.                         break;
  310.                     case WEST:
  311.                         GL11.glRotatef(90, 0.0F, 1.0F, 0.0F);
  312.                         if (needDistance(list)) {
  313.                             GL11.glTranslatef(0.0F, 0.0F, -0.15F);
  314.                         }
  315.                         break;
  316.                     default:
  317.                         ;
  318.                 }
  319.                 renderSign(pipe, pair.getValue2(), partialTickTime);
  320.                 GL11.glPopMatrix();
  321.             }
  322.         }
  323.     }
  324.  
  325.     private void renderSign(CoreRoutedPipe pipe, IPipeSign type, float partialTickTime) {
  326.         if (partialTickTime > -100000) {
  327.             return;
  328.         }
  329.         GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  330.  
  331.         GL11.glDisable(GL12.GL_RESCALE_NORMAL);
  332.  
  333.         float signScale = 2 / 3.0F;
  334.         GL11.glTranslatef(0.0F, -0.3125F, -0.36F);
  335.         GL11.glRotatef(180, 0.0f, 1.0f, 0.0f);
  336.         Minecraft.getMinecraft().renderEngine.bindTexture(LogisticsRenderPipe.SIGN);
  337.  
  338.         GL11.glPushMatrix();
  339.         GL11.glScalef(signScale, -signScale, -signScale);
  340.         modelSign.renderSign();
  341.         GL11.glPopMatrix();
  342.  
  343.         GL11.glTranslatef(-0.32F, 0.5F * signScale + 0.08F, 0.07F * signScale);
  344.  
  345.         IPipeSignData data = type.getRenderData(pipe);
  346.         GLRenderList renderList = pipeSignRenderListMap.get(data);
  347.         if(data.isListCompatible(this)) {
  348.             if (renderList == null || renderList.isInvalid() || !renderList.isFilled()) {
  349.                 renderList = SimpleServiceLocator.renderListHandler.getNewRenderList();
  350.                 pipeSignRenderListMap.put(data, renderList);
  351.                 renderList.startListCompile();
  352.                 type.render(pipe, this);
  353.                 renderList.stopCompile();
  354.             }
  355.             renderList.render();
  356.         } else {
  357.             type.render(pipe, this);
  358.         }
  359.     }
  360.  
  361.     public void renderItemStackOnSign(ItemStack itemstack) {
  362.         if (itemstack == null || itemstack.getItem() == null) {
  363.             return; // Only happens on false configuration
  364.         }
  365.  
  366.         Item item = itemstack.getItem();
  367.  
  368.         IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(itemstack, ItemRenderType.INVENTORY);
  369.  
  370.         Minecraft.getMinecraft().renderEngine.bindTexture(itemstack.getItemSpriteNumber() == 0 ? TextureMap.locationBlocksTexture : TextureMap.locationItemsTexture);
  371.  
  372.         GL11.glPushMatrix();
  373.  
  374.         if (customRenderer != null) {
  375.             if (customRenderer.shouldUseRenderHelper(ItemRenderType.INVENTORY, itemstack, ItemRendererHelper.INVENTORY_BLOCK)) {
  376.                 GL11.glScalef(0.20F, -0.20F, -0.01F);
  377.  
  378.                 GL11.glRotatef(210.0F, 1.0F, 0.0F, 0.0F);
  379.                 GL11.glRotatef(-45.0F, 0.0F, 1.0F, 0.0F);
  380.  
  381.                 GL11.glDisable(GL11.GL_LIGHTING);
  382.                 GL11.glDisable(GL11.GL_LIGHT0);
  383.                 GL11.glDisable(GL11.GL_LIGHT1);
  384.                 GL11.glDisable(GL11.GL_COLOR_MATERIAL);
  385.  
  386.                 customRenderer.renderItem(ItemRenderType.INVENTORY, itemstack, renderBlocks);
  387.  
  388.                 GL11.glEnable(GL11.GL_LIGHTING);
  389.                 GL11.glEnable(GL11.GL_LIGHT0);
  390.                 GL11.glEnable(GL11.GL_LIGHT1);
  391.                 GL11.glEnable(GL11.GL_COLOR_MATERIAL);
  392.             } else {
  393.                 GL11.glScalef(0.018F, -0.018F, -0.01F);
  394.                 GL11.glTranslatef(-7F, -8F, 0F);
  395.  
  396.                 GL11.glDisable(GL11.GL_LIGHTING);
  397.                 GL11.glDisable(GL11.GL_LIGHT0);
  398.                 GL11.glDisable(GL11.GL_LIGHT1);
  399.                 GL11.glDisable(GL11.GL_COLOR_MATERIAL);
  400.  
  401.                 customRenderer.renderItem(ItemRenderType.INVENTORY, itemstack, renderBlocks);
  402.  
  403.                 GL11.glEnable(GL11.GL_LIGHTING);
  404.                 GL11.glEnable(GL11.GL_LIGHT0);
  405.                 GL11.glEnable(GL11.GL_LIGHT1);
  406.                 GL11.glEnable(GL11.GL_COLOR_MATERIAL);
  407.             }
  408.         } else if (item instanceof ItemBlock && RenderBlocks.renderItemIn3d(Block.getBlockFromItem(item).getRenderType())) {
  409.             GL11.glScalef(0.20F, -0.20F, -0.01F);
  410.  
  411.             GL11.glRotatef(210.0F, 1.0F, 0.0F, 0.0F);
  412.             GL11.glRotatef(-45.0F, 0.0F, 1.0F, 0.0F);
  413.  
  414.             renderBlocks.useInventoryTint = false;
  415.  
  416.             GL11.glDisable(GL11.GL_LIGHTING);
  417.             GL11.glDisable(GL11.GL_LIGHT0);
  418.             GL11.glDisable(GL11.GL_LIGHT1);
  419.             GL11.glDisable(GL11.GL_COLOR_MATERIAL);
  420.  
  421.             renderBlocks.renderBlockAsItem(Block.getBlockFromItem(item), itemstack.getItemDamage(), 1.0F);
  422.  
  423.             GL11.glEnable(GL11.GL_LIGHTING);
  424.             GL11.glEnable(GL11.GL_LIGHT0);
  425.             GL11.glEnable(GL11.GL_LIGHT1);
  426.             GL11.glEnable(GL11.GL_COLOR_MATERIAL);
  427.         } else {
  428.             GL11.glScalef(0.02F, -0.02F, -0.01F);
  429.  
  430.             GL11.glDisable(GL11.GL_LIGHTING);
  431.             GL11.glDisable(GL11.GL_LIGHT0);
  432.             GL11.glDisable(GL11.GL_LIGHT1);
  433.             GL11.glDisable(GL11.GL_COLOR_MATERIAL);
  434.  
  435.             GL11.glTranslatef(-8F, -8F, 0.0F);
  436.  
  437.             if (item.requiresMultipleRenderPasses()) {
  438.                 for (int var14 = 0; var14 < item.getRenderPasses(itemstack.getItemDamage()); ++var14) {
  439.                     IIcon var15 = item.getIconFromDamageForRenderPass(itemstack.getItemDamage(), var14);
  440.                     renderItem(var15);
  441.                 }
  442.             } else {
  443.                 renderItem(item.getIconIndex(itemstack));
  444.             }
  445.  
  446.             GL11.glEnable(GL11.GL_LIGHTING);
  447.             GL11.glEnable(GL11.GL_LIGHT0);
  448.             GL11.glEnable(GL11.GL_LIGHT1);
  449.             GL11.glEnable(GL11.GL_COLOR_MATERIAL);
  450.         }
  451.  
  452.         GL11.glPopMatrix();
  453.     }
  454.  
  455.     private void renderItem(IIcon par3Icon) {
  456.         if (par3Icon == null) {
  457.             return;
  458.         }
  459.         int par1 = 0;
  460.         int par2 = 0;
  461.         int par4 = 16;
  462.         int par5 = 16;
  463.         double zLevel = 0;
  464.         GL11.glPushMatrix();
  465.         Tessellator tessellator = Tessellator.instance;
  466.         tessellator.startDrawingQuads();
  467.         tessellator.setNormal(0.0F, 1.0F, 0.0F);
  468.         tessellator.addVertexWithUV(par1 + 0, par2 + par5, zLevel, par3Icon.getMinU(), par3Icon.getMaxV());
  469.         tessellator.addVertexWithUV(par1 + par4, par2 + par5, zLevel, par3Icon.getMaxU(), par3Icon.getMaxV());
  470.         tessellator.addVertexWithUV(par1 + par4, par2 + 0, zLevel, par3Icon.getMaxU(), par3Icon.getMinV());
  471.         tessellator.addVertexWithUV(par1 + 0, par2 + 0, zLevel, par3Icon.getMinU(), par3Icon.getMinV());
  472.         tessellator.draw();
  473.         GL11.glPopMatrix();
  474.     }
  475.  
  476.     public String cut(String name, FontRenderer renderer) {
  477.         if (renderer.getStringWidth(name) < 90) {
  478.             return name;
  479.         }
  480.         StringBuilder sum = new StringBuilder();
  481.         for (int i = 0; i < name.length(); i++) {
  482.             if (renderer.getStringWidth(sum.toString() + name.charAt(i) + "...") < 90) {
  483.                 sum.append(name.charAt(i));
  484.             } else {
  485.                 return sum.toString() + "...";
  486.             }
  487.         }
  488.         return sum.toString();
  489.     }
  490.  
  491.     // BC copy, except where marked with XXX
  492.     private void renderFluids(CoreUnroutedPipe pipe, double x, double y, double z) {
  493.         // XXX PipeTransportFluids trans = pipe.transport;
  494.         PipeFluidTransportLogistics trans = (PipeFluidTransportLogistics) (pipe.transport);
  495.  
  496.         boolean needsRender = false;
  497.         for (int i = 0; i < 7; ++i) {
  498.             FluidStack fluidStack = trans.renderCache[i];
  499.             if (fluidStack != null && fluidStack.amount > 0) {
  500.                 needsRender = true;
  501.                 break;
  502.             }
  503.         }
  504.  
  505.         if (!needsRender) {
  506.             return;
  507.         }
  508.  
  509.         GL11.glPushMatrix();
  510.         GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
  511.         GL11.glEnable(GL11.GL_CULL_FACE);
  512.         GL11.glDisable(GL11.GL_LIGHTING);
  513.         GL11.glEnable(GL11.GL_BLEND);
  514.         GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
  515.  
  516.         GL11.glTranslatef((float) x, (float) y, (float) z);
  517.  
  518.         int skylight = pipe.container.getWorld().getSkyBlockTypeBrightness(EnumSkyBlock.Sky, pipe.getX(), pipe.getY(), pipe.getZ());
  519.         int blocklight = pipe.container.getWorld().getSkyBlockTypeBrightness(EnumSkyBlock.Block, pipe.getX(), pipe.getY(), pipe.getZ());
  520.  
  521.         // sides
  522.  
  523.         boolean sides = false, above = false;
  524.  
  525.         for (int i = 0; i < 6; ++i) {
  526.             FluidStack fluidStack = trans.renderCache[i];
  527.  
  528.             if (fluidStack != null && fluidStack.amount > 0) {
  529.                 DisplayFluidList d = getListFromBuffer(fluidStack, skylight, blocklight, fluidStack.getFluid().getLuminosity(fluidStack), pipe.container.getWorldObj());
  530.  
  531.                 if (d == null) {
  532.                     continue;
  533.                 }
  534.  
  535.                 // XXX int stage = (int) ((float) fluidStack.amount / (float) (trans.getCapacity()) * (LIQUID_STAGES - 1));
  536.                 int stage = (int) ((float) fluidStack.amount / (float) (trans.getSideCapacity()) * (LogisticsRenderPipe.LIQUID_STAGES - 1));
  537.  
  538.                 GL11.glPushMatrix();
  539.                 int list = 0;
  540.  
  541.                 switch (ForgeDirection.VALID_DIRECTIONS[i]) {
  542.                     case UP:
  543.                         above = true;
  544.                         list = d.sideVertical[stage];
  545.                         break;
  546.                     case DOWN:
  547.                         GL11.glTranslatef(0, -0.75F, 0);
  548.                         list = d.sideVertical[stage];
  549.                         break;
  550.                     case EAST:
  551.                     case WEST:
  552.                     case SOUTH:
  553.                     case NORTH:
  554.                         sides = true;
  555.                         // Yes, this is kind of ugly, but was easier than transform the coordinates above.
  556.                         GL11.glTranslatef(0.5F, 0.0F, 0.5F);
  557.                         GL11.glRotatef(angleY[i], 0, 1, 0);
  558.                         GL11.glRotatef(angleZ[i], 0, 0, 1);
  559.                         GL11.glTranslatef(-0.5F, 0.0F, -0.5F);
  560.                         list = d.sideHorizontal[stage];
  561.                         break;
  562.                     default:
  563.                 }
  564.                 bindTexture(TextureMap.locationBlocksTexture);
  565.                 FluidRenderer.setColorForFluidStack(fluidStack);
  566.                 GL11.glCallList(list);
  567.                 GL11.glPopMatrix();
  568.             }
  569.         }
  570.         // CENTER
  571.         FluidStack fluidStack = trans.renderCache[ForgeDirection.UNKNOWN.ordinal()];
  572.  
  573.         if (fluidStack != null && fluidStack.amount > 0) {
  574.             DisplayFluidList d = getListFromBuffer(fluidStack, skylight, blocklight, fluidStack.getFluid().getLuminosity(fluidStack), pipe.container.getWorldObj());
  575.  
  576.             if (d != null) {
  577.                 // XXX int stage = (int) ((float) fluidStack.amount / (float) (trans.getCapacity()) * (LIQUID_STAGES - 1));
  578.                 int stage = (int) ((float) fluidStack.amount / (float) (trans.getInnerCapacity()) * (LogisticsRenderPipe.LIQUID_STAGES - 1));
  579.  
  580.                 bindTexture(TextureMap.locationBlocksTexture);
  581.                 FluidRenderer.setColorForFluidStack(fluidStack);
  582.  
  583.                 if (above) {
  584.                     GL11.glCallList(d.centerVertical[stage]);
  585.                 }
  586.  
  587.                 if (!above || sides) {
  588.                     GL11.glCallList(d.centerHorizontal[stage]);
  589.                 }
  590.             }
  591.  
  592.         }
  593.  
  594.         GL11.glPopAttrib();
  595.         GL11.glPopMatrix();
  596.     }
  597.  
  598.     // BC copy
  599.     private DisplayFluidList getListFromBuffer(FluidStack stack, int skylight, int blocklight, int flags, World world) {
  600.  
  601.         int liquidId = stack.getFluidID();
  602.  
  603.         if (liquidId == 0) {
  604.             return null;
  605.         }
  606.  
  607.         return getDisplayFluidLists(liquidId, skylight, blocklight, flags, world);
  608.     }
  609.  
  610.     // BC copy
  611.     private DisplayFluidList getDisplayFluidLists(int liquidId, int skylight, int blocklight, int flags, World world) {
  612.         int finalBlockLight = Math.max(flags & 31, blocklight);
  613.         int listId = (liquidId & 0x3FFFF) << 13 | (flags & 0xE0 | finalBlockLight) << 5 | (skylight & 31);
  614.  
  615.         if (displayFluidLists.containsItem(listId)) {
  616.             return (DisplayFluidList) displayFluidLists.lookup(listId);
  617.         }
  618.  
  619.         Fluid fluid = FluidRegistry.getFluid(liquidId);
  620.  
  621.         if (fluid == null) {
  622.             return null;
  623.         }
  624.  
  625.         DisplayFluidList d = new DisplayFluidList();
  626.         displayFluidLists.addKey(listId, d);
  627.  
  628.         RenderInfo block = new RenderInfo();
  629.  
  630.         if (fluid.getBlock() != null) {
  631.             block.baseBlock = fluid.getBlock();
  632.         } else {
  633.             block.baseBlock = Blocks.water;
  634.         }
  635.  
  636.         block.texture = fluid.getStillIcon();
  637.         block.brightness = skylight << 16 | finalBlockLight;
  638.  
  639.         float size = LPConstants.BC_PIPE_MAX_POS - LPConstants.BC_PIPE_MIN_POS;
  640.  
  641.         // render size
  642.  
  643.         for (int s = 0; s < LogisticsRenderPipe.LIQUID_STAGES; ++s) {
  644.             float ratio = (float) s / (float) LogisticsRenderPipe.LIQUID_STAGES;
  645.  
  646.             // SIDE HORIZONTAL
  647.  
  648.             d.sideHorizontal[s] = GLAllocation.generateDisplayLists(1);
  649.             GL11.glNewList(d.sideHorizontal[s], GL11.GL_COMPILE);
  650.  
  651.             block.minX = 0.0F;
  652.             block.minZ = LPConstants.BC_PIPE_MIN_POS + 0.01F;
  653.  
  654.             block.maxX = block.minX + size / 2F + 0.01F;
  655.             block.maxZ = block.minZ + size - 0.02F;
  656.  
  657.             block.minY = LPConstants.BC_PIPE_MIN_POS + 0.01F;
  658.             block.maxY = block.minY + (size - 0.02F) * ratio;
  659.  
  660.             CustomBlockRenderer.INSTANCE.renderBlock(block, world, 0, 0, 0, false, true);
  661.  
  662.             GL11.glEndList();
  663.  
  664.             // SIDE VERTICAL
  665.  
  666.             d.sideVertical[s] = GLAllocation.generateDisplayLists(1);
  667.             GL11.glNewList(d.sideVertical[s], GL11.GL_COMPILE);
  668.  
  669.             block.minY = LPConstants.BC_PIPE_MAX_POS - 0.01;
  670.             block.maxY = 1;
  671.  
  672.             block.minX = 0.5 - (size / 2 - 0.01) * ratio;
  673.             block.maxX = 0.5 + (size / 2 - 0.01) * ratio;
  674.  
  675.             block.minZ = 0.5 - (size / 2 - 0.01) * ratio;
  676.             block.maxZ = 0.5 + (size / 2 - 0.01) * ratio;
  677.  
  678.             CustomBlockRenderer.INSTANCE.renderBlock(block, world, 0, 0, 0, false, true);
  679.  
  680.             GL11.glEndList();
  681.  
  682.             // CENTER HORIZONTAL
  683.  
  684.             d.centerHorizontal[s] = GLAllocation.generateDisplayLists(1);
  685.             GL11.glNewList(d.centerHorizontal[s], GL11.GL_COMPILE);
  686.  
  687.             block.minX = LPConstants.BC_PIPE_MIN_POS + 0.01;
  688.             block.minZ = LPConstants.BC_PIPE_MIN_POS + 0.01;
  689.  
  690.             block.maxX = block.minX + size - 0.02;
  691.             block.maxZ = block.minZ + size - 0.02;
  692.  
  693.             block.minY = LPConstants.BC_PIPE_MIN_POS + 0.01;
  694.             block.maxY = block.minY + (size - 0.02F) * ratio;
  695.  
  696.             CustomBlockRenderer.INSTANCE.renderBlock(block, world, 0, 0, 0, false, true);
  697.  
  698.             GL11.glEndList();
  699.  
  700.             // CENTER VERTICAL
  701.  
  702.             d.centerVertical[s] = GLAllocation.generateDisplayLists(1);
  703.             GL11.glNewList(d.centerVertical[s], GL11.GL_COMPILE);
  704.  
  705.             block.minY = LPConstants.BC_PIPE_MIN_POS + 0.01;
  706.             block.maxY = LPConstants.BC_PIPE_MAX_POS - 0.01;
  707.  
  708.             block.minX = 0.5 - (size / 2 - 0.02) * ratio;
  709.             block.maxX = 0.5 + (size / 2 - 0.02) * ratio;
  710.  
  711.             block.minZ = 0.5 - (size / 2 - 0.02) * ratio;
  712.             block.maxZ = 0.5 + (size / 2 - 0.02) * ratio;
  713.  
  714.             CustomBlockRenderer.INSTANCE.renderBlock(block, world, 0, 0, 0, false, true);
  715.  
  716.             GL11.glEndList();
  717.  
  718.         }
  719.  
  720.         return d;
  721.     }
  722.  
  723.     public boolean isRenderListCompatible(ItemStack stack) {
  724.         GL11.glPushMatrix();
  725.         GL11.glScaled(0, 0, 0);
  726.         try {
  727.             renderItemStackOnSign(stack);
  728.             int i = GL11.glGetError();
  729.             if (i != 0) {
  730.                 GL11.glPopMatrix();
  731.                 return false;
  732.             }
  733.             if(localItemTestRenderList == -1) {
  734.                 localItemTestRenderList = GLAllocation.generateDisplayLists(1);
  735.             }
  736.             GL11.glNewList(localItemTestRenderList, GL11.GL_COMPILE);
  737.             i = GL11.glGetError();
  738.             if (i != 0) {
  739.                 GL11.glPopMatrix();
  740.                 return false;
  741.             }
  742.             renderItemStackOnSign(stack);
  743.             i = GL11.glGetError();
  744.             if (i != 0) {
  745.                 GL11.glPopMatrix();
  746.                 return false;
  747.             }
  748.             GL11.glEndList();
  749.             i = GL11.glGetError();
  750.             if (i != 0) {
  751.                 GL11.glPopMatrix();
  752.                 return false;
  753.             }
  754.             GL11.glCallList(localItemTestRenderList);
  755.             i = GL11.glGetError();
  756.             if (i != 0) {
  757.                 GL11.glPopMatrix();
  758.                 return false;
  759.             }
  760.             GL11.glPopMatrix();
  761.             return true;
  762.         } catch (Exception e) {
  763.         }
  764.         GL11.glPopMatrix();
  765.         return false;
  766.     }
  767.  
  768.     private class DisplayFluidList {
  769.  
  770.         public int[] sideHorizontal = new int[LogisticsRenderPipe.LIQUID_STAGES];
  771.         public int[] sideVertical = new int[LogisticsRenderPipe.LIQUID_STAGES];
  772.         public int[] centerHorizontal = new int[LogisticsRenderPipe.LIQUID_STAGES];
  773.         public int[] centerVertical = new int[LogisticsRenderPipe.LIQUID_STAGES];
  774.     }
  775. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement