Skip to content

Commit

Permalink
Cleanup (#6)
Browse files Browse the repository at this point in the history
* Cleanup build

* applyDecompilerCleanupToMain

* IJ cleanup: Redundant type cast

* IJ cleanup: Unnecessary label on 'continue' statement

* IJ cleanup: Condition is covered by further condition

* IJ cleanup: Redundant 'String' operation

* IJ cleanup: Redundant array creation

* IJ cleanup: Unnecessary 'continue' statement

* IJ cleanup: Magic constant

* IJ cleanup: 'InputStream' and 'OutputStream' can be constructed using 'Files' methods

* IJ cleanup: String concatenation '+' in loop

* IJ cleanup: 'equals("")' can be replaced with 'isEmpty()'

* IJ cleanup: Declaration can have 'final' modifier

* IJ cleanup: Unused label

* IJ cleanup: Redundant local variable

* IJ cleanup: Standard 'Charset' object can be used

* IJ cleanup: Unnecessary call to 'toString()'

* IJ cleanup: Unnecessary modifier

* IJ cleanup: Unnecessary semicolon

* enableGenericInjection

* IJ cleanup: Raw use of parameterized class

* IJ cleanup: Identical 'catch' branches in 'try' statement

* IJ cleanup: Explicit type can be replaced with '<>'

* IJ cleanup: Simplifiable 'Map' operations

* IJ cleanup: Redundant type cast

* IJ cleanup: Too weak variable type leads to unnecessary cast

* Convert manual array iteration to enhanced for loop

* enableModernJavaSyntax

* IJ cleanup: Pattern variable can be used

* IJ cleanup: Redundant 'throws' clause

* updateBuildScript
  • Loading branch information
miozune authored Mar 9, 2024
1 parent 4c26f79 commit e0a8b6f
Show file tree
Hide file tree
Showing 45 changed files with 486 additions and 591 deletions.
12 changes: 0 additions & 12 deletions .github/scripts/update_version

This file was deleted.

8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ whitelist.json
*.iml
*.ipr
*.iws
src/main/resources/mixins.*.json
src/main/resources/mixins.*([!.]).json
*.bat
*.DS_Store
!gradlew.bat
.factorypath
addon.local.gradle
addon.local.gradle.kts
addon.late.local.gradle
addon.late.local.gradle.kts
layout.json
22 changes: 7 additions & 15 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,35 @@ channel = stable
mappingsVersion = 12

# Defines other MCP mappings for dependency deobfuscation.
remoteMappings = https://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/
remoteMappings = https\://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/

# Select a default username for testing your mod. You can always override this per-run by running
# `./gradlew runClient --username=AnotherPlayer`, or configuring this command in your IDE.
developmentEnvironmentUserName = Developer

# Enables using modern Java syntax (up to version 17) via Jabel, while still targeting JVM 8.
# See https://github.com/bsideup/jabel for details on how this works.
enableModernJavaSyntax = false
enableModernJavaSyntax = true

# Enables injecting missing generics into the decompiled source code for a better coding experience.
# Turns most publicly visible List, Map, etc. into proper List<E>, Map<K, V> types.
enableGenericInjection = false
enableGenericInjection = true

# Generate a class with a String field for the mod version named as defined below.
# If generateGradleTokenClass is empty or not missing, no such class will be generated.
# If gradleTokenVersion is empty or missing, the field will not be present in the class.
generateGradleTokenClass =
generateGradleTokenClass = lumien.custommainmenu.Tags

# Name of the token containing the project's current version to generate/replace.
gradleTokenVersion = GRADLETOKEN_VERSION

# [DEPRECATED] Mod ID replacement token.
gradleTokenModId =

# [DEPRECATED] Mod name replacement token.
gradleTokenModName =
gradleTokenVersion = VERSION

# [DEPRECATED]
# Multiple source files can be defined here by providing a comma-separated list: Class1.java,Class2.java,Class3.java
# public static final String VERSION = "GRADLETOKEN_VERSION";
# The string's content will be replaced with your mod's version when compiled. You should use this to specify your mod's
# version in @Mod([...], version = VERSION, [...]).
# Leave these properties empty to skip individual token replacements.
replaceGradleTokenInFile = CustomMainMenu.java
# replaceGradleTokenInFile =

# In case your mod provides an API for other mods to implement you may declare its package here. Otherwise, you can
# leave this property empty.
Expand Down Expand Up @@ -123,7 +117,7 @@ includeWellKnownRepositories = true
usesMavenPublishing = true

# Maven repository to publish the mod to.
# mavenPublishUrl = https://nexus.gtnewhorizons.com/repository/releases/
# mavenPublishUrl = https\://nexus.gtnewhorizons.com/repository/releases/

# Publishing to Modrinth requires you to set the MODRINTH_TOKEN environment variable to your current Modrinth API token.
#
Expand Down Expand Up @@ -187,5 +181,3 @@ curseForgeRelations =
# This is meant to be set in $HOME/.gradle/gradle.properties.
# ideaCheckSpotlessOnBuild = true

# Non-GTNH properties
gradleTokenGroupName =
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pluginManagement {
}

plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.8'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.16'
}


13 changes: 4 additions & 9 deletions src/main/java/lumien/custommainmenu/CustomMainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
import lumien.custommainmenu.configuration.ConfigurationLoader;
import lumien.custommainmenu.handler.CMMEventHandler;

@Mod(modid = CustomMainMenu.MOD_ID, name = CustomMainMenu.MOD_NAME, version = CustomMainMenu.MOD_VERSION)
@Mod(modid = CustomMainMenu.MOD_ID, name = CustomMainMenu.MOD_NAME, version = Tags.VERSION)
public class CustomMainMenu {

public static final String MOD_ID = "custommainmenu";
public static final String MOD_NAME = "Custom Main Menu";
public static final String MOD_VERSION = "GRADLETOKEN_VERSION";

@Mod.Instance(value = CustomMainMenu.MOD_ID)
public static CustomMainMenu INSTANCE;
Expand All @@ -46,8 +45,8 @@ public void preInit(FMLPreInitializationEvent event) {
this.config = new Config();
transparentTexture = new ResourceLocation("custommainmenu:textures/gui/transparent.png");
EVENT_HANDLER = new CMMEventHandler();
MinecraftForge.EVENT_BUS.register((Object) EVENT_HANDLER);
FMLCommonHandler.instance().bus().register((Object) EVENT_HANDLER);
MinecraftForge.EVENT_BUS.register(EVENT_HANDLER);
FMLCommonHandler.instance().bus().register(EVENT_HANDLER);
this.logger = event.getModLog();
this.configLoader = new ConfigurationLoader(this.config);
try {
Expand All @@ -64,11 +63,7 @@ public void postInit(FMLPostInitializationEvent event) {
compound.setString("curseProjectName", "226406-custom-main-menu");
compound.setString("curseFilenameParser", "CustomMainMenu-MC1.8-[].jar");
compound.setString("modDisplayName", MOD_NAME);
FMLInterModComms.sendRuntimeMessage(
(Object) MOD_ID,
(String) "VersionChecker",
(String) "addCurseCheck",
(NBTTagCompound) compound);
FMLInterModComms.sendRuntimeMessage(MOD_ID, "VersionChecker", "addCurseCheck", compound);
}

public void reload() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public class Alignment {

public float factorX;
public float factorY;
public final float factorX;
public final float factorY;

public Alignment(float factorX, float factorY) {
this.factorX = factorX;
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/lumien/custommainmenu/configuration/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@

public class Config {

HashMap<String, GuiEntry> guis = new HashMap();
final HashMap<String, GuiEntry> guis = new HashMap<>();

public void addGui(String name, GuiCustom gc) {
int scale;
GuiEntry entry = this.guis.get(name);
if (entry == null) {
entry = new GuiEntry();
this.guis.put(name, entry);
}
GuiEntry entry = this.guis.computeIfAbsent(name, k -> new GuiEntry());
if ((scale = gc.guiConfig.guiScale) == -1) {
entry.standard = gc;
} else if (scale == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;

import org.apache.commons.io.IOUtils;

Expand All @@ -22,13 +20,13 @@

public class ConfigurationLoader {

Config config;
final Config config;

public ConfigurationLoader(Config config) {
this.config = config;
}

public void load() throws Exception {
public void load() {
JsonReader reader;
File[] jsonFiles;
JsonObject jsonObject;
Expand All @@ -47,26 +45,22 @@ public void load() throws Exception {
try {
output = new FileOutputStream(mainmenuConfig);
input = this.getClass().getResourceAsStream("/assets/custommainmenu/mainmenu_default.json");
ByteStreams.copy((InputStream) input, (OutputStream) output);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
IOUtils.closeQuietly((OutputStream) output);
IOUtils.closeQuietly(input);
ByteStreams.copy(input, output);
} catch (IOException e) {
e.printStackTrace();
IOUtils.closeQuietly((OutputStream) output);
IOUtils.closeQuietly(output);
IOUtils.closeQuietly(input);
}
IOUtils.closeQuietly((OutputStream) output);
IOUtils.closeQuietly((InputStream) input);
IOUtils.closeQuietly(output);
IOUtils.closeQuietly(input);
}
for (File guiFile : jsonFiles = configFolder.listFiles()) {
if (!guiFile.getName().equals("mainmenu.json")) continue;
guiConfig = new GuiConfig();
name = guiFile.getName().replace(".json", "");
reader = null;
try {
reader = new JsonReader((Reader) new FileReader(guiFile));
reader = new JsonReader(new FileReader(guiFile));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Expand All @@ -90,18 +84,13 @@ public void load() throws Exception {
}
this.config.addGui(guiConfig.name, new GuiCustom(guiConfig));
}
File[] arr$ = jsonFiles;
int len$ = arr$.length;
int i$ = 0;
while (i$ < len$) {
File guiFile;
guiFile = arr$[i$];
for (File guiFile : jsonFiles) {
if (!guiFile.getName().equals("mainmenu.json") && guiFile.getName().endsWith(".json")) {
guiConfig = new GuiConfig();
name = guiFile.getName().replace(".json", "");
reader = null;
try {
reader = new JsonReader((Reader) new FileReader(guiFile));
reader = new JsonReader(new FileReader(guiFile));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Expand All @@ -125,7 +114,6 @@ public void load() throws Exception {
}
this.config.addGui(guiConfig.name, new GuiCustom(guiConfig));
}
++i$;
}
}
}
38 changes: 19 additions & 19 deletions src/main/java/lumien/custommainmenu/configuration/GuiConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public void load(String name, JsonObject jsonObject) {
}
this.name = name;
this.loadAlignments(jsonObject);
this.customTexts = new ArrayList();
this.customImages = new ArrayList();
this.customButtons = new ArrayList();
this.customTexts = new ArrayList<>();
this.customImages = new ArrayList<>();
this.customButtons = new ArrayList<>();
this.splashText = null;
this.panorama = null;
this.background = null;
Expand All @@ -80,7 +80,7 @@ public void load(String name, JsonObject jsonObject) {
}

private void loadAlignments(JsonObject jsonObject) {
this.alignments = new HashMap();
this.alignments = new HashMap<>();
this.alignments.put("bottom_left", new Alignment(0.0f, 1.0f));
this.alignments.put("top_left", new Alignment(0.0f, 0.0f));
this.alignments.put("top_right", new Alignment(1.0f, 0.0f));
Expand All @@ -94,8 +94,8 @@ private void loadAlignments(JsonObject jsonObject) {
if (jsonObject.has("alignments")) {
JsonObject alignmentObject = (JsonObject) jsonObject.get("alignments");
Set<Map.Entry<String, JsonElement>> buttons = alignmentObject.entrySet();
for (Map.Entry entry : buttons) {
String name = (String) entry.getKey();
for (Map.Entry<String, JsonElement> entry : buttons) {
String name = entry.getKey();
JsonObject object = (JsonObject) entry.getValue();
Alignment a = new Alignment(
object.get("factorWidth").getAsFloat(),
Expand Down Expand Up @@ -205,31 +205,31 @@ private void loadOthers(JsonObject jsonObject) {
private void loadImages(JsonObject jsonObject) {
JsonObject textElements = jsonObject.get("images").getAsJsonObject();
Set<Map.Entry<String, JsonElement>> images = textElements.entrySet();
for (Map.Entry entry : images) {
String name = (String) entry.getKey();
JsonElement element = (JsonElement) entry.getValue();
for (Map.Entry<String, JsonElement> entry : images) {
String name = entry.getKey();
JsonElement element = entry.getValue();
this.customImages.add(this.getImage((JsonObject) element));
}
}

private void loadTexts(JsonObject jsonObject) {
JsonObject textElements = jsonObject.get("texts").getAsJsonObject();
Set<Map.Entry<String, JsonElement>> texts = textElements.entrySet();
for (Map.Entry entry : texts) {
String name = (String) entry.getKey();
JsonElement element = (JsonElement) entry.getValue();
for (Map.Entry<String, JsonElement> entry : texts) {
String name = entry.getKey();
JsonElement element = entry.getValue();
this.customTexts.add(this.getText(name, (JsonObject) element));
}
}

private void loadButtons(JsonObject jsonObject) {
JsonObject buttonElements = jsonObject.get("buttons").getAsJsonObject();
Set<Map.Entry<String, JsonElement>> buttons = buttonElements.entrySet();
for (Map.Entry entry : buttons) {
String name = (String) entry.getKey();
for (Map.Entry<String, JsonElement> entry : buttons) {
String name = entry.getKey();
JsonObject object = (JsonObject) entry.getValue();
Button b = this.getButton(object);
b.name = (String) entry.getKey();
b.name = entry.getKey();
this.customButtons.add(b);
}
}
Expand Down Expand Up @@ -370,13 +370,13 @@ private String getStringPlease(JsonElement jsonElement) {
JsonArray array = jsonElement.getAsJsonArray();
return array.get(rng.nextInt(array.size())).getAsString();
}
CustomMainMenu.INSTANCE.logger.log(Level.ERROR, "Error getting random value out of " + jsonElement.toString());
CustomMainMenu.INSTANCE.logger.log(Level.ERROR, "Error getting random value out of " + jsonElement);
return "ERROR";
}

public static ITexture getWantedTexture(String textureString) {
if (textureString.startsWith("web:")) {
String url = textureString.substring(4, textureString.length());
String url = textureString.substring(4);
return new TextureURL(url);
}
return new TextureResourceLocation(textureString);
Expand Down Expand Up @@ -419,11 +419,11 @@ public Alignment getAlignment(String name) {

public static IText getWantedText(String textString) {
if (textString.startsWith("web:")) {
String url = textString.substring(4, textString.length());
String url = textString.substring(4);
return new TextURL(url);
}
if (textString.startsWith("file:")) {
String resource = textString.substring(5, textString.length());
String resource = textString.substring(5);
return new TextResourceLocation(resource);
}
return new TextString(textString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class Background extends Element {

public ITexture image;
public final ITexture image;
public MODE mode;
public boolean ichBinEineSlideshow;
public Slideshow slideShow;
Expand All @@ -24,10 +24,10 @@ public void setMode(String newMode) {
this.mode = MODE.valueOf(newMode.toUpperCase(Locale.US));
}

public static enum MODE {
public enum MODE {
FILL,
STRETCH,
CENTER,
TILE;
TILE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public class Button extends Element {
public IAction action;
public IText tooltip;
public Alignment alignment;
public int posX;
public int posY;
public int width;
public int height;
public final int posX;
public final int posY;
public final int width;
public final int height;
public int imageWidth;
public int imageHeight;
public ITexture texture;
Expand Down
Loading

0 comments on commit e0a8b6f

Please sign in to comment.