Skip to content

Make #fullcube match double slabs#2952

Open
TomyLobo wants to merge 8 commits intoversion/7.4.xfrom
fullcube-double-slabs
Open

Make #fullcube match double slabs#2952
TomyLobo wants to merge 8 commits intoversion/7.4.xfrom
fullcube-double-slabs

Conversation

@TomyLobo
Copy link
Copy Markdown
Collaborator

No description provided.

@TomyLobo TomyLobo requested a review from a team as a code owner April 19, 2026 20:51
@TomyLobo TomyLobo changed the base branch from version/7.3.x to version/7.4.x April 19, 2026 20:53
if (mat == null) {
return null;
}
return materialMap.computeIfAbsent(mat, material -> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IMO we should just remove the materialMap entirely, and cache this in the BlockState using a LazyReference like BlockType already does.

Plus, the one in BlockType can be removed and replaced with a call to getDefaultState().getMaterial().

Copy link
Copy Markdown
Collaborator Author

@TomyLobo TomyLobo Apr 26, 2026

Choose a reason for hiding this comment

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

I'm not so sure about removing materialMap.
A LazyReference in BlockState would only survive as long as the BlockState does, and I'm not sure BlockStates are cached for as long as that materialMap would be.
From what I can tell, BlockStates can be created by a LazyReference in BlockType and BlockType's constructors are public, so anyone could create a new instance at any time, and, along with it, a BlockState.

Basically, every new BlockType(0).getDefaultState().getMaterial() would create a new BlockMaterial instance representing air.
With the current implementation, the materialMap deduplicates that and we get the same BlockMaterial instance each time.

On the other hand, what do we gain?

  • Do we reduce complexity?
    • Not really. We replace one field by another. I'd even argue that LazyReference is a more obscure feature than Map.computeIfAbsent.
  • Do we save memory by discarding unneeded BlockMaterial instances?
    • Most of the time, no:
      • If we use a LazyReference, BlockMaterials will be referenced by their BlockState, so they are tied to that BlockState's lifetime.
      • All BlockStates are referenced by their BlockType's internal BlockTypeStateList, so they are tied to that BlockType's lifetime.
      • BlockTypes, in turn, are mostly created on server start and held indefinitely, so nothing is ever discarded, just like with the materialMap.
      • And for user-created BlockType instances, we lose BlockMaterial deduplication, as mentioned before.

As best as I can tell, it's down to taste, so changing it is beyond the scope of this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We don't expect people to be making new BlockTypes at all, so this is acceptable. We save memory because a HashMap uses extra memory than just that required for the items in it, due to the load factor. It's also a lot faster to read two fields (the reference and its stored value) from an object we're already in, rather than do a hash lookup. Also, as soon as we hit a Java version with a stable Lazy Constants, we're likely going to replace all LazyReferences with that, so it won't be so obscure anymore.

I think we can do it outside of this PR though.

* @return the material, or null if the material information is not known
*/
@Nullable
default BlockMaterial getMaterial(BlockState blockState) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's a bit complicated, but I think this would be best as @NonAbstractForCompatibility, and getMaterial(BlockType) should be deprecated for removal.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added @NonAbstractForCompatibility and the apiNote like I saw in other places.
But I don't quite understand why getMaterial(BlockType) should be deprecated for removal.
As far as I can tell, this gets the actual nms-level default block state, whereas getMaterial(blockType.getDefaultState()) merely gets the first in the list of possible states.

I don't know if that's a distinction without a difference, but I like to understand changes before I put my name on them :)

octylFractal and others added 4 commits April 20, 2026 02:01
* create parity between //snow and //thaw

* use layer visitor + cylinder region

* fix wildcard import

* make simulate snow and thaw match javadocs
@TomyLobo TomyLobo force-pushed the fullcube-double-slabs branch from 746fccf to a9b08cf Compare April 26, 2026 12:09
@TomyLobo TomyLobo force-pushed the fullcube-double-slabs branch from a9b08cf to 96ac382 Compare April 26, 2026 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants