Exemplo n.º 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));
  }
}
Exemplo n.º 2
0
  @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);
  }
/**
 * 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);
  }
}
Exemplo n.º 4
0
  private boolean handleClientSideCustomPacket(
      S3FPacketCustomPayload msg, ChannelHandlerContext context) {
    String channelName = msg.getChannelName();
    if ("FML|MP".equals(channelName)) {
      try {
        if (multipart == null) {
          multipart = new MultiPartCustomPayload(msg.getBufferData());
        } else {
          multipart.processPart(msg.getBufferData());
        }
      } catch (IOException e) {
        this.kickWithMessage(e.getMessage());
        multipart = null;
        return true;
      }

      if (multipart.isComplete()) {
        msg = multipart;
        channelName = msg.getChannelName();
        multipart = null;
      } else {
        return true; // Haven't received all so return till we have.
      }
    }
    if ("FML|HS".equals(channelName)
        || "REGISTER".equals(channelName)
        || "UNREGISTER".equals(channelName)) {
      FMLProxyPacket proxy = new FMLProxyPacket(msg);
      proxy.setDispatcher(this);
      handshakeChannel.writeInbound(proxy);
      // forward any messages into the regular channel
      for (Object push : handshakeChannel.inboundMessages()) {
        List<FMLProxyPacket> messageResult =
            FMLNetworkHandler.forwardHandshake(
                (FMLMessage.CompleteHandshake) push, this, Side.CLIENT);
        for (FMLProxyPacket result : messageResult) {
          result.setTarget(Side.CLIENT);
          result.payload().resetReaderIndex();
          context.fireChannelRead(result);
        }
      }
      handshakeChannel.inboundMessages().clear();
      return true;
    } else if (NetworkRegistry.INSTANCE.hasChannel(channelName, Side.CLIENT)) {
      FMLProxyPacket proxy = new FMLProxyPacket(msg);
      proxy.setDispatcher(this);
      context.fireChannelRead(proxy);
      return true;
    }
    return false;
  }
  @Mod.EventHandler
  public void preInit(FMLPreInitializationEvent event) {
    Config.load(event);

    HarvestLevels.init();

    NetworkRegistry.INSTANCE.registerGuiHandler(instance, guiHandler);

    if (event.getSide().isClient()) {
      ClientProxy.initClient();
    }

    TinkerNetwork.instance.setup();
    CapabilityTinkerProjectile.register();
  }
Exemplo n.º 6
0
  public void preInit(FMLPreInitializationEvent event) {
    PsiAPI.internalHandler = new InternalMethodHandler();

    ConfigHandler.init(event.getSuggestedConfigurationFile());

    ModItems.init();
    ModBlocks.init();
    ModEntities.init();
    ModSpellPieces.init();
    ModCraftingRecipes.init();

    NetworkHandler.init();
    NetworkRegistry.INSTANCE.registerGuiHandler(Psi.instance, new GuiHandler());

    MinecraftForge.EVENT_BUS.register(new PlayerDataHandler.EventHandler());
  }
  @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";
  }
  @EventHandler
  public void init(FMLInitializationEvent event) {
    log("Setting up inter-mod stuff...");

    FMLInterModComms.sendMessage(
        "Waila",
        "register",
        "net.breakinbad.securitycraft.imc.waila.WailaDataProvider.callbackRegister");

    NBTTagCompound vcUpdateTag = VersionUpdateChecker.getNBTTagCompound();
    if (vcUpdateTag != null) {
      FMLInterModComms.sendRuntimeMessage(MODID, "VersionChecker", "addUpdate", vcUpdateTag);
    }

    this.serverProxy.setupTextureRegistry();

    log("Doing registering stuff... (PT 2/2)");

    NetworkRegistry.INSTANCE.registerGuiHandler(this, GuiHandler);

    this.configHandler.setupEntityRegistry();
    serverProxy.registerRenderThings();
  }
Exemplo n.º 9
0
 private boolean handleServerSideCustomPacket(
     C17PacketCustomPayload msg, ChannelHandlerContext context) {
   if (state == ConnectionState.AWAITING_HANDSHAKE) {
     synchronized (this) { // guard from other threads changing the state on us
       if (state == ConnectionState.AWAITING_HANDSHAKE) {
         state = ConnectionState.HANDSHAKING;
       }
     }
   }
   String channelName = msg.getChannelName();
   if ("FML|HS".equals(channelName)
       || "REGISTER".equals(channelName)
       || "UNREGISTER".equals(channelName)) {
     FMLProxyPacket proxy = new FMLProxyPacket(msg);
     proxy.setDispatcher(this);
     handshakeChannel.writeInbound(proxy);
     for (Object push : handshakeChannel.inboundMessages()) {
       List<FMLProxyPacket> messageResult =
           FMLNetworkHandler.forwardHandshake(
               (FMLMessage.CompleteHandshake) push, this, Side.SERVER);
       for (FMLProxyPacket result : messageResult) {
         result.setTarget(Side.SERVER);
         result.payload().resetReaderIndex();
         context.fireChannelRead(result);
       }
     }
     handshakeChannel.inboundMessages().clear();
     return true;
   } else if (NetworkRegistry.INSTANCE.hasChannel(channelName, Side.SERVER)) {
     FMLProxyPacket proxy = new FMLProxyPacket(msg);
     proxy.setDispatcher(this);
     context.fireChannelRead(proxy);
     return true;
   }
   return false;
 }
Exemplo n.º 10
0
 public void init(FMLInitializationEvent e) {
   TKCrafting.initCrafting();
   GameRegistry.registerWorldGenerator(new TKWorldGen(), 0);
   NetworkRegistry.INSTANCE.registerGuiHandler(Main.instance, new TKGuiHandler());
 }
 public static void init() {
   WECUI_CHANNEL =
       NetworkRegistry.INSTANCE.newEventDrivenChannel(ForgeWorldEdit.CUI_PLUGIN_CHANNEL);
   WECUI_CHANNEL.register(new WECUIPacketHandler());
 }
Exemplo n.º 12
0
 public void initialise() {
   this.channels = NetworkRegistry.INSTANCE.newChannel(CHANNEL, this);
 }
Exemplo n.º 13
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);
  }
}
Exemplo n.º 14
0
  public static void initPackets() {
    net = NetworkRegistry.INSTANCE.newSimpleChannel(Constants.MODID.toUpperCase());

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