Skip to content

Commit

Permalink
Added timer command
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollointhehouse committed Nov 6, 2023
1 parent 9da1290 commit 07f51c9
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 38 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 21 additions & 0 deletions src/main/java/apollointhehouse/timercommand/Main.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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 <set, get> <tps>");
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
16 changes: 0 additions & 16 deletions src/main/java/turniplabs/examplemod/ExampleMod.java

This file was deleted.

13 changes: 0 additions & 13 deletions src/main/resources/examplemod.mixins.json

This file was deleted.

12 changes: 6 additions & 6 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -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": "",
Expand All @@ -18,11 +18,11 @@
"environment": "*",
"entrypoints": {
"main": [
"turniplabs.examplemod.ExampleMod"
"apollointhehouse.timercommand.Main"
]
},
"mixins": [
"examplemod.mixins.json"
"timercommand.mixins.json"
],

"depends": {
Expand Down
Empty file.
12 changes: 12 additions & 0 deletions src/main/resources/timercommand.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"required": true,
"minVersion": "0.8",
"package": "apollointhehouse.timercommand.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"MinecraftAccessor"
],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit 07f51c9

Please # to comment.