|
10 | 10 | import net.minecraft.world.entity.decoration.ArmorStand;
|
11 | 11 | import net.minecraft.world.entity.player.Player;
|
12 | 12 |
|
| 13 | +import java.util.List; |
13 | 14 | import java.util.UUID;
|
14 | 15 |
|
15 | 16 | public record SyncData(UUID entityUUID, CompoundTag tag) {
|
16 |
| - public void encode(FriendlyByteBuf buf) { |
17 |
| - buf.writeUUID(entityUUID); |
18 |
| - buf.writeNbt(tag); |
19 |
| - } |
20 | 17 |
|
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 | + ); |
24 | 28 |
|
25 | 29 | public void handleData(ArmorStand armorStand, Player player) {
|
26 | 30 | CompoundTag entityTag = armorStand.saveWithoutId(new CompoundTag());
|
27 | 31 | CompoundTag entityTagCopy = entityTag.copy();
|
28 | 32 |
|
29 | 33 | if (!tag.isEmpty()) {
|
| 34 | + List<String> keysToRemove = tag.getAllKeys().stream() |
| 35 | + .filter(key -> !allowedKeys.contains(key)) |
| 36 | + .toList(); |
| 37 | + keysToRemove.forEach(tag::remove); |
| 38 | + |
30 | 39 | entityTagCopy.merge(tag);
|
31 | 40 | armorStand.load(entityTagCopy);
|
32 | 41 | armorStand.setUUID(entityUUID);
|
|
0 commit comments