Skip to content

Commit a23a651

Browse files
committed
[ChunkDataThrottle] Add enhancedAntiXray option
1 parent 99bff99 commit a23a651

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

bukkit/src/main/kotlin/io/github/rothes/esu/bukkit/module/NetworkThrottleModule.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,12 @@ object NetworkThrottleModule: BukkitModule<NetworkThrottleModule.ModuleConfig, N
207207
}
208208
}.toMutableList())
209209
put("world_the_end", mutableListOf(Material.END_STONE))
210-
}
210+
},
211+
@Comment("""
212+
If enabled, we add a extra block type to chunk section palettes for the random block.
213+
This will greatly enhance anti-xray capabilities while giving only few bytes of additional bandwidth.
214+
""")
215+
val enhancedAntiXray: Boolean = true,
211216
) {
212217

213218
@RemovedNode

bukkit/version/v1_18/src/main/kotlin/io/github/rothes/esu/bukkit/module/networkthrottle/chunkdatathrottle/v1_18/ChunkDataThrottleHandlerImpl.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,11 +440,12 @@ class ChunkDataThrottleHandlerImpl: ChunkDataThrottleHandler,
440440
bits = (32 - (frequency.size - empty - 1).countLeadingZeroBits())
441441
.coerceAtLeast(4) // Vanilla forces at least 4
442442
val remapped =
443-
if (frequency.size - empty - 1 and (1 shl bits - 1) ==
444-
frequency.size - empty and (1 shl bits - 1) ||
445-
frequency.size - empty + 1 <= (1 shl 4)
443+
if (config.enhancedAntiXray && (
444+
// Check if we can add a block type without adding bits used.
445+
frequency.size - empty - 1 and (1 shl bits - 1) ==
446+
frequency.size - empty and (1 shl bits - 1) ||
447+
frequency.size - empty + 1 <= (1 shl 4))
446448
) {
447-
// If we can add a block type without adding bits used, we add one random block.
448449
for ((i, v) in remappedState.withIndex()) {
449450
remappedState[i] = v + 1
450451
}

0 commit comments

Comments
 (0)