-
-
Notifications
You must be signed in to change notification settings - Fork 125
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
Add some QoL APIs to ModelData #884
base: 1.20.x
Are you sure you want to change the base?
Conversation
Last commit published: bfa1b198301e6973ebc2b2c9228e4d05cfde7ed2. PR PublishingThe artifacts published by this PR:
Repository DeclarationIn order to use the artifacts published by the PR, add the following repository to your buildscript: repositories {
maven {
name 'Maven for PR #884' // https://github.com/neoforged/NeoForge/pull/884
url 'https://prmaven.neoforged.net/NeoForge/pr884'
content {
includeModule('net.neoforged', 'neoforge')
includeModule('net.neoforged', 'testframework')
}
}
} MDK installationIn order to setup a MDK using the latest PR version, run the following commands in a terminal. mkdir NeoForge-pr884
cd NeoForge-pr884
curl -L https://prmaven.neoforged.net/NeoForge/pr884/net/neoforged/neoforge/20.5.22-beta-pr-884-model-data-object-qol/mdk-pr884.zip -o mdk.zip
jar xf mdk.zip
rm mdk.zip || del mdk.zip To test a production environment, you can download the installer from here. |
I am pretty sure that one should never use foreign |
You can't implement |
Why should we implement either one? |
For instance (something I came up with just now): a worker thread passing back a more populated model data object to a block entity to use for future remeshes, but only if the BE hasn't changed the base properties in that model data since the snapshot. With |
My problem would be the misuse potential. It can only be useful in cases where you are fully in control of the model data, but could easily set the wrong expectations. |
This PR adds some general quality-of-life improvements to
ModelData
, not targeting a specific use case. I also added some basic javadoc, might be redundant but no real harm in having it there.getOrDefault
was added as a companion toget
. The semantics are the same asMap#getOrDefault
.equals()
, to allow determining if two model data objects contain the same properties & values.Reference2Object
, rather thanReference2Reference
, to make sure equality of the contained values is checked byequals()
rather than==
. The keys still use identity equality, which is what matters for the hot path.ModelData
objects use distinct backing map implementations with the same contents, as theMap#equals
contract is defined to work across distinct implementations. (Also, in our case it's impossible, because we explicitly use array maps for one size range and hash maps for the rest).hashCode()
, to fulfill the contract having also implementedequals()
. As a side effect this allows usingModelData
as a key in a hashmap if desired.