Jump to content

[1.8] Just wondering something about DataWatcher


HappyKiller1O1

Recommended Posts

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.

Link to comment
Share on other sites

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 ;)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
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.
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

    • As a seasoned investor, I’ve learned that the financial world can be exciting and treacherous. My experiences with investments have taught me the importance of diligence and thorough research, particularly when dealing with newer and high-risk assets like Bitcoin. Unfortunately, my journey with Bitcoin was marred by a painful lesson in the form of a scam, which I hope to share to help others avoid similar pitfalls. My introduction to Bitcoin investing seemed promising. The allure of high returns and the buzz surrounding cryptocurrency were captivating. I was drawn to several Bitcoin investment platforms that promised substantial profits. These platforms presented themselves with professional websites, attractive promotions, and genuine testimonials. I was led to believe that these sites were reliable and that I was making a sound investment. However, this trust proved to be misplaced. The platform I initially invested in showcased fake success stories and substantial profits to entice investors. They used these fabricated examples to build credibility and persuade new investors like me to commit more funds. Their tactics were sophisticated; they knew exactly how to create an illusion of success and security. I, too, was lured by their promises and gradually invested a considerable amount of money, totaling 68,000 USD.The initial investments went smoothly. My account appeared to grow with impressive returns, and I felt a sense of validation in my investment strategy. But things took a drastic turn when I decided to make a more significant investment, believing that the returns would only get better. Once I deposited a substantial sum, the platform’s behavior changed abruptly. My account was frozen without warning, and I was faced with a barrage of demands for additional payments before I could access my funds or the supposed profits. The situation was both distressing and bewildering. I was met with excuses and obstructions at every turn. It became clear that I was dealing with a fraudulent company that had no intention of honoring its commitments. The realization that I had been deceived was crushing. The emotional and financial toll of the situation was overwhelming. Determined to recover my funds, I reached out to Trust Geeks Hack Expert, a service recommended by a trusted friend who had faced a similar ordeal. My initial skepticism was tempered by desperation and hope. Trust Geeks Hack Expert took immediate action. Their team worked tirelessly to investigate the fraudulent platform and recover my lost funds. Their dedication and expertise were evident throughout the process. In just a few weeks, Trust Geeks Hack Expert managed to successfully retrieve the full amount of 68,000 USD. Their assistance was thorough and professional, and they kept me informed every step of the way. Their efforts not only resulted in the recovery of my funds but also provided me with invaluable insights into how these scams operate. This. This experience has been a harsh lesson in the importance of conducting thorough research before investing in any platform, particularly in the cryptocurrency space. The allure of high returns can be overwhelming, but it’s crucial to approach such investments with caution. Verify the legitimacy of the platform, seek out reviews from reliable sources, and ensure that any investment opportunity has a track record of transparency and reliability. To anyone who finds themselves in a similar predicament, I cannot recommend Trust Geeks Hack Expert  enough. Their professionalism and commitment to recovering my funds were exemplary:: E>mail: trustgeekshackexpert {@} fastservice{.}com -----> Tele>gram : Trustgeekshackexpert, And also  What's>App   + 1-7-1-9-4-9-2-2-6-9-3
    • As a seasoned investor, I’ve learned that the financial world can be exciting and treacherous. My experiences with investments have taught me the importance of diligence and thorough research, particularly when dealing with newer and high-risk assets like Bitcoin. Unfortunately, my journey with Bitcoin was marred by a painful lesson in the form of a scam, which I hope to share to help others avoid similar pitfalls. My introduction to Bitcoin investing seemed promising. The allure of high returns and the buzz surrounding cryptocurrency were captivating. I was drawn to several Bitcoin investment platforms that promised substantial profits. These platforms presented themselves with professional websites, attractive promotions, and genuine testimonials. I was led to believe that these sites were reliable and that I was making a sound investment. However, this trust proved to be misplaced. The platform I initially invested in showcased fake success stories and substantial profits to entice investors. They used these fabricated examples to build credibility and persuade new investors like me to commit more funds. Their tactics were sophisticated; they knew exactly how to create an illusion of success and security. I, too, was lured by their promises and gradually invested a considerable amount of money, totaling 68,000 USD.The initial investments went smoothly. My account appeared to grow with impressive returns, and I felt a sense of validation in my investment strategy. But things took a drastic turn when I decided to make a more significant investment, believing that the returns would only get better. Once I deposited a substantial sum, the platform’s behavior changed abruptly. My account was frozen without warning, and I was faced with a barrage of demands for additional payments before I could access my funds or the supposed profits. The situation was both distressing and bewildering. I was met with excuses and obstructions at every turn. It became clear that I was dealing with a fraudulent company that had no intention of honoring its commitments. The realization that I had been deceived was crushing. The emotional and financial toll of the situation was overwhelming. Determined to recover my funds, I reached out to Trust Geeks Hack Expert, a service recommended by a trusted friend who had faced a similar ordeal. My initial skepticism was tempered by desperation and hope. Trust Geeks Hack Expert took immediate action. Their team worked tirelessly to investigate the fraudulent platform and recover my lost funds. Their dedication and expertise were evident throughout the process. In just a few weeks, Trust Geeks Hack Expert managed to successfully retrieve the full amount of 68,000 USD. Their assistance was thorough and professional, and they kept me informed every step of the way. Their efforts not only resulted in the recovery of my funds but also provided me with invaluable insights into how these scams operate. This. This experience has been a harsh lesson in the importance of conducting thorough research before investing in any platform, particularly in the cryptocurrency space. The allure of high returns can be overwhelming, but it’s crucial to approach such investments with caution. Verify the legitimacy of the platform, seek out reviews from reliable sources, and ensure that any investment opportunity has a track record of transparency and reliability. To anyone who finds themselves in a similar predicament, I cannot recommend Trust Geeks Hack Expert  enough. Their professionalism and commitment to recovering my funds were exemplary:: E>mail: trustgeekshackexpert{@}fastservice{.}com -----> Tele>gram : Trustgeekshackexpert, And also  What's>App   + 1-7-1-9-4-9-2-2-6-9-3
    • I've been playing it for only 1 day and it doesn't want to go into the game anymore. I've tried reinstalling the game and repairing the game files (on curseforge) but it still doesn't work. Whenever i try to click on the Singleplayer icon, it just flickers into the world creation page and flickers back 
    • https://gist.github.com/RealMangoBot/03ce10d60ce10f126dcf2c033c3a4f46  
  • Topics

×
×
  • Create New...

Important Information

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