Jump to content

Recommended Posts

Posted (edited)

Hello,

I want to create a command to give an item with the structure that it get's from a file.

This worked properly with all vanilla items, after some tests i tried it with a mod and it crashed.

Whenever i use the card wich i get from the command it crashes but if i create it without the file in a block it works, i checked the NBT data of the players inventory and everything is exact the same.

 

What am i doing wrong ?

NBTUtil#readBlockState crashes with modBlocks

 

Commands.java - private void giveMemorycard gives error

  Reveal hidden contents

 

 

Error log:

  Reveal hidden contents

 

Edited by KYPremco
Posted

This is due to the property used. The way Minecraft handles things means that it expects the exact value used to create the property, so unless you're being particularly careful, strings won't work here.

Posted
  On 12/27/2017 at 8:58 PM, quadraxis said:

This is due to the property used. The way Minecraft handles things means that it expects the exact value used to create the property, so unless you're being particularly careful, strings won't work here.

Expand  

 

I use NBTUtil#readBlockState & NBTUtil#writeBlockState

 

After some more testeing: not all blocks will let it crash probably only a small amount.

But what bugs me is why is it working without the command while it's setup exact the same

 

This is the player data saved, one card from the command left, the other from the block right.

BCkb3vr.png

Posted
  On 12/27/2017 at 10:45 PM, diesieben07 said:

Like @quadraxis eluded to, unfortunately Minecraft does not check equals when comparing properties in certain circumstances, it uses ==.

In this case (and many other cases where String is used) this can be circumvented by callingString::intern on the property values before passing them into IBlockState::withProperty. This works, because the IProperty instances are created using string literals, which always resolve to interned strings.

Expand  

Ah okay didn't understand the first time, well sad but true.

Then i'll just check if they going to cause errors and remove that type of block before passing into the item.

I hope not to much blocks have this problem, but thanks for the help anyway

Posted
  On 12/27/2017 at 11:09 PM, diesieben07 said:

Ok... well then. Just ignore my perfectly valid fix and just ignore the problem. Sure, why not.

Expand  

Oh sorry i misunderstood it because i tought i could not change the NBTUtils#readBlockState

Now i have copied that code in the command and changed 

Optional<T> optional = p_193590_1_.parseValue(p_193590_3_.getString(p_193590_2_));

To:

Optional<T> optional = p_193590_1_.parseValue(p_193590_3_.getString(p_193590_2_).intern());

 

And it's workign fine now indeed

But could i do this more smooth then copy paste that code ?(sorry i'm still a beginner)

 

Full code added:

  Reveal hidden contents

 

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.