From 4f8287ae9cf598f9a7d4d82e38e68bd74fe66b7c Mon Sep 17 00:00:00 2001 From: aromaa Date: Thu, 16 May 2024 14:25:35 +0300 Subject: [PATCH] Allow ChunkBatchReceived when dead --- .../bridge/network/protocol/PacketBridge.java | 30 +++++++++++++ .../phase/packet/PacketPhaseUtil.java | 10 ++--- .../core/network/protocol/PacketMixin.java | 38 ++++++++++++++++ .../ServerboundCustomPayloadPacketMixin.java | 38 ++++++++++++++++ ...verboundChunkBatchReceivedPacketMixin.java | 38 ++++++++++++++++ .../ServerboundClientCommandPacketMixin.java | 44 +++++++++++++++++++ src/mixins/resources/mixins.sponge.core.json | 5 +++ 7 files changed, 196 insertions(+), 7 deletions(-) create mode 100644 src/main/java/org/spongepowered/common/bridge/network/protocol/PacketBridge.java create mode 100644 src/mixins/java/org/spongepowered/common/mixin/core/network/protocol/PacketMixin.java create mode 100644 src/mixins/java/org/spongepowered/common/mixin/core/network/protocol/common/ServerboundCustomPayloadPacketMixin.java create mode 100644 src/mixins/java/org/spongepowered/common/mixin/core/network/protocol/game/ServerboundChunkBatchReceivedPacketMixin.java create mode 100644 src/mixins/java/org/spongepowered/common/mixin/core/network/protocol/game/ServerboundClientCommandPacketMixin.java diff --git a/src/main/java/org/spongepowered/common/bridge/network/protocol/PacketBridge.java b/src/main/java/org/spongepowered/common/bridge/network/protocol/PacketBridge.java new file mode 100644 index 00000000000..3f25f76c03f --- /dev/null +++ b/src/main/java/org/spongepowered/common/bridge/network/protocol/PacketBridge.java @@ -0,0 +1,30 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.common.bridge.network.protocol; + +public interface PacketBridge { + + boolean bridge$canProcessWhenDead(); +} diff --git a/src/main/java/org/spongepowered/common/event/tracking/phase/packet/PacketPhaseUtil.java b/src/main/java/org/spongepowered/common/event/tracking/phase/packet/PacketPhaseUtil.java index 1e351b0f957..3e6f610aaa2 100644 --- a/src/main/java/org/spongepowered/common/event/tracking/phase/packet/PacketPhaseUtil.java +++ b/src/main/java/org/spongepowered/common/event/tracking/phase/packet/PacketPhaseUtil.java @@ -29,9 +29,7 @@ import net.minecraft.network.PacketListener; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.common.ServerboundClientInformationPacket; -import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; -import net.minecraft.network.protocol.game.ServerboundClientCommandPacket; import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.server.network.ServerGamePacketListenerImpl; @@ -68,6 +66,7 @@ import org.spongepowered.common.accessor.world.entity.animal.SheepAccessor; import org.spongepowered.common.accessor.world.entity.animal.WolfAccessor; import org.spongepowered.common.accessor.world.inventory.SlotAccessor; +import org.spongepowered.common.bridge.network.protocol.PacketBridge; import org.spongepowered.common.bridge.world.level.block.TrackableBlockBridge; import org.spongepowered.common.event.tracking.IPhaseState; import org.spongepowered.common.event.tracking.PhaseContext; @@ -203,11 +202,8 @@ public static boolean allTransactionsInvalid(final List slotTra public static void onProcessPacket(final Packet packetIn, final PacketListener netHandler) { if (netHandler instanceof ServerGamePacketListenerImpl) { net.minecraft.server.level.ServerPlayer packetPlayer = ((ServerGamePacketListenerImpl) netHandler).player; - // Only process the CustomPayload & Respawn packets from players if they are dead. - if (!packetPlayer.isAlive() - && (!(packetIn instanceof ServerboundCustomPayloadPacket) - && (!(packetIn instanceof ServerboundClientCommandPacket) - || ((ServerboundClientCommandPacket) packetIn).getAction() != ServerboundClientCommandPacket.Action.PERFORM_RESPAWN))) { + // Only process the CustomPayload, Respawn & ChunkBatchReceived packets from players if they are dead. + if (!packetPlayer.isAlive() && !((PacketBridge) packetIn).bridge$canProcessWhenDead()) { return; } try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) { diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/network/protocol/PacketMixin.java b/src/mixins/java/org/spongepowered/common/mixin/core/network/protocol/PacketMixin.java new file mode 100644 index 00000000000..1a99676dcae --- /dev/null +++ b/src/mixins/java/org/spongepowered/common/mixin/core/network/protocol/PacketMixin.java @@ -0,0 +1,38 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.common.mixin.core.network.protocol; + +import net.minecraft.network.protocol.Packet; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.common.bridge.network.protocol.PacketBridge; + +@Mixin(Packet.class) +public interface PacketMixin extends PacketBridge { + + @Override + default boolean bridge$canProcessWhenDead() { + return false; + } +} diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/network/protocol/common/ServerboundCustomPayloadPacketMixin.java b/src/mixins/java/org/spongepowered/common/mixin/core/network/protocol/common/ServerboundCustomPayloadPacketMixin.java new file mode 100644 index 00000000000..36a811198b2 --- /dev/null +++ b/src/mixins/java/org/spongepowered/common/mixin/core/network/protocol/common/ServerboundCustomPayloadPacketMixin.java @@ -0,0 +1,38 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.common.mixin.core.network.protocol.common; + +import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.common.bridge.network.protocol.PacketBridge; + +@Mixin(ServerboundCustomPayloadPacket.class) +public abstract class ServerboundCustomPayloadPacketMixin implements PacketBridge { + + @Override + public boolean bridge$canProcessWhenDead() { + return true; + } +} diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/network/protocol/game/ServerboundChunkBatchReceivedPacketMixin.java b/src/mixins/java/org/spongepowered/common/mixin/core/network/protocol/game/ServerboundChunkBatchReceivedPacketMixin.java new file mode 100644 index 00000000000..f1361876e24 --- /dev/null +++ b/src/mixins/java/org/spongepowered/common/mixin/core/network/protocol/game/ServerboundChunkBatchReceivedPacketMixin.java @@ -0,0 +1,38 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.common.mixin.core.network.protocol.game; + +import net.minecraft.network.protocol.game.ServerboundChunkBatchReceivedPacket; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.common.bridge.network.protocol.PacketBridge; + +@Mixin(ServerboundChunkBatchReceivedPacket.class) +public abstract class ServerboundChunkBatchReceivedPacketMixin implements PacketBridge { + + @Override + public boolean bridge$canProcessWhenDead() { + return true; + } +} diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/network/protocol/game/ServerboundClientCommandPacketMixin.java b/src/mixins/java/org/spongepowered/common/mixin/core/network/protocol/game/ServerboundClientCommandPacketMixin.java new file mode 100644 index 00000000000..0a6163d9b30 --- /dev/null +++ b/src/mixins/java/org/spongepowered/common/mixin/core/network/protocol/game/ServerboundClientCommandPacketMixin.java @@ -0,0 +1,44 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.common.mixin.core.network.protocol.game; + +import net.minecraft.network.protocol.game.ServerboundClientCommandPacket; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.common.bridge.network.protocol.PacketBridge; + +@Mixin(ServerboundClientCommandPacket.class) +public abstract class ServerboundClientCommandPacketMixin implements PacketBridge { + + // @formatter:off + @Shadow @Final private ServerboundClientCommandPacket.Action action; + // @formatter:on + + @Override + public boolean bridge$canProcessWhenDead() { + return this.action == ServerboundClientCommandPacket.Action.PERFORM_RESPAWN; + } +} diff --git a/src/mixins/resources/mixins.sponge.core.json b/src/mixins/resources/mixins.sponge.core.json index 43fd41c9b35..003fc78237c 100644 --- a/src/mixins/resources/mixins.sponge.core.json +++ b/src/mixins/resources/mixins.sponge.core.json @@ -40,7 +40,12 @@ "network.chat.Component_SerializerMixin", "network.chat.StyleMixin", "network.chat.TranslatableContentsMixin", + "network.protocol.PacketMixin", + "network.protocol.common.ServerboundCustomPayloadPacketMixin", "network.protocol.game.ClientboundResourcePackPushPacketMixin", + "network.protocol.game.ClientboundSetObjectivePacketMixin", + "network.protocol.game.ServerboundChunkBatchReceivedPacketMixin", + "network.protocol.game.ServerboundClientCommandPacketMixin", "network.syncher.EntityDataAccessorMixin", "network.syncher.SynchedEntityDataMixin", "registries.BuiltInRegistriesMixin",