Skip to content

Commit 534e09c

Browse files
Move SkyBlock constants to a separate file and update Gradle to 8.3
- Better error handling when a resource is not found - Remove build dependency on DownloadTranslationsTask :warning: This update breaks existing Fancy Warp Menu resource packs. Please disable any Fancy Warp Menu resource packs before updating
1 parent 7abc838 commit 534e09c

30 files changed

Lines changed: 397 additions & 173 deletions

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
- name: Grant execute permission for gradlew
5656
run: chmod +x gradlew
5757
- name: Build with Gradle
58-
run: ./gradlew build --no-daemon -x downloadTranslations
58+
run: ./gradlew build --no-daemon
5959
- name: Read Project Version
6060
id: read_project_version
6161
if: ${{ github.ref_name == 'main' || contains(github.event.inputs.upload_artifact, 'y') }}

build.gradle.kts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ tasks.shadowJar {
136136

137137
tasks.register<DownloadTranslationsTask>("downloadTranslations") {
138138
group = "translations"
139-
getTranslationsDirectory().set(buildDir.resolve("generated/resources/crowdin"))
140139
}
141140
tasks.register<UploadTranslationsTask>("uploadTranslations") {
142141
group = "translations"
@@ -153,13 +152,13 @@ tasks.register<Copy>("copyTranslationsToClassesDirectory") {
153152
* Copy built jar into a Minecraft launcher instance for debugging in a production environment
154153
*/
155154
tasks.register<Copy>("copyJarToMinecraftLauncher") {
156-
from(buildDir.resolve("libs"))
155+
from(layout.buildDirectory.dir("libs"))
157156
into(file(System.getenv("MC_LAUNCHER_DIR")))
158157
}
159158

160159
tasks.assemble.get().dependsOn(tasks.remapJar)
161160

162161
sourceSets.main {
163162
output.setResourcesDir(sourceSets.main.flatMap { it.java.classesDirectory })
164-
output.dir(tasks.getByName("downloadTranslations"))
163+
output.dir(layout.buildDirectory.dir("generated/resources/crowdin"))
165164
}

buildSrc/src/main/java/ca/tirelesstraveler/DownloadTranslationsTask.kt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@
2323
package ca.tirelesstraveler
2424

2525
import org.gradle.api.DefaultTask
26-
import org.gradle.api.file.DirectoryProperty
2726
import org.gradle.api.file.ProjectLayout
2827
import org.gradle.api.tasks.Input
29-
import org.gradle.api.tasks.OutputDirectory
3028
import org.gradle.api.tasks.TaskAction
3129
import org.gradle.process.ExecOperations
3230
import java.io.ByteArrayOutputStream
@@ -55,8 +53,7 @@ import javax.inject.Inject
5553
*/
5654

5755
/**
58-
* This task uses the Crowdin CLI to download translations.
59-
* It also tells the jar task to pull them from a folder specified by "getTranslationsDirectory" when building.
56+
* This task uses the Crowdin CLI to download translations to the folder configured in crowdin.yml.
6057
* It is incremental and will re-run when the Crowdin project's translation progress changes.
6158
*/
6259
abstract class DownloadTranslationsTask: DefaultTask() {
@@ -79,13 +76,6 @@ abstract class DownloadTranslationsTask: DefaultTask() {
7976
return outputStream.toString()
8077
}
8178

82-
/**
83-
* This property tells the jar task where it should pull the translation files from. It doesn't set the folder
84-
* Crowdin CLI downloads to. That is configured by crowdin.yml.
85-
*/
86-
@OutputDirectory
87-
abstract fun getTranslationsDirectory(): DirectoryProperty
88-
8979
@TaskAction
9080
fun downloadTranslations() {
9181
getExecOperations().exec {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xmx2g
33
baseGroup = ca.tirelesstraveler
44
mcVersion = 1.8.9
55
modid = fancywarpmenu
6-
version = 0.9.0
6+
version = 1.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/main/java/ca/tirelesstraveler/fancywarpmenu/FancyWarpMenu.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@
2222

2323
package ca.tirelesstraveler.fancywarpmenu;
2424

25-
import ca.tirelesstraveler.fancywarpmenu.data.Island;
26-
import ca.tirelesstraveler.fancywarpmenu.data.Layout;
25+
import ca.tirelesstraveler.fancywarpmenu.data.layout.Island;
26+
import ca.tirelesstraveler.fancywarpmenu.data.layout.Layout;
2727
import ca.tirelesstraveler.fancywarpmenu.data.Settings;
28+
import ca.tirelesstraveler.fancywarpmenu.resourceloaders.LayoutLoader;
29+
import ca.tirelesstraveler.fancywarpmenu.data.skyblockconstants.SkyBlockConstants;
2830
import ca.tirelesstraveler.fancywarpmenu.listeners.SkyBlockJoinListener;
2931
import ca.tirelesstraveler.fancywarpmenu.listeners.WarpMenuListener;
32+
import ca.tirelesstraveler.fancywarpmenu.resourceloaders.SkyBlockConstantsLoader;
3033
import net.minecraft.client.Minecraft;
3134
import net.minecraft.client.renderer.texture.TextureManager;
3235
import net.minecraft.client.resources.IReloadableResourceManager;
@@ -56,6 +59,7 @@ public class FancyWarpMenu {
5659
static Logger logger;
5760
private static ForgeVersion.CheckResult updateCheckResult;
5861
private static Layout layout;
62+
private static SkyBlockConstants skyBlockConstants;
5963
private static SkyBlockJoinListener skyblockJoinListener;
6064
private static WarpMenuListener warpMenuListener;
6165
private static KeyBinding keyBindingOpenWarpMenu;
@@ -66,7 +70,7 @@ public static FancyWarpMenu getInstance() {
6670

6771
@Mod.EventHandler
6872
public void preInit(FMLPreInitializationEvent event) {
69-
ProgressManager.ProgressBar bar = ProgressManager.push("Pre-init", 3);
73+
ProgressManager.ProgressBar bar = ProgressManager.push("Pre-init", 4);
7074
EnvironmentDetails.deobfuscatedEnvironment = (Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
7175
modId = event.getModMetadata().modId;
7276
modContainer = Loader.instance().activeModContainer();
@@ -82,7 +86,9 @@ public void preInit(FMLPreInitializationEvent event) {
8286
Settings.syncConfig(true);
8387
logger = event.getModLog();
8488
event.getModMetadata().version = modContainer.getVersion();
85-
bar.step("Loading Warp Configuration");
89+
bar.step("Loading SkyBlock Constants");
90+
skyBlockConstants = SkyBlockConstantsLoader.loadSkyBlockConstants();
91+
bar.step("Loading Layout");
8692
layout = LayoutLoader.loadLayout();
8793
ProgressManager.pop(bar);
8894
}
@@ -137,13 +143,23 @@ public boolean isPlayerOnSkyBlock() {
137143

138144
public void reloadResources() {
139145
Minecraft.getMinecraft().refreshResources();
146+
reloadSkyBlockConstants();
140147
reloadLayout();
141148
}
142149

150+
public void reloadSkyBlockConstants() {
151+
SkyBlockConstants loadedSkyBlockConstants = SkyBlockConstantsLoader.loadSkyBlockConstants();
152+
153+
// Will be null if json syntax is wrong or SkyBlock constants are invalid
154+
if (loadedSkyBlockConstants != null) {
155+
FancyWarpMenu.skyBlockConstants = loadedSkyBlockConstants;
156+
}
157+
}
158+
143159
public void reloadLayout() {
144160
Layout loadedLayout = LayoutLoader.loadLayout();
145161

146-
// Will be null if json syntax is wrong or config is invalid
162+
// Will be null if json syntax is wrong or layout is invalid
147163
if (loadedLayout != null) {
148164
FancyWarpMenu.layout = loadedLayout;
149165
}
@@ -163,4 +179,8 @@ public static KeyBinding getKeyBindingOpenWarpMenu() {
163179
public static Layout getLayout() {
164180
return layout;
165181
}
182+
183+
public static SkyBlockConstants getSkyBlockConstants() {
184+
return skyBlockConstants;
185+
}
166186
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2023. TirelessTraveler
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
20+
* OR OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
23+
package ca.tirelesstraveler.fancywarpmenu.data;
24+
25+
import com.google.gson.Gson;
26+
import com.google.gson.GsonBuilder;
27+
28+
public class DataCommon {
29+
public static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
30+
}

src/main/java/ca/tirelesstraveler/fancywarpmenu/data/Button.java renamed to src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/Button.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
* OR OTHER DEALINGS IN THE SOFTWARE.
2121
*/
2222

23-
package ca.tirelesstraveler.fancywarpmenu.data;
23+
package ca.tirelesstraveler.fancywarpmenu.data.layout;
2424

2525
import net.minecraft.client.gui.GuiScreen;
2626
import net.minecraft.client.gui.ScaledResolution;
2727
import net.minecraft.util.ResourceLocation;
2828

29+
import static ca.tirelesstraveler.fancywarpmenu.data.DataCommon.gson;
30+
2931
/**
3032
* Class that holds the settings for drawing buttons that are not islands, like the config button.
3133
* This class should not be used directly. Subclasses should provide their own textures and additional fields.
@@ -89,7 +91,7 @@ public void setTextureDimensions(int textureWidth, int textureHeight) {
8991
}
9092

9193
public String toString() {
92-
return Layout.gson.toJson(this);
94+
return gson.toJson(this);
9395
}
9496

9597
public static void validateButtonIcon(Button button) throws IllegalArgumentException, NullPointerException {

src/main/java/ca/tirelesstraveler/fancywarpmenu/data/ConfigButton.java renamed to src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/ConfigButton.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* OR OTHER DEALINGS IN THE SOFTWARE.
2121
*/
2222

23-
package ca.tirelesstraveler.fancywarpmenu.data;
23+
package ca.tirelesstraveler.fancywarpmenu.data.layout;
2424

2525
import ca.tirelesstraveler.fancywarpmenu.FancyWarpMenu;
2626
import net.minecraft.client.Minecraft;

src/main/java/ca/tirelesstraveler/fancywarpmenu/data/Island.java renamed to src/main/java/ca/tirelesstraveler/fancywarpmenu/data/layout/Island.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* OR OTHER DEALINGS IN THE SOFTWARE.
2121
*/
2222

23-
package ca.tirelesstraveler.fancywarpmenu.data;
23+
package ca.tirelesstraveler.fancywarpmenu.data.layout;
2424

2525
import ca.tirelesstraveler.fancywarpmenu.FancyWarpMenu;
2626
import net.minecraft.client.Minecraft;
@@ -32,6 +32,8 @@
3232
import java.io.IOException;
3333
import java.util.List;
3434

35+
import static ca.tirelesstraveler.fancywarpmenu.data.DataCommon.gson;
36+
3537
/**
3638
* Island data used to create the island buttons on the GUI
3739
*/
@@ -153,7 +155,7 @@ public void setHoverEffectTextureLocation() {
153155
}
154156

155157
public String toString() {
156-
return Layout.gson.toJson(this);
158+
return gson.toJson(this);
157159
}
158160

159161
public static void validateIsland(Island island) throws IllegalArgumentException, NullPointerException {

0 commit comments

Comments
 (0)