Skip to content

Commit 180fa02

Browse files
Wesley1808DrexHD
andauthored
Anti-Xray rewrite for 1.18 (#14)
* Anti-Xray rewrite for 1.18 - Both EngineMode's are now stable - most notably, EngineMode 2. - Resolves lagspikes when used together with C2ME no-tick. * Re-add polymer mod compatibility * Clean up code * Enable mixins on server environment only * Fixed: anti-xray failing to obfuscate blocks next to chunkborders. * Cache preset blockstate arrays. * Bump version and adjust default nether config Co-authored-by: DrexHD <nicknamedrex@gmail.com>
1 parent 731e2e0 commit 180fa02

36 files changed

+478
-392
lines changed

gradle.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
org.gradle.jvmargs=-Xmx1G
33
# Fabric Properties
44
# check these on https://fabricmc.net/versions.html
5-
minecraft_version=1.18-pre6
6-
loader_version=0.12.5
5+
minecraft_version=1.18
6+
loader_version=0.12.8
77
# Mod Properties
8-
mod_version=1.1.1
8+
mod_version=1.1.2
99
maven_group=me.drex
1010
archives_base_name=anti-xray
1111
# Dependencies
12-
fabric_version=0.42.9+1.18
12+
fabric_version=0.43.1+1.18
1313
toml_version=0.7.2

src/main/java/me/drex/antixray/AntiXray.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ public void onInitializeServer() {
2222
ServerLifecycleEvents.SERVER_STARTING.register(server -> minecraftServer = server);
2323
Config.loadConfig(FabricLoader.getInstance().getConfigDir().resolve("antixray.toml").toFile());
2424
}
25-
26-
}
25+
}

src/main/java/me/drex/antixray/config/Config.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.Objects;
1010

1111
public class Config {
12-
1312
public static Toml toml;
1413

1514
public static void loadConfig(File file) {
@@ -23,5 +22,4 @@ public static void loadConfig(File file) {
2322
}
2423
toml = new Toml().read(file);
2524
}
26-
27-
}
25+
}

src/main/java/me/drex/antixray/config/WorldConfig.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package me.drex.antixray.config;
22

33
import com.moandjiezana.toml.Toml;
4-
import me.drex.antixray.AntiXray;
54
import me.drex.antixray.util.ChunkPacketBlockControllerAntiXray;
65
import net.minecraft.resources.ResourceLocation;
76
import org.jetbrains.annotations.NotNull;
@@ -10,7 +9,6 @@
109
import java.util.List;
1110

1211
public class WorldConfig {
13-
1412
public boolean enabled = false;
1513
public ChunkPacketBlockControllerAntiXray.EngineMode engineMode = ChunkPacketBlockControllerAntiXray.EngineMode.HIDE;
1614
public int maxBlockHeight = 64;
@@ -19,10 +17,8 @@ public class WorldConfig {
1917
public boolean usePermission = false;
2018
public List<String> hiddenBlocks = new ArrayList<>();
2119
public List<String> replacementBlocks = new ArrayList<>();
22-
private ResourceLocation location;
2320

2421
public WorldConfig(ResourceLocation location) {
25-
this.location = location;
2622
Toml defaultToml = Config.toml;
2723
// Load default values
2824
this.loadValues(defaultToml);
@@ -38,16 +34,7 @@ private void loadValues(@NotNull Toml toml) {
3834
if (toml.contains("engineMode")) {
3935
ChunkPacketBlockControllerAntiXray.EngineMode mode = ChunkPacketBlockControllerAntiXray.EngineMode.getById(Math.toIntExact(toml.getLong("engineMode")));
4036
if (mode != null) {
41-
if (mode == ChunkPacketBlockControllerAntiXray.EngineMode.OBFUSCATE) {
42-
this.engineMode = ChunkPacketBlockControllerAntiXray.EngineMode.HIDE;
43-
AntiXray.LOGGER.info("######################## ANTI XRAY ########################");
44-
AntiXray.LOGGER.info("DETECTED ENGINE MODE 2 FOR " + location.toString() + ".");
45-
AntiXray.LOGGER.info("FALLING BACK TO ENGINE MODE 1, ");
46-
AntiXray.LOGGER.info("BECAUSE ENGINE MODE 2 IS VERY UNSTABLE!!!");
47-
AntiXray.LOGGER.info("###########################################################");
48-
} else {
49-
this.engineMode = mode;
50-
}
37+
this.engineMode = mode;
5138
}
5239
}
5340
if (toml.contains("maxBlockHeight")) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package me.drex.antixray.interfaces;
2+
3+
public interface IChunkPacket {
4+
5+
boolean isReady();
6+
7+
void setReady(boolean ready);
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package me.drex.antixray.interfaces;
2+
3+
import me.drex.antixray.util.ChunkPacketInfo;
4+
import net.minecraft.world.level.block.state.BlockState;
5+
6+
public interface IChunkPacketData {
7+
void customExtractChunkData(ChunkPacketInfo<BlockState> packetInfo);
8+
}

src/main/java/me/drex/antixray/util/LevelChunkSectionInterface.java renamed to src/main/java/me/drex/antixray/interfaces/IChunkSection.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
package me.drex.antixray.util;
1+
package me.drex.antixray.interfaces;
22

3+
import me.drex.antixray.util.ChunkPacketInfo;
34
import net.minecraft.network.FriendlyByteBuf;
45
import net.minecraft.world.level.Level;
5-
import net.minecraft.world.level.LevelHeightAccessor;
66
import net.minecraft.world.level.block.state.BlockState;
77

8-
public interface LevelChunkSectionInterface {
8+
public interface IChunkSection {
99

1010
void addBlockPresets(Level level);
1111

12-
void initValues(LevelHeightAccessor chunkAccess);
13-
1412
void write(FriendlyByteBuf friendlyByteBuf, ChunkPacketInfo<BlockState> chunkPacketInfo);
15-
1613
}

src/main/java/me/drex/antixray/util/LevelInterface.java renamed to src/main/java/me/drex/antixray/interfaces/ILevel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
package me.drex.antixray.util;
1+
package me.drex.antixray.interfaces;
22

33
import me.drex.antixray.config.WorldConfig;
4+
import me.drex.antixray.util.ChunkPacketBlockController;
45

56
import java.util.concurrent.Executor;
67

7-
public interface LevelInterface {
8+
public interface ILevel {
89

910
void initValues(Executor executor);
1011

1112
ChunkPacketBlockController getChunkPacketBlockController();
1213

1314
WorldConfig getWorldConfig();
14-
1515
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package me.drex.antixray.interfaces;
2+
3+
import me.drex.antixray.util.ChunkPacketInfo;
4+
import net.minecraft.network.FriendlyByteBuf;
5+
6+
public interface IPalettedContainer<T> {
7+
8+
void addPresetValuesWithEntries(T[] presetValues);
9+
10+
void addPresetValues(T[] presetValues);
11+
12+
void write(FriendlyByteBuf friendlyByteBuf, ChunkPacketInfo<T> chunkPacketInfo, int bottomBlockY);
13+
}
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
package me.drex.antixray.mixin;
22

3-
import me.drex.antixray.util.LevelChunkSectionInterface;
3+
import me.drex.antixray.interfaces.IChunkSection;
4+
import me.drex.antixray.util.Util;
45
import net.minecraft.core.Registry;
56
import net.minecraft.world.level.LevelHeightAccessor;
67
import net.minecraft.world.level.biome.Biome;
78
import net.minecraft.world.level.chunk.ChunkAccess;
89
import net.minecraft.world.level.chunk.LevelChunkSection;
910
import org.spongepowered.asm.mixin.Mixin;
1011
import org.spongepowered.asm.mixin.injection.At;
11-
import org.spongepowered.asm.mixin.injection.Inject;
12-
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
12+
import org.spongepowered.asm.mixin.injection.Redirect;
1313

1414
@Mixin(ChunkAccess.class)
1515
public abstract class ChunkAccessMixin {
1616

17-
@Inject(
17+
@Redirect(
1818
method = "replaceMissingSections",
19-
at = @At("RETURN")
19+
at = @At(
20+
value = "NEW",
21+
target = "net/minecraft/world/level/chunk/LevelChunkSection"
22+
)
23+
2024
)
21-
private static void initializeChunkSections(LevelHeightAccessor levelHeightAccessor, Registry<Biome> registry, LevelChunkSection[] levelChunkSections, CallbackInfo ci) {
22-
for (LevelChunkSection levelChunkSection : levelChunkSections) {
23-
((LevelChunkSectionInterface) levelChunkSection).initValues(levelHeightAccessor);
24-
}
25+
private static LevelChunkSection addPresetValues(int y, Registry<Biome> registry, LevelHeightAccessor accessor, Registry<Biome> registry2, LevelChunkSection[] sections) {
26+
final LevelChunkSection section = new LevelChunkSection(y, registry);
27+
((IChunkSection) section).addBlockPresets(Util.getLevel(accessor));
28+
return section;
2529
}
26-
2730
}

0 commit comments

Comments
 (0)