Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error is thrown for key not found even when not checking for that key #3337

Closed
JimiIT92 opened this issue Mar 16, 2021 · 4 comments
Closed
Labels
platform: forge Affects SpongeForge type: bug Something isn't working version: 1.12 (u) API: 7 (unsupported since May 21st 2021)

Comments

@JimiIT92
Copy link

ERROR
Sponge throws an error when a certain key is expected for a block, but that block doesn't have that key. For instance, Sponge expects a leaf block to have a property called decayable. But if that block doesn't have that property, than any other property checks will throw an error, even if you are not checking the decayable property

EXAMPLE
Let's hook the block placing event. In that event let's check if the block has a specific Key, for example extended in it's properties

public void onBlockPlaced(ChangeBlockEvent.Place event) {
   if (!event.getTransactions().isEmpty()) {
      BlockSnapshot block = event.getTransactions().get(0).getFinal();
      if(block.get(Keys.EXTENDED).isPresent()) {
         //do stuff
      }
   }
}

Now, let's go into the server and place a block via /setblock command. For this example we will use the leaves_flowering block from DynamicTreesBOP. This is a leaf block, so Sponge thinks it will have a property named decayable. However that block does not have this property. Anyway, when you place that block via the /setblock dynamictreesbop:leaves_flowering command, the onBlockPlaced listener comes in. Remember, in this listener we check if the placed block has the extended key, and if so do some stuff. When the listener checks for that key, an error is thrown

java.lang.IllegalArgumentException:                                                                                        
Cannot get property                                                                                                        
PropertyBool{name=decayable,                                                                                               
clazz=class java.lang.Boolean,                                                                                             
values=[true, false]} as it does not                                                                                       
exist in                                                                                                                   
BlockStateContainer{block=dynamictre                                                                                       
sbop:leaves_flowering,                                                                                                     
properties=[can_flower, fast_leaves,                                                                                       
flowering, hydro, tree]}                                                                                                   
net.minecraft.block.state.BlockStateContainer$StateImplementation.func_177229_b(BlockStateContainer.java:201)              
net.minecraft.block.BlockLeaves.impl$getIsDecayableFor(BlockLeaves.java:647)                                               
net.minecraft.block.BlockLeaves.bridge$getManipulators(BlockLeaves.java:709)                                               
net.minecraft.block.state.BlockStateContainer$StateImplementation.lazyLoadManipulatorsAndKeys(BlockStateContainer.java:726)
net.minecraft.block.state.BlockStateContainer$StateImplementation.getValues(BlockStateContainer.java:919)                  
org.spongepowered.common.block.SpongeBlockSnapshot.getKeyValueMap(SpongeBlockSnapshot.java:429)                            
org.spongepowered.common.block.SpongeBlockSnapshot.get(SpongeBlockSnapshot.java:420

As you can see Sponge complains about the lack of the decayable property. However no one asked for that! And even if asked, we didn't get the value directly, but just check if that property is present or not

API VERSION 7.1.0

@dualspiral
Copy link
Contributor

This isn't an API error, but potentially an implementation one, so moving this issue.

We need to know the version of the implementation you're running, not the API version (whether you're running SpongeForge or SpongeVanilla and what version)

@dualspiral dualspiral transferred this issue from SpongePowered/SpongeAPI Mar 16, 2021
@limbo-app limbo-app added the status: needs triage This label is automatically applied to new issues and pull requests to indicate they require triage label Mar 16, 2021
@dualspiral dualspiral added the version: 1.12 (u) API: 7 (unsupported since May 21st 2021) label Mar 16, 2021
@limbo-app limbo-app removed the status: needs triage This label is automatically applied to new issues and pull requests to indicate they require triage label Mar 16, 2021
@dualspiral dualspiral added status: needs triage This label is automatically applied to new issues and pull requests to indicate they require triage status: waiting for reply there was a specific question for the author labels Mar 16, 2021
@limbo-app limbo-app removed the status: needs triage This label is automatically applied to new issues and pull requests to indicate they require triage label Mar 16, 2021
@JimiIT92
Copy link
Author

I'm running on SpongeForge for 1.12.2
Specifically: spongeforge-1.12.2-2838-7.2.1

@dualspiral
Copy link
Contributor

Try the latest please - 7.2.1 is very old now and the issue may have been fixed: https://github.com/SpongePowered/SpongeForge/actions/runs/570272675 - select the production jar at the bottom.

@JimiIT92
Copy link
Author

I tried with the latest download from the Sponge page, 7.3.0, and with the linked production jar, but it still throws the error

gabizou added a commit that referenced this issue Jan 4, 2022
Signed-off-by: Gabriel Harris-Rouquette <gabizou@me.com>
@gabizou gabizou closed this as completed Jan 4, 2022
@gabizou gabizou added platform: forge Affects SpongeForge type: bug Something isn't working and removed status: waiting for reply there was a specific question for the author labels Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: forge Affects SpongeForge type: bug Something isn't working version: 1.12 (u) API: 7 (unsupported since May 21st 2021)
Projects
None yet
Development

No branches or pull requests

4 participants