Skip to content

Commit

Permalink
Prevents item swap when running player animation.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Dec 28, 2024
1 parent f03aaf5 commit 8abdb8e
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@

public final class PlayerTracker extends EntityTracker {

private final Player player;

public PlayerTracker(@NotNull Player entity, @NotNull RenderInstance instance) {
super(entity, instance);
this.player = entity;
instance.filter(p -> BetterModel.inst().playerManager().player(p).showPlayerLimb());
}

@Override
public boolean isRunningSingleAnimation() {
return false;
}

@Override
public void close() throws Exception {
super.close();
player.updateInventory();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,21 @@ class NMSImpl : NMS {
super.write(ctx, msg, promise)
}

override fun channelRead(ctx: ChannelHandlerContext, msg: Any) {
when (msg) {
is ServerboundSetCarriedItemPacket -> {
if (connection.player.id.toTracker() != null) {
connection.send(ClientboundSetCarriedItemPacket(player.inventory.heldItemSlot))
return
}
}
is ServerboundPlayerActionPacket -> {
if (connection.player.id.toTracker() != null) return
}
}
super.channelRead(ctx, msg)
}

private fun EntityTracker.remove() {
entityUUIDMap.remove(uuid())
remove(player)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,21 @@ class NMSImpl : NMS {
super.write(ctx, msg, promise)
}

override fun channelRead(ctx: ChannelHandlerContext, msg: Any) {
when (msg) {
is ServerboundSetCarriedItemPacket -> {
if (connection.player.id.toTracker() != null) {
connection.send(ClientboundSetCarriedItemPacket(player.inventory.heldItemSlot))
return
}
}
is ServerboundPlayerActionPacket -> {
if (connection.player.id.toTracker() != null) return
}
}
super.channelRead(ctx, msg)
}

private fun EntityTracker.remove() {
entityUUIDMap.remove(uuid())
remove(player)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,21 @@ class NMSImpl : NMS {
super.write(ctx, msg, promise)
}

override fun channelRead(ctx: ChannelHandlerContext, msg: Any) {
when (msg) {
is ServerboundSetCarriedItemPacket -> {
if (connection.player.id.toTracker() != null) {
connection.send(ClientboundSetCarriedItemPacket(player.inventory.heldItemSlot))
return
}
}
is ServerboundPlayerActionPacket -> {
if (connection.player.id.toTracker() != null) return
}
}
super.channelRead(ctx, msg)
}

private fun EntityTracker.remove() {
entityUUIDMap.remove(uuid())
remove(player)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,21 @@ class NMSImpl : NMS {
super.write(ctx, msg, promise)
}

override fun channelRead(ctx: ChannelHandlerContext, msg: Any) {
when (msg) {
is ServerboundSetCarriedItemPacket -> {
if (connection.player.id.toTracker() != null) {
connection.send(ClientboundSetHeldSlotPacket(player.inventory.heldItemSlot))
return
}
}
is ServerboundPlayerActionPacket -> {
if (connection.player.id.toTracker() != null) return
}
}
super.channelRead(ctx, msg)
}

private fun EntityTracker.remove() {
entityUUIDMap.remove(uuid())
remove(player)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,21 @@ class NMSImpl : NMS {
super.write(ctx, msg, promise)
}

override fun channelRead(ctx: ChannelHandlerContext, msg: Any) {
when (msg) {
is ServerboundSetCarriedItemPacket -> {
if (connection.player.id.toTracker() != null) {
connection.send(ClientboundSetHeldSlotPacket(player.inventory.heldItemSlot))
return
}
}
is ServerboundPlayerActionPacket -> {
if (connection.player.id.toTracker() != null) return
}
}
super.channelRead(ctx, msg)
}

private fun EntityTracker.remove() {
entityUUIDMap.remove(uuid())
remove(player)
Expand Down

0 comments on commit 8abdb8e

Please sign in to comment.