Posted December 30, 20213 yr Hi, I feel really stupid asking this question because there are already multiple topics on this, however received no guidance from any of them at all. I already tried using sponge but I need the server to be 1.18, so Spigot is my only option since I actually know how to use it. In spigot, I am running this piece of code when a player joins the server: // Inside onPlayerJoin Event e.getPlayer().sendPluginMessage(instance, MOD_CHANNEL, "MESSAGE".getBytes()); And now in forge I have no idea what to do to capture that plugin message. I have tried looking through the event list, I looked at different posts, and had no luck. I know it is something to do with the SimpleChannel object, but have no idea where to start from. This is the only thing I have in my forge mod. SimpleChannel HANDLER = NetworkRegistry.ChannelBuilder .named(new ResourceLocation(MOD_ID, MOD_CHANNEL)) .simpleChannel(); // What the hell do I do next?? Any help would be appreciated, Thank you in advance.
December 30, 20213 yr Author Quote https://mcforge.readthedocs.io/en/latest/networking/simpleimpl/ Helped me getting the SimpleChannel correct, thank you for that. I'm getting a little confused though on the difference between Registering packets and handling packets, can you explain this to me? Quote Why are you not just using Forge on the server as well? Well, multiple reasons, but the main one is that I want knowledge on this topic (communication between forge and spigot).
December 30, 20213 yr Author Quote You register packets at startup, to the simple channel. The simple channel than handles decoding of those packets based on the packet ID and calls the provided handler once the packet is received. Okay I understand the difference now, however the parameters don't make much sense to me (other than the first one). what is a FriendlyByteBuf? is it a static class? How do I use it with the registerMessage method within the simpleChannel object? same thing with BiConsumor.
December 30, 20213 yr Author How do I use it with the registerMessage method from the SimpleChannel object? Do I need to initialise it with certain parameters? or...?
December 30, 20213 yr Author That doesn't answer my question though. I know about the first parameter, the ID. For the second parameter should the class extend MSG or something? I don't understand there Third parameter, where do I get the BiConsumer from? Do I just reference it using BiConsumer.class (which doesn't make sense to me)? Fourth parameter, same thing as Third, where do I get the FriendlyByteBuf from? I'm really only looking to trade "Hello World"'s between spigot and forge, I don't have a very big understanding of this.
December 30, 20213 yr Author Quote Please learn about Java generics. Completely forgot half of java for a moment. Can you show me an example of registering a message? I spent long enough fiddling with it and I can't get it to be correct. This is really embarrassing.
December 30, 20213 yr Author ByteBuffer bb; ByteBuf bb2; bb2.writeInt(3); bb.putChar('C'); FriendlyByteBuf fbb = new FriendlyByteBuf(bb2); INSTANCE.registerMessage(0, new MSG(bb), new BiConsumer() { @Override public void accept(Object t, Object u) { // TODO Auto-generated method stub System.out.println(t.toString() + " " + u.toString()); }}, fbb); Don't laugh LOL
December 30, 20213 yr Author Ben that doesn't really help me, I know how to write a class that contains data but what do you mean by provide implementations?
December 30, 20213 yr Author Ah, that's what you mean, interface implementations. I'll see what I can do and I'll come back.
December 30, 20213 yr Author Alright, I've got this, but I feel like i'm being really stupid. public class ApeData implements BiConsumer<MSG, FriendlyByteBuf>, Function<FriendlyByteBuf, MSG> { BlockPos blockPos = null; public ApeData(BlockPos blockPos) { this.blockPos = blockPos; } public FriendlyByteBuf getFriendlyByteBuf() { ByteBuf bb = null; FriendlyByteBuf fbb = new FriendlyByteBuf(bb); fbb.writeBlockPos(this.blockPos); return fbb; } public void setBlockPos(BlockPos blockPos) { this.blockPos = blockPos; } public BlockPos getBlockPos() { return this.blockPos; } @Override public void accept(MSG t, FriendlyByteBuf u) { // TODO Auto-generated method stub } @Override public MSG apply(FriendlyByteBuf t) { // TODO Auto-generated method stub return null; } } Then I do this to try to register it ByteBuffer bb; ApeData data = new ApeData(new BlockPos(0,0,0)); ApeDataNetwork dataNetwork = new ApeDataNetwork(); INSTANCE.registerMessage(0, new MSG(bb), data, dataNetwork); // ERROR But on the line where I commented "ERROR" I get this. The method registerMessage(int, Class<MSG>, BiConsumer<MSG,FriendlyByteBuf>, Function<FriendlyByteBuf,MSG>, BiConsumer<MSG,Supplier<NetworkEvent.Context>>) in the type SimpleChannel is not applicable for the arguments (int, MSG, ApeData, ApeDataNetwork) Ignore the first 2 parameters I'm lacking a bit of java knowledge here. I did as you said and made a new class that implements all that stuff.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.