-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
164 additions
and
29 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
42 changes: 42 additions & 0 deletions
42
src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/ServerLinkP2PHandlerMixin.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,42 @@ | ||
package com.nomiceu.nomilabs.mixin.betterp2p; | ||
|
||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage; | ||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; | ||
|
||
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.CallbackInfoReturnable; | ||
|
||
import com.projecturanus.betterp2p.network.ModNetwork; | ||
import com.projecturanus.betterp2p.network.PlayerRequest; | ||
import com.projecturanus.betterp2p.network.packet.C2SLinkP2P; | ||
import com.projecturanus.betterp2p.network.packet.ServerLinkP2PHandler; | ||
|
||
/** | ||
* Fixes an edge case CME. | ||
*/ | ||
@Mixin(value = ServerLinkP2PHandler.class, remap = false) | ||
public class ServerLinkP2PHandlerMixin { | ||
|
||
@Inject(method = "onMessage(Lcom/projecturanus/betterp2p/network/packet/C2SLinkP2P;Lnet/minecraftforge/fml/common/network/simpleimpl/MessageContext;)Lnet/minecraftforge/fml/common/network/simpleimpl/IMessage;", | ||
at = @At("HEAD"), | ||
cancellable = true) | ||
private void newMsgHandling(C2SLinkP2P message, MessageContext ctx, CallbackInfoReturnable<IMessage> cir) { | ||
cir.setReturnValue(null); | ||
|
||
if (!ctx.side.isServer()) return; | ||
if (message.getInput() == null || message.getOutput() == null) return; | ||
|
||
PlayerRequest state = ModNetwork.INSTANCE.getPlayerState().get(ctx.getServerHandler().player.getUniqueID()); | ||
if (state == null) return; | ||
|
||
ctx.getServerHandler().server.addScheduledTask(() -> { | ||
var result = state.getGridCache().linkP2P(message.getInput(), message.getOutput()); | ||
|
||
if (result != null) { | ||
ModNetwork.INSTANCE.requestP2PUpdate(ctx.getServerHandler().player); | ||
} | ||
}); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/ServerTypeChangeHandlerMixin.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,43 @@ | ||
package com.nomiceu.nomilabs.mixin.betterp2p; | ||
|
||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; | ||
|
||
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.CallbackInfoReturnable; | ||
|
||
import com.projecturanus.betterp2p.BetterP2P; | ||
import com.projecturanus.betterp2p.network.ModNetwork; | ||
import com.projecturanus.betterp2p.network.PlayerRequest; | ||
import com.projecturanus.betterp2p.network.packet.*; | ||
import com.projecturanus.betterp2p.util.p2p.TunnelInfo; | ||
|
||
/** | ||
* Fixes an edge case CME. | ||
*/ | ||
@Mixin(value = ServerTypeChangeHandler.class, remap = false) | ||
public class ServerTypeChangeHandlerMixin { | ||
|
||
@Inject(method = "onMessage(Lcom/projecturanus/betterp2p/network/packet/C2STypeChange;Lnet/minecraftforge/fml/common/network/simpleimpl/MessageContext;)Lcom/projecturanus/betterp2p/network/packet/S2COpenGui;", | ||
at = @At("HEAD"), | ||
cancellable = true) | ||
private void newMsgHandling(C2STypeChange message, MessageContext ctx, CallbackInfoReturnable<S2COpenGui> cir) { | ||
cir.setReturnValue(null); | ||
|
||
if (!ctx.side.isServer()) return; | ||
if (message.getP2p() == null) return; | ||
|
||
PlayerRequest state = ModNetwork.INSTANCE.getPlayerState().get(ctx.getServerHandler().player.getUniqueID()); | ||
TunnelInfo type = BetterP2P.proxy.getP2PFromIndex(message.getNewType()); | ||
if (state == null || type == null) return; | ||
|
||
ctx.getServerHandler().server.addScheduledTask(() -> { | ||
var result = state.getGridCache().changeAllP2Ps(message.getP2p(), type); | ||
|
||
if (result) { | ||
ModNetwork.INSTANCE.requestP2PList(ctx.getServerHandler().player, type.getIndex()); | ||
} | ||
}); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/ServerUnlinkP2PHandlerMixin.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,38 @@ | ||
package com.nomiceu.nomilabs.mixin.betterp2p; | ||
|
||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; | ||
|
||
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.CallbackInfoReturnable; | ||
|
||
import com.projecturanus.betterp2p.network.ModNetwork; | ||
import com.projecturanus.betterp2p.network.PlayerRequest; | ||
import com.projecturanus.betterp2p.network.packet.*; | ||
|
||
/** | ||
* Fixes an edge case CME. | ||
*/ | ||
@Mixin(value = ServerUnlinkP2PHandler.class, remap = false) | ||
public class ServerUnlinkP2PHandlerMixin { | ||
|
||
@Inject(method = "onMessage(Lcom/projecturanus/betterp2p/network/packet/C2SUnlinkP2P;Lnet/minecraftforge/fml/common/network/simpleimpl/MessageContext;)Lcom/projecturanus/betterp2p/network/packet/S2COpenGui;", | ||
at = @At("HEAD"), | ||
cancellable = true) | ||
private void newMsgHandling(C2SUnlinkP2P message, MessageContext ctx, CallbackInfoReturnable<S2COpenGui> cir) { | ||
cir.setReturnValue(null); | ||
|
||
if (!ctx.side.isServer()) return; | ||
if (message.getP2p() == null) return; | ||
|
||
PlayerRequest state = ModNetwork.INSTANCE.getPlayerState().get(ctx.getServerHandler().player.getUniqueID()); | ||
if (state == null) return; | ||
|
||
ctx.getServerHandler().server.addScheduledTask(() -> { | ||
state.getGridCache().unlinkP2P(message.getP2p()); | ||
|
||
ModNetwork.INSTANCE.requestP2PUpdate(ctx.getServerHandler().player); | ||
}); | ||
} | ||
} |
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
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