From f855392db690a7c094ccbf426c157de1e0efdf33 Mon Sep 17 00:00:00 2001 From: ZANX3Y <74610540+ZANX3Y@users.noreply.github.com> Date: Sun, 22 Oct 2023 21:53:13 +0200 Subject: [PATCH 01/10] Make X-Ray fully compatible with Sodium --- build.gradle | 11 +++++ gradle.properties | 1 + .../mixin/SodiumBlockOcclusionCacheMixin.java | 20 ++++----- .../mixin/SodiumBlockRendererMixin.java | 42 +++++++++++++++++++ .../mixin/SodiumFluidRendererMixin.java | 42 +++++++++++++++++++ src/main/resources/wurst.mixins.json | 2 + 6 files changed, 106 insertions(+), 12 deletions(-) create mode 100644 src/main/java/net/wurstclient/mixin/SodiumBlockRendererMixin.java create mode 100644 src/main/java/net/wurstclient/mixin/SodiumFluidRendererMixin.java diff --git a/build.gradle b/build.gradle index f9c14b900d..84ee7559f9 100644 --- a/build.gradle +++ b/build.gradle @@ -24,6 +24,14 @@ repositories { // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. // See https://docs.gradle.org/current/userguide/declaring_repositories.html // for more information about repositories. + maven { + name = 'Modrinth' + url = 'https://api.modrinth.com/maven' + + content { + includeGroup "maven.modrinth" + } + } } dependencies { @@ -34,6 +42,9 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + + // Sodium, required for X-Ray compatibility. + modCompileOnly "maven.modrinth:sodium:${project.sodium_version}" // net.wurstclient.ai.PathPos extends net.minecraft.util.math.BlockPos, // which uses javax.annotation.concurrent.Immutable, which is part of diff --git a/gradle.properties b/gradle.properties index 26c3651a87..d6dd5de177 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,3 +18,4 @@ maven_group = net.wurstclient archives_base_name = Wurst-Client # Dependencies +sodium_version=mc1.20.2-0.5.3 diff --git a/src/main/java/net/wurstclient/mixin/SodiumBlockOcclusionCacheMixin.java b/src/main/java/net/wurstclient/mixin/SodiumBlockOcclusionCacheMixin.java index 6cef24cca6..f4e4399def 100644 --- a/src/main/java/net/wurstclient/mixin/SodiumBlockOcclusionCacheMixin.java +++ b/src/main/java/net/wurstclient/mixin/SodiumBlockOcclusionCacheMixin.java @@ -7,11 +7,7 @@ */ package net.wurstclient.mixin; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockOcclusionCache; import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; @@ -20,17 +16,17 @@ import net.wurstclient.event.EventManager; import net.wurstclient.events.ShouldDrawSideListener.ShouldDrawSideEvent; -@Pseudo -@Mixin(targets = { - "me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockOcclusionCache", - "me.jellysquid.mods.sodium.client.render.occlusion.BlockOcclusionCache"}, - remap = false) +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(value = BlockOcclusionCache.class, remap = false) public class SodiumBlockOcclusionCacheMixin { @Inject(at = @At("HEAD"), method = "shouldDrawSide", - cancellable = true, - remap = false) + cancellable = true) public void shouldDrawSide(BlockState state, BlockView world, BlockPos pos, Direction side, CallbackInfoReturnable cir) { diff --git a/src/main/java/net/wurstclient/mixin/SodiumBlockRendererMixin.java b/src/main/java/net/wurstclient/mixin/SodiumBlockRendererMixin.java new file mode 100644 index 0000000000..9046d28887 --- /dev/null +++ b/src/main/java/net/wurstclient/mixin/SodiumBlockRendererMixin.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2014-2023 Wurst-Imperium and contributors. + * + * This source code is subject to the terms of the GNU General Public + * License, version 3. If a copy of the GPL was not distributed with this + * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt + */ +package net.wurstclient.mixin; + +import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderContext; +import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderer; + +import net.minecraft.client.render.model.BakedQuad; +import net.minecraft.util.math.Direction; +import net.wurstclient.event.EventManager; +import net.wurstclient.events.ShouldDrawSideListener.ShouldDrawSideEvent; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.List; + +@Mixin(value = BlockRenderer.class, remap = false) +public class SodiumBlockRendererMixin +{ + @Inject(at = @At("HEAD"), + method = "getGeometry", + cancellable = true) + private void getGeometry(BlockRenderContext ctx, Direction face, + CallbackInfoReturnable> cir) + { + if (face != null) return; + + ShouldDrawSideEvent event = new ShouldDrawSideEvent(ctx.state(), ctx.pos()); + EventManager.fire(event); + + if (event.isRendered() != null && !event.isRendered()) + cir.setReturnValue(List.of()); + } +} diff --git a/src/main/java/net/wurstclient/mixin/SodiumFluidRendererMixin.java b/src/main/java/net/wurstclient/mixin/SodiumFluidRendererMixin.java new file mode 100644 index 0000000000..dd19c2afbe --- /dev/null +++ b/src/main/java/net/wurstclient/mixin/SodiumFluidRendererMixin.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2014-2023 Wurst-Imperium and contributors. + * + * This source code is subject to the terms of the GNU General Public + * License, version 3. If a copy of the GPL was not distributed with this + * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt + */ +package net.wurstclient.mixin; + +import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.FluidRenderer; + +import net.minecraft.block.BlockState; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.BlockRenderView; +import net.wurstclient.event.EventManager; +import net.wurstclient.events.ShouldDrawSideListener.ShouldDrawSideEvent; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(value = FluidRenderer.class, remap = false) +public class SodiumFluidRendererMixin +{ + @Inject(at = @At("HEAD"), + method = "isSideExposed", + cancellable = true) + private void isSideExposed(BlockRenderView world, + int x, int y, int z, Direction dir, float height, + CallbackInfoReturnable cir) + { + BlockPos pos = new BlockPos(x, y, z); + BlockState state = world.getBlockState(pos); + ShouldDrawSideEvent event = new ShouldDrawSideEvent(state, pos); + EventManager.fire(event); + + if(event.isRendered() != null) + cir.setReturnValue(event.isRendered()); + } +} diff --git a/src/main/resources/wurst.mixins.json b/src/main/resources/wurst.mixins.json index b650abf67c..3c2b8fc57e 100644 --- a/src/main/resources/wurst.mixins.json +++ b/src/main/resources/wurst.mixins.json @@ -54,6 +54,8 @@ "ShulkerBoxScreenMixin", "SimpleOptionMixin", "SodiumBlockOcclusionCacheMixin", + "SodiumBlockRendererMixin", + "SodiumFluidRendererMixin", "StatsScreenMixin", "StatusEffectInstanceMixin", "TelemetryManagerMixin", From 6d072577db2abeeb1c5bdf18eb3ad1730d845d06 Mon Sep 17 00:00:00 2001 From: ZANX3Y <74610540+ZANX3Y@users.noreply.github.com> Date: Thu, 26 Oct 2023 23:55:22 +0200 Subject: [PATCH 02/10] Modify Sodium X-Ray mixins No longer needs Sodium as a dependency. --- build.gradle | 11 ----- gradle.properties | 1 - .../ShouldDrawFacelessModelListener.java | 45 +++++++++++++++++++ .../java/net/wurstclient/hacks/XRayHack.java | 31 +++++++++---- ...erMixin.java => BasicBakedModelMixin.java} | 28 ++++++------ .../mixin/MultipartBakedModelMixin.java | 40 +++++++++++++++++ .../mixin/SodiumBlockOcclusionCacheMixin.java | 11 +++-- .../mixin/SodiumFluidRendererMixin.java | 11 +++-- .../mixin/WeightedBakedModelMixin.java | 40 +++++++++++++++++ src/main/resources/wurst.mixins.json | 4 +- 10 files changed, 179 insertions(+), 43 deletions(-) create mode 100644 src/main/java/net/wurstclient/events/ShouldDrawFacelessModelListener.java rename src/main/java/net/wurstclient/mixin/{SodiumBlockRendererMixin.java => BasicBakedModelMixin.java} (52%) create mode 100644 src/main/java/net/wurstclient/mixin/MultipartBakedModelMixin.java create mode 100644 src/main/java/net/wurstclient/mixin/WeightedBakedModelMixin.java diff --git a/build.gradle b/build.gradle index 84ee7559f9..f9c14b900d 100644 --- a/build.gradle +++ b/build.gradle @@ -24,14 +24,6 @@ repositories { // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. // See https://docs.gradle.org/current/userguide/declaring_repositories.html // for more information about repositories. - maven { - name = 'Modrinth' - url = 'https://api.modrinth.com/maven' - - content { - includeGroup "maven.modrinth" - } - } } dependencies { @@ -42,9 +34,6 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - - // Sodium, required for X-Ray compatibility. - modCompileOnly "maven.modrinth:sodium:${project.sodium_version}" // net.wurstclient.ai.PathPos extends net.minecraft.util.math.BlockPos, // which uses javax.annotation.concurrent.Immutable, which is part of diff --git a/gradle.properties b/gradle.properties index d6dd5de177..26c3651a87 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,4 +18,3 @@ maven_group = net.wurstclient archives_base_name = Wurst-Client # Dependencies -sodium_version=mc1.20.2-0.5.3 diff --git a/src/main/java/net/wurstclient/events/ShouldDrawFacelessModelListener.java b/src/main/java/net/wurstclient/events/ShouldDrawFacelessModelListener.java new file mode 100644 index 0000000000..ad45dce0d9 --- /dev/null +++ b/src/main/java/net/wurstclient/events/ShouldDrawFacelessModelListener.java @@ -0,0 +1,45 @@ +package net.wurstclient.events; + +import net.minecraft.block.BlockState; +import net.wurstclient.event.CancellableEvent; +import net.wurstclient.event.Listener; + +import java.util.ArrayList; + +public interface ShouldDrawFacelessModelListener extends Listener +{ + public void onShouldDrawFacelessModel(ShouldDrawFacelessModelEvent event); + + public static class ShouldDrawFacelessModelEvent extends CancellableEvent + { + private final BlockState state; + + public ShouldDrawFacelessModelEvent(BlockState state) + { + this.state = state; + } + + public BlockState getState() + { + return state; + } + + @Override + public void fire(ArrayList listeners) + { + // fire only if called from Sodium's BlockRenderer + if (Thread.currentThread().getStackTrace().length < 8 || !Thread.currentThread().getStackTrace()[7].getClassName() + .equals("me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderer")) + return; + + for(ShouldDrawFacelessModelListener listener : listeners) + listener.onShouldDrawFacelessModel(this); + } + + @Override + public Class getListenerType() + { + return ShouldDrawFacelessModelListener.class; + } + } +} diff --git a/src/main/java/net/wurstclient/hacks/XRayHack.java b/src/main/java/net/wurstclient/hacks/XRayHack.java index d989824dad..8ff9bb6209 100644 --- a/src/main/java/net/wurstclient/hacks/XRayHack.java +++ b/src/main/java/net/wurstclient/hacks/XRayHack.java @@ -9,6 +9,7 @@ import java.util.ArrayList; import java.util.Collections; +import java.util.List; import java.util.regex.Pattern; import java.util.stream.Stream; @@ -16,17 +17,16 @@ import net.fabricmc.loader.api.ModContainer; import net.fabricmc.loader.api.metadata.ModMetadata; import net.minecraft.block.Block; +import net.minecraft.block.BlockState; import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.render.model.BakedQuad; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; import net.wurstclient.Category; import net.wurstclient.SearchTags; import net.wurstclient.clickgui.screens.EditBlockListScreen; -import net.wurstclient.events.GetAmbientOcclusionLightLevelListener; -import net.wurstclient.events.RenderBlockEntityListener; -import net.wurstclient.events.SetOpaqueCubeListener; -import net.wurstclient.events.ShouldDrawSideListener; -import net.wurstclient.events.TesselateBlockListener; -import net.wurstclient.events.UpdateListener; +import net.wurstclient.event.EventManager; +import net.wurstclient.events.*; import net.wurstclient.hack.Hack; import net.wurstclient.mixinterface.ISimpleOption; import net.wurstclient.settings.BlockListSetting; @@ -34,10 +34,14 @@ import net.wurstclient.util.BlockUtils; import net.wurstclient.util.ChatUtils; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + @SearchTags({"XRay", "x ray", "OreFinder", "ore finder"}) public final class XRayHack extends Hack implements UpdateListener, - SetOpaqueCubeListener, GetAmbientOcclusionLightLevelListener, - ShouldDrawSideListener, TesselateBlockListener, RenderBlockEntityListener + SetOpaqueCubeListener,GetAmbientOcclusionLightLevelListener, + ShouldDrawSideListener, ShouldDrawFacelessModelListener, + TesselateBlockListener, RenderBlockEntityListener { private final BlockListSetting ores = new BlockListSetting("Ores", "A list of blocks that X-Ray will show. They don't have to be just ores" @@ -109,6 +113,7 @@ public void onEnable() EVENTS.add(SetOpaqueCubeListener.class, this); EVENTS.add(GetAmbientOcclusionLightLevelListener.class, this); EVENTS.add(ShouldDrawSideListener.class, this); + EVENTS.add(ShouldDrawFacelessModelListener.class, this); EVENTS.add(TesselateBlockListener.class, this); EVENTS.add(RenderBlockEntityListener.class, this); @@ -128,6 +133,7 @@ public void onDisable() EVENTS.remove(SetOpaqueCubeListener.class, this); EVENTS.remove(GetAmbientOcclusionLightLevelListener.class, this); EVENTS.remove(ShouldDrawSideListener.class, this); + EVENTS.remove(ShouldDrawFacelessModelListener.class, this); EVENTS.remove(TesselateBlockListener.class, this); EVENTS.remove(RenderBlockEntityListener.class, this); @@ -167,6 +173,13 @@ public void onShouldDrawSide(ShouldDrawSideEvent event) event.setRendered( isVisible(event.getState().getBlock(), event.getPos())); } + + @Override + public void onShouldDrawFacelessModel(ShouldDrawFacelessModelEvent event) + { + if (!isVisible(event.getState().getBlock(), null)) + event.cancel(); + } @Override public void onTesselateBlock(TesselateBlockEvent event) @@ -189,7 +202,7 @@ private boolean isVisible(Block block, BlockPos pos) int index = Collections.binarySearch(oreNamesCache, name); boolean visible = index >= 0; - if(visible && onlyExposed.isChecked()) + if(visible && onlyExposed.isChecked() && pos != null) return !BlockUtils.isOpaqueFullCube(pos.up()) || !BlockUtils.isOpaqueFullCube(pos.down()) || !BlockUtils.isOpaqueFullCube(pos.east()) diff --git a/src/main/java/net/wurstclient/mixin/SodiumBlockRendererMixin.java b/src/main/java/net/wurstclient/mixin/BasicBakedModelMixin.java similarity index 52% rename from src/main/java/net/wurstclient/mixin/SodiumBlockRendererMixin.java rename to src/main/java/net/wurstclient/mixin/BasicBakedModelMixin.java index 9046d28887..de330397d8 100644 --- a/src/main/java/net/wurstclient/mixin/SodiumBlockRendererMixin.java +++ b/src/main/java/net/wurstclient/mixin/BasicBakedModelMixin.java @@ -7,14 +7,15 @@ */ package net.wurstclient.mixin; -import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderContext; -import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderer; - +import net.minecraft.block.BlockState; import net.minecraft.client.render.model.BakedQuad; +import net.minecraft.client.render.model.BasicBakedModel; import net.minecraft.util.math.Direction; +import net.minecraft.util.math.random.Random; import net.wurstclient.event.EventManager; -import net.wurstclient.events.ShouldDrawSideListener.ShouldDrawSideEvent; +import net.wurstclient.events.ShouldDrawFacelessModelListener.ShouldDrawFacelessModelEvent; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -22,21 +23,18 @@ import java.util.List; -@Mixin(value = BlockRenderer.class, remap = false) -public class SodiumBlockRendererMixin -{ - @Inject(at = @At("HEAD"), - method = "getGeometry", - cancellable = true) - private void getGeometry(BlockRenderContext ctx, Direction face, - CallbackInfoReturnable> cir) +@Mixin(BasicBakedModel.class) +public class BasicBakedModelMixin { + @Inject(at = @At("HEAD"), method = "getQuads", cancellable = true) + private void getQuads(@Nullable BlockState state, @Nullable Direction face, + Random random, CallbackInfoReturnable> cir) { - if (face != null) return; + if (face != null || state == null) return; - ShouldDrawSideEvent event = new ShouldDrawSideEvent(ctx.state(), ctx.pos()); + ShouldDrawFacelessModelEvent event = new ShouldDrawFacelessModelEvent(state); EventManager.fire(event); - if (event.isRendered() != null && !event.isRendered()) + if(event.isCancelled()) cir.setReturnValue(List.of()); } } diff --git a/src/main/java/net/wurstclient/mixin/MultipartBakedModelMixin.java b/src/main/java/net/wurstclient/mixin/MultipartBakedModelMixin.java new file mode 100644 index 0000000000..f48624a06a --- /dev/null +++ b/src/main/java/net/wurstclient/mixin/MultipartBakedModelMixin.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2014-2023 Wurst-Imperium and contributors. + * + * This source code is subject to the terms of the GNU General Public + * License, version 3. If a copy of the GPL was not distributed with this + * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt + */ +package net.wurstclient.mixin; + +import net.minecraft.block.BlockState; +import net.minecraft.client.render.model.BakedQuad; +import net.minecraft.client.render.model.MultipartBakedModel; +import net.minecraft.util.math.Direction; +import net.minecraft.util.math.random.Random; +import net.wurstclient.event.EventManager; +import net.wurstclient.events.ShouldDrawFacelessModelListener.ShouldDrawFacelessModelEvent; + +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.List; + +@Mixin(MultipartBakedModel.class) +public class MultipartBakedModelMixin { + @Inject(at = @At("HEAD"), method = "getQuads", cancellable = true) + private void getQuads(@Nullable BlockState state, @Nullable Direction face, + Random random, CallbackInfoReturnable> cir) + { + if (face != null || state == null) return; + + ShouldDrawFacelessModelEvent event = new ShouldDrawFacelessModelEvent(state); + EventManager.fire(event); + + if(event.isCancelled()) + cir.setReturnValue(List.of()); + } +} diff --git a/src/main/java/net/wurstclient/mixin/SodiumBlockOcclusionCacheMixin.java b/src/main/java/net/wurstclient/mixin/SodiumBlockOcclusionCacheMixin.java index f4e4399def..2392d5a035 100644 --- a/src/main/java/net/wurstclient/mixin/SodiumBlockOcclusionCacheMixin.java +++ b/src/main/java/net/wurstclient/mixin/SodiumBlockOcclusionCacheMixin.java @@ -7,8 +7,6 @@ */ package net.wurstclient.mixin; -import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockOcclusionCache; - import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -17,11 +15,18 @@ import net.wurstclient.events.ShouldDrawSideListener.ShouldDrawSideEvent; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(value = BlockOcclusionCache.class, remap = false) +@Pseudo +@Mixin(targets = { + // current target + "me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockOcclusionCache", + // < Sodium 0.5.0 + "me.jellysquid.mods.sodium.client.render.occlusion.BlockOcclusionCache"}, + remap = false) public class SodiumBlockOcclusionCacheMixin { @Inject(at = @At("HEAD"), diff --git a/src/main/java/net/wurstclient/mixin/SodiumFluidRendererMixin.java b/src/main/java/net/wurstclient/mixin/SodiumFluidRendererMixin.java index dd19c2afbe..fc8746dcc0 100644 --- a/src/main/java/net/wurstclient/mixin/SodiumFluidRendererMixin.java +++ b/src/main/java/net/wurstclient/mixin/SodiumFluidRendererMixin.java @@ -7,8 +7,6 @@ */ package net.wurstclient.mixin; -import me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.FluidRenderer; - import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -17,11 +15,18 @@ import net.wurstclient.events.ShouldDrawSideListener.ShouldDrawSideEvent; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(value = FluidRenderer.class, remap = false) +@Pseudo +@Mixin(targets = { + // current target + "me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.FluidRenderer", + // < Sodium 0.4.9 + "me.jellysquid.mods.sodium.client.render.pipeline.FluidRenderer"}, + remap = false) public class SodiumFluidRendererMixin { @Inject(at = @At("HEAD"), diff --git a/src/main/java/net/wurstclient/mixin/WeightedBakedModelMixin.java b/src/main/java/net/wurstclient/mixin/WeightedBakedModelMixin.java new file mode 100644 index 0000000000..059b1938d3 --- /dev/null +++ b/src/main/java/net/wurstclient/mixin/WeightedBakedModelMixin.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2014-2023 Wurst-Imperium and contributors. + * + * This source code is subject to the terms of the GNU General Public + * License, version 3. If a copy of the GPL was not distributed with this + * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt + */ +package net.wurstclient.mixin; + +import net.minecraft.block.BlockState; +import net.minecraft.client.render.model.BakedQuad; +import net.minecraft.client.render.model.WeightedBakedModel; +import net.minecraft.util.math.Direction; +import net.minecraft.util.math.random.Random; +import net.wurstclient.event.EventManager; +import net.wurstclient.events.ShouldDrawFacelessModelListener.ShouldDrawFacelessModelEvent; + +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.List; + +@Mixin(WeightedBakedModel.class) +public class WeightedBakedModelMixin { + @Inject(at = @At("HEAD"), method = "getQuads", cancellable = true) + private void getQuads(@Nullable BlockState state, @Nullable Direction face, + Random random, CallbackInfoReturnable> cir) + { + if (face != null || state == null) return; + + ShouldDrawFacelessModelEvent event = new ShouldDrawFacelessModelEvent(state); + EventManager.fire(event); + + if(event.isCancelled()) + cir.setReturnValue(List.of()); + } +} diff --git a/src/main/resources/wurst.mixins.json b/src/main/resources/wurst.mixins.json index 3c2b8fc57e..da71520817 100644 --- a/src/main/resources/wurst.mixins.json +++ b/src/main/resources/wurst.mixins.json @@ -10,6 +10,7 @@ "AbstractSignEditScreenMixin", "AllowedAddressResolverMixin", "BackgroundRendererMixin", + "BasicBakedModelMixin", "BlockEntityRenderDispatcherMixin", "BlockMixin", "BlockModelRendererMixin", @@ -44,6 +45,7 @@ "LivingEntityRendererMixin", "MinecraftClientMixin", "MouseMixin", + "MultipartBakedModelMixin", "MultiplayerScreenMixin", "PackScreenMixin", "PlayerInventoryMixin", @@ -54,7 +56,6 @@ "ShulkerBoxScreenMixin", "SimpleOptionMixin", "SodiumBlockOcclusionCacheMixin", - "SodiumBlockRendererMixin", "SodiumFluidRendererMixin", "StatsScreenMixin", "StatusEffectInstanceMixin", @@ -62,6 +63,7 @@ "TerrainRenderContextMixin", "TextVisitFactoryMixin", "TitleScreenMixin", + "WeightedBakedModelMixin", "WorldMixin", "WorldRendererMixin" ], From 09e51e777d72f9250b993cbbd12b752805396e11 Mon Sep 17 00:00:00 2001 From: ZANX3Y <74610540+ZANX3Y@users.noreply.github.com> Date: Fri, 27 Oct 2023 00:13:35 +0200 Subject: [PATCH 03/10] Remove unused imports Forgot about those --- src/main/java/net/wurstclient/hacks/XRayHack.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/main/java/net/wurstclient/hacks/XRayHack.java b/src/main/java/net/wurstclient/hacks/XRayHack.java index 8ff9bb6209..b88eac60b6 100644 --- a/src/main/java/net/wurstclient/hacks/XRayHack.java +++ b/src/main/java/net/wurstclient/hacks/XRayHack.java @@ -9,7 +9,6 @@ import java.util.ArrayList; import java.util.Collections; -import java.util.List; import java.util.regex.Pattern; import java.util.stream.Stream; @@ -17,15 +16,11 @@ import net.fabricmc.loader.api.ModContainer; import net.fabricmc.loader.api.metadata.ModMetadata; import net.minecraft.block.Block; -import net.minecraft.block.BlockState; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.render.model.BakedQuad; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; import net.wurstclient.Category; import net.wurstclient.SearchTags; import net.wurstclient.clickgui.screens.EditBlockListScreen; -import net.wurstclient.event.EventManager; import net.wurstclient.events.*; import net.wurstclient.hack.Hack; import net.wurstclient.mixinterface.ISimpleOption; @@ -34,9 +29,6 @@ import net.wurstclient.util.BlockUtils; import net.wurstclient.util.ChatUtils; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - @SearchTags({"XRay", "x ray", "OreFinder", "ore finder"}) public final class XRayHack extends Hack implements UpdateListener, SetOpaqueCubeListener,GetAmbientOcclusionLightLevelListener, From d8d20bbb87fa36c16a5dfe5c8a7f6013993f5402 Mon Sep 17 00:00:00 2001 From: ZANX3Y <74610540+ZANX3Y@users.noreply.github.com> Date: Fri, 27 Oct 2023 00:29:57 +0200 Subject: [PATCH 04/10] Sodium X-Ray efficiency tweaks Suggested by coderabbitai --- .../events/ShouldDrawFacelessModelListener.java | 3 ++- src/main/java/net/wurstclient/hacks/XRayHack.java | 8 +++++++- .../java/net/wurstclient/mixin/BasicBakedModelMixin.java | 4 +++- .../net/wurstclient/mixin/MultipartBakedModelMixin.java | 4 +++- .../net/wurstclient/mixin/WeightedBakedModelMixin.java | 4 +++- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/wurstclient/events/ShouldDrawFacelessModelListener.java b/src/main/java/net/wurstclient/events/ShouldDrawFacelessModelListener.java index ad45dce0d9..bbd8f76016 100644 --- a/src/main/java/net/wurstclient/events/ShouldDrawFacelessModelListener.java +++ b/src/main/java/net/wurstclient/events/ShouldDrawFacelessModelListener.java @@ -28,7 +28,8 @@ public BlockState getState() public void fire(ArrayList listeners) { // fire only if called from Sodium's BlockRenderer - if (Thread.currentThread().getStackTrace().length < 8 || !Thread.currentThread().getStackTrace()[7].getClassName() + StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); + if (stackTrace.length < 8 || !stackTrace[7].getClassName() .equals("me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderer")) return; diff --git a/src/main/java/net/wurstclient/hacks/XRayHack.java b/src/main/java/net/wurstclient/hacks/XRayHack.java index b88eac60b6..751ebcebee 100644 --- a/src/main/java/net/wurstclient/hacks/XRayHack.java +++ b/src/main/java/net/wurstclient/hacks/XRayHack.java @@ -21,7 +21,13 @@ import net.wurstclient.Category; import net.wurstclient.SearchTags; import net.wurstclient.clickgui.screens.EditBlockListScreen; -import net.wurstclient.events.*; +import net.wurstclient.events.GetAmbientOcclusionLightLevelListener; +import net.wurstclient.events.RenderBlockEntityListener; +import net.wurstclient.events.SetOpaqueCubeListener; +import net.wurstclient.events.ShouldDrawSideListener; +import net.wurstclient.events.ShouldDrawFacelessModelListener; +import net.wurstclient.events.TesselateBlockListener; +import net.wurstclient.events.UpdateListener; import net.wurstclient.hack.Hack; import net.wurstclient.mixinterface.ISimpleOption; import net.wurstclient.settings.BlockListSetting; diff --git a/src/main/java/net/wurstclient/mixin/BasicBakedModelMixin.java b/src/main/java/net/wurstclient/mixin/BasicBakedModelMixin.java index de330397d8..2f458f0000 100644 --- a/src/main/java/net/wurstclient/mixin/BasicBakedModelMixin.java +++ b/src/main/java/net/wurstclient/mixin/BasicBakedModelMixin.java @@ -12,6 +12,7 @@ import net.minecraft.client.render.model.BasicBakedModel; import net.minecraft.util.math.Direction; import net.minecraft.util.math.random.Random; +import net.wurstclient.WurstClient; import net.wurstclient.event.EventManager; import net.wurstclient.events.ShouldDrawFacelessModelListener.ShouldDrawFacelessModelEvent; @@ -29,7 +30,8 @@ public class BasicBakedModelMixin { private void getQuads(@Nullable BlockState state, @Nullable Direction face, Random random, CallbackInfoReturnable> cir) { - if (face != null || state == null) return; + if (face != null || state == null || !WurstClient.INSTANCE.getHax().xRayHack.isEnabled()) + return; ShouldDrawFacelessModelEvent event = new ShouldDrawFacelessModelEvent(state); EventManager.fire(event); diff --git a/src/main/java/net/wurstclient/mixin/MultipartBakedModelMixin.java b/src/main/java/net/wurstclient/mixin/MultipartBakedModelMixin.java index f48624a06a..7b069b62b4 100644 --- a/src/main/java/net/wurstclient/mixin/MultipartBakedModelMixin.java +++ b/src/main/java/net/wurstclient/mixin/MultipartBakedModelMixin.java @@ -12,6 +12,7 @@ import net.minecraft.client.render.model.MultipartBakedModel; import net.minecraft.util.math.Direction; import net.minecraft.util.math.random.Random; +import net.wurstclient.WurstClient; import net.wurstclient.event.EventManager; import net.wurstclient.events.ShouldDrawFacelessModelListener.ShouldDrawFacelessModelEvent; @@ -29,7 +30,8 @@ public class MultipartBakedModelMixin { private void getQuads(@Nullable BlockState state, @Nullable Direction face, Random random, CallbackInfoReturnable> cir) { - if (face != null || state == null) return; + if (face != null || state == null || !WurstClient.INSTANCE.getHax().xRayHack.isEnabled()) + return; ShouldDrawFacelessModelEvent event = new ShouldDrawFacelessModelEvent(state); EventManager.fire(event); diff --git a/src/main/java/net/wurstclient/mixin/WeightedBakedModelMixin.java b/src/main/java/net/wurstclient/mixin/WeightedBakedModelMixin.java index 059b1938d3..253c0c9d95 100644 --- a/src/main/java/net/wurstclient/mixin/WeightedBakedModelMixin.java +++ b/src/main/java/net/wurstclient/mixin/WeightedBakedModelMixin.java @@ -12,6 +12,7 @@ import net.minecraft.client.render.model.WeightedBakedModel; import net.minecraft.util.math.Direction; import net.minecraft.util.math.random.Random; +import net.wurstclient.WurstClient; import net.wurstclient.event.EventManager; import net.wurstclient.events.ShouldDrawFacelessModelListener.ShouldDrawFacelessModelEvent; @@ -29,7 +30,8 @@ public class WeightedBakedModelMixin { private void getQuads(@Nullable BlockState state, @Nullable Direction face, Random random, CallbackInfoReturnable> cir) { - if (face != null || state == null) return; + if (face != null || state == null || !WurstClient.INSTANCE.getHax().xRayHack.isEnabled()) + return; ShouldDrawFacelessModelEvent event = new ShouldDrawFacelessModelEvent(state); EventManager.fire(event); From be90e0423025dc3dfd3fe0bc3f13ca259a054c4d Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Fri, 27 Oct 2023 18:10:00 +0200 Subject: [PATCH 05/10] Eclipse auto cleanup --- .../ShouldDrawFacelessModelListener.java | 76 ++++++++++--------- .../java/net/wurstclient/hacks/XRayHack.java | 8 +- .../mixin/BasicBakedModelMixin.java | 47 ++++++------ .../mixin/MultipartBakedModelMixin.java | 47 ++++++------ .../mixin/SodiumBlockOcclusionCacheMixin.java | 16 ++-- .../mixin/SodiumFluidRendererMixin.java | 49 ++++++------ .../mixin/WeightedBakedModelMixin.java | 47 ++++++------ 7 files changed, 148 insertions(+), 142 deletions(-) diff --git a/src/main/java/net/wurstclient/events/ShouldDrawFacelessModelListener.java b/src/main/java/net/wurstclient/events/ShouldDrawFacelessModelListener.java index bbd8f76016..df981d05b6 100644 --- a/src/main/java/net/wurstclient/events/ShouldDrawFacelessModelListener.java +++ b/src/main/java/net/wurstclient/events/ShouldDrawFacelessModelListener.java @@ -1,46 +1,48 @@ package net.wurstclient.events; +import java.util.ArrayList; + import net.minecraft.block.BlockState; import net.wurstclient.event.CancellableEvent; import net.wurstclient.event.Listener; -import java.util.ArrayList; - public interface ShouldDrawFacelessModelListener extends Listener { - public void onShouldDrawFacelessModel(ShouldDrawFacelessModelEvent event); - - public static class ShouldDrawFacelessModelEvent extends CancellableEvent - { - private final BlockState state; - - public ShouldDrawFacelessModelEvent(BlockState state) - { - this.state = state; - } - - public BlockState getState() - { - return state; - } - - @Override - public void fire(ArrayList listeners) - { - // fire only if called from Sodium's BlockRenderer - StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); - if (stackTrace.length < 8 || !stackTrace[7].getClassName() - .equals("me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderer")) - return; - - for(ShouldDrawFacelessModelListener listener : listeners) - listener.onShouldDrawFacelessModel(this); - } - - @Override - public Class getListenerType() - { - return ShouldDrawFacelessModelListener.class; - } - } + public void onShouldDrawFacelessModel(ShouldDrawFacelessModelEvent event); + + public static class ShouldDrawFacelessModelEvent + extends CancellableEvent + { + private final BlockState state; + + public ShouldDrawFacelessModelEvent(BlockState state) + { + this.state = state; + } + + public BlockState getState() + { + return state; + } + + @Override + public void fire(ArrayList listeners) + { + // fire only if called from Sodium's BlockRenderer + StackTraceElement[] stackTrace = + Thread.currentThread().getStackTrace(); + if(stackTrace.length < 8 || !stackTrace[7].getClassName().equals( + "me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderer")) + return; + + for(ShouldDrawFacelessModelListener listener : listeners) + listener.onShouldDrawFacelessModel(this); + } + + @Override + public Class getListenerType() + { + return ShouldDrawFacelessModelListener.class; + } + } } diff --git a/src/main/java/net/wurstclient/hacks/XRayHack.java b/src/main/java/net/wurstclient/hacks/XRayHack.java index 751ebcebee..95d497ee50 100644 --- a/src/main/java/net/wurstclient/hacks/XRayHack.java +++ b/src/main/java/net/wurstclient/hacks/XRayHack.java @@ -24,8 +24,8 @@ import net.wurstclient.events.GetAmbientOcclusionLightLevelListener; import net.wurstclient.events.RenderBlockEntityListener; import net.wurstclient.events.SetOpaqueCubeListener; -import net.wurstclient.events.ShouldDrawSideListener; import net.wurstclient.events.ShouldDrawFacelessModelListener; +import net.wurstclient.events.ShouldDrawSideListener; import net.wurstclient.events.TesselateBlockListener; import net.wurstclient.events.UpdateListener; import net.wurstclient.hack.Hack; @@ -37,7 +37,7 @@ @SearchTags({"XRay", "x ray", "OreFinder", "ore finder"}) public final class XRayHack extends Hack implements UpdateListener, - SetOpaqueCubeListener,GetAmbientOcclusionLightLevelListener, + SetOpaqueCubeListener, GetAmbientOcclusionLightLevelListener, ShouldDrawSideListener, ShouldDrawFacelessModelListener, TesselateBlockListener, RenderBlockEntityListener { @@ -171,11 +171,11 @@ public void onShouldDrawSide(ShouldDrawSideEvent event) event.setRendered( isVisible(event.getState().getBlock(), event.getPos())); } - + @Override public void onShouldDrawFacelessModel(ShouldDrawFacelessModelEvent event) { - if (!isVisible(event.getState().getBlock(), null)) + if(!isVisible(event.getState().getBlock(), null)) event.cancel(); } diff --git a/src/main/java/net/wurstclient/mixin/BasicBakedModelMixin.java b/src/main/java/net/wurstclient/mixin/BasicBakedModelMixin.java index 2f458f0000..2372f0a0a9 100644 --- a/src/main/java/net/wurstclient/mixin/BasicBakedModelMixin.java +++ b/src/main/java/net/wurstclient/mixin/BasicBakedModelMixin.java @@ -7,6 +7,14 @@ */ package net.wurstclient.mixin; +import java.util.List; + +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + import net.minecraft.block.BlockState; import net.minecraft.client.render.model.BakedQuad; import net.minecraft.client.render.model.BasicBakedModel; @@ -16,27 +24,22 @@ import net.wurstclient.event.EventManager; import net.wurstclient.events.ShouldDrawFacelessModelListener.ShouldDrawFacelessModelEvent; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.List; - @Mixin(BasicBakedModel.class) -public class BasicBakedModelMixin { - @Inject(at = @At("HEAD"), method = "getQuads", cancellable = true) - private void getQuads(@Nullable BlockState state, @Nullable Direction face, - Random random, CallbackInfoReturnable> cir) - { - if (face != null || state == null || !WurstClient.INSTANCE.getHax().xRayHack.isEnabled()) - return; - - ShouldDrawFacelessModelEvent event = new ShouldDrawFacelessModelEvent(state); - EventManager.fire(event); - - if(event.isCancelled()) - cir.setReturnValue(List.of()); - } +public class BasicBakedModelMixin +{ + @Inject(at = @At("HEAD"), method = "getQuads", cancellable = true) + private void getQuads(@Nullable BlockState state, @Nullable Direction face, + Random random, CallbackInfoReturnable> cir) + { + if(face != null || state == null + || !WurstClient.INSTANCE.getHax().xRayHack.isEnabled()) + return; + + ShouldDrawFacelessModelEvent event = + new ShouldDrawFacelessModelEvent(state); + EventManager.fire(event); + + if(event.isCancelled()) + cir.setReturnValue(List.of()); + } } diff --git a/src/main/java/net/wurstclient/mixin/MultipartBakedModelMixin.java b/src/main/java/net/wurstclient/mixin/MultipartBakedModelMixin.java index 7b069b62b4..82f3533790 100644 --- a/src/main/java/net/wurstclient/mixin/MultipartBakedModelMixin.java +++ b/src/main/java/net/wurstclient/mixin/MultipartBakedModelMixin.java @@ -7,6 +7,14 @@ */ package net.wurstclient.mixin; +import java.util.List; + +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + import net.minecraft.block.BlockState; import net.minecraft.client.render.model.BakedQuad; import net.minecraft.client.render.model.MultipartBakedModel; @@ -16,27 +24,22 @@ import net.wurstclient.event.EventManager; import net.wurstclient.events.ShouldDrawFacelessModelListener.ShouldDrawFacelessModelEvent; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.List; - @Mixin(MultipartBakedModel.class) -public class MultipartBakedModelMixin { - @Inject(at = @At("HEAD"), method = "getQuads", cancellable = true) - private void getQuads(@Nullable BlockState state, @Nullable Direction face, - Random random, CallbackInfoReturnable> cir) - { - if (face != null || state == null || !WurstClient.INSTANCE.getHax().xRayHack.isEnabled()) - return; - - ShouldDrawFacelessModelEvent event = new ShouldDrawFacelessModelEvent(state); - EventManager.fire(event); - - if(event.isCancelled()) - cir.setReturnValue(List.of()); - } +public class MultipartBakedModelMixin +{ + @Inject(at = @At("HEAD"), method = "getQuads", cancellable = true) + private void getQuads(@Nullable BlockState state, @Nullable Direction face, + Random random, CallbackInfoReturnable> cir) + { + if(face != null || state == null + || !WurstClient.INSTANCE.getHax().xRayHack.isEnabled()) + return; + + ShouldDrawFacelessModelEvent event = + new ShouldDrawFacelessModelEvent(state); + EventManager.fire(event); + + if(event.isCancelled()) + cir.setReturnValue(List.of()); + } } diff --git a/src/main/java/net/wurstclient/mixin/SodiumBlockOcclusionCacheMixin.java b/src/main/java/net/wurstclient/mixin/SodiumBlockOcclusionCacheMixin.java index 2392d5a035..08bce6047b 100644 --- a/src/main/java/net/wurstclient/mixin/SodiumBlockOcclusionCacheMixin.java +++ b/src/main/java/net/wurstclient/mixin/SodiumBlockOcclusionCacheMixin.java @@ -7,6 +7,12 @@ */ package net.wurstclient.mixin; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -14,12 +20,6 @@ import net.wurstclient.event.EventManager; import net.wurstclient.events.ShouldDrawSideListener.ShouldDrawSideEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - @Pseudo @Mixin(targets = { // current target @@ -29,9 +29,7 @@ remap = false) public class SodiumBlockOcclusionCacheMixin { - @Inject(at = @At("HEAD"), - method = "shouldDrawSide", - cancellable = true) + @Inject(at = @At("HEAD"), method = "shouldDrawSide", cancellable = true) public void shouldDrawSide(BlockState state, BlockView world, BlockPos pos, Direction side, CallbackInfoReturnable cir) { diff --git a/src/main/java/net/wurstclient/mixin/SodiumFluidRendererMixin.java b/src/main/java/net/wurstclient/mixin/SodiumFluidRendererMixin.java index fc8746dcc0..4c6aebe3bc 100644 --- a/src/main/java/net/wurstclient/mixin/SodiumFluidRendererMixin.java +++ b/src/main/java/net/wurstclient/mixin/SodiumFluidRendererMixin.java @@ -7,6 +7,12 @@ */ package net.wurstclient.mixin; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -14,34 +20,25 @@ import net.wurstclient.event.EventManager; import net.wurstclient.events.ShouldDrawSideListener.ShouldDrawSideEvent; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Pseudo; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - @Pseudo @Mixin(targets = { - // current target - "me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.FluidRenderer", - // < Sodium 0.4.9 - "me.jellysquid.mods.sodium.client.render.pipeline.FluidRenderer"}, - remap = false) + // current target + "me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.FluidRenderer", + // < Sodium 0.4.9 + "me.jellysquid.mods.sodium.client.render.pipeline.FluidRenderer"}, + remap = false) public class SodiumFluidRendererMixin { - @Inject(at = @At("HEAD"), - method = "isSideExposed", - cancellable = true) - private void isSideExposed(BlockRenderView world, - int x, int y, int z, Direction dir, float height, - CallbackInfoReturnable cir) - { - BlockPos pos = new BlockPos(x, y, z); - BlockState state = world.getBlockState(pos); - ShouldDrawSideEvent event = new ShouldDrawSideEvent(state, pos); - EventManager.fire(event); - - if(event.isRendered() != null) - cir.setReturnValue(event.isRendered()); - } + @Inject(at = @At("HEAD"), method = "isSideExposed", cancellable = true) + private void isSideExposed(BlockRenderView world, int x, int y, int z, + Direction dir, float height, CallbackInfoReturnable cir) + { + BlockPos pos = new BlockPos(x, y, z); + BlockState state = world.getBlockState(pos); + ShouldDrawSideEvent event = new ShouldDrawSideEvent(state, pos); + EventManager.fire(event); + + if(event.isRendered() != null) + cir.setReturnValue(event.isRendered()); + } } diff --git a/src/main/java/net/wurstclient/mixin/WeightedBakedModelMixin.java b/src/main/java/net/wurstclient/mixin/WeightedBakedModelMixin.java index 253c0c9d95..47da29f304 100644 --- a/src/main/java/net/wurstclient/mixin/WeightedBakedModelMixin.java +++ b/src/main/java/net/wurstclient/mixin/WeightedBakedModelMixin.java @@ -7,6 +7,14 @@ */ package net.wurstclient.mixin; +import java.util.List; + +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + import net.minecraft.block.BlockState; import net.minecraft.client.render.model.BakedQuad; import net.minecraft.client.render.model.WeightedBakedModel; @@ -16,27 +24,22 @@ import net.wurstclient.event.EventManager; import net.wurstclient.events.ShouldDrawFacelessModelListener.ShouldDrawFacelessModelEvent; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.List; - @Mixin(WeightedBakedModel.class) -public class WeightedBakedModelMixin { - @Inject(at = @At("HEAD"), method = "getQuads", cancellable = true) - private void getQuads(@Nullable BlockState state, @Nullable Direction face, - Random random, CallbackInfoReturnable> cir) - { - if (face != null || state == null || !WurstClient.INSTANCE.getHax().xRayHack.isEnabled()) - return; - - ShouldDrawFacelessModelEvent event = new ShouldDrawFacelessModelEvent(state); - EventManager.fire(event); - - if(event.isCancelled()) - cir.setReturnValue(List.of()); - } +public class WeightedBakedModelMixin +{ + @Inject(at = @At("HEAD"), method = "getQuads", cancellable = true) + private void getQuads(@Nullable BlockState state, @Nullable Direction face, + Random random, CallbackInfoReturnable> cir) + { + if(face != null || state == null + || !WurstClient.INSTANCE.getHax().xRayHack.isEnabled()) + return; + + ShouldDrawFacelessModelEvent event = + new ShouldDrawFacelessModelEvent(state); + EventManager.fire(event); + + if(event.isCancelled()) + cir.setReturnValue(List.of()); + } } From 04b543cc1e2ba1318cde59da05eba873e188aa00 Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Sat, 28 Oct 2023 18:47:54 +0200 Subject: [PATCH 06/10] Document what each mixin does --- .../java/net/wurstclient/mixin/BasicBakedModelMixin.java | 4 ++++ src/main/java/net/wurstclient/mixin/BlockMixin.java | 4 ++++ .../java/net/wurstclient/mixin/BlockModelRendererMixin.java | 6 ++++++ src/main/java/net/wurstclient/mixin/FluidRendererMixin.java | 4 ++++ .../net/wurstclient/mixin/MultipartBakedModelMixin.java | 3 +++ .../wurstclient/mixin/SodiumBlockOcclusionCacheMixin.java | 4 ++++ .../net/wurstclient/mixin/SodiumFluidRendererMixin.java | 3 +++ .../net/wurstclient/mixin/TerrainRenderContextMixin.java | 2 ++ .../java/net/wurstclient/mixin/WeightedBakedModelMixin.java | 3 +++ 9 files changed, 33 insertions(+) diff --git a/src/main/java/net/wurstclient/mixin/BasicBakedModelMixin.java b/src/main/java/net/wurstclient/mixin/BasicBakedModelMixin.java index 2372f0a0a9..838b84ed8b 100644 --- a/src/main/java/net/wurstclient/mixin/BasicBakedModelMixin.java +++ b/src/main/java/net/wurstclient/mixin/BasicBakedModelMixin.java @@ -27,6 +27,10 @@ @Mixin(BasicBakedModel.class) public class BasicBakedModelMixin { + /** + * This mixin hides blocks like grass and snow when using X-Ray. It works + * with and without Sodium installed. + */ @Inject(at = @At("HEAD"), method = "getQuads", cancellable = true) private void getQuads(@Nullable BlockState state, @Nullable Direction face, Random random, CallbackInfoReturnable> cir) diff --git a/src/main/java/net/wurstclient/mixin/BlockMixin.java b/src/main/java/net/wurstclient/mixin/BlockMixin.java index ca1c5ad976..c5936a18e7 100644 --- a/src/main/java/net/wurstclient/mixin/BlockMixin.java +++ b/src/main/java/net/wurstclient/mixin/BlockMixin.java @@ -26,6 +26,10 @@ @Mixin(Block.class) public abstract class BlockMixin implements ItemConvertible { + /** + * This mixin allows X-Ray to show ores that would normally be obstructed by + * other blocks. + */ @Inject(at = @At("HEAD"), method = "shouldDrawSide(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/Direction;Lnet/minecraft/util/math/BlockPos;)Z", cancellable = true) diff --git a/src/main/java/net/wurstclient/mixin/BlockModelRendererMixin.java b/src/main/java/net/wurstclient/mixin/BlockModelRendererMixin.java index 03cbd0f665..a620fb47da 100644 --- a/src/main/java/net/wurstclient/mixin/BlockModelRendererMixin.java +++ b/src/main/java/net/wurstclient/mixin/BlockModelRendererMixin.java @@ -28,6 +28,12 @@ @Mixin(BlockModelRenderer.class) public abstract class BlockModelRendererMixin { + /** + * This mixin hides and shows blocks when using X-Ray with OptiFine + * installed. + * + * TODO: Does {@link BasicBakedModelMixin} make this mixin redundant? + */ @Inject(at = @At("HEAD"), method = { "renderSmooth(Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/client/render/model/BakedModel;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;ZLnet/minecraft/util/math/random/Random;JI)V", diff --git a/src/main/java/net/wurstclient/mixin/FluidRendererMixin.java b/src/main/java/net/wurstclient/mixin/FluidRendererMixin.java index e14efae00e..ce119c4401 100644 --- a/src/main/java/net/wurstclient/mixin/FluidRendererMixin.java +++ b/src/main/java/net/wurstclient/mixin/FluidRendererMixin.java @@ -23,6 +23,10 @@ @Mixin(FluidRenderer.class) public class FluidRendererMixin { + /** + * This mixin hides and shows fluids when using X-Ray without Sodium + * installed. + */ @Inject(at = @At("HEAD"), method = "isSideCovered(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/Direction;FLnet/minecraft/block/BlockState;)Z", cancellable = true) diff --git a/src/main/java/net/wurstclient/mixin/MultipartBakedModelMixin.java b/src/main/java/net/wurstclient/mixin/MultipartBakedModelMixin.java index 82f3533790..785a5cc126 100644 --- a/src/main/java/net/wurstclient/mixin/MultipartBakedModelMixin.java +++ b/src/main/java/net/wurstclient/mixin/MultipartBakedModelMixin.java @@ -27,6 +27,9 @@ @Mixin(MultipartBakedModel.class) public class MultipartBakedModelMixin { + /** + * TODO: This mixin doesn't seem to do anything? + */ @Inject(at = @At("HEAD"), method = "getQuads", cancellable = true) private void getQuads(@Nullable BlockState state, @Nullable Direction face, Random random, CallbackInfoReturnable> cir) diff --git a/src/main/java/net/wurstclient/mixin/SodiumBlockOcclusionCacheMixin.java b/src/main/java/net/wurstclient/mixin/SodiumBlockOcclusionCacheMixin.java index 08bce6047b..cd36e13c56 100644 --- a/src/main/java/net/wurstclient/mixin/SodiumBlockOcclusionCacheMixin.java +++ b/src/main/java/net/wurstclient/mixin/SodiumBlockOcclusionCacheMixin.java @@ -29,6 +29,10 @@ remap = false) public class SodiumBlockOcclusionCacheMixin { + /** + * This mixin hides and shows regular full blocks when using X-Ray with + * Sodium installed. + */ @Inject(at = @At("HEAD"), method = "shouldDrawSide", cancellable = true) public void shouldDrawSide(BlockState state, BlockView world, BlockPos pos, Direction side, CallbackInfoReturnable cir) diff --git a/src/main/java/net/wurstclient/mixin/SodiumFluidRendererMixin.java b/src/main/java/net/wurstclient/mixin/SodiumFluidRendererMixin.java index 4c6aebe3bc..550debc194 100644 --- a/src/main/java/net/wurstclient/mixin/SodiumFluidRendererMixin.java +++ b/src/main/java/net/wurstclient/mixin/SodiumFluidRendererMixin.java @@ -29,6 +29,9 @@ remap = false) public class SodiumFluidRendererMixin { + /** + * This mixin hides and shows fluids when using X-Ray with Sodium installed. + */ @Inject(at = @At("HEAD"), method = "isSideExposed", cancellable = true) private void isSideExposed(BlockRenderView world, int x, int y, int z, Direction dir, float height, CallbackInfoReturnable cir) diff --git a/src/main/java/net/wurstclient/mixin/TerrainRenderContextMixin.java b/src/main/java/net/wurstclient/mixin/TerrainRenderContextMixin.java index 8812de7e33..febe55df43 100644 --- a/src/main/java/net/wurstclient/mixin/TerrainRenderContextMixin.java +++ b/src/main/java/net/wurstclient/mixin/TerrainRenderContextMixin.java @@ -31,6 +31,8 @@ public class TerrainRenderContextMixin *

* We could make this optional to stop the game from crashing, but then * X-Ray would silently stop working and it would be much harder to debug. + * + * TODO: {@link BasicBakedModelMixin} makes this mixin redundant. */ @Inject(at = @At("HEAD"), method = "tessellateBlock", diff --git a/src/main/java/net/wurstclient/mixin/WeightedBakedModelMixin.java b/src/main/java/net/wurstclient/mixin/WeightedBakedModelMixin.java index 47da29f304..f82ca82615 100644 --- a/src/main/java/net/wurstclient/mixin/WeightedBakedModelMixin.java +++ b/src/main/java/net/wurstclient/mixin/WeightedBakedModelMixin.java @@ -27,6 +27,9 @@ @Mixin(WeightedBakedModel.class) public class WeightedBakedModelMixin { + /** + * TODO: This mixin doesn't seem to do anything? + */ @Inject(at = @At("HEAD"), method = "getQuads", cancellable = true) private void getQuads(@Nullable BlockState state, @Nullable Direction face, Random random, CallbackInfoReturnable> cir) From d4eb1411464132f7ae42dfc20a494eeb84ac4d26 Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Sun, 29 Oct 2023 11:04:38 +0100 Subject: [PATCH 07/10] Remove MultipartBakedModelMixin and WeightedBakedModelMixin --- .../mixin/MultipartBakedModelMixin.java | 48 ------------------- .../mixin/WeightedBakedModelMixin.java | 48 ------------------- src/main/resources/wurst.mixins.json | 2 - 3 files changed, 98 deletions(-) delete mode 100644 src/main/java/net/wurstclient/mixin/MultipartBakedModelMixin.java delete mode 100644 src/main/java/net/wurstclient/mixin/WeightedBakedModelMixin.java diff --git a/src/main/java/net/wurstclient/mixin/MultipartBakedModelMixin.java b/src/main/java/net/wurstclient/mixin/MultipartBakedModelMixin.java deleted file mode 100644 index 785a5cc126..0000000000 --- a/src/main/java/net/wurstclient/mixin/MultipartBakedModelMixin.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2014-2023 Wurst-Imperium and contributors. - * - * This source code is subject to the terms of the GNU General Public - * License, version 3. If a copy of the GPL was not distributed with this - * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt - */ -package net.wurstclient.mixin; - -import java.util.List; - -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import net.minecraft.block.BlockState; -import net.minecraft.client.render.model.BakedQuad; -import net.minecraft.client.render.model.MultipartBakedModel; -import net.minecraft.util.math.Direction; -import net.minecraft.util.math.random.Random; -import net.wurstclient.WurstClient; -import net.wurstclient.event.EventManager; -import net.wurstclient.events.ShouldDrawFacelessModelListener.ShouldDrawFacelessModelEvent; - -@Mixin(MultipartBakedModel.class) -public class MultipartBakedModelMixin -{ - /** - * TODO: This mixin doesn't seem to do anything? - */ - @Inject(at = @At("HEAD"), method = "getQuads", cancellable = true) - private void getQuads(@Nullable BlockState state, @Nullable Direction face, - Random random, CallbackInfoReturnable> cir) - { - if(face != null || state == null - || !WurstClient.INSTANCE.getHax().xRayHack.isEnabled()) - return; - - ShouldDrawFacelessModelEvent event = - new ShouldDrawFacelessModelEvent(state); - EventManager.fire(event); - - if(event.isCancelled()) - cir.setReturnValue(List.of()); - } -} diff --git a/src/main/java/net/wurstclient/mixin/WeightedBakedModelMixin.java b/src/main/java/net/wurstclient/mixin/WeightedBakedModelMixin.java deleted file mode 100644 index f82ca82615..0000000000 --- a/src/main/java/net/wurstclient/mixin/WeightedBakedModelMixin.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2014-2023 Wurst-Imperium and contributors. - * - * This source code is subject to the terms of the GNU General Public - * License, version 3. If a copy of the GPL was not distributed with this - * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt - */ -package net.wurstclient.mixin; - -import java.util.List; - -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import net.minecraft.block.BlockState; -import net.minecraft.client.render.model.BakedQuad; -import net.minecraft.client.render.model.WeightedBakedModel; -import net.minecraft.util.math.Direction; -import net.minecraft.util.math.random.Random; -import net.wurstclient.WurstClient; -import net.wurstclient.event.EventManager; -import net.wurstclient.events.ShouldDrawFacelessModelListener.ShouldDrawFacelessModelEvent; - -@Mixin(WeightedBakedModel.class) -public class WeightedBakedModelMixin -{ - /** - * TODO: This mixin doesn't seem to do anything? - */ - @Inject(at = @At("HEAD"), method = "getQuads", cancellable = true) - private void getQuads(@Nullable BlockState state, @Nullable Direction face, - Random random, CallbackInfoReturnable> cir) - { - if(face != null || state == null - || !WurstClient.INSTANCE.getHax().xRayHack.isEnabled()) - return; - - ShouldDrawFacelessModelEvent event = - new ShouldDrawFacelessModelEvent(state); - EventManager.fire(event); - - if(event.isCancelled()) - cir.setReturnValue(List.of()); - } -} diff --git a/src/main/resources/wurst.mixins.json b/src/main/resources/wurst.mixins.json index b26af57241..cc2eaa33df 100644 --- a/src/main/resources/wurst.mixins.json +++ b/src/main/resources/wurst.mixins.json @@ -44,7 +44,6 @@ "LivingEntityRendererMixin", "MinecraftClientMixin", "MouseMixin", - "MultipartBakedModelMixin", "MultiplayerScreenMixin", "PackScreenMixin", "PlayerInventoryMixin", @@ -62,7 +61,6 @@ "TerrainRenderContextMixin", "TextVisitFactoryMixin", "TitleScreenMixin", - "WeightedBakedModelMixin", "WorldMixin", "WorldRendererMixin" ], From 1198270e29944b108e6eba0faf530a3469d06b16 Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Sun, 29 Oct 2023 12:19:52 +0100 Subject: [PATCH 08/10] Replace TerrainRenderContextMixin with BasicBakedModelMixin --- .../ShouldDrawFacelessModelListener.java | 7 --- .../mixin/TerrainRenderContextMixin.java | 50 ------------------- src/main/resources/wurst.mixins.json | 1 - 3 files changed, 58 deletions(-) delete mode 100644 src/main/java/net/wurstclient/mixin/TerrainRenderContextMixin.java diff --git a/src/main/java/net/wurstclient/events/ShouldDrawFacelessModelListener.java b/src/main/java/net/wurstclient/events/ShouldDrawFacelessModelListener.java index df981d05b6..6ce2bfb760 100644 --- a/src/main/java/net/wurstclient/events/ShouldDrawFacelessModelListener.java +++ b/src/main/java/net/wurstclient/events/ShouldDrawFacelessModelListener.java @@ -28,13 +28,6 @@ public BlockState getState() @Override public void fire(ArrayList listeners) { - // fire only if called from Sodium's BlockRenderer - StackTraceElement[] stackTrace = - Thread.currentThread().getStackTrace(); - if(stackTrace.length < 8 || !stackTrace[7].getClassName().equals( - "me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderer")) - return; - for(ShouldDrawFacelessModelListener listener : listeners) listener.onShouldDrawFacelessModel(this); } diff --git a/src/main/java/net/wurstclient/mixin/TerrainRenderContextMixin.java b/src/main/java/net/wurstclient/mixin/TerrainRenderContextMixin.java deleted file mode 100644 index febe55df43..0000000000 --- a/src/main/java/net/wurstclient/mixin/TerrainRenderContextMixin.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2014-2023 Wurst-Imperium and contributors. - * - * This source code is subject to the terms of the GNU General Public - * License, version 3. If a copy of the GPL was not distributed with this - * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt - */ -package net.wurstclient.mixin; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import net.fabricmc.fabric.impl.client.indigo.renderer.render.TerrainRenderContext; -import net.minecraft.block.BlockState; -import net.minecraft.client.render.model.BakedModel; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.math.BlockPos; -import net.wurstclient.event.EventManager; -import net.wurstclient.events.TesselateBlockListener.TesselateBlockEvent; - -@Mixin(TerrainRenderContext.class) -public class TerrainRenderContextMixin -{ - /** - * This is a part of what allows X-Ray to make blocks invisible. It's - * also the part that keeps breaking whenever Fabric API updates their - * rendering code. - * - *

- * We could make this optional to stop the game from crashing, but then - * X-Ray would silently stop working and it would be much harder to debug. - * - * TODO: {@link BasicBakedModelMixin} makes this mixin redundant. - */ - @Inject(at = @At("HEAD"), - method = "tessellateBlock", - cancellable = true, - remap = false) - private void onTessellateBlock(BlockState state, BlockPos pos, - final BakedModel model, MatrixStack matrixStack, CallbackInfo ci) - { - TesselateBlockEvent event = new TesselateBlockEvent(state, pos); - EventManager.fire(event); - - if(event.isCancelled()) - ci.cancel(); - } -} diff --git a/src/main/resources/wurst.mixins.json b/src/main/resources/wurst.mixins.json index cc2eaa33df..2c3d20b8a9 100644 --- a/src/main/resources/wurst.mixins.json +++ b/src/main/resources/wurst.mixins.json @@ -58,7 +58,6 @@ "StatsScreenMixin", "StatusEffectInstanceMixin", "TelemetryManagerMixin", - "TerrainRenderContextMixin", "TextVisitFactoryMixin", "TitleScreenMixin", "WorldMixin", From fa0d37c6ff3386053bc9704b2e3be5d10b8d95e5 Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Sun, 29 Oct 2023 13:15:57 +0100 Subject: [PATCH 09/10] Remove BlockModelRendererMixin --- .../mixin/BlockModelRendererMixin.java | 73 ------------------- src/main/resources/wurst.mixins.json | 1 - 2 files changed, 74 deletions(-) delete mode 100644 src/main/java/net/wurstclient/mixin/BlockModelRendererMixin.java diff --git a/src/main/java/net/wurstclient/mixin/BlockModelRendererMixin.java b/src/main/java/net/wurstclient/mixin/BlockModelRendererMixin.java deleted file mode 100644 index a620fb47da..0000000000 --- a/src/main/java/net/wurstclient/mixin/BlockModelRendererMixin.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2014-2023 Wurst-Imperium and contributors. - * - * This source code is subject to the terms of the GNU General Public - * License, version 3. If a copy of the GPL was not distributed with this - * file, You can obtain one at: https://www.gnu.org/licenses/gpl-3.0.txt - */ -package net.wurstclient.mixin; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import net.minecraft.block.BlockState; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.block.BlockModelRenderer; -import net.minecraft.client.render.model.BakedModel; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.random.Random; -import net.minecraft.world.BlockRenderView; -import net.wurstclient.event.EventManager; -import net.wurstclient.events.ShouldDrawSideListener.ShouldDrawSideEvent; -import net.wurstclient.events.TesselateBlockListener.TesselateBlockEvent; - -@Mixin(BlockModelRenderer.class) -public abstract class BlockModelRendererMixin -{ - /** - * This mixin hides and shows blocks when using X-Ray with OptiFine - * installed. - * - * TODO: Does {@link BasicBakedModelMixin} make this mixin redundant? - */ - @Inject(at = @At("HEAD"), - method = { - "renderSmooth(Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/client/render/model/BakedModel;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;ZLnet/minecraft/util/math/random/Random;JI)V", - "renderFlat(Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/client/render/model/BakedModel;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;ZLnet/minecraft/util/math/random/Random;JI)V"}, - cancellable = true) - private void onRenderSmoothOrFlat(BlockRenderView world, BakedModel model, - BlockState state, BlockPos pos, MatrixStack matrices, - VertexConsumer vertexConsumer, boolean cull, Random random, long seed, - int overlay, CallbackInfo ci) - { - TesselateBlockEvent event = new TesselateBlockEvent(state, pos); - EventManager.fire(event); - - if(event.isCancelled()) - { - ci.cancel(); - return; - } - - if(!cull) - return; - - ShouldDrawSideEvent event2 = new ShouldDrawSideEvent(state, pos); - EventManager.fire(event2); - if(!Boolean.TRUE.equals(event2.isRendered())) - return; - - renderSmooth(world, model, state, pos, matrices, vertexConsumer, false, - random, seed, overlay); - } - - @Shadow - public abstract void renderSmooth(BlockRenderView world, BakedModel model, - BlockState state, BlockPos pos, MatrixStack matrices, - VertexConsumer vertexConsumer, boolean cull, Random random, long seed, - int overlay); -} diff --git a/src/main/resources/wurst.mixins.json b/src/main/resources/wurst.mixins.json index 2c3d20b8a9..af1d213237 100644 --- a/src/main/resources/wurst.mixins.json +++ b/src/main/resources/wurst.mixins.json @@ -13,7 +13,6 @@ "BasicBakedModelMixin", "BlockEntityRenderDispatcherMixin", "BlockMixin", - "BlockModelRendererMixin", "CactusBlockMixin", "CameraMixin", "ChatHudMixin", From 062311c7b5ce60550f549020bc38b76c142f8a5d Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Sun, 29 Oct 2023 14:17:34 +0100 Subject: [PATCH 10/10] Change ShouldDrawFacelessModelEvent back to ShouldDrawSideEvent --- .../ShouldDrawFacelessModelListener.java | 41 ------------------- .../events/ShouldDrawSideListener.java | 3 +- .../java/net/wurstclient/hacks/XRayHack.java | 13 +----- .../mixin/BasicBakedModelMixin.java | 7 ++-- 4 files changed, 6 insertions(+), 58 deletions(-) delete mode 100644 src/main/java/net/wurstclient/events/ShouldDrawFacelessModelListener.java diff --git a/src/main/java/net/wurstclient/events/ShouldDrawFacelessModelListener.java b/src/main/java/net/wurstclient/events/ShouldDrawFacelessModelListener.java deleted file mode 100644 index 6ce2bfb760..0000000000 --- a/src/main/java/net/wurstclient/events/ShouldDrawFacelessModelListener.java +++ /dev/null @@ -1,41 +0,0 @@ -package net.wurstclient.events; - -import java.util.ArrayList; - -import net.minecraft.block.BlockState; -import net.wurstclient.event.CancellableEvent; -import net.wurstclient.event.Listener; - -public interface ShouldDrawFacelessModelListener extends Listener -{ - public void onShouldDrawFacelessModel(ShouldDrawFacelessModelEvent event); - - public static class ShouldDrawFacelessModelEvent - extends CancellableEvent - { - private final BlockState state; - - public ShouldDrawFacelessModelEvent(BlockState state) - { - this.state = state; - } - - public BlockState getState() - { - return state; - } - - @Override - public void fire(ArrayList listeners) - { - for(ShouldDrawFacelessModelListener listener : listeners) - listener.onShouldDrawFacelessModel(this); - } - - @Override - public Class getListenerType() - { - return ShouldDrawFacelessModelListener.class; - } - } -} diff --git a/src/main/java/net/wurstclient/events/ShouldDrawSideListener.java b/src/main/java/net/wurstclient/events/ShouldDrawSideListener.java index c99b2d448f..bd0744a21f 100644 --- a/src/main/java/net/wurstclient/events/ShouldDrawSideListener.java +++ b/src/main/java/net/wurstclient/events/ShouldDrawSideListener.java @@ -8,6 +8,7 @@ package net.wurstclient.events; import java.util.ArrayList; +import java.util.Objects; import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; @@ -27,7 +28,7 @@ public static class ShouldDrawSideEvent public ShouldDrawSideEvent(BlockState state, BlockPos pos) { - this.state = state; + this.state = Objects.requireNonNull(state); this.pos = pos; } diff --git a/src/main/java/net/wurstclient/hacks/XRayHack.java b/src/main/java/net/wurstclient/hacks/XRayHack.java index 95d497ee50..4288b7e280 100644 --- a/src/main/java/net/wurstclient/hacks/XRayHack.java +++ b/src/main/java/net/wurstclient/hacks/XRayHack.java @@ -24,7 +24,6 @@ import net.wurstclient.events.GetAmbientOcclusionLightLevelListener; import net.wurstclient.events.RenderBlockEntityListener; import net.wurstclient.events.SetOpaqueCubeListener; -import net.wurstclient.events.ShouldDrawFacelessModelListener; import net.wurstclient.events.ShouldDrawSideListener; import net.wurstclient.events.TesselateBlockListener; import net.wurstclient.events.UpdateListener; @@ -38,8 +37,7 @@ @SearchTags({"XRay", "x ray", "OreFinder", "ore finder"}) public final class XRayHack extends Hack implements UpdateListener, SetOpaqueCubeListener, GetAmbientOcclusionLightLevelListener, - ShouldDrawSideListener, ShouldDrawFacelessModelListener, - TesselateBlockListener, RenderBlockEntityListener + ShouldDrawSideListener, TesselateBlockListener, RenderBlockEntityListener { private final BlockListSetting ores = new BlockListSetting("Ores", "A list of blocks that X-Ray will show. They don't have to be just ores" @@ -111,7 +109,6 @@ public void onEnable() EVENTS.add(SetOpaqueCubeListener.class, this); EVENTS.add(GetAmbientOcclusionLightLevelListener.class, this); EVENTS.add(ShouldDrawSideListener.class, this); - EVENTS.add(ShouldDrawFacelessModelListener.class, this); EVENTS.add(TesselateBlockListener.class, this); EVENTS.add(RenderBlockEntityListener.class, this); @@ -131,7 +128,6 @@ public void onDisable() EVENTS.remove(SetOpaqueCubeListener.class, this); EVENTS.remove(GetAmbientOcclusionLightLevelListener.class, this); EVENTS.remove(ShouldDrawSideListener.class, this); - EVENTS.remove(ShouldDrawFacelessModelListener.class, this); EVENTS.remove(TesselateBlockListener.class, this); EVENTS.remove(RenderBlockEntityListener.class, this); @@ -172,13 +168,6 @@ public void onShouldDrawSide(ShouldDrawSideEvent event) isVisible(event.getState().getBlock(), event.getPos())); } - @Override - public void onShouldDrawFacelessModel(ShouldDrawFacelessModelEvent event) - { - if(!isVisible(event.getState().getBlock(), null)) - event.cancel(); - } - @Override public void onTesselateBlock(TesselateBlockEvent event) { diff --git a/src/main/java/net/wurstclient/mixin/BasicBakedModelMixin.java b/src/main/java/net/wurstclient/mixin/BasicBakedModelMixin.java index 838b84ed8b..98c372ae49 100644 --- a/src/main/java/net/wurstclient/mixin/BasicBakedModelMixin.java +++ b/src/main/java/net/wurstclient/mixin/BasicBakedModelMixin.java @@ -22,7 +22,7 @@ import net.minecraft.util.math.random.Random; import net.wurstclient.WurstClient; import net.wurstclient.event.EventManager; -import net.wurstclient.events.ShouldDrawFacelessModelListener.ShouldDrawFacelessModelEvent; +import net.wurstclient.events.ShouldDrawSideListener.ShouldDrawSideEvent; @Mixin(BasicBakedModel.class) public class BasicBakedModelMixin @@ -39,11 +39,10 @@ private void getQuads(@Nullable BlockState state, @Nullable Direction face, || !WurstClient.INSTANCE.getHax().xRayHack.isEnabled()) return; - ShouldDrawFacelessModelEvent event = - new ShouldDrawFacelessModelEvent(state); + ShouldDrawSideEvent event = new ShouldDrawSideEvent(state, null); EventManager.fire(event); - if(event.isCancelled()) + if(Boolean.FALSE.equals(event.isRendered())) cir.setReturnValue(List.of()); } }