Skip to content

Conversation

@SirYwell
Copy link
Member

Overview

Fixes #2961

Description

Different block types can share a property with the same name but with different types. In such case, we shouldn't try to apply the property with invalid values.

We could probably also remove the IllegalArgumentException and just return the current block state instead in BlockState#with(PropertyKey,V), but that might hide other problems. Thoughts?

### Submitter Checklist
- [x] Make sure you are opening from a topic branch (**/feature/fix/docs/ branch** (right side)) and not your main branch.
- [x] Ensure that the pull request title represents the desired changelog entry.
- [x] New public fields and methods are annotated with `@since TODO`.
- [x] I read and followed the [contribution guidelines](https://github.com/IntellectualSites/.github/blob/main/CONTRIBUTING.md).

@SirYwell SirYwell requested a review from a team as a code owner October 27, 2024 08:53
@github-actions github-actions bot added the Bugfix This PR fixes a bug label Oct 27, 2024
@dordsor21
Copy link
Member

We should keep the exception, else we're just silently failing. No failure implies it should have "worked"

public boolean hasPropertyOfType(PropertyKey key, Class<?> propertyType) {
int ordinal = key.getId();
Property<?> property;
return this.settings.propertiesMapArr.length > ordinal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this definitely make sense to have? If the key ID is dynamic to the original block state, that may not work, and if it's global that wouldn't work either?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our PropertyKey and its ID are unique, so they are at the same position in each propertiesMapArr. But the actual property class stored there can have different types in different arrays.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay cool, so just a quick and dirty check so we don't need to check further

@SirYwell
Copy link
Member Author

We should keep the exception, else we're just silently failing. No failure implies it should have "worked"

Probably worth to note that the default impl of Property#getIndex(T) doesn't fail when passing incompatible types, but overridden methods will throw a CCE. That's also why fence -> wall doesn't throw in the related issue, but wall -> fence does.

@dordsor21
Copy link
Member

dordsor21 commented Oct 27, 2024

We should keep the exception, else we're just silently failing. No failure implies it should have "worked"

Probably worth to note that the default impl of Property#getIndex(T) doesn't fail when passing incompatible types, but overridden methods will throw a CCE. That's also why fence -> wall doesn't throw in the related issue, but wall -> fence does.

I think I'm looking at the wrong getIndex method - it seems like it returns -1 on failure? in all overrides?

@SirYwell
Copy link
Member Author

I think I'm looking at the wrong getIndex method - it seems like it returns -1 on failure? in all overrides?

E.g.

@Override
public int getIndex(Boolean value) {
return value ? defaultIndex : 1 - defaultIndex;
}
only accepts Boolean arguments. The compiler adds a synthetic bridge method getIndex(Object) that basically just delegates but with a cast. That's where we fail then.

@dordsor21
Copy link
Member

dordsor21 commented Oct 27, 2024

E.g.

@Override
public int getIndex(Boolean value) {
return value ? defaultIndex : 1 - defaultIndex;
}

only accepts Boolean arguments. The compiler adds a synthetic bridge method getIndex(Object) that basically just delegates but with a cast. That's where we fail then.

Ah yeah of course, missed that. I wonder if we should keep that though - having the "wrong" value of the right type return -1 is okay, whereas the wrong type altogether feels like a larger error (as would be the case for nearly/if not all other generic-type situations like this). As it is the default implementation would throw a CCE if the wrong type is given anyway

@dordsor21 dordsor21 requested a review from a team October 27, 2024 11:46
@dordsor21
Copy link
Member

dordsor21 commented Nov 2, 2024

@dordsor21
Copy link
Member

So this isn't actually fully fixing the issue. It's possible to have properties of the same type, with the same length of values, and the same name (i.e. slab and chest type).

Copy link
Member

@PierreSchwang PierreSchwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dordsor21 dordsor21 merged commit 7281fa3 into main Nov 4, 2024
@dordsor21 dordsor21 deleted the fix/incompatible-properties branch November 4, 2024 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bugfix This PR fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replacing walls with fences keeping equal block states throws error

4 participants