Alright so I've been messing around with ModLoader for the first time, just to see if it was possible to do something with it that I've done before without it but easier (Turns out the answer to that is yes, keybinding is 100% easier with ModLoader).
I'm having the issue though that sometimes the onTickInGame that I'm using seems to be called too fast, messing things up. This has been happening especially if I'm swimming, drowning, or other similar events.
Following is the entirety of my code. Literally, all of it.
net.minecraft.src;
import net.minecraft.client.Minecraft;
public class mod_TimeControl extends BaseMod {
public KeyBinding timeBackward = new KeyBinding("timeBackward", 12);
public KeyBinding timeForward = new KeyBinding("timeForward", 13);
public long timeChange;
long time;
public mod_TimeControl()
{
ModLoader.registerKey(this, timeBackward, false);
ModLoader.registerKey(this, timeForward, false);
ModLoader.addLocalization("timeBackward", "Time Backwards");
ModLoader.addLocalization("timeForward", "Time Forwards");
ModLoader.setInGameHook(this, true, true);
player = ModLoader.getMinecraftInstance().thePlayer;
timeChange = 100;
}
public boolean onTickInGame(float tick, Minecraft game){
World world = game.theWorld;
time = world.getWorldTime();
if(timeBackward.pressed){
if((time - timeChange) >= 0){
world.setWorldTime(time - timeChange);
}else{
world.setWorldTime(23999);
}
}
if(timeForward.pressed){
if((time + timeChange) <= 23999){
world.setWorldTime(time + timeChange);
}else{
world.setWorldTime(0);
}
}
return true;
}
@Override
public String getVersion() {
// TODO Auto-generated method stub
return null;
}
@Override
public void load() {
// TODO Auto-generated method stub
}
}
Yes I do need to set some stuff yet, but I'm just trying to make this work. In case you care to know, what this code does is changes time by pressing + or -.
P.s. This is the first time I have ever used ModLoader. Just a mention.
EDIT: Another mention: I do need the onTickInGame to be continually run, simply so that you can hold plus or minus to continually increase/decrease world time. If there is another function similar to this that would work as well, I'd love to know.
This causes onTickInGame to be called for every frame update, therefore it will be analogous to your framerate and not a constant value.
Replacing that with this will call onTickInGame according to game logic updates, that is, 20 times per second, a more constant value that is also slower than many FPS values.
I'm having the issue though that sometimes the onTickInGame that I'm using seems to be called too fast, messing things up. This has been happening especially if I'm swimming, drowning, or other similar events.
Following is the entirety of my code. Literally, all of it.
Yes I do need to set some stuff yet, but I'm just trying to make this work. In case you care to know, what this code does is changes time by pressing + or -.
P.s. This is the first time I have ever used ModLoader. Just a mention.
EDIT: Another mention: I do need the onTickInGame to be continually run, simply so that you can hold plus or minus to continually increase/decrease world time. If there is another function similar to this that would work as well, I'd love to know.
Which is the better way to do it:
or
I'm pretty sure that onTickInGame() always runs at the same speed, and doesn't depend on weather you are swimming/drowning or not.
This causes onTickInGame to be called for every frame update, therefore it will be analogous to your framerate and not a constant value.
Replacing that with this will call onTickInGame according to game logic updates, that is, 20 times per second, a more constant value that is also slower than many FPS values.