diff --git a/gradle.properties b/gradle.properties index 14d8321..59a9e59 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,6 +10,6 @@ loader_version=0.14.19-babric.1-bta halplibe_version=2.4.0 # Mod -mod_version=1.0.0 -mod_group=turniplabs -mod_name=examplemod +mod_version=1.0.1 +mod_group=apollointhehouse +mod_name=TimerCommand diff --git a/src/main/java/apollointhehouse/timercommand/Main.java b/src/main/java/apollointhehouse/timercommand/Main.java new file mode 100644 index 0000000..17073e2 --- /dev/null +++ b/src/main/java/apollointhehouse/timercommand/Main.java @@ -0,0 +1,21 @@ +package apollointhehouse.timercommand; + +import apollointhehouse.timercommand.commands.TimerCommand; +import net.fabricmc.api.ModInitializer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import turniplabs.halplibe.helper.CommandHelper; + + +public class Main implements ModInitializer { + public static final String MOD_ID = "timercommand"; + public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); + + @Override + public void onInitialize() { + LOGGER.info("TimerCommand initialized."); + + // Register commands + CommandHelper.createCommand(new TimerCommand()); + } +} diff --git a/src/main/java/apollointhehouse/timercommand/commands/TimerCommand.java b/src/main/java/apollointhehouse/timercommand/commands/TimerCommand.java new file mode 100644 index 0000000..2a4ac73 --- /dev/null +++ b/src/main/java/apollointhehouse/timercommand/commands/TimerCommand.java @@ -0,0 +1,51 @@ +package apollointhehouse.timercommand.commands; + +import apollointhehouse.timercommand.mixin.MinecraftAccessor; +import net.minecraft.client.Minecraft; +import net.minecraft.core.Timer; +import net.minecraft.core.net.command.Command; +import net.minecraft.core.net.command.CommandHandler; +import net.minecraft.core.net.command.CommandSender; + +public class TimerCommand extends Command { + public TimerCommand() { + super("timer"); + } + + @Override + public boolean execute(CommandHandler commandHandler, CommandSender commandSender, String[] strings) { + Minecraft mc = Minecraft.getMinecraft(Minecraft.class); + Timer timer = ((MinecraftAccessor) mc).getTimer(); + + if (strings.length < 1) return false; + + if (strings[0].equals("get")) { + commandHandler.sendCommandFeedback(commandSender, "Current TPS: " + timer.ticksPerSecond); + return true; + } + + if (strings[0].equals("set") && strings.length >= 2) { + try { + float tps = Float.parseFloat(strings[1]); + timer.ticksPerSecond = tps; + commandHandler.sendCommandFeedback(commandSender, "Set TPS to " + tps); + } catch (NumberFormatException e) { + commandHandler.sendCommandFeedback(commandSender, "Invalid TPS: " + strings[1] + ", TPS must be a float."); + return false; + } + return true; + } + + return false; + } + + @Override + public boolean opRequired(String[] strings) { + return true; + } + + @Override + public void sendCommandSyntax(CommandHandler commandHandler, CommandSender commandSender) { + commandHandler.sendCommandFeedback(commandSender, "/timer "); + } +} diff --git a/src/main/java/apollointhehouse/timercommand/mixin/MinecraftAccessor.java b/src/main/java/apollointhehouse/timercommand/mixin/MinecraftAccessor.java new file mode 100644 index 0000000..0174376 --- /dev/null +++ b/src/main/java/apollointhehouse/timercommand/mixin/MinecraftAccessor.java @@ -0,0 +1,12 @@ +package apollointhehouse.timercommand.mixin; + +import net.minecraft.client.Minecraft; +import net.minecraft.core.Timer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(value = Minecraft.class, remap = false) +public interface MinecraftAccessor { + @Accessor("timer") + Timer getTimer(); +} diff --git a/src/main/java/turniplabs/examplemod/ExampleMod.java b/src/main/java/turniplabs/examplemod/ExampleMod.java deleted file mode 100644 index eb07098..0000000 --- a/src/main/java/turniplabs/examplemod/ExampleMod.java +++ /dev/null @@ -1,16 +0,0 @@ -package turniplabs.examplemod; - -import net.fabricmc.api.ModInitializer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -public class ExampleMod implements ModInitializer { - public static final String MOD_ID = "examplemod"; - public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); - - @Override - public void onInitialize() { - LOGGER.info("ExampleMod initialized."); - } -} diff --git a/src/main/resources/examplemod.mixins.json b/src/main/resources/examplemod.mixins.json deleted file mode 100644 index e98223c..0000000 --- a/src/main/resources/examplemod.mixins.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "turniplabs.examplemod.mixin", - "compatibilityLevel": "JAVA_8", - "mixins": [ - ], - "client": [ - ], - "injectors": { - "defaultRequire": 1 - } -} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index c93d2bc..82b62ba 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,12 +1,12 @@ { "schemaVersion": 1, - "id": "examplemod", + "id": "timercommand", "version": "${version}", - "name": "Example Mod", - "description": "This mod aims to help new BTA modders.", + "name": "TimerCommand", + "description": "Allows you to set the games TPS with /timer or /tps.", "authors": [ - "Turnip Labs" + "Apollointhehouse" ], "contact": { "homepage": "", @@ -18,11 +18,11 @@ "environment": "*", "entrypoints": { "main": [ - "turniplabs.examplemod.ExampleMod" + "apollointhehouse.timercommand.Main" ] }, "mixins": [ - "examplemod.mixins.json" + "timercommand.mixins.json" ], "depends": { diff --git a/src/main/resources/lang/examplemod/en_US.lang b/src/main/resources/lang/examplemod/en_US.lang deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/resources/timercommand.mixins.json b/src/main/resources/timercommand.mixins.json new file mode 100644 index 0000000..5362b40 --- /dev/null +++ b/src/main/resources/timercommand.mixins.json @@ -0,0 +1,12 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "apollointhehouse.timercommand.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "MinecraftAccessor" + ], + "injectors": { + "defaultRequire": 1 + } +}