Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-20 06:50:08 +01:00
Explain backup tags (#1)
Dieser Commit ist enthalten in:
Ursprung
4b780b92ee
Commit
7932b79080
@ -509,6 +509,15 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int unmappedItemId(final String name) {
|
||||||
|
return protocol.getMappingData().itemId(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int toMappedItemId(final String name) {
|
||||||
|
final int unmappedId = unmappedItemId(name);
|
||||||
|
return unmappedId != -1 ? protocol.getMappingData().getNewItemId(unmappedId) : -1;
|
||||||
|
}
|
||||||
|
|
||||||
private void restoreFromBackupTag(final CompoundTag backupTag, final StructuredDataContainer data) {
|
private void restoreFromBackupTag(final CompoundTag backupTag, final StructuredDataContainer data) {
|
||||||
final CompoundTag instrument = backupTag.getCompoundTag("instrument");
|
final CompoundTag instrument = backupTag.getCompoundTag("instrument");
|
||||||
if (instrument != null) {
|
if (instrument != null) {
|
||||||
@ -586,7 +595,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
|||||||
final CompoundTag soundEventCompound = (CompoundTag) soundEventTag;
|
final CompoundTag soundEventCompound = (CompoundTag) soundEventTag;
|
||||||
final StringTag identifier = soundEventCompound.getStringTag("identifier");
|
final StringTag identifier = soundEventCompound.getStringTag("identifier");
|
||||||
if (identifier == null) {
|
if (identifier == null) {
|
||||||
return; // Nothing we can do about
|
return;
|
||||||
}
|
}
|
||||||
soundEvent = Holder.of(new SoundEvent(
|
soundEvent = Holder.of(new SoundEvent(
|
||||||
identifier.getValue(),
|
identifier.getValue(),
|
||||||
@ -594,7 +603,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
|||||||
soundEventCompound.getFloat("fixed_range") : null
|
soundEventCompound.getFloat("fixed_range") : null
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
return; // Nothing we can do about
|
return;
|
||||||
}
|
}
|
||||||
data.set(StructuredDataKey.INSTRUMENT, Holder.of(new Instrument(soundEvent, useDuration, range)));
|
data.set(StructuredDataKey.INSTRUMENT, Holder.of(new Instrument(soundEvent, useDuration, range)));
|
||||||
}
|
}
|
||||||
@ -613,7 +622,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
|||||||
for (final CompoundTag effect : possibleEffectsTag) {
|
for (final CompoundTag effect : possibleEffectsTag) {
|
||||||
final CompoundTag potionEffectTag = effect.getCompoundTag("effect");
|
final CompoundTag potionEffectTag = effect.getCompoundTag("effect");
|
||||||
if (potionEffectTag == null) {
|
if (potionEffectTag == null) {
|
||||||
continue; // Nothing we can do about
|
continue;
|
||||||
}
|
}
|
||||||
possibleEffects.add(new FoodEffect(
|
possibleEffects.add(new FoodEffect(
|
||||||
new PotionEffect(
|
new PotionEffect(
|
||||||
@ -643,7 +652,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (blocks == null) {
|
if (blocks == null) {
|
||||||
continue; // Nothing we can do about
|
continue;
|
||||||
}
|
}
|
||||||
rules.add(new ToolRule(
|
rules.add(new ToolRule(
|
||||||
blocks,
|
blocks,
|
||||||
@ -663,7 +672,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
|||||||
for (final CompoundTag tag : bannerPatterns) {
|
for (final CompoundTag tag : bannerPatterns) {
|
||||||
final CompoundTag patternTag = tag.getCompoundTag("pattern");
|
final CompoundTag patternTag = tag.getCompoundTag("pattern");
|
||||||
if (patternTag == null) {
|
if (patternTag == null) {
|
||||||
continue; // Nothing we can do about
|
continue;
|
||||||
}
|
}
|
||||||
final String assetId = patternTag.getString("asset_id");
|
final String assetId = patternTag.getString("asset_id");
|
||||||
final String translationKey = patternTag.getString("translation_key");
|
final String translationKey = patternTag.getString("translation_key");
|
||||||
@ -673,15 +682,6 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
|||||||
data.set(StructuredDataKey.BANNER_PATTERNS, patternLayer.toArray(new BannerPatternLayer[0]));
|
data.set(StructuredDataKey.BANNER_PATTERNS, patternLayer.toArray(new BannerPatternLayer[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
private int unmappedItemId(final String name) {
|
|
||||||
return protocol.getMappingData().itemId(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int toMappedItemId(final String name) {
|
|
||||||
final int unmappedId = unmappedItemId(name);
|
|
||||||
return unmappedId != -1 ? protocol.getMappingData().getNewItemId(unmappedId) : -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private AdventureModePredicate updateBlockPredicates(final ListTag<StringTag> tag, final boolean showInTooltip) {
|
private AdventureModePredicate updateBlockPredicates(final ListTag<StringTag> tag, final boolean showInTooltip) {
|
||||||
final BlockPredicate[] predicates = tag.stream()
|
final BlockPredicate[] predicates = tag.stream()
|
||||||
.map(StringTag::getValue)
|
.map(StringTag::getValue)
|
||||||
|
@ -79,9 +79,13 @@ public final class StructuredDataConverter {
|
|||||||
static final int HIDE_DYE_COLOR = 1 << 6;
|
static final int HIDE_DYE_COLOR = 1 << 6;
|
||||||
static final int HIDE_ARMOR_TRIM = 1 << 7;
|
static final int HIDE_ARMOR_TRIM = 1 << 7;
|
||||||
|
|
||||||
// Can't do nicely
|
// Store invalid/inconvertible data in the backup tag and later
|
||||||
|
// restore it when converting back to the original version
|
||||||
private static final String BACKUP_TAG_KEY = "VV|DataComponents";
|
private static final String BACKUP_TAG_KEY = "VV|DataComponents";
|
||||||
private static final String ITEM_BACKUP_TAG_KEY = "VV|id";
|
|
||||||
|
// Store item ids separately to avoid copying whole data tree
|
||||||
|
// just for the item id
|
||||||
|
private static final String ITEM_BACKUP_TAG_KEY = "VV|Id";
|
||||||
|
|
||||||
private final Map<StructuredDataKey<?>, DataConverter<?>> rewriters = new Reference2ObjectOpenHashMap<>();
|
private final Map<StructuredDataKey<?>, DataConverter<?>> rewriters = new Reference2ObjectOpenHashMap<>();
|
||||||
private final boolean backupInconvertibleData;
|
private final boolean backupInconvertibleData;
|
||||||
@ -301,8 +305,8 @@ public final class StructuredDataConverter {
|
|||||||
for (final int id : data.itemIds()) {
|
for (final int id : data.itemIds()) {
|
||||||
final String name = toMappedItemName(id);
|
final String name = toMappedItemName(id);
|
||||||
if (name.isEmpty()) {
|
if (name.isEmpty()) {
|
||||||
// Backup whole data if one of the sherds is inconvertible
|
// Backup whole data if one of the entries is inconvertible
|
||||||
// Since we don't want to break the order of the sherds
|
// Since we don't want to break the order of the entries
|
||||||
if (backupInconvertibleData && originalSherds == null) {
|
if (backupInconvertibleData && originalSherds == null) {
|
||||||
originalSherds = new IntArrayTag(data.itemIds());
|
originalSherds = new IntArrayTag(data.itemIds());
|
||||||
}
|
}
|
||||||
@ -410,8 +414,8 @@ public final class StructuredDataConverter {
|
|||||||
register(StructuredDataKey.BANNER_PATTERNS, (data, tag) -> {
|
register(StructuredDataKey.BANNER_PATTERNS, (data, tag) -> {
|
||||||
final ListTag<CompoundTag> originalPatterns = new ListTag<>(CompoundTag.class);
|
final ListTag<CompoundTag> originalPatterns = new ListTag<>(CompoundTag.class);
|
||||||
if (backupInconvertibleData) {
|
if (backupInconvertibleData) {
|
||||||
// Backup whole data if one of the patterns is inconvertible
|
// Backup whole data if one of the entries is inconvertible
|
||||||
// Since we don't want to break the order of the patterns
|
// Since we don't want to break the order of the entries
|
||||||
if (Arrays.stream(data).anyMatch(layer -> layer.pattern().isDirect())) {
|
if (Arrays.stream(data).anyMatch(layer -> layer.pattern().isDirect())) {
|
||||||
for (final BannerPatternLayer layer : data) {
|
for (final BannerPatternLayer layer : data) {
|
||||||
final CompoundTag layerTag = new CompoundTag();
|
final CompoundTag layerTag = new CompoundTag();
|
||||||
@ -645,6 +649,7 @@ public final class StructuredDataConverter {
|
|||||||
return backupTag;
|
return backupTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if item name could be mapped, if not, locate original/backup item id and use it
|
||||||
static int removeItemBackupTag(final CompoundTag tag, final int unmappedId) {
|
static int removeItemBackupTag(final CompoundTag tag, final int unmappedId) {
|
||||||
if (unmappedId != -1) {
|
if (unmappedId != -1) {
|
||||||
return unmappedId;
|
return unmappedId;
|
||||||
@ -674,8 +679,10 @@ public final class StructuredDataConverter {
|
|||||||
} else {
|
} else {
|
||||||
for (final int id : holders.ids()) {
|
for (final int id : holders.ids()) {
|
||||||
final String name = toMappedItemName(id);
|
final String name = toMappedItemName(id);
|
||||||
if (backupInconvertibleData && name.isEmpty()) {
|
if (name.isEmpty()) {
|
||||||
// TODO HANDLE
|
if (backupInconvertibleData) {
|
||||||
|
// TODO Backup
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
predicatedListTag.add(serializeBlockPredicate(predicate, name));
|
predicatedListTag.add(serializeBlockPredicate(predicate, name));
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren