SPIGOT-7654: ItemStack#isSimilar does not work with empty BlockStateMeta

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot 2024-05-02 21:22:32 +10:00
parent 54dd884d80
commit de3b4d1800
3 changed files with 36 additions and 36 deletions

View File

@ -49,7 +49,18 @@
return nbttagcompound;
}
@@ -265,7 +289,7 @@
@@ -260,12 +284,18 @@
}
public final void applyComponents(DataComponentMap datacomponentmap, DataComponentPatch datacomponentpatch) {
+ // CraftBukkit start
+ this.applyComponentsSet(datacomponentmap, datacomponentpatch);
+ }
+
+ public final Set<DataComponentType<?>> applyComponentsSet(DataComponentMap datacomponentmap, DataComponentPatch datacomponentpatch) {
+ // CraftBukkit end
final Set<DataComponentType<?>> set = new HashSet();
set.add(DataComponents.BLOCK_ENTITY_DATA);
final PatchedDataComponentMap patcheddatacomponentmap = PatchedDataComponentMap.fromPatch(datacomponentmap, datacomponentpatch);
@ -58,7 +69,18 @@
@Nullable
@Override
public <T> T get(DataComponentType<T> datacomponenttype) {
@@ -317,6 +341,15 @@
@@ -283,6 +313,10 @@
DataComponentPatch datacomponentpatch1 = datacomponentpatch.forget(set::contains);
this.components = datacomponentpatch1.split().added();
+ // CraftBukkit start
+ set.remove(DataComponents.BLOCK_ENTITY_DATA); // Remove as never actually added by applyImplicitComponents
+ return set;
+ // CraftBukkit end
}
protected void collectImplicitComponents(DataComponentMap.a datacomponentmap_a) {}
@@ -317,6 +351,15 @@
}
}

View File

@ -1,8 +1,10 @@
package org.bukkit.craftbukkit.block;
import java.util.Set;
import net.minecraft.core.IRegistryCustom;
import net.minecraft.core.component.DataComponentMap;
import net.minecraft.core.component.DataComponentPatch;
import net.minecraft.core.component.DataComponentType;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.PacketListenerPlayOut;
@ -60,9 +62,10 @@ public class CraftBlockEntityState<T extends TileEntity> extends CraftBlockState
return snapshot;
}
public void applyComponents(DataComponentMap datacomponentmap, DataComponentPatch datacomponentpatch) {
snapshot.applyComponents(datacomponentmap, datacomponentpatch);
public Set<DataComponentType<?>> applyComponents(DataComponentMap datacomponentmap, DataComponentPatch datacomponentpatch) {
Set<DataComponentType<?>> result = snapshot.applyComponentsSet(datacomponentmap, datacomponentpatch);
load(snapshot);
return result;
}
public DataComponentMap collectComponents() {

View File

@ -4,8 +4,6 @@ import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import net.minecraft.core.BlockPosition;
@ -137,32 +135,6 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
Material.VAULT
);
private static final class TrackedDataComponentMap implements DataComponentMap {
private final Set<DataComponentType<?>> seen = new HashSet<>();
private final DataComponentMap handle;
public TrackedDataComponentMap(DataComponentMap map) {
this.handle = map;
}
@Override
public <T> T get(DataComponentType<? extends T> type) {
seen.add(type);
return handle.get(type);
}
@Override
public Set<DataComponentType<?>> keySet() {
return handle.keySet();
}
@Override
public Iterator<TypedDataComponent<?>> iterator() {
return handle.iterator();
}
}
static {
// Add shulker boxes to the list of block state materials too
BLOCK_STATE_MATERIALS.addAll(SHULKER_BOX_MATERIALS);
@ -198,6 +170,7 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
});
if (!tag.isEmpty()) {
CraftBlockEntityState<?> blockEntityTag = this.blockEntityTag;
if (blockEntityTag == null) {
blockEntityTag = getBlockState(material, null);
}
@ -205,14 +178,16 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
// Convert to map
PatchedDataComponentMap map = new PatchedDataComponentMap(DataComponentMap.EMPTY);
map.applyPatch(tag);
// Setup tracking
TrackedDataComponentMap track = new TrackedDataComponentMap(map);
// Apply
blockEntityTag.applyComponents(track, tag);
Set<DataComponentType<?>> applied = blockEntityTag.applyComponents(map, tag);
// Mark applied components as handled
for (DataComponentType<?> seen : track.seen) {
for (DataComponentType<?> seen : applied) {
unhandledTags.clear(seen);
}
// Only set blockEntityTag if something was applied
if (!applied.isEmpty()) {
this.blockEntityTag = blockEntityTag;
}
}
}