Posted February 28, 20169 yr Good evening, I'm currently trying to make a block, an "experience container" that drains the player experience when rightclicking on it. I think I'm managing well for now but I have few questions about player exp management : Do I have to check the isRemote variable inside the drainExperienceFromPlayer ? In the method bolded above, do I have to cast the EntityPlayer to a multiplayer one ? I feel it is "safer" to perform operations on variables, such as experience, on multiplayer entities (it is for a private server) As you can see in the same method, I'm managing player experience super simply : I just make an exp transfer in the block and I reset the player exp variables just putting them at 0 : public boolean drainExperienceFromPlayer(EntityPlayer playerIn) { if (!this.worldObj.isRemote && playerIn instanceof EntityPlayerMP) { EntityPlayerMP playerMP; playerMP = (EntityPlayerMP) playerIn; if (playerMP.experienceTotal > 0) { this.experienceTotal += playerMP.experienceTotal; playerMP.experienceTotal = 0; playerMP.experienceLevel = 0; playerMP.experience = 0.0f; } else return (false); } return (true); } I made some googling such as this gamepedia link, this topic and the EntityPlayer class to see that leveling up is specially treated, and I'd like not to f*ck up player experience performing this kind of operation. The following files : BlockExpContainer.java TileEntityBlockExpContainer.java Thank you in advance for your help ! Squirrel ! Squirrel ! Squirrel !
February 28, 20169 yr 1) Yes. But not necesserily. It will be synced from server to client anyway. 2) Do NOT cast player to client/server/singleplayer specific unless you really have to. If you can perform operations on player, without casting to specific type, do not cast it. Sode note: why are you doing (false) ? Just wondering. First time seeing this style. Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
February 28, 20169 yr Author 1) Yes. But not necesserily. It will be synced from server to client anyway. 2) Do NOT cast player to client/server/singleplayer specific unless you really have to. If you can perform operations on player, without casting to specific type, do not cast it. Sode note: why are you doing (false) ? Just wondering. First time seeing this style. Hi elix, thanks for your reply. I will modify my code, considering what you said above. About return (false), I like to get a clear view of what I am returning inside my code. It's an habit I got since college. What about the player experience management I did ? Is it ok ? I took a look earlier on the EntityPlayer class and it seems that these variables are initialized with negative values, so I don't really know if it's ok to do the way I did. Squirrel ! Squirrel ! Squirrel !
February 28, 20169 yr 1) Yes. But not necesserily. It will be synced from server to client anyway. 2) Do NOT cast player to client/server/singleplayer specific unless you really have to. If you can perform operations on player, without casting to specific type, do not cast it. Sode note: why are you doing (false) ? Just wondering. First time seeing this style. Hi elix, thanks for your reply. I will modify my code, considering what you said above. About return (false), I like to get a clear view of what I am returning inside my code. It's an habit I got since college. What about the player experience management I did ? Is it ok ? I took a look earlier on the EntityPlayer class and it seems that these variables are initialized with negative values, so I don't really know if it's ok to do the way I did. I'm not able to tell you anything about this part, as i've never worked with experience (). You'll have to try or to ask/wait someone else to answer. Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
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.