Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Mod {
- public static final SimpleChannel CHANNEL = NetworkRegistry.ChannelBuilder
- .named(new ResourceLocation(Mod.MOD_ID, "my_channel"))
- .networkProtocolVersion(() -> "1")
- .clientAcceptedVersions(PROTOCOL_VERSION::equals)
- .serverAcceptedVersions(PROTOCOL_VERSION::equals)
- .simpleChannel();
- public ModTutorial() {
- FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
- }
- private void setup(final FMLCommonSetupEvent event)
- {
- CHANNEL.messageBuilder(MySimplePacket.class, 0)
- .encoder(MySimplePacket::encode)
- .decoder(MySimplePacket::decode)
- .consumer(MySimplePacket::handle)
- .add();
- }
- }
- //packet class
- public class MySimplePacket
- {
- private String value;
- public MySimplePacket(String value)
- {
- this.value = value;
- }
- public static void encode(MySimplePacket packet, PacketBuffer buffer)
- {
- buffer.writeString(packet.value);
- }
- public static MySimplePacket decode(PacketBuffer buffer)
- {
- String value = buffer.readString();
- MySimplePacket instance = new MySimplePacket(value);
- return instance;
- }
- public static void handle(MySimplePacket packet, Supplier<NetworkEvent.Context> ctx)
- {
- if(Utils.client) {
- Utils.playerInstance.playSound(ModSounds.forestEvent,1.0f,1.0f);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement