侧边栏壁纸
  • 累计撰写 781 篇文章
  • 累计创建 1 个标签
  • 累计收到 1 条评论
标签搜索
MC

Tick

Dettan
2021-07-10 / 0 评论 / 0 点赞 / 100 阅读 / 2,194 字
温馨提示:
本文最后更新于 2022-04-30,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。
C:\JAVA\MC\minecolonies\src\main\java\com\minecolonies\coremod\event\FMLEventHandler.java
这个东西 订阅所有tick事件
package com.minecolonies.coremod.event;

import com.minecolonies.api.colony.IColonyManager;
import com.minecolonies.coremod.Network;
import com.minecolonies.coremod.commands.EntryPoint;
import com.minecolonies.coremod.entity.pathfinding.Pathfinding;
import com.minecolonies.coremod.network.messages.client.ColonyStylesMessage;
import com.minecolonies.coremod.network.messages.client.ServerUUIDMessage;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.event.server.FMLServerStoppingEvent;
import org.jetbrains.annotations.NotNull;

/**

  • Event handler used to catch various forge events.
    */
    public class FMLEventHandler
    {
    @SubscribeEvent
    public static void onServerTick(final TickEvent.ServerTickEvent event)
    {
    IColonyManager.getInstance().onServerTick(event);
    }

    @SubscribeEvent
    public static void onClientTick(final TickEvent.ClientTickEvent event)
    {
    IColonyManager.getInstance().onClientTick(event);
    }

    @SubscribeEvent
    public static void onWorldTick(final TickEvent.WorldTickEvent event)
    {
    //只有在world被加载后才会调用, 只用来调用colony的状态机的tick()
    IColonyManager.getInstance().onWorldTick(event);
    }

    @SubscribeEvent
    public static void onPlayerLogin(@NotNull final PlayerEvent.PlayerLoggedInEvent event)
    {
    if (event.getPlayer() instanceof ServerPlayerEntity)
    {
    Network.getNetwork().sendToPlayer(new ServerUUIDMessage(), (ServerPlayerEntity) event.getPlayer());
    Network.getNetwork().sendToPlayer(new ColonyStylesMessage(), (ServerPlayerEntity) event.getPlayer());

         // This automatically reloads the owner of the colony if failed.
         IColonyManager.getInstance().getIColonyByOwner(((ServerPlayerEntity) event.getPlayer()).getServerWorld(), event.getPlayer());
         //ColonyManager.syncAllColoniesAchievements();
     }
    

    }

    @SubscribeEvent
    public static void onServerStarting(final FMLServerStartingEvent event)
    {
    EntryPoint.register(event.getCommandDispatcher());
    }

    @SubscribeEvent
    public static void onServerStopped(final FMLServerStoppingEvent event)
    {
    Pathfinding.shutdown();
    }

}

0

评论区