Skip to content
This repository has been archived by the owner on Apr 22, 2021. It is now read-only.

Commit

Permalink
impr: Separate BoatFly from EntitySpeed (#2155)
Browse files Browse the repository at this point in the history
Co-authored-by: lv <[email protected]>
  • Loading branch information
ToxicAven and 5HT2 authored Mar 25, 2021
1 parent a8982ab commit 05f7959
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import net.minecraft.client.model.ModelBoat;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.Entity;
import org.kamiblue.client.module.modules.movement.EntitySpeed;
import org.kamiblue.client.module.modules.movement.BoatFly;
import org.kamiblue.client.util.Wrapper;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -18,8 +18,8 @@ public class MixinModelBoat {

@Inject(method = "render", at = @At("HEAD"))
public void render(Entity entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale, CallbackInfo info) {
if (Wrapper.getPlayer().getRidingEntity() == entityIn && EntitySpeed.INSTANCE.isEnabled()) {
GlStateManager.color(1.0f, 1.0f, 1.0f, EntitySpeed.getOpacity());
if (Wrapper.getPlayer().getRidingEntity() == entityIn && BoatFly.INSTANCE.isEnabled()) {
GlStateManager.color(1.0f, 1.0f, 1.0f, BoatFly.INSTANCE.getOpacity());
GlStateManager.enableBlend();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package org.kamiblue.client.module.modules.movement

import net.minecraft.entity.Entity
import net.minecraft.entity.item.EntityBoat
import net.minecraft.network.play.client.CPacketInput
import net.minecraft.network.play.client.CPacketPlayer
import net.minecraft.network.play.client.CPacketVehicleMove
import net.minecraft.network.play.server.SPacketMoveVehicle
import net.minecraft.util.EnumHand
import net.minecraft.world.chunk.EmptyChunk
import org.kamiblue.client.event.SafeClientEvent
import org.kamiblue.client.event.events.PacketEvent
import org.kamiblue.client.event.events.PlayerTravelEvent
import org.kamiblue.client.module.Category
import org.kamiblue.client.module.Module
import org.kamiblue.client.util.EntityUtils.steerEntity
import org.kamiblue.client.util.MovementUtils
import org.kamiblue.client.util.MovementUtils.calcMoveYaw
import org.kamiblue.client.util.threads.safeListener
import kotlin.math.cos
import kotlin.math.sin

internal object BoatFly : Module(
name = "BoatFly",
category = Category.MOVEMENT,
description = "Fly using boats"
) {
private const val flight = true

private val speed by setting("Speed", 1.0f, 0.1f..25.0f, 0.1f)
private val antiStuck by setting("Anti Stuck", true)
private val glideSpeed by setting("Glide Speed", 0.1f, 0.0f..1.0f, 0.01f)
private val upSpeed by setting("Up Speed", 1.0f, 0.0f..5.0f, 0.1f)
val opacity by setting("Boat Opacity", 1.0f, 0.0f..1.0f, 0.01f)
private val forceInteract by setting("Force Interact", false)
private val interactTickDelay by setting("Interact Delay", 2, 1..20, 1, { forceInteract }, description = "Force interact packet delay, in ticks.")

init {
safeListener<PacketEvent.Send> {
val ridingEntity = player.ridingEntity

if (!forceInteract || ridingEntity !is EntityBoat) return@safeListener

if (it.packet is CPacketPlayer.Rotation || it.packet is CPacketInput) {
it.cancel()
}

if (it.packet is CPacketVehicleMove) {
if (player.ticksExisted % interactTickDelay == 0) {
playerController.interactWithEntity(player, ridingEntity, EnumHand.MAIN_HAND)
}
}
}

safeListener<PacketEvent.Receive> {
if (!forceInteract || player.ridingEntity !is EntityBoat || it.packet !is SPacketMoveVehicle) return@safeListener
it.cancel()
}

safeListener<PlayerTravelEvent> {
player.ridingEntity?.let { entity ->
if (entity is EntityBoat && entity.controllingPassenger == player) {
steerEntity(entity, speed, antiStuck)

// Make sure the boat doesn't turn etc (params: isLeftDown, isRightDown, isForwardDown, isBackDown)
entity.rotationYaw = player.rotationYaw
entity.updateInputs(false, false, false, false)

if (flight) fly(entity)
}
}
}
}

private fun fly(entity: Entity) {
if (!entity.isInWater) entity.motionY = -glideSpeed.toDouble()
if (mc.gameSettings.keyBindJump.isKeyDown) entity.motionY += upSpeed / 2.0
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.kamiblue.client.module.modules.movement

import net.minecraft.entity.Entity
import net.minecraft.entity.item.EntityBoat
import net.minecraft.entity.passive.AbstractHorse
import net.minecraft.entity.passive.EntityHorse
import net.minecraft.entity.passive.EntityPig
Expand All @@ -16,6 +15,7 @@ import org.kamiblue.client.event.events.PacketEvent
import org.kamiblue.client.event.events.PlayerTravelEvent
import org.kamiblue.client.module.Category
import org.kamiblue.client.module.Module
import org.kamiblue.client.util.EntityUtils.steerEntity
import org.kamiblue.client.util.MovementUtils
import org.kamiblue.client.util.MovementUtils.calcMoveYaw
import org.kamiblue.client.util.threads.safeListener
Expand All @@ -27,78 +27,30 @@ internal object EntitySpeed : Module(
category = Category.MOVEMENT,
description = "Abuse client-sided movement to shape sound barrier breaking rideables"
) {
private val speed = setting("Speed", 1.0f, 0.1f..25.0f, 0.1f)
private val antiStuck = setting("Anti Stuck", true)
private val flight = setting("Flight", false)
private val glideSpeed = setting("Glide Speed", 0.1f, 0.0f..1.0f, 0.01f, { flight.value })
private val upSpeed = setting("Up Speed", 1.0f, 0.0f..5.0f, 0.1f, { flight.value })
private val opacity = setting("Boat Opacity", 1.0f, 0.0f..1.0f, 0.01f)
private val forceInteract = setting("Force Interact", false)
private val interactTickDelay = setting("Interact Delay", 2, 1..20, 1, { forceInteract.value }, description = "Force interact packet delay, in ticks.")
private val speed by setting("Speed", 1.0f, 0.1f..25.0f, 0.1f)
private val antiStuck by setting("Anti Stuck", true)
private val flight by setting("Flight", false)
private val glideSpeed by setting("Glide Speed", 0.1f, 0.0f..1.0f, 0.01f, { flight })
private val upSpeed by setting("Up Speed", 1.0f, 0.0f..5.0f, 0.1f, { flight })

init {
safeListener<PacketEvent.Send> {
val ridingEntity = player.ridingEntity

if (!forceInteract.value || ridingEntity !is EntityBoat) return@safeListener

if (it.packet is CPacketPlayer.Rotation || it.packet is CPacketInput) {
it.cancel()
}

if (it.packet is CPacketVehicleMove) {
if (player.ticksExisted % interactTickDelay.value == 0) {
playerController.interactWithEntity(player, ridingEntity, EnumHand.MAIN_HAND)
}
}
}
safeListener<PlayerTravelEvent> {
player.ridingEntity?.let { entity ->
if (entity is EntityPig || entity is AbstractHorse && entity.controllingPassenger == player) {
steerEntity(entity, speed, antiStuck)

safeListener<PacketEvent.Receive> {
if (!forceInteract.value || player.ridingEntity !is EntityBoat || it.packet !is SPacketMoveVehicle) return@safeListener
it.cancel()
}
if (entity is EntityHorse) {
entity.rotationYaw = player.rotationYaw
}

safeListener<PlayerTravelEvent> {
player.ridingEntity?.let {
if (it is EntityPig || it is AbstractHorse || it is EntityBoat && it.controllingPassenger == player) {
steerEntity(it)
if (flight.value) fly(it)
if (flight) fly(entity)
}
}
}
}

private fun SafeClientEvent.steerEntity(entity: Entity) {
val yawRad = calcMoveYaw()

val motionX = -sin(yawRad) * speed.value
val motionZ = cos(yawRad) * speed.value

if (MovementUtils.isInputting && !isBorderingChunk(entity, motionX, motionZ)) {
entity.motionX = motionX
entity.motionZ = motionZ
} else {
entity.motionX = 0.0
entity.motionZ = 0.0
}

if (entity is EntityHorse || entity is EntityBoat) {
entity.rotationYaw = player.rotationYaw

// Make sure the boat doesn't turn etc (params: isLeftDown, isRightDown, isForwardDown, isBackDown)
if (entity is EntityBoat) entity.updateInputs(false, false, false, false)
}
}

private fun fly(entity: Entity) {
if (!entity.isInWater) entity.motionY = -glideSpeed.value.toDouble()
if (mc.gameSettings.keyBindJump.isKeyDown) entity.motionY += upSpeed.value / 2.0
if (!entity.isInWater) entity.motionY = -glideSpeed.toDouble()
if (mc.gameSettings.keyBindJump.isKeyDown) entity.motionY += upSpeed / 2.0
}

private fun SafeClientEvent.isBorderingChunk(entity: Entity, motionX: Double, motionZ: Double): Boolean {
return antiStuck.value && world.getChunk((entity.posX + motionX).toInt() shr 4, (entity.posZ + motionZ).toInt() shr 4) is EmptyChunk
}

@JvmStatic
fun getOpacity(): Float = opacity.value
}
23 changes: 23 additions & 0 deletions src/main/kotlin/org/kamiblue/client/util/EntityUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ import net.minecraft.entity.passive.*
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Vec3d
import net.minecraft.world.chunk.EmptyChunk
import org.kamiblue.client.event.SafeClientEvent
import org.kamiblue.client.manager.managers.FriendManager
import org.kamiblue.client.util.MovementUtils.calcMoveYaw
import org.kamiblue.client.util.items.id
import org.kamiblue.client.util.math.VectorUtils.toBlockPos
import org.kamiblue.commons.extension.ceilToInt
import org.kamiblue.commons.extension.floorToInt
import kotlin.math.cos
import kotlin.math.sin

object EntityUtils {
private val mc = Minecraft.getMinecraft()
Expand Down Expand Up @@ -170,4 +174,23 @@ object EntityUtils {
.minByOrNull { player.getDistance(it) }
?.positionVector
?.toBlockPos()

fun SafeClientEvent.steerEntity(entity: Entity, speed: Float, antiStuck: Boolean) {
val yawRad = calcMoveYaw()

val motionX = -sin(yawRad) * speed
val motionZ = cos(yawRad) * speed

if (MovementUtils.isInputting && !isBorderingChunk(entity, motionX, motionZ, antiStuck)) {
entity.motionX = motionX
entity.motionZ = motionZ
} else {
entity.motionX = 0.0
entity.motionZ = 0.0
}
}

private fun SafeClientEvent.isBorderingChunk(entity: Entity, motionX: Double, motionZ: Double, antiStuck: Boolean): Boolean {
return antiStuck && world.getChunk((entity.posX + motionX).toInt() shr 4, (entity.posZ + motionZ).toInt() shr 4) is EmptyChunk
}
}

0 comments on commit 05f7959

Please sign in to comment.