Make BlockDataMeta#setBlockData hide unspecified states

This commit is contained in:
md_5 2024-11-23 21:08:50 +11:00
parent dd08a71208
commit e9447dc5e5
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
2 changed files with 7 additions and 3 deletions

View File

@ -253,10 +253,14 @@ public class CraftBlockData implements BlockData {
return stateString.toString(); return stateString.toString();
} }
public Map<String, String> toStates() { public Map<String, String> toStates(boolean hideUnspecified) {
return (hideUnspecified && parsedStates != null) ? toStates(parsedStates) : toStates(state.getValues());
}
private static Map<String, String> toStates(Map<IBlockState<?>, Comparable<?>> states) {
Map<String, String> compound = new HashMap<>(); Map<String, String> compound = new HashMap<>();
for (Map.Entry<IBlockState<?>, Comparable<?>> entry : state.getValues().entrySet()) { for (Map.Entry<IBlockState<?>, Comparable<?>> entry : states.entrySet()) {
IBlockState iblockstate = (IBlockState) entry.getKey(); IBlockState iblockstate = (IBlockState) entry.getKey();
compound.put(iblockstate.getName(), iblockstate.getName(entry.getValue())); compound.put(iblockstate.getName(), iblockstate.getName(entry.getValue()));

View File

@ -1318,7 +1318,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
@Override @Override
public void setBlockData(BlockData blockData) { public void setBlockData(BlockData blockData) {
this.blockData = (blockData == null) ? null : ((CraftBlockData) blockData).toStates(); this.blockData = (blockData == null) ? null : ((CraftBlockData) blockData).toStates(true);
} }
@Override @Override