Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello.

I'm starting this mod for testing.

I was reading that executing commands with ICommandManager is a bad practice.

 

My mod does only one thing, slower the timer (increasing day/night length).

It's actually working. But I have some questions...

 

  1. Is there a better way to stop the game timer and change it manually instead of execute the game command?
     
  2. When I run the the mod on a server, or just "open lan", I start to see tons of "Server: Added 1 to the time". Is there a way to prevent that?

     
Spoiler

@Mod.EventBusSubscriber
public class Events {
    public static boolean isSet = false;
    public static int tickCounter = 0; 
    
    @SubscribeEvent
    public static void onTick(TickEvent.WorldTickEvent event) {
        tickCounter++;
        if (tickCounter < 70) return;
        
        try {
            tickCounter = 0;
            
            if (event == null) return;
            
            World world = event.world;
            if (world == null) return;
            
            execCommand(world, "/time add 1");
        }catch(Exception ex) {
            System.out.println("swn => event [onTick] fail!");
            System.out.println("       " + ex.getMessage());
        }
    }
    
    @SubscribeEvent
    public static void onWorldLoaded(WorldEvent.Load event)    {
        try {
            if (isSet) return;
            
            if (event == null) return;
            
            World world = event.getWorld();
            if (world == null) return;
            
            execCommand(world, "/gamerule doDaylightCycle false");
        }catch(Exception ex) {
            System.out.println("swn => event [onWorldLoaded] fail!");
            System.out.println("       " + ex.getMessage());
        }
    }
    
    private static void execCommand(World world, String command) {
        if (world.provider.getDimension() != 0) return;
        if (world.isRemote) return;
    
        MinecraftServer server = world.getMinecraftServer();
        ICommandManager cmd = server.getCommandManager();
        cmd.executeCommand(server, command);
    }
}

 

Edited by sworn

To quote myself from a similar post

On 2017-04-01 at 0:17 PM, Matryoshika said:

You need to create a custom WorldProvider, and override calculateCelestialAngle.
Then you need to register said WorldProvider to the wanted dimension(s), by calling DimensionManager#unregisterDimension(id) and then re-registering it with DimensionManager#registerDimension(id, DimensionType#register(...))

Though I would iterate over the worlds, and check their WorldProvider's first, and only change if the WorldProvider is an instanceof the overworld's WorldProvider, as some dimensions have "frozen" time, etc.

calculateCelestialAngle is the method Minecraft uses to figure out time for the WorldProvider's associated dimension.
If you override it, you can make it state whatever time you want.

Edited by Matryoshika

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.