| 1 | package net.minecraft.client.renderer.tileentity;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import com.google.common.collect.Maps;
|
| 5 | import java.util.Iterator;
|
| 6 | import java.util.List;
|
| 7 | import java.util.Map;
|
| 8 | import net.minecraft.client.Minecraft;
|
| 9 | import net.minecraft.client.model.ModelBanner;
|
| 10 | import net.minecraft.client.renderer.GlStateManager;
|
| 11 | import net.minecraft.client.renderer.texture.LayeredColorMaskTexture;
|
| 12 | import net.minecraft.init.Blocks;
|
| 13 | import net.minecraft.item.EnumDyeColor;
|
| 14 | import net.minecraft.tileentity.TileEntityBanner;
|
| 15 | import net.minecraft.util.BlockPos;
|
| 16 | import net.minecraft.util.MathHelper;
|
| 17 | import net.minecraft.util.ResourceLocation;
|
| 18 |
|
| 19 | public class TileEntityBannerRenderer extends TileEntitySpecialRenderer<TileEntityBanner>
|
| 20 | {
|
| 21 | private static final Map<String, TileEntityBannerRenderer.TimedBannerTexture> DESIGNS = Maps.<String, TileEntityBannerRenderer.TimedBannerTexture>newHashMap();
|
| 22 | private static final ResourceLocation BANNERTEXTURES = new ResourceLocation("textures/entity/banner_base.png");
|
| 23 | private ModelBanner bannerModel = new ModelBanner();
|
| 24 |
|
| 25 | public void renderTileEntityAt(TileEntityBanner te, double x, double y, double z, float partialTicks, int destroyStage)
|
| 26 | {
|
| 27 | boolean flag = te.getWorld() != null;
|
| 28 | boolean flag1 = !flag || te.getBlockType() == Blocks.standing_banner;
|
| 29 | int i = flag ? te.getBlockMetadata() : 0;
|
| 30 | long j = flag ? te.getWorld().getTotalWorldTime() : 0L;
|
| 31 | GlStateManager.pushMatrix();
|
| 32 | float f = 0.6666667F;
|
| 33 |
|
| 34 | if (flag1)
|
| 35 | {
|
| 36 | GlStateManager.translate((float)x + 0.5F, (float)y + 0.75F * f, (float)z + 0.5F);
|
| 37 | float f1 = (float)(i * 360) / 16.0F;
|
| 38 | GlStateManager.rotate(-f1, 0.0F, 1.0F, 0.0F);
|
| 39 | this.bannerModel.bannerStand.showModel = true;
|
| 40 | }
|
| 41 | else
|
| 42 | {
|
| 43 | float f2 = 0.0F;
|
| 44 |
|
| 45 | if (i == 2)
|
| 46 | {
|
| 47 | f2 = 180.0F;
|
| 48 | }
|
| 49 |
|
| 50 | if (i == 4)
|
| 51 | {
|
| 52 | f2 = 90.0F;
|
| 53 | }
|
| 54 |
|
| 55 | if (i == 5)
|
| 56 | {
|
| 57 | f2 = -90.0F;
|
| 58 | }
|
| 59 |
|
| 60 | GlStateManager.translate((float)x + 0.5F, (float)y - 0.25F * f, (float)z + 0.5F);
|
| 61 | GlStateManager.rotate(-f2, 0.0F, 1.0F, 0.0F);
|
| 62 | GlStateManager.translate(0.0F, -0.3125F, -0.4375F);
|
| 63 | this.bannerModel.bannerStand.showModel = false;
|
| 64 | }
|
| 65 |
|
| 66 | BlockPos blockpos = te.getPos();
|
| 67 | float f3 = (float)(blockpos.getX() * 7 + blockpos.getY() * 9 + blockpos.getZ() * 13) + (float)j + partialTicks;
|
| 68 | this.bannerModel.bannerSlate.rotateAngleX = (-0.0125F + 0.01F * MathHelper.cos(f3 * (float)Math.PI * 0.02F)) * (float)Math.PI;
|
| 69 | GlStateManager.enableRescaleNormal();
|
| 70 | ResourceLocation resourcelocation = this.func_178463_a(te);
|
| 71 |
|
| 72 | if (resourcelocation != null)
|
| 73 | {
|
| 74 | this.bindTexture(resourcelocation);
|
| 75 | GlStateManager.pushMatrix();
|
| 76 | GlStateManager.scale(f, -f, -f);
|
| 77 | this.bannerModel.renderBanner();
|
| 78 | GlStateManager.popMatrix();
|
| 79 | }
|
| 80 |
|
| 81 | GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
| 82 | GlStateManager.popMatrix();
|
| 83 | }
|
| 84 |
|
| 85 | private ResourceLocation func_178463_a(TileEntityBanner bannerObj)
|
| 86 | {
|
| 87 | String s = bannerObj.getPatternResourceLocation();
|
| 88 |
|
| 89 | if (s.isEmpty())
|
| 90 | {
|
| 91 | return null;
|
| 92 | }
|
| 93 | else
|
| 94 | {
|
| 95 | TileEntityBannerRenderer.TimedBannerTexture tileentitybannerrenderer$timedbannertexture = (TileEntityBannerRenderer.TimedBannerTexture)DESIGNS.get(s);
|
| 96 |
|
| 97 | if (tileentitybannerrenderer$timedbannertexture == null)
|
| 98 | {
|
| 99 | if (DESIGNS.size() >= 256)
|
| 100 | {
|
| 101 | long i = System.currentTimeMillis();
|
| 102 | Iterator<String> iterator = DESIGNS.keySet().iterator();
|
| 103 |
|
| 104 | while (iterator.hasNext())
|
| 105 | {
|
| 106 | String s1 = (String)iterator.next();
|
| 107 | TileEntityBannerRenderer.TimedBannerTexture tileentitybannerrenderer$timedbannertexture1 = (TileEntityBannerRenderer.TimedBannerTexture)DESIGNS.get(s1);
|
| 108 |
|
| 109 | if (i - tileentitybannerrenderer$timedbannertexture1.systemTime > 60000L)
|
| 110 | {
|
| 111 | Minecraft.getMinecraft().getTextureManager().deleteTexture(tileentitybannerrenderer$timedbannertexture1.bannerTexture);
|
| 112 | iterator.remove();
|
| 113 | }
|
| 114 | }
|
| 115 |
|
| 116 | if (DESIGNS.size() >= 256)
|
| 117 | {
|
| 118 | return null;
|
| 119 | }
|
| 120 | }
|
| 121 |
|
| 122 | List<TileEntityBanner.EnumBannerPattern> list1 = bannerObj.getPatternList();
|
| 123 | List<EnumDyeColor> list = bannerObj.getColorList();
|
| 124 | List<String> list2 = Lists.<String>newArrayList();
|
| 125 |
|
| 126 | for (TileEntityBanner.EnumBannerPattern tileentitybanner$enumbannerpattern : list1)
|
| 127 | {
|
| 128 | list2.add("textures/entity/banner/" + tileentitybanner$enumbannerpattern.getPatternName() + ".png");
|
| 129 | }
|
| 130 |
|
| 131 | tileentitybannerrenderer$timedbannertexture = new TileEntityBannerRenderer.TimedBannerTexture();
|
| 132 | tileentitybannerrenderer$timedbannertexture.bannerTexture = new ResourceLocation(s);
|
| 133 | Minecraft.getMinecraft().getTextureManager().loadTexture(tileentitybannerrenderer$timedbannertexture.bannerTexture, new LayeredColorMaskTexture(BANNERTEXTURES, list2, list));
|
| 134 | DESIGNS.put(s, tileentitybannerrenderer$timedbannertexture);
|
| 135 | }
|
| 136 |
|
| 137 | tileentitybannerrenderer$timedbannertexture.systemTime = System.currentTimeMillis();
|
| 138 | return tileentitybannerrenderer$timedbannertexture.bannerTexture;
|
| 139 | }
|
| 140 | }
|
| 141 |
|
| 142 | static class TimedBannerTexture
|
| 143 | {
|
| 144 | public long systemTime;
|
| 145 | public ResourceLocation bannerTexture;
|
| 146 |
|
| 147 | private TimedBannerTexture()
|
| 148 | {
|
| 149 | }
|
| 150 | }
|
| 151 | }
|
| 152 |
|