Advertisement
Gamebuster

Untitled

Jul 9th, 2018
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.91 KB | None | 0 0
  1. package com.gamebuster19901.dungeonforge.client.render.tileentity;
  2.  
  3. import org.apache.logging.log4j.Level;
  4. import org.lwjgl.opengl.GL11;
  5.  
  6. import com.gamebuster19901.dungeonforge.Main;
  7. import com.gamebuster19901.dungeonforge.block.BlockWrapper;
  8. import com.gamebuster19901.dungeonforge.client.render.NonOccludedModel;
  9. import com.gamebuster19901.dungeonforge.tileentity.TileEntityChangeableBlock;
  10.  
  11. import net.minecraft.block.Block;
  12. import net.minecraft.block.material.Material;
  13. import net.minecraft.block.state.IBlockState;
  14.  
  15. import net.minecraft.client.Minecraft;
  16. import net.minecraft.client.entity.EntityPlayerSP;
  17. import net.minecraft.client.renderer.BlockRendererDispatcher;
  18. import net.minecraft.client.renderer.BufferBuilder;
  19. import net.minecraft.client.renderer.GlStateManager;
  20. import net.minecraft.client.renderer.RenderHelper;
  21. import net.minecraft.client.renderer.Tessellator;
  22. import net.minecraft.client.renderer.texture.TextureMap;
  23. import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
  24. import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
  25. import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
  26.  
  27. import net.minecraft.tileentity.TileEntity;
  28.  
  29. import net.minecraft.util.math.BlockPos;
  30. import net.minecraft.util.math.MathHelper;
  31. import net.minecraft.util.text.ITextComponent;
  32.  
  33. public class TileEntityChangeableBlockRenderer<T extends TileEntityChangeableBlock> extends TileEntitySpecialRenderer<TileEntityChangeableBlock> {
  34.     protected BlockRendererDispatcher renderer;
  35.     private boolean canRenderTE = true;
  36.    
  37.     @Override
  38.     public void render(TileEntityChangeableBlock te, double x, double y, double z, float partialTicks, int destroyStage, float alpha){
  39.         EntityPlayerSP player = Minecraft.getMinecraft().player;
  40.         ITextComponent itextcomponent = te.getHoverText(player);
  41.         this.setLightmapDisabled(true);
  42.         if (itextcomponent != null && this.rendererDispatcher.cameraHitResult != null && te.getPos().equals(this.rendererDispatcher.cameraHitResult.getBlockPos()))
  43.         {
  44.             if(player.isSneaking()) {
  45.                 this.drawNameplate(te, "When connected:", x, y + 0.3, z, 12);
  46.             }
  47.             else {
  48.                 this.drawNameplate(te, "When disconnected:", x, y + 0.3, z, 12);
  49.             }
  50.             this.drawNameplate(te, itextcomponent.getFormattedText(), x, y, z, 12);
  51.         }
  52.         renderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
  53.        
  54.         BlockWrapper wrapper = te.getDisplayingWrapper(Minecraft.getMinecraft().player);
  55.        
  56.         this.setLightmapDisabled(false);
  57.        
  58.         if(te == null || wrapper == null) {
  59.             return;
  60.         }
  61.        
  62.         Block block = wrapper.getBlock();
  63.         BlockPos blockpos = new BlockPos(0,0,0);
  64.         IBlockState blockState = block.getActualState(block.getStateFromMeta(wrapper.getMeta()), getWorld(), blockpos);
  65.         TileEntitySpecialRenderer wrappedRenderer = null;
  66.         if(block.hasTileEntity() && canRenderTE){
  67.             TileEntity wrappedTileEntity = block.createTileEntity(getWorld(), block.getActualState(block.getStateFromMeta(wrapper.getMeta()), getWorld(), new BlockPos(x,y,z)));
  68.             Class<TileEntity> wrappedTileEntityClass = (Class<TileEntity>) wrappedTileEntity.getClass();
  69.             if (wrappedTileEntity != null) {
  70.                 wrappedRenderer = TileEntityRendererDispatcher.instance.renderers.get(wrappedTileEntityClass);
  71.                 if(wrappedRenderer != null) {
  72.                     try {
  73.                         wrappedTileEntity.setWorld(getWorld());
  74.                         wrappedRenderer.render(wrappedTileEntity, x, y, z, partialTicks, destroyStage, alpha);
  75.                     }
  76.                     catch(Exception e) {
  77.                         UnsupportedOperationException ex = new UnsupportedOperationException("Could not render TileEntityDoorwayMarkerRenderer with nbt " + wrapper.getNBT(), e);
  78.                         Main.LOGGER.catching(Level.ERROR, ex);
  79.                         canRenderTE = false;
  80.                     }
  81.                 }
  82.             }
  83.         }
  84.        
  85.         Tessellator tessellator = Tessellator.getInstance();
  86.         BufferBuilder bufferbuilder = tessellator.getBuffer();
  87.  
  88.         if(block.getMaterial(blockState) != Material.AIR && wrappedRenderer == null || (wrappedRenderer != null && block.getBoundingBox(blockState, getWorld(), blockpos).equals(Block.FULL_BLOCK_AABB))){
  89.             this.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
  90.             RenderHelper.disableStandardItemLighting();
  91.             GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
  92.             GlStateManager.enableBlend();
  93.             GlStateManager.enableLighting();
  94.  
  95.             bufferbuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
  96.            
  97.             BlockPos tepos = te.getPos();
  98.            
  99.             bufferbuilder.setTranslation(x - tepos.getX(), tepos.getY(), tepos.getZ());
  100.            
  101.             if(partialTicks < 1.0F) {
  102.                 NonOccludedModel model = new NonOccludedModel(renderer.getModelForState(blockState));
  103.                 renderer.getBlockModelRenderer().renderModel(getWorld(), model, blockState, te.getPos(), bufferbuilder, false, MathHelper.getPositionRandom(blockpos));
  104.             }
  105.             tessellator.draw();
  106.             bufferbuilder.setTranslation(0.0D, 0.0D, 0.0D);
  107.             RenderHelper.enableStandardItemLighting();
  108.         }
  109.     }
  110.    
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement