LightCoordsUtil.java

net.minecraft.util.LightCoordsUtil

信息

  • 全限定名:net.minecraft.util.LightCoordsUtil
  • 类型:public class
  • 包:net.minecraft.util
  • 源码路径:src/main/java/net/minecraft/util/LightCoordsUtil.java
  • 起始行号:L3
  • 职责:

    TODO

字段/常量

  • FULL_BRIGHT

    • 类型: int
    • 修饰符: public static final
    • 源码定位: L4
    • 说明:

      TODO

  • FULL_SKY

    • 类型: int
    • 修饰符: public static final
    • 源码定位: L5
    • 说明:

      TODO

  • MAX_SMOOTH_LIGHT_LEVEL

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

      TODO

内部类/嵌套类型

构造器

方法

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

public static int pack(int block, int sky) @ L8

  • 方法名:pack
  • 源码定位:L8
  • 返回类型:int
  • 修饰符:public static

参数:

  • block: int
  • sky: int

说明:

TODO

public static int block(int packed) @ L12

  • 方法名:block
  • 源码定位:L12
  • 返回类型:int
  • 修饰符:public static

参数:

  • packed: int

说明:

TODO

public static int sky(int packed) @ L16

  • 方法名:sky
  • 源码定位:L16
  • 返回类型:int
  • 修饰符:public static

参数:

  • packed: int

说明:

TODO

public static int withBlock(int coords, int block) @ L20

  • 方法名:withBlock
  • 源码定位:L20
  • 返回类型:int
  • 修饰符:public static

参数:

  • coords: int
  • block: int

说明:

TODO

public static int smoothPack(int block, int sky) @ L24

  • 方法名:smoothPack
  • 源码定位:L24
  • 返回类型:int
  • 修饰符:public static

参数:

  • block: int
  • sky: int

说明:

TODO

public static int smoothBlock(int packed) @ L28

  • 方法名:smoothBlock
  • 源码定位:L28
  • 返回类型:int
  • 修饰符:public static

参数:

  • packed: int

说明:

TODO

public static int smoothSky(int packed) @ L32

  • 方法名:smoothSky
  • 源码定位:L32
  • 返回类型:int
  • 修饰符:public static

参数:

  • packed: int

说明:

TODO

public static int addSmoothBlockEmission(int lightCoords, float blockLightEmission) @ L36

  • 方法名:addSmoothBlockEmission
  • 源码定位:L36
  • 返回类型:int
  • 修饰符:public static

参数:

  • lightCoords: int
  • blockLightEmission: float

说明:

TODO

public static int max(int coords1, int coords2) @ L43

  • 方法名:max
  • 源码定位:L43
  • 返回类型:int
  • 修饰符:public static

参数:

  • coords1: int
  • coords2: int

说明:

TODO

public static int lightCoordsWithEmission(int lightCoords, int emission) @ L51

  • 方法名:lightCoordsWithEmission
  • 源码定位:L51
  • 返回类型:int
  • 修饰符:public static

参数:

  • lightCoords: int
  • emission: int

说明:

TODO

public static int smoothBlend(int neighbor1, int neighbor2, int neighbor3, int center) @ L61

  • 方法名:smoothBlend
  • 源码定位:L61
  • 返回类型:int
  • 修饰符:public static

参数:

  • neighbor1: int
  • neighbor2: int
  • neighbor3: int
  • center: int

说明:

TODO

public static int smoothWeightedBlend(int coords1, int coords2, int coords3, int coords4, float weight1, float weight2, float weight3, float weight4) @ L91

  • 方法名:smoothWeightedBlend
  • 源码定位:L91
  • 返回类型:int
  • 修饰符:public static

参数:

  • coords1: int
  • coords2: int
  • coords3: int
  • coords4: int
  • weight1: float
  • weight2: float
  • weight3: float
  • weight4: float

说明:

TODO

代码

public class LightCoordsUtil {
    public static final int FULL_BRIGHT = 15728880;
    public static final int FULL_SKY = 15728640;
    private static final int MAX_SMOOTH_LIGHT_LEVEL = 240;
 
    public static int pack(int block, int sky) {
        return block << 4 | sky << 20;
    }
 
    public static int block(int packed) {
        return packed >> 4 & 15;
    }
 
    public static int sky(int packed) {
        return packed >> 20 & 15;
    }
 
    public static int withBlock(int coords, int block) {
        return coords & 0xFF0000 | block << 4;
    }
 
    public static int smoothPack(int block, int sky) {
        return block & 0xFF | (sky & 0xFF) << 16;
    }
 
    public static int smoothBlock(int packed) {
        return packed & 0xFF;
    }
 
    public static int smoothSky(int packed) {
        return packed >> 16 & 0xFF;
    }
 
    public static int addSmoothBlockEmission(int lightCoords, float blockLightEmission) {
        blockLightEmission = Mth.clamp(blockLightEmission, 0.0F, 1.0F);
        int emittedBlock = (int)(Mth.clamp(blockLightEmission, 0.0F, 1.0F) * 240.0F);
        int block = Math.min(smoothBlock(lightCoords) + emittedBlock, 240);
        return smoothPack(block, smoothSky(lightCoords));
    }
 
    public static int max(int coords1, int coords2) {
        int block1 = block(coords1);
        int block2 = block(coords2);
        int sky1 = sky(coords1);
        int sky2 = sky(coords2);
        return pack(Math.max(block1, block2), Math.max(sky1, sky2));
    }
 
    public static int lightCoordsWithEmission(int lightCoords, int emission) {
        if (emission == 0) {
            return lightCoords;
        } else {
            int sky = Math.max(sky(lightCoords), emission);
            int block = Math.max(block(lightCoords), emission);
            return pack(block, sky);
        }
    }
 
    public static int smoothBlend(int neighbor1, int neighbor2, int neighbor3, int center) {
        if (sky(center) > 2 || block(center) > 2) {
            if (sky(neighbor1) == 0) {
                neighbor1 |= center & 0xFF0000;
            }
 
            if (block(neighbor1) == 0) {
                neighbor1 |= center & 0xFF;
            }
 
            if (sky(neighbor2) == 0) {
                neighbor2 |= center & 0xFF0000;
            }
 
            if (block(neighbor2) == 0) {
                neighbor2 |= center & 0xFF;
            }
 
            if (sky(neighbor3) == 0) {
                neighbor3 |= center & 0xFF0000;
            }
 
            if (block(neighbor3) == 0) {
                neighbor3 |= center & 0xFF;
            }
        }
 
        return neighbor1 + neighbor2 + neighbor3 + center >> 2 & 16711935;
    }
 
    public static int smoothWeightedBlend(int coords1, int coords2, int coords3, int coords4, float weight1, float weight2, float weight3, float weight4) {
        int sky = (int)(smoothSky(coords1) * weight1 + smoothSky(coords2) * weight2 + smoothSky(coords3) * weight3 + smoothSky(coords4) * weight4);
        int block = (int)(smoothBlock(coords1) * weight1 + smoothBlock(coords2) * weight2 + smoothBlock(coords3) * weight3 + smoothBlock(coords4) * weight4);
        return smoothPack(block, sky);
    }
}

引用的其他类

  • Mth
    • 引用位置: 方法调用
    • 关联成员: Mth.clamp()