Skip to content

Commit

Permalink
Make X-Ray fully compatible with Sodium
Browse files Browse the repository at this point in the history
  • Loading branch information
ZANX3Y committed Oct 22, 2023
1 parent b1076bd commit f855392
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 12 deletions.
11 changes: 11 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ maven_group = net.wurstclient
archives_base_name = Wurst-Client

# Dependencies
sodium_version=mc1.20.2-0.5.3
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Boolean> cir)
{
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/net/wurstclient/mixin/SodiumBlockRendererMixin.java
Original file line number Diff line number Diff line change
@@ -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<List<BakedQuad>> 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());
}
}
42 changes: 42 additions & 0 deletions src/main/java/net/wurstclient/mixin/SodiumFluidRendererMixin.java
Original file line number Diff line number Diff line change
@@ -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<Boolean> 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());
}
}
2 changes: 2 additions & 0 deletions src/main/resources/wurst.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
"ShulkerBoxScreenMixin",
"SimpleOptionMixin",
"SodiumBlockOcclusionCacheMixin",
"SodiumBlockRendererMixin",
"SodiumFluidRendererMixin",
"StatsScreenMixin",
"StatusEffectInstanceMixin",
"TelemetryManagerMixin",
Expand Down

0 comments on commit f855392

Please sign in to comment.