Advertisement
tahg

Untitled

Aug 29th, 2018
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. package com.tahgcraft.lca.client;
  2.  
  3. import java.awt.geom.Rectangle2D;
  4. import java.util.HashMap;
  5.  
  6. import org.lwjgl.opengl.GL11;
  7.  
  8. import com.tahgcraft.lca.common.LCA;
  9. import com.tahgcraft.lca.common.TileEntityHybridProjector;
  10.  
  11. import net.minecraft.block.Block;
  12. import net.minecraft.client.model.PositionTextureVertex;
  13. import net.minecraft.client.model.TexturedQuad;
  14. import net.minecraft.client.renderer.Tessellator;
  15. import net.minecraft.client.renderer.entity.RenderItem;
  16. import net.minecraft.client.renderer.entity.RenderManager;
  17. import net.minecraft.client.renderer.texture.SimpleTexture;
  18. import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
  19. import net.minecraft.entity.item.EntityItem;
  20. import net.minecraft.item.Item;
  21. import net.minecraft.item.ItemStack;
  22. import net.minecraft.tileentity.TileEntity;
  23. import net.minecraft.util.ResourceLocation;
  24. import net.minecraft.util.Vec3;
  25.  
  26. public class TileEntityHybridProjectorRenderer extends TileEntitySpecialRenderer {
  27. private static final ResourceLocation RSC_PROJECTOR = new ResourceLocation("lca:textures/entities/projector.png");
  28. static HashMap<ResourceLocation, SimpleTexture> textures = new HashMap<ResourceLocation, SimpleTexture>();
  29. ModelProjector projector = new ModelProjector();
  30. RenderItem ri = null;
  31. TexturedQuad quad = new TexturedQuad(new PositionTextureVertex[] {
  32. new PositionTextureVertex(-.5F, -.5F, 0, 0, 0),
  33. new PositionTextureVertex(.5F, -.5F, 0, 1, 0),
  34. new PositionTextureVertex(.5F, .5F, 0, 1, 1),
  35. new PositionTextureVertex(-.5F, .5F, 0, 0, 1)});
  36.  
  37. public void renderTileEntityAt(TileEntityHybridProjector entity, double x, double y, double z, float f) {
  38. int meta = entity.getWorldObj().getBlockMetadata(entity.xCoord, entity.yCoord, entity.zCoord);
  39. int dir = meta & 3;
  40. Block block = entity.getWorldObj().getBlock(entity.xCoord, entity.yCoord, entity.zCoord);
  41. bindTexture(RSC_PROJECTOR);
  42. GL11.glPushMatrix();
  43. GL11.glTranslated(x + .5, y + .5, z + .5);
  44. GL11.glScaled(1, -1, -1);
  45. GL11.glColor3f(1, 1, 1);
  46. GL11.glRotated(90 * (dir + 2), 0, 1, 0);
  47. if (block == LCA.blockVerticalProjector) {
  48. GL11.glRotated(90, 1, 0, 0);
  49. }
  50.  
  51. if (entity.location == null) entity.setPictureLocation();
  52. ResourceLocation location = entity.location;
  53. projector.renderAll(location != null);
  54.  
  55. if (block == LCA.blockVerticalProjector) {
  56. GL11.glRotated(-90, 1, 0, 0);
  57. }
  58. if (location != null && entity.hasPower()) {
  59. String name = entity.getRawImageName();
  60. int dmgOffset = name.indexOf('@');
  61. int damage = 0;
  62. if (dmgOffset > 0) {
  63. try {
  64. damage = Integer.parseInt(name.substring(dmgOffset + 1));
  65. }
  66. catch (Exception e) {
  67. }
  68. name = name.substring(0, dmgOffset);
  69. }
  70. Item item = (Item)Item.itemRegistry.getObject(name);
  71. Vec3 center = entity.getCenter();
  72. Vec3 size = entity.getSize();
  73. GL11.glTranslated(-center.xCoord, -center.yCoord, center.zCoord + .5);
  74. double yaw = entity.getRotation();
  75. double scale = entity.getScale();
  76. if (entity.getPeriod() != 0)
  77. yaw += (entity.getWorldObj().getTotalWorldTime() + f) / entity.getPeriod() / 20 * 360;
  78. GL11.glRotated(yaw, 0, 1, 0);
  79. if (item != null) {
  80. GL11.glScaled(-scale, -scale, scale);
  81. if (ri == null) {
  82. ri = new StaticRenderItem();
  83. ri.setRenderManager(RenderManager.instance);
  84. }
  85. EntityItem ei = new EntityItem(entity.getWorldObj(), 0, 0, 0, new ItemStack(item, 1, damage));
  86. ri.doRender(ei, 0, 0, 0, 0, 0);
  87. }
  88. else {
  89. GL11.glScaled(-size.xCoord * scale, size.yCoord * scale, 1);
  90. GL11.glDisable(GL11.GL_CULL_FACE);
  91. bindTexture(location);
  92. Rectangle2D.Double tex = entity.getTexCoords();
  93. quad.vertexPositions[0] = quad.vertexPositions[0].setTexturePosition((float) tex.getX(), (float) tex.getY());
  94. quad.vertexPositions[1] = quad.vertexPositions[1].setTexturePosition((float) (tex.getX() + tex.getWidth()), (float) tex.getY());
  95. quad.vertexPositions[2] = quad.vertexPositions[2].setTexturePosition((float) (tex.getX() + tex.getWidth()), (float) (tex.getY() + tex.getHeight()));
  96. quad.vertexPositions[3] = quad.vertexPositions[3].setTexturePosition((float) tex.getX(), (float) (tex.getY() + tex.getHeight()));
  97. GL11.glEnable(GL11.GL_BLEND);
  98. GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
  99. quad.draw(Tessellator.instance, 1);
  100. GL11.glDisable(GL11.GL_BLEND);
  101. GL11.glEnable(GL11.GL_CULL_FACE);
  102. }
  103. }
  104. GL11.glPopMatrix();
  105. }
  106.  
  107. @Override
  108. public void renderTileEntityAt(TileEntity entity, double x, double y, double z, float f) {
  109. renderTileEntityAt((TileEntityHybridProjector)entity, x, y, z, f);
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement