Java Code Examples for net.minecraft.world.World#setWorldTime()

The following examples show how to use net.minecraft.world.World#setWorldTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServerStateMachine.java    From malmo with MIT License 4 votes vote down vote up
@Override
protected void execute()
{
    // Set up some initial conditions:
    ServerSection ss = currentMissionInit().getMission().getServerSection();
    ServerInitialConditions sic = (ss != null) ? ss.getServerInitialConditions() : null;
    if (sic != null && sic.getTime() != null)
    {
        boolean allowTimeToPass = (sic.getTime().isAllowPassageOfTime() != Boolean.FALSE);  // Defaults to true if unspecified.
        MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
        if (server.worlds != null && server.worlds.length != 0)
        {
            for (int i = 0; i < server.worlds.length; ++i)
            {
                World world = server.worlds[i];
                world.getGameRules().setOrCreateGameRule("doDaylightCycle", allowTimeToPass ? "true" : "false");
                if (sic.getTime().getStartTime() != null)
                    world.setWorldTime(sic.getTime().getStartTime());
            }
        }
    }
    ModSettings modsettings = currentMissionInit().getMission().getModSettings();
    if (modsettings != null && modsettings.getMsPerTick() != null)
        TimeHelper.serverTickLength = (long)(modsettings.getMsPerTick());
        
    if (getHandlers().quitProducer != null)
        getHandlers().quitProducer.prepare(currentMissionInit());

    if (getHandlers().worldDecorator != null)
        getHandlers().worldDecorator.prepare(currentMissionInit());

    // Fire the starting pistol:
    MalmoMod.safeSendToAll(MalmoMessageType.SERVER_GO);
    // And start the turn schedule turning, if there is one:
    if (!ServerStateMachine.this.userTurnSchedule.isEmpty())
    {
        String agentName = ServerStateMachine.this.userTurnSchedule.get(0);
        PlayerList scoman = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList();
        EntityPlayerMP player = scoman.getPlayerByUsername(agentName);
        if (player != null)
        {
            MalmoMod.network.sendTo(new MalmoMod.MalmoMessage(MalmoMessageType.SERVER_YOUR_TURN, ""), player);
        }
        else if (getHandlers().worldDecorator != null)
        {
            // Not a player - is it a world decorator?
            getHandlers().worldDecorator.targetedUpdate(agentName);
        }
    }
}