net.minecraftforge.fml.common.gameevent.TickEvent.ServerTickEvent Java Examples

The following examples show how to use net.minecraftforge.fml.common.gameevent.TickEvent.ServerTickEvent. 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: TickHandler.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public void onServerTick(ServerTickEvent event)
{
    if (event.phase == TickEvent.Phase.END)
    {
        return;
    }

    // Once every second
    if (++this.serverTickCounter >= 20)
    {
        this.serverTickCounter = 0;

        ChunkLoading.getInstance().tickChunkTimeouts();
    }

    // This is currently only used for debug tasks, so let's disable it normally
    //TaskScheduler.getInstance().runTasks();

    this.teleportPlayers();
    ++this.playerTickCounter;
}
 
Example #2
Source File: ClientStateMachine.java    From malmo with MIT License 5 votes vote down vote up
@Override
protected void onServerTick(ServerTickEvent ev)
{
    if (this.worldCreated && !this.serverStarted)
    {
        // The server has started ticking - we can set up its state machine,
        // and move on to the next state in our own machine.
        this.serverStarted = true;
        MalmoMod.instance.initIntegratedServer(currentMissionInit()); // Needs to be done from the server thread.
        episodeHasCompleted(ClientState.WAITING_FOR_SERVER_READY);
    }
}
 
Example #3
Source File: ServerStateMachine.java    From malmo with MIT License 5 votes vote down vote up
@Override
protected void onServerTick(TickEvent.ServerTickEvent ev)
{
    try
    {
        checkForMissionCommand();
    }
    catch (Exception e)
    {
        // TODO: What now?
        e.printStackTrace();
    }
}
 
Example #4
Source File: ServerStateMachine.java    From malmo with MIT License 5 votes vote down vote up
@Override
protected void onServerTick(ServerTickEvent ev)
{
    if (!ServerStateMachine.this.checkWatchList())
    {
        // Something has gone wrong - we've lost a connection.
        // Need to respond to this, otherwise we'll sit here forever waiting for a client that no longer exists
        // to tell us it's finished its mission.
        MalmoMod.safeSendToAll(MalmoMessageType.SERVER_ABORT);
        episodeHasCompleted(ServerState.ERROR);
    }
}
 
Example #5
Source File: EventHandler.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onPostServerTick(ServerTickEvent event){
    if(event.phase == Phase.END) {
        RailNetworkManager.getServerInstance().onPostServerTick();
        ChunkLoadManager.INSTANCE.update();
    }
}
 
Example #6
Source File: StateEpisode.java    From malmo with MIT License 4 votes vote down vote up
/** Subclass should overrride this to act on server ticks.*/
protected void onServerTick(ServerTickEvent ev) {}
 
Example #7
Source File: ServerStateMachine.java    From malmo with MIT License 4 votes vote down vote up
@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent ev)
{
    // Use the server tick to ensure we regularly update our state (from the server thread)
    updateState();
}
 
Example #8
Source File: ServerStateMachine.java    From malmo with MIT License 4 votes vote down vote up
@Override
protected void onServerTick(ServerTickEvent ev)
{
    // We wait until we start to get server ticks, at which point we assume Minecraft has finished starting up.
    episodeHasCompleted(ServerState.DORMANT);
}
 
Example #9
Source File: ServerStateMachine.java    From malmo with MIT License 4 votes vote down vote up
@Override
protected void onServerTick(ServerTickEvent ev)
{
    if (!ServerStateMachine.this.checkWatchList())
        onError(null);  // We've lost a connection - abort the mission.
}
 
Example #10
Source File: ServerStateMachine.java    From malmo with MIT License 4 votes vote down vote up
@Override
protected void onServerTick(ServerTickEvent ev)
{
    if (this.missionHasEnded)
        return;	// In case we get in here after deciding the mission is over.
    
    if (!ServerStateMachine.this.checkWatchList())
        onError(null);  // We've lost a connection - abort the mission.

    if (ev.phase == Phase.START)
    {
        // Measure our performance - especially useful if we've been overclocked.
        if (this.secondStartTimeMs == 0)
            this.secondStartTimeMs = System.currentTimeMillis();

        long timeNow = System.currentTimeMillis();
        if (timeNow - this.secondStartTimeMs > 1000)
        {
            long targetTicks = 1000 / TimeHelper.serverTickLength;
            if (this.tickCount < targetTicks)
                System.out.println("Warning: managed " + this.tickCount + "/" + targetTicks + " ticks this second.");
            this.secondStartTimeMs = timeNow;
            this.tickCount = 0;
        }
        this.tickCount++;
    }

	MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();

    if (ev.phase == Phase.END && getHandlers() != null && getHandlers().worldDecorator != null)
    {
        World world = server.getEntityWorld();
        getHandlers().worldDecorator.update(world);
    }

    if (ev.phase == Phase.END)
    {
        if (getHandlers() != null && getHandlers().quitProducer != null && getHandlers().quitProducer.doIWantToQuit(currentMissionInit()))
        {
            ServerStateMachine.this.quitCode = getHandlers().quitProducer.getOutcome();
            onMissionEnded(true);
        }
        else if (this.runningAgents.isEmpty())
        {
            ServerStateMachine.this.quitCode = "All agents finished";
            onMissionEnded(true);
        }
        // We need to make sure we keep the weather within mission parameters.
        // We set the weather just after building the world, but it's not a permanent setting,
        // and apparently there is a known bug in Minecraft that means the weather sometimes changes early.
        // To get around this, we reset it periodically.
        if (server.getTickCounter() % 500 == 0)
        {
            EnvironmentHelper.setMissionWeather(currentMissionInit(), server.getEntityWorld().getWorldInfo());
        }
    }
}
 
Example #11
Source File: EventHandler.java    From Signals with GNU General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void onPreServerTick(ServerTickEvent event){
    if(event.phase == Phase.START) {
        RailNetworkManager.getServerInstance().onPreServerTick();
    }
}