Skip to content

Commit

Permalink
[forge] Update to 1.19.4
Browse files Browse the repository at this point in the history
  • Loading branch information
BoBkiNN committed Jul 29, 2023
1 parent 8e5b9ef commit ec30f0f
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 98 deletions.
70 changes: 31 additions & 39 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ plugins {

apply plugin: 'org.spongepowered.mixin'

version = '1.1.19-Forge_1.19.4'
group = 'xyz.bobkinn_'
project.version = '1.1-b15-R-Forge_1.19.2'
String semVer = ((String) version).split("-")[0]+".0"
archivesBaseName = 'opentopublic'

String semVer = ((String) version).split("-")[0]

println("Forge mod version: "+version+ " ("+semVer+")")

build.doLast {
project.build.doLast {
println "Build output directory: ${project.buildDir}"+"\\libs"
}

Expand All @@ -40,13 +42,13 @@ minecraft {
// See more information here: https://github.com/MinecraftForge/MCPConfig/blob/master/Mojang.md
//
// Parchment is an unofficial project maintained by ParchmentMC, separate from MinecraftForge
// Additional setup is needed to use their mappings: https://github.com/ParchmentMC/Parchment/wiki/Getting-Started
// Additional setup is needed to use their mappings: https://parchmentmc.org/docs/getting-started
//
// Use non-default mappings at your own risk. They may not always work.
// Simply re-run your setup task after changing the mappings to update your workspace.
mappings channel: 'official', version: '1.19.2'
mappings channel: 'official', version: '1.19.4'

// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') // Currently, this location cannot be changed from the default.

// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
Expand All @@ -67,6 +69,8 @@ minecraft {
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
property 'forge.logging.console.level', 'debug'

// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
property 'forge.enabledGameTestNamespaces', 'opentopublic'

mods {
opentopublic {
Expand All @@ -82,6 +86,26 @@ minecraft {

property 'forge.logging.console.level', 'debug'

property 'forge.enabledGameTestNamespaces', 'opentopublic'

mods {
opentopublic {
source sourceSets.main
}
}
}

// This run config launches GameTestServer and runs all registered gametests, then exits.
// By default, the server will crash when no gametests are provided.
// The gametest system is also enabled by default for other run configs under the /test command.
gameTestServer {
workingDirectory project.file('run')

property 'forge.logging.markers', 'REGISTRIES'

property 'forge.logging.console.level', 'debug'

property 'forge.enabledGameTestNamespaces', 'examplemod'

mods {
opentopublic {
Expand Down Expand Up @@ -118,38 +142,6 @@ mixin {
// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }

ext {
semVersion = semVer
}

processResources {
// inputs.property "version", semVer
filteringCharset "UTF-8"
inputs.property 'version', semVer
filesMatching("**/mods.tml"){
expand("semVersion": semVer)
replaceText("META-INF/mods.toml", '$semVersion', semVer)
}
outputs.upToDateWhen { false }
}

def replaceText(String fileName, String targetText, String textToReplace) {
String to = ("${buildDir}/resources/main/"+fileName).replace("/", "\\")
copy {
from fileName
into(to)
// println("To "+to)
// rename { "test_replaced.toml" }
expand(targetText: textToReplace)
filter { line -> {
// println(line)
line.replace(targetText, textToReplace) } }
// println("Replaced "+it)
}

return to
}

repositories {
mavenCentral()

Expand All @@ -169,7 +161,7 @@ dependencies {
// Specify the version of Minecraft to use. If this is any group other than 'net.minecraft' it is assumed
// that the dep is a ForgeGradle 'patcher' dependency, and its patches will be applied.
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
minecraft 'net.minecraftforge:forge:1.19.2-43.2.0'
minecraft 'net.minecraftforge:forge:1.19.4-45.1.16'

// Real mod deobf dependency examples - these get remapped to your current mappings
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}:api") // Adds JEI API as a compile dependency
Expand Down
12 changes: 11 additions & 1 deletion forge/src/main/java/xyz/bobkinn_/opentopublic/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.toasts.SystemToast;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.storage.LevelResource;
Expand Down Expand Up @@ -63,7 +65,15 @@ public static void atSuccessOpen(boolean successOpen){
MutableComponent successWAN;
String ip = (OpenToPublic.upnpIp == null) ? "0.0.0.0" : OpenToPublic.upnpIp;
if (!OpenToPublic.cfg.isHideIps()) {
successWAN = Component.translatable("opentopublic.publish.started_wan", ip + ":" + OpenToPublic.customPort);
successWAN = Component.translatable("opentopublic.publish.started_wan", ip + ":" + OpenToPublic.customPort)
.withStyle(
(style -> style.withClickEvent(
new ClickEvent(
ClickEvent.Action.COPY_TO_CLIPBOARD, ip + ":" + OpenToPublic.customPort
))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.translatable("chat.copy.click")))
)
);
} else {
successWAN = Component.translatable("opentopublic.publish.started_wan_noIp", Integer.toString(OpenToPublic.customPort));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.ShareToLanScreen;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.server.IntegratedServer;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.status.ServerStatus;
import net.minecraft.world.level.GameType;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
Expand Down Expand Up @@ -68,14 +69,31 @@ public void render(PoseStack matrices, int mouseX, int mouseY, float delta, Call
}

@Redirect(method = "init", at = @At(value = "INVOKE",ordinal = 2, target = "Lnet/minecraft/client/gui/screens/ShareToLanScreen;addRenderableWidget(Lnet/minecraft/client/gui/components/events/GuiEventListener;)Lnet/minecraft/client/gui/components/events/GuiEventListener;"))
private GuiEventListener movePort(ShareToLanScreen instance, GuiEventListener element) {
// port enter field
PortInputTextField portField = new PortInputTextField(font, this.width / 2 - 154 + 147/2,
this.height - 54,
147/2, 20,
Component.translatable("opentopublic.button.port"), OpenToPublic.customPort);
portField.setResponder((text) -> {
portField.setTextColor(validatePort(text) >= 0 ? 0xFFFFFF : 0xFF5555);
enteredPort = portField.getServerPort();
});
this.addRenderableWidget(portField);
return portField;
}

@Redirect(method = "init", at = @At(value = "INVOKE",ordinal = 3, target = "Lnet/minecraft/client/gui/screens/ShareToLanScreen;addRenderableWidget(Lnet/minecraft/client/gui/components/events/GuiEventListener;)Lnet/minecraft/client/gui/components/events/GuiEventListener;"))
private GuiEventListener addButtonRedirect(ShareToLanScreen instance, GuiEventListener element) {
AbstractWidget newBtn = new Button(this.width / 2 - 155, this.height - 28, 150, 20, Component.translatable("lanServer.start"), buttonWidget -> {
Button.OnPress act = (w) -> {
if (this.minecraft == null) return;
IntegratedServer server = this.minecraft.getSingleplayerServer();
String playerName = Minecraft.getInstance().getUser().getName();
if (server == null) return;

if (validatePort(Integer.toString(enteredPort)) == -1) return;
if (validatePort(Integer.toString(enteredPort)) == -1) {
return;
}
if (MaxPlayersInputTextField.validateNum(Integer.toString(enteredMaxPN)) == -1) return;
String enteredMotd = motdInput.getMotd();
if (enteredMotd == null) return;
Expand Down Expand Up @@ -115,7 +133,9 @@ private GuiEventListener addButtonRedirect(ShareToLanScreen instance, GuiEventLi
boolean successOpen = server.publishServer(this.gameMode, this.commands, OpenToPublic.customPort);

String parsedMotd = Util.parseValues(motd, playerName, worldName);
((ServerMetadataAccessor) server).getStatusResponse().setDescription(Component.literal(parsedMotd));
server.setMotd(parsedMotd);
ServerStatus md = ((ServerMetadataAccessor) server).buildServerStatus();
((ServerMetadataAccessor) server).setStatus(md);

if (doUPnP) {
Util.displayToast(Component.translatable("opentopublic.toast.upnp_in_process.title"), Component.translatable("opentopublic.toast.upnp_in_process.desc"));
Expand All @@ -124,7 +144,9 @@ private GuiEventListener addButtonRedirect(ShareToLanScreen instance, GuiEventLi
Util.atSuccessOpen(successOpen);
}
this.minecraft.updateTitle();
});
};
Button newBtn = Button.builder(Component.translatable("lanServer.start"), act)
.bounds(this.width / 2 - 155, this.height - 28, 150, 20).build();
this.addRenderableWidget(newBtn);
return newBtn;
}
Expand All @@ -137,7 +159,6 @@ private void onInit(CallbackInfo ci){
if (player == null || server == null){
return;
}
Screen self = this;
this.motd = server.getMotd();

OpenToPublic.updateConfig(OpenToPublic.modConfigPath.resolve("config.json")); // update config
Expand All @@ -155,57 +176,47 @@ private void onInit(CallbackInfo ci){


// open to wan button
Button.OnTooltip wanTooltip = (button, matrices, mouseX, mouseY) -> {
String tooltipTextKey;
if (OpenToPublic.openPublic.isTrue()){
tooltipTextKey = "opentopublic.tooltip.wan_tooltip.manual";
} else if (OpenToPublic.openPublic.isFalse()) {
tooltipTextKey = "opentopublic.tooltip.wan_tooltip.lan";
} else {
tooltipTextKey = "opentopublic.tooltip.wan_tooltip.upnp";
}
self.renderTooltip(matrices, Component.translatable(tooltipTextKey), mouseX, mouseY);
};
openToWan = new Button(this.width / 2 + 5,
this.height - 54, 150, 20,
Component.translatable("opentopublic.button.open_public"), button -> {
OpenToPublic.openPublic.next();
updateButtonText();
}, wanTooltip);
this.addRenderableWidget(openToWan);
String tooltipTextKey;
if (OpenToPublic.openPublic.isTrue()){
tooltipTextKey = "opentopublic.tooltip.wan_tooltip.manual";
} else if (OpenToPublic.openPublic.isFalse()) {
tooltipTextKey = "opentopublic.tooltip.wan_tooltip.lan";
} else {
tooltipTextKey = "opentopublic.tooltip.wan_tooltip.upnp";
}
Tooltip wanTooltip = Tooltip.create(Component.translatable(tooltipTextKey));

// port enter field
PortInputTextField portField = new PortInputTextField(font, this.width / 2 - 154 + 147/2,
this.height - 54,
147/2, 20,
Component.translatable("opentopublic.button.port"), OpenToPublic.customPort);
portField.setResponder((text) -> {
portField.setTextColor(validatePort(text) >= 0 ? 0xFFFFFF : 0xFF5555);
enteredPort = portField.getServerPort();
});
this.addRenderableWidget(portField);
openToWan = Button.builder(
Component.translatable("opentopublic.button.open_public"),
(w) -> {
OpenToPublic.openPublic.next();
updateButtonText();
})
.bounds(this.width / 2 + 5, this.height - 54, 150, 20)
.tooltip(wanTooltip)
.build();
this.addRenderableWidget(openToWan);

// online mode switch
Button.OnTooltip onlineModeTooltip = (button, matrices, mouseX, mouseY) ->
self.renderTooltip(matrices,
Component.translatable("opentopublic.tooltip.online_mode_tooltip"), mouseX, mouseY);
onlineModeButton =
new Button(this.width / 2 - 155, 144, 150, 20,
Util.parseYN("opentopublic.button.online_mode", OpenToPublic.onlineMode),
button -> {
Tooltip onlineModeTooltip = Tooltip.create(Component.translatable("opentopublic.tooltip.online_mode_tooltip"));
onlineModeButton = Button.builder(Util.parseYN("opentopublic.button.online_mode", OpenToPublic.onlineMode),
(w) -> {
OpenToPublic.onlineMode = !OpenToPublic.onlineMode;
updateButtonText();
},
onlineModeTooltip
);
})
.bounds(this.width / 2 - 155, 144, 150, 20)
.tooltip(onlineModeTooltip)
.build();
this.addRenderableWidget(onlineModeButton);

// pvp on/off button
pvpButton =
new Button(this.width / 2 + 5, 144, 150, 20, Util.parseYN("opentopublic.button.enable_pvp", OpenToPublic.enablePvp), button -> {
OpenToPublic.enablePvp = ! OpenToPublic.enablePvp;
updateButtonText();
});
pvpButton = Button.builder(Util.parseYN("opentopublic.button.enable_pvp", OpenToPublic.enablePvp),
(w) -> {
OpenToPublic.enablePvp = ! OpenToPublic.enablePvp;
updateButtonText();
})
.bounds(this.width / 2 + 5, 144, 150, 20)
.build();
this.addRenderableWidget(pvpButton);

// max player input field
Expand All @@ -228,6 +239,15 @@ private void updateButtonText(){
if (OpenToPublic.openPublic.isTrue()) this.openToWan.setMessage(Component.translatable("opentopublic.button.open_public", Component.translatable("opentopublic.text.manual")));
else if (OpenToPublic.openPublic.isFalse()) this.openToWan.setMessage(Component.translatable("opentopublic.button.open_public", Util.off));
else if (OpenToPublic.openPublic.isThird()) this.openToWan.setMessage(Component.translatable("opentopublic.button.open_public", "UPnP"));
String wanTooltip;
if (OpenToPublic.openPublic.isTrue()){
wanTooltip = "opentopublic.tooltip.wan_tooltip.manual";
} else if (OpenToPublic.openPublic.isFalse()) {
wanTooltip = "opentopublic.tooltip.wan_tooltip.lan";
} else {
wanTooltip = "opentopublic.tooltip.wan_tooltip.upnp";
}
this.openToWan.setTooltip(Tooltip.create(Component.translatable(wanTooltip)));
this.onlineModeButton.setMessage(Util.parseYN("opentopublic.button.online_mode", OpenToPublic.onlineMode));
this.pvpButton.setMessage(Util.parseYN("opentopublic.button.enable_pvp", OpenToPublic.enablePvp));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(MinecraftServer.class)
public interface ServerMetadataAccessor {

@Mutable @Accessor("status")
ServerStatus getStatusResponse();
@Invoker("buildServerStatus")
ServerStatus buildServerStatus();

@Mutable
@Accessor
void setStatus(ServerStatus status);
}
12 changes: 6 additions & 6 deletions forge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml
modLoader = "javafml" #mandatory
# A version range to match for said mod loader - for regular FML @Mod it will be the forge version
loaderVersion = "[43,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions.
loaderVersion = "[45,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions.
# The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties.
# Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here.
license = "MIT"
# A URL to refer people to when problems occur with this mod
#issueTrackerURL="http://my.issue.tracker/" #optional
issueTrackerURL="https://github.com/BoBkiNN/OpenToPublic/issues" #optional
# A list of mods - how many allowed here is determined by the individual mod loader
[[mods]] #mandatory
# The modid of the mod
modId = "opentopublic" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
# see the associated build.gradle script for how to populate this completely automatically during a build
#version = "${project.mod_version}" #mandatory idk why not working
version = "1.1.0"
#version = "${project.mod_version}" #mandatory | idk why not working
version = "1.1.19"
# A display name for the mod
displayName = "OpenToPublic" #mandatory
# A URL to query for updates for this mod. See the JSON update specification <here>
Expand All @@ -44,7 +44,7 @@ modId = "forge" #mandatory
# Does this dependency have to exist - if not, ordering below must be specified
mandatory = true #mandatory
# The version range of the dependency
versionRange = "[43,)" #mandatory
versionRange = "[45,)" #mandatory
# An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory
ordering = "NONE"
# Side this dependency is applied on - BOTH, CLIENT or SERVER
Expand All @@ -54,6 +54,6 @@ side = "BOTH"
modId = "minecraft"
mandatory = true
# This version range declares a minimum of the current minecraft version up to but not including the next major version
versionRange = "[1.19.2,1.20)"
versionRange = "[1.19.4,1.20)"
ordering = "NONE"
side = "BOTH"
Loading

0 comments on commit ec30f0f

Please sign in to comment.