Jump to content

[1.7.2] ExtendedEntityProperties not saving correctly.


Zer0HD2

Recommended Posts

Well, one problem solved creates 2 more, I guess. I've created a levelling system (as some people will know, I've posted enough issues about it on here), where a player gains levels by killing mobs. I decided to add in a system using stats, where the player gets skill points for levelling up, and can spend them on those stats. I have the GUI working, I have the buttons working, and the stats SEEM to update when you click the button, but there are a few issues;

 

1. When you log out, you get back all the skill points you spent, and all stats reset to 1

2. Same thing happens when you level up

3. (least important) Can't figure out how to remove the buttons (for adding points) when your skill points hit 0. They disappear when you close and re-open the GUI though.

 

Relevant class files:

 

ExtendedProperties (Yes, I know I am still using data watchers, working on a system that doesn't use them): https://gist.github.com/Zer0HD/a71170366ac1ccb29313

GUI: https://gist.github.com/Zer0HD/689cee94b0fcfbe3c613

Packet (sent when adding skill point): https://gist.github.com/Zer0HD/88f580b107bffc8105c3

Handler for said packet: https://gist.github.com/Zer0HD/8f8ce1d753694684b630

 

If any other code is required, please let me know.

 

Thanks,

 

Zer0

Link to comment
Share on other sites

The only thing I can think of right now is that there's an issue syncing between client and server. An I on the right track?

 

It kinda sounds like your stats are never getting changed on the server extended properties and then they are being saved and loaded.

 

One thing I do is I actually sync the entire NBTTagCompound of the extended properties.  ByteBufUtils allows you to read and write a whole tag compound.  Assuming you don't have a lot of properties, it isn't really that wasteful to send the whole thing and it makes the coding a lot easier than making a packet to sync each property type. 

 

Otherwis, I just say add a bunch of System.out.println() statements that are informative in each method to help you trace the execution.  You should be able to print out the values as you put them into the packets and as you receive them, you should be able to trace the values on both the client and server side to see if they get out of sync.  Basically you just need to do some old fashioned debugging/

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Thanks for the tip, I'll do that when I get home. I did have some stuff printing to the console, and the stat values do change, they just don't save. I also send the whole tag in the packet sent in the extended properties class. Perhaps the tag data is being saved before the stat is updated?

 

Sorry for slow replies and stuff, writing this on my phone.

Link to comment
Share on other sites

A huge part of your problem is your 'upgrade stat' packet handler looks like it is handling the packet on the client side, but aren't you trying to send the packet to the server?

// this is a client player:
EntityPlayer player = Minecraft.getMinecraft().thePlayer;

 

I can't see how you registered your packet, but it should be registered for Side.SERVER, i.e. the server receives the message from the client. You would then use 'ctx.getServerHandler().playerEntity' to get the player entity when handling the packet.

Link to comment
Share on other sites

Ah - so it's currently trying to update the values on the client side? That would explain why it gets quite upset when I try to send a packet to the client from that method... I did set Side.SERVER when registering the packet, but I'll try changing the player variable to what you suggested.

 

Edit: Nope. It now throws NPEs on that line in the message handler. Changed it to:

EntityPlayer player = ctx.getServerHandler().playerEntity;

 

Error:

 

[01:43:59] [server thread/ERROR] [FML]: There was a critical exception handling a packet on channel mchardcore
java.lang.NullPointerException
at com.zer0.hardcore.packets.UpgradeStatPacketHandler.onMessage(UpgradeStatPacketHandler.java:18) ~[upgradeStatPacketHandler.class:?]
at com.zer0.hardcore.packets.UpgradeStatPacketHandler.onMessage(UpgradeStatPacketHandler.java:1) ~[upgradeStatPacketHandler.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:33) ~[simpleChannelHandlerWrapper.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:13) ~[simpleChannelHandlerWrapper.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[simpleChannelInboundHandler.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) ~[MessageToMessageDecoder.class:?]
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) ~[DefaultChannelPipeline.class:?]
at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) ~[EmbeddedChannel.class:?]
at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:80) [FMLProxyPacket.class:?]
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:232) [NetworkManager.class:?]
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:720) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:608) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:482) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:746) [MinecraftServer$2.class:?]

 

Line 18 is the one I pasted above. Line 1 is my package :L

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



×
×
  • Create New...

Important Information

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