Jump to content

Recommended Posts

Posted

How should I send data from server to client on player login? I am trying to do this:

public void onEntityLoad(AttachCapabilitiesEvent.Entity event) {
        if (event.getEntity() instanceof EntityPlayer) {
            event.addCapability(new ResourceLocation(TESItems.attributesTagName), new PlayerAttributesCapabilityProvider());
            IPlayerAttributesCapability cap = event.getEntity().getCapability(TESItems.attributesCapability, null);
            networkWrapper.sendTo(new AttributesMessage(cap.getAttributes()), (EntityPlayerMP) event.getEntity());
            System.out.println("onEntityLoad(" + event.getEntity().getDisplayName() + ")");
        }

, but I get cap == null. Where should I send my packet? Capability works fine on server side, I already used it.

Posted

Capabilities are only attached and read from NBT after

AttachCapabilityEvent

has been fired. You should send the packet from

EntityJoinWorldEvent

.

 

To make the capability persist through respawning, subscribe to

PlayerEvent.Clone

and copy the capability's data from the old player to the new one.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

No, it's still null. Here's my code:

@SubscribeEvent
    public void onEntityJoinWorld(EntityJoinWorldEvent event) {
        IPlayerAttributesCapability cap = event.getEntity().getCapability(TESItems.attributesCapability, null);
        if (cap == null) System.out.println("cap == null");
        networkWrapper.sendTo(new AttributesMessage(cap.getAttributes()), (EntityPlayerMP) event.getEntity());
    }

Posted

EntityJoinWorldEvent

is fired for all entities, not just players. Check if the entity is a player before trying to retrieve the capability.

 

If it still doesn't work, post your code.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

There's another problem now. Minecraft#thePlayer here is null:

@Override
    public IMessage onMessage(AttributesMessage message, MessageContext ctx) {
        System.out.println("got message");
        EntityPlayer player = Minecraft.getMinecraft().thePlayer;
        if (player == null) System.out.println("player == null");
        IPlayerAttributesCapability cap = player.getCapability(TESItems.attributesCapability, null);

        for (String s : TESItems.ATTRIBUTES) {
            System.out.println("Adding " + s + " to player");
            cap.setAttribute(s, message.getAttribute(s));
        }

        return null;
    }

Posted

Packets are handled on a separate thread in 1.8+, so you need to schedule a task on the main thread before you can safely interact with game objects. This page explains more.

 

If scheduling a task on the main thread doesn't fix this, post your new code.

 

The client player is created and spawned when the client receives

SPacketJoinGame

from the server. The server sends this before spawning the player, so it should usually be received before a packet sent from

EntityJoinWorldEvent

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
    • Maybe you need to create file in assets/<modid>/items/<itemname>.json with content like this:   { "model": { "type": "minecraft:model", "model": "modname:item/itemname" } }  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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