@SubscribeEvent
  public void onServerTick(TickEvent.WorldTickEvent event) {
    if (FMLCommonHandler.instance().getMinecraftServerInstance() == null
        || event.phase == TickEvent.Phase.END
        || event.world.provider.getDimensionId() != 0) return;

    if (MechnicalNetworkManager.getNetworkManagerForWorld(event.world) == null) {

      VCraftWorldSavedData worlddata = getOrCreateWorldData(event.world);
      worlddata.setWorld(event.world);
      MechnicalNetworkManager.addManager(event.world, worlddata.getNetworks());
    }

    long worldtime = event.world.getTotalWorldTime();
    long timeofday = event.world.getWorldTime() / 24000L;

    if (worldtime % 6000L == 0) {
      VintageCraftMobTweaker.setSpawnCap(
          EnumCreatureType.MONSTER,
          VintageCraftMobTweaker.spawnCapByDay(worldtime / 24000L, event.world.getDifficulty()));
      VintageCraftConfig.saveConfig();
    }

    int moonphase = event.world.provider.getMoonPhase(event.world.getWorldTime());
    boolean cannotSleeptonight =
        moonphase == 0
            || (event.world.getDifficulty() == EnumDifficulty.HARD
                && (moonphase == 7 || moonphase == 1));

    if (cannotSleeptonight) {
      for (Object obj : event.world.playerEntities) {
        EntityPlayer player = (EntityPlayer) obj;
        if (player.isPlayerSleeping() && getSleepTimer(player) > 80) {
          player.wakeUpPlayer(true, true, true);
          player.addChatMessage(
              new ChatComponentText(
                  "You tried to fall sleep, but something is keeping you awake tonight."));
        }
      }
    }

    long day = worldtime / 24000L;
    if (day > 0 && day % 20 == 0 && timeofday % 24000L == 14000) {
      packetPipeline.sendToAll(new StartMeteorShowerPacket(10000));
      MinecraftServer.getServer()
          .getConfigurationManager()
          .sendChatMsg(new ChatComponentText("Something strange is happening in the night sky"));
    }
  }
Exemple #2
0
 public static void sendToAll(IMessage toSend) {
   packetPipeline.sendToAll(toSend);
 }