Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2025-01-11 23:51:00 +01:00
Keep empty items in CONTAINER in 1.20.3->1.20.5 (#4338)
Dieser Commit ist enthalten in:
Ursprung
a92e75b8cc
Commit
d05bdd9eda
@ -101,11 +101,13 @@ import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
import com.viaversion.viaversion.util.Either;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import com.viaversion.viaversion.util.MathUtil;
|
||||
import com.viaversion.viaversion.util.SerializerVersion;
|
||||
import com.viaversion.viaversion.util.UUIDUtil;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -557,9 +559,9 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
|
||||
updateMobTags(data, tag);
|
||||
|
||||
updateItemList(connection, data, tag, "ChargedProjectiles", StructuredDataKey.CHARGED_PROJECTILES1_20_5, false);
|
||||
updateItemList(connection, data, tag, "ChargedProjectiles", StructuredDataKey.CHARGED_PROJECTILES1_20_5);
|
||||
if (old.identifier() == 927) {
|
||||
updateItemList(connection, data, tag, "Items", StructuredDataKey.BUNDLE_CONTENTS1_20_5, false);
|
||||
updateItemList(connection, data, tag, "Items", StructuredDataKey.BUNDLE_CONTENTS1_20_5);
|
||||
}
|
||||
|
||||
updateEnchantments(data, tag, "Enchantments", StructuredDataKey.ENCHANTMENTS, (hideFlagsValue & StructuredDataConverter.HIDE_ENCHANTMENTS) == 0);
|
||||
@ -1224,13 +1226,13 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
}
|
||||
|
||||
private void updateItemList(final UserConnection connection, final StructuredDataContainer data, final CompoundTag tag,
|
||||
final String key, final StructuredDataKey<Item[]> dataKey, final boolean allowEmpty) {
|
||||
final String key, final StructuredDataKey<Item[]> dataKey) {
|
||||
final ListTag<CompoundTag> itemsTag = tag.getListTag(key, CompoundTag.class);
|
||||
if (itemsTag != null) {
|
||||
final Item[] items = itemsTag.stream()
|
||||
.limit(256)
|
||||
.map(item -> itemFromTag(connection, item))
|
||||
.filter(item -> allowEmpty || !item.isEmpty())
|
||||
.filter(item -> !item.isEmpty())
|
||||
.toArray(Item[]::new);
|
||||
data.set(dataKey, items);
|
||||
}
|
||||
@ -1486,8 +1488,36 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
data.set(StructuredDataKey.BASE_COLOR, baseColorIntTag.asInt());
|
||||
}
|
||||
|
||||
if (tag.contains("Items")) {
|
||||
updateItemList(connection, data, tag, "Items", StructuredDataKey.CONTAINER1_20_5, true);
|
||||
final ListTag<CompoundTag> itemsTag = tag.getListTag("Items", CompoundTag.class);
|
||||
if (itemsTag != null) {
|
||||
int highestSlot = 0;
|
||||
|
||||
for (int i = 0, size = Math.min(itemsTag.size(), 256); i < size; i++) {
|
||||
final CompoundTag itemTag = itemsTag.get(i);
|
||||
final Item item = itemFromTag(connection, itemTag);
|
||||
if (item.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final int slot = itemTag.getByte("Slot");
|
||||
highestSlot = MathUtil.clamp(slot, highestSlot, 255);
|
||||
}
|
||||
|
||||
final Item[] filteredItems = new Item[highestSlot + 1];
|
||||
Arrays.fill(filteredItems, StructuredItem.empty());
|
||||
for (final CompoundTag itemTag : itemsTag) {
|
||||
final Item item = itemFromTag(connection, itemTag);
|
||||
if (item.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final int slot = itemTag.getByte("Slot");
|
||||
if (slot >= 0 && slot < filteredItems.length) {
|
||||
filteredItems[slot] = item;
|
||||
}
|
||||
}
|
||||
|
||||
data.set(StructuredDataKey.CONTAINER1_20_5, filteredItems);
|
||||
addBlockEntityId(tag, "shulker_box"); // Won't happen to the others and doesn't actually have to be correct otherwise
|
||||
}
|
||||
}
|
||||
|
@ -849,12 +849,18 @@ public class ComponentRewriter1_20_5<C extends ClientboundPacketType> extends Co
|
||||
|
||||
protected ListTag<CompoundTag> convertContainer(final UserConnection connection, final Item[] value) {
|
||||
final ListTag<CompoundTag> tag = new ListTag<>(CompoundTag.class);
|
||||
final ListTag<CompoundTag> items = convertItemArray(connection, value);
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
for (int i = 0; i < value.length; i++) {
|
||||
final Item item = value[i];
|
||||
if (item.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final CompoundTag slotTag = new CompoundTag();
|
||||
final CompoundTag itemTag = new CompoundTag();
|
||||
itemTag.putInt("slot", i);
|
||||
itemTag.put("item", items.get(i));
|
||||
tag.add(itemTag);
|
||||
convertItem(connection, itemTag, item);
|
||||
slotTag.putInt("slot", i);
|
||||
slotTag.put("item", itemTag);
|
||||
tag.add(slotTag);
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
@ -967,7 +973,10 @@ public class ComponentRewriter1_20_5<C extends ClientboundPacketType> extends Co
|
||||
tag.putInt("count", 1);
|
||||
}
|
||||
final Map<StructuredDataKey<?>, StructuredData<?>> components = item.dataContainer().data();
|
||||
tag.put("components", toTag(connection, components, true));
|
||||
final CompoundTag componentsTag = toTag(connection, components, true);
|
||||
if (!componentsTag.isEmpty()) {
|
||||
tag.put("components", componentsTag);
|
||||
}
|
||||
}
|
||||
|
||||
protected void convertFilterableString(final CompoundTag tag, final FilterableString string, final int max) {
|
||||
|
@ -2,7 +2,7 @@
|
||||
projectVersion=5.2.2-SNAPSHOT
|
||||
|
||||
# Smile emoji
|
||||
mcVersions=1.21.4,1.21.3,1.21.2,1.21.1,1.21,1.20.6,1.20.5,1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10, 1.9.4, 1.9.3, 1.9.2, 1.9.1, 1.9, 1.8.9
|
||||
mcVersions=1.21.4, 1.21.3, 1.21.2, 1.21.1, 1.21, 1.20.6, 1.20.5, 1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10, 1.9.4, 1.9.3, 1.9.2, 1.9.1, 1.9, 1.8.9
|
||||
mcVersionRange=1.8-1.21.4
|
||||
velocityVersion=3.4
|
||||
|
||||
|
0
sponge/build.gradle.kts
Normale Datei
0
sponge/build.gradle.kts
Normale Datei
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren