Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 08:30:09 +01:00
Prepare class for structured data->tag rewriting
Dieser Commit ist enthalten in:
Ursprung
bfab9b0c11
Commit
666b204ebb
@ -66,14 +66,14 @@ public class ItemType1_20_5 extends Type<Item> {
|
||||
for (int i = 0; i < valuesSize; i++) {
|
||||
final StructuredData<?> value = dataType.read(buffer);
|
||||
final StructuredDataKey<?> key = dataType.key(value.id());
|
||||
Preconditions.checkNotNull(key, "No data component serializer found for $s", value);
|
||||
Preconditions.checkNotNull(key, "No data component serializer found for %s", value);
|
||||
map.put(key, value);
|
||||
}
|
||||
|
||||
for (int i = 0; i < markersSize; i++) {
|
||||
final int id = Type.VAR_INT.readPrimitive(buffer);
|
||||
final StructuredDataKey<?> key = dataType.key(id);
|
||||
Preconditions.checkNotNull(key, "No data component serializer found for empty id $s", id);
|
||||
Preconditions.checkNotNull(key, "No data component serializer found for empty id %s", id);
|
||||
map.put(key, StructuredData.empty(key, id));
|
||||
}
|
||||
return map;
|
||||
|
@ -82,7 +82,6 @@ import com.viaversion.viaversion.util.Key;
|
||||
import com.viaversion.viaversion.util.UUIDUtil;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -250,7 +249,9 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
return dataItem;
|
||||
}
|
||||
|
||||
// TODO
|
||||
for (final StructuredData<?> structuredData : data.data().values()) {
|
||||
StructuredDataConverter.rewrite(structuredData, tag);
|
||||
}
|
||||
|
||||
return dataItem;
|
||||
}
|
||||
@ -395,14 +396,15 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
// TODO
|
||||
// StructuredDataKey.CAN_PLACE_ON
|
||||
// StructuredDataKey.CAN_BREAK
|
||||
// StructuredDataKey.CREATIVE_SLOT_LOCK
|
||||
// StructuredDataKey.INTANGIBLE_PROJECTILE
|
||||
// StructuredDataKey.NOTE_BLOCK_SOUND
|
||||
// (remaining ones should only affect non-essential item tooltip, or not be shown/checked at all)
|
||||
// StructuredDataKey.POT_DECORATIONS
|
||||
// StructuredDataKey.CONTAINER
|
||||
// StructuredDataKey.CONTAINER_LOOT
|
||||
// StructuredDataKey.INTANGIBLE_PROJECTILE
|
||||
// StructuredDataKey.CREATIVE_SLOT_LOCK
|
||||
// StructuredDataKey.BEES
|
||||
// StructuredDataKey.LOCK
|
||||
// StructuredDataKey.CONTAINER_LOOT
|
||||
// StructuredDataKey.NOTE_BLOCK_SOUND
|
||||
|
||||
data.set(StructuredDataKey.CUSTOM_DATA, tag);
|
||||
return item;
|
||||
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.rewriter;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
final class StructuredDataConverter {
|
||||
|
||||
private static final Map<StructuredDataKey<?>, Rewriter<?>> REWRITERS = new Reference2ObjectOpenHashMap<>();
|
||||
|
||||
static {
|
||||
// TODO
|
||||
register(StructuredDataKey.CUSTOM_NAME, (data, tag) -> tag.putString("CustomName", ComponentUtil.tagToJsonString(data.value())));
|
||||
}
|
||||
|
||||
public static <T> void rewrite(final StructuredData<T> data, final CompoundTag tag) {
|
||||
if (data.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//noinspection unchecked
|
||||
final Rewriter<T> rewriter = (Rewriter<T>) REWRITERS.get(data.key());
|
||||
if (rewriter != null) {
|
||||
rewriter.rewrite(data, tag);
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> void register(final StructuredDataKey<T> key, final Rewriter<T> rewriter) {
|
||||
REWRITERS.put(key, rewriter);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface Rewriter<T> {
|
||||
|
||||
void rewrite(StructuredData<T> data, CompoundTag tag);
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren