Jump to content

OuiOuiCroissant

Members
  • Posts

    13
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

OuiOuiCroissant's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. It's still giving me those same 3 errors on the underlined bits: INSTANCE.registerMessage(id++, SetKingPacket.class, SetKingPacket::encode, SetKingPacket::decode, SetKingPacket.Handler::handle); "The type SetKingPacket does not define encode(MSG, PacketBuffer) that is applicable here" "The type of decode(PacketBuffer) from the type SetKingPacket is SetKingPacket, this is incompatible with the descriptor's return type: MSG" "The type SetKingPacket.Handler does not define handle(MSG, Supplier<NetworkEvent.Context>) that is applicable here" SetKingPacket.encode() is a static void method, but SimpleChannel.registerMessage() wants a BiConsumer<MSG,PacketBuffer> in that parameter. How would encode ever work? Handler: package com.siegemod.packets; import com.siegemod.SiegeMod; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.network.NetworkRegistry; import net.minecraftforge.fml.network.simple.SimpleChannel; public class SiegePacketHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(new ResourceLocation(SiegeMod.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals); private static int id; public static void registerPackets() { INSTANCE.registerMessage(id++, SetKingPacket.class, SetKingPacket::encode, SetKingPacket::decode, SetKingPacket.Handler::handle); } } /* // Sending to one player INSTANCE.send(PacketDistributor.PLAYER.with(playerMP),new MyMessage()); // Send to all players tracking this chunk INSTANCE.send(PacketDistributor.TRACKING_CHUNK.with(chunk),new MyMessage()); // Sending to all connected players INSTANCE.send(PacketDistributor.ALL.noArg(),new MyMessage()); */ Packet: package com.siegemod.packets; import com.google.common.base.Supplier; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.network.PacketBuffer; import net.minecraftforge.fml.network.NetworkEvent; public class SetKingPacket { private final int data; public SetKingPacket(int dataIn) { this.data = dataIn; } public static void encode(SetKingPacket msg, PacketBuffer buf) { buf.writeInt(msg.data); } public static SetKingPacket decode(PacketBuffer buf) { int data = buf.readInt(); return new SetKingPacket(data); } public static class Handler { public static void handle(SetKingPacket msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { // Work that needs to be threadsafe (most work) ServerPlayerEntity sender = ctx.get().getSender(); // the client that sent this packet // do stuff }); ctx.get().setPacketHandled(true); } } }
  2. That makes sense. I'm still getting errors on the last 3 parameters of INSTANCE.registerMessage() in my packet handler. Is there a new way to register packets in 1.15.2? My Packet: package com.siegemod.packets; import com.google.common.base.Supplier; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.network.PacketBuffer; import net.minecraftforge.fml.network.NetworkEvent; public class SetKingPacket { private final int data; public SetKingPacket(int dataIn) { this.data = dataIn; } public static void encode(SetKingPacket msg, PacketBuffer buf) { buf.writeInt(msg.data); } public static SetKingPacket decode(PacketBuffer buf) { int data = buf.readInt(); return new SetKingPacket(data); } public static class Handler { public static void handle(SetKingPacket msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { // Work that needs to be threadsafe (most work) ServerPlayerEntity sender = ctx.get().getSender(); // the client that sent this packet // do stuff }); ctx.get().setPacketHandled(true); } } } My Packet Handler: package com.siegemod.packets; import com.siegemod.SiegeMod; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.network.NetworkRegistry; import net.minecraftforge.fml.network.simple.SimpleChannel; public final class SiegePacketHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(new ResourceLocation(SiegeMod.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals); private static int id; public static void register() { INSTANCE.registerMessage(id++, SetKingPacket.class, SetKingPacket::encode, SetKingPacket::new, SetKingPacket.Handler::handle); } } /* // Sending to one player INSTANCE.send(PacketDistributor.PLAYER.with(playerMP),new MyMessage()); // Send to all players tracking this chunk INSTANCE.send(PacketDistributor.TRACKING_CHUNK.with(chunk),new MyMessage()); // Sending to all connected players INSTANCE.send(PacketDistributor.ALL.noArg(),new MyMessage()); */
  3. I just learned how to do packets for the first time by following the forge documentation, but it only got me so far. I don't understand what SimpleChannel.registerMessages() should take as parameters. In a lot of examples and tutorials they give it static void methods from the message class, but it won't accept those in my code. It "is not applicable for the arguments". I see people implementing IMessage into their packet class, but there is no IMessage interface! Has it been replaced with MSG? Do I have to create it? If you know a lot about packets, can you tell me what I'm doing wrong? My Packet Handler: package com.siegemod.util; import com.siegemod.SiegeMod; import com.siegemod.packets.SetKingPacket; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.network.NetworkRegistry; import net.minecraftforge.fml.network.simple.SimpleChannel; public class SiegePacketHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(new ResourceLocation(SiegeMod.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals); private static int id; public static void registerPackets() { INSTANCE.registerMessage(id++, SetKingPacket.class, SetKingPacket::encode, SetKingPacket::decode, SetKingPacket::handle); } } /* // Sending to one player INSTANCE.send(PacketDistributor.PLAYER.with(playerMP),new MyMessage()); // Send to all players tracking this chunk INSTANCE.send(PacketDistributor.TRACKING_CHUNK.with(chunk),new MyMessage()); // Sending to all connected players INSTANCE.send(PacketDistributor.ALL.noArg(),new MyMessage()); */ My Message: package com.siegemod.packets; import java.nio.ByteBuffer; import org.lwjgl.system.windows.MSG; import com.google.common.base.Supplier; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.network.PacketBuffer; import net.minecraftforge.fml.network.NetworkEvent; public class SetKingPacket extends MSG { private String kingUUID; public SetKingPacket(ByteBuffer buffer) { super(buffer); } public static void encode(SetKingPacket msg, PacketBuffer buf) { buf.writeString(msg.kingUUID); } public static void decode(PacketBuffer buf, SetKingPacket msg) { msg.kingUUID = buf.readString(); } public static void handle(SetKingPacket msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { // Work that needs to be threadsafe (most work) ServerPlayerEntity sender = ctx.get().getSender(); // the client that sent this packet // do stuff }); ctx.get().setPacketHandled(true); } }
  4. My god, it works. Thank you, you absolute legend. Updated post with solution.
  5. Something I implement? As in I implement an interface? Or do you mean I create a new instance of PacketBuffer like so: ContainerProvider: Here are my other classes as they currently are: EntityClass: Container Factory: Screen Factory: Container:
  6. I just meant a static field to pass into NetworkHooks.openGui(ServerPlayerEntity, INamedContainerProvider, Consumer<PacketBuffer>) like so: So far my container factory looks like: And I made a screen factory: Will both of these create() methods be run if I run NetworkHooks.openGui(ServerPlayerEntity, INamedContainerProvider, Consumer<PacketBuffer>) on the server side? Thank you so much for your patience and help.
  7. IContainerFactory doesn't have a PacketBuffer field, it only exists as a parameter in its create() method. Where does an instance of PacketBuffer come from? Or should I create my own static instance in my container factory? Implementing IContainerFactory on my container factory has me implement a create() method: But I cannot make a static instance of my container, right? And create() is not a static method so I can't call it from somewhere else. I have nothing to pass into widowId or playerInv from here either.
  8. Update! I have discovered that I MUST use the required constructor: However, I need both the Screen and Container classes to identify the entity they belong to. I bet I can pass getEntityID through the PacketBuffer parameter of Container class. Do I make a new PacketBuffer in the createMenu method and give it Unpooled.buffer()? When I read it in the Container class it throws an IndexOutOfBoundsException. I will need to read up on how PacketBuffer works. I will update if I figure it out.
  9. I am trying to create an entity with a gui that displays slots for their armor, mainhand, offhand, and a 10 slot inventory. Currently my gui will open when the entity is right-clicked by the player, but it is unfortunately NOT interactable. Entity Super Class - SiegeEntity: Entity Class - PeasantEntity: Container Class: Container Screen Class: ContainerTypes Class: ClientEventBusSubscriber: Main Class: I will be converting from Inventory to ItemHandler soon, but for now I just want the container to open. --SOLUTION-- Main Entity Class: ContainerFactory: ScreenFactory: Container Class: Screen Class:
  10. Hello! Title. The Forge Documentation page doesn't show examples of how to save/load data from other classes (like MyEventHandler), it kind of explains which methods to use, but I'm still unsure how to do it properly and I want to do it properly. Both the MyWorldSavedData#write/readNBTTagCompounds() are run, and MyEventHandler#countFullMoons() is run properly. MyWorldSavedData: MyEventHandler:
  11. Ahhh thank you. What's the easiest way to call a specific entity using an entity ID on the server? I'm using this. ctx is the MessageContext parameter in #onMessage(). ctx.getServerHandler().player.world.getEntityByID(message.peasant_id);
  12. Hello! I followed SimpleImpl as closely as I could, but my ServerMessageHandler is being run on the client side! It is printing out "Remote = true" after I add this to it: System.out.println("Remote = " + Minecraft.getMinecraft().world.isRemote); Here is everything: Registering my ServerMessageHandler: My ServerMessage: And my ServerMessageHandler (ignore all the "!= null"s, I've had... issues): Packet is sent from WorkerGUI Class (WorkerGUI is opened when interacting with EntityCitizen) in #mouseReleased() Thanks!
×
×
  • Create New...

Important Information

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