Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.9.4] Syncing Player Capabilities
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 0
TLHPoE

[1.9.4] Syncing Player Capabilities

By TLHPoE, July 11, 2016 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

TLHPoE    39

TLHPoE

TLHPoE    39

  • Dragon Slayer
  • TLHPoE
  • Members
  • 39
  • 638 posts
Posted July 11, 2016

The line where I sync the code (in the 1st code excerpt below) it returns a null error.

 

Attach Event:

@SubscribeEvent
public void attachCapabilities(AttachCapabilitiesEvent.Entity e) {
	net.minecraft.entity.Entity et = e.getEntity();

	if(!et.worldObj.isRemote && et instanceof EntityPlayer) {
		e.addCapability(new ResourceLocation(Scalae.MODID, "IScalaeCapability"), new ICapabilitySerializable<NBTTagCompound>() {
			IScalaeCapability instance = Scalae.CAPABILITY.getDefaultInstance();

			@Override
			public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
				return capability == Scalae.CAPABILITY;
			}

			@Override
			public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
				return capability == Scalae.CAPABILITY ? Scalae.CAPABILITY.<T> cast(instance) : null;
			}

			@Override
			public NBTTagCompound serializeNBT() {
				return (NBTTagCompound) Scalae.CAPABILITY.getStorage().writeNBT(Scalae.CAPABILITY, instance, null);
			}

			@Override
			public void deserializeNBT(NBTTagCompound nbt) {
				Scalae.CAPABILITY.getStorage().readNBT(Scalae.CAPABILITY, instance, null, nbt);
			}
		});

		ScalaeCapabilities.getStats((EntityPlayerMP) et).sync();
	}
}

 

Here's the get method:

public static PlayerStats getStats(EntityPlayer p) {
	if(!p.worldObj.isRemote) {
		final IScalaeCapability cap = p.getCapability(Scalae.CAPABILITY, null);

		if(cap != null) {
			return cap.getStats().setPlayer(p);
		}
	}

	return null;
}

 

And the sync method:

public void sync() { //Located in PlayerStats.class, has a player field
	if(player != null) {
		Scalae.network.sendTo(new MessageSync(this), (EntityPlayerMP) player);
	}
}

 

I have a message class that can be sent from the client to the server for a request to sync data, but I can't find a good event to place it in client-side.

  • Quote

Share this post


Link to post
Share on other sites

Ernio    598

Ernio

Ernio    598

  • Reality Controller
  • Ernio
  • Forge Modder
  • 598
  • 2638 posts
Posted July 11, 2016

AttachCapabilitiesEvent.Entity is fired directly after EntityConstructingEvent which bascially means - there is NOTHING to sync (example: entity can be constructed with "new", but that doesn't mean it is spawned to world or has its equivalent on client).

 

Syncing should happen from EntityJoinedWorldEvent. (Attach event is ONLY for attaching, not getting/modifying/syncing).

  • Quote

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • DaemonUmbra
      Forge 1.14.4 not working

      By DaemonUmbra · Posted 13 minutes ago

      I see you're using Java 13, this isn't going to work for running Forge, though I don't think it's the issue here. Apparently your Minecraft jar is somehow incomplete, delete versions/1.14.4/1.14.4.jar and try again.
    • DaemonUmbra
      re:server tick loop

      By DaemonUmbra · Posted 16 minutes ago

      How did you install the modpack?
    • geekles
      [Forge 1.14.4] Loading saved world

      By geekles · Posted 38 minutes ago

      I'm working on a mod (for a personal project of mine) that allows for the game to be controlled wirelessly through commands. It's a challenge for the game where the output from the game will be streamed to connected viewers. The audience may control the game's instance through commands. I currently have it so that the ingame character's movement may be controlled via commands as well as specifying which multiplayer server to join etc. however loading up a singleplayer world is ironically seemingly more tedious and I haven't been able to get far with that part. I would like to give the audience the opportunity to either choose to join a server and try controlling the game through commands only or choose to create or join a pre-existing singleplayer world. Naturally, checks will be made to ensure no one abuses this system and tries spamming servers with connection requests. 
    • BeardlessBrady
      [1.12.2] NBT inconsistencies

      By BeardlessBrady · Posted 59 minutes ago

      Yes it seems the tile entity method #writeToNBT is acting the same way
    • diesieben07
      [1.12.2] NBT inconsistencies

      By diesieben07 · Posted 1 hour ago

      Did you verify your tile entity was being saved? Or just the custom item?
  • Topics

    • izaakbobo1
      10
      Forge 1.14.4 not working

      By izaakbobo1
      Started October 13

    • daylite
      7
      re:server tick loop

      By daylite
      Started 18 hours ago

    • geekles
      4
      [Forge 1.14.4] Loading saved world

      By geekles
      Started Friday at 02:37 AM

    • BeardlessBrady
      8
      [1.12.2] NBT inconsistencies

      By BeardlessBrady
      Started Saturday at 04:12 AM

    • Baconator
      4
      pw.mods.fml.common.LoaderException: java.lang.NoSuchFieldError: rock

      By Baconator
      Started 5 hours ago

  • Who's Online (See full list)

    • Royy212
    • DaemonUmbra
    • Rick57
    • LexManos
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.9.4] Syncing Player Capabilities
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community