TextureAtlasSprite.java

net.minecraft.client.renderer.texture.TextureAtlasSprite

信息

  • 全限定名:net.minecraft.client.renderer.texture.TextureAtlasSprite
  • 类型:public class
  • 包:net.minecraft.client.renderer.texture
  • 源码路径:src/main/java/net/minecraft/client/renderer/texture/TextureAtlasSprite.java
  • 起始行号:L18
  • 实现:AutoCloseable
  • 职责:

    TODO

字段/常量

  • atlasLocation

    • 类型: Identifier
    • 修饰符: private final
    • 源码定位: L19
    • 说明:

      TODO

  • contents

    • 类型: SpriteContents
    • 修饰符: private final
    • 源码定位: L20
    • 说明:

      TODO

  • x

    • 类型: int
    • 修饰符: private final
    • 源码定位: L21
    • 说明:

      TODO

  • y

    • 类型: int
    • 修饰符: private final
    • 源码定位: L22
    • 说明:

      TODO

  • u0

    • 类型: float
    • 修饰符: private final
    • 源码定位: L23
    • 说明:

      TODO

  • u1

    • 类型: float
    • 修饰符: private final
    • 源码定位: L24
    • 说明:

      TODO

  • v0

    • 类型: float
    • 修饰符: private final
    • 源码定位: L25
    • 说明:

      TODO

  • v1

    • 类型: float
    • 修饰符: private final
    • 源码定位: L26
    • 说明:

      TODO

  • padding

    • 类型: int
    • 修饰符: private final
    • 源码定位: L27
    • 说明:

      TODO

内部类/嵌套类型

构造器

protected TextureAtlasSprite(Identifier atlasLocation, SpriteContents contents, int atlasWidth, int atlasHeight, int x, int y, int padding) @ L29

  • 构造器名:TextureAtlasSprite
  • 源码定位:L29
  • 修饰符:protected

参数:

  • atlasLocation: Identifier
  • contents: SpriteContents
  • atlasWidth: int
  • atlasHeight: int
  • x: int
  • y: int
  • padding: int

说明:

TODO

方法

下面的方法块按源码顺序生成。

public int getX() @ L41

  • 方法名:getX
  • 源码定位:L41
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

public int getY() @ L45

  • 方法名:getY
  • 源码定位:L45
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

public float getU0() @ L49

  • 方法名:getU0
  • 源码定位:L49
  • 返回类型:float
  • 修饰符:public

参数:

说明:

TODO

public float getU1() @ L53

  • 方法名:getU1
  • 源码定位:L53
  • 返回类型:float
  • 修饰符:public

参数:

说明:

TODO

public SpriteContents contents() @ L57

  • 方法名:contents
  • 源码定位:L57
  • 返回类型:SpriteContents
  • 修饰符:public

参数:

说明:

TODO

public SpriteContents.AnimationState createAnimationState(GpuBufferSlice uboSlice, int spriteUboSize) @ L61

  • 方法名:createAnimationState
  • 源码定位:L61
  • 返回类型:SpriteContents.AnimationState
  • 修饰符:public

参数:

  • uboSlice: GpuBufferSlice
  • spriteUboSize: int

说明:

TODO

public Transparency transparency() @ L65

  • 方法名:transparency
  • 源码定位:L65
  • 返回类型:Transparency
  • 修饰符:public

参数:

说明:

TODO

public float getU(float offset) @ L69

  • 方法名:getU
  • 源码定位:L69
  • 返回类型:float
  • 修饰符:public

参数:

  • offset: float

说明:

TODO

public float getV0() @ L74

  • 方法名:getV0
  • 源码定位:L74
  • 返回类型:float
  • 修饰符:public

参数:

说明:

TODO

public float getV1() @ L78

  • 方法名:getV1
  • 源码定位:L78
  • 返回类型:float
  • 修饰符:public

参数:

说明:

TODO

public float getV(float offset) @ L82

  • 方法名:getV
  • 源码定位:L82
  • 返回类型:float
  • 修饰符:public

参数:

  • offset: float

说明:

TODO

public Identifier atlasLocation() @ L87

  • 方法名:atlasLocation
  • 源码定位:L87
  • 返回类型:Identifier
  • 修饰符:public

参数:

说明:

TODO

public String toString() @ L91

  • 方法名:toString
  • 源码定位:L91
  • 返回类型:String
  • 修饰符:public

参数:

说明:

TODO

public void uploadFirstFrame(GpuTexture destination, int level) @ L96

  • 方法名:uploadFirstFrame
  • 源码定位:L96
  • 返回类型:void
  • 修饰符:public

参数:

  • destination: GpuTexture
  • level: int

说明:

TODO

public VertexConsumer wrap(VertexConsumer buffer) @ L100

  • 方法名:wrap
  • 源码定位:L100
  • 返回类型:VertexConsumer
  • 修饰符:public

参数:

  • buffer: VertexConsumer

说明:

TODO

boolean isAnimated() @ L104

  • 方法名:isAnimated
  • 源码定位:L104
  • 返回类型:boolean
  • 修饰符:package-private

参数:

说明:

TODO

public void uploadSpriteUbo(ByteBuffer uboBuffer, int startOffset, int maxMipLevel, int atlasWidth, int atlasHeight, int spriteUboSize) @ L108

  • 方法名:uploadSpriteUbo
  • 源码定位:L108
  • 返回类型:void
  • 修饰符:public

参数:

  • uboBuffer: ByteBuffer
  • startOffset: int
  • maxMipLevel: int
  • atlasWidth: int
  • atlasHeight: int
  • spriteUboSize: int

说明:

TODO

public void close() @ L123

  • 方法名:close
  • 源码定位:L123
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class TextureAtlasSprite implements AutoCloseable {
    private final Identifier atlasLocation;
    private final SpriteContents contents;
    private final int x;
    private final int y;
    private final float u0;
    private final float u1;
    private final float v0;
    private final float v1;
    private final int padding;
 
    protected TextureAtlasSprite(Identifier atlasLocation, SpriteContents contents, int atlasWidth, int atlasHeight, int x, int y, int padding) {
        this.atlasLocation = atlasLocation;
        this.contents = contents;
        this.padding = padding;
        this.x = x;
        this.y = y;
        this.u0 = (float)(x + padding) / atlasWidth;
        this.u1 = (float)(x + padding + contents.width()) / atlasWidth;
        this.v0 = (float)(y + padding) / atlasHeight;
        this.v1 = (float)(y + padding + contents.height()) / atlasHeight;
    }
 
    public int getX() {
        return this.x;
    }
 
    public int getY() {
        return this.y;
    }
 
    public float getU0() {
        return this.u0;
    }
 
    public float getU1() {
        return this.u1;
    }
 
    public SpriteContents contents() {
        return this.contents;
    }
 
    public SpriteContents.@Nullable AnimationState createAnimationState(GpuBufferSlice uboSlice, int spriteUboSize) {
        return this.contents.createAnimationState(uboSlice, spriteUboSize);
    }
 
    public Transparency transparency() {
        return this.contents.transparency();
    }
 
    public float getU(float offset) {
        float diff = this.u1 - this.u0;
        return this.u0 + diff * offset;
    }
 
    public float getV0() {
        return this.v0;
    }
 
    public float getV1() {
        return this.v1;
    }
 
    public float getV(float offset) {
        float diff = this.v1 - this.v0;
        return this.v0 + diff * offset;
    }
 
    public Identifier atlasLocation() {
        return this.atlasLocation;
    }
 
    @Override
    public String toString() {
        return "TextureAtlasSprite{contents='" + this.contents + "', u0=" + this.u0 + ", u1=" + this.u1 + ", v0=" + this.v0 + ", v1=" + this.v1 + "}";
    }
 
    public void uploadFirstFrame(GpuTexture destination, int level) {
        this.contents.uploadFirstFrame(destination, level);
    }
 
    public VertexConsumer wrap(VertexConsumer buffer) {
        return new SpriteCoordinateExpander(buffer, this);
    }
 
    boolean isAnimated() {
        return this.contents.isAnimated();
    }
 
    public void uploadSpriteUbo(ByteBuffer uboBuffer, int startOffset, int maxMipLevel, int atlasWidth, int atlasHeight, int spriteUboSize) {
        for (int level = 0; level <= maxMipLevel; level++) {
            Std140Builder.intoBuffer(MemoryUtil.memSlice(uboBuffer, startOffset + level * spriteUboSize, spriteUboSize))
                .putMat4f(new Matrix4f().ortho2D(0.0F, atlasWidth >> level, 0.0F, atlasHeight >> level))
                .putMat4f(
                    new Matrix4f()
                        .translate(this.x >> level, this.y >> level, 0.0F)
                        .scale(this.contents.width() + this.padding * 2 >> level, this.contents.height() + this.padding * 2 >> level, 1.0F)
                )
                .putFloat((float)this.padding / this.contents.width())
                .putFloat((float)this.padding / this.contents.height())
                .putInt(level);
        }
    }
 
    @Override
    public void close() {
        this.contents.close();
    }
}

引用的其他类