Skip to content

Commit

Permalink
Add RenderUtils for block outline width
Browse files Browse the repository at this point in the history
  • Loading branch information
lowercasebtw committed Dec 22, 2024
1 parent 6dc2c4f commit f0dfe1b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import me.mixces.animatium.config.AnimatiumConfig;
import me.mixces.animatium.util.RenderUtils;
import net.minecraft.client.gl.ShaderProgram;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -11,10 +11,6 @@
public abstract class MixinShaderProgram {
@WrapOperation(method = "initializeUniforms", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;getShaderLineWidth()F"))
private float animatium$legacyBlockOutlineRendering$lineWidth(Operation<Float> original) {
if (AnimatiumConfig.getInstance().getLegacyBlockOutlineRendering()) {
return 2.0F;
} else {
return original.call();
}
return RenderUtils.getLineWidth(original.call());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
import me.mixces.animatium.mixins.accessor.ClientWorldPropertiesAccessor;
import me.mixces.animatium.mixins.accessor.SkyRenderingAccessor;
import me.mixces.animatium.util.MathUtils;
import me.mixces.animatium.util.RenderUtils;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gl.ShaderProgram;
import net.minecraft.client.gl.ShaderProgramKeys;
import net.minecraft.client.gl.VertexBuffer;
import net.minecraft.client.render.DimensionEffects;
import net.minecraft.client.render.Fog;
import net.minecraft.client.render.SkyRendering;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.render.*;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.math.BlockPos;
Expand Down Expand Up @@ -107,6 +105,20 @@ public abstract class MixinWorldRenderer {
}
}

@Inject(method = "renderTargetBlockOutline", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldRenderer;drawBlockOutline(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;Lnet/minecraft/entity/Entity;DDDLnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)V", shift = At.Shift.BEFORE))
private void animatium$setBlockOutlineWidth$on(Camera camera, VertexConsumerProvider.Immediate vertexConsumers, MatrixStack matrices, boolean translucent, CallbackInfo ci) {
if (AnimatiumConfig.getInstance().getLegacyBlockOutlineRendering()) {
RenderUtils.setLineWidth(2.0F);
}
}

@Inject(method = "renderTargetBlockOutline", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/VertexConsumerProvider$Immediate;drawCurrentLayer()V", shift = At.Shift.AFTER))
private void animatium$setBlockOutlineWidth$off(Camera camera, VertexConsumerProvider.Immediate vertexConsumers, MatrixStack matrices, boolean translucent, CallbackInfo ci) {
if (AnimatiumConfig.getInstance().getLegacyBlockOutlineRendering()) {
RenderUtils.setLineWidth(-1.0F);
}
}

@WrapOperation(method = "drawBlockOutline", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;getOutlineShape(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/ShapeContext;)Lnet/minecraft/util/shape/VoxelShape;"))
private VoxelShape animatium$legacyBlockOutlineRendering(BlockState instance, BlockView blockView, BlockPos blockPos, ShapeContext shapeContext, Operation<VoxelShape> original) {
VoxelShape shape = original.call(instance, blockView, blockPos, shapeContext);
Expand Down
24 changes: 24 additions & 0 deletions src/main/kotlin/me/mixces/animatium/util/RenderUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package me.mixces.animatium.util

import com.mojang.blaze3d.systems.RenderSystem

abstract class RenderUtils {
companion object {
private var lineWidth: Float = -1.0F

@JvmStatic
fun getLineWidth(): Float {
return if (lineWidth == -1.0F) RenderSystem.getShaderLineWidth() else lineWidth
}

@JvmStatic
fun getLineWidth(default: Float): Float {
return if (lineWidth == -1.0F) default else lineWidth
}

@JvmStatic
fun setLineWidth(width: Float) {
lineWidth = width
}
}
}

0 comments on commit f0dfe1b

Please sign in to comment.