Advertisement
Camellias_

Untitled

Jun 20th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.15 KB | None | 0 0
  1.     @SubscribeEvent
  2.     public static void onTextureStitch(final TextureStitchEvent.Pre event)
  3.     {
  4.         final TextureMap map = event.getMap();
  5.        
  6.         if(map == Minecraft.getMinecraft().getTextureMapBlocks())
  7.         {
  8.             map.setTextureEntry(new AlphaSprite(new ResourceLocation(Reference.MODID, "items/glyphs/glyph_1")));
  9.         }
  10.     }
  11.    
  12.     static class AlphaSprite extends TextureAtlasSprite
  13.     {
  14.         private AnimationMetadataSection animationMetadata;
  15.        
  16.         AlphaSprite(final ResourceLocation name)
  17.         {
  18.             super(name.toString());
  19.         }
  20.        
  21.         @Override
  22.         public void updateAnimation()
  23.         {
  24.             ++this.tickCounter;
  25.            
  26.             if(this.tickCounter >= this.animationMetadata.getFrameTimeSingle(this.frameCounter))
  27.             {
  28.                 int i = this.animationMetadata.getFrameIndex(this.frameCounter);
  29.                 int j = this.animationMetadata.getFrameCount() == 0 ? this.framesTextureData.size() : this.animationMetadata.getFrameCount();
  30.                 this.frameCounter = (this.frameCounter + 1) % j;
  31.                 this.tickCounter = 0;
  32.                 int k = this.animationMetadata.getFrameIndex(this.frameCounter);
  33.                
  34.                 if(i != k && k >= 0 && k < this.framesTextureData.size())
  35.                 {
  36.                     TextureUtil.uploadTextureMipmap(this.framesTextureData.get(k), this.width, this.height, this.originX, this.originY, false, false);
  37.                 }
  38.             }
  39.             else if(this.animationMetadata.isInterpolate())
  40.             {
  41.                 this.updateAnimationInterpolated();
  42.             }
  43.         }
  44.        
  45.         private void updateAnimationInterpolated()
  46.         {
  47.             double d0 = 1.0D - (double)this.tickCounter / (double)this.animationMetadata.getFrameTimeSingle(this.frameCounter);
  48.             int i = this.animationMetadata.getFrameIndex(this.frameCounter);
  49.             int j = this.animationMetadata.getFrameCount() == 0 ? this.framesTextureData.size() : this.animationMetadata.getFrameCount();
  50.             int k = this.animationMetadata.getFrameIndex((this.frameCounter + 1) % j);
  51.  
  52.             if(i != k && k >= 0 && k < this.framesTextureData.size())
  53.             {
  54.                 int[][] aint = this.framesTextureData.get(i);
  55.                 int[][] aint1 = this.framesTextureData.get(k);
  56.  
  57.                 if(this.interpolatedFrameData == null || this.interpolatedFrameData.length != aint.length)
  58.                 {
  59.                     this.interpolatedFrameData = new int[aint.length][];
  60.                 }
  61.  
  62.                 for(int l = 0; l < aint.length; ++l)
  63.                 {
  64.                     if(this.interpolatedFrameData[l] == null)
  65.                     {
  66.                         this.interpolatedFrameData[l] = new int[aint[l].length];
  67.                     }
  68.  
  69.                     if(l < aint1.length && aint1[l].length == aint[l].length)
  70.                     {
  71.                         for(int i1 = 0; i1 < aint[l].length; ++i1)
  72.                         {
  73.                             int j1 = aint[l][i1];
  74.                             int k1 = aint1[l][i1];
  75.                             int a = this.interpolateColor(d0, j1 >> 24 & 255, k1 >> 24 & 255);
  76.                             int r = this.interpolateColor(d0, j1 >> 16 & 255, k1 >> 16 & 255);
  77.                             int g = this.interpolateColor(d0, j1 >> 8 & 255, k1 >> 8 & 255);
  78.                             int b = this.interpolateColor(d0, j1 & 255, k1 & 255);
  79.                             this.interpolatedFrameData[l][i1] = a << 24 | r << 16 | g << 8 | b;
  80.                         }
  81.                     }
  82.                 }
  83.  
  84.                 TextureUtil.uploadTextureMipmap(this.interpolatedFrameData, this.width, this.height, this.originX, this.originY, false, false);
  85.             }
  86.         }
  87.        
  88.         private int interpolateColor(double d0, int i1, int i2)
  89.         {
  90.             return (int)(d0 * (double)i1 + (1.0D - d0) * (double)i2);
  91.         }
  92.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement