Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I don't understand where I should register my messages. I want to send one message to server and then send another back to client in onMessage(). It modifies player player's ExtendedProperties(it saves on server, but in client it being registered every connect and don't sync with server), but my hanlder on client side doesn't work. On server side all works.

 

Request message:

public class CustomPlayerAttrsRequestMessage implements IMessage {

    public CustomPlayerAttrsRequestMessage() {}

 

    @Override

    public void fromBytes(ByteBuf buf) {

    }

 

    @Override

    public void toBytes(ByteBuf buf) {

    }

}

 

 

 

Here's server handler:

 

public class CustomPlayerAttrsRequestHandler implements IMessageHandler<CustomPlayerAttrsRequestMessage, IMessage> {

    @Override

    public IMessage onMessage(CustomPlayerAttrsRequestMessage message, MessageContext ctx) {

        TESItems.networkWrapper.sendTo(new CustomPlayerAttrsMessage(ctx.getServerHandler().playerEntity), ctx.getServerHandler().playerEntity);

        System.out.println("Sending attrs packet to + " + ctx.getServerHandler().playerEntity.getDisplayName());

        return null;

    }

}

 

 

 

data message:

 

public class CustomPlayerAttrsMessage implements IMessage {

    public float strength, speed, luck, agility;

    public float blades, archery, blunt, mining;

    public NBTTagCompound tag = new NBTTagCompound();

 

    public CustomPlayerAttrsMessage(EntityPlayer player) {

        System.out.println("Getting attrs on player " + player.getDisplayName());

        CustomPlayer p = CustomPlayer.get(player);

        p.saveNBTData(tag);

    }

 

    @Override

    public void fromBytes(ByteBuf buf) {

        strength = buf.getFloat(0);

        speed = buf.getFloat(1);

        luck = buf.getFloat(2);

        agility = buf.getFloat(3);

        blades = buf.getFloat(4);

        archery = buf.getFloat(5);

        blunt = buf.getFloat(6);

        mining = buf.getFloat(7);

    }

 

    @Override

    public void toBytes(ByteBuf buf) {

        buf.setFloat(0, tag.getFloat("strength"));

        buf.setFloat(1, tag.getFloat("speed"));

        buf.setFloat(2, tag.getFloat("luck"));

        buf.setFloat(3, tag.getFloat("agility"));

        buf.setFloat(4, tag.getFloat("blades"));

        buf.setFloat(5, tag.getFloat("archery"));

        buf.setFloat(6, tag.getFloat("blunt"));

        buf.setFloat(7, tag.getFloat("mining"));

    }

}

 

 

 

Client handler(it don't write log, so it doesn't work)

public class CustomPlayerAttrsHandler implements IMessageHandler<CustomPlayerAttrsMessage, IMessage> {

    @Override

    public IMessage onMessage(CustomPlayerAttrsMessage msg, MessageContext ctx) {

        System.out.println("Got attrs package from server");

        CustomPlayer player = CustomPlayer.get(Minecraft.getMinecraft().thePlayer);

        player.strength = msg.strength;

        player.agility = msg.agility;

        player.speed = msg.speed;

        player.luck = msg.luck;

        player.blades = msg.blades;

        player.blunt = msg.blunt;

        player.archery = msg.archery;

        player.mining = msg.mining;

        return null;

    }

}

 

 

 

Registering:

@EventHandler

    public void Init(FMLInitializationEvent event) {

        networkWrapper = NetworkRegistry.INSTANCE.newSimpleChannel("customPlayerChannel");

        networkWrapper.registerMessage(CustomPlayerOpenInventoryHandler.class, CustomPlayerOpenInventoryMessage.class, 0, Side.SERVER);

 

@EventHandler

    @SideOnly(Side.CLIENT)

    public void Load(FMLInitializationEvent event) {

        networkWrapper.registerMessage(CustomPlayerAttrsHandler.class, CustomPlayerAttrsMessage.class, 1, Side.CLIENT);

 

I tried to move client handler registration to Init(), but this throws exception on server launch due to missing EntityClientPlayerMP class.

  • Author

 

@EventHandler

    public void PreInit(FMLPreInitializationEvent event) {

        networkWrapper = NetworkRegistry.INSTANCE.newSimpleChannel("customPlayerChannel");

        networkWrapper.registerMessage(CustomPlayerOpenInventoryHandler.class, CustomPlayerOpenInventoryMessage.class, 0, Side.SERVER);

        networkWrapper.registerMessage(CustomPlayerAttrsHandler.class, CustomPlayerAttrsMessage.class, 1, Side.CLIENT);

    }

 

  • Author

I added no-arg constructor to CustomPlayerAttrsMessage and CustomPlayerAttrsHandler, but it still don't work

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.