summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2014-11-03 20:00:46 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2014-11-03 20:00:46 +0000
commit58a62299851576f00421e4f20acac8c7e684e8a7 (patch)
tree65229c4017e203c45cca5adc8720a3e376a460ba
parent08470bb534c4faf8b449d613271166d07542f0fe (diff)
downloadnoctis-58a62299851576f00421e4f20acac8c7e684e8a7.tar.bz2
Try and fix time command
-rw-r--r--src/main/java/net/flarn/noctis/Noctis.java2
-rw-r--r--src/main/java/net/flarn/noctis/commands/CommandTimeFixed.java40
2 files changed, 42 insertions, 0 deletions
diff --git a/src/main/java/net/flarn/noctis/Noctis.java b/src/main/java/net/flarn/noctis/Noctis.java
index 383d608..403130e 100644
--- a/src/main/java/net/flarn/noctis/Noctis.java
+++ b/src/main/java/net/flarn/noctis/Noctis.java
@@ -9,6 +9,7 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.relauncher.Side;
import net.flarn.noctis.client.gui.GuiHandler;
+import net.flarn.noctis.commands.CommandTimeFixed;
import net.flarn.noctis.handler.ConfigHandler;
import net.flarn.noctis.handler.PlayerHandler;
import net.flarn.noctis.init.ModItems;
@@ -45,6 +46,7 @@ public class Noctis {
Recipes.init();
Recipes.initCatalysedRecipes();
NetworkRegistry.INSTANCE.registerGuiHandler(Noctis.instance, new GuiHandler());
+ CommandTimeFixed.registerReplacementCommand();
}
@Mod.EventHandler
diff --git a/src/main/java/net/flarn/noctis/commands/CommandTimeFixed.java b/src/main/java/net/flarn/noctis/commands/CommandTimeFixed.java
new file mode 100644
index 0000000..cd5df63
--- /dev/null
+++ b/src/main/java/net/flarn/noctis/commands/CommandTimeFixed.java
@@ -0,0 +1,40 @@
+package net.flarn.noctis.commands;
+
+
+import cpw.mods.fml.common.FMLCommonHandler;
+import net.flarn.noctis.refs.Numbers;
+import net.flarn.noctis.utils.LogHelper;
+import net.minecraft.command.CommandHandler;
+import net.minecraft.command.CommandTime;
+import net.minecraft.command.ICommandSender;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.world.WorldServer;
+
+public class CommandTimeFixed extends CommandTime {
+ /**
+ * Set the time in the server object.
+ */
+ @Override
+ protected void setTime(ICommandSender p_71552_1_, int p_71552_2_)
+ {
+ for (int j = 0; j < MinecraftServer.getServer().worldServers.length; ++j)
+ {
+ WorldServer ws = MinecraftServer.getServer().worldServers[j];
+ long curTime = ws.getWorldTime();
+ long curDayTime = curTime % Numbers.TICKS_PER_DAY;
+ long targDayTime = p_71552_2_ % Numbers.TICKS_PER_DAY;
+ long diffTime = ((targDayTime - curDayTime) + Numbers.TICKS_PER_DAY) % Numbers.TICKS_PER_DAY;
+ ws.setWorldTime(curTime + diffTime);
+ }
+ }
+
+ public static void registerReplacementCommand() {
+ CommandHandler cm = (CommandHandler)FMLCommonHandler.instance().getMinecraftServerInstance().getCommandManager();
+ if (cm == null) {
+ LogHelper.warn("Unable to register replacement time command, server does not have usable command manager.");
+ } else {
+ cm.registerCommand(new CommandTimeFixed());
+ }
+ }
+
+}