Advertisement
Guest User

Untitled

a guest
Sep 21st, 2016
53
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package se.Matryoshika.Underworld.Content.Rendering;
  2.  
  3. import org.lwjgl.opengl.GL11;
  4.  
  5. import net.minecraft.client.Minecraft;
  6. import net.minecraft.client.renderer.GlStateManager;
  7. import net.minecraft.client.renderer.OpenGlHelper;
  8. import net.minecraft.client.renderer.RenderHelper;
  9. import net.minecraft.client.renderer.Tessellator;
  10. import net.minecraft.client.renderer.block.model.IBakedModel;
  11. import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
  12. import net.minecraft.client.renderer.texture.TextureMap;
  13. import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
  14. import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
  15. import net.minecraft.entity.player.EntityPlayer;
  16. import net.minecraft.init.Blocks;
  17. import net.minecraft.item.ItemStack;
  18. import net.minecraft.util.ResourceLocation;
  19. import net.minecraft.world.World;
  20. import net.minecraftforge.client.model.IModel;
  21. import net.minecraftforge.client.model.ModelLoaderRegistry;
  22. import net.minecraftforge.common.model.TRSRTransformation;
  23. import net.minecraftforge.fml.relauncher.Side;
  24. import net.minecraftforge.fml.relauncher.SideOnly;
  25. import se.Matryoshika.Underworld.Underworld;
  26. import se.Matryoshika.Underworld.Content.Blocks.BlockMetamorphicTable;
  27. import se.Matryoshika.Underworld.Content.TileEntity.TileMetamorphicTable;
  28.  
  29. @SideOnly(Side.CLIENT)
  30. public class TEMetamorphicTableRenderer extends TileEntitySpecialRenderer<TileMetamorphicTable> {
  31.  
  32.     private IModel model;
  33.     private IBakedModel bakedModel;
  34.  
  35.     private IBakedModel getBakedModel() {
  36.  
  37.         if (bakedModel == null) {
  38.             try {
  39.                 model = ModelLoaderRegistry.getModel(new ResourceLocation(Underworld.MODID, "block/Metamorphic_table"));
  40.             } catch (Exception e) {
  41.                 throw new RuntimeException(e);
  42.             }
  43.             bakedModel = model.bake(TRSRTransformation.identity(), DefaultVertexFormats.ITEM,
  44.                     location -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString()));
  45.         }
  46.         return bakedModel;
  47.     }
  48.  
  49.     @Override
  50.     public void renderTileEntityAt(TileMetamorphicTable te, double x, double y, double z, float partialTicks, int destroyStage) {
  51.         Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
  52.         GlStateManager.disableCull();
  53.         GlStateManager.translate(x, y, z);
  54.         GlStateManager.translate(0.5f, 0.5f, 0.5f);
  55.  
  56.         GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  57.  
  58.         int brightness = getWorld().getCombinedLight(te.getPos(), 0);
  59.  
  60.  
  61.         OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float) (brightness % 0x10000) / 1f, (float) (brightness / 0x10000) / 1f);
  62.  
  63.         renderBody(te);
  64.         renderFrame(te);
  65.         if(te.getWorld() != null)
  66.             renderItem(te);
  67.        
  68.         GlStateManager.enableCull();
  69.        
  70.     }
  71.    
  72.    
  73.     private void renderBody(TileMetamorphicTable te) {
  74.         GlStateManager.pushMatrix();
  75.  
  76.         GlStateManager.translate(-0.5, -0.5, -0.5);
  77.  
  78.         RenderHelper.disableStandardItemLighting();
  79.         this.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
  80.  
  81.         World world = getWorld();
  82.         GlStateManager.translate(-te.getPos().getX(), -te.getPos().getY(), -te.getPos().getZ());
  83.  
  84.         Tessellator tessellator = Tessellator.getInstance();
  85.         tessellator.getBuffer().begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
  86.         Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModel(
  87.                 world,
  88.                 getBakedModel(),
  89.                 world.getBlockState(te.getPos()),
  90.                 te.getPos(),
  91.                 Tessellator.getInstance().getBuffer(), false);
  92.         tessellator.draw();
  93.  
  94.         RenderHelper.enableStandardItemLighting();
  95.         GlStateManager.popMatrix();
  96.     }
  97.    
  98.    
  99.     private void renderItem(TileMetamorphicTable te){
  100.         BlockMetamorphicTable block = (BlockMetamorphicTable) te.getWorld().getBlockState(te.getPos()).getBlock();
  101.         if(block.isBlocked(getWorld(), te.getPos()))
  102.             return;
  103.            
  104.         EntityPlayer player = te.getWorld().getClosestPlayer(te.getPos().getX(), te.getPos().getY(), te.getPos().getZ(), 32, false);
  105.         if(player != null){
  106.             ItemStack stack = player.getHeldItemMainhand();
  107.             if (stack != null && te.hasValidInput(stack)) {
  108.                 GlStateManager.pushMatrix();
  109.                 GlStateManager.translate(0, 0.6, 0);
  110.                 GlStateManager.scale(.35f, .35f, .35f);
  111.                 long angle = (System.currentTimeMillis() / 10) % 360;
  112.                 GlStateManager.rotate(angle, 0, 1, 0);
  113.                
  114.                 GL11.glEnable(GL11.GL_BLEND);
  115.                 GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);
  116.                
  117.  
  118.                 Minecraft.getMinecraft().getRenderItem().renderItem(te.getOutputFromInput(stack), ItemCameraTransforms.TransformType.NONE);
  119.                 GL11.glDisable(GL11.GL_BLEND);
  120.                 GlStateManager.popMatrix();
  121.             }
  122.         }
  123.     }
  124.    
  125.    
  126.     private void renderFrame(TileMetamorphicTable te){
  127.         GlStateManager.pushMatrix();
  128.         GlStateManager.translate(0, 0.1, 0);
  129.         GlStateManager.scale(.35f, .35f, .35f);
  130.  
  131.         Minecraft.getMinecraft().getRenderItem().renderItem(new ItemStack(Blocks.END_PORTAL_FRAME), ItemCameraTransforms.TransformType.NONE);
  132.         GlStateManager.popMatrix();
  133.     }
  134. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement