Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/src/main/java/pro/mikey/xray/XRay.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum XRay {
INSTANCE;

public static final String MOD_ID = "xray";
public static final Identifier SERVER_DISABLE_CHANNEL = id("disable");
private static final Logger LOGGER = LogManager.getLogger();

public static final XPlatShim XPLAT = ServiceLoader.load(XPlatShim.class).findFirst().orElseThrow();
Expand Down
17 changes: 16 additions & 1 deletion common/src/main/java/pro/mikey/xray/core/ScanController.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public enum ScanController {

// Draw states
private boolean xrayActive = false; // Off by default
private boolean serverDisabled = false;

public void init() {
this.scanStore.load();
Expand All @@ -62,12 +63,15 @@ public void init() {

// Public accessors
public boolean isXRayActive() {
return this.xrayActive && Minecraft.getInstance().level != null && Minecraft.getInstance().player != null;
return this.xrayActive && !this.serverDisabled && Minecraft.getInstance().level != null && Minecraft.getInstance().player != null;
}

public void toggleXRay() {
if (!xrayActive) // enable drawing
{
if (serverDisabled) {
return;
}
syncRenderList.clear(); // first, clear the buffer
xrayActive = true; // then, enable drawing
requestBlockFinder(true); // finally, force a refresh
Expand All @@ -83,6 +87,17 @@ public void toggleXRay() {
}
}

public void disableOnServer() {
serverDisabled = true;
xrayActive = false;
syncRenderList.clear();
OutlineRender.clearVBOs();
}

public void onDisconnect() {
serverDisabled = false;
}

public boolean isLavaActive() {
return XRay.config().lavaActive.get();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package pro.mikey.xray.mixins;

import net.minecraft.client.multiplayer.ClientCommonPacketListenerImpl;
import net.minecraft.network.DisconnectionDetails;
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.CallbackInfo;
import pro.mikey.xray.core.ScanController;

@Mixin(ClientCommonPacketListenerImpl.class)
public class ClientCommonPacketListenerMixin {

@Inject(method = "onDisconnect(Lnet/minecraft/network/DisconnectionDetails;)V", at = @At("HEAD"))
private void onDisconnect(DisconnectionDetails details, CallbackInfo ci) {
ScanController.INSTANCE.onDisconnect();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package pro.mikey.xray.mixins;

import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
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.CallbackInfo;
import pro.mikey.xray.XRay;
import pro.mikey.xray.core.ScanController;

@Mixin(ClientPacketListener.class)
public class ClientPacketListenerMixin {

@Inject(method = "handleCustomPayload(Lnet/minecraft/network/protocol/common/custom/CustomPacketPayload;)V", at = @At("HEAD"))
private void onCustomPayload(CustomPacketPayload payload, CallbackInfo ci) {
if (XRay.SERVER_DISABLE_CHANNEL.equals(payload.type().id())) {
ScanController.INSTANCE.disableOnServer();
}
}
}
4 changes: 3 additions & 1 deletion fabric/src/main/resources/xray.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"package": "pro.mikey.xray.mixins",
"compatibilityLevel": "JAVA_17",
"client": [
"LevelMixin"
"LevelMixin",
"ClientPacketListenerMixin",
"ClientCommonPacketListenerMixin"
],
"mixins": [
],
Expand Down
4 changes: 3 additions & 1 deletion neoforge/src/main/resources/xray.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"package": "pro.mikey.xray.mixins",
"compatibilityLevel": "JAVA_17",
"client": [
"LevelMixin"
"LevelMixin",
"ClientPacketListenerMixin",
"ClientCommonPacketListenerMixin"
],
"mixins": [
],
Expand Down