-
-
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.
- Loading branch information
1 parent
c672948
commit 6e31341
Showing
9 changed files
with
57 additions
and
71 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
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
15 changes: 6 additions & 9 deletions
15
forge/src/main/java/org/embeddedt/modernfix/forge/mixin/core/NetworkHooksMixin.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 |
---|---|---|
@@ -1,22 +1,19 @@ | ||
package org.embeddedt.modernfix.forge.mixin.core; | ||
|
||
import net.minecraft.network.Connection; | ||
import net.minecraftforge.network.NetworkHooks; | ||
import net.minecraftforge.common.ForgeHooks; | ||
import net.minecraftforge.network.ConnectionType; | ||
import net.minecraftforge.network.NetworkContext; | ||
import org.embeddedt.modernfix.forge.packet.NetworkUtils; | ||
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(NetworkHooks.class) | ||
@Mixin(ForgeHooks.class) | ||
public abstract class NetworkHooksMixin { | ||
@Shadow public static boolean isVanillaConnection(Connection manager) { | ||
throw new AssertionError(); | ||
} | ||
|
||
@Inject(method = "handleClientLoginSuccess", at = @At("RETURN"), remap = false) | ||
@Inject(method = "handleClientConfigurationComplete", at = @At("RETURN"), remap = false) | ||
private static void setVanillaGlobalFlag(Connection manager, CallbackInfo ci) { | ||
NetworkUtils.isCurrentlyVanilla = isVanillaConnection(manager); | ||
NetworkUtils.isCurrentlyVanilla = NetworkContext.get(manager).getType() == ConnectionType.VANILLA; | ||
} | ||
} |
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
37 changes: 16 additions & 21 deletions
37
forge/src/main/java/org/embeddedt/modernfix/forge/packet/PacketHandler.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 |
---|---|---|
@@ -1,35 +1,30 @@ | ||
package org.embeddedt.modernfix.forge.packet; | ||
|
||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraftforge.network.NetworkEvent; | ||
import net.minecraftforge.network.NetworkRegistry; | ||
import net.minecraftforge.network.simple.SimpleChannel; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.fml.DistExecutor; | ||
import net.minecraftforge.network.Channel; | ||
import net.minecraftforge.network.ChannelBuilder; | ||
import net.minecraftforge.network.SimpleChannel; | ||
import org.embeddedt.modernfix.ModernFix; | ||
import org.embeddedt.modernfix.ModernFixClient; | ||
import org.embeddedt.modernfix.packet.EntityIDSyncPacket; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class PacketHandler { | ||
private static final String PROTOCOL_VERSION = "1"; | ||
public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel( | ||
new ResourceLocation(ModernFix.MODID, "main"), | ||
() -> PROTOCOL_VERSION, | ||
NetworkRegistry.acceptMissingOr(PROTOCOL_VERSION), | ||
NetworkRegistry.acceptMissingOr(PROTOCOL_VERSION) | ||
); | ||
private static final int PROTOCOL_VERSION = 1; | ||
public static final SimpleChannel INSTANCE = ChannelBuilder | ||
.named(new ResourceLocation(ModernFix.MODID, "main")) | ||
.networkProtocolVersion(PROTOCOL_VERSION) | ||
.serverAcceptedVersions(Channel.VersionTest.ACCEPT_MISSING.or(Channel.VersionTest.exact(PROTOCOL_VERSION))) | ||
.clientAcceptedVersions(Channel.VersionTest.ACCEPT_MISSING.or(Channel.VersionTest.exact(PROTOCOL_VERSION))) | ||
.simpleChannel(); | ||
|
||
public static void register() { | ||
int id = 1; | ||
INSTANCE.registerMessage(id++, EntityIDSyncPacket.class, EntityIDSyncPacket::serialize, EntityIDSyncPacket::deserialize, PacketHandler::handleSyncPacket); | ||
} | ||
|
||
private static void handleSyncPacket(EntityIDSyncPacket packet, Supplier<NetworkEvent.Context> contextSupplier) { | ||
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { | ||
contextSupplier.get().enqueueWork(() -> ModernFixClient.handleEntityIDSync(packet)); | ||
contextSupplier.get().setPacketHandled(true); | ||
}); | ||
INSTANCE.messageBuilder(EntityIDSyncPacket.class).encoder(EntityIDSyncPacket::serialize).decoder(EntityIDSyncPacket::deserialize).consumerNetworkThread((msg, ctx) -> { | ||
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { | ||
ctx.enqueueWork(() -> ModernFixClient.handleEntityIDSync(msg)); | ||
ctx.setPacketHandled(true); | ||
}); | ||
}).add(); | ||
} | ||
} |
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