3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 16:40:10 +01:00

Rename itemdata to be more generic

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-02-28 22:46:33 +01:00
Ursprung 2480eb6a7f
Commit aa262bb0a5
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
12 geänderte Dateien mit 46 neuen und 41 gelöschten Zeilen

Datei anzeigen

@ -115,7 +115,7 @@ public interface MappingData {
@Nullable FullMappings getRecipeSerializerMappings();
FullMappings getItemDataSerializerMappings();
FullMappings getDataComponentSerializerMappings();
@Nullable Mappings getPaintingMappings();
}

Datei anzeigen

@ -87,7 +87,7 @@ public class MappingDataBase implements MappingData {
entityMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "entities");
argumentTypeMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "argumenttypes");
recipeSerializerMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "recipe_serializers");
itemDataSerializerMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "item_serializers");
itemDataSerializerMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "data_component_type");
final ListTag unmappedParticles = unmappedIdentifierData.get("particles");
final ListTag mappedParticles = mappedIdentifierData.get("particles");
@ -241,7 +241,7 @@ public class MappingDataBase implements MappingData {
}
@Override
public @Nullable FullMappings getItemDataSerializerMappings() {
public @Nullable FullMappings getDataComponentSerializerMappings() {
return itemDataSerializerMappings;
}

Datei anzeigen

@ -20,27 +20,28 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.item;
package com.viaversion.viaversion.api.minecraft.data;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.util.IdHolder;
import com.viaversion.viaversion.util.Unit;
import io.netty.buffer.ByteBuf;
public final class ItemData<T> implements IdHolder {
public final class StructuredData<T> implements IdHolder {
private final Type<T> type;
private T value;
private int id;
public ItemData(final Type<T> type, final T value, final int id) {
public StructuredData(final Type<T> type, final T value, final int id) {
this.type = type;
this.value = value;
this.id = id;
}
public static ItemData<?> empty(final int id) {
return new ItemData<>(Type.UNIT, Unit.INSTANCE, id);
public static StructuredData<?> empty(final int id) {
// Indicates empty structures, whereas an empty optional is used to remove default values
return new StructuredData<>(Type.UNIT, Unit.INSTANCE, id);
}
public boolean isEmpty() {

Datei anzeigen

@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.minecraft.item;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.google.gson.annotations.SerializedName;
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.util.Objects;
@ -95,7 +96,7 @@ public class DataItem implements Item {
}
@Override
public Int2ObjectMap<Optional<ItemData<?>>> itemData() {
public Int2ObjectMap<Optional<StructuredData<?>>> itemData() {
return new Int2ObjectOpenHashMap<>();
}

Datei anzeigen

@ -23,13 +23,14 @@
package com.viaversion.viaversion.api.minecraft.item;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.util.Optional;
import org.checkerframework.checker.nullness.qual.Nullable;
public class DynamicItem implements Item {
private final Int2ObjectMap<Optional<ItemData<?>>> data;
private final Int2ObjectMap<Optional<StructuredData<?>>> data;
private int identifier;
private byte amount;
@ -37,7 +38,7 @@ public class DynamicItem implements Item {
this(0, (byte) 0, new Int2ObjectOpenHashMap<>());
}
public DynamicItem(int identifier, byte amount, Int2ObjectMap<Optional<ItemData<?>>> data) {
public DynamicItem(int identifier, byte amount, Int2ObjectMap<Optional<StructuredData<?>>> data) {
this.identifier = identifier;
this.amount = amount;
this.data = data;
@ -77,15 +78,16 @@ public class DynamicItem implements Item {
}
@Override
public Int2ObjectMap<Optional<ItemData<?>>> itemData() {
public Int2ObjectMap<Optional<StructuredData<?>>> itemData() {
return data;
}
public void addData(ItemData<?> data) {
public void addData(StructuredData<?> data) {
this.data.put(data.id(), Optional.of(data));
}
public void addMarkerData(int id) {
public void removeDefault(int id) {
// Empty optional to override the Minecraft default
this.data.put(id, Optional.empty());
}

Datei anzeigen

@ -23,6 +23,7 @@
package com.viaversion.viaversion.api.minecraft.item;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import java.util.Optional;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -90,7 +91,7 @@ public interface Item {
*/
void setTag(@Nullable CompoundTag tag);
Int2ObjectMap<Optional<ItemData<?>>> itemData();
Int2ObjectMap<Optional<StructuredData<?>>> itemData();
/**
* Returns a copy of the item.

Datei anzeigen

@ -24,7 +24,7 @@ package com.viaversion.viaversion.api.type.types.item;
import com.viaversion.viaversion.api.minecraft.item.DynamicItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.item.ItemData;
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
@ -34,9 +34,9 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class ItemType1_20_5 extends Type<Item> {
private final Type<ItemData<?>> dataType;
private final Type<StructuredData<?>> dataType;
public ItemType1_20_5(final Type<ItemData<?>> itemDataType) {
public ItemType1_20_5(final Type<StructuredData<?>> itemDataType) {
super(Item.class);
this.dataType = itemDataType;
}
@ -49,20 +49,20 @@ public class ItemType1_20_5 extends Type<Item> {
}
final int id = Type.VAR_INT.readPrimitive(buffer);
final Int2ObjectMap<Optional<ItemData<?>>> data = readData(buffer);
final Int2ObjectMap<Optional<StructuredData<?>>> data = readData(buffer);
return new DynamicItem(id, amount, data);
}
private Int2ObjectMap<Optional<ItemData<?>>> readData(final ByteBuf buffer) throws Exception {
private Int2ObjectMap<Optional<StructuredData<?>>> readData(final ByteBuf buffer) throws Exception {
final int valuesSize = Type.VAR_INT.readPrimitive(buffer);
final int markersSize = Type.VAR_INT.readPrimitive(buffer);
if (valuesSize == 0 && markersSize == 0) {
return new Int2ObjectOpenHashMap<>();
}
final Int2ObjectMap<Optional<ItemData<?>>> map = new Int2ObjectOpenHashMap<>(valuesSize + markersSize);
final Int2ObjectMap<Optional<StructuredData<?>>> map = new Int2ObjectOpenHashMap<>(valuesSize + markersSize);
for (int i = 0; i < valuesSize; i++) {
final ItemData<?> value = dataType.read(buffer);
final StructuredData<?> value = dataType.read(buffer);
map.put(value.id(), Optional.of(value));
}
@ -83,10 +83,10 @@ public class ItemType1_20_5 extends Type<Item> {
buffer.writeByte(object.amount());
Type.VAR_INT.writePrimitive(buffer, object.identifier());
final Int2ObjectMap<Optional<ItemData<?>>> data = object.itemData();
final Int2ObjectMap<Optional<StructuredData<?>>> data = object.itemData();
int valuesSize = 0;
int markersSize = 0;
for (final Int2ObjectMap.Entry<Optional<ItemData<?>>> entry : data.int2ObjectEntrySet()) {
for (final Int2ObjectMap.Entry<Optional<StructuredData<?>>> entry : data.int2ObjectEntrySet()) {
if (entry.getValue().isPresent()) {
valuesSize++;
} else {
@ -97,12 +97,12 @@ public class ItemType1_20_5 extends Type<Item> {
Type.VAR_INT.writePrimitive(buffer, valuesSize);
Type.VAR_INT.writePrimitive(buffer, markersSize);
for (final Int2ObjectMap.Entry<Optional<ItemData<?>>> entry : data.int2ObjectEntrySet()) {
for (final Int2ObjectMap.Entry<Optional<StructuredData<?>>> entry : data.int2ObjectEntrySet()) {
if (entry.getValue().isPresent()) {
dataType.write(buffer, entry.getValue().get());
}
}
for (final Int2ObjectMap.Entry<Optional<ItemData<?>>> entry : data.int2ObjectEntrySet()) {
for (final Int2ObjectMap.Entry<Optional<StructuredData<?>>> entry : data.int2ObjectEntrySet()) {
if (!entry.getValue().isPresent()) {
Type.VAR_INT.writePrimitive(buffer, entry.getIntKey());
}

Datei anzeigen

@ -23,39 +23,39 @@
package com.viaversion.viaversion.api.type.types.item;
import com.viaversion.viaversion.api.data.FullMappings;
import com.viaversion.viaversion.api.minecraft.item.ItemData;
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
public class ItemDataType extends Type<ItemData<?>> {
public class StructuredDataType extends Type<StructuredData<?>> {
private final Int2ObjectMap<Type<?>> types = new Int2ObjectOpenHashMap<>();
public ItemDataType() {
super(ItemData.class);
public StructuredDataType() {
super(StructuredData.class);
}
@Override
public void write(final ByteBuf buffer, final ItemData<?> object) throws Exception {
public void write(final ByteBuf buffer, final StructuredData<?> object) throws Exception {
Type.VAR_INT.writePrimitive(buffer, object.id());
object.write(buffer);
}
@Override
public ItemData<?> read(final ByteBuf buffer) throws Exception {
public StructuredData<?> read(final ByteBuf buffer) throws Exception {
final int id = Type.VAR_INT.readPrimitive(buffer);
final Type<?> type = this.types.get(id);
if (type != null) {
return readItemData(buffer, type, id);
return readData(buffer, type, id);
}
throw new IllegalArgumentException("Unknown item data type id: " + id);
}
private <T> ItemData<T> readItemData(final ByteBuf buffer, final Type<T> type, final int id) throws Exception {
return new ItemData<>(type, type.read(buffer), id);
private <T> StructuredData<T> readData(final ByteBuf buffer, final Type<T> type, final int id) throws Exception {
return new StructuredData<>(type, type.read(buffer), id);
}
public DataFiller filler(final Protocol<?, ?, ?, ?> protocol) {
@ -72,7 +72,7 @@ public class ItemDataType extends Type<ItemData<?>> {
private final boolean useMappedNames;
private DataFiller(final Protocol<?, ?, ?, ?> protocol, final boolean useMappedNames) {
this.mappings = protocol.getMappingData().getItemDataSerializerMappings();
this.mappings = protocol.getMappingData().getDataComponentSerializerMappings();
this.useMappedNames = useMappedNames;
}

Datei anzeigen

@ -28,7 +28,7 @@ import com.viaversion.viaversion.api.minecraft.metadata.types.MetaTypes1_20_5;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.ArrayType;
import com.viaversion.viaversion.api.type.types.item.ItemType1_20_5;
import com.viaversion.viaversion.api.type.types.item.ItemDataType;
import com.viaversion.viaversion.api.type.types.item.StructuredDataType;
import com.viaversion.viaversion.api.type.types.metadata.MetaListType;
import com.viaversion.viaversion.api.type.types.metadata.MetadataType;
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
@ -38,7 +38,7 @@ public final class Types1_20_5 {
// Only safe to use after protocol loading
public static final ParticleType PARTICLE = new ParticleType();
public static final ItemDataType ITEM_DATA = new ItemDataType();
public static final StructuredDataType ITEM_DATA = new StructuredDataType();
public static final Type<Item> ITEM = new ItemType1_20_5(ITEM_DATA);
public static final Type<Item[]> ITEM_ARRAY = new ArrayType<>(ITEM);

Datei anzeigen

@ -25,7 +25,7 @@ import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.DynamicItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.item.ItemData;
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2;
import com.viaversion.viaversion.api.type.types.version.Types1_20_3;
@ -202,11 +202,11 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
return;
}
item.addData(new ItemData<>(type, value, id));
item.addData(new StructuredData<>(type, value, id));
}
private int serializerId(final String type) {
return protocol.getMappingData().getItemDataSerializerMappings().mappedId(type);
return protocol.getMappingData().getDataComponentSerializerMappings().mappedId(type);
}
@Override