Skip to content

Commit

Permalink
fix: mapping issues, world height checking, chunkPos fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHillcox committed Feb 14, 2021
1 parent 6377aa5 commit 27b1aa3
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 33 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
org.gradle.jvmargs=-Xmx4G
# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.16.5
yarn_mappings=1.16.5+build.3
minecraft_version=21w06a
yarn_mappings=21w06a+build.20
loader_version=0.11.1
# Mod Properties
mod_version=0.5.0
mod_version=0.5.0s
maven_group=pro.mikey.fabric.xray
archives_base_name=advanced-xray-fabric
# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.30.0+1.16
fabric_version=0.30.2+1.17
6 changes: 2 additions & 4 deletions src/main/java/pro/mikey/fabric/xray/ScanController.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ private static boolean playerLocationChanged() {
return false;
}

return playerLastChunk == null
|| playerLastChunk.x != player.chunkX
|| playerLastChunk.z != player.chunkZ;
return playerLastChunk == null || !playerLastChunk.equals(player.getChunkPos());
}

/**
Expand All @@ -45,7 +43,7 @@ public static synchronized void runTask(boolean forceRerun) {
}

// Update the players last chunk to eval against above.
playerLastChunk = new ChunkPos(client.player.chunkX, client.player.chunkZ);
playerLastChunk = client.player.getChunkPos();
Util.getMainWorkerExecutor().execute(new ScanTask());
}
}
6 changes: 3 additions & 3 deletions src/main/java/pro/mikey/fabric/xray/ScanTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ private Set<BlockPosWithColor> collectBlocks() {

final Set<BlockPosWithColor> renderQueue = new HashSet<>();

int cX = player.chunkX;
int cZ = player.chunkZ;
int cX = player.getChunkPos().x;
int cZ = player.getChunkPos().z;

int range = StateSettings.DISTANCE_STEPS[Stores.SETTINGS.get().getRange()] / 2;

Expand All @@ -76,7 +76,7 @@ private Set<BlockPosWithColor> collectBlocks() {

for (int k = chunkStartX; k < chunkStartX + 16; k++) {
for (int l = chunkStartZ; l < chunkStartZ + 16; l++) {
for (int m = 0; m < height + (1 << 4); m++) {
for (int m = world.getBottomY(); m < height + (1 << 4); m++) {
BlockPos pos = new BlockPos(k, m, l);
BasicColor validBlock = this.isValidBlock(pos, world, blocks);
if (validBlock != null) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pro/mikey/fabric/xray/XRay.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.options.KeyBinding;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import org.apache.logging.log4j.LogManager;
Expand Down
49 changes: 34 additions & 15 deletions src/main/java/pro/mikey/fabric/xray/render/XRayRenderType.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,45 @@
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import org.lwjgl.opengl.GL11;

import java.util.OptionalDouble;

public class XRayRenderType extends RenderLayer {
private static final LineWidth THICK_LINES = new LineWidth(OptionalDouble.of(3.0D));
static final RenderLayer OVERLAY_LINES = of("overlay_lines",
VertexFormats.POSITION_COLOR, GL11.GL_LINES, 256,
RenderLayer.MultiPhaseParameters.builder().lineWidth(THICK_LINES)
.layering(VIEW_OFFSET_Z_LAYERING)
.transparency(TRANSLUCENT_TRANSPARENCY)
.texture(NO_TEXTURE)
.depthTest(ALWAYS_DEPTH_TEST)
.cull(DISABLE_CULLING)
.lightmap(DISABLE_LIGHTMAP)
.writeMaskState(COLOR_MASK)
.build(false)
);
static final RenderLayer OVERLAY_LINES =
of(
"overlay_lines",
VertexFormats.POSITION_COLOR,
VertexFormat.DrawMode.LINES,
256,
RenderLayer.MultiPhaseParameters.builder()
.lineWidth(THICK_LINES)
.layering(VIEW_OFFSET_Z_LAYERING)
.transparency(TRANSLUCENT_TRANSPARENCY)
.texture(NO_TEXTURE)
.depthTest(ALWAYS_DEPTH_TEST)
.cull(DISABLE_CULLING)
.lightmap(DISABLE_LIGHTMAP)
.writeMaskState(COLOR_MASK)
.build(false));

public XRayRenderType(String name, VertexFormat vertexFormat, int drawMode, int expectedBufferSize, boolean hasCrumbling, boolean translucent, Runnable startAction, Runnable endAction) {
super(name, vertexFormat, drawMode, expectedBufferSize, hasCrumbling, translucent, startAction, endAction);
public XRayRenderType(
String name,
VertexFormat vertexFormat,
VertexFormat.DrawMode drawMode,
int expectedBufferSize,
boolean hasCrumbling,
boolean translucent,
Runnable startAction,
Runnable endAction) {
super(
name,
vertexFormat,
drawMode,
expectedBufferSize,
hasCrumbling,
translucent,
startAction,
endAction);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import net.minecraft.block.BlockState;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.DiffuseLighting;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.render.*;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -56,7 +53,7 @@ static void renderPreview(int x, int y, float r, float g, float b) {
GlStateManager.SrcFactor.ONE,
GlStateManager.DstFactor.ZERO);
RenderSystem.color4f(r / 255, g / 255, b / 255, 1);
tessellate.begin(7, VertexFormats.POSITION);
tessellate.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION);
tessellate.vertex(x, y, 0.0D).next();
tessellate.vertex(x, y + 64, 0.0D).next();
tessellate.vertex(x + 100, y + 64, 0.0D).next();
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"depends": {
"fabricloader": ">=0.7.4",
"fabric": "*",
"minecraft": "1.16.x"
"minecraft": "1.17.x"
}
}

0 comments on commit 27b1aa3

Please sign in to comment.