Skip to content

Commit 0d2ea62

Browse files
feat: rendering + shader fixes + lava issue + other issues
1 parent 60dbe9e commit 0d2ea62

File tree

12 files changed

+86
-146
lines changed

12 files changed

+86
-146
lines changed

common/src/main/java/pro/mikey/xray/XRay.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import org.apache.logging.log4j.LogManager;
88
import org.apache.logging.log4j.Logger;
99
import org.lwjgl.glfw.GLFW;
10-
import pro.mikey.xray.compatability.IrisCompat;
1110
import pro.mikey.xray.screens.ScanManageScreen;
1211
import pro.mikey.xray.utils.XPlatShim;
1312
import pro.mikey.xray.core.ScanController;
@@ -27,10 +26,6 @@ public enum XRay {
2726
public static final KeyMapping OPEN_GUI_KEY = new KeyMapping(I18n.get("xray.config.open"), GLFW.GLFW_KEY_G, CATEGORY);
2827

2928
public void init() {
30-
if (XPLAT.isModLoaded("iris")) {
31-
LOGGER.info("Iris detected, enabling compatibility features.");
32-
IrisCompat.init();
33-
}
3429
}
3530

3631
public void onToggleKeyPressed() {

common/src/main/java/pro/mikey/xray/compatability/IrisCompat.java

Lines changed: 0 additions & 11 deletions
This file was deleted.

common/src/main/java/pro/mikey/xray/core/ChunkScanTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void run() {
4040
fluidState = state.getFluidState();
4141

4242
if ((fluidState.getType() == Fluids.LAVA || fluidState.getType() == Fluids.FLOWING_LAVA) && ScanController.INSTANCE.isLavaActive()) {
43-
renderQueue.add(new OutlineRenderTarget(pos.getX(), pos.getY(), pos.getZ(), 0xff0000));
43+
renderQueue.add(new OutlineRenderTarget(pos.getX(), pos.getY(), pos.getZ(), 0xffff0000));
4444
continue;
4545
}
4646

common/src/main/java/pro/mikey/xray/core/OutlineRender.java

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,33 @@
44
import com.mojang.blaze3d.buffers.GpuBufferSlice;
55
import com.mojang.blaze3d.pipeline.BlendFunction;
66
import com.mojang.blaze3d.pipeline.RenderPipeline;
7-
import com.mojang.blaze3d.pipeline.RenderTarget;
87
import com.mojang.blaze3d.systems.RenderPass;
98
import com.mojang.blaze3d.systems.RenderSystem;
109
import com.mojang.blaze3d.textures.GpuTextureView;
1110
import com.mojang.blaze3d.vertex.*;
12-
import net.irisshaders.iris.api.v0.IrisApi;
13-
import net.irisshaders.iris.api.v0.IrisProgram;
1411
import net.minecraft.client.Minecraft;
1512
import net.minecraft.client.renderer.DynamicUniforms;
1613
import net.minecraft.client.renderer.RenderPipelines;
1714
import net.minecraft.client.renderer.ShapeRenderer;
18-
import net.minecraft.resources.ResourceLocation;
15+
import net.minecraft.resources.Identifier;
1916
import net.minecraft.world.level.ChunkPos;
2017
import net.minecraft.world.phys.Vec3;
18+
import net.minecraft.world.phys.shapes.Shapes;
2119
import org.joml.Matrix4f;
2220
import org.joml.Matrix4fStack;
2321
import org.joml.Vector3f;
2422
import org.joml.Vector4f;
2523
import org.lwjgl.opengl.GL11;
26-
import pro.mikey.xray.XRay;
2724

2825
import java.io.Closeable;
2926
import java.util.*;
3027

3128
public class OutlineRender {
32-
3329
private static final RenderSystem.AutoStorageIndexBuffer indices = RenderSystem.getSequentialBuffer(VertexFormat.Mode.LINES);
3430
private static final Map<ChunkPos, VBOHolder> vertexBuffers = new HashMap<>();
3531

3632
private static final Set<ChunkPos> chunksToRefresh = Collections.synchronizedSet(new HashSet<>());
3733

38-
public static RenderPipeline LINES_NO_DEPTH = RenderPipeline.builder(RenderPipelines.MATRICES_FOG_SNIPPET, RenderPipelines.GLOBALS_SNIPPET)
39-
.withLocation(ResourceLocation.fromNamespaceAndPath(XRay.MOD_ID, "pipeline/lines_2"))
40-
.withVertexShader("core/rendertype_lines")
41-
.withFragmentShader(ResourceLocation.fromNamespaceAndPath(XRay.MOD_ID, "frag/constant_color"))
42-
.withBlend(BlendFunction.TRANSLUCENT)
43-
.withCull(false)
44-
.withVertexFormat(DefaultVertexFormat.POSITION_COLOR_NORMAL, VertexFormat.Mode.LINES)
45-
.build();
46-
4734
public static void renderBlocks(PoseStack poseStack) {
4835
if (!ScanController.INSTANCE.isXRayActive() || Minecraft.getInstance().player == null) {
4936
return;
@@ -78,7 +65,7 @@ public static void renderBlocks(PoseStack poseStack) {
7865

7966
VBOHolder holder = vertexBuffers.get(chunkPos);
8067
if (holder == null) {
81-
BufferBuilder bufferBuilder = Tesselator.getInstance().begin(LINES_NO_DEPTH.getVertexFormatMode(), LINES_NO_DEPTH.getVertexFormat());
68+
BufferBuilder bufferBuilder = Tesselator.getInstance().begin(RenderPipelines.LINES.getVertexFormatMode(), RenderPipelines.LINES.getVertexFormat());
8269

8370
// More concurrent modification exceptions can happen here, so we clone the list
8471
var blockPropsClone = new ArrayList<>(blocksWithProps);
@@ -88,18 +75,9 @@ public static void renderBlocks(PoseStack poseStack) {
8875
continue;
8976
}
9077

91-
final float size = 1.0f;
92-
final int x = blockProps.x(), y = blockProps.y(), z = blockProps.z();
93-
94-
final float alpha = ((blockProps.color() >> 24) & 0xff) / 255f;
95-
final float red = (blockProps.color() >> 16 & 0xff) / 255f;
96-
final float green = (blockProps.color() >> 8 & 0xff) / 255f;
97-
final float blue = (blockProps.color() & 0xff) / 255f;
98-
99-
// Use the alpha from the color, or default to 1.0 if alpha is 0
100-
final float opacity = alpha > 0 ? alpha : 1.0f;
78+
final int x = blockProps.x(), y = blockProps.y(), z = blockProps.z();
10179

102-
ShapeRenderer.renderLineBox(poseStack.last(), bufferBuilder, x, y, z, x + size, y + size, z + size, red, green, blue, opacity);
80+
ShapeRenderer.renderShape(poseStack, bufferBuilder, Shapes.block(), x, y, z, blockProps.color(), 1f);
10381
}
10482

10583
try (MeshData meshData = bufferBuilder.buildOrThrow()) {
@@ -116,40 +94,34 @@ public static void renderBlocks(PoseStack poseStack) {
11694
continue;
11795
}
11896

119-
Vec3 playerPos = Minecraft.getInstance().gameRenderer.getMainCamera().getPosition().reverse();
120-
121-
RenderTarget renderTarget = Minecraft.getInstance().getMainRenderTarget();
122-
if (renderTarget.getColorTexture() == null) {
123-
return;
124-
}
97+
Vec3 playerPos = Minecraft.getInstance().gameRenderer.getMainCamera().position().reverse();
12598

12699
Matrix4fStack matrix4fStack = RenderSystem.getModelViewStack();
127100
GpuTextureView colorTextureView = Minecraft.getInstance().getMainRenderTarget().getColorTextureView();
128101
GpuTextureView depthTextureView = Minecraft.getInstance().getMainRenderTarget().getDepthTextureView();
129102

130103
matrix4fStack.pushMatrix();
131104
matrix4fStack.translate((float) playerPos.x(), (float) playerPos.y(), (float) playerPos.z());
132-
GpuBufferSlice[] gpubufferslice = RenderSystem.getDynamicUniforms().writeTransforms(new DynamicUniforms.Transform(RenderSystem.getModelViewMatrix(), new Vector4f(1.0F, 1.0F, 1.0F, 1.0F), new Vector3f(), new Matrix4f(), 2.0F));
133-
matrix4fStack.popMatrix();
105+
GpuBufferSlice[] gpubufferslice = RenderSystem.getDynamicUniforms().writeTransforms(new DynamicUniforms.Transform(new Matrix4f(matrix4fStack), new Vector4f(1.0F, 1.0F, 1.0F, 1.0F), new Vector3f(), new Matrix4f()));
106+
107+
GL11.glDisable(GL11.GL_DEPTH_TEST);
108+
RenderSystem.setShaderFog(gpubufferslice[0]);
134109

135110
GpuBuffer gpuBuffer = indices.getBuffer(holder.indexCount);
136111
try (RenderPass renderPass = RenderSystem.getDevice()
137112
.createCommandEncoder()
138113
.createRenderPass(() -> "xray", colorTextureView, OptionalInt.empty(), depthTextureView, OptionalDouble.empty())) {
139114

140-
GL11.glDisable(GL11.GL_DEPTH_TEST);
141-
142-
renderPass.setPipeline(LINES_NO_DEPTH);
143115
RenderSystem.bindDefaultUniforms(renderPass);
144116
renderPass.setVertexBuffer(0, holder.vertexBuffer);
145117
renderPass.setIndexBuffer(gpuBuffer, indices.type());
146118
renderPass.setUniform("DynamicTransforms", gpubufferslice[0]);
147-
renderPass.setPipeline(LINES_NO_DEPTH);
119+
renderPass.setPipeline(RenderPipelines.LINES);
148120
renderPass.drawIndexed(0, 0, holder.indexCount, 1);
149-
150-
// Re-enable depth test after drawing
151-
GL11.glEnable(GL11.GL_DEPTH_TEST);
152121
}
122+
123+
GL11.glEnable(GL11.GL_DEPTH_TEST);
124+
matrix4fStack.popMatrix();
153125
}
154126
}
155127

common/src/main/java/pro/mikey/xray/core/ScanController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public synchronized void requestBlockFinder(boolean force) {
150150
OutlineRender.clearVBOs(); // Clear the VBOs as well
151151
}
152152

153-
if (this.scanStore.activeScanTargets().isEmpty()) {
153+
if (this.scanStore.activeScanTargets().isEmpty() && !isLavaActive()) {
154154
return;
155155
}
156156

common/src/main/java/pro/mikey/xray/screens/ScanConfigureScreen.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,28 @@ public void init() {
7575
layout.setPosition(getWidth() / 2 - 100, getHeight() / 2 + 85);
7676
GridLayout.RowHelper rowHelper = layout.createRowHelper(3);
7777

78-
rowHelper.addChild(ImageButton.builder(b -> {
79-
removeBlock();
80-
})
81-
.image(XRay.assetLocation("gui/trash.png"), 16, 16)
82-
.size(20, 20)
83-
.build());
78+
if (editingType != null) {
79+
rowHelper.addChild(ImageButton.builder(b -> {
80+
removeBlock();
81+
})
82+
.image(XRay.assetLocation("gui/trash.png"), 16, 16)
83+
.size(20, 20)
84+
.build());
85+
}
8486

8587
rowHelper.addChild(Button.builder(Component.translatable("xray.single.cancel"), b -> Minecraft.getInstance().setScreen(this.previousScreenCallback.get()))
8688
.size(60, 20)
8789
.build());
8890

8991
rowHelper.addChild(Button.builder(Component.translatable(editingType != null ? "xray.title.edit" : "xray.single.add"), b -> {
90-
if (editingType != null) {
91-
editBlock();
92-
} else {
93-
addBlock();
94-
}
95-
})
96-
.size(117, 20)
97-
.build());
92+
if (editingType != null) {
93+
editBlock();
94+
} else {
95+
addBlock();
96+
}
97+
})
98+
.size(editingType != null ? 117 : 138, 20)
99+
.build());
98100

99101
layout.arrangeElements();
100102
layout.visitWidgets(this::addRenderableWidget);
@@ -116,7 +118,7 @@ public void init() {
116118

117119
addRenderableWidget(redSlider = new SliderWidget(getWidth() / 2 - 100, getHeight() / 2 - 16, 202, 20, "xray.color.red", red));
118120
addRenderableWidget(greenSlider = new SliderWidget(getWidth() / 2 - 100, getHeight() / 2 + 7, 202, 20, "xray.color.green", green));
119-
addRenderableWidget(blueSlider = new SliderWidget(getWidth() / 2 - 100, getHeight() / 2 + 30, 202, 20, "xray.color.blue", blue));
121+
addRenderableWidget(blueSlider = new SliderWidget(getWidth() / 2 - 100, getHeight() / 2 + 30, 202, 20, "xray.color.blue", blue));
120122
addRenderableWidget(alphaSlider = new SliderWidget(getWidth() / 2 - 100, getHeight() / 2 + 53, 202, 20, "xray.color.alpha", alpha));
121123

122124
oreName = new EditBox(minecraft.font, getWidth() / 2 - 100, getHeight() / 2 - 70, 202, 20, Component.empty());

common/src/main/java/pro/mikey/xray/screens/ScanManageScreen.java

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.minecraft.client.gui.components.Button;
77
import net.minecraft.client.gui.components.EditBox;
88
import net.minecraft.client.gui.components.ObjectSelectionList;
9+
import net.minecraft.client.gui.components.Tooltip;
910
import net.minecraft.client.input.KeyEvent;
1011
import net.minecraft.client.input.MouseButtonEvent;
1112
import net.minecraft.client.renderer.RenderPipelines;
@@ -78,12 +79,17 @@ public void init() {
7879
this.search.setCanLoseFocus(true);
7980
addRenderableWidget(this.search);
8081

81-
// side bar buttons
82-
addRenderableWidget(new SupportButtonInner((getWidth() / 2) + 79, getHeight() / 2 - 60, 120, 20, Component.translatable("xray.input.add"), "xray.tooltips.add_block", button -> {
83-
minecraft.setScreen(new FindBlockScreen());
84-
}));
82+
addRenderableWidget(
83+
Button.builder(Component.translatable("xray.input.add"), (btn) -> {
84+
minecraft.setScreen(new FindBlockScreen());
85+
})
86+
.pos((getWidth() / 2) + 79, getHeight() / 2 - 60)
87+
.size(120, 20)
88+
.tooltip(Tooltip.create(Component.translatable("xray.tooltips.add_block")))
89+
.build()
90+
);
8591

86-
addRenderableWidget(new SupportButtonInner(getWidth() / 2 + 79, getHeight() / 2 - 38, 120, 20, Component.translatable("xray.input.add_hand"), "xray.tooltips.add_block_in_hand", button -> {
92+
addRenderableWidget(Button.builder(Component.translatable("xray.input.add_hand"), btn -> {
8793
ItemStack handItem = minecraft.player.getItemInHand(InteractionHand.MAIN_HAND);
8894

8995
// Check if the hand item is a block or not
@@ -94,9 +100,14 @@ public void init() {
94100
}
95101

96102
minecraft.setScreen(new ScanConfigureScreen(((BlockItem) handItem.getItem()).getBlock(), ScanManageScreen::new));
97-
}));
103+
})
104+
.pos(getWidth() / 2 + 79, getHeight() / 2 - 38)
105+
.size(120, 20)
106+
.tooltip(Tooltip.create(Component.translatable("xray.tooltips.add_block_in_hand")))
107+
.build()
108+
);
98109

99-
addRenderableWidget(new SupportButtonInner(getWidth() / 2 + 79, getHeight() / 2 - 16, 120, 20, Component.translatable("xray.input.add_look"), "xray.tooltips.add_block_looking_at", button -> {
110+
addRenderableWidget(Button.builder(Component.translatable("xray.input.add_look"), btn -> {
100111
Player player = minecraft.player;
101112
if (minecraft.level == null || player == null) {
102113
return;
@@ -122,17 +133,33 @@ public void init() {
122133
player.displayClientMessage(Component.literal("[XRay] " + I18n.get("xray.message.thats_odd")), false);
123134
this.onClose();
124135
}
125-
}));
136+
})
137+
.pos(getWidth() / 2 + 79, getHeight() / 2 - 16)
138+
.size(120, 20)
139+
.tooltip(Tooltip.create(Component.translatable("xray.tooltips.add_block_looking_at"))
140+
).build());
141+
126142

127-
addRenderableWidget(distButtons = new SupportButtonInner((getWidth() / 2) + 79, getHeight() / 2 + 6, 120, 20, Component.translatable("xray.input.show-lava", ScanController.INSTANCE.isLavaActive()), "xray.tooltips.show_lava", button -> {
128-
ScanController.INSTANCE.toggleLava();
129-
button.setMessage(Component.translatable("xray.input.show-lava", ScanController.INSTANCE.isLavaActive()));
130-
}));
131143

132-
addRenderableWidget(distButtons = new SupportButtonInner((getWidth() / 2) + 79, getHeight() / 2 + 36, 120, 20, Component.translatable("xray.input.distance", ScanController.INSTANCE.getVisualRadius()), "xray.tooltips.distance", button -> {
144+
addRenderableWidget(Button.builder(Component.translatable("xray.input.show-lava", ScanController.INSTANCE.isLavaActive()), btn -> {
145+
ScanController.INSTANCE.toggleLava();
146+
btn.setMessage(Component.translatable("xray.input.show-lava", ScanController.INSTANCE.isLavaActive()));
147+
})
148+
.pos(getWidth() / 2 + 79, getHeight() / 2 + 6)
149+
.size(120, 20)
150+
.tooltip(Tooltip.create(Component.translatable("xray.tooltips.show_lava")))
151+
.build());
152+
153+
154+
addRenderableWidget(distButtons = Button.builder(Component.translatable("xray.input.distance", ScanController.INSTANCE.getVisualRadius()), btn -> {
133155
ScanController.INSTANCE.incrementCurrentDist();
134-
button.setMessage(Component.translatable("xray.input.distance", ScanController.INSTANCE.getVisualRadius()));
135-
}));
156+
btn.setMessage(Component.translatable("xray.input.distance", ScanController.INSTANCE.getVisualRadius()));
157+
})
158+
.pos(getWidth() / 2 + 79, getHeight() / 2 + 36)
159+
.size(120, 20)
160+
.tooltip(Tooltip.create(Component.translatable("xray.tooltips.distance")))
161+
.build()
162+
);
136163

137164
addRenderableWidget(
138165
Button.builder(Component.translatable("xray.single.help"), button -> {
@@ -184,6 +211,7 @@ public boolean mouseClicked(MouseButtonEvent event, boolean bl) {
184211
if (search.mouseClicked(event, bl))
185212
this.setFocused(search);
186213

214+
// Shift action!
187215
if (event.button() == 1 && distButtons.isMouseOver(event.x(), event.y())) {
188216
ScanController.INSTANCE.decrementCurrentDist();
189217
distButtons.setMessage(Component.translatable("xray.input.distance", ScanController.INSTANCE.getVisualRadius()));

common/src/main/resources/assets/xray/shaders/frag/constant_color.fsh

Lines changed: 0 additions & 11 deletions
This file was deleted.

fabric/src/main/java/pro/mikey/xray/fabric/XRayFabric.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
66
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
77
import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElementRegistry;
8+
import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderContext;
9+
import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderEvents;
810
import net.minecraft.client.Minecraft;
911
import net.minecraft.resources.Identifier;
1012
import pro.mikey.xray.ClientController;
1113
import pro.mikey.xray.XRay;
14+
import pro.mikey.xray.core.OutlineRender;
1215
import pro.mikey.xray.screens.HudOverlay;
1316
import pro.mikey.xray.core.ScanController;
1417

@@ -24,12 +27,15 @@ public void onInitializeClient() {
2427

2528
ClientTickEvents.END_CLIENT_TICK.register(this::clientTickEvent);
2629
ClientLifecycleEvents.CLIENT_STARTED.register((mc) -> ClientController.onSetup());
27-
// TODO: Fixme
28-
// WorldRenderEvents.LAST.register((context) -> OutlineRender.renderBlocks(context.matrixStack()));
30+
WorldRenderEvents.END_MAIN.register(this::renderOverlay);
2931

3032
HudElementRegistry.addLast(HUD_ELEMENT_ID, (guiGraphics, tickCounter) -> HudOverlay.renderGameOverlayEvent(guiGraphics));
3133
}
3234

35+
private void renderOverlay(WorldRenderContext worldRenderContext) {
36+
OutlineRender.renderBlocks(worldRenderContext.matrices());
37+
}
38+
3339
private void clientTickEvent(Minecraft mc) {
3440
if (mc.player == null || mc.level == null || mc.screen != null) {
3541
return;

0 commit comments

Comments
 (0)