-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[no changelog]
- Loading branch information
Showing
10 changed files
with
99 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
src/main/java/moe/nea/firmament/mixins/CustomPayloadEventDispatcher.java
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
src/main/java/moe/nea/firmament/mixins/custompayload/CustomPayloadEventDispatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Linnea Gräf <[email protected]> | ||
* | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
package moe.nea.firmament.mixins.custompayload; | ||
|
||
import moe.nea.firmament.apis.ingame.FirmamentCustomPayload; | ||
import moe.nea.firmament.events.FirmamentCustomPayloadEvent; | ||
import net.minecraft.client.network.ClientCommonNetworkHandler; | ||
import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(value = ClientCommonNetworkHandler.class, priority = 500) | ||
public class CustomPayloadEventDispatcher { | ||
@Inject(method = "onCustomPayload(Lnet/minecraft/network/packet/s2c/common/CustomPayloadS2CPacket;)V", at = @At("HEAD"), cancellable = true) | ||
private void handleFirmamentParsedPayload(CustomPayloadS2CPacket packet, CallbackInfo ci) { | ||
if (packet.payload() instanceof FirmamentCustomPayload customPayload) { | ||
FirmamentCustomPayloadEvent.Companion.publishSync(new FirmamentCustomPayloadEvent(customPayload)); | ||
ci.cancel(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/moe/nea/firmament/mixins/custompayload/SplitJoinedCustomPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Linnea Gräf <[email protected]> | ||
* | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
package moe.nea.firmament.mixins.custompayload; | ||
|
||
import moe.nea.firmament.apis.ingame.JoinedCustomPayload; | ||
import net.minecraft.network.listener.ClientCommonPacketListener; | ||
import net.minecraft.network.packet.CustomPayload; | ||
import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; | ||
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.callback.CallbackInfo; | ||
|
||
@Mixin(CustomPayloadS2CPacket.class) | ||
public abstract class SplitJoinedCustomPayload { | ||
|
||
@Shadow | ||
public abstract CustomPayload payload(); | ||
|
||
@Inject(method = "apply(Lnet/minecraft/network/listener/ClientCommonPacketListener;)V", at = @At("HEAD"), cancellable = true) | ||
private void onApply(ClientCommonPacketListener clientCommonPacketListener, CallbackInfo ci) { | ||
if (payload() instanceof JoinedCustomPayload joinedCustomPayload) { | ||
new CustomPayloadS2CPacket(joinedCustomPayload.getOriginal()).apply(clientCommonPacketListener); | ||
new CustomPayloadS2CPacket(joinedCustomPayload.getSmuggled()).apply(clientCommonPacketListener); | ||
ci.cancel(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Linnea Gräf <[email protected]> | ||
* SPDX-FileCopyrightText: 2024 Linnea Gräf <[email protected]> | ||
* | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
@@ -8,6 +9,7 @@ package moe.nea.firmament.events | |
|
||
import java.util.concurrent.CopyOnWriteArrayList | ||
import moe.nea.firmament.Firmament | ||
import moe.nea.firmament.util.MC | ||
|
||
/** | ||
* A pubsub event bus. | ||
|
@@ -47,4 +49,9 @@ open class FirmamentEventBus<T : FirmamentEvent> { | |
return event | ||
} | ||
|
||
fun publishSync(event: T) { | ||
MC.onMainThread { | ||
publish(event) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters