Skip to content

Commit 1c1eb6f

Browse files
feat: updated to 1.18.2, fixed block store issues, much better performance
1 parent 1286aaf commit 1c1eb6f

26 files changed

+740
-1116
lines changed

CHANGELOG.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
# Changelog
22

3-
Updated to Minecraft 1.18
3+
## Added
4+
5+
- New render logic (from Forge version) that greatly improves performance!
6+
- Auto-populate block list with Ores
7+
- This only happens when the list is empty and opened for the first time.
8+
9+
## Changed
10+
11+
- Updated to 1.18.2!
12+
- We no longer store if `XRay` is on in a file so upon a game restart, it will now always be off by default.
13+
- Use a different radius number. It's now calculated by chunks around the player. 1 = 1x1, 3 = 3x3 chunks, etc.
14+
15+
## Fixed
16+
17+
- Fixed `Show lava` not rendering working when the blocks to find is empty.

build.gradle

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ sourceCompatibility = JavaVersion.VERSION_17
88
targetCompatibility = JavaVersion.VERSION_17
99

1010
def ENV = System.getenv();
11-
archivesBaseName = "${project.archives_base_name}-${project.minecraft_version}"
12-
version = "${project.mod_version}-build.${ENV.GITHUB_RUN_NUMBER ?: 9999}"
11+
archivesBaseName = "${project.archives_base_name}"
12+
version = "${project.minecraft_version}-${project.mod_version}-build.${ENV.GITHUB_RUN_NUMBER ?: 9999}"
1313
group = project.maven_group
1414

1515
dependencies {
@@ -29,7 +29,6 @@ processResources {
2929
}
3030

3131
tasks.withType(JavaCompile).configureEach {
32-
it.options.encoding = "UTF-8"
3332
it.options.release = 17
3433
}
3534

@@ -73,7 +72,7 @@ if (ENV.CURSE_DEPLOY_TOKEN) {
7372
releaseType = "release"
7473
addGameVersion "Fabric"
7574
addGameVersion "$minecraft_version"
76-
changelog = "See [Commit history](https://github.com/MichaelHillcox/XRay-Fabric/commits/main)"
75+
changelog = file('CHANGELOG.md')
7776
changelogType = 'markdown'
7877
mainArtifact(remapJar)
7978
}

gradle.properties

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
org.gradle.jvmargs=-Xmx4G
33
# Fabric Properties
44
# check these on https://fabricmc.net/use
5-
minecraft_version=1.18
6-
yarn_mappings=1.18+build.1
7-
loader_version=0.12.8
5+
minecraft_version=1.18.2
6+
yarn_mappings=1.18.2+build.2
7+
loader_version=0.13.3
88
# Mod Properties
9-
mod_version=0.7.0
10-
maven_group=pro.mikey.fabric
9+
mod_version=1.0.0
10+
maven_group=pro.mikey
1111
archives_base_name=advanced-xray-fabric
1212
# Dependencies
1313
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
14-
fabric_version=0.43.1+1.18
14+
fabric_version=0.48.0+1.18.2

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ public class ScanController {
2626
* No point even running if the player is still in the same chunk.
2727
*/
2828
private static boolean playerLocationChanged() {
29-
ClientPlayerEntity player = MinecraftClient.getInstance().player;
30-
if (player == null) {
29+
if (MinecraftClient.getInstance().player == null)
3130
return false;
32-
}
3331

34-
return playerLastChunk == null || !playerLastChunk.equals(player.getChunkPos());
32+
ChunkPos plyChunkPos = MinecraftClient.getInstance().player.getChunkPos();
33+
int range = StateSettings.getHalfRange();
34+
35+
return playerLastChunk == null ||
36+
plyChunkPos.x > playerLastChunk.x + range || plyChunkPos.x < playerLastChunk.x - range ||
37+
plyChunkPos.z > playerLastChunk.z + range || plyChunkPos.z < playerLastChunk.z - range;
3538
}
3639

3740
/**
@@ -59,7 +62,7 @@ public static synchronized void runTask(boolean forceRerun) {
5962
public static void blockBroken(World world, PlayerEntity playerEntity, BlockPos blockPos, BlockState blockState, BlockEntity blockEntity) {
6063
if (!Stores.SETTINGS.get().isActive()) return;
6164

62-
if (renderQueue.stream().anyMatch(e -> e.getPos().equals(blockPos))) {
65+
if (renderQueue.stream().anyMatch(e -> e.pos().equals(blockPos))) {
6366
runTask(true);
6467
}
6568
}

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

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111
import pro.mikey.fabric.xray.cache.BlockSearchEntry;
1212
import pro.mikey.fabric.xray.records.BasicColor;
1313
import pro.mikey.fabric.xray.records.BlockPosWithColor;
14+
import pro.mikey.fabric.xray.render.RenderOutlines;
1415
import pro.mikey.fabric.xray.storage.Stores;
1516

1617
import java.util.*;
18+
import java.util.concurrent.atomic.AtomicBoolean;
1719

1820
public class ScanTask implements Runnable {
21+
private static AtomicBoolean isScanning = new AtomicBoolean(false);
22+
1923
ScanTask() {
2024
}
2125

@@ -29,29 +33,31 @@ public static BasicColor isValidBlock(BlockPos pos, World world, Set<BlockSearch
2933
return null;
3034
}
3135

32-
if (Stores.SETTINGS.get().isShowLava()
33-
&& state.getFluidState().getFluid() instanceof LavaFluid) {
36+
if (Stores.SETTINGS.get().isShowLava() && state.getFluidState().getFluid() instanceof LavaFluid) {
3437
return new BasicColor(210, 10, 10);
3538
}
3639

3740
BlockState defaultState = state.getBlock().getDefaultState();
3841

39-
Optional<BlockSearchEntry> contains =
40-
blocks.stream()
41-
.filter(
42-
localState ->
43-
localState.isDefault() && defaultState == localState.getState()
44-
|| !localState.isDefault() && state == localState.getState())
45-
.findFirst();
46-
47-
return contains.map(BlockSearchEntry::getColor).orElse(null);
42+
return blocks.stream()
43+
.filter(localState -> localState.isDefault() && defaultState == localState.getState() || !localState.isDefault() && state == localState.getState())
44+
.findFirst()
45+
.map(BlockSearchEntry::getColor)
46+
.orElse(null);
4847
}
4948

5049
@Override
5150
public void run() {
51+
if (isScanning.get()) {
52+
return;
53+
}
54+
55+
isScanning.set(true);
5256
Set<BlockPosWithColor> c = this.collectBlocks();
5357
ScanController.renderQueue.clear();
5458
ScanController.renderQueue.addAll(c);
59+
isScanning.set(false);
60+
RenderOutlines.requestedRefresh.set(true);
5561
}
5662

5763
/**
@@ -67,7 +73,7 @@ private Set<BlockPosWithColor> collectBlocks() {
6773
Set<BlockSearchEntry> blocks = Stores.BLOCKS.getCache().get();
6874

6975
// If we're not looking for blocks, don't run.
70-
if (blocks.isEmpty()) {
76+
if (blocks.isEmpty() && !Stores.SETTINGS.get().isShowLava()) {
7177
if (!ScanController.renderQueue.isEmpty()) {
7278
ScanController.renderQueue.clear();
7379
}
@@ -89,19 +95,18 @@ private Set<BlockPosWithColor> collectBlocks() {
8995
int cX = player.getChunkPos().x;
9096
int cZ = player.getChunkPos().z;
9197

92-
int range = StateSettings.DISTANCE_STEPS[Stores.SETTINGS.get().getRange()] / 2;
98+
int range = StateSettings.getHalfRange();
9399

94100
for (int i = cX - range; i <= cX + range; i++) {
95101
int chunkStartX = i << 4;
96102
for (int j = cZ - range; j <= cZ + range; j++) {
97103
int chunkStartZ = j << 4;
98104

99-
int height =
100-
Arrays.stream(world.getChunk(i, j).getSectionArray())
101-
.filter(Objects::nonNull)
102-
.mapToInt(ChunkSection::getYOffset)
103-
.max()
104-
.orElse(0);
105+
int height = Arrays.stream(world.getChunk(i, j).getSectionArray())
106+
.filter(Objects::nonNull)
107+
.mapToInt(ChunkSection::getYOffset)
108+
.max()
109+
.orElse(0);
105110

106111
for (int k = chunkStartX; k < chunkStartX + 16; k++) {
107112
for (int l = chunkStartZ; l < chunkStartZ + 16; l++) {
Lines changed: 66 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,70 @@
11
package pro.mikey.fabric.xray;
22

3+
import net.minecraft.util.math.MathHelper;
4+
import pro.mikey.fabric.xray.storage.Stores;
5+
36
public class StateSettings {
4-
public static final int[] DISTANCE_STEPS = new int[] {2, 4, 8, 16, 32, 64, 128, 256};
5-
private boolean isActive;
6-
private boolean showLava;
7-
private int range;
8-
private boolean showOverlay;
9-
10-
public StateSettings() {
11-
this.isActive = false;
12-
this.showLava = false;
13-
this.showOverlay = true;
14-
this.range = 3;
15-
}
16-
17-
public boolean isActive() {
18-
return this.isActive;
19-
}
20-
21-
void setActive(boolean active) {
22-
this.isActive = active;
23-
}
24-
25-
public boolean isShowLava() {
26-
return this.showLava;
27-
}
28-
29-
public void setShowLava(boolean showLava) {
30-
this.showLava = showLava;
31-
}
32-
33-
// Fail softly if the index is out of bounds
34-
public int getRange() {
35-
return Math.max(0, Math.min(DISTANCE_STEPS.length - 1, this.range));
36-
}
37-
38-
public void increaseRange() {
39-
if (this.range < DISTANCE_STEPS.length - 1) {
40-
this.range += 1;
41-
} else {
42-
this.range = 0;
43-
}
44-
}
45-
46-
public void decreaseRange() {
47-
if (this.range > 0) {
48-
this.range -= 1;
49-
} else {
50-
this.range = DISTANCE_STEPS.length - 1;
51-
}
52-
}
53-
54-
public boolean showOverlay() {
55-
return this.showOverlay;
56-
}
57-
58-
public void setShowOverlay(boolean showOverlay) {
59-
this.showOverlay = showOverlay;
60-
}
7+
private static final int maxStepsToScan = 5;
8+
9+
private transient boolean isActive;
10+
private boolean showLava;
11+
private int range;
12+
private boolean showOverlay;
13+
14+
public StateSettings() {
15+
this.isActive = false;
16+
this.showLava = false;
17+
this.showOverlay = true;
18+
this.range = 3;
19+
}
20+
21+
public boolean isActive() {
22+
return this.isActive;
23+
}
24+
25+
void setActive(boolean active) {
26+
this.isActive = active;
27+
}
28+
29+
public boolean isShowLava() {
30+
return this.showLava;
31+
}
32+
33+
public void setShowLava(boolean showLava) {
34+
this.showLava = showLava;
35+
}
36+
37+
public static int getRadius() {
38+
return MathHelper.clamp(Stores.SETTINGS.get().range, 0, maxStepsToScan) * 3;
39+
}
40+
41+
public static int getHalfRange() {
42+
return Math.max(0, getRadius() / 2);
43+
}
44+
45+
public static int getVisualRadius() {
46+
return Math.max(1, getRadius());
47+
}
48+
49+
public void increaseRange() {
50+
if (Stores.SETTINGS.get().range < maxStepsToScan)
51+
Stores.SETTINGS.get().range = Stores.SETTINGS.get().range + 1;
52+
else
53+
Stores.SETTINGS.get().range = 0;
54+
}
55+
56+
public void decreaseRange() {
57+
if (Stores.SETTINGS.get().range > 0)
58+
Stores.SETTINGS.get().range = Stores.SETTINGS.get().range - 1;
59+
else
60+
Stores.SETTINGS.get().range = maxStepsToScan;
61+
}
62+
63+
public boolean showOverlay() {
64+
return this.showOverlay;
65+
}
66+
67+
public void setShowOverlay(boolean showOverlay) {
68+
this.showOverlay = showOverlay;
69+
}
6170
}

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,41 @@
77
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
88
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
99
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
10+
import net.minecraft.block.Block;
11+
import net.minecraft.block.Blocks;
1012
import net.minecraft.client.MinecraftClient;
1113
import net.minecraft.client.option.KeyBinding;
14+
import net.minecraft.item.Item;
15+
import net.minecraft.tag.BlockTags;
16+
import net.minecraft.tag.ItemTags;
17+
import net.minecraft.tag.TagKey;
1218
import net.minecraft.text.TranslatableText;
1319
import net.minecraft.util.Formatting;
20+
import net.minecraft.util.registry.Registry;
21+
import net.minecraft.util.registry.RegistryEntryList;
1422
import org.apache.logging.log4j.LogManager;
1523
import org.apache.logging.log4j.Logger;
1624
import org.lwjgl.glfw.GLFW;
25+
import pro.mikey.fabric.xray.records.BasicColor;
26+
import pro.mikey.fabric.xray.records.BlockEntry;
27+
import pro.mikey.fabric.xray.records.BlockGroup;
1728
import pro.mikey.fabric.xray.render.RenderOutlines;
1829
import pro.mikey.fabric.xray.screens.forge.GuiOverlay;
1930
import pro.mikey.fabric.xray.screens.forge.GuiSelectionScreen;
2031
import pro.mikey.fabric.xray.storage.Stores;
2132

33+
import java.util.*;
34+
import java.util.concurrent.atomic.AtomicInteger;
35+
2236
public class XRay implements ModInitializer {
2337

2438
public static final String MOD_ID = "advanced-xray-fabric";
2539
public static final String PREFIX_GUI = String.format("%s:textures/gui/", MOD_ID);
2640
public static final Logger LOGGER = LogManager.getLogger(MOD_ID);
2741

28-
private final KeyBinding xrayButton =
29-
new KeyBinding("keybinding.enable_xray", GLFW.GLFW_KEY_BACKSLASH, "category.xray");
30-
private final KeyBinding guiButton =
31-
new KeyBinding("keybinding.open_gui", GLFW.GLFW_KEY_G, "category.xray");
42+
private final KeyBinding xrayButton = new KeyBinding("keybinding.enable_xray", GLFW.GLFW_KEY_BACKSLASH, "category.xray");
43+
44+
private final KeyBinding guiButton = new KeyBinding("keybinding.open_gui", GLFW.GLFW_KEY_G, "category.xray");
3245

3346
@Override
3447
public void onInitialize() {
@@ -42,7 +55,6 @@ public void onInitialize() {
4255

4356
WorldRenderEvents.LAST.register(RenderOutlines::render);
4457
PlayerBlockBreakEvents.AFTER.register(ScanController::blockBroken);
45-
// Interaction
4658

4759
KeyBindingHelper.registerKeyBinding(this.xrayButton);
4860
KeyBindingHelper.registerKeyBinding(this.guiButton);
@@ -80,16 +92,7 @@ private void clientTickEvent(MinecraftClient mc) {
8092

8193
ScanController.runTask(true);
8294

83-
mc.player.sendMessage(
84-
new TranslatableText(
85-
"message.xray_" + (!stateSettings.isActive()
86-
? "deactivate"
87-
: "active"))
88-
.formatted(stateSettings.isActive()
89-
? Formatting.GREEN
90-
: Formatting.RED),
91-
true
92-
);
95+
mc.player.sendMessage(new TranslatableText("message.xray_" + (!stateSettings.isActive() ? "deactivate" : "active")).formatted(stateSettings.isActive() ? Formatting.GREEN : Formatting.RED), true);
9396
}
9497
}
9598
}

0 commit comments

Comments
 (0)