FuskedLLCC

Untitled

May 15th, 2021
654
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. public class Mod {
  3. public static final SimpleChannel CHANNEL = NetworkRegistry.ChannelBuilder
  4.         .named(new ResourceLocation(Mod.MOD_ID, "my_channel"))
  5.         .networkProtocolVersion(() -> "1")
  6.         .clientAcceptedVersions(PROTOCOL_VERSION::equals)
  7.         .serverAcceptedVersions(PROTOCOL_VERSION::equals)
  8.         .simpleChannel();
  9.  
  10. public ModTutorial() {
  11.    
  12.     FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
  13.    
  14. }
  15.  
  16. private void setup(final FMLCommonSetupEvent event)
  17. {
  18.  
  19.     CHANNEL.messageBuilder(MySimplePacket.class, 0)
  20.             .encoder(MySimplePacket::encode)
  21.             .decoder(MySimplePacket::decode)
  22.             .consumer(MySimplePacket::handle)
  23.             .add();
  24.    
  25. }
  26. }
  27.  
  28. //packet class
  29. public class MySimplePacket
  30. {
  31.     private String value;
  32.  
  33.     public MySimplePacket(String value)
  34.     {
  35.         this.value = value;
  36.     }
  37.  
  38. public static void encode(MySimplePacket packet, PacketBuffer buffer)
  39. {
  40.     buffer.writeString(packet.value);
  41. }
  42.  
  43. public static MySimplePacket decode(PacketBuffer buffer)
  44. {
  45.     String value = buffer.readString();
  46.     MySimplePacket instance = new MySimplePacket(value);
  47.     return instance;
  48. }
  49.  
  50. public static void handle(MySimplePacket packet, Supplier<NetworkEvent.Context> ctx)
  51. {
  52. if(Utils.client) {
  53.     Utils.playerInstance.playSound(ModSounds.forestEvent,1.0f,1.0f);
  54. }
  55. }
RAW Paste Data