Skip to content

Commit

Permalink
[fabric] Update to 1.20.4, fixed that ports was closed even if upnp w…
Browse files Browse the repository at this point in the history
…as off
  • Loading branch information
BoBkiNN committed Feb 6, 2024
1 parent f454fbd commit 9e13460
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,5 @@ run/

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar
/bckp/
/libs/waifupnp-1.2.7z
3 changes: 0 additions & 3 deletions TODO.md

This file was deleted.

10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
org.gradle.jvmargs=-Xmx3G
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.10
loader_version=0.14.21
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.3
loader_version=0.15.6
# Mod Properties
mod_version=1.1.50-Fabric_1.20.1
mod_version=1.1.53-Fabric_1.20.4
maven_group=xyz.bobkinn_
archives_base_name=opentopublic
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.86.1+1.20.1
fabric_version=0.95.4+1.20.4
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtIo;
import net.minecraft.nbt.NbtSizeTracker;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.PersistentState;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -86,7 +87,7 @@ public void loadFromFile(@NotNull ServerWorld world) {
if (!inputFile.exists()) {
return;
}
NbtCompound compressedTag = NbtIo.readCompressed(inputFile);
NbtCompound compressedTag = NbtIo.readCompressed(inputFile.toPath(), NbtSizeTracker.ofUnlimitedBytes());
NbtCompound tag = compressedTag.copy();
tag.remove("DataVersion");
fromNbt(tag);
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/xyz/bobkinn_/opentopublic/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.toast.SystemToast;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.*;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.WorldSavePath;

import java.nio.file.Path;
Expand Down Expand Up @@ -84,7 +87,7 @@ public static void atSuccessOpen(boolean successOpen){
}

public static void displayToast(Text title, Text desc){
mc.getToastManager().add(SystemToast.create(mc, SystemToast.Type.TUTORIAL_HINT, title, desc));
mc.getToastManager().add(SystemToast.create(mc, new SystemToast.Type(), title, desc));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ private void onStart(CallbackInfoReturnable<Boolean> cir){
@Inject(at = @At("HEAD"), method = "stop")
private void atServerStop(boolean bl, CallbackInfo ci) {
OpenedStatus.current = null;
var wasOpen = OpenToPublic.upnpIp != null;
OpenToPublic.upnpIp = null;
OpenToPublic.serverStopped = true;
if (OpenToPublic.openPublic.isThird()) UpnpThread.runClose();
if (OpenToPublic.openPublic.isThird() && wasOpen) UpnpThread.runClose();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.world.GameMode;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
Expand All @@ -33,29 +34,31 @@

@Mixin(value = OpenToLanScreen.class)
public abstract class MixinLanServerScreen extends Screen {
final Screen parent;
protected MixinLanServerScreen(Text title, Screen parent) {

protected MixinLanServerScreen(Text title) {
super(title);
this.parent=parent;
}

ButtonWidget openToWan = null;
ButtonWidget onlineModeButton = null;
ButtonWidget pvpButton = null;
MotdInputTextField motdInput;
@Unique
private ButtonWidget openToWan, onlineModeButton, pvpButton = null;
@Unique
private MotdInputTextField motdInput;

@Shadow
private GameMode gameMode = GameMode.SURVIVAL;
@Shadow
private boolean allowCommands;

int enteredPort = OpenToPublic.customPort;
int enteredMaxPN = OpenToPublic.maxPlayers;
String motd = null;
@Unique
private int enteredPort = OpenToPublic.customPort;
@Unique
private int enteredMaxPN = OpenToPublic.maxPlayers;
@Unique
private String motd = null;

@Inject(at = @At("HEAD"), method = "render", cancellable = true)
public void render(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
this.renderBackground(context);
this.renderBackground(context, mouseX, mouseY, delta);
context.drawCenteredTextWithShadow(this.textRenderer, this.title.asOrderedText(), this.width / 2, 50, 0xFFFFFF);
context.drawCenteredTextWithShadow(this.textRenderer, Text.translatable("opentopublic.gui.new_player_settings").asOrderedText(), this.width / 2, 82, 0xFFFFFF);
context.drawCenteredTextWithShadow(this.textRenderer, Text.translatable("opentopublic.gui.server_settings").asOrderedText(), this.width / 2, 130, 0xFFFFFF);
Expand Down Expand Up @@ -230,6 +233,7 @@ private void onInit(CallbackInfo ci){
}


@Unique
private void updateButtonText(){
if (OpenToPublic.openPublic.isTrue()) this.openToWan.setMessage(Text.translatable("opentopublic.button.open_public", Text.translatable("opentopublic.text.manual")));
else if (OpenToPublic.openPublic.isFalse()) this.openToWan.setMessage(Text.translatable("opentopublic.button.open_public", Util.off));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import net.minecraft.SharedConstants;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ServerInfo;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.client.util.Window;
import net.minecraft.server.integrated.IntegratedServer;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand Down Expand Up @@ -41,17 +43,18 @@ public void run(CallbackInfo ci){
@Shadow
private @Nullable IntegratedServer server;

@Shadow public abstract boolean isConnectedToRealms();

@Shadow public abstract @Nullable ClientPlayNetworkHandler getNetworkHandler();

@Shadow @Final private Window window;

@Shadow @Nullable public abstract ServerInfo getCurrentServerEntry();

@Inject(method = "updateWindowTitle", at = @At("RETURN"))
public void onUpdateWindowTitle(CallbackInfo ci){
this.window.setTitle(getTitle());
}

@Unique
public String getTitle(){
StringBuilder stringBuilder = new StringBuilder("Minecraft");
if (MinecraftClient.getModStatus().isModded()) {
Expand All @@ -62,9 +65,10 @@ public String getTitle(){
ClientPlayNetworkHandler clientPlayNetworkHandler = this.getNetworkHandler();
if (clientPlayNetworkHandler != null && clientPlayNetworkHandler.getConnection().isOpen()) {
stringBuilder.append(" - ");
var info = this.getCurrentServerEntry();
if (this.server != null && !this.server.isRemote() || OpenedStatus.current == null) {
stringBuilder.append(I18n.translate("title.singleplayer"));
} else if (this.isConnectedToRealms()) {
} else if (info != null && info.isRealm()) {
stringBuilder.append(I18n.translate("title.multiplayer.realms"));
} else if (OpenedStatus.current == OpenedStatus.UPNP) {
stringBuilder.append(I18n.translate("opentopublic.title.multiplayer.upnp"));
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
],
"depends": {
"fabricloader": ">=0.14.21",
"minecraft": "1.20.1"
"minecraft": "1.20.4"
}
}

0 comments on commit 9e13460

Please sign in to comment.