Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-19 14:30:16 +01:00
Start working on 24w09a
Dieser Commit ist enthalten in:
Ursprung
56b82b049a
Commit
2480eb6a7f
@ -115,5 +115,7 @@ public interface MappingData {
|
|||||||
|
|
||||||
@Nullable FullMappings getRecipeSerializerMappings();
|
@Nullable FullMappings getRecipeSerializerMappings();
|
||||||
|
|
||||||
|
FullMappings getItemDataSerializerMappings();
|
||||||
|
|
||||||
@Nullable Mappings getPaintingMappings();
|
@Nullable Mappings getPaintingMappings();
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,7 @@ public class MappingDataBase implements MappingData {
|
|||||||
protected FullMappings argumentTypeMappings;
|
protected FullMappings argumentTypeMappings;
|
||||||
protected FullMappings entityMappings;
|
protected FullMappings entityMappings;
|
||||||
protected FullMappings recipeSerializerMappings;
|
protected FullMappings recipeSerializerMappings;
|
||||||
|
protected FullMappings itemDataSerializerMappings;
|
||||||
protected ParticleMappings particleMappings;
|
protected ParticleMappings particleMappings;
|
||||||
protected Mappings blockMappings;
|
protected Mappings blockMappings;
|
||||||
protected Mappings blockStateMappings;
|
protected Mappings blockStateMappings;
|
||||||
@ -86,6 +87,7 @@ public class MappingDataBase implements MappingData {
|
|||||||
entityMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "entities");
|
entityMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "entities");
|
||||||
argumentTypeMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "argumenttypes");
|
argumentTypeMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "argumenttypes");
|
||||||
recipeSerializerMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "recipe_serializers");
|
recipeSerializerMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "recipe_serializers");
|
||||||
|
itemDataSerializerMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "item_serializers");
|
||||||
|
|
||||||
final ListTag unmappedParticles = unmappedIdentifierData.get("particles");
|
final ListTag unmappedParticles = unmappedIdentifierData.get("particles");
|
||||||
final ListTag mappedParticles = mappedIdentifierData.get("particles");
|
final ListTag mappedParticles = mappedIdentifierData.get("particles");
|
||||||
@ -238,6 +240,11 @@ public class MappingDataBase implements MappingData {
|
|||||||
return argumentTypeMappings;
|
return argumentTypeMappings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable FullMappings getItemDataSerializerMappings() {
|
||||||
|
return itemDataSerializerMappings;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable Mappings getPaintingMappings() {
|
public @Nullable Mappings getPaintingMappings() {
|
||||||
return paintingMappings;
|
return paintingMappings;
|
||||||
|
@ -24,11 +24,12 @@ package com.viaversion.viaversion.api.minecraft;
|
|||||||
|
|
||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import com.viaversion.viaversion.util.IdHolder;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public final class Particle {
|
public final class Particle implements IdHolder {
|
||||||
private final List<ParticleData<?>> arguments = new ArrayList<>(4);
|
private final List<ParticleData<?>> arguments = new ArrayList<>(4);
|
||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
@ -36,10 +37,16 @@ public final class Particle {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int id() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
public void setId(final int id) {
|
public void setId(final int id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,10 @@ package com.viaversion.viaversion.api.minecraft.item;
|
|||||||
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public class DataItem implements Item {
|
public class DataItem implements Item {
|
||||||
@ -91,6 +94,11 @@ public class DataItem implements Item {
|
|||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Int2ObjectMap<Optional<ItemData<?>>> itemData() {
|
||||||
|
return new Int2ObjectOpenHashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Item copy() {
|
public Item copy() {
|
||||||
return new DataItem(identifier, amount, data, tag);
|
return new DataItem(identifier, amount, data, tag);
|
||||||
@ -119,10 +127,10 @@ public class DataItem implements Item {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Item{" +
|
return "Item{" +
|
||||||
"identifier=" + identifier +
|
"identifier=" + identifier +
|
||||||
", amount=" + amount +
|
", amount=" + amount +
|
||||||
", data=" + data +
|
", data=" + data +
|
||||||
", tag=" + tag +
|
", tag=" + tag +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,114 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft.item;
|
||||||
|
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
|
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 int identifier;
|
||||||
|
private byte amount;
|
||||||
|
|
||||||
|
public DynamicItem() {
|
||||||
|
this(0, (byte) 0, new Int2ObjectOpenHashMap<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public DynamicItem(int identifier, byte amount, Int2ObjectMap<Optional<ItemData<?>>> data) {
|
||||||
|
this.identifier = identifier;
|
||||||
|
this.amount = amount;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int identifier() {
|
||||||
|
return identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setIdentifier(int identifier) {
|
||||||
|
this.identifier = identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int amount() {
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setAmount(int amount) {
|
||||||
|
if (amount > Byte.MAX_VALUE || amount < Byte.MIN_VALUE) {
|
||||||
|
throw new IllegalArgumentException("Invalid item amount: " + amount);
|
||||||
|
}
|
||||||
|
this.amount = (byte) amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable CompoundTag tag() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTag(@Nullable CompoundTag tag) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Int2ObjectMap<Optional<ItemData<?>>> itemData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addData(ItemData<?> data) {
|
||||||
|
this.data.put(data.id(), Optional.of(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addMarkerData(int id) {
|
||||||
|
this.data.put(id, Optional.empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Item copy() {
|
||||||
|
return new DynamicItem(identifier, amount, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(final Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
final DynamicItem that = (DynamicItem) o;
|
||||||
|
if (identifier != that.identifier) return false;
|
||||||
|
if (amount != that.amount) return false;
|
||||||
|
return data.equals(that.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = data.hashCode();
|
||||||
|
result = 31 * result + identifier;
|
||||||
|
result = 31 * result + amount;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@ -23,6 +23,8 @@
|
|||||||
package com.viaversion.viaversion.api.minecraft.item;
|
package com.viaversion.viaversion.api.minecraft.item;
|
||||||
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
|
import java.util.Optional;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public interface Item {
|
public interface Item {
|
||||||
@ -88,6 +90,8 @@ public interface Item {
|
|||||||
*/
|
*/
|
||||||
void setTag(@Nullable CompoundTag tag);
|
void setTag(@Nullable CompoundTag tag);
|
||||||
|
|
||||||
|
Int2ObjectMap<Optional<ItemData<?>>> itemData();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a copy of the item.
|
* Returns a copy of the item.
|
||||||
*
|
*
|
||||||
|
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft.item;
|
||||||
|
|
||||||
|
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 {
|
||||||
|
|
||||||
|
private final Type<T> type;
|
||||||
|
private T value;
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
public ItemData(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 boolean isEmpty() {
|
||||||
|
return type == Type.UNIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(final T value) {
|
||||||
|
if (value != null && !type.getOutputClass().isAssignableFrom(value.getClass())) {
|
||||||
|
throw new IllegalArgumentException("Item data type and value are incompatible. Type=" + type
|
||||||
|
+ ", value=" + value + " (" + value.getClass().getSimpleName() + ")");
|
||||||
|
}
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write(final ByteBuf buffer) throws Exception {
|
||||||
|
type.write(buffer, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(final int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Type<T> type() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T value() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int id() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public final class BannerPattern {
|
||||||
|
|
||||||
|
public static final Type<BannerPattern> TYPE = new Type<BannerPattern>(BannerPattern.class) {
|
||||||
|
@Override
|
||||||
|
public BannerPattern read(final ByteBuf buffer) throws Exception {
|
||||||
|
final int pattern = Type.VAR_INT.readPrimitive(buffer);
|
||||||
|
final int color = Type.VAR_INT.readPrimitive(buffer);
|
||||||
|
return new BannerPattern(pattern, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final BannerPattern value) throws Exception {
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, value.pattern);
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, value.color);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Type<BannerPattern[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||||
|
|
||||||
|
private final int pattern;
|
||||||
|
private final int color;
|
||||||
|
|
||||||
|
public BannerPattern(final int pattern, final int color) {
|
||||||
|
this.pattern = pattern;
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int pattern() {
|
||||||
|
return this.pattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int color() {
|
||||||
|
return this.color;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||||
|
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public final class Bee {
|
||||||
|
|
||||||
|
public static final Type<Bee> TYPE = new Type<Bee>(Bee.class) {
|
||||||
|
@Override
|
||||||
|
public Bee read(final ByteBuf buffer) throws Exception {
|
||||||
|
final CompoundTag entityData = Type.COMPOUND_TAG.read(buffer);
|
||||||
|
final int ticksInHive = Type.VAR_INT.readPrimitive(buffer);
|
||||||
|
final int minTicksInHive = Type.VAR_INT.readPrimitive(buffer);
|
||||||
|
return new Bee(entityData, ticksInHive, minTicksInHive);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final Bee value) throws Exception {
|
||||||
|
Type.COMPOUND_TAG.write(buffer, value.entityData);
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, value.ticksInHive);
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, value.minTicksInHive);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Type<Bee[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||||
|
|
||||||
|
private final CompoundTag entityData;
|
||||||
|
private final int ticksInHive;
|
||||||
|
private final int minTicksInHive;
|
||||||
|
|
||||||
|
public Bee(CompoundTag entityData, int ticksInHive, int minTicksInHive) {
|
||||||
|
this.entityData = entityData;
|
||||||
|
this.ticksInHive = ticksInHive;
|
||||||
|
this.minTicksInHive = minTicksInHive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompoundTag entityData() {
|
||||||
|
return entityData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ticksInHive() {
|
||||||
|
return ticksInHive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int minTicksInHive() {
|
||||||
|
return minTicksInHive;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public final class BlockStateProperties {
|
||||||
|
|
||||||
|
public static final Type<BlockStateProperties> TYPE = new Type<BlockStateProperties>(BlockStateProperties.class) {
|
||||||
|
@Override
|
||||||
|
public BlockStateProperties read(final ByteBuf buffer) throws Exception {
|
||||||
|
final int size = Type.VAR_INT.readPrimitive(buffer);
|
||||||
|
final Map<String, String> properties = new Object2ObjectOpenHashMap<>(size);
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
properties.put(Type.STRING.read(buffer), Type.STRING.read(buffer));
|
||||||
|
}
|
||||||
|
return new BlockStateProperties(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final BlockStateProperties value) throws Exception {
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, value.properties.size());
|
||||||
|
for (final Map.Entry<String, String> entry : value.properties.entrySet()) {
|
||||||
|
Type.STRING.write(buffer, entry.getKey());
|
||||||
|
Type.STRING.write(buffer, entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final Map<String, String> properties;
|
||||||
|
|
||||||
|
public BlockStateProperties(final Map<String, String> properties) {
|
||||||
|
this.properties = properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> properties() {
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public final class DyedColor {
|
||||||
|
|
||||||
|
public static final Type<DyedColor> TYPE = new Type<DyedColor>(DyedColor.class) {
|
||||||
|
@Override
|
||||||
|
public DyedColor read(final ByteBuf buffer) {
|
||||||
|
final int rgb = buffer.readInt();
|
||||||
|
final boolean showInTooltip = buffer.readBoolean();
|
||||||
|
return new DyedColor(rgb, showInTooltip);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final DyedColor value) {
|
||||||
|
buffer.writeInt(value.rgb);
|
||||||
|
buffer.writeBoolean(value.showInTooltip);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final int rgb;
|
||||||
|
private final boolean showInTooltip;
|
||||||
|
|
||||||
|
public DyedColor(final int rgb, final boolean showInTooltip) {
|
||||||
|
this.rgb = rgb;
|
||||||
|
this.showInTooltip = showInTooltip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int rgb() {
|
||||||
|
return this.rgb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean showInTooltip() {
|
||||||
|
return this.showInTooltip;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||||
|
|
||||||
|
public final class Enchantments {
|
||||||
|
|
||||||
|
public static final Type<Enchantments> TYPE = new Type<Enchantments>(Enchantments.class) {
|
||||||
|
@Override
|
||||||
|
public Enchantments read(final ByteBuf buffer) {
|
||||||
|
final Int2IntMap enchantments = new Int2IntOpenHashMap();
|
||||||
|
final int size = Type.VAR_INT.readPrimitive(buffer);
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
final int id = Type.VAR_INT.readPrimitive(buffer);
|
||||||
|
final int level = Type.VAR_INT.readPrimitive(buffer);
|
||||||
|
enchantments.put(id, level);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Enchantments(enchantments, buffer.readBoolean());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final Enchantments value) {
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, value.enchantments.size());
|
||||||
|
for (final Int2IntMap.Entry entry : value.enchantments.int2IntEntrySet()) {
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, entry.getIntValue());
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, entry.getIntValue());
|
||||||
|
}
|
||||||
|
buffer.writeBoolean(value.showInTooltip());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final Int2IntMap enchantments;
|
||||||
|
private final boolean showInTooltip;
|
||||||
|
|
||||||
|
public Enchantments(final Int2IntMap enchantments, final boolean showInTooltip) {
|
||||||
|
this.enchantments = enchantments;
|
||||||
|
this.showInTooltip = showInTooltip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Int2IntMap enchantments() {
|
||||||
|
return enchantments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean showInTooltip() {
|
||||||
|
return showInTooltip;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import java.util.UUID;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
public final class GameProfile {
|
||||||
|
|
||||||
|
public static final Type<GameProfile> TYPE = new Type<GameProfile>(GameProfile.class) {
|
||||||
|
@Override
|
||||||
|
public GameProfile read(final ByteBuf buffer) throws Exception {
|
||||||
|
final String name = Type.STRING.read(buffer);
|
||||||
|
final UUID id = Type.OPTIONAL_UUID.read(buffer);
|
||||||
|
final int propertyCount = Type.VAR_INT.readPrimitive(buffer);
|
||||||
|
final Property[] properties = new Property[propertyCount];
|
||||||
|
for (int i = 0; i < propertyCount; i++) {
|
||||||
|
final String propertyName = Type.STRING.read(buffer);
|
||||||
|
final String propertyValue = Type.STRING.read(buffer);
|
||||||
|
final String propertySignature = Type.OPTIONAL_STRING.read(buffer);
|
||||||
|
properties[i] = new Property(propertyName, propertyValue, propertySignature);
|
||||||
|
}
|
||||||
|
return new GameProfile(name, id, properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final GameProfile value) throws Exception {
|
||||||
|
Type.STRING.write(buffer, value.name);
|
||||||
|
Type.OPTIONAL_UUID.write(buffer, value.id);
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, value.properties.length);
|
||||||
|
for (final Property property : value.properties) {
|
||||||
|
Type.STRING.write(buffer, property.name);
|
||||||
|
Type.STRING.write(buffer, property.value);
|
||||||
|
Type.OPTIONAL_STRING.write(buffer, property.signature);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final UUID id;
|
||||||
|
private final Property[] properties;
|
||||||
|
|
||||||
|
public GameProfile(final String name, @Nullable final UUID id, final Property[] properties) {
|
||||||
|
this.name = name;
|
||||||
|
this.id = id;
|
||||||
|
this.properties = properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String name() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable UUID id() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Property[] properties() {
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class Property {
|
||||||
|
private final String name;
|
||||||
|
private final String value;
|
||||||
|
private final String signature;
|
||||||
|
|
||||||
|
public Property(final String name, final String value, @Nullable final String signature) {
|
||||||
|
this.name = name;
|
||||||
|
this.value = value;
|
||||||
|
this.signature = signature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String name() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String value() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String signature() {
|
||||||
|
return signature;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.minecraft.GlobalPosition;
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public final class LodestoneTarget {
|
||||||
|
|
||||||
|
public static final Type<LodestoneTarget> TYPE = new Type<LodestoneTarget>(LodestoneTarget.class) {
|
||||||
|
@Override
|
||||||
|
public LodestoneTarget read(final ByteBuf buffer) throws Exception {
|
||||||
|
final GlobalPosition position = Type.GLOBAL_POSITION.read(buffer);
|
||||||
|
final boolean tracked = buffer.readBoolean();
|
||||||
|
return new LodestoneTarget(position, tracked);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final LodestoneTarget value) throws Exception {
|
||||||
|
Type.GLOBAL_POSITION.write(buffer, value.position);
|
||||||
|
buffer.writeBoolean(value.tracked);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final GlobalPosition position;
|
||||||
|
private final boolean tracked;
|
||||||
|
|
||||||
|
public LodestoneTarget(final GlobalPosition position, final boolean tracked) {
|
||||||
|
this.position = position;
|
||||||
|
this.tracked = tracked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GlobalPosition pos() {
|
||||||
|
return this.position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean tracked() {
|
||||||
|
return this.tracked;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public final class WrittenBook {
|
||||||
|
|
||||||
|
public static final Type<WrittenBook> TYPE = new Type<WrittenBook>(WrittenBook.class) {
|
||||||
|
@Override
|
||||||
|
public WrittenBook read(final ByteBuf buffer) throws Exception {
|
||||||
|
final String title = Type.STRING.read(buffer);
|
||||||
|
final String author = Type.STRING.read(buffer);
|
||||||
|
final int generation = Type.VAR_INT.readPrimitive(buffer);
|
||||||
|
final String[] pages = Type.STRING_ARRAY.read(buffer);
|
||||||
|
final boolean resolved = buffer.readBoolean();
|
||||||
|
return new WrittenBook(title, author, generation, pages, resolved);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final WrittenBook value) throws Exception {
|
||||||
|
Type.STRING.write(buffer, value.title);
|
||||||
|
Type.STRING.write(buffer, value.author);
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, value.generation);
|
||||||
|
Type.STRING_ARRAY.write(buffer, value.pages);
|
||||||
|
buffer.writeBoolean(value.resolved);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final String title;
|
||||||
|
private final String author;
|
||||||
|
private final int generation;
|
||||||
|
private final String[] pages;
|
||||||
|
private final boolean resolved;
|
||||||
|
|
||||||
|
public WrittenBook(final String title, final String author, final int generation, final String[] pages, final boolean resolved) {
|
||||||
|
this.title = title;
|
||||||
|
this.author = author;
|
||||||
|
this.generation = generation;
|
||||||
|
this.pages = pages;
|
||||||
|
this.resolved = resolved;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String title() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String author() {
|
||||||
|
return author;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int generation() {
|
||||||
|
return generation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] pages() {
|
||||||
|
return pages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean resolved() {
|
||||||
|
return resolved;
|
||||||
|
}
|
||||||
|
}
|
@ -22,6 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.api.minecraft.metadata;
|
package com.viaversion.viaversion.api.minecraft.metadata;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
|
||||||
public interface MetaType {
|
public interface MetaType {
|
||||||
@ -49,6 +50,7 @@ public interface MetaType {
|
|||||||
private final Type<?> type;
|
private final Type<?> type;
|
||||||
|
|
||||||
MetaTypeImpl(final int typeId, final Type<?> type) {
|
MetaTypeImpl(final int typeId, final Type<?> type) {
|
||||||
|
Preconditions.checkNotNull(type);
|
||||||
this.typeId = typeId;
|
this.typeId = typeId;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.minecraft.metadata.types;
|
|||||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
|
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
|
||||||
|
import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
|
||||||
|
|
||||||
public final class MetaTypes1_20_5 extends AbstractMetaTypes {
|
public final class MetaTypes1_20_5 extends AbstractMetaTypes {
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ public final class MetaTypes1_20_5 extends AbstractMetaTypes {
|
|||||||
public final MetaType stringType = add(4, Type.STRING);
|
public final MetaType stringType = add(4, Type.STRING);
|
||||||
public final MetaType componentType = add(5, Type.TAG);
|
public final MetaType componentType = add(5, Type.TAG);
|
||||||
public final MetaType optionalComponentType = add(6, Type.OPTIONAL_TAG);
|
public final MetaType optionalComponentType = add(6, Type.OPTIONAL_TAG);
|
||||||
public final MetaType itemType = add(7, Type.ITEM1_20_2);
|
public final MetaType itemType = add(7, Types1_20_5.ITEM);
|
||||||
public final MetaType booleanType = add(8, Type.BOOLEAN);
|
public final MetaType booleanType = add(8, Type.BOOLEAN);
|
||||||
public final MetaType rotationType = add(9, Type.ROTATION);
|
public final MetaType rotationType = add(9, Type.ROTATION);
|
||||||
public final MetaType positionType = add(10, Type.POSITION1_14);
|
public final MetaType positionType = add(10, Type.POSITION1_14);
|
||||||
|
@ -83,7 +83,7 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
|
|||||||
public static final ProtocolVersion v1_20 = register(763, "1.20/1.20.1", new SubVersionRange("1.20", 0, 1));
|
public static final ProtocolVersion v1_20 = register(763, "1.20/1.20.1", new SubVersionRange("1.20", 0, 1));
|
||||||
public static final ProtocolVersion v1_20_2 = register(764, "1.20.2");
|
public static final ProtocolVersion v1_20_2 = register(764, "1.20.2");
|
||||||
public static final ProtocolVersion v1_20_3 = register(765, "1.20.3/1.20.4", new SubVersionRange("1.20", 3, 4));
|
public static final ProtocolVersion v1_20_3 = register(765, "1.20.3/1.20.4", new SubVersionRange("1.20", 3, 4));
|
||||||
public static final ProtocolVersion v1_20_5 = register(766, 177, "1.20.5");
|
public static final ProtocolVersion v1_20_5 = register(766, 178, "1.20.5");
|
||||||
public static final ProtocolVersion unknown = new ProtocolVersion(VersionType.SPECIAL, -1, -1, "UNKNOWN", null);
|
public static final ProtocolVersion unknown = new ProtocolVersion(VersionType.SPECIAL, -1, -1, "UNKNOWN", null);
|
||||||
|
|
||||||
public static ProtocolVersion register(int version, String name) {
|
public static ProtocolVersion register(int version, String name) {
|
||||||
|
@ -56,6 +56,7 @@ import com.viaversion.viaversion.api.type.types.ShortByteArrayType;
|
|||||||
import com.viaversion.viaversion.api.type.types.ShortType;
|
import com.viaversion.viaversion.api.type.types.ShortType;
|
||||||
import com.viaversion.viaversion.api.type.types.StringType;
|
import com.viaversion.viaversion.api.type.types.StringType;
|
||||||
import com.viaversion.viaversion.api.type.types.UUIDType;
|
import com.viaversion.viaversion.api.type.types.UUIDType;
|
||||||
|
import com.viaversion.viaversion.api.type.types.UnitType;
|
||||||
import com.viaversion.viaversion.api.type.types.UnsignedByteType;
|
import com.viaversion.viaversion.api.type.types.UnsignedByteType;
|
||||||
import com.viaversion.viaversion.api.type.types.UnsignedShortType;
|
import com.viaversion.viaversion.api.type.types.UnsignedShortType;
|
||||||
import com.viaversion.viaversion.api.type.types.VarIntArrayType;
|
import com.viaversion.viaversion.api.type.types.VarIntArrayType;
|
||||||
@ -87,6 +88,7 @@ import com.viaversion.viaversion.api.type.types.block.VarLongBlockChangeRecordTy
|
|||||||
import com.viaversion.viaversion.api.type.types.math.Vector3fType;
|
import com.viaversion.viaversion.api.type.types.math.Vector3fType;
|
||||||
import com.viaversion.viaversion.api.type.types.math.VectorType;
|
import com.viaversion.viaversion.api.type.types.math.VectorType;
|
||||||
import com.viaversion.viaversion.api.type.types.misc.VillagerDataType;
|
import com.viaversion.viaversion.api.type.types.misc.VillagerDataType;
|
||||||
|
import com.viaversion.viaversion.util.Unit;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,6 +98,8 @@ import java.util.UUID;
|
|||||||
*/
|
*/
|
||||||
public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
||||||
|
|
||||||
|
public static final Type<Unit> UNIT = new UnitType();
|
||||||
|
|
||||||
public static final ByteType BYTE = new ByteType();
|
public static final ByteType BYTE = new ByteType();
|
||||||
public static final UnsignedByteType UNSIGNED_BYTE = new UnsignedByteType();
|
public static final UnsignedByteType UNSIGNED_BYTE = new UnsignedByteType();
|
||||||
public static final Type<byte[]> BYTE_ARRAY_PRIMITIVE = new ByteArrayType();
|
public static final Type<byte[]> BYTE_ARRAY_PRIMITIVE = new ByteArrayType();
|
||||||
@ -149,6 +153,7 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
|||||||
public static final Type<CompoundTag> COMPOUND_TAG = new CompoundTagType();
|
public static final Type<CompoundTag> COMPOUND_TAG = new CompoundTagType();
|
||||||
public static final Type<CompoundTag> OPTIONAL_COMPOUND_TAG = new CompoundTagType.OptionalCompoundTagType();
|
public static final Type<CompoundTag> OPTIONAL_COMPOUND_TAG = new CompoundTagType.OptionalCompoundTagType();
|
||||||
public static final Type<Tag> TAG = new TagType();
|
public static final Type<Tag> TAG = new TagType();
|
||||||
|
public static final Type<Tag[]> TAG_ARRAY = new ArrayType<>(TAG);
|
||||||
public static final Type<Tag> OPTIONAL_TAG = new TagType.OptionalTagType();
|
public static final Type<Tag> OPTIONAL_TAG = new TagType.OptionalTagType();
|
||||||
@Deprecated/*(forRemoval=true)*/
|
@Deprecated/*(forRemoval=true)*/
|
||||||
public static final Type<CompoundTag> NBT = NAMED_COMPOUND_TAG;
|
public static final Type<CompoundTag> NBT = NAMED_COMPOUND_TAG;
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.type.types;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import com.viaversion.viaversion.util.Unit;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public final class UnitType extends Type<Unit> {
|
||||||
|
|
||||||
|
public UnitType() {
|
||||||
|
super(Unit.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Unit read(final ByteBuf buffer) throws Exception {
|
||||||
|
return Unit.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final Unit value) throws Exception {
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
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.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<?>> {
|
||||||
|
|
||||||
|
private final Int2ObjectMap<Type<?>> types = new Int2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
|
public ItemDataType() {
|
||||||
|
super(ItemData.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final ItemData<?> object) throws Exception {
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, object.id());
|
||||||
|
object.write(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemData<?> 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);
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataFiller filler(final Protocol<?, ?, ?, ?> protocol) {
|
||||||
|
return filler(protocol, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataFiller filler(final Protocol<?, ?, ?, ?> protocol, final boolean useMappedNames) {
|
||||||
|
return new DataFiller(protocol, useMappedNames);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class DataFiller {
|
||||||
|
|
||||||
|
private final FullMappings mappings;
|
||||||
|
private final boolean useMappedNames;
|
||||||
|
|
||||||
|
private DataFiller(final Protocol<?, ?, ?, ?> protocol, final boolean useMappedNames) {
|
||||||
|
this.mappings = protocol.getMappingData().getItemDataSerializerMappings();
|
||||||
|
this.useMappedNames = useMappedNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataFiller reader(final String identifier, final Type<?> reader) {
|
||||||
|
types.put(useMappedNames ? mappings.mappedId(identifier) : mappings.id(identifier), reader);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataFiller reader(final int id, final Type<?> type) {
|
||||||
|
types.put(id, type);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,111 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
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.type.Type;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
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 ItemType1_20_5 extends Type<Item> {
|
||||||
|
|
||||||
|
private final Type<ItemData<?>> dataType;
|
||||||
|
|
||||||
|
public ItemType1_20_5(final Type<ItemData<?>> itemDataType) {
|
||||||
|
super(Item.class);
|
||||||
|
this.dataType = itemDataType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable Item read(final ByteBuf buffer) throws Exception {
|
||||||
|
final byte amount = buffer.readByte();
|
||||||
|
if (amount <= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final int id = Type.VAR_INT.readPrimitive(buffer);
|
||||||
|
final Int2ObjectMap<Optional<ItemData<?>>> data = readData(buffer);
|
||||||
|
return new DynamicItem(id, amount, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Int2ObjectMap<Optional<ItemData<?>>> 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);
|
||||||
|
for (int i = 0; i < valuesSize; i++) {
|
||||||
|
final ItemData<?> value = dataType.read(buffer);
|
||||||
|
map.put(value.id(), Optional.of(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < markersSize; i++) {
|
||||||
|
final int key = Type.VAR_INT.readPrimitive(buffer);
|
||||||
|
map.put(key, Optional.empty());
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, @Nullable final Item object) throws Exception {
|
||||||
|
if (object == null) {
|
||||||
|
buffer.writeByte(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.writeByte(object.amount());
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, object.identifier());
|
||||||
|
|
||||||
|
final Int2ObjectMap<Optional<ItemData<?>>> data = object.itemData();
|
||||||
|
int valuesSize = 0;
|
||||||
|
int markersSize = 0;
|
||||||
|
for (final Int2ObjectMap.Entry<Optional<ItemData<?>>> entry : data.int2ObjectEntrySet()) {
|
||||||
|
if (entry.getValue().isPresent()) {
|
||||||
|
valuesSize++;
|
||||||
|
} else {
|
||||||
|
markersSize++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, valuesSize);
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, markersSize);
|
||||||
|
|
||||||
|
for (final Int2ObjectMap.Entry<Optional<ItemData<?>>> entry : data.int2ObjectEntrySet()) {
|
||||||
|
if (entry.getValue().isPresent()) {
|
||||||
|
dataType.write(buffer, entry.getValue().get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (final Int2ObjectMap.Entry<Optional<ItemData<?>>> entry : data.int2ObjectEntrySet()) {
|
||||||
|
if (!entry.getValue().isPresent()) {
|
||||||
|
Type.VAR_INT.writePrimitive(buffer, entry.getIntKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.type.types.misc;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.data.FullMappings;
|
||||||
|
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import com.viaversion.viaversion.util.IdHolder;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
|
|
||||||
|
public abstract class DynamicType<T extends IdHolder> extends Type<T> {
|
||||||
|
|
||||||
|
protected final Int2ObjectMap<DataReader<T>> readers;
|
||||||
|
|
||||||
|
protected DynamicType(final Int2ObjectMap<DataReader<T>> readers, final Class<T> outputClass) {
|
||||||
|
super(outputClass.getSimpleName(), outputClass);
|
||||||
|
this.readers = readers;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected DynamicType(final Class<T> outputClass) {
|
||||||
|
this(new Int2ObjectOpenHashMap<>(), outputClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataFiller filler(final Protocol<?, ?, ?, ?> protocol) {
|
||||||
|
return filler(protocol, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataFiller filler(final Protocol<?, ?, ?, ?> protocol, final boolean useMappedNames) {
|
||||||
|
return new DataFiller(protocol, useMappedNames);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void readData(final ByteBuf buffer, final T value) throws Exception {
|
||||||
|
final DataReader<T> reader = readers.get(value.id());
|
||||||
|
if (reader != null) {
|
||||||
|
reader.read(buffer, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class DataFiller {
|
||||||
|
|
||||||
|
private final FullMappings mappings;
|
||||||
|
private final boolean useMappedNames;
|
||||||
|
|
||||||
|
private DataFiller(final Protocol<?, ?, ?, ?> protocol, final boolean useMappedNames) {
|
||||||
|
this.mappings = mappings(protocol);
|
||||||
|
this.useMappedNames = useMappedNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataFiller reader(final String identifier, final DataReader<T> reader) {
|
||||||
|
readers.put(useMappedNames ? mappings.mappedId(identifier) : mappings.id(identifier), reader);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataFiller reader(final int id, final DataReader<T> reader) {
|
||||||
|
readers.put(id, reader);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract FullMappings mappings(Protocol<?, ?, ?, ?> protocol);
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface DataReader<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads a value from the buffer and adds it to the data.
|
||||||
|
*
|
||||||
|
* @param buf buffer
|
||||||
|
* @param value value
|
||||||
|
* @throws Exception if an error occurs during buffer reading
|
||||||
|
*/
|
||||||
|
void read(ByteBuf buf, T value) throws Exception;
|
||||||
|
}
|
||||||
|
}
|
@ -23,40 +23,23 @@
|
|||||||
package com.viaversion.viaversion.api.type.types.misc;
|
package com.viaversion.viaversion.api.type.types.misc;
|
||||||
|
|
||||||
import com.viaversion.viaversion.api.Via;
|
import com.viaversion.viaversion.api.Via;
|
||||||
import com.viaversion.viaversion.api.data.ParticleMappings;
|
import com.viaversion.viaversion.api.data.FullMappings;
|
||||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
import com.viaversion.viaversion.api.minecraft.Particle;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
import com.viaversion.viaversion.util.Key;
|
import com.viaversion.viaversion.util.Key;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
|
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
|
||||||
|
|
||||||
public class ParticleType extends Type<Particle> {
|
public class ParticleType extends DynamicType<Particle> {
|
||||||
|
|
||||||
private final Int2ObjectMap<ParticleReader> readers;
|
|
||||||
|
|
||||||
public ParticleType(final Int2ObjectMap<ParticleReader> readers) {
|
|
||||||
super("Particle", Particle.class);
|
|
||||||
this.readers = readers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ParticleType() {
|
public ParticleType() {
|
||||||
this(new Int2ObjectArrayMap<>());
|
super(Particle.class);
|
||||||
}
|
|
||||||
|
|
||||||
public ParticleTypeFiller filler(final Protocol<?, ?, ?, ?> protocol) {
|
|
||||||
return filler(protocol, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ParticleTypeFiller filler(final Protocol<?, ?, ?, ?> protocol, final boolean useMappedNames) {
|
|
||||||
return new ParticleTypeFiller(protocol, useMappedNames);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(final ByteBuf buffer, final Particle object) throws Exception {
|
public void write(final ByteBuf buffer, final Particle object) throws Exception {
|
||||||
Type.VAR_INT.writePrimitive(buffer, object.getId());
|
Type.VAR_INT.writePrimitive(buffer, object.id());
|
||||||
for (final Particle.ParticleData<?> data : object.getArguments()) {
|
for (final Particle.ParticleData<?> data : object.getArguments()) {
|
||||||
data.write(buffer);
|
data.write(buffer);
|
||||||
}
|
}
|
||||||
@ -70,32 +53,30 @@ public class ParticleType extends Type<Particle> {
|
|||||||
return particle;
|
return particle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readData(final ByteBuf buffer, final Particle particle) throws Exception {
|
@Override
|
||||||
final ParticleReader reader = readers.get(particle.getId());
|
protected FullMappings mappings(final Protocol<?, ?, ?, ?> protocol) {
|
||||||
if (reader != null) {
|
return protocol.getMappingData().getParticleMappings();
|
||||||
reader.read(buffer, particle);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ParticleReader itemHandler(final Type<Item> itemType) {
|
public static DataReader<Particle> itemHandler(final Type<Item> itemType) {
|
||||||
return (buf, particle) -> particle.add(itemType, itemType.read(buf));
|
return (buf, particle) -> particle.add(itemType, itemType.read(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class Readers {
|
public static final class Readers {
|
||||||
|
|
||||||
public static final ParticleReader BLOCK = (buf, particle) -> {
|
public static final DataReader<Particle> BLOCK = (buf, particle) -> {
|
||||||
particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Flat Block
|
particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Flat Block
|
||||||
};
|
};
|
||||||
public static final ParticleReader ITEM1_13 = itemHandler(Type.ITEM1_13);
|
public static final DataReader<Particle> ITEM1_13 = itemHandler(Type.ITEM1_13);
|
||||||
public static final ParticleReader ITEM1_13_2 = itemHandler(Type.ITEM1_13_2);
|
public static final DataReader<Particle> ITEM1_13_2 = itemHandler(Type.ITEM1_13_2);
|
||||||
public static final ParticleReader ITEM1_20_2 = itemHandler(Type.ITEM1_20_2);
|
public static final DataReader<Particle> ITEM1_20_2 = itemHandler(Type.ITEM1_20_2);
|
||||||
public static final ParticleReader DUST = (buf, particle) -> {
|
public static final DataReader<Particle> DUST = (buf, particle) -> {
|
||||||
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Red 0-1
|
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Red 0-1
|
||||||
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Green 0-1
|
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Green 0-1
|
||||||
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Blue 0-1
|
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Blue 0-1
|
||||||
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Scale 0.01-4
|
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Scale 0.01-4
|
||||||
};
|
};
|
||||||
public static final ParticleReader DUST_TRANSITION = (buf, particle) -> {
|
public static final DataReader<Particle> DUST_TRANSITION = (buf, particle) -> {
|
||||||
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Red 0-1
|
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Red 0-1
|
||||||
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Green 0-1
|
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Green 0-1
|
||||||
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Blue 0-1
|
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Blue 0-1
|
||||||
@ -104,7 +85,7 @@ public class ParticleType extends Type<Particle> {
|
|||||||
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Green
|
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Green
|
||||||
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Blue
|
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Blue
|
||||||
};
|
};
|
||||||
public static final ParticleReader VIBRATION = (buf, particle) -> {
|
public static final DataReader<Particle> VIBRATION = (buf, particle) -> {
|
||||||
particle.add(Type.POSITION1_14, Type.POSITION1_14.read(buf)); // From block pos
|
particle.add(Type.POSITION1_14, Type.POSITION1_14.read(buf)); // From block pos
|
||||||
|
|
||||||
String resourceLocation = Type.STRING.read(buf);
|
String resourceLocation = Type.STRING.read(buf);
|
||||||
@ -120,7 +101,7 @@ public class ParticleType extends Type<Particle> {
|
|||||||
}
|
}
|
||||||
particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Arrival in ticks
|
particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Arrival in ticks
|
||||||
};
|
};
|
||||||
public static final ParticleReader VIBRATION1_19 = (buf, particle) -> {
|
public static final DataReader<Particle> VIBRATION1_19 = (buf, particle) -> {
|
||||||
String resourceLocation = Type.STRING.read(buf);
|
String resourceLocation = Type.STRING.read(buf);
|
||||||
particle.add(Type.STRING, resourceLocation);
|
particle.add(Type.STRING, resourceLocation);
|
||||||
|
|
||||||
@ -135,7 +116,7 @@ public class ParticleType extends Type<Particle> {
|
|||||||
}
|
}
|
||||||
particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Arrival in ticks
|
particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Arrival in ticks
|
||||||
};
|
};
|
||||||
public static final ParticleReader VIBRATION1_20_3 = (buf, particle) -> {
|
public static final DataReader<Particle> VIBRATION1_20_3 = (buf, particle) -> {
|
||||||
final int sourceTypeId = Type.VAR_INT.readPrimitive(buf);
|
final int sourceTypeId = Type.VAR_INT.readPrimitive(buf);
|
||||||
particle.add(Type.VAR_INT, sourceTypeId);
|
particle.add(Type.VAR_INT, sourceTypeId);
|
||||||
if (sourceTypeId == 0) { // Block
|
if (sourceTypeId == 0) { // Block
|
||||||
@ -148,45 +129,11 @@ public class ParticleType extends Type<Particle> {
|
|||||||
}
|
}
|
||||||
particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Arrival in ticks
|
particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Arrival in ticks
|
||||||
};
|
};
|
||||||
public static final ParticleReader SCULK_CHARGE = (buf, particle) -> {
|
public static final DataReader<Particle> SCULK_CHARGE = (buf, particle) -> {
|
||||||
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Roll
|
particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Roll
|
||||||
};
|
};
|
||||||
public static final ParticleReader SHRIEK = (buf, particle) -> {
|
public static final DataReader<Particle> SHRIEK = (buf, particle) -> {
|
||||||
particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Delay
|
particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Delay
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public final class ParticleTypeFiller {
|
|
||||||
|
|
||||||
private final ParticleMappings mappings;
|
|
||||||
private final boolean useMappedNames;
|
|
||||||
|
|
||||||
private ParticleTypeFiller(final Protocol<?, ?, ?, ?> protocol, final boolean useMappedNames) {
|
|
||||||
this.mappings = protocol.getMappingData().getParticleMappings();
|
|
||||||
this.useMappedNames = useMappedNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ParticleTypeFiller reader(final String identifier, final ParticleReader reader) {
|
|
||||||
readers.put(useMappedNames ? mappings.mappedId(identifier) : mappings.id(identifier), reader);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ParticleTypeFiller reader(final int id, final ParticleReader reader) {
|
|
||||||
readers.put(id, reader);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface ParticleReader {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads particle data from the buffer and adds it to the particle data.
|
|
||||||
*
|
|
||||||
* @param buf buffer
|
|
||||||
* @param particle particle
|
|
||||||
* @throws Exception if an error occurs during buffer reading
|
|
||||||
*/
|
|
||||||
void read(ByteBuf buf, Particle particle) throws Exception;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,13 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.api.type.types.version;
|
package com.viaversion.viaversion.api.type.types.version;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||||
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||||
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaTypes1_20_5;
|
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaTypes1_20_5;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
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.metadata.MetaListType;
|
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.metadata.MetadataType;
|
||||||
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
|
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
|
||||||
@ -32,7 +36,12 @@ import java.util.List;
|
|||||||
|
|
||||||
public final class Types1_20_5 {
|
public final class Types1_20_5 {
|
||||||
|
|
||||||
public static final ParticleType PARTICLE = new ParticleType(); // Only safe to use after protocol loading
|
// 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 Type<Item> ITEM = new ItemType1_20_5(ITEM_DATA);
|
||||||
|
public static final Type<Item[]> ITEM_ARRAY = new ArrayType<>(ITEM);
|
||||||
|
|
||||||
public static final MetaTypes1_20_5 META_TYPES = new MetaTypes1_20_5(PARTICLE);
|
public static final MetaTypes1_20_5 META_TYPES = new MetaTypes1_20_5(PARTICLE);
|
||||||
public static final Type<Metadata> METADATA = new MetadataType(META_TYPES);
|
public static final Type<Metadata> METADATA = new MetadataType(META_TYPES);
|
||||||
public static final Type<List<Metadata>> METADATA_LIST = new MetaListType(METADATA);
|
public static final Type<List<Metadata>> METADATA_LIST = new MetaListType(METADATA);
|
||||||
|
28
api/src/main/java/com/viaversion/viaversion/util/IdHolder.java
Normale Datei
28
api/src/main/java/com/viaversion/viaversion/util/IdHolder.java
Normale Datei
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.util;
|
||||||
|
|
||||||
|
public interface IdHolder {
|
||||||
|
|
||||||
|
int id();
|
||||||
|
}
|
@ -22,8 +22,13 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.util;
|
package com.viaversion.viaversion.util;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public final class Key {
|
public final class Key {
|
||||||
|
|
||||||
|
private static final Pattern PATTERN = Pattern.compile("([0-9a-z_.-]*:)?[0-9a-z_/.-]*");
|
||||||
|
private static final int MINECRAFT_NAMESPACE_LENGTH = "minecraft:".length();
|
||||||
|
|
||||||
public static String stripNamespace(final String identifier) {
|
public static String stripNamespace(final String identifier) {
|
||||||
int index = identifier.indexOf(':');
|
int index = identifier.indexOf(':');
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
@ -34,13 +39,17 @@ public final class Key {
|
|||||||
|
|
||||||
public static String stripMinecraftNamespace(final String identifier) {
|
public static String stripMinecraftNamespace(final String identifier) {
|
||||||
if (identifier.startsWith("minecraft:")) {
|
if (identifier.startsWith("minecraft:")) {
|
||||||
return identifier.substring(10);
|
return identifier.substring(MINECRAFT_NAMESPACE_LENGTH);
|
||||||
} else if (identifier.startsWith(":")) {
|
} else if (!identifier.isEmpty() && identifier.charAt(0) == ':') {
|
||||||
return identifier.substring(1);
|
return identifier.substring(1);
|
||||||
}
|
}
|
||||||
return identifier;
|
return identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean equals(final String firstIdentifier, final String secondIdentifier) {
|
||||||
|
return stripNamespace(firstIdentifier).equals(stripNamespace(secondIdentifier));
|
||||||
|
}
|
||||||
|
|
||||||
public static String namespaced(final String identifier) {
|
public static String namespaced(final String identifier) {
|
||||||
final int index = identifier.indexOf(':');
|
final int index = identifier.indexOf(':');
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
@ -52,7 +61,6 @@ public final class Key {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isValid(final String identifier) {
|
public static boolean isValid(final String identifier) {
|
||||||
return identifier.matches("([0-9a-z_.-]*:)?[0-9a-z_/.-]*");
|
return PATTERN.matcher(identifier).matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
28
api/src/main/java/com/viaversion/viaversion/util/Unit.java
Normale Datei
28
api/src/main/java/com/viaversion/viaversion/util/Unit.java
Normale Datei
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.util;
|
||||||
|
|
||||||
|
public enum Unit {
|
||||||
|
|
||||||
|
INSTANCE
|
||||||
|
}
|
@ -19,12 +19,12 @@ package com.viaversion.viaversion.data.entity;
|
|||||||
|
|
||||||
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
|
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public final class StoredEntityDataImpl implements StoredEntityData {
|
public final class StoredEntityDataImpl implements StoredEntityData {
|
||||||
private final Map<Class<?>, Object> storedObjects = new ConcurrentHashMap<>();
|
private final Map<Class<?>, Object> storedObjects = new HashMap<>();
|
||||||
private final EntityType type;
|
private final EntityType type;
|
||||||
|
|
||||||
public StoredEntityDataImpl(EntityType type) {
|
public StoredEntityDataImpl(EntityType type) {
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.rewriter;
|
package com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.rewriter;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
@ -48,7 +49,8 @@ public class RecipeRewriter1_19_3<C extends ClientboundPacketType> extends Recip
|
|||||||
wrapper.passthrough(Type.STRING); // Group
|
wrapper.passthrough(Type.STRING); // Group
|
||||||
wrapper.passthrough(Type.VAR_INT); // Crafting book category
|
wrapper.passthrough(Type.VAR_INT); // Crafting book category
|
||||||
handleIngredients(wrapper);
|
handleIngredients(wrapper);
|
||||||
rewrite(wrapper.passthrough(itemType())); // Result
|
final Item result = rewrite(wrapper.read(itemType()));
|
||||||
|
wrapper.write(mappedItemType(), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -59,7 +61,8 @@ public class RecipeRewriter1_19_3<C extends ClientboundPacketType> extends Recip
|
|||||||
for (int i = 0; i < ingredients; i++) {
|
for (int i = 0; i < ingredients; i++) {
|
||||||
handleIngredient(wrapper);
|
handleIngredient(wrapper);
|
||||||
}
|
}
|
||||||
rewrite(wrapper.passthrough(itemType())); // Result
|
final Item result = rewrite(wrapper.read(itemType()));
|
||||||
|
wrapper.write(mappedItemType(), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -67,7 +70,8 @@ public class RecipeRewriter1_19_3<C extends ClientboundPacketType> extends Recip
|
|||||||
wrapper.passthrough(Type.STRING); // Group
|
wrapper.passthrough(Type.STRING); // Group
|
||||||
wrapper.passthrough(Type.VAR_INT); // Crafting book category
|
wrapper.passthrough(Type.VAR_INT); // Crafting book category
|
||||||
handleIngredient(wrapper);
|
handleIngredient(wrapper);
|
||||||
rewrite(wrapper.passthrough(itemType())); // Result
|
final Item result = rewrite(wrapper.read(itemType()));
|
||||||
|
wrapper.write(mappedItemType(), result);
|
||||||
wrapper.passthrough(Type.FLOAT); // EXP
|
wrapper.passthrough(Type.FLOAT); // EXP
|
||||||
wrapper.passthrough(Type.VAR_INT); // Cooking time
|
wrapper.passthrough(Type.VAR_INT); // Cooking time
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,9 @@ public class RecipeRewriter1_20_3<C extends ClientboundPacketType> extends Recip
|
|||||||
for (int i = 0; i < ingredients; i++) {
|
for (int i = 0; i < ingredients; i++) {
|
||||||
handleIngredient(wrapper);
|
handleIngredient(wrapper);
|
||||||
}
|
}
|
||||||
rewrite(wrapper.passthrough(itemType())); // Result
|
|
||||||
|
final Item item = rewrite(wrapper.read(itemType())); // Result
|
||||||
|
wrapper.write(mappedItemType(), item);
|
||||||
wrapper.passthrough(Type.BOOLEAN); // Show notification
|
wrapper.passthrough(Type.BOOLEAN); // Show notification
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,11 +22,19 @@ import com.viaversion.viaversion.api.data.MappingData;
|
|||||||
import com.viaversion.viaversion.api.data.MappingDataBase;
|
import com.viaversion.viaversion.api.data.MappingDataBase;
|
||||||
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
|
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.item.data.BannerPattern;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.item.data.Bee;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.item.data.BlockStateProperties;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.item.data.DyedColor;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.item.data.GameProfile;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.item.data.LodestoneTarget;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.item.data.WrittenBook;
|
||||||
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
|
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider;
|
import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider;
|
import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.item.data.Enchantments;
|
||||||
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
|
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
|
||||||
import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
|
import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
|
||||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||||
@ -102,15 +110,57 @@ public final class Protocol1_20_5To1_20_3 extends AbstractProtocol<ClientboundPa
|
|||||||
|
|
||||||
EntityTypes1_20_5.initialize(this);
|
EntityTypes1_20_5.initialize(this);
|
||||||
Types1_20_5.PARTICLE.filler(this)
|
Types1_20_5.PARTICLE.filler(this)
|
||||||
.reader("block", ParticleType.Readers.BLOCK)
|
.reader("block", ParticleType.Readers.BLOCK)
|
||||||
.reader("block_marker", ParticleType.Readers.BLOCK)
|
.reader("block_marker", ParticleType.Readers.BLOCK)
|
||||||
.reader("dust", ParticleType.Readers.DUST)
|
.reader("dust", ParticleType.Readers.DUST)
|
||||||
.reader("falling_dust", ParticleType.Readers.BLOCK)
|
.reader("falling_dust", ParticleType.Readers.BLOCK)
|
||||||
.reader("dust_color_transition", ParticleType.Readers.DUST_TRANSITION)
|
.reader("dust_color_transition", ParticleType.Readers.DUST_TRANSITION)
|
||||||
.reader("item", ParticleType.Readers.ITEM1_20_2)
|
.reader("item", ParticleType.Readers.ITEM1_20_2)
|
||||||
.reader("vibration", ParticleType.Readers.VIBRATION1_20_3)
|
.reader("vibration", ParticleType.Readers.VIBRATION1_20_3)
|
||||||
.reader("sculk_charge", ParticleType.Readers.SCULK_CHARGE)
|
.reader("sculk_charge", ParticleType.Readers.SCULK_CHARGE)
|
||||||
.reader("shriek", ParticleType.Readers.SHRIEK);
|
.reader("shriek", ParticleType.Readers.SHRIEK);
|
||||||
|
Types1_20_5.ITEM_DATA.filler(this)
|
||||||
|
.reader("damage", Type.VAR_INT)
|
||||||
|
.reader("unbreakable", Type.BOOLEAN)
|
||||||
|
.reader("custom_name", Type.TAG)
|
||||||
|
.reader("lore", Type.TAG_ARRAY)
|
||||||
|
.reader("enchantments", Enchantments.TYPE)
|
||||||
|
.reader("can_place_on", Type.UNIT) // TODO
|
||||||
|
.reader("can_break", Type.UNIT) // TODO
|
||||||
|
.reader("attribute_modifiers", Type.UNIT) // TODO
|
||||||
|
.reader("custom_model_data", Type.VAR_INT)
|
||||||
|
.reader("hide_additional_tooltip", Type.UNIT)
|
||||||
|
.reader("repair_cost", Type.VAR_INT)
|
||||||
|
.reader("creative_slot_lock", Type.UNIT)
|
||||||
|
.reader("enchantment_glint_override", Type.BOOLEAN)
|
||||||
|
.reader("intangible_projectile", Type.UNIT)
|
||||||
|
.reader("stored_enchantments", Enchantments.TYPE)
|
||||||
|
.reader("dyed_color", DyedColor.TYPE)
|
||||||
|
.reader("map_color", Type.INT)
|
||||||
|
.reader("map_id", Type.VAR_INT)
|
||||||
|
.reader("map_post_processing", Type.VAR_INT)
|
||||||
|
.reader("charged_projectiles", Types1_20_5.ITEM_ARRAY)
|
||||||
|
.reader("bundle_contents", Types1_20_5.ITEM_ARRAY)
|
||||||
|
.reader("potion_contents", Type.UNIT) // TODO
|
||||||
|
.reader("suspicious_stew_effects", Type.UNIT) // TODO
|
||||||
|
.reader("writable_book_content", Type.STRING_ARRAY)
|
||||||
|
.reader("written_book_content", WrittenBook.TYPE)
|
||||||
|
.reader("trim", Type.UNIT) // TODO
|
||||||
|
.reader("entity_data", Type.COMPOUND_TAG)
|
||||||
|
.reader("bucket_entity_data", Type.COMPOUND_TAG)
|
||||||
|
.reader("block_entity_data", Type.COMPOUND_TAG)
|
||||||
|
.reader("instrument", Type.VAR_INT) // TODO
|
||||||
|
.reader("lodestone_target", LodestoneTarget.TYPE)
|
||||||
|
.reader("firework_explosion", Type.UNIT) // TODO
|
||||||
|
.reader("fireworks", Type.UNIT) // TODO
|
||||||
|
.reader("profile", GameProfile.TYPE)
|
||||||
|
.reader("note_block_sound", Type.STRING)
|
||||||
|
.reader("banner_patterns", BannerPattern.ARRAY_TYPE)
|
||||||
|
.reader("base_color", Type.VAR_INT)
|
||||||
|
.reader("pot_decorations", Types1_20_5.ITEM_ARRAY)
|
||||||
|
.reader("container", Types1_20_5.ITEM_ARRAY)
|
||||||
|
.reader("block_state", BlockStateProperties.TYPE)
|
||||||
|
.reader("bees", Bee.ARRAY_TYPE);
|
||||||
|
|
||||||
tagRewriter.addTag(RegistryType.ITEM, "minecraft:dyeable", 853, 854, 855, 856, 1120);
|
tagRewriter.addTag(RegistryType.ITEM, "minecraft:dyeable", 853, 854, 855, 856, 1120);
|
||||||
}
|
}
|
||||||
@ -138,10 +188,10 @@ public final class Protocol1_20_5To1_20_3 extends AbstractProtocol<ClientboundPa
|
|||||||
@Override
|
@Override
|
||||||
protected PacketTypesProvider<ClientboundPacket1_20_3, ClientboundPacket1_20_5, ServerboundPacket1_20_3, ServerboundPacket1_20_5> createPacketTypesProvider() {
|
protected PacketTypesProvider<ClientboundPacket1_20_3, ClientboundPacket1_20_5, ServerboundPacket1_20_3, ServerboundPacket1_20_5> createPacketTypesProvider() {
|
||||||
return new SimplePacketTypesProvider<>(
|
return new SimplePacketTypesProvider<>(
|
||||||
packetTypeMap(unmappedClientboundPacketType, ClientboundPackets1_20_3.class, ClientboundConfigurationPackets1_20_3.class),
|
packetTypeMap(unmappedClientboundPacketType, ClientboundPackets1_20_3.class, ClientboundConfigurationPackets1_20_3.class),
|
||||||
packetTypeMap(mappedClientboundPacketType, ClientboundPackets1_20_5.class, ClientboundConfigurationPackets1_20_5.class),
|
packetTypeMap(mappedClientboundPacketType, ClientboundPackets1_20_5.class, ClientboundConfigurationPackets1_20_5.class),
|
||||||
packetTypeMap(mappedServerboundPacketType, ServerboundPackets1_20_3.class, ServerboundConfigurationPackets1_20_2.class),
|
packetTypeMap(mappedServerboundPacketType, ServerboundPackets1_20_3.class, ServerboundConfigurationPackets1_20_2.class),
|
||||||
packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_20_5.class, ServerboundConfigurationPackets1_20_5.class)
|
packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_20_5.class, ServerboundConfigurationPackets1_20_5.class)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,9 +18,14 @@
|
|||||||
package com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.rewriter;
|
package com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.rewriter;
|
||||||
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
|
||||||
|
import com.viaversion.viaversion.api.Via;
|
||||||
import com.viaversion.viaversion.api.data.ParticleMappings;
|
import com.viaversion.viaversion.api.data.ParticleMappings;
|
||||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
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.Item;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.item.ItemData;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
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.chunk.ChunkType1_20_2;
|
||||||
import com.viaversion.viaversion.api.type.types.version.Types1_20_3;
|
import com.viaversion.viaversion.api.type.types.version.Types1_20_3;
|
||||||
@ -34,11 +39,13 @@ import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.Serverb
|
|||||||
import com.viaversion.viaversion.rewriter.BlockRewriter;
|
import com.viaversion.viaversion.rewriter.BlockRewriter;
|
||||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||||
import com.viaversion.viaversion.util.Key;
|
import com.viaversion.viaversion.util.Key;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<ClientboundPacket1_20_3, ServerboundPacket1_20_5, Protocol1_20_5To1_20_3> {
|
public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<ClientboundPacket1_20_3, ServerboundPacket1_20_5, Protocol1_20_5To1_20_3> {
|
||||||
|
|
||||||
public BlockItemPacketRewriter1_20_5(final Protocol1_20_5To1_20_3 protocol) {
|
public BlockItemPacketRewriter1_20_5(final Protocol1_20_5To1_20_3 protocol) {
|
||||||
super(protocol, Type.ITEM1_20_2, Type.ITEM1_20_2_ARRAY);
|
super(protocol, Type.ITEM1_20_2, Type.ITEM1_20_2_ARRAY, Types1_20_5.ITEM, Types1_20_5.ITEM_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -88,7 +95,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
|||||||
particle.add(Type.VAR_INT, protocol.getMappingData().getNewBlockStateId(blockStateId));
|
particle.add(Type.VAR_INT, protocol.getMappingData().getNewBlockStateId(blockStateId));
|
||||||
} else if (mappings.isItemParticle(particleId)) {
|
} else if (mappings.isItemParticle(particleId)) {
|
||||||
final Item item = handleItemToClient(wrapper.read(Type.ITEM1_20_2));
|
final Item item = handleItemToClient(wrapper.read(Type.ITEM1_20_2));
|
||||||
particle.add(Type.ITEM1_20_2, item);
|
particle.add(Types1_20_5.ITEM, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
wrapper.write(Types1_20_5.PARTICLE, particle);
|
wrapper.write(Types1_20_5.PARTICLE, particle);
|
||||||
@ -120,9 +127,13 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
|||||||
wrapper.passthrough(Type.VAR_INT); // Container id
|
wrapper.passthrough(Type.VAR_INT); // Container id
|
||||||
final int size = wrapper.passthrough(Type.VAR_INT);
|
final int size = wrapper.passthrough(Type.VAR_INT);
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
handleItemToClient(wrapper.passthrough(Type.ITEM1_20_2)); // Input
|
final Item input = handleItemToClient(wrapper.read(Type.ITEM1_20_2));
|
||||||
handleItemToClient(wrapper.passthrough(Type.ITEM1_20_2)); // Output
|
final Item output = handleItemToClient(wrapper.read(Type.ITEM1_20_2));
|
||||||
handleItemToClient(wrapper.passthrough(Type.ITEM1_20_2)); // Second Item
|
final Item secondItem = handleItemToClient(wrapper.read(Type.ITEM1_20_2));
|
||||||
|
wrapper.write(Types1_20_5.ITEM, input);
|
||||||
|
wrapper.write(Types1_20_5.ITEM, output);
|
||||||
|
wrapper.write(Types1_20_5.ITEM, secondItem);
|
||||||
|
|
||||||
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
|
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
|
||||||
wrapper.passthrough(Type.INT); // Number of tools uses
|
wrapper.passthrough(Type.INT); // Number of tools uses
|
||||||
wrapper.passthrough(Type.INT); // Maximum number of trade uses
|
wrapper.passthrough(Type.INT); // Maximum number of trade uses
|
||||||
@ -135,7 +146,17 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
final RecipeRewriter1_20_3<ClientboundPacket1_20_3> recipeRewriter = new RecipeRewriter1_20_3<>(protocol);
|
final RecipeRewriter1_20_3<ClientboundPacket1_20_3> recipeRewriter = new RecipeRewriter1_20_3<ClientboundPacket1_20_3>(protocol) {
|
||||||
|
@Override
|
||||||
|
protected Type<Item> mappedItemType() {
|
||||||
|
return Types1_20_5.ITEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Type<Item[]> mappedItemArrayType() {
|
||||||
|
return Types1_20_5.ITEM_ARRAY;
|
||||||
|
}
|
||||||
|
};
|
||||||
protocol.registerClientbound(ClientboundPackets1_20_3.DECLARE_RECIPES, wrapper -> {
|
protocol.registerClientbound(ClientboundPackets1_20_3.DECLARE_RECIPES, wrapper -> {
|
||||||
final int size = wrapper.passthrough(Type.VAR_INT);
|
final int size = wrapper.passthrough(Type.VAR_INT);
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
@ -148,4 +169,53 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable Item handleItemToClient(@Nullable final Item item) {
|
||||||
|
if (item == null) return null;
|
||||||
|
|
||||||
|
super.handleItemToClient(item);
|
||||||
|
|
||||||
|
final CompoundTag tag = item.tag();
|
||||||
|
final DynamicItem dynamicItem = new DynamicItem(item.identifier(), (byte) item.amount(), new Int2ObjectOpenHashMap<>());
|
||||||
|
if (tag == null) {
|
||||||
|
return dynamicItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rewrite nbt to new data structures
|
||||||
|
final NumberTag damage = tag.getNumberTag("Damage");
|
||||||
|
if (damage != null) {
|
||||||
|
addData(dynamicItem, "damage", Type.VAR_INT, damage.asInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
final NumberTag repairCost = tag.getNumberTag("RepairCost");
|
||||||
|
if (repairCost != null) {
|
||||||
|
addData(dynamicItem, "repair_cost", Type.VAR_INT, repairCost.asInt());
|
||||||
|
}
|
||||||
|
return dynamicItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> void addData(final DynamicItem item, final String serializer, final Type<T> type, final T value) {
|
||||||
|
final int id = serializerId(serializer);
|
||||||
|
if (id == -1) {
|
||||||
|
Via.getPlatform().getLogger().severe("Could not find item data serializer for type " + type);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
item.addData(new ItemData<>(type, value, id));
|
||||||
|
}
|
||||||
|
|
||||||
|
private int serializerId(final String type) {
|
||||||
|
return protocol.getMappingData().getItemDataSerializerMappings().mappedId(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable Item handleItemToServer(@Nullable final Item item) {
|
||||||
|
if (item == null) return null;
|
||||||
|
|
||||||
|
super.handleItemToServer(item);
|
||||||
|
|
||||||
|
final CompoundTag tag = new CompoundTag();
|
||||||
|
return new DataItem(item.identifier(), (byte) item.amount(), (short) 0, tag);
|
||||||
|
}
|
||||||
}
|
}
|
@ -23,6 +23,7 @@ import com.viaversion.viaversion.api.minecraft.Particle;
|
|||||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||||
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
||||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||||
@ -31,14 +32,22 @@ import com.viaversion.viaversion.api.type.Type;
|
|||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public class ItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType,
|
public class ItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType,
|
||||||
T extends Protocol<C, ?, ?, S>> extends RewriterBase<T> implements com.viaversion.viaversion.api.rewriter.ItemRewriter<T> {
|
T extends Protocol<C, ?, ?, S>> extends RewriterBase<T> implements com.viaversion.viaversion.api.rewriter.ItemRewriter<T> {
|
||||||
private final Type<Item> itemType;
|
private final Type<Item> itemType;
|
||||||
|
private final Type<Item> mappedItemType;
|
||||||
private final Type<Item[]> itemArrayType;
|
private final Type<Item[]> itemArrayType;
|
||||||
|
private final Type<Item[]> mappedItemArrayType;
|
||||||
|
|
||||||
public ItemRewriter(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType) {
|
public ItemRewriter(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType, Type<Item> mappedItemType, Type<Item[]> mappedItemArrayType) {
|
||||||
super(protocol);
|
super(protocol);
|
||||||
this.itemType = itemType;
|
this.itemType = itemType;
|
||||||
this.itemArrayType = itemArrayType;
|
this.itemArrayType = itemArrayType;
|
||||||
|
this.mappedItemType = mappedItemType;
|
||||||
|
this.mappedItemArrayType = mappedItemArrayType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemRewriter(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType) {
|
||||||
|
this(protocol, itemType, itemArrayType, itemType, itemArrayType);
|
||||||
}
|
}
|
||||||
|
|
||||||
// These two methods always return the same item instance *for now*
|
// These two methods always return the same item instance *for now*
|
||||||
@ -66,8 +75,13 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
@Override
|
@Override
|
||||||
public void register() {
|
public void register() {
|
||||||
map(Type.UNSIGNED_BYTE); // Window id
|
map(Type.UNSIGNED_BYTE); // Window id
|
||||||
map(itemArrayType); // Items
|
handler(wrapper -> {
|
||||||
handler(itemArrayToClientHandler(itemArrayType));
|
Item[] items = wrapper.read(itemArrayType);
|
||||||
|
wrapper.write(mappedItemArrayType, items);
|
||||||
|
for (Item item : items) {
|
||||||
|
handleItemToClient(item);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -79,12 +93,13 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
map(Type.UNSIGNED_BYTE); // Window id
|
map(Type.UNSIGNED_BYTE); // Window id
|
||||||
map(Type.VAR_INT); // State id
|
map(Type.VAR_INT); // State id
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
Item[] items = wrapper.passthrough(itemArrayType);
|
Item[] items = wrapper.read(itemArrayType);
|
||||||
|
wrapper.write(mappedItemArrayType, items);
|
||||||
for (Item item : items) {
|
for (Item item : items) {
|
||||||
handleItemToClient(item);
|
handleItemToClient(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleItemToClient(wrapper.passthrough(itemType)); // Carried item
|
handleClientboundItem(wrapper);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -115,8 +130,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
public void register() {
|
public void register() {
|
||||||
map(Type.UNSIGNED_BYTE); // Window id
|
map(Type.UNSIGNED_BYTE); // Window id
|
||||||
map(Type.SHORT); // Slot id
|
map(Type.SHORT); // Slot id
|
||||||
map(itemType); // Item
|
handler(wrapper -> handleClientboundItem(wrapper));
|
||||||
handler(itemToClientHandler(itemType));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -128,8 +142,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
map(Type.UNSIGNED_BYTE); // Window id
|
map(Type.UNSIGNED_BYTE); // Window id
|
||||||
map(Type.VAR_INT); // State id
|
map(Type.VAR_INT); // State id
|
||||||
map(Type.SHORT); // Slot id
|
map(Type.SHORT); // Slot id
|
||||||
map(itemType); // Item
|
handler(wrapper -> handleClientboundItem(wrapper));
|
||||||
handler(itemToClientHandler(itemType));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -139,11 +152,9 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
protocol.registerClientbound(packetType, new PacketHandlers() {
|
||||||
@Override
|
@Override
|
||||||
public void register() {
|
public void register() {
|
||||||
map(Type.VAR_INT); // 0 - Entity ID
|
map(Type.VAR_INT); // Entity ID
|
||||||
map(Type.VAR_INT); // 1 - Slot ID
|
map(Type.VAR_INT); // Slot ID
|
||||||
map(itemType); // 2 - Item
|
handler(wrapper -> handleClientboundItem(wrapper));
|
||||||
|
|
||||||
handler(itemToClientHandler(itemType));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -160,7 +171,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
do {
|
do {
|
||||||
slot = wrapper.passthrough(Type.BYTE);
|
slot = wrapper.passthrough(Type.BYTE);
|
||||||
// & 0x7F into an extra variable if slot is needed
|
// & 0x7F into an extra variable if slot is needed
|
||||||
handleItemToClient(wrapper.passthrough(itemType));
|
handleClientboundItem(wrapper);
|
||||||
} while (slot < 0);
|
} while (slot < 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -172,8 +183,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
@Override
|
@Override
|
||||||
public void register() {
|
public void register() {
|
||||||
map(Type.SHORT); // 0 - Slot
|
map(Type.SHORT); // 0 - Slot
|
||||||
map(itemType); // 1 - Clicked Item
|
handler(wrapper -> handleServerboundItem(wrapper));
|
||||||
handler(itemToServerHandler(itemType));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -187,9 +197,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
map(Type.BYTE); // 2 - Button
|
map(Type.BYTE); // 2 - Button
|
||||||
map(Type.SHORT); // 3 - Action number
|
map(Type.SHORT); // 3 - Action number
|
||||||
map(Type.VAR_INT); // 4 - Mode
|
map(Type.VAR_INT); // 4 - Mode
|
||||||
map(itemType); // 5 - Clicked Item
|
handler(wrapper -> handleServerboundItem(wrapper));
|
||||||
|
|
||||||
handler(itemToServerHandler(itemType));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -209,11 +217,11 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
int length = wrapper.passthrough(Type.VAR_INT);
|
int length = wrapper.passthrough(Type.VAR_INT);
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
wrapper.passthrough(Type.SHORT); // Slot
|
wrapper.passthrough(Type.SHORT); // Slot
|
||||||
handleItemToServer(wrapper.passthrough(itemType));
|
handleServerboundItem(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carried item
|
// Carried item
|
||||||
handleItemToServer(wrapper.passthrough(itemType));
|
handleServerboundItem(wrapper);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -232,11 +240,11 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
wrapper.passthrough(Type.VAR_INT);
|
wrapper.passthrough(Type.VAR_INT);
|
||||||
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
handleItemToClient(wrapper.passthrough(itemType)); // Input
|
handleClientboundItem(wrapper); // Input
|
||||||
handleItemToClient(wrapper.passthrough(itemType)); // Output
|
handleClientboundItem(wrapper); // Output
|
||||||
|
|
||||||
if (wrapper.passthrough(Type.BOOLEAN)) { // Has second item
|
if (wrapper.passthrough(Type.BOOLEAN)) { // Has second item
|
||||||
handleItemToClient(wrapper.passthrough(itemType)); // Second Item
|
handleClientboundItem(wrapper); // Second item
|
||||||
}
|
}
|
||||||
|
|
||||||
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
|
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
|
||||||
@ -257,9 +265,9 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
wrapper.passthrough(Type.VAR_INT); // Container id
|
wrapper.passthrough(Type.VAR_INT); // Container id
|
||||||
int size = wrapper.passthrough(Type.VAR_INT);
|
int size = wrapper.passthrough(Type.VAR_INT);
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
handleItemToClient(wrapper.passthrough(itemType)); // Input
|
handleClientboundItem(wrapper); // Input
|
||||||
handleItemToClient(wrapper.passthrough(itemType)); // Output
|
handleClientboundItem(wrapper); // Output
|
||||||
handleItemToClient(wrapper.passthrough(itemType)); // Second Item
|
handleClientboundItem(wrapper); // Second item
|
||||||
|
|
||||||
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
|
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
|
||||||
wrapper.passthrough(Type.INT); // Number of tools uses
|
wrapper.passthrough(Type.INT); // Number of tools uses
|
||||||
@ -278,9 +286,9 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
wrapper.passthrough(Type.VAR_INT); // Container id
|
wrapper.passthrough(Type.VAR_INT); // Container id
|
||||||
int size = wrapper.passthrough(Type.VAR_INT);
|
int size = wrapper.passthrough(Type.VAR_INT);
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
handleItemToClient(wrapper.passthrough(itemType)); // Input
|
handleClientboundItem(wrapper); // Input
|
||||||
handleItemToClient(wrapper.passthrough(itemType)); // Output
|
handleClientboundItem(wrapper); // Output
|
||||||
handleItemToClient(wrapper.passthrough(itemType)); // Second Item
|
handleClientboundItem(wrapper); // Second item
|
||||||
|
|
||||||
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
|
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
|
||||||
wrapper.passthrough(Type.INT); // Number of tools uses
|
wrapper.passthrough(Type.INT); // Number of tools uses
|
||||||
@ -310,7 +318,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
if (wrapper.passthrough(Type.BOOLEAN)) {
|
if (wrapper.passthrough(Type.BOOLEAN)) {
|
||||||
wrapper.passthrough(Type.COMPONENT); // Title
|
wrapper.passthrough(Type.COMPONENT); // Title
|
||||||
wrapper.passthrough(Type.COMPONENT); // Description
|
wrapper.passthrough(Type.COMPONENT); // Description
|
||||||
handleItemToClient(wrapper.passthrough(itemType)); // Icon
|
handleClientboundItem(wrapper); // Icon
|
||||||
wrapper.passthrough(Type.VAR_INT); // Frame type
|
wrapper.passthrough(Type.VAR_INT); // Frame type
|
||||||
int flags = wrapper.passthrough(Type.INT); // Flags
|
int flags = wrapper.passthrough(Type.INT); // Flags
|
||||||
if ((flags & 1) != 0) {
|
if ((flags & 1) != 0) {
|
||||||
@ -354,7 +362,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
if (wrapper.passthrough(Type.BOOLEAN)) {
|
if (wrapper.passthrough(Type.BOOLEAN)) {
|
||||||
wrapper.passthrough(componentType); // Title
|
wrapper.passthrough(componentType); // Title
|
||||||
wrapper.passthrough(componentType); // Description
|
wrapper.passthrough(componentType); // Description
|
||||||
handleItemToClient(wrapper.passthrough(itemType)); // Icon
|
handleClientboundItem(wrapper); // Icon
|
||||||
wrapper.passthrough(Type.VAR_INT); // Frame type
|
wrapper.passthrough(Type.VAR_INT); // Frame type
|
||||||
int flags = wrapper.passthrough(Type.INT); // Flags
|
int flags = wrapper.passthrough(Type.INT); // Flags
|
||||||
if ((flags & 1) != 0) {
|
if ((flags & 1) != 0) {
|
||||||
@ -501,7 +509,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
int data = wrapper.read(Type.VAR_INT);
|
int data = wrapper.read(Type.VAR_INT);
|
||||||
wrapper.write(Type.VAR_INT, protocol.getMappingData().getNewBlockStateId(data));
|
wrapper.write(Type.VAR_INT, protocol.getMappingData().getNewBlockStateId(data));
|
||||||
} else if (mappings.isItemParticle(id)) {
|
} else if (mappings.isItemParticle(id)) {
|
||||||
handleItemToClient(wrapper.passthrough(itemType));
|
handleClientboundItem(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mappedId = protocol.getMappingData().getNewParticleId(id);
|
int mappedId = protocol.getMappingData().getNewParticleId(id);
|
||||||
@ -528,6 +536,16 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
return wrapper -> handleItemToServer(wrapper.get(type, 0));
|
return wrapper -> handleItemToServer(wrapper.get(type, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleClientboundItem(final PacketWrapper wrapper) throws Exception {
|
||||||
|
final Item item = handleItemToClient(wrapper.read(itemType));
|
||||||
|
wrapper.write(mappedItemType, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleServerboundItem(final PacketWrapper wrapper) throws Exception {
|
||||||
|
final Item item = handleItemToServer(wrapper.read(mappedItemType));
|
||||||
|
wrapper.write(itemType, item);
|
||||||
|
}
|
||||||
|
|
||||||
protected void rewriteParticle(Particle particle) {
|
protected void rewriteParticle(Particle particle) {
|
||||||
ParticleMappings mappings = protocol.getMappingData().getParticleMappings();
|
ParticleMappings mappings = protocol.getMappingData().getParticleMappings();
|
||||||
int id = particle.getId();
|
int id = particle.getId();
|
||||||
|
@ -95,19 +95,23 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
|
|||||||
for (int i = 0; i < ingredientsNo; i++) {
|
for (int i = 0; i < ingredientsNo; i++) {
|
||||||
handleIngredient(wrapper);
|
handleIngredient(wrapper);
|
||||||
}
|
}
|
||||||
rewrite(wrapper.passthrough(itemType())); // Result
|
|
||||||
|
final Item result = rewrite(wrapper.read(itemType()));
|
||||||
|
wrapper.write(mappedItemType(), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleCraftingShapeless(PacketWrapper wrapper) throws Exception {
|
public void handleCraftingShapeless(PacketWrapper wrapper) throws Exception {
|
||||||
wrapper.passthrough(Type.STRING); // Group
|
wrapper.passthrough(Type.STRING); // Group
|
||||||
handleIngredients(wrapper);
|
handleIngredients(wrapper);
|
||||||
rewrite(wrapper.passthrough(itemType())); // Result
|
final Item result = rewrite(wrapper.read(itemType()));
|
||||||
|
wrapper.write(mappedItemType(), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleSmelting(PacketWrapper wrapper) throws Exception {
|
public void handleSmelting(PacketWrapper wrapper) throws Exception {
|
||||||
wrapper.passthrough(Type.STRING); // Group
|
wrapper.passthrough(Type.STRING); // Group
|
||||||
handleIngredient(wrapper);
|
handleIngredient(wrapper);
|
||||||
rewrite(wrapper.passthrough(itemType())); // Result
|
final Item result = rewrite(wrapper.read(itemType()));
|
||||||
|
wrapper.write(mappedItemType(), result);
|
||||||
wrapper.passthrough(Type.FLOAT); // EXP
|
wrapper.passthrough(Type.FLOAT); // EXP
|
||||||
wrapper.passthrough(Type.VAR_INT); // Cooking time
|
wrapper.passthrough(Type.VAR_INT); // Cooking time
|
||||||
}
|
}
|
||||||
@ -115,13 +119,15 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
|
|||||||
public void handleStonecutting(PacketWrapper wrapper) throws Exception {
|
public void handleStonecutting(PacketWrapper wrapper) throws Exception {
|
||||||
wrapper.passthrough(Type.STRING); // Group
|
wrapper.passthrough(Type.STRING); // Group
|
||||||
handleIngredient(wrapper);
|
handleIngredient(wrapper);
|
||||||
rewrite(wrapper.passthrough(itemType())); // Result
|
final Item result = rewrite(wrapper.read(itemType()));
|
||||||
|
wrapper.write(mappedItemType(), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleSmithing(PacketWrapper wrapper) throws Exception {
|
public void handleSmithing(PacketWrapper wrapper) throws Exception {
|
||||||
handleIngredient(wrapper); // Base
|
handleIngredient(wrapper); // Base
|
||||||
handleIngredient(wrapper); // Addition
|
handleIngredient(wrapper); // Addition
|
||||||
rewrite(wrapper.passthrough(itemType())); // Result
|
final Item result = rewrite(wrapper.read(itemType()));
|
||||||
|
wrapper.write(mappedItemType(), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleSimpleRecipe(final PacketWrapper wrapper) throws Exception {
|
public void handleSimpleRecipe(final PacketWrapper wrapper) throws Exception {
|
||||||
@ -132,7 +138,8 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
|
|||||||
handleIngredient(wrapper); // Template
|
handleIngredient(wrapper); // Template
|
||||||
handleIngredient(wrapper); // Base
|
handleIngredient(wrapper); // Base
|
||||||
handleIngredient(wrapper); // Additions
|
handleIngredient(wrapper); // Additions
|
||||||
rewrite(wrapper.passthrough(itemType())); // Result
|
final Item result = rewrite(wrapper.read(itemType()));
|
||||||
|
wrapper.write(mappedItemType(), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleSmithingTrim(final PacketWrapper wrapper) throws Exception {
|
public void handleSmithingTrim(final PacketWrapper wrapper) throws Exception {
|
||||||
@ -141,16 +148,19 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
|
|||||||
handleIngredient(wrapper); // Additions
|
handleIngredient(wrapper); // Additions
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void rewrite(@Nullable Item item) {
|
protected @Nullable Item rewrite(@Nullable Item item) {
|
||||||
if (protocol.getItemRewriter() != null) {
|
if (protocol.getItemRewriter() != null) {
|
||||||
protocol.getItemRewriter().handleItemToClient(item);
|
return protocol.getItemRewriter().handleItemToClient(item);
|
||||||
}
|
}
|
||||||
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleIngredient(final PacketWrapper wrapper) throws Exception {
|
protected void handleIngredient(final PacketWrapper wrapper) throws Exception {
|
||||||
final Item[] items = wrapper.passthrough(itemArrayType());
|
final Item[] items = wrapper.read(itemArrayType());
|
||||||
for (final Item item : items) {
|
wrapper.write(mappedItemArrayType(), items);
|
||||||
rewrite(item);
|
for (int i = 0; i < items.length; i++) {
|
||||||
|
Item item = items[i];
|
||||||
|
items[i] = rewrite(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,4 +184,12 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
|
|||||||
protected Type<Item[]> itemArrayType() {
|
protected Type<Item[]> itemArrayType() {
|
||||||
return Type.ITEM1_13_2_ARRAY;
|
return Type.ITEM1_13_2_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Type<Item> mappedItemType() {
|
||||||
|
return itemType();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Type<Item[]> mappedItemArrayType() {
|
||||||
|
return itemArrayType();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Binäre Datei nicht angezeigt.
Binäre Datei nicht angezeigt.
Binäre Datei nicht angezeigt.
@ -1,5 +1,5 @@
|
|||||||
# Project properties - we put these here so they can be modified without causing a recompile of the build scripts
|
# Project properties - we put these here so they can be modified without causing a recompile of the build scripts
|
||||||
projectVersion=4.10.0-24w07a-SNAPSHOT
|
projectVersion=4.10.0-24w09a-SNAPSHOT
|
||||||
|
|
||||||
# Smile emoji
|
# Smile emoji
|
||||||
mcVersions=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.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
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren