Jump to content

Recommended Posts

Posted

Hello,

 

I want my plugin to send an integer to my mod but I don't understand how to get the integer.

Registering in main class

 

		SimpleNetworkWrapper network = NetworkRegistry.INSTANCE.newSimpleChannel("MyChannel");
	    network.registerMessage(CommunicationMessage.Handler.class, CommunicationMessage.class, 0, Side.CLIENT);

 

My CommunicationMessage class :

public class CommunicationMessage implements IMessage {
	 private static int actualMana;

	    public CommunicationMessage() {
	    }

	    public CommunicationMessage(int actualMana) {
	        this.actualMana = actualMana;
	    }

	    @Override
	    public void fromBytes(ByteBuf buf) {
	        actualMana = ByteBufUtils.readVarInt(buf, 100000);
	    }

	    @Override
	    public void toBytes(ByteBuf buf) {
	        ByteBufUtils.writeVarInt(buf, actualMana, 100000);
	    }

	    public static class Handler implements IMessageHandler<CommunicationMessage, IMessage> {

	        @Override
	        public IMessage onMessage(CommunicationMessage message, MessageContext ctx) {
	        	Minecraft.getMinecraft().player.sendChatMessage("detected");
	            return null;
	        }
	    }
	}

 

Registering in plugin the channel :

 

Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(this, "MyChannel");

 

How I send the packet in my plugin :

 

public static void sendManaToHUD(Player p, int actualMana) {

		ByteArrayDataOutput output  = ByteStreams.newDataOutput();
		
		output.writeInt(0);
		output.writeInt(actualMana);
		p.sendPluginMessage(ModPluginAPI.pl, "MyChannel", output.toByteArray());
	}

 

So, the packet is detected within my onMessage event, but how do I get the integer I sent ?

I checked and the ByteBuf is null so the int actualMana too.

Could you explain what I did wrong ?

Thank you very much

 

Posted

Sorry 1.12.2 is no longer supported on this forum. Please update to a modern version of Minecraft to receive support. For more information read the LTS at the top of the page.

  • Sad 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)

Isn't the system the same for every version ?

 

Edit : I read it and it says 

Quote

What does this mean?


1.15 is latest. It will get full support.
1.14 is LTS. It will also get support, and new features, but new features must be made for 1.15 first.

1.12 is no longer supported on this forum, no new features, and no more bugfixes.


All other versions are not supported. This means if you come to us for help with those, we will ask you to update. This includes crashes/bugs.

Doesn't it mean I can get help for 1.12.2 anyway ?

Edited by Shelk
Posted
16 minutes ago, Shelk said:

Doesn't it mean I can get help for 1.12.2 anyway ?

No.

16 minutes ago, Shelk said:

1.12 is no longer supported on this forum

 

  • Sad 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)
Quote

All other versions are not supported. This means if you come to us for help with those, we will ask you to update. This includes crashes/bugs.

It says if you come for help with other versions, you can't. But 1.12 is not in the other versions. And what differences are there with 1.14 and 1.12 for plugin messages ?

Edited by Shelk
Posted

It also explicitly states 1.12 is no longer supported, likely singled out for mention because it was the go-to version for a long time while the 1.13 rewrite happened.

  • Sad 1
Posted
1 minute ago, Shelk said:

It says if you come for help with other versions, you can't. But 1.12 is not in the other versions

It specifically says 1.12 is no longer supported. It says this to make it clear. "Other Versions" means not the latest and the one immediately before the latest in this case.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.