From 0f0cb86d789c57297df01f07796139bedd595403 Mon Sep 17 00:00:00 2001 From: ALFEECLARE Date: Sun, 18 Feb 2024 12:32:53 +0900 Subject: [PATCH] Fix compatibility with Rubidium. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.fix compatibility with Rubidium.(Rubidiumとの互換性が損なわれていたのを修正) 2.Bugfix: Sometimes Crashed in BlockSelecter page. --- .gitignore | 7 +- build.gradle | 7 ++ src/main/java/fr/atesab/xray/XrayMain.java | 54 ++++++++++----- .../xray/mixins/MixinBlockOcclusionCache.java | 19 +++--- .../fr/atesab/xray/utils/RenderUtils.java | 67 ++++++++++++++++++- 5 files changed, 124 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index 99e73c6..21f0ae6 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,9 @@ run # Files from Forge MDK forge*changelog.txt -logs \ No newline at end of file +logs +/wrapper/ +/libs/ +/native/ +/daemon/ +/caches/ diff --git a/build.gradle b/build.gradle index d50daaa..635344b 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,12 @@ project.ext.groupId = project.maven_group project.ext.projectVersion = "${version}-fabric-${project.minecraft_version}" repositories { + maven { + url "https://api.modrinth.com/maven" + content { + includeGroup "maven.modrinth" + } + } } dependencies { @@ -22,6 +28,7 @@ dependencies { modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + modCompileOnly "maven.modrinth:sodium:mc1.20.1-0.5.8" } processResources { diff --git a/src/main/java/fr/atesab/xray/XrayMain.java b/src/main/java/fr/atesab/xray/XrayMain.java index 37dea8f..48afff5 100644 --- a/src/main/java/fr/atesab/xray/XrayMain.java +++ b/src/main/java/fr/atesab/xray/XrayMain.java @@ -1,10 +1,31 @@ package fr.atesab.xray; +import java.io.File; +import java.net.URL; +import java.util.Collection; +import java.util.List; +import java.util.Locale; +import java.util.Objects; +import java.util.stream.Collector; +import java.util.stream.Collectors; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.joml.Vector3f; +import org.lwjgl.glfw.GLFW; +import org.lwjgl.opengl.GL11; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + import com.mojang.blaze3d.systems.RenderSystem; + import fr.atesab.xray.color.ColorSupplier; import fr.atesab.xray.color.IColorObject; import fr.atesab.xray.color.TextHudBuffer; -import fr.atesab.xray.config.*; +import fr.atesab.xray.config.AbstractModeConfig; +import fr.atesab.xray.config.BlockConfig; +import fr.atesab.xray.config.ESPConfig; +import fr.atesab.xray.config.LocationFormatTool; +import fr.atesab.xray.config.XrayConfig; import fr.atesab.xray.screen.XrayMenu; import fr.atesab.xray.utils.GuiUtils; import fr.atesab.xray.utils.GuiUtils.RGBResult; @@ -30,7 +51,12 @@ import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.option.KeyBinding; import net.minecraft.client.option.SimpleOption; -import net.minecraft.client.render.*; +import net.minecraft.client.render.BufferBuilder; +import net.minecraft.client.render.Camera; +import net.minecraft.client.render.GameRenderer; +import net.minecraft.client.render.Tessellator; +import net.minecraft.client.render.VertexFormat; +import net.minecraft.client.render.VertexFormats; import net.minecraft.client.resource.language.I18n; import net.minecraft.client.util.InputUtil; import net.minecraft.client.util.math.MatrixStack; @@ -39,22 +65,14 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.registry.Registries; import net.minecraft.text.Text; -import net.minecraft.util.math.*; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Box; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.BlockView; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.ChunkStatus; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.joml.Vector3f; -import org.lwjgl.glfw.GLFW; -import org.lwjgl.opengl.GL11; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.io.File; -import java.net.URL; -import java.util.*; -import java.util.stream.Collector; -import java.util.stream.Collectors; public class XrayMain implements ClientModInitializer, HudRenderCallback, EndTick, AfterEntities { public static final String MOD_ID = "atianxray"; @@ -423,7 +441,8 @@ public void afterEntities(WorldRenderContext context) { blockPos.getX() + 1, blockPos.getY() + 1, blockPos.getZ() + 1 ); - WorldRenderer.drawBox(stack, buffer, aabb, r, g, b, a); + RenderUtils.drawBoxVanillaStyle(stack, buffer, aabb, r, g, b, a); + //WorldRenderer.drawBox(stack, buffer, aabb, r, g, b, a); if (esp.hasTracer()) { Vec3d center = aabb.getCenter(); @@ -468,7 +487,8 @@ public void afterEntities(WorldRenderContext context) { Box aabb = type.createSimpleBoundingBox(x, y, z); - WorldRenderer.drawBox(stack, buffer, aabb, r, g, b, a); + RenderUtils.drawBoxVanillaStyle(stack, buffer, aabb, r, g, b, a); + //WorldRenderer.drawBox(stack, buffer, aabb, r, g, b, a); if (esp.hasTracer()) { Vec3d center = aabb.getCenter(); diff --git a/src/main/java/fr/atesab/xray/mixins/MixinBlockOcclusionCache.java b/src/main/java/fr/atesab/xray/mixins/MixinBlockOcclusionCache.java index 3bfe4f6..37ec781 100644 --- a/src/main/java/fr/atesab/xray/mixins/MixinBlockOcclusionCache.java +++ b/src/main/java/fr/atesab/xray/mixins/MixinBlockOcclusionCache.java @@ -1,21 +1,22 @@ package fr.atesab.xray.mixins; +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 fr.atesab.xray.XrayMain; +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; import net.minecraft.world.BlockView; -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 = "me.jellysquid.mods.sodium.client.render.occlusion.BlockOcclusionCache") +//@Pseudo +@Mixin(value = BlockOcclusionCache.class) public class MixinBlockOcclusionCache { - @Inject(at = @At("HEAD"), method = "shouldDrawSide", cancellable = true, remap = false) - private void shouldDrawSide(BlockState state, BlockView reader, BlockPos pos, Direction face, + @Inject(at = @At("RETURN"), method = "shouldDrawSide", cancellable = true, remap = false) + public void shouldDrawSide(BlockState state, BlockView reader, BlockPos pos, Direction face, CallbackInfoReturnable ci) { XrayMain.getMod().shouldSideBeRendered(state, reader, pos, face, ci); } diff --git a/src/main/java/fr/atesab/xray/utils/RenderUtils.java b/src/main/java/fr/atesab/xray/utils/RenderUtils.java index bff6476..cdbe8d2 100644 --- a/src/main/java/fr/atesab/xray/utils/RenderUtils.java +++ b/src/main/java/fr/atesab/xray/utils/RenderUtils.java @@ -1,11 +1,13 @@ package fr.atesab.xray.utils; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.util.math.MatrixStack; import org.joml.Matrix3f; import org.joml.Matrix4f; import org.joml.Vector3f; +import net.minecraft.client.render.VertexConsumer; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.math.Box; + public class RenderUtils { public static void renderSingleLine(MatrixStack stack, VertexConsumer buffer, float x1, float y1, float z1, @@ -28,6 +30,65 @@ public static void renderSingleLine(MatrixStack stack, VertexConsumer buffer, fl .normal(matrix3f, normalX, normalY, normalZ).next(); } - private RenderUtils() { + + // copied vanilla code for Sodium/Rubidium compatibility, because they overwrite and broke this vanilla code. + public static void drawBoxVanillaStyle(MatrixStack matrices, VertexConsumer vertexConsumer, Box box, float red, float green, float blue, float alpha) { + drawBoxVanillaStyle(matrices, vertexConsumer, box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ, red, green, blue, alpha, red, green, blue); + } + + public static void drawBoxVanillaStyle(MatrixStack matrices, VertexConsumer vertexConsumer, double x1, double y1, double z1, double x2, double y2, double z2, float red, float green, float blue, float alpha) { + drawBoxVanillaStyle(matrices, vertexConsumer, x1, y1, z1, x2, y2, z2, red, green, blue, alpha, red, green, blue); + } + + public static void drawBoxVanillaStyle(MatrixStack matrices, VertexConsumer vertexConsumer, double x1, double y1, double z1, double x2, double y2, double z2, float red, float green, float blue, float alpha, float xAxisRed, float yAxisGreen, float zAxisBlue) { + Matrix4f matrix4f = matrices.peek().getPositionMatrix(); + Matrix3f matrix3f = matrices.peek().getNormalMatrix(); + float f = (float)x1; + float g = (float)y1; + float h = (float)z1; + float i = (float)x2; + float j = (float)y2; + float k = (float)z2; + + vertexConsumer.vertex(matrix4f, f, g, h).color(red, yAxisGreen, zAxisBlue, alpha).normal(matrix3f, 1.0F, 0.0F, 0.0F).next(); + vertexConsumer.vertex(matrix4f, i, g, h).color(red, yAxisGreen, zAxisBlue, alpha).normal(matrix3f, 1.0F, 0.0F, 0.0F).next(); + + vertexConsumer.vertex(matrix4f, f, g, h).color(xAxisRed, green, zAxisBlue, alpha).normal(matrix3f, 0.0F, 1.0F, 0.0F).next(); + vertexConsumer.vertex(matrix4f, f, j, h).color(xAxisRed, green, zAxisBlue, alpha).normal(matrix3f, 0.0F, 1.0F, 0.0F).next(); + + vertexConsumer.vertex(matrix4f, f, g, h).color(xAxisRed, yAxisGreen, blue, alpha).normal(matrix3f, 0.0F, 0.0F, 1.0F).next(); + vertexConsumer.vertex(matrix4f, f, g, k).color(xAxisRed, yAxisGreen, blue, alpha).normal(matrix3f, 0.0F, 0.0F, 1.0F).next(); + + + vertexConsumer.vertex(matrix4f, i, g, h).color(red, green, blue, alpha).normal(matrix3f, 0.0F, 1.0F, 0.0F).next(); + vertexConsumer.vertex(matrix4f, i, j, h).color(red, green, blue, alpha).normal(matrix3f, 0.0F, 1.0F, 0.0F).next(); + + vertexConsumer.vertex(matrix4f, i, j, h).color(red, green, blue, alpha).normal(matrix3f, -1.0F, 0.0F, 0.0F).next(); + vertexConsumer.vertex(matrix4f, f, j, h).color(red, green, blue, alpha).normal(matrix3f, -1.0F, 0.0F, 0.0F).next(); + + vertexConsumer.vertex(matrix4f, f, j, h).color(red, green, blue, alpha).normal(matrix3f, 0.0F, 0.0F, 1.0F).next(); + vertexConsumer.vertex(matrix4f, f, j, k).color(red, green, blue, alpha).normal(matrix3f, 0.0F, 0.0F, 1.0F).next(); + + vertexConsumer.vertex(matrix4f, f, j, k).color(red, green, blue, alpha).normal(matrix3f, 0.0F, -1.0F, 0.0F).next(); + vertexConsumer.vertex(matrix4f, f, g, k).color(red, green, blue, alpha).normal(matrix3f, 0.0F, -1.0F, 0.0F).next(); + + vertexConsumer.vertex(matrix4f, f, g, k).color(red, green, blue, alpha).normal(matrix3f, 1.0F, 0.0F, 0.0F).next(); + vertexConsumer.vertex(matrix4f, i, g, k).color(red, green, blue, alpha).normal(matrix3f, 1.0F, 0.0F, 0.0F).next(); + + vertexConsumer.vertex(matrix4f, i, g, k).color(red, green, blue, alpha).normal(matrix3f, 0.0F, 0.0F, -1.0F).next(); + vertexConsumer.vertex(matrix4f, i, g, h).color(red, green, blue, alpha).normal(matrix3f, 0.0F, 0.0F, -1.0F).next(); + + + vertexConsumer.vertex(matrix4f, f, j, k).color(red, green, blue, alpha).normal(matrix3f, 1.0F, 0.0F, 0.0F).next(); + vertexConsumer.vertex(matrix4f, i, j, k).color(red, green, blue, alpha).normal(matrix3f, 1.0F, 0.0F, 0.0F).next(); + + vertexConsumer.vertex(matrix4f, i, g, k).color(red, green, blue, alpha).normal(matrix3f, 0.0F, 1.0F, 0.0F).next(); + vertexConsumer.vertex(matrix4f, i, j, k).color(red, green, blue, alpha).normal(matrix3f, 0.0F, 1.0F, 0.0F).next(); + + vertexConsumer.vertex(matrix4f, i, j, h).color(red, green, blue, alpha).normal(matrix3f, 0.0F, 0.0F, 1.0F).next(); + vertexConsumer.vertex(matrix4f, i, j, k).color(red, green, blue, alpha).normal(matrix3f, 0.0F, 0.0F, 1.0F).next(); + } + + private RenderUtils() { } }