Jump to content

Recommended Posts

Posted

So, I am using DataWatcher to sync some ExtendedPlayer values between server and client. Along with the ease it provides. :P But, I was wondering if anyone could point me to an explanation of it in general. The main part I am wondering about is, when adding an Object, you have the ID of course. But, the actual object you add, what is that used for? Is that just the type of Object, or a certain cap of some sort? Just never quite understood that when I decided to switch to DataWatcher.

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

As diesieben mentioned, there are limited IDs available, so DataWatcher is not recommended for use in something like IEEP of any kind, especially one for players, as there are probably many other mods that unwisely use it in those cases and you will end up with game-breaking conflicts.

 

I suggest you use custom packets to synchronize whatever variables you need available to you on the client; that's all DataWatcher does anyway, is send a packet with the data to the client.

 

"Object" is the base Java class - everything extends from it, so it is the most general type that you could use for something, which is why you can pass int (auot-boxed to Integer), boolean (auto-boxed to Boolean), String, etc. all to the same method. Might want to brush up on those basics ;)

Posted

Alright, that explains a lot. But here's something that I don't seem to get.

 

Here is where I set the Object for DataWatcher, which I got by following coolAlias's tutorial on IEEP:

public static final int WEIGHT_WATCHER = 20;

private int maxWeight;

private final EntityPlayer player;

public final InventoryWeightLimit inv = new InventoryWeightLimit();

public ExtendedPlayer(EntityPlayer player) {
	this.player = player;
	this.maxWeight = 150;
	this.player.getDataWatcher().addObject(WEIGHT_WATCHER, this.maxWeight);
}

 

Now see, he says to save the maxMana (maxWeight in my case) as the Object. But, here is how I save it to NBT:

 

public void saveNBTData(NBTTagCompound compound) {
	NBTTagCompound props = new NBTTagCompound();

	props.setInteger("CurrentWeight", this.player.getDataWatcher().getWatchableObjectInt(WEIGHT_WATCHER));

	compound.setTag(EXT_PROP_NAME, props);

	this.inv.writeToNBT(compound);
}

 

I am setting the Integer of "CurrentWeight" to be the value of the Object I saved to DataWatcher. Now, when I go in game to test it, the Objects value is 0 (which is what I want). But, considering I set it to be the value of the maxWeight int, wouldn't the value be 150?

 

And, I actually know what an Object is. xD I'm just confused about what I stated above. It just seems like it should be 150, right?

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

Also, I will be switching to just my own packet sync. This has just been bothering me for quite some time.

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

I had assumed that the addObject also pushed the value to the client from the server, however, it is possible it only reserves it, in this case as a type int. Certainly you only want to do this once during initialisation.

 

In this tutorial, it recommends you do the addObject in an event handler for Entity construction.

 

http://www.minecraftforge.net/wiki/Datawatcher

 

You may need to actually populate it with values and trigger an update from server to client with something like the following in the relevant points in your code where the value of weight changes.

 

DataWatcher dw = player.getDataWatcher();
dw.updateObject( WEIGHT_WATCHER, newWeightValue );

 

I use this quite a lot right now, and I know it to be good for value propagation from server to client, having manually added extensive debug during shake out.

 

Noting as others have commented to stay compatible with other mods, using this on player entities is not recommended, however, in my use case, I am using it with a custom mob entity so assuming I am safe.

Posted

I understand that, thanks. :P I will be switching over to updating the client manually as to not conflict with other mods. I just really want to understand why, when setting the value to 150, it becomes 0 when saved to NBT. I am probably missing something you have stated, but I just find this so confusing that it bugs me. Is the Object simply just telling DataWatcher that we will be storing this certain Object (int, byte, float, etc.)?

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

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.

×
×
  • Create New...

Important Information

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