Skip to content
This repository has been archived by the owner on Nov 7, 2022. It is now read-only.

Commit

Permalink
Adds the new translation system and old buttons #29
Browse files Browse the repository at this point in the history
This release replaces the built-in minecraft translation system with a dedicated JSON-based translation system. Similarly, a lot of fat has been trimmed from unused methods and classes. The installer has also been tweaked to ask if you'd like to delete mod files, and if the user agrees it will scan jar files to check if they are the mod instead of just using the name of the file. An attempt has also been made to tweak optifine.
  • Loading branch information
boomboompower committed Dec 22, 2020
1 parent 96b64b9 commit 0d7720e
Show file tree
Hide file tree
Showing 28 changed files with 1,185 additions and 888 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ configurations {
compile.extendsFrom(provided)
}

// For obfuscating the jar file.
task proguard(type: ProGuardTask) {
configuration 'proguard/proguard.txt'

Expand Down
65 changes: 56 additions & 9 deletions src/main/java/wtf/boomy/mods/skinchanger/SkinChangerMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,24 @@

import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.ModMetadata;
import net.minecraftforge.fml.common.event.FMLFingerprintViolationEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import wtf.boomy.apagoge.ApagogeHandler;
import wtf.boomy.mods.skinchanger.commands.impl.SkinCommand;
import wtf.boomy.mods.skinchanger.configuration.ConfigurationHandler;
import wtf.boomy.mods.skinchanger.cosmetic.CosmeticFactory;
import wtf.boomy.mods.skinchanger.cosmetic.impl.SkinChangerStorage;
import wtf.boomy.mods.skinchanger.language.Language;
import wtf.boomy.mods.skinchanger.utils.ChatColor;
import wtf.boomy.mods.skinchanger.utils.backend.CacheRetriever;

Expand Down Expand Up @@ -61,13 +67,16 @@ public class SkinChangerMod {

private File modConfigDirectory;

private final SkinChangerStorage skinChangerStorage;
private final SkinChangerStorage skinChangerStorage = new SkinChangerStorage(this);
private final Logger logger = LogManager.getLogger("SkinChanger - Core");
private final ApagogeHandler apagogeHandler;

// When forge creates a new instance of this class we need
// to also build the storage component of the mod.
/**
* A basic constructor for the mod.
*
* @throws URISyntaxException an exception thrown when Java is unable to locate the code source.
*/
public SkinChangerMod() throws URISyntaxException {
this.skinChangerStorage = new SkinChangerStorage(this);
this.apagogeHandler = new ApagogeHandler(new File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI()), "SkinChanger", SkinChangerMod.VERSION);
}

Expand All @@ -94,14 +103,15 @@ public void init(FMLInitializationEvent event) {
SkinCommand.class,
CacheRetriever.class,
ConfigurationHandler.class,
CosmeticFactory.class
CosmeticFactory.class,
Language.class
);

this.apagogeHandler.addCompletionListener((handler, success) -> {
if (!success) {
System.err.println("Apagoge failed.");
this.logger.error("Apagoge failed.");
} else {
System.err.println("Apagoge succeeded");
this.logger.trace("Apagoge succeeded");
}
});

Expand All @@ -114,18 +124,55 @@ public void postInit(FMLPostInitializationEvent event) {

this.cosmeticFactory = new CosmeticFactory(this);

// Load the translation system!
Language.loadTranslations();

// This forces our patches to be done as the game loads
new NetworkPlayerInfo((GameProfile) null);
}

@Mod.EventHandler
public void onSignatureViolation(FMLFingerprintViolationEvent event) {
System.err.println("Signature violation detected. Killing updater.");
this.logger.warn("Signature violation detected. SkinChanger is NOT running an official release.");
this.logger.warn("This may be a sign the mod has been modified, or a dev build is being ran");
this.logger.warn("The only official place to get SkinChanger safely is from https://mods.boomy.wtf/");
this.logger.warn("or from the github page located at https://github.com/boomboompower/SkinChanger/");

// Deletes updater & all data under it
// Requests the updater to destroy itself.
// Depending on the implementation this can be ignored.
this.apagogeHandler.requestKill();
}

/**
* Version independent event registering. 1.7 does not
* use the same event bus as 1.8 and above.
*
* @param target the object to register events under.
*/
public void registerEvents(Object target) {
// noinspection ConstantConditions
if (ForgeVersion.mcVersion.startsWith("1.7")) {
FMLCommonHandler.instance().bus().register(target);
} else {
MinecraftForge.EVENT_BUS.register(target);
}
}

/**
* Version independent event registering. 1.7 does not
* use the same event bus as 1.8 and above.
*
* @param target the object to deregister events under.
*/
public void unregisterEvents(Object target) {
// noinspection ConstantConditions
if (ForgeVersion.mcVersion.startsWith("1.7")) {
FMLCommonHandler.instance().bus().unregister(target);
} else {
MinecraftForge.EVENT_BUS.unregister(target);
}
}

/**
* Returns the storage container containing the players custom skin, cape and skin type options
*
Expand Down
39 changes: 23 additions & 16 deletions src/main/java/wtf/boomy/mods/skinchanger/commands/ModCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public ModCommand(SkinChangerMod skinChangerMod) {
* @return the message to send this player if {@link net.minecraft.command.WrongUsageException} is
* thrown
*/
@Override
public String getCommandUsage(ICommandSender sender) {
return ChatColor.RED + "Usage: /" + getCommandName();
}
Expand All @@ -68,7 +67,6 @@ public String getCommandUsage(ICommandSender sender) {
*
* @return a never-null list of command aliases.
*/
@Override
public final List<String> getCommandAliases() {
List<String> aliases = getAliases();

Expand Down Expand Up @@ -119,19 +117,6 @@ public final void processCommand(ICommandSender sender, final String[] args) {
}
}

/**
* Used in newer versions of the game.
*
* @param server the minecraft server instance
* @param sender the sender of the command
* @param args the arguments of the command
* @throws CommandException a required throws
*/
public void func_184881_a(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
processCommand(sender, args);
}


/**
* A safer way to execute a command. Errors which occur here will not cause the game to crash.
*
Expand All @@ -155,7 +140,6 @@ public void func_184881_a(MinecraftServer server, ICommandSender sender, String[
*
* @return true if the sender can use this command.
*/
@Override
public boolean canCommandSenderUseCommand(ICommandSender sender) {
return true;
}
Expand Down Expand Up @@ -233,4 +217,27 @@ protected void sendBrandedMessage(String message) {
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new ChatComponentText(
ChatColor.AQUA + "SkinChanger" + ChatColor.GOLD + " > " + ChatColor.GRAY + message));
}

/// ----------------------------------- Compatibility --------------------------------

// For 1.12.2 functionality
public final String getName() {
return getCommandName();
}

public final String getUsage(ICommandSender sender) {
return getCommandUsage(sender);
}

public final void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
processCommand(sender, args);
}

public final boolean checkPermission(MinecraftServer server, ICommandSender sender) {
return true;
}

public final int getRequiredPermissionLevel() {
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
import java.util.List;

/**
* NOTE: This class is temporary and it's methods will eventually be tuned into a new gui.
* The core SkinChanger command
*
* Note: Most of this file will be trimmed for release. A lot of the subcommands exist for debugging only.
*/
public class SkinCommand extends ModCommand {

Expand All @@ -54,7 +56,7 @@ public List<String> getAliases() {

@Override
public void onCommand(ICommandSender sender, String[] args) {
// TODO remove this during production.
// TODO remove this during release.
if (args.length == 1) {
if (args[0].equalsIgnoreCase("reload")) {
this.mainMenu = new SkinChangerMenu();
Expand All @@ -73,10 +75,9 @@ public void onCommand(ICommandSender sender, String[] args) {
if (args[0].equalsIgnoreCase("reset")) {
getMenu().getReflectionOptions().resetPlayer(this.mod.getStorage());

sendBrandedMessage(ChatColor.GREEN + Language.format("skinchanger.phrase.apply"));
sendBrandedMessage(ChatColor.GREEN + Language.format("skinchanger.chat.applied"));

return;
// } else if (args[0].equalsIgnoreCase("skin") || args[0].equalsIgnoreCase("cape")) {
} else if (args[0].equalsIgnoreCase("toggle")) {
if (args.length == 1) {
this.mod.getConfig().setModEnabled(!this.mod.getConfig().isModEnabled());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public class ConfigurationHandler {
@SaveableField(customName = "animationSpeed")
private float animationSpeed = 1;

@SaveableField
private boolean oldButtons = false;

// A bloody hack
private boolean everyoneMe = false;

Expand Down Expand Up @@ -424,6 +427,10 @@ public void setUsingLighting(boolean usingLighting) {
this.usingLighting = usingLighting;
}

public void setOldButtons(boolean oldButtons) {
this.oldButtons = oldButtons;
}

public void setAnimationSpeed(float animationSpeed) {
this.animationSpeed = animationSpeed;
}
Expand All @@ -437,7 +444,11 @@ public boolean isUsingAnimatedCape() {
}

public boolean isUsingLighting() {
return usingLighting;
return this.usingLighting;
}

public boolean isOldButtons() {
return this.oldButtons;
}

public boolean isEveryoneMe() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,6 @@ public class ConfigurationData {

private Object parent; // null for static fields

/**
* Constructor for a serializable field
*
* @param fieldIn the field to load data from
*/
public ConfigurationData(Field fieldIn) {
this(fieldIn, fieldIn.getName(), true);
}

/**
* Constructor for a serializable field
*
* @param fieldIn the field to load data from
* @param saveName the name of the field as it appears in the json
*/
public ConfigurationData(Field fieldIn, String saveName) {
this(fieldIn, saveName, true);
}

/**
* Constructor for a serializable field
*
Expand Down
Loading

0 comments on commit 0d7720e

Please sign in to comment.