Skip to content

Commit

Permalink
Merge branch '1.21.0' into 1.21.4
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle.kts
  • Loading branch information
rfresh2 committed Dec 28, 2024
2 parents ce3dbc5 + ceb8520 commit 3b91554
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 39 deletions.
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ dependencies {
implementation("com.github.rfresh2.discord4j:discord4j-core:3.4.4.11") {
exclude(group = "io.netty")
}
implementation("com.github.rfresh2:MCProtocolLib:1.21.4.4") {
implementation("com.github.rfresh2:MCProtocolLib:1.21.4.5") {
exclude(group = "io.netty")
}
val nettyVersion = "4.1.115.Final"
val nettyVersion = "4.1.116.Final"
implementation("io.netty:netty-codec-haproxy:$nettyVersion")
implementation("io.netty:netty-codec-dns:$nettyVersion")
implementation("io.netty:netty-codec-http2:$nettyVersion")
Expand All @@ -71,7 +71,7 @@ dependencies {
implementation("io.netty:netty-resolver-dns-native-macos:$nettyVersion:osx-aarch_64")
implementation("org.cloudburstmc.math:api:2.0")
implementation("org.cloudburstmc.math:immutable:2.0")
implementation("org.redisson:redisson:3.40.2") {
implementation("org.redisson:redisson:3.41.0") {
exclude(group = "io.netty")
}
implementation("com.github.rfresh2:SimpleEventBus:1.2")
Expand All @@ -96,7 +96,7 @@ dependencies {
// which adds about 10mb to the binary size for zero benefit because we do not use jfr
implementation("org.jdbi:jdbi3-postgres:3.45.4")
implementation("com.google.guava:guava:33.4.0-jre")
implementation("ch.qos.logback:logback-classic:1.5.12")
implementation("ch.qos.logback:logback-classic:1.5.15")
implementation("org.slf4j:slf4j-api:2.0.16")
implementation("org.slf4j:jul-to-slf4j:2.0.16")
implementation("com.mojang:brigadier:1.3.10")
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/zenith/cache/data/PlayerCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.geysermc.mcprotocollib.protocol.data.game.entity.EquipmentSlot;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.GlobalPos;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand;
import org.geysermc.mcprotocollib.protocol.data.game.inventory.ContainerActionType;
import org.geysermc.mcprotocollib.protocol.data.game.inventory.ContainerType;
import org.geysermc.mcprotocollib.protocol.data.game.inventory.CreativeGrabAction;
Expand Down Expand Up @@ -197,6 +198,13 @@ public ItemStack getEquipment(final EquipmentSlot slot) {
};
}

public ItemStack getEquipment(Hand hand) {
return switch (hand) {
case Hand.MAIN_HAND -> getEquipment(MAIN_HAND);
case Hand.OFF_HAND -> getEquipment(OFF_HAND);
};
}

// prefer calling getEquipment with a slot type instead of this, creates gc spam
public Map<EquipmentSlot, ItemStack> getEquipment() {
final Map<EquipmentSlot, ItemStack> equipment = new EnumMap<>(EquipmentSlot.class);
Expand Down
57 changes: 37 additions & 20 deletions src/main/java/com/zenith/command/impl/ClickCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,21 @@ public CommandUsage commandUsage() {
"click",
CommandCategory.MODULE,
"""
Clicks the block in front of you
Simulates a click to the block or entity in front of you
""",
asList(
"hold",
"stop",
"left"
// "right" // todo: implement right click
"left",
"left hold",
"right",
"right hold",
"stop"
)
);
}

@Override
public LiteralArgumentBuilder<CommandContext> register() {
return command("click")
.then(literal("hold").executes(c -> {
if (!Proxy.getInstance().isConnected()) {
c.getSource().getEmbed()
.title("Not Connected")
.errorColor();
return OK;
}
MODULE.get(PlayerSimulation.class).holdLeftClickOverride = true;
c.getSource().getEmbed()
.title("Click Hold On")
.primaryColor();
return OK;
}))
.then(literal("stop").executes(c -> {
if (!Proxy.getInstance().isConnected()) {
c.getSource().getEmbed()
Expand All @@ -55,6 +43,7 @@ public LiteralArgumentBuilder<CommandContext> register() {
return OK;
}
MODULE.get(PlayerSimulation.class).holdLeftClickOverride = false;
MODULE.get(PlayerSimulation.class).holdRightClickOverride = false;
c.getSource().getEmbed()
.title("Click Hold Off")
.primaryColor();
Expand All @@ -74,7 +63,21 @@ public LiteralArgumentBuilder<CommandContext> register() {
.title("Left Clicked")
.primaryColor();
return 1;
}))
})
.then(literal("hold").executes(c -> {
if (!Proxy.getInstance().isConnected()) {
c.getSource().getEmbed()
.title("Not Connected")
.errorColor();
return OK;
}
MODULE.get(PlayerSimulation.class).holdLeftClickOverride = true;
MODULE.get(PlayerSimulation.class).holdRightClickOverride = false;
c.getSource().getEmbed()
.title("Left Click Hold")
.primaryColor();
return OK;
})))
.then(literal("right").executes(c -> {
if (!Proxy.getInstance().isConnected()) {
c.getSource().getEmbed()
Expand All @@ -89,6 +92,20 @@ public LiteralArgumentBuilder<CommandContext> register() {
.title("Right Clicked")
.primaryColor();
return 1;
}));
})
.then(literal("hold").executes(c -> {
if (!Proxy.getInstance().isConnected()) {
c.getSource().getEmbed()
.title("Not Connected")
.errorColor();
return OK;
}
MODULE.get(PlayerSimulation.class).holdLeftClickOverride = false;
MODULE.get(PlayerSimulation.class).holdRightClickOverride = true;
c.getSource().getEmbed()
.title("Right Click Hold")
.primaryColor();
return OK;
})));
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/zenith/discord/DiscordEventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -795,9 +795,9 @@ public void handleReplayStoppedEvent(final ReplayStoppedEvent event) {
var replayFile = event.replayFile();
if (replayFile != null && CONFIG.client.extra.replayMod.sendRecordingsToDiscord) {
try (InputStream in = new BufferedInputStream(new FileInputStream(replayFile))) {
// 25MB discord file attachment size limit
// 10mb discord file attachment size limit
long replaySizeMb = replayFile.length() / (1024 * 1024);
if (replaySizeMb > 24) {
if (replaySizeMb > 10) {
if (CONFIG.client.extra.replayMod.fileIOUploadIfTooLarge) {
DISCORD_LOG.info("Uploading large replay to file.io with size: {}", replayFile.length());
var notiEmbed = Embed.builder()
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/zenith/feature/world/InteractionResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.zenith.feature.world;

public enum InteractionResult {
SUCCESS,
SUCCESS_NO_ITEM_USED,
CONSUME,
CONSUME_PARTIAL,
PASS,
FAIL;

public boolean consumesAction() {
return this == SUCCESS || this == CONSUME || this == CONSUME_PARTIAL || this == SUCCESS_NO_ITEM_USED;
}

public boolean shouldSwing() {
return this == SUCCESS || this == SUCCESS_NO_ITEM_USED;
}

public boolean indicateItemUse() {
return this == SUCCESS || this == CONSUME;
}

public static InteractionResult sidedSuccess(boolean isClientSide) {
return isClientSide ? SUCCESS : CONSUME;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.zenith.feature.pathing;
package com.zenith.feature.world;

import com.zenith.Proxy;
import com.zenith.cache.data.inventory.Container;
import com.zenith.feature.world.World;
import com.zenith.feature.world.raycast.BlockRaycastResult;
import com.zenith.feature.world.raycast.EntityRaycastResult;
import com.zenith.mc.block.Block;
import com.zenith.mc.block.BlockRegistry;
Expand All @@ -27,10 +27,7 @@
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.ItemEnchantments;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundInteractPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundSetCarriedItemPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundSwingPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.*;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;
Expand Down Expand Up @@ -298,6 +295,54 @@ private void destroyBlock(int x, int y, int z) {
.setBlock(x & 15, y & 15, z & 15, BlockRegistry.AIR.id());
}

public InteractionResult interact(Hand hand, EntityRaycastResult ray) {
Proxy.getInstance().getClient().send(new ServerboundInteractPacket(
ray.entity().getEntityId(),
InteractAction.INTERACT,
0, 0, 0,
hand,
player.isSneaking()
));
return InteractionResult.PASS;
}

public InteractionResult interactAt(Hand hand, EntityRaycastResult ray) {
Proxy.getInstance().getClient().send(new ServerboundInteractPacket(
ray.entity().getEntityId(),
InteractAction.INTERACT_AT,
0, 0, 0,
hand,
player.isSneaking()
));
return InteractionResult.PASS;
}

public InteractionResult useItemOn(Hand hand, BlockRaycastResult ray) {
Proxy.getInstance().getClient().send(new ServerboundUseItemOnPacket(
ray.x(), ray.y(), ray.z(),
ray.direction(),
hand,
// todo: cursor raytrace
0, 0, 0,
false,
false,
CACHE.getPlayerCache().getSeqId().incrementAndGet()
));
// todo: check if we are placing a block
// if so, add the block to the world so we don't have a brief desync
return InteractionResult.PASS;
}

public InteractionResult useItem(Hand hand) {
Proxy.getInstance().getClient().send(new ServerboundUseItemPacket(
hand,
CACHE.getPlayerCache().getSeqId().incrementAndGet(),
player.getYaw(),
player.getPitch()
));
return InteractionResult.PASS;
}

public void ensureHasSentCarriedItem() {
int heldItemSlot = CACHE.getPlayerCache().getHeldItemSlot();
if (carriedIndex != heldItemSlot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.zenith.mc.block.BlockRegistry;
import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction;

public record BlockRaycastResult(boolean hit, double x, double y, double z, Direction direction, Block block) {
public record BlockRaycastResult(boolean hit, int x, int y, int z, Direction direction, Block block) {
public static BlockRaycastResult miss() {
return new BlockRaycastResult(false, 0, 0, 0, Direction.UP, BlockRegistry.AIR);
}
Expand Down
27 changes: 21 additions & 6 deletions src/main/java/com/zenith/module/impl/PlayerSimulation.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.zenith.module.impl;

import com.zenith.event.module.ClientBotTick;
import com.zenith.feature.pathing.PlayerInteractionManager;
import com.zenith.feature.world.Input;
import com.zenith.feature.world.MovementInputRequest;
import com.zenith.feature.world.Pathing;
import com.zenith.feature.world.World;
import com.zenith.feature.world.*;
import com.zenith.feature.world.raycast.RaycastHelper;
import com.zenith.mc.block.*;
import com.zenith.mc.dimension.DimensionRegistry;
Expand Down Expand Up @@ -47,7 +43,7 @@ public class PlayerSimulation extends Module {
private float lastPitch;
@Getter private boolean onGround;
private boolean lastOnGround;
private boolean isSneaking;
@Getter private boolean isSneaking;
private boolean wasSneaking;
private boolean isSprinting;
private boolean lastSprinting;
Expand Down Expand Up @@ -82,6 +78,8 @@ public class PlayerSimulation extends Module {
private boolean verticalCollision = false;
private final PlayerInteractionManager interactions = new PlayerInteractionManager(this);
public boolean holdLeftClickOverride = false;
public boolean holdRightClickOverride = false;
private final Timer rightClickOverrideTimer = Timer.createTickTimer();

@Override
public void subscribeEvents() {
Expand All @@ -105,6 +103,7 @@ public boolean enabledSetting() {
public synchronized void handleClientTickStarting(final ClientBotTick.Starting event) {
syncFromCache(false);
this.holdLeftClickOverride = false;
this.holdRightClickOverride = false;
}

public synchronized void handleClientTickStopped(final ClientBotTick.Stopped event) {
Expand All @@ -115,6 +114,7 @@ public synchronized void handleClientTickStopped(final ClientBotTick.Stopped eve
sendClientPacketAsync(new ServerboundPlayerCommandPacket(CACHE.getPlayerCache().getEntityId(), PlayerState.STOP_SPRINTING));
}
this.holdLeftClickOverride = false;
this.holdRightClickOverride = false;
}

public void doRotate(float yaw, float pitch) {
Expand Down Expand Up @@ -219,6 +219,21 @@ private void interactionTick() {
interactions.attackEntity(raycast.entity());
}
}
} else if (movementInput.isRightClick() || (holdRightClickOverride && rightClickOverrideTimer.tick(10))) {
var raycast = RaycastHelper.playerBlockOrEntityRaycast(4.5);
if (raycast.hit() && raycast.isBlock()) {
interactions.ensureHasSentCarriedItem();
interactions.useItemOn(Hand.MAIN_HAND, raycast.block());
sendClientPacketAsync(new ServerboundSwingPacket(Hand.MAIN_HAND));
} else if (raycast.hit() && raycast.isEntity()) {
interactions.ensureHasSentCarriedItem();
interactions.interactAt(Hand.MAIN_HAND, raycast.entity());
sendClientPacketAsync(new ServerboundSwingPacket(Hand.MAIN_HAND));
} else if (!raycast.hit()) {
interactions.ensureHasSentCarriedItem();
interactions.useItem(Hand.MAIN_HAND);
sendClientPacketAsync(new ServerboundSwingPacket(Hand.MAIN_HAND));
}
}
interactions.stopDestroyBlock();
wasLeftClicking = false;
Expand Down

0 comments on commit 3b91554

Please sign in to comment.