Jump to content

Recommended Posts

Posted

Hi!

Currently I'm trying to make a Jetpack. But I ran into a quite tricky problem when I decided to make the Jetpack store Energy.

 

Problem:

If you want to detect if the player who wears the Jetpack is jumping, you need to do all of the velocity and energy reducing stuff on the client because there's no way the server can access the client's gamesettings.

Now, I store the data used to determinate how much energy the Jetpack has left by writing a float with the key "storageValue" to the ItemStacks tagCompound.

if (stack.getTagCompound() != null) {
            if (stack.getTagCompound().hasKey("storageVoltage") && stack.getTagCompound().hasKey("storageValue")) {
                stack.getTagCompound().setFloat("storageVoltage", storage.getVoltage());
                stack.getTagCompound().setFloat("storageValue", storage.getCurrentlyStored().getAmount());
            }
}

But because the NBT stuff is done by the Client, the Server does not know if the damage of the item, which is the indicator for how much energy is stored, or if the tagcompound has changed.

So, after I click on the Item, the energy jumps back to full, what is completely logical.

I do have a few guesses how I could fix this. If I set myself to gamemode creative,  the serverside storage-value somehow gets updated after the inventory is opened.

So, if I adjust the player's capabilities to match creative (excluding flying), but leave the client's gamemode at survival,  there should be a way of controlling your inventory fully even though you're in survival... But how? The values don't get updated even with the adjusted capabilities!

I just wan't to know if there's any way of sending the server the inventory-changes.

 

Thanks for your help,

Michael

Posted
2 minutes ago, Michael K said:

If I set myself to gamemode creative,  the serverside storage-value somehow gets updated after the inventory is opened.

This is because in creative mode the client has authority on inventory changes.

 

3 minutes ago, Michael K said:

here should be a way of controlling your inventory fully even though you're in survival... But how?

Through the magic of packets.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

What I've just found out is really intresting... Yeah you're right! Through the magic of packets. Using CPacketCreativeInventoryAction to be exact. But there's one little problem... The NetHandlerPlayServer.

public void processCreativeInventoryAction(CPacketCreativeInventoryAction packetIn){
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.player.getServerWorld());

    if (this.player.interactionManager.isCreative()){

That's the problem... In order to controll the inventory, I need to be in creative... Any other ideas?

Posted

/me face desk

Don't use that.

Use your own packets.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.