Skip to content

Commit 86d51a0

Browse files
committed
Limit the nbt when handling the sync compound tag
1 parent 4f718e5 commit 86d51a0

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

common/src/main/java/com/mrbysco/armorposer/data/SyncData.java

+16-7
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,32 @@
1010
import net.minecraft.world.entity.decoration.ArmorStand;
1111
import net.minecraft.world.entity.player.Player;
1212

13+
import java.util.List;
1314
import java.util.UUID;
1415

1516
public record SyncData(UUID entityUUID, CompoundTag tag) {
16-
public void encode(FriendlyByteBuf buf) {
17-
buf.writeUUID(entityUUID);
18-
buf.writeNbt(tag);
19-
}
2017

21-
public static SyncData decode(final FriendlyByteBuf packetBuffer) {
22-
return new SyncData(packetBuffer.readUUID(), packetBuffer.readNbt());
23-
}
18+
public static final StreamCodec<FriendlyByteBuf, SyncData> STREAM_CODEC = StreamCodec.composite(
19+
UUIDUtil.STREAM_CODEC,
20+
SyncData::entityUUID,
21+
ByteBufCodecs.COMPOUND_TAG,
22+
SyncData::tag,
23+
SyncData::new);
24+
private static final List<String> allowedKeys = List.of(
25+
"Invisible", "NoBasePlate", "NoGravity", "ShowArms", "Small", "CustomNameVisible", "Invulnerable",
26+
"Pose", "DisabledSlots", "Pose", "Scale", "Move", "Rotation"
27+
);
2428

2529
public void handleData(ArmorStand armorStand, Player player) {
2630
CompoundTag entityTag = armorStand.saveWithoutId(new CompoundTag());
2731
CompoundTag entityTagCopy = entityTag.copy();
2832

2933
if (!tag.isEmpty()) {
34+
List<String> keysToRemove = tag.getAllKeys().stream()
35+
.filter(key -> !allowedKeys.contains(key))
36+
.toList();
37+
keysToRemove.forEach(tag::remove);
38+
3039
entityTagCopy.merge(tag);
3140
armorStand.load(entityTagCopy);
3241
armorStand.setUUID(entityUUID);

0 commit comments

Comments
 (0)