generated from Turnip-Labs/bta-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9da1290
commit 07f51c9
Showing
9 changed files
with
105 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/apollointhehouse/timercommand/commands/TimerCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>"); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/apollointhehouse/timercommand/mixin/MinecraftAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |