Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.11 KB | None | 0 0
  1. /**
  2.  *
  3.  */
  4. package se.Matryoshika.Saligia.API.Rendering;
  5.  
  6. import org.lwjgl.opengl.GL11;
  7.  
  8. import net.minecraft.block.Block;
  9. import net.minecraft.client.Minecraft;
  10. import net.minecraft.client.renderer.GlStateManager;
  11. import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
  12. import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraftforge.fml.relauncher.Side;
  15. import net.minecraftforge.fml.relauncher.SideOnly;
  16. import se.Matryoshika.Saligia.API.Rituals.RitualRegistry;
  17. import se.Matryoshika.Saligia.Content.Tiles.TileRitual;
  18.  
  19. /**
  20.  * This class was created by Matryoshika Oct 1, 2016
  21.  * Property of Matryoshika.
  22.  * Part of the Saligia mod.
  23.  * May be viewed for educational purposes.
  24.  */
  25. @SideOnly(Side.CLIENT)
  26. public class RenderMultiblock extends TileEntitySpecialRenderer<TileRitual> {
  27.    
  28.    
  29.    
  30.    
  31.     @Override
  32.     public void renderTileEntityAt(TileRitual te, double x, double y, double z, float partialTicks, int destroyStage) {
  33.        
  34.         super.renderTileEntityAt(te, x, y, z, partialTicks, destroyStage);
  35.        
  36.         //Get the multiblock in an array of Object arrays from the registry, which consists of x, y, z, Block
  37.         Object[][] MULTIBLOCK = RitualRegistry.getMultiblock(te.renderMultiBlockKey);
  38.         if(MULTIBLOCK == null)
  39.             return;
  40.        
  41.         //If this tile isn't the one that was whacked with the Ritual Activator, return
  42.         if(!te.isClicked)
  43.             return;
  44.            
  45.         GlStateManager.pushAttrib();
  46.         GlStateManager.pushMatrix();
  47.  
  48.         GlStateManager.translate(x, y, z);
  49.         for(Object[] object : MULTIBLOCK){
  50.        
  51.             int dx = (Integer)object[0];
  52.             int dy = (Integer)object[1];
  53.             int dz = (Integer)object[2];
  54.             Block block =  (Block)  object[3];
  55.            
  56.             GlStateManager.translate(0.5, 0.5, 0.5);
  57.             GlStateManager.enableBlend();
  58.             //Render missing blocks as ghost-blocks
  59.             GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_COLOR);
  60.             if(te.getWorld().isAirBlock(te.getPos().add(dx, dy, dz)))
  61.                 renderMultiblock(te, dx, dy, dz, block);
  62.             //return to normal blend value
  63.             GL11.glBlendFunc(GL11.GL_ONE_MINUS_SRC_COLOR, GL11.GL_ONE);
  64.            
  65.             GlStateManager.disableBlend();
  66.             GlStateManager.translate(-0.5, -0.5, -0.5);
  67.            
  68.         }
  69.        
  70.        
  71.         GlStateManager.popMatrix();
  72.         GlStateManager.popAttrib();
  73.        
  74.     }
  75.    
  76.     private void renderMultiblock(TileRitual te, int dx, int dy, int dz, Block block){
  77.        
  78.         GlStateManager.pushMatrix();
  79.         //Spin me right round
  80.         long angle = (System.currentTimeMillis() / 40) % 360;
  81.        
  82.         //offset the rendered block from the Tile, using the Multiblock's registered x, y & z
  83.         GlStateManager.translate(dx, dy, dz);
  84.        
  85.         GlStateManager.scale(0.5, 0.5, 0.5);
  86.         GlStateManager.rotate(angle, 0, 1, 0);
  87.        
  88.         //Render the block in the world
  89.         Minecraft.getMinecraft().getRenderItem().renderItem(new ItemStack(block), ItemCameraTransforms.TransformType.NONE);
  90.        
  91.         //Un-rotate the rotation
  92.         GlStateManager.rotate(-angle, 0, 1, 0);
  93.         GlStateManager.scale(2, 2, 2);
  94.        
  95.         GlStateManager.translate(-dx, -dy, -dz);
  96.         GlStateManager.popMatrix();
  97.        
  98.     }
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement