Skip to content

Commit

Permalink
Move SkyBlock constants to a separate file and update Gradle to 8.3
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
ILikePlayingGames committed Sep 6, 2023
1 parent 7abc838 commit 534e09c
Show file tree
Hide file tree
Showing 30 changed files with 397 additions and 173 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build --no-daemon -x downloadTranslations
run: ./gradlew build --no-daemon
- name: Read Project Version
id: read_project_version
if: ${{ github.ref_name == 'main' || contains(github.event.inputs.upload_artifact, 'y') }}
Expand Down
5 changes: 2 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ tasks.shadowJar {

tasks.register<DownloadTranslationsTask>("downloadTranslations") {
group = "translations"
getTranslationsDirectory().set(buildDir.resolve("generated/resources/crowdin"))
}
tasks.register<UploadTranslationsTask>("uploadTranslations") {
group = "translations"
Expand All @@ -153,13 +152,13 @@ tasks.register<Copy>("copyTranslationsToClassesDirectory") {
* Copy built jar into a Minecraft launcher instance for debugging in a production environment
*/
tasks.register<Copy>("copyJarToMinecraftLauncher") {
from(buildDir.resolve("libs"))
from(layout.buildDirectory.dir("libs"))
into(file(System.getenv("MC_LAUNCHER_DIR")))
}

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

sourceSets.main {
output.setResourcesDir(sourceSets.main.flatMap { it.java.classesDirectory })
output.dir(tasks.getByName("downloadTranslations"))
output.dir(layout.buildDirectory.dir("generated/resources/crowdin"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
package ca.tirelesstraveler

import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.ProjectLayout
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import org.gradle.process.ExecOperations
import java.io.ByteArrayOutputStream
Expand Down Expand Up @@ -55,8 +53,7 @@ import javax.inject.Inject
*/

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

/**
* This property tells the jar task where it should pull the translation files from. It doesn't set the folder
* Crowdin CLI downloads to. That is configured by crowdin.yml.
*/
@OutputDirectory
abstract fun getTranslationsDirectory(): DirectoryProperty

@TaskAction
fun downloadTranslations() {
getExecOperations().exec {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xmx2g
baseGroup = ca.tirelesstraveler
mcVersion = 1.8.9
modid = fancywarpmenu
version = 0.9.0
version = 1.0
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-8.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
30 changes: 25 additions & 5 deletions src/main/java/ca/tirelesstraveler/fancywarpmenu/FancyWarpMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@

package ca.tirelesstraveler.fancywarpmenu;

import ca.tirelesstraveler.fancywarpmenu.data.Island;
import ca.tirelesstraveler.fancywarpmenu.data.Layout;
import ca.tirelesstraveler.fancywarpmenu.data.layout.Island;
import ca.tirelesstraveler.fancywarpmenu.data.layout.Layout;
import ca.tirelesstraveler.fancywarpmenu.data.Settings;
import ca.tirelesstraveler.fancywarpmenu.resourceloaders.LayoutLoader;
import ca.tirelesstraveler.fancywarpmenu.data.skyblockconstants.SkyBlockConstants;
import ca.tirelesstraveler.fancywarpmenu.listeners.SkyBlockJoinListener;
import ca.tirelesstraveler.fancywarpmenu.listeners.WarpMenuListener;
import ca.tirelesstraveler.fancywarpmenu.resourceloaders.SkyBlockConstantsLoader;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.IReloadableResourceManager;
Expand Down Expand Up @@ -56,6 +59,7 @@ public class FancyWarpMenu {
static Logger logger;
private static ForgeVersion.CheckResult updateCheckResult;
private static Layout layout;
private static SkyBlockConstants skyBlockConstants;
private static SkyBlockJoinListener skyblockJoinListener;
private static WarpMenuListener warpMenuListener;
private static KeyBinding keyBindingOpenWarpMenu;
Expand All @@ -66,7 +70,7 @@ public static FancyWarpMenu getInstance() {

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
ProgressManager.ProgressBar bar = ProgressManager.push("Pre-init", 3);
ProgressManager.ProgressBar bar = ProgressManager.push("Pre-init", 4);
EnvironmentDetails.deobfuscatedEnvironment = (Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
modId = event.getModMetadata().modId;
modContainer = Loader.instance().activeModContainer();
Expand All @@ -82,7 +86,9 @@ public void preInit(FMLPreInitializationEvent event) {
Settings.syncConfig(true);
logger = event.getModLog();
event.getModMetadata().version = modContainer.getVersion();
bar.step("Loading Warp Configuration");
bar.step("Loading SkyBlock Constants");
skyBlockConstants = SkyBlockConstantsLoader.loadSkyBlockConstants();
bar.step("Loading Layout");
layout = LayoutLoader.loadLayout();
ProgressManager.pop(bar);
}
Expand Down Expand Up @@ -137,13 +143,23 @@ public boolean isPlayerOnSkyBlock() {

public void reloadResources() {
Minecraft.getMinecraft().refreshResources();
reloadSkyBlockConstants();
reloadLayout();
}

public void reloadSkyBlockConstants() {
SkyBlockConstants loadedSkyBlockConstants = SkyBlockConstantsLoader.loadSkyBlockConstants();

// Will be null if json syntax is wrong or SkyBlock constants are invalid
if (loadedSkyBlockConstants != null) {
FancyWarpMenu.skyBlockConstants = loadedSkyBlockConstants;
}
}

public void reloadLayout() {
Layout loadedLayout = LayoutLoader.loadLayout();

// Will be null if json syntax is wrong or config is invalid
// Will be null if json syntax is wrong or layout is invalid
if (loadedLayout != null) {
FancyWarpMenu.layout = loadedLayout;
}
Expand All @@ -163,4 +179,8 @@ public static KeyBinding getKeyBindingOpenWarpMenu() {
public static Layout getLayout() {
return layout;
}

public static SkyBlockConstants getSkyBlockConstants() {
return skyBlockConstants;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2023. TirelessTraveler
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
* OR OTHER DEALINGS IN THE SOFTWARE.
*/

package ca.tirelesstraveler.fancywarpmenu.data;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class DataCommon {
public static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
* OR OTHER DEALINGS IN THE SOFTWARE.
*/

package ca.tirelesstraveler.fancywarpmenu.data;
package ca.tirelesstraveler.fancywarpmenu.data.layout;

import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.util.ResourceLocation;

import static ca.tirelesstraveler.fancywarpmenu.data.DataCommon.gson;

/**
* Class that holds the settings for drawing buttons that are not islands, like the config button.
* This class should not be used directly. Subclasses should provide their own textures and additional fields.
Expand Down Expand Up @@ -89,7 +91,7 @@ public void setTextureDimensions(int textureWidth, int textureHeight) {
}

public String toString() {
return Layout.gson.toJson(this);
return gson.toJson(this);
}

public static void validateButtonIcon(Button button) throws IllegalArgumentException, NullPointerException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* OR OTHER DEALINGS IN THE SOFTWARE.
*/

package ca.tirelesstraveler.fancywarpmenu.data;
package ca.tirelesstraveler.fancywarpmenu.data.layout;

import ca.tirelesstraveler.fancywarpmenu.FancyWarpMenu;
import net.minecraft.client.Minecraft;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* OR OTHER DEALINGS IN THE SOFTWARE.
*/

package ca.tirelesstraveler.fancywarpmenu.data;
package ca.tirelesstraveler.fancywarpmenu.data.layout;

import ca.tirelesstraveler.fancywarpmenu.FancyWarpMenu;
import net.minecraft.client.Minecraft;
Expand All @@ -32,6 +32,8 @@
import java.io.IOException;
import java.util.List;

import static ca.tirelesstraveler.fancywarpmenu.data.DataCommon.gson;

/**
* Island data used to create the island buttons on the GUI
*/
Expand Down Expand Up @@ -153,7 +155,7 @@ public void setHoverEffectTextureLocation() {
}

public String toString() {
return Layout.gson.toJson(this);
return gson.toJson(this);
}

public static void validateIsland(Island island) throws IllegalArgumentException, NullPointerException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,19 @@
* OR OTHER DEALINGS IN THE SOFTWARE.
*/

package ca.tirelesstraveler.fancywarpmenu.data;

import com.google.gson.Gson;
package ca.tirelesstraveler.fancywarpmenu.data.layout;

import java.util.List;

import static ca.tirelesstraveler.fancywarpmenu.data.DataCommon.gson;

@SuppressWarnings("unused")
public class Layout {
static Gson gson = new Gson();

private List<Island> islandList;
private WarpIcon warpIcon;
private ConfigButton configButton;
private RegularWarpMenuButton regularWarpMenuButton;
private WarpMessages warpMessages;
private List<WarpCommandVariant> warpCommandVariants;

private Layout(){}

Expand All @@ -55,14 +52,6 @@ public RegularWarpMenuButton getRegularWarpMenuButton() {
return regularWarpMenuButton;
}

public WarpMessages getWarpMessages() {
return warpMessages;
}

public List<WarpCommandVariant> getWarpCommandVariants() {
return warpCommandVariants;
}

public static void validateLayout(Layout layout) throws IllegalArgumentException, NullPointerException {
if (layout == null) {
throw new NullPointerException("Warp configuration cannot be null");
Expand All @@ -79,15 +68,6 @@ public static void validateLayout(Layout layout) throws IllegalArgumentException
WarpIcon.validateWarpIcon(layout.getWarpIcon());
ConfigButton.validateConfigButtonIcon(layout.getConfigButton());
RegularWarpMenuButton.validateRegularMenuButtonIcon(layout.getRegularWarpMenuButton());
WarpMessages.validateWarpMessages(layout.getWarpMessages());

if (layout.warpCommandVariants == null || layout.warpCommandVariants.isEmpty()) {
throw new NullPointerException("Warp command variant list cannot be empty");
}

for (WarpCommandVariant warpCommandVariant : layout.warpCommandVariants) {
WarpCommandVariant.validateWarpCommandVariant(warpCommandVariant);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* OR OTHER DEALINGS IN THE SOFTWARE.
*/

package ca.tirelesstraveler.fancywarpmenu.data;
package ca.tirelesstraveler.fancywarpmenu.data.layout;

import ca.tirelesstraveler.fancywarpmenu.FancyWarpMenu;
import net.minecraft.client.Minecraft;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
* OR OTHER DEALINGS IN THE SOFTWARE.
*/

package ca.tirelesstraveler.fancywarpmenu.data;
package ca.tirelesstraveler.fancywarpmenu.data.layout;

import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.util.ResourceLocation;

import static ca.tirelesstraveler.fancywarpmenu.data.DataCommon.gson;

/**
* Warp entry data used to create the warp buttons on the GUI
*/
Expand Down Expand Up @@ -104,7 +106,7 @@ public boolean shouldHideButton() {
}

public String toString() {
return Layout.gson.toJson(this);
return gson.toJson(this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* OR OTHER DEALINGS IN THE SOFTWARE.
*/

package ca.tirelesstraveler.fancywarpmenu.data;
package ca.tirelesstraveler.fancywarpmenu.data.layout;

import ca.tirelesstraveler.fancywarpmenu.FancyWarpMenu;
import net.minecraft.client.Minecraft;
Expand All @@ -30,6 +30,8 @@

import java.io.IOException;

import static ca.tirelesstraveler.fancywarpmenu.data.DataCommon.gson;

/**
* Class that holds the settings for drawing the warp icon (portal)
*/
Expand Down Expand Up @@ -91,7 +93,7 @@ public void setTextureDimensions(int textureWidth, int textureHeight) {
heightPercentage = textureHeight / textureWidth;
}
public String toString() {
return Layout.gson.toJson(this);
return gson.toJson(this);
}

public static void validateWarpIcon(WarpIcon warpIcon) throws IllegalArgumentException, NullPointerException {
Expand Down
Loading

0 comments on commit 534e09c

Please sign in to comment.