Guest User

RenderSapphireCrop

a guest
Jul 2nd, 2014
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.60 KB | None | 0 0
  1. package sometimesHardcoreSometimes;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.client.Minecraft;
  5. import net.minecraft.client.renderer.OpenGlHelper;
  6. import net.minecraft.client.renderer.Tessellator;
  7. import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
  8. import net.minecraft.entity.Entity;
  9. import net.minecraft.tileentity.TileEntity;
  10. import net.minecraft.util.ResourceLocation;
  11. import net.minecraft.world.World;
  12.  
  13. import org.lwjgl.opengl.GL11;
  14.  
  15. public class RenderSapphireCrop extends TileEntitySpecialRenderer
  16. {
  17.     private final ModelSapphireCrop model;
  18.     int bAmt;
  19.    
  20.     public RenderSapphireCrop()
  21.     {
  22.         this.model = new ModelSapphireCrop();
  23.     }
  24.    
  25.     private void adjustedRotatePivotViaMeta(World world, int x, int y, int z)
  26.     {
  27.         int meta = world.getBlockMetadata(x, y, z);
  28.        
  29.         GL11.glPushMatrix();
  30.         GL11.glRotatef(meta * (-90), 0.0F, 0.0F, 1.0F);
  31.         GL11.glPopMatrix();
  32.     }
  33.    
  34.     @Override
  35.     public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float scale)
  36.     {
  37.         GL11.glPushMatrix();
  38.         GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F);
  39.        
  40.         TileEntity te = tileEntity;
  41.        
  42.         if(te != null)
  43.         {
  44.             if(te instanceof TileEntitySapphireCrop)
  45.                 te = (TileEntitySapphireCrop)te;
  46.            
  47.             bAmt = ((TileEntitySapphireCrop) te).getBerryAmount();
  48.         }
  49.        
  50.         ResourceLocation textures;
  51.        
  52.         //Handles the texture
  53.         switch(bAmt)
  54.         {
  55.         case 0:
  56.             textures = (new ResourceLocation(Base.modid + ":textures/tileentity/sapphireCrop/sapphireCrop_0.png"));
  57.             break;
  58.         case 1:
  59.             textures = (new ResourceLocation(Base.modid + ":textures/tileentity/sapphireCrop/sapphireCrop_1.png"));
  60.             break;
  61.         case 2:
  62.             textures = (new ResourceLocation(Base.modid + ":textures/tileentity/sapphireCrop/sapphireCrop_2.png"));
  63.             break;
  64.         case 3:
  65.             textures = (new ResourceLocation(Base.modid + ":textures/tileentity/sapphireCrop/sapphireCrop_3.png"));
  66.             break;
  67.         case 4:
  68.             textures = (new ResourceLocation(Base.modid + ":textures/tileentity/sapphireCrop/sapphireCrop_4.png"));
  69.             break;
  70.         case 5:
  71.             textures = (new ResourceLocation(Base.modid + ":textures/tileentity/sapphireCrop/sapphireCrop_5.png"));
  72.             break;
  73.         case 6:
  74.             textures = (new ResourceLocation(Base.modid + ":textures/tileentity/sapphireCrop/sapphireCrop_6.png"));
  75.             break;
  76.         case 7:
  77.             textures = (new ResourceLocation(Base.modid + ":textures/tileentity/sapphireCrop/sapphireCrop_7.png"));
  78.             break;
  79.         default:
  80.             textures = (new ResourceLocation(Base.modid + ":textures/tileentity/sapphireCrop/sapphireCrop_0.png"));
  81.             break;
  82.         }
  83.        
  84.         Minecraft.getMinecraft().renderEngine.bindTexture(textures);
  85.        
  86.         int meta = tileEntity.getBlockMetadata();
  87.         GL11.glPushMatrix();
  88.        
  89.         if(meta % 4 == 0) GL11.glRotatef(-180F, 1.0F, 0.0F, 1.0F);
  90.         if(meta % 4 == 1) GL11.glRotatef(-180F, -1.0F, 0.0F, 1.0F);
  91.         if(meta % 4 == 2) GL11.glRotatef(-180F, 0.0F, 0.0F, 1.0F);
  92.         if(meta % 4 == 3) GL11.glRotatef(-180F, 90F, 0.0F, 1.0F);
  93.        
  94.         this.model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
  95.        
  96.         GL11.glPopMatrix();
  97.         GL11.glPopMatrix();
  98.     }
  99.    
  100.     private void adjustLightFixture(World world, int i, int j, int k, Block block)
  101.     {
  102.         Tessellator tess = Tessellator.instance;
  103.        
  104.         float brightness = block.getBlockBrightness(world, i, j, k);
  105.         int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0);
  106.         int modulousModifier = skyLight % 65536;
  107.         int divModifier = skyLight / 65536;
  108.        
  109.         tess.setColorOpaque_F(brightness, brightness, brightness);
  110.         OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)modulousModifier, divModifier);
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment