From 1ec7014cd38c764da44d56739bcddbfd23762160 Mon Sep 17 00:00:00 2001 From: tinywifi Date: Sat, 25 Oct 2025 01:32:36 +0700 Subject: [PATCH 1/2] attributeswap omg omg --- .../module/impl/combat/AttributeSwap.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/main/java/com/syuto/bytes/module/impl/combat/AttributeSwap.java diff --git a/src/main/java/com/syuto/bytes/module/impl/combat/AttributeSwap.java b/src/main/java/com/syuto/bytes/module/impl/combat/AttributeSwap.java new file mode 100644 index 0000000..77eda2c --- /dev/null +++ b/src/main/java/com/syuto/bytes/module/impl/combat/AttributeSwap.java @@ -0,0 +1,65 @@ +package com.syuto.bytes.module.impl.combat; + +import com.syuto.bytes.eventbus.EventHandler; +import com.syuto.bytes.eventbus.impl.AttackEntityEvent; +import com.syuto.bytes.eventbus.impl.AttackEntityEvent.Mode; +import com.syuto.bytes.module.Module; +import com.syuto.bytes.module.api.Category; +import com.syuto.bytes.utils.impl.client.ChatUtils; +import com.syuto.bytes.utils.impl.player.PlayerUtil; +import net.minecraft.item.ItemStack; +import net.minecraft.item.MaceItem; +import net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket; + +/** + * Swaps to mace on attack, then swaps back on next tick. + */ +public class AttributeSwap extends Module { + + private int previousSlot = -1; + + public AttributeSwap() { + super("AttributeSwap", "Swap to mace during attacks", Category.COMBAT); + } + + @EventHandler + public void onAttack(AttackEntityEvent event) { + if (mc.player == null || mc.interactionManager == null) return; + + if (event.getMode() == Mode.Pre) { + int current = mc.player.getInventory().selectedSlot; + previousSlot = current; + if (PlayerUtil.isHoldingWeapon()) { + int maceSlot = findMaceInHotbar(); + if (maceSlot != -1) { + mc.player.getInventory().selectedSlot = maceSlot; + if (mc.getNetworkHandler() != null) { + mc.getNetworkHandler().sendPacket(new UpdateSelectedSlotC2SPacket(maceSlot)); + } + ChatUtils.print("Swapped to mace " + maceSlot + " from " + current); + } + } + } + + if (event.getMode() == Mode.Post) { + if (previousSlot >= 0) { + mc.player.getInventory().selectedSlot = previousSlot; + if (mc.getNetworkHandler() != null) { + mc.getNetworkHandler().sendPacket(new UpdateSelectedSlotC2SPacket(previousSlot)); + } + ChatUtils.print("Swapped back " + previousSlot); + previousSlot = -1; + } + } + } + + private int findMaceInHotbar() { + for (int i = 0; i < 9; i++) { + ItemStack stack = mc.player.getInventory().getStack(i); + if (stack != null && stack.getItem() instanceof MaceItem) { + return i; + } + } + return -1; + } +} From 74fb32456dca155b37ee984ca06b959399b7017e Mon Sep 17 00:00:00 2001 From: tinywifi Date: Sat, 25 Oct 2025 01:39:42 +0700 Subject: [PATCH 2/2] i forgor --- .../bytes/eventbus/impl/AttackEntityEvent.java | 13 +++++++++++-- .../mixin/ClientPlayerInteractionManagerMixin.java | 13 ++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/syuto/bytes/eventbus/impl/AttackEntityEvent.java b/src/main/java/com/syuto/bytes/eventbus/impl/AttackEntityEvent.java index 31c4eb7..09bb48b 100644 --- a/src/main/java/com/syuto/bytes/eventbus/impl/AttackEntityEvent.java +++ b/src/main/java/com/syuto/bytes/eventbus/impl/AttackEntityEvent.java @@ -4,17 +4,26 @@ import lombok.Getter; import lombok.Setter; import net.minecraft.entity.Entity; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; public class AttackEntityEvent implements Event { + public enum Mode { Pre, Post } + + @Getter + private final Entity target; + @Getter - private Entity target; + private final Mode mode; @Getter @Setter private boolean cancelled; public AttackEntityEvent(Entity target) { + this(target, Mode.Pre); + } + + public AttackEntityEvent(Entity target, Mode mode) { this.target = target; + this.mode = mode; } } diff --git a/src/main/java/com/syuto/bytes/mixin/ClientPlayerInteractionManagerMixin.java b/src/main/java/com/syuto/bytes/mixin/ClientPlayerInteractionManagerMixin.java index 8b1f0e2..b7a9f6b 100644 --- a/src/main/java/com/syuto/bytes/mixin/ClientPlayerInteractionManagerMixin.java +++ b/src/main/java/com/syuto/bytes/mixin/ClientPlayerInteractionManagerMixin.java @@ -2,6 +2,7 @@ import com.syuto.bytes.Byte; import com.syuto.bytes.eventbus.impl.AttackEntityEvent; +import com.syuto.bytes.eventbus.impl.AttackEntityEvent.Mode; import net.minecraft.client.network.ClientPlayerInteractionManager; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; @@ -20,7 +21,7 @@ public class ClientPlayerInteractionManagerMixin { cancellable = true ) private void attackEntity(PlayerEntity player, Entity target, CallbackInfo ci) { - AttackEntityEvent event = new AttackEntityEvent(target); + AttackEntityEvent event = new AttackEntityEvent(target, Mode.Pre); Byte.INSTANCE.eventBus.post(event); if (event.isCancelled()) { @@ -28,5 +29,15 @@ private void attackEntity(PlayerEntity player, Entity target, CallbackInfo ci) { } } + @Inject( + method = "attackEntity", + at = @At("TAIL"), + cancellable = false + ) + private void attackEntityPost(PlayerEntity player, Entity target, CallbackInfo ci) { + AttackEntityEvent post = new AttackEntityEvent(target, Mode.Post); + Byte.INSTANCE.eventBus.post(post); + } + }