added noglitchblocks to close #725

This commit is contained in:
Bella 2020-04-24 21:58:51 -04:00
parent f1501b6f77
commit 456cd901e6
No known key found for this signature in database
GPG Key ID: DBD4A6030080C8B3
1 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,65 @@
package me.zeroeightsix.kami.module.modules.player
import me.zeroeightsix.kami.module.Module
import me.zeroeightsix.kami.setting.Settings
import net.minecraft.client.network.NetHandlerPlayClient
import net.minecraft.network.play.client.CPacketPlayerDigging
import net.minecraft.util.EnumFacing
import net.minecraft.util.math.BlockPos
/**
* @author gbl
*
* Used with permission from GPL licensing as proven by
* https://github.com/gbl/AntiGhost/issues/1
* and
* https://github.com/gbl/AntiGhost/issues/6
*
* You can view the source code here:
* https://github.com/gbl/AntiGhost/
*/
@Module.Info(
name = "NoGlitchBlocks",
description = "Prevents blocks desyncing and creating ghost blocks",
category = Module.Category.PLAYER
)
class NoGlitchBlocks : Module() {
private val range = register(Settings.integerBuilder("Range").withRange(1, 5).withValue(4).build())
private var previous = -1
private var conn: NetHandlerPlayClient? = null
public override fun onEnable() {
conn = mc.connection
previous = range.value
}
override fun onUpdate() {
if (mc.player == null || mc.isIntegratedServerRunning) return
if (conn == null) {
conn = mc.connection
}
if (previous != range.value) {
previous = range.value
return // prevents running when changing size
}
run()
}
private fun run() {
if (conn == null) {
return
}
val pos = mc.player.position
for (dx in -range.value..range.value) {
for (dy in -range.value..range.value) for (dz in -range.value..range.value) {
val packet = CPacketPlayerDigging(
CPacketPlayerDigging.Action.ABORT_DESTROY_BLOCK,
BlockPos(pos.getX() + dx, pos.getY() + dy, pos.getZ() + dz),
EnumFacing.UP /* with ABORT_DESTROY_BLOCK, this value is unused */
)
conn!!.sendPacket(packet)
}
}
}
}