Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.vehicle.AbstractBoatEntity;
import net.minecraft.util.PlayerInput;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
Expand Down Expand Up @@ -130,6 +133,25 @@ private void onTickHasVehicleBeforeSendPackets(CallbackInfo info) {
MeteorClient.EVENT_BUS.post(SendMovementPacketsEvent.Pre.get());
}

@ModifyArg(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/c2s/play/PlayerInputC2SPacket;<init>(Lnet/minecraft/util/PlayerInput;)V"), index = 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outdated branch.

private PlayerInput onCreateVehicleInputPacket(PlayerInput input) {
BoatFly boatFly = Modules.get().get(BoatFly.class);
if (!boatFly.sneakDescendsDownward()) return input;
if (!input.sneak()) return input;
if (!(getVehicle() instanceof AbstractBoatEntity boat)) return input;
if (boat.getControllingPassenger() != (Object) this) return input;

return new PlayerInput(
input.forward(),
input.backward(),
input.left(),
input.right(),
input.jump(),
false,
input.sprint()
);
}

@Inject(method = "sendMovementPackets", at = @At("TAIL"))
private void onSendMovementPacketsTail(CallbackInfo info) {
MeteorClient.EVENT_BUS.post(SendMovementPacketsEvent.Post.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ public class BoatFly extends Module {
.build()
);

private final Setting<Boolean> sneakDescendsDownward = sgGeneral.add(new BoolSetting.Builder()
.name("sneak-descends-downward")
.description("Uses the sneak key to descend instead of sprint.")
.defaultValue(false)
.build()
);

public BoatFly() {
super(Categories.Movement, "boat-fly", "Transforms your boat into a plane.");
}
Expand All @@ -73,7 +80,12 @@ private void onBoatMove(BoatMoveEvent event) {

// Vertical movement
if (mc.options.jumpKey.isPressed()) velY += verticalSpeed.get() / 20;
if (mc.options.sprintKey.isPressed()) velY -= verticalSpeed.get() / 20;

boolean descending = sneakDescendsDownward.get()
? mc.options.sneakKey.isPressed()
: mc.options.sprintKey.isPressed();

if (descending) velY -= verticalSpeed.get() / 20;
else velY -= fallSpeed.get() / 20;

// Apply velocity
Expand All @@ -86,4 +98,8 @@ private void onReceivePacket(PacketEvent.Receive event) {
event.cancel();
}
}

public boolean sneakDescendsDownward() {
return isActive() && sneakDescendsDownward.get();
}
}