示例#1
0
/** Created by universallp on 08.01.2016 12:28. */
public class PacketHandler {
  public static final SimpleNetworkWrapper INSTANCE =
      NetworkRegistry.INSTANCE.newSimpleChannel(References.MOD_ID);
  private static int ID = 0;

  public static void init() {
    // Register Network Messages
    INSTANCE.registerMessage(
        MessageSyncRecipeChip.class, MessageSyncRecipeChip.class, ID++, Side.SERVER);
    //        INSTANCE.registerMessage(MessageSyncIngredients.class, MessageSyncIngredients.class,
    // ID++, Side.SERVER);
    //        INSTANCE.registerMessage(MessageUpdateMissingItems.class,
    // MessageUpdateMissingItems.class, ID++, Side.SERVER);
    //        INSTANCE.registerMessage(MessageSwitchItems.class, MessageSwitchItems.class, ID++,
    // Side.SERVER);
    //        INSTANCE.registerMessage(MessageSwitchGui.class, MessageSwitchGui.class, ID++,
    // Side.SERVER);
    //        INSTANCE.registerMessage(MessageNameCrafter.class, MessageNameCrafter.class, ID++,
    // Side.SERVER);
    //        INSTANCE.registerMessage(MessageNameCrafterClient.class,
    // MessageNameCrafterClient.class, ID++, Side.CLIENT);

  }

  @SideOnly(Side.CLIENT)
  public static void sendItemToServer(int slotID, ItemStack item) {
    PacketHandler.INSTANCE.sendToServer(new MessageSyncRecipeChip(item, (byte) slotID));
  }
}
/**
 * GraveStone mod
 *
 * @author NightKosh
 * @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
 */
public class GSMessageHandler {
  public static final SimpleNetworkWrapper networkWrapper =
      NetworkRegistry.INSTANCE.newSimpleChannel(ModInfo.ID.toLowerCase());

  public static void init() {
    networkWrapper.registerMessage(
        GraveDeathMessageToServer.class, GraveDeathMessageToServer.class, 0, Side.SERVER);
    networkWrapper.registerMessage(
        AltarMessageToServer.class, AltarMessageToServer.class, 1, Side.SERVER);
    networkWrapper.registerMessage(
        AltarMessageToClient.class, AltarMessageToClient.class, 2, Side.CLIENT);
  }
}
  @EventHandler
  public void preInit(FMLPreInitializationEvent event) {
    log("Starting to load....");
    log("Loading config file....");
    log(
        mod_SecurityCraft.VERSION
            + " of SecurityCraft is for a post MC-1.6.4 version! Configuration files are useless for setting anything besides options.");
    mod_SecurityCraft.configFile = new Configuration(event.getSuggestedConfigurationFile());
    this.configHandler.setupConfiguration();
    log("Config file loaded.");
    log("Setting up handlers!");
    this.configHandler.setupHandlers(event);
    log("Handlers registered.");
    log("Setting up network....");
    mod_SecurityCraft.network = NetworkRegistry.INSTANCE.newSimpleChannel(mod_SecurityCraft.MODID);
    this.configHandler.setupPackets(mod_SecurityCraft.network);
    log("Network setup.");

    log("Loading mod additions....");
    this.configHandler.setupAdditions();

    if (this.debuggingMode) {
      this.configHandler.setupDebugAdditions();
    }

    log("Finished loading mod additions.");
    log("Doing registering stuff... (PT 1/2)");
    this.configHandler.setupGameRegistry();

    serverProxy.registerTextureFiles();

    ModMetadata modMeta = event.getModMetadata();
    modMeta.authorList = Arrays.asList(new String[] {"Geforce, bl4ckscor3"});
    modMeta.autogenerated = false;
    modMeta.credits = "Thanks to all of you guys for your support!";
    modMeta.description =
        "Adds a load of things to keep your house safe with.\nIf you like this mod, hit the green arrow\nin the corner of the forum thread!\nPlease visit the URL above for help. \n \nMessage of the update: \n"
            + MOTU;
    modMeta.url = "breakinbad.net";
  }
示例#4
0
@Mod(modid = ModInfo.ModID, version = ModInfo.ModVersion)
public class VintageCraft {
  @Instance("vintagecraft")
  public static VintageCraft instance;

  @SidedProxy(clientSide = ModInfo.CLIENT_PROXY_CLASS, serverSide = ModInfo.SERVER_PROXY_CLASS)
  public static CommonProxy proxy;

  public static final SimpleNetworkWrapper packetPipeline =
      NetworkRegistry.INSTANCE.newSimpleChannel("vintagecraft");

  public static CreativeTabsVC terrainTab =
      new CreativeTabsVC(CreativeTabsVC.getNextID(), "terrain");
  public static CreativeTabsVC floraTab = new CreativeTabsVC(CreativeTabsVC.getNextID(), "flora");
  public static CreativeTabsVC resourcesTab =
      new CreativeTabsVC(CreativeTabsVC.getNextID(), "resources");
  public static CreativeTabsVC craftedBlocksTab =
      new CreativeTabsVC(CreativeTabsVC.getNextID(), "craftedblocks");
  public static CreativeTabsVC toolsarmorTab =
      new CreativeTabsVC(CreativeTabsVC.getNextID(), "toolsandarmor");
  public static CreativeTabsVC mechanicsTab =
      new CreativeTabsVC(CreativeTabsVC.getNextID(), "mechanics");

  @EventHandler
  public static void preInit(FMLPreInitializationEvent event) {
    VintageCraftConfig.loadConfig(event);
  }

  @EventHandler
  public void init(FMLInitializationEvent event) throws Exception {
    packetPipeline.registerMessage(
        AnvilTechniquePacket.Handler.class, AnvilTechniquePacket.class, 0, Side.SERVER);
    packetPipeline.registerMessage(
        ChunkPutNbtPacket.Handler.class, ChunkPutNbtPacket.class, 1, Side.CLIENT);
    packetPipeline.registerMessage(
        ChunkRemoveNbtPacket.Handler.class, ChunkRemoveNbtPacket.class, 2, Side.CLIENT);
    packetPipeline.registerMessage(
        SoundEffectToServerPacket.Handler.class, SoundEffectToServerPacket.class, 3, Side.SERVER);
    packetPipeline.registerMessage(
        MechanicalNetworkNBTPacket.ClientHandler.class,
        MechanicalNetworkNBTPacket.class,
        4,
        Side.CLIENT);
    packetPipeline.registerMessage(
        StartMeteorShowerPacket.ClientHandler.class, StartMeteorShowerPacket.class, 5, Side.CLIENT);
    packetPipeline.registerMessage(
        WorldDataPacket.ClientHandler.class, WorldDataPacket.class, 6, Side.CLIENT);
    packetPipeline.registerMessage(
        CarpentryTechniquePacket.Handler.class, CarpentryTechniquePacket.class, 7, Side.SERVER);

    BlocksVC.init();
    ItemsVC.init();
    AchievementsVC.init();

    FMLCommonHandler.instance().bus().register(this);
    MinecraftForge.EVENT_BUS.register(this);

    proxy.registerTileEntities();

    NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy);

    System.out.println("vcraft has init.");

    GameRegistry.registerWorldGenerator(new WorldGenDeposits(), 4);

    WorldType.DEFAULT = WorldTypeVC.DEFAULT;
    WorldType.FLAT = WorldTypeVC.FLAT;

    // DimensionManager.unregisterDimension(-1);
    DimensionManager.unregisterDimension(0);
    DimensionManager.unregisterDimension(1);

    // DimensionManager.unregisterProviderType(-1);
    DimensionManager.unregisterProviderType(0);
    DimensionManager.unregisterProviderType(1);
    DimensionManager.registerProviderType(0, WorldProviderVC.class, true);
    DimensionManager.registerProviderType(1, WorldProviderVC.class, false);

    // DimensionManager.registerDimension(-1, -1);
    DimensionManager.registerDimension(0, 0);
    DimensionManager.registerDimension(1, 1);

    proxy.init(event);
  }

  @EventHandler
  public void postInit(FMLPostInitializationEvent event) {
    proxy.postInit(event);

    ItemsVC.initTabIcons();
    DynTreeGenerators.initGenerators();

    Recipes.addRecipes();
    EnumAnvilRecipe.registerRecipes();
    EnumCarpentryRecipes.registerRecipes();
  }

  @EventHandler
  public void onServerStart(FMLServerStartingEvent evt) {
    MinecraftServer server = MinecraftServer.getServer();
    ICommandManager command = server.getCommandManager();
    ServerCommandManager manager = (ServerCommandManager) command;
    manager.registerCommand(new ServerCommandsVC());
  }

  @SubscribeEvent
  public void entityJoin(EntityJoinWorldEvent evt) {
    if (!evt.world.isRemote && evt.entity instanceof EntityPlayerMP) {

      packetPipeline.sendTo(new WorldDataPacket(evt.world.getSeed()), (EntityPlayerMP) evt.entity);
    }

    if (evt.entity instanceof EntityZombie) {
      if (((EntityZombie) evt.entity).isChild()) {
        ((EntityZombie) evt.entity).setChild(false);
      }
    }
  }

  @SubscribeEvent
  public void entitySpawn(SpecialSpawn evt) {
    if (evt.world.isRemote) return;
    VintageCraftMobTweaker.entitySpawn(evt);
  }

  @SubscribeEvent
  public void entityDeath(LivingDeathEvent evt) {
    if (evt.entityLiving instanceof EntityZombie
        && evt.source.getEntity() instanceof EntityPlayer) {
      ItemStack[] inventory = evt.entityLiving.getInventory();
      int numArmorItems = 0;
      for (ItemStack stack : inventory) {
        if (stack != null && stack.getItem() instanceof ItemArmorVC) {
          ItemArmorVC armoritem = (ItemArmorVC) stack.getItem();
          if (armoritem.getArmorMaterial().name().equals("IRONVC")) numArmorItems++;
        }
      }

      if (numArmorItems == 4) {
        ((EntityPlayer) evt.source.getEntity())
            .triggerAchievement(AchievementsVC.killIronArmorZombie);
      }
    }
  }

  public VCraftWorldSavedData getOrCreateWorldData(World world) {
    VCraftWorldSavedData worlddata;

    worlddata =
        (VCraftWorldSavedData)
            world.getPerWorldStorage().loadData(VCraftWorldSavedData.class, "vcraft");

    if (worlddata == null) {
      worlddata = new VCraftWorldSavedData("vcraft");
      world.getPerWorldStorage().setData("vcraft", worlddata);
    }

    return worlddata;
  }

  @SubscribeEvent
  public void loadWorld(WorldEvent.Load evt) {
    VintageCraftMobTweaker.setSpawnCap(
        EnumCreatureType.MONSTER,
        VintageCraftMobTweaker.spawnCapByDay(
            evt.world.getTotalWorldTime() / 24000L, evt.world.getDifficulty()));

    WindGen.registerWorld(evt.world);
  }

  @SubscribeEvent
  public void unloadWorld(WorldEvent.Unload evt) {
    WindGen.unregisterWorld(evt.world);

    VCraftWorldSavedData worlddata = getOrCreateWorldData(evt.world);

    System.out.println("unload networks");
    MechnicalNetworkManager.unloadManagers();
  }

  @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"));
    }
  }

  public int getSleepTimer(EntityPlayer player) {
    int timer = ReflectionHelper.getPrivateValue(EntityPlayer.class, player, 20);
    return timer;
  }

  @SubscribeEvent
  public void onEvent(LivingDropsEvent event) {
    VintageCraftMobTweaker.tweakDrops(event);
  }
}
示例#5
0
  public static void initPackets() {
    net = NetworkRegistry.INSTANCE.newSimpleChannel(Constants.MODID.toUpperCase());

    registerMessage(ThermalBinderPacket.class, ThermalBinderPacket.StartMessage.class);
    registerMessage(ElectricMinerPacket.class, ElectricMinerPacket.StartMessage.class);
  }