Skip to content

Commit

Permalink
Render block overlay fix based on state
Browse files Browse the repository at this point in the history
  • Loading branch information
jchung01 committed Aug 31, 2024
1 parent c5ddc55 commit 260f9ef
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,28 @@
import net.minecraft.util.math.BlockPos.MutableBlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.relauncher.Side;

import mod.acgaming.universaltweaks.UniversalTweaks;
import mod.acgaming.universaltweaks.config.UTConfigBugfixes;

// Courtesy of Meldexun
@Mod.EventBusSubscriber(modid = UniversalTweaks.MODID, value = Side.CLIENT)
public class UTBlockOverlay
{
/**
* Flag to only render block overlay when expected.
* Necessary as some other mods (i.e. Portal Gun) render the world an additional time sometime in the pass.
*/
private static boolean render = false;

public static boolean shouldRender()
{
return render;
}

public static void setRender(boolean value)
{
UTBlockOverlay.render = value;
}

@SuppressWarnings("deprecation")
public static void renderNearbyBlocks(float partialTicks)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public class UTBlockOverlayMixin
private Minecraft mc;

@Inject(method = "renderBlockLayer(Lnet/minecraft/util/BlockRenderLayer;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/ChunkRenderContainer;renderChunkLayer(Lnet/minecraft/util/BlockRenderLayer;)V"))
public void utBlockOverlay(BlockRenderLayer blockLayerIn, CallbackInfo info)
public void utRenderBlockOverlay(BlockRenderLayer blockLayerIn, CallbackInfo info)
{
if (!UTConfigBugfixes.BLOCKS.BLOCK_OVERLAY.utBlockOverlayToggle) return;
if (!UTConfigBugfixes.BLOCKS.BLOCK_OVERLAY.utBlockOverlayToggle || !UTBlockOverlay.shouldRender()) return;
if (UTConfigGeneral.DEBUG.utDebugToggle) UniversalTweaks.LOGGER.debug("UTBlockOverlay ::: Render block layer");
Block block = world.getBlockState(mc.player.getPosition().up()).getBlock();
if ((blockLayerIn == BlockRenderLayer.SOLID && !UTBlockOverlayLists.blacklistedBlocks.contains(block)) || UTBlockOverlayLists.whitelistedBlocks.contains(block))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package mod.acgaming.universaltweaks.bugfixes.blocks.blockoverlay.mixin;

import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.entity.Entity;
import net.minecraft.util.BlockRenderLayer;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import mod.acgaming.universaltweaks.bugfixes.blocks.blockoverlay.UTBlockOverlay;
import mod.acgaming.universaltweaks.config.UTConfigBugfixes;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Slice;

// Courtesy of jchung01
@Mixin(value = EntityRenderer.class)
public class UTEntityRendererMixin
{
@WrapOperation(method = "renderWorldPass",
slice = @Slice(from = @At(value = "FIELD", target = "Lnet/minecraft/util/BlockRenderLayer;SOLID:Lnet/minecraft/util/BlockRenderLayer;", opcode = Opcodes.GETSTATIC),
to = @At(value = "FIELD", target = "Lnet/minecraft/util/BlockRenderLayer;CUTOUT_MIPPED:Lnet/minecraft/util/BlockRenderLayer;", opcode = Opcodes.GETSTATIC)),
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderGlobal;renderBlockLayer(Lnet/minecraft/util/BlockRenderLayer;DILnet/minecraft/entity/Entity;)I"))
private int utSetBlockOverlayState(RenderGlobal instance, BlockRenderLayer layer, double partialTicks, int pass, Entity entity, Operation<Integer> original)
{
if (!UTConfigBugfixes.BLOCKS.BLOCK_OVERLAY.utBlockOverlayToggle) return original.call(instance, layer, partialTicks, pass, entity);
int ret;
UTBlockOverlay.setRender(true);
ret = original.call(instance, layer, partialTicks, pass, entity);
UTBlockOverlay.setRender(false);
return ret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"refmap": "universaltweaks.refmap.json",
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"client": ["UTBlockOverlayMixin"]
"client": ["UTBlockOverlayMixin", "UTEntityRendererMixin"]
}

0 comments on commit 260f9ef

Please sign in to comment.