ScreenEffectRenderer.java

net.minecraft.client.renderer.ScreenEffectRenderer

信息

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

    TODO

字段/常量

  • UNDERWATER_LOCATION

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

      TODO

  • minecraft

    • 类型: Minecraft
    • 修饰符: private final
    • 源码定位: L34
    • 说明:

      TODO

  • sprites

    • 类型: SpriteGetter
    • 修饰符: private final
    • 源码定位: L35
    • 说明:

      TODO

  • bufferSource

    • 类型: MultiBufferSource
    • 修饰符: private final
    • 源码定位: L36
    • 说明:

      TODO

  • ITEM_ACTIVATION_ANIMATION_LENGTH

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

      TODO

  • itemActivationItem

    • 类型: ItemStack
    • 修饰符: private
    • 源码定位: L38
    • 说明:

      TODO

  • itemActivationTicks

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

      TODO

  • itemActivationOffX

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

      TODO

  • itemActivationOffY

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

      TODO

内部类/嵌套类型

构造器

public ScreenEffectRenderer(Minecraft minecraft, SpriteGetter sprites, MultiBufferSource bufferSource) @ L43

  • 构造器名:ScreenEffectRenderer
  • 源码定位:L43
  • 修饰符:public

参数:

  • minecraft: Minecraft
  • sprites: SpriteGetter
  • bufferSource: MultiBufferSource

说明:

TODO

方法

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

public void tick() @ L49

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

参数:

说明:

TODO

public void renderScreenEffect(boolean isFirstPerson, boolean isSleeping, float partialTicks, SubmitNodeCollector submitNodeCollector, boolean hideGui) @ L58

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

参数:

  • isFirstPerson: boolean
  • isSleeping: boolean
  • partialTicks: float
  • submitNodeCollector: SubmitNodeCollector
  • hideGui: boolean

说明:

TODO

private void renderItemActivationAnimation(PoseStack poseStack, float partialTicks, SubmitNodeCollector submitNodeCollector) @ L86

  • 方法名:renderItemActivationAnimation
  • 源码定位:L86
  • 返回类型:void
  • 修饰符:private

参数:

  • poseStack: PoseStack
  • partialTicks: float
  • submitNodeCollector: SubmitNodeCollector

说明:

TODO

public void resetItemActivation() @ L113

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

参数:

说明:

TODO

public void displayItemActivation(ItemStack itemStack, RandomSource random) @ L117

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

参数:

  • itemStack: ItemStack
  • random: RandomSource

说明:

TODO

private static BlockState getViewBlockingState(Player player) @ L124

  • 方法名:getViewBlockingState
  • 源码定位:L124
  • 返回类型:BlockState
  • 修饰符:private static

参数:

  • player: Player

说明:

TODO

private static void renderTex(TextureAtlasSprite sprite, PoseStack poseStack, MultiBufferSource bufferSource) @ L141

  • 方法名:renderTex
  • 源码定位:L141
  • 返回类型:void
  • 修饰符:private static

参数:

  • sprite: TextureAtlasSprite
  • poseStack: PoseStack
  • bufferSource: MultiBufferSource

说明:

TODO

private static void renderWater(Minecraft minecraft, PoseStack poseStack, MultiBufferSource bufferSource) @ L161

  • 方法名:renderWater
  • 源码定位:L161
  • 返回类型:void
  • 修饰符:private static

参数:

  • minecraft: Minecraft
  • poseStack: PoseStack
  • bufferSource: MultiBufferSource

说明:

TODO

private static void renderFire(PoseStack poseStack, MultiBufferSource bufferSource, TextureAtlasSprite sprite) @ L181

  • 方法名:renderFire
  • 源码定位:L181
  • 返回类型:void
  • 修饰符:private static

参数:

  • poseStack: PoseStack
  • bufferSource: MultiBufferSource
  • sprite: TextureAtlasSprite

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class ScreenEffectRenderer {
    private static final Identifier UNDERWATER_LOCATION = Identifier.withDefaultNamespace("textures/misc/underwater.png");
    private final Minecraft minecraft;
    private final SpriteGetter sprites;
    private final MultiBufferSource bufferSource;
    public static final int ITEM_ACTIVATION_ANIMATION_LENGTH = 40;
    private @Nullable ItemStack itemActivationItem;
    private int itemActivationTicks;
    private float itemActivationOffX;
    private float itemActivationOffY;
 
    public ScreenEffectRenderer(Minecraft minecraft, SpriteGetter sprites, MultiBufferSource bufferSource) {
        this.minecraft = minecraft;
        this.sprites = sprites;
        this.bufferSource = bufferSource;
    }
 
    public void tick() {
        if (this.itemActivationTicks > 0) {
            this.itemActivationTicks--;
            if (this.itemActivationTicks == 0) {
                this.itemActivationItem = null;
            }
        }
    }
 
    public void renderScreenEffect(boolean isFirstPerson, boolean isSleeping, float partialTicks, SubmitNodeCollector submitNodeCollector, boolean hideGui) {
        PoseStack poseStack = new PoseStack();
        Player player = this.minecraft.player;
        if (isFirstPerson && !isSleeping) {
            if (!player.noPhysics) {
                BlockState blockState = getViewBlockingState(player);
                if (blockState != null) {
                    renderTex(this.minecraft.getModelManager().getBlockStateModelSet().getParticleMaterial(blockState).sprite(), poseStack, this.bufferSource);
                }
            }
 
            if (!this.minecraft.player.isSpectator()) {
                if (this.minecraft.player.isEyeInFluid(FluidTags.WATER)) {
                    renderWater(this.minecraft, poseStack, this.bufferSource);
                }
 
                if (this.minecraft.player.isOnFire()) {
                    TextureAtlasSprite fireSprite = this.sprites.get(ModelBakery.FIRE_1);
                    renderFire(poseStack, this.bufferSource, fireSprite);
                }
            }
        }
 
        if (!hideGui) {
            this.renderItemActivationAnimation(poseStack, partialTicks, submitNodeCollector);
        }
    }
 
    private void renderItemActivationAnimation(PoseStack poseStack, float partialTicks, SubmitNodeCollector submitNodeCollector) {
        if (this.itemActivationItem != null && this.itemActivationTicks > 0) {
            int tick = 40 - this.itemActivationTicks;
            float scale = (tick + partialTicks) / 40.0F;
            float ts = scale * scale;
            float tc = scale * ts;
            float smoothScale = 10.25F * tc * ts - 24.95F * ts * ts + 25.5F * tc - 13.8F * ts + 4.0F * scale;
            float piScale = smoothScale * (float) Math.PI;
            WindowRenderState windowState = this.minecraft.gameRenderer.getGameRenderState().windowRenderState;
            float aspectRatio = (float)windowState.width / windowState.height;
            float offX = this.itemActivationOffX * 0.3F * aspectRatio;
            float offY = this.itemActivationOffY * 0.3F;
            poseStack.pushPose();
            poseStack.translate(offX * Mth.abs(Mth.sin(piScale * 2.0F)), offY * Mth.abs(Mth.sin(piScale * 2.0F)), -10.0F + 9.0F * Mth.sin(piScale));
            float size = 0.8F;
            poseStack.scale(0.8F, 0.8F, 0.8F);
            poseStack.mulPose(Axis.YP.rotationDegrees(900.0F * Mth.abs(Mth.sin(piScale))));
            poseStack.mulPose(Axis.XP.rotationDegrees(6.0F * Mth.cos(scale * 8.0F)));
            poseStack.mulPose(Axis.ZP.rotationDegrees(6.0F * Mth.cos(scale * 8.0F)));
            this.minecraft.gameRenderer.getLighting().setupFor(Lighting.Entry.ITEMS_3D);
            ItemStackRenderState itemState = new ItemStackRenderState();
            this.minecraft.getItemModelResolver().updateForTopItem(itemState, this.itemActivationItem, ItemDisplayContext.FIXED, this.minecraft.level, null, 0);
            itemState.submit(poseStack, submitNodeCollector, 15728880, OverlayTexture.NO_OVERLAY, 0);
            poseStack.popPose();
        }
    }
 
    public void resetItemActivation() {
        this.itemActivationItem = null;
    }
 
    public void displayItemActivation(ItemStack itemStack, RandomSource random) {
        this.itemActivationItem = itemStack;
        this.itemActivationTicks = 40;
        this.itemActivationOffX = random.nextFloat() * 2.0F - 1.0F;
        this.itemActivationOffY = random.nextFloat() * 2.0F - 1.0F;
    }
 
    private static @Nullable BlockState getViewBlockingState(Player player) {
        BlockPos.MutableBlockPos testPos = new BlockPos.MutableBlockPos();
 
        for (int i = 0; i < 8; i++) {
            double xo = player.getX() + ((i >> 0) % 2 - 0.5F) * player.getBbWidth() * 0.8F;
            double yo = player.getEyeY() + ((i >> 1) % 2 - 0.5F) * 0.1F * player.getScale();
            double zo = player.getZ() + ((i >> 2) % 2 - 0.5F) * player.getBbWidth() * 0.8F;
            testPos.set(xo, yo, zo);
            BlockState blockState = player.level().getBlockState(testPos);
            if (blockState.getRenderShape() != RenderShape.INVISIBLE && blockState.isViewBlocking(player.level(), testPos)) {
                return blockState;
            }
        }
 
        return null;
    }
 
    private static void renderTex(TextureAtlasSprite sprite, PoseStack poseStack, MultiBufferSource bufferSource) {
        float br = 0.1F;
        int color = ARGB.colorFromFloat(1.0F, 0.1F, 0.1F, 0.1F);
        float x0 = -1.0F;
        float x1 = 1.0F;
        float y0 = -1.0F;
        float y1 = 1.0F;
        float z0 = -0.5F;
        float u0 = sprite.getU0();
        float u1 = sprite.getU1();
        float v0 = sprite.getV0();
        float v1 = sprite.getV1();
        Matrix4f pose = poseStack.last().pose();
        VertexConsumer builder = bufferSource.getBuffer(RenderTypes.blockScreenEffect(sprite.atlasLocation()));
        builder.addVertex(pose, -1.0F, -1.0F, -0.5F).setUv(u1, v1).setColor(color);
        builder.addVertex(pose, 1.0F, -1.0F, -0.5F).setUv(u0, v1).setColor(color);
        builder.addVertex(pose, 1.0F, 1.0F, -0.5F).setUv(u0, v0).setColor(color);
        builder.addVertex(pose, -1.0F, 1.0F, -0.5F).setUv(u1, v0).setColor(color);
    }
 
    private static void renderWater(Minecraft minecraft, PoseStack poseStack, MultiBufferSource bufferSource) {
        BlockPos pos = BlockPos.containing(minecraft.player.getX(), minecraft.player.getEyeY(), minecraft.player.getZ());
        float br = Lightmap.getBrightness(minecraft.player.level().dimensionType(), minecraft.player.level().getMaxLocalRawBrightness(pos));
        int color = ARGB.colorFromFloat(0.1F, br, br, br);
        float size = 4.0F;
        float x0 = -1.0F;
        float x1 = 1.0F;
        float y0 = -1.0F;
        float y1 = 1.0F;
        float z0 = -0.5F;
        float uo = -minecraft.player.getYRot() / 64.0F;
        float vo = minecraft.player.getXRot() / 64.0F;
        Matrix4f pose = poseStack.last().pose();
        VertexConsumer builder = bufferSource.getBuffer(RenderTypes.blockScreenEffect(UNDERWATER_LOCATION));
        builder.addVertex(pose, -1.0F, -1.0F, -0.5F).setUv(4.0F + uo, 4.0F + vo).setColor(color);
        builder.addVertex(pose, 1.0F, -1.0F, -0.5F).setUv(0.0F + uo, 4.0F + vo).setColor(color);
        builder.addVertex(pose, 1.0F, 1.0F, -0.5F).setUv(0.0F + uo, 0.0F + vo).setColor(color);
        builder.addVertex(pose, -1.0F, 1.0F, -0.5F).setUv(4.0F + uo, 0.0F + vo).setColor(color);
    }
 
    private static void renderFire(PoseStack poseStack, MultiBufferSource bufferSource, TextureAtlasSprite sprite) {
        VertexConsumer builder = bufferSource.getBuffer(RenderTypes.fireScreenEffect(sprite.atlasLocation()));
        float u0 = sprite.getU0();
        float u1 = sprite.getU1();
        float v0 = sprite.getV0();
        float v1 = sprite.getV1();
        float size = 1.0F;
 
        for (int i = 0; i < 2; i++) {
            poseStack.pushPose();
            float x0 = -0.5F;
            float x1 = 0.5F;
            float y0 = -0.5F;
            float y1 = 0.5F;
            float z0 = -0.5F;
            poseStack.translate(-(i * 2 - 1) * 0.24F, -0.3F, 0.0F);
            poseStack.mulPose(Axis.YP.rotationDegrees((i * 2 - 1) * 10.0F));
            Matrix4f pose = poseStack.last().pose();
            builder.addVertex(pose, -0.5F, -0.5F, -0.5F).setUv(u1, v1).setColor(1.0F, 1.0F, 1.0F, 0.9F);
            builder.addVertex(pose, 0.5F, -0.5F, -0.5F).setUv(u0, v1).setColor(1.0F, 1.0F, 1.0F, 0.9F);
            builder.addVertex(pose, 0.5F, 0.5F, -0.5F).setUv(u0, v0).setColor(1.0F, 1.0F, 1.0F, 0.9F);
            builder.addVertex(pose, -0.5F, 0.5F, -0.5F).setUv(u1, v0).setColor(1.0F, 1.0F, 1.0F, 0.9F);
            poseStack.popPose();
        }
    }
}

引用的其他类

  • PoseStack

    • 引用位置: 参数/构造调用
    • 关联成员: PoseStack()
  • Minecraft

    • 引用位置: 参数/字段
  • Lightmap

    • 引用位置: 方法调用
    • 关联成员: Lightmap.getBrightness()
  • MultiBufferSource

    • 引用位置: 参数/字段
  • SubmitNodeCollector

    • 引用位置: 参数
  • ItemStackRenderState

    • 引用位置: 构造调用
    • 关联成员: ItemStackRenderState()
  • RenderTypes

    • 引用位置: 方法调用
    • 关联成员: RenderTypes.blockScreenEffect(), RenderTypes.fireScreenEffect()
  • TextureAtlasSprite

    • 引用位置: 参数
  • SpriteGetter

    • 引用位置: 参数/字段
  • BlockPos

    • 引用位置: 方法调用/构造调用
    • 关联成员: BlockPos.MutableBlockPos(), BlockPos.containing(), MutableBlockPos()
  • Identifier

    • 引用位置: 字段/方法调用
    • 关联成员: Identifier.withDefaultNamespace()
  • ARGB

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

    • 引用位置: 方法调用
    • 关联成员: Mth.abs(), Mth.cos(), Mth.sin()
  • RandomSource

    • 引用位置: 参数
  • Player

    • 引用位置: 参数
  • ItemStack

    • 引用位置: 参数/字段
  • BlockState

    • 引用位置: 返回值