diff --git a/build.gradle b/build.gradle index 1d0cf21..35264a2 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { mavenCentral() } dependencies { - classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true + classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT' } } @@ -18,10 +18,10 @@ group = 'io.izzel.lightfall' version = '1.0.0' archivesBaseName = 'lightfallclient' -sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' +java.toolchain.languageVersion = JavaLanguageVersion.of(17) minecraft { - mappings channel: 'snapshot', version: "20210215-1.16.3" + mappings channel: 'official', version: "1.18" runs { client { workingDirectory project.file('run') @@ -46,8 +46,8 @@ repositories { } dependencies { - minecraft 'net.minecraftforge:forge:1.16.5-36.0.46' - compile 'org.spongepowered:mixin:0.8.2' + minecraft 'net.minecraftforge:forge:1.18-38.0.12' + annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' } mixin { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 290541c..e750102 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/io/izzel/lightfall/client/LightfallClient.java b/src/main/java/io/izzel/lightfall/client/LightfallClient.java index 079abf5..1a6c69d 100644 --- a/src/main/java/io/izzel/lightfall/client/LightfallClient.java +++ b/src/main/java/io/izzel/lightfall/client/LightfallClient.java @@ -4,21 +4,22 @@ import io.izzel.lightfall.client.gui.LightfallHandshakeScreen; import io.netty.buffer.Unpooled; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screen.MainMenuScreen; -import net.minecraft.client.gui.screen.MultiplayerScreen; -import net.minecraft.client.network.login.ClientLoginNetHandler; -import net.minecraft.client.network.play.ClientPlayNetHandler; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.PacketBuffer; -import net.minecraft.network.ProtocolType; -import net.minecraft.network.login.client.CCustomPayloadLoginPacket; -import net.minecraft.util.ResourceLocation; +import net.minecraft.client.gui.screens.TitleScreen; +import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen; +import net.minecraft.client.multiplayer.ClientHandshakePacketListenerImpl; +import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.network.ConnectionProtocol; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.game.ClientGamePacketListener; +import net.minecraft.network.protocol.login.ServerboundCustomQueryPacket; +import net.minecraft.resources.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; +import net.minecraftforge.fml.IExtensionPoint; +import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.network.NetworkEvent; -import net.minecraftforge.fml.network.NetworkRegistry; -import net.minecraftforge.fml.network.event.EventNetworkChannel; +import net.minecraftforge.network.NetworkEvent; +import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.registries.GameData; import java.nio.charset.StandardCharsets; @@ -30,10 +31,12 @@ public class LightfallClient { public LightfallClient() { DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> this::registerChannel); + ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, + () -> new IExtensionPoint.DisplayTest(() -> "", (a, b) -> b)); } private void registerChannel() { - EventNetworkChannel channel = NetworkRegistry.newEventChannel( + var channel = NetworkRegistry.newEventChannel( new ResourceLocation("lightfall", "reset"), () -> "1", s -> true, s -> true ); @@ -41,25 +44,25 @@ private void registerChannel() { } private void handleReset(NetworkEvent.ServerCustomPayloadEvent event) { - NetworkEvent.Context context = event.getSource().get(); - NetworkManager netManager = context.getNetworkManager(); - if (netManager == null || !(netManager.getNetHandler() instanceof ClientPlayNetHandler)) { + var context = event.getSource().get(); + var netManager = context.getNetworkManager(); + if (netManager == null || !(netManager.getPacketListener() instanceof ClientGamePacketListener)) { return; } context.enqueueWork(() -> { - Minecraft client = Minecraft.getInstance(); - LightfallHandshakeScreen screen = new LightfallHandshakeScreen(netManager); - client.displayGuiScreen(screen); - if (client.world != null) { + var client = Minecraft.getInstance(); + var screen = new LightfallHandshakeScreen(netManager); + client.setScreen(screen); + if (client.level != null) { GameData.revertToFrozen(); - client.world = null; + client.level = null; } - netManager.setConnectionState(ProtocolType.LOGIN); - PacketBuffer buffer = new PacketBuffer(Unpooled.wrappedBuffer(RESET_ACK)); - netManager.sendPacket(new CCustomPayloadLoginPacket(0x11FFA1, buffer)); - ClientLoginNetHandler netHandler = new ClientLoginNetHandler(netManager, client, new MultiplayerScreen(new MainMenuScreen()), screen::displaySavingString); - ((ClientLoginNetHandlerBridge) netHandler).bridge$reusePlayHandler((ClientPlayNetHandler) netManager.getNetHandler()); - netManager.setNetHandler(netHandler); + netManager.setProtocol(ConnectionProtocol.LOGIN); + var buffer = new FriendlyByteBuf(Unpooled.wrappedBuffer(RESET_ACK)); + netManager.send(new ServerboundCustomQueryPacket(0x11FFA1, buffer)); + var netHandler = new ClientHandshakePacketListenerImpl(netManager, client, new JoinMultiplayerScreen(new TitleScreen()), screen::setComponent); + ((ClientLoginNetHandlerBridge) netHandler).bridge$reusePlayHandler((ClientPacketListener) netManager.getPacketListener()); + netManager.setListener(netHandler); }); context.setPacketHandled(true); } diff --git a/src/main/java/io/izzel/lightfall/client/bridge/ClientLoginNetHandlerBridge.java b/src/main/java/io/izzel/lightfall/client/bridge/ClientLoginNetHandlerBridge.java index 5cb2b9f..69d6037 100644 --- a/src/main/java/io/izzel/lightfall/client/bridge/ClientLoginNetHandlerBridge.java +++ b/src/main/java/io/izzel/lightfall/client/bridge/ClientLoginNetHandlerBridge.java @@ -1,8 +1,9 @@ package io.izzel.lightfall.client.bridge; -import net.minecraft.client.network.play.ClientPlayNetHandler; + +import net.minecraft.client.multiplayer.ClientPacketListener; public interface ClientLoginNetHandlerBridge { - void bridge$reusePlayHandler(ClientPlayNetHandler handler); + void bridge$reusePlayHandler(ClientPacketListener handler); } diff --git a/src/main/java/io/izzel/lightfall/client/gui/LightfallHandshakeScreen.java b/src/main/java/io/izzel/lightfall/client/gui/LightfallHandshakeScreen.java index 36db7af..95a1e90 100644 --- a/src/main/java/io/izzel/lightfall/client/gui/LightfallHandshakeScreen.java +++ b/src/main/java/io/izzel/lightfall/client/gui/LightfallHandshakeScreen.java @@ -1,44 +1,65 @@ package io.izzel.lightfall.client.gui; +import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.DialogTexts; -import net.minecraft.client.gui.screen.MainMenuScreen; -import net.minecraft.client.gui.screen.MultiplayerScreen; -import net.minecraft.client.gui.screen.WorkingScreen; -import net.minecraft.client.gui.widget.button.Button; -import net.minecraft.network.NetworkManager; -import net.minecraft.util.text.TranslationTextComponent; +import net.minecraft.client.gui.chat.NarratorChatListener; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.TitleScreen; +import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen; +import net.minecraft.network.Connection; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TranslatableComponent; +import org.jetbrains.annotations.NotNull; -public class LightfallHandshakeScreen extends WorkingScreen { +public class LightfallHandshakeScreen extends Screen { - private final NetworkManager networkManager; + private final Connection networkManager; + private Component component; - public LightfallHandshakeScreen(NetworkManager netManager) { + public LightfallHandshakeScreen(Connection netManager) { + super(NarratorChatListener.NO_TITLE); this.networkManager = netManager; } @Override public void tick() { - if (this.networkManager.isChannelOpen()) { + if (this.networkManager.isConnected()) { this.networkManager.tick(); } else { this.networkManager.handleDisconnection(); - if (Minecraft.getInstance().currentScreen == this) { - Minecraft.getInstance().displayGuiScreen(new MultiplayerScreen(new MainMenuScreen())); + if (Minecraft.getInstance().screen == this) { + Minecraft.getInstance().setScreen(new JoinMultiplayerScreen(new TitleScreen())); } } } @Override protected void init() { - this.displaySavingString(new TranslationTextComponent("connect.connecting")); - this.addButton( - new Button(this.width / 2 - 100, this.height / 4 + 120 + 12, 200, 20, DialogTexts.GUI_CANCEL, + this.addRenderableWidget( + new Button(this.width / 2 - 100, this.height / 4 + 120 + 12, 200, 20, CommonComponents.GUI_CANCEL, button -> { - this.networkManager.closeChannel(new TranslationTextComponent("connect.aborted")); - this.minecraft.displayGuiScreen(new MultiplayerScreen(new MainMenuScreen())); + this.networkManager.disconnect(new TranslatableComponent("connect.aborted")); + this.minecraft.setScreen(new JoinMultiplayerScreen(new TitleScreen())); } ) ); } + + public void setComponent(Component component) { + this.component = component; + } + + public void render(@NotNull PoseStack poseStack, int p_96531_, int p_96532_, float p_96533_) { + this.renderDirtBackground(0); + drawCenteredString(poseStack, this.font, component != null ? component : new TranslatableComponent("connect.connecting"), + this.width / 2, this.height / 2 - 50, 16777215); + super.render(poseStack, p_96531_, p_96532_, p_96533_); + } + + @Override + public boolean shouldCloseOnEsc() { + return false; + } } diff --git a/src/main/java/io/izzel/lightfall/client/mixin/ClientLoginNetHandlerMixin.java b/src/main/java/io/izzel/lightfall/client/mixin/ClientLoginNetHandlerMixin.java index 7a9ea84..5e186a3 100644 --- a/src/main/java/io/izzel/lightfall/client/mixin/ClientLoginNetHandlerMixin.java +++ b/src/main/java/io/izzel/lightfall/client/mixin/ClientLoginNetHandlerMixin.java @@ -2,31 +2,31 @@ import io.izzel.lightfall.client.bridge.ClientLoginNetHandlerBridge; import net.minecraft.client.Minecraft; -import net.minecraft.client.network.login.ClientLoginNetHandler; -import net.minecraft.client.network.play.ClientPlayNetHandler; -import net.minecraft.network.INetHandler; +import net.minecraft.client.multiplayer.ClientHandshakePacketListenerImpl; +import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.network.PacketListener; import org.spongepowered.asm.mixin.Final; 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.ModifyArg; -@Mixin(ClientLoginNetHandler.class) +@Mixin(ClientHandshakePacketListenerImpl.class) public class ClientLoginNetHandlerMixin implements ClientLoginNetHandlerBridge { - @Shadow @Final private Minecraft mc; + @Shadow @Final private Minecraft minecraft; - private ClientPlayNetHandler lightfall$reuse; + private ClientPacketListener lightfall$reuse; @Override - public void bridge$reusePlayHandler(ClientPlayNetHandler handler) { + public void bridge$reusePlayHandler(ClientPacketListener handler) { this.lightfall$reuse = handler; } - @ModifyArg(method = "handleLoginSuccess", index = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkManager;setNetHandler(Lnet/minecraft/network/INetHandler;)V")) - private INetHandler lightfall$reuse(INetHandler origin) { + @ModifyArg(method = "handleGameProfile", index = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/network/Connection;setListener(Lnet/minecraft/network/PacketListener;)V")) + private PacketListener lightfall$reuse(PacketListener origin) { if (lightfall$reuse != null) { - this.mc.world = lightfall$reuse.getWorld(); + this.minecraft.level = lightfall$reuse.getLevel(); } return lightfall$reuse == null ? origin : lightfall$reuse; } diff --git a/src/main/java/io/izzel/lightfall/client/mixin/MinecraftMixin.java b/src/main/java/io/izzel/lightfall/client/mixin/MinecraftMixin.java index 05c9b04..2edfa5a 100644 --- a/src/main/java/io/izzel/lightfall/client/mixin/MinecraftMixin.java +++ b/src/main/java/io/izzel/lightfall/client/mixin/MinecraftMixin.java @@ -1,20 +1,9 @@ package io.izzel.lightfall.client.mixin; import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.player.ClientPlayerEntity; -import net.minecraft.client.world.ClientWorld; 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.Redirect; @Mixin(Minecraft.class) public class MinecraftMixin { - @Shadow public ClientPlayerEntity player; - - @Redirect(method = "getBackgroundMusicSelector", at = @At(value = "FIELD", target = "Lnet/minecraft/client/Minecraft;world:Lnet/minecraft/client/world/ClientWorld;")) - private ClientWorld lightfall$usePlayerWorld(Minecraft minecraft) { - return (ClientWorld) this.player.world; - } } diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta index d13a54a..b4b3f2f 100644 --- a/src/main/resources/pack.mcmeta +++ b/src/main/resources/pack.mcmeta @@ -1,7 +1,6 @@ { "pack": { "description": "lightfallclient resources", - "pack_format": 4, - "_comment": "A pack_format of 4 requires json lang files. Note: we require v4 pack meta for all mods." + "pack_format": 8 } }