Skip to content
This repository has been archived by the owner on Dec 17, 2023. It is now read-only.

Commit

Permalink
Update to Minecraft 1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed Dec 3, 2021
1 parent 1d4473d commit 35690d6
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 76 deletions.
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
Expand All @@ -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')
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
57 changes: 30 additions & 27 deletions src/main/java/io/izzel/lightfall/client/LightfallClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,36 +31,38 @@ 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
);
channel.addListener(this::handleReset);
}

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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/io/izzel/lightfall/client/mixin/MinecraftMixin.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
3 changes: 1 addition & 2 deletions src/main/resources/pack.mcmeta
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 35690d6

Please sign in to comment.