Skip to content

Commit

Permalink
Merge pull request #75 from TangyKiwi/master
Browse files Browse the repository at this point in the history
Fix Sodium XRay compat
  • Loading branch information
coltonk9043 authored Dec 9, 2024
2 parents b3cd7fc + 6f2fc81 commit 5904802
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 119 deletions.
9 changes: 4 additions & 5 deletions src/main/java/net/aoba/mixin/BlockMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@
@Mixin(Block.class)
public abstract class BlockMixin implements ItemConvertible {

@Inject(at = { @At("HEAD") }, method = {
"shouldDrawSide(Lnet/minecraft/block/BlockState;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/Direction;)Z" }, cancellable = true)
@Inject(at = { @At("RETURN") }, method = {
"shouldDrawSide" }, cancellable = true)
private static void onShouldDrawSide(BlockState state, BlockState otherState, Direction side,
CallbackInfoReturnable<Boolean> cir) {
CallbackInfoReturnable<Boolean> cir) {
AobaClient aoba = Aoba.getInstance();
XRay xray = (XRay) aoba.moduleManager.xray;
if (xray.state.getValue()) {
boolean isXray = xray.isXRayBlock(state.getBlock());
cir.setReturnValue(isXray);
cir.setReturnValue(xray.isXRayBlock(state.getBlock()));
}
}

Expand Down
56 changes: 0 additions & 56 deletions src/main/java/net/aoba/mixin/BlockModelRendererMixin.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

@Mixin(ChunkOcclusionDataBuilder.class)
public class ChunkOcclusionDataBuilderMixin {
@Inject(at = { @At("HEAD") }, method = { "markClosed(Lnet/minecraft/util/math/BlockPos;)V" }, cancellable = true)
@Inject(at = { @At("HEAD") }, method = { "markClosed" }, cancellable = true)
private void onMarkClosed(BlockPos pos, CallbackInfo ci) {
if (Aoba.getInstance().moduleManager.xray.state.getValue()) {
ci.cancel();
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/net/aoba/mixin/FluidRendererMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package net.aoba.mixin;

import net.aoba.Aoba;
import net.aoba.AobaClient;
import net.aoba.module.modules.render.XRay;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.block.FluidRenderer;
import net.minecraft.fluid.FluidState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockRenderView;
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;

@Mixin(FluidRenderer.class)
public class FluidRendererMixin {
@Inject(method = "render", at = @At("HEAD"), cancellable = true)
private void onRender(BlockRenderView world, BlockPos pos, VertexConsumer vertexConsumer, BlockState blockState, FluidState fluidState, CallbackInfo ci) {
AobaClient aoba = Aoba.getInstance();
XRay xray = (XRay) aoba.moduleManager.xray;
if (xray.state.getValue()) {
if (!xray.isXRayBlock(blockState.getBlock()) && !xray.fluids.getValue()) {
ci.cancel();
}
}
}
}
49 changes: 0 additions & 49 deletions src/main/java/net/aoba/mixin/TerrainRenderContextMixin.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
@Mixin(value = BlockOcclusionCache.class, remap = false)
public abstract class SodiumBlockOcclusionCacheMixin {

@Inject(at = { @At("TAIL") }, method = "shouldDrawSide", cancellable = true)
@Inject(at = { @At("RETURN") }, method = "shouldDrawSide", cancellable = true)
private void onShouldDrawSide(BlockState state, BlockView view, BlockPos pos, Direction facing,
CallbackInfoReturnable<Boolean> cir) {
CallbackInfoReturnable<Boolean> cir) {
AobaClient aoba = Aoba.getInstance();
XRay xray = aoba.moduleManager.xray;
if (xray.state.getValue()) {
cir.setReturnValue(!xray.isXRayBlock(state.getBlock()));
cir.setReturnValue(xray.isXRayBlock(state.getBlock()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ private void onRenderModel(BakedModel model, BlockState state, BlockPos pos, Blo
AobaClient aoba = Aoba.getInstance();
XRay xray = (XRay) aoba.moduleManager.xray;
if (xray.state.getValue()) {
if (xray.isXRayBlock(state.getBlock())) {
if (!xray.isXRayBlock(state.getBlock())) {
ci.cancel();
return;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.aoba.mixin.sodium;

import net.aoba.Aoba;
import net.aoba.AobaClient;
import net.aoba.module.modules.render.XRay;
import net.caffeinemc.mods.sodium.client.render.chunk.compile.ChunkBuildBuffers;
import net.caffeinemc.mods.sodium.client.render.chunk.translucent_sorting.TranslucentGeometryCollector;
import net.caffeinemc.mods.sodium.client.world.LevelSlice;
import net.caffeinemc.mods.sodium.fabric.render.FluidRendererImpl;
import net.minecraft.block.BlockState;
import net.minecraft.fluid.FluidState;
import net.minecraft.util.math.BlockPos;
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;

@Mixin(value = FluidRendererImpl.class, remap = false)
public abstract class SodiumFluidRendererImplMixin {
@Inject(method = "render", at = @At("HEAD"), cancellable = true)
private void onRender(LevelSlice level, BlockState blockState, FluidState fluidState, BlockPos blockPos, BlockPos offset, TranslucentGeometryCollector collector, ChunkBuildBuffers buffers, CallbackInfo ci) {
AobaClient aoba = Aoba.getInstance();
XRay xray = (XRay) aoba.moduleManager.xray;
if (xray.state.getValue()) {
if (!xray.isXRayBlock(blockState.getBlock()) && !xray.fluids.getValue()) {
ci.cancel();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private void onInit(CallbackInfo info) {
private int compute_modifyBL(int light) {
if (xray.state.getValue()) {
BlockState state = level.getBlockState(pos);
if (!xray.isXRayBlock(state.getBlock()))
if (xray.isXRayBlock(state.getBlock()))
return FULL_LIGHT;
}

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/net/aoba/module/modules/render/XRay.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.util.HashSet;

import net.aoba.settings.types.BooleanSetting;
import org.lwjgl.glfw.GLFW;

import com.google.common.collect.Lists;
Expand All @@ -45,11 +46,17 @@ public class XRay extends Module {
Blocks.DEEPSLATE_GOLD_ORE, Blocks.DEEPSLATE_IRON_ORE, Blocks.DEEPSLATE_COAL_ORE)))
.onUpdate(this::ReloadRenderer).build();

public BooleanSetting fluids = BooleanSetting.builder().id("fluids").displayName("Show Fluids")
.description("Show fluids (water/lava) when using Xray")
.defaultValue(true)
.onUpdate(this::ReloadRenderer).build();

public XRay() {
super("XRay", InputUtil.fromKeyCode(GLFW.GLFW_KEY_X, 0));
this.setCategory(Category.of("Render"));
this.setDescription("Allows the player to see ores.");
this.addSetting(blocks);
this.addSetting(fluids);
}

@Override
Expand Down Expand Up @@ -81,4 +88,10 @@ public void ReloadRenderer(HashSet<Block> block) {
MC.worldRenderer.reload();
}
}

public void ReloadRenderer(Boolean fluids) {
if (MC.worldRenderer != null && state.getValue()) {
MC.worldRenderer.reload();
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/aoba-sodium.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"client": [
"SodiumBlockRendererMixin",
"SodiumBlockOcclusionCacheMixin",
"SodiumFluidRendererImplMixin",
"SodiumLightDataAccessMixin"
],
"injectors": {
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/aoba.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
"interfaces.ICuboid",
"interfaces.IEntityModel",
"interfaces.IPlayerMoveC2SPacket",
"interfaces.IMouse",
"interfaces.IMouse"
],
"client": [
"AbstractBlockStateMixin",
"AbstractClientPlayerEntityMixin",
"AbstractSignEditScreenMixin",
"BackgroundRendererMixin",
"BlockMixin",
"BlockModelRendererMixin",
"CactusBlockMixin",
"CameraMixin",
"ChatHudMixin",
Expand All @@ -40,6 +39,7 @@
"EntityMixin",
"EntityRendererMixin",
"FluidBlockMixin",
"FluidRendererMixin",
"GameOptionsMixin",
"GameRendererMixin",
"HungerManagerMixin",
Expand Down

0 comments on commit 5904802

Please sign in to comment.