mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2025-01-03 14:27:51 +01:00
24w19a
This commit is contained in:
parent
1fe6f72aec
commit
58d7dc7ca6
@ -105,6 +105,13 @@ public final class StructuredDataContainer {
|
||||
}
|
||||
}
|
||||
|
||||
public <T> void replaceKey(final StructuredDataKey<T> key, final StructuredDataKey<T> toKey) {
|
||||
final StructuredData<T> data = remove(key);
|
||||
if (data != null) {
|
||||
set(toKey, data.value());
|
||||
}
|
||||
}
|
||||
|
||||
public void set(final StructuredDataKey<Unit> key) {
|
||||
this.set(key, Unit.INSTANCE);
|
||||
}
|
||||
|
@ -47,9 +47,9 @@ import com.viaversion.viaversion.api.minecraft.item.data.SuspiciousStewEffect;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.ToolProperties;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Unbreakable;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.WrittenBook;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
|
||||
import com.viaversion.viaversion.api.Types.Type;
|
||||
import com.viaversion.viaversion.api.Types.Types;
|
||||
import com.viaversion.viaversion.api.Types.types.version.Types1_20_5;
|
||||
import com.viaversion.viaversion.util.Unit;
|
||||
|
||||
public record StructuredDataKey<T>(String identifier, Type<T> type) {
|
||||
@ -74,7 +74,8 @@ public record StructuredDataKey<T>(String identifier, Type<T> type) {
|
||||
public static final StructuredDataKey<Unit> CREATIVE_SLOT_LOCK = new StructuredDataKey<>("creative_slot_lock", Types.EMPTY);
|
||||
public static final StructuredDataKey<Boolean> ENCHANTMENT_GLINT_OVERRIDE = new StructuredDataKey<>("enchantment_glint_override", Types.BOOLEAN);
|
||||
public static final StructuredDataKey<Tag> INTANGIBLE_PROJECTILE = new StructuredDataKey<>("intangible_projectile", Types.TAG); // Doesn't actually hold data
|
||||
public static final StructuredDataKey<FoodProperties> FOOD = new StructuredDataKey<>("food", FoodProperties.TYPE);
|
||||
public static final StructuredDataKey<FoodProperties> FOOD1_20_5 = new StructuredDataKey<>("food", FoodProperties.TYPE1_20_5);
|
||||
public static final StructuredDataKey<FoodProperties> FOOD1_21 = new StructuredDataKey<>("food", FoodProperties.TYPE1_21);
|
||||
public static final StructuredDataKey<Unit> FIRE_RESISTANT = new StructuredDataKey<>("fire_resistant", Types.EMPTY);
|
||||
public static final StructuredDataKey<ToolProperties> TOOL = new StructuredDataKey<>("tool", ToolProperties.TYPE);
|
||||
public static final StructuredDataKey<Enchantments> STORED_ENCHANTMENTS = new StructuredDataKey<>("stored_enchantments", Enchantments.TYPE);
|
||||
|
@ -24,12 +24,13 @@ package com.viaversion.viaversion.api.minecraft.item.data;
|
||||
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_21;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public record FoodProperties(int nutrition, float saturationModifier, boolean canAlwaysEat, float eatSeconds,
|
||||
FoodEffect[] possibleEffects) {
|
||||
|
||||
public static final Type<FoodProperties> TYPE = new Type<>(FoodProperties.class) {
|
||||
public static final Type<FoodProperties> TYPE1_20_5 = new Type<>(FoodProperties.class) {
|
||||
@Override
|
||||
public FoodProperties read(final ByteBuf buffer) {
|
||||
final int nutrition = Types.VAR_INT.readPrimitive(buffer);
|
||||
@ -49,5 +50,26 @@ public record FoodProperties(int nutrition, float saturationModifier, boolean ca
|
||||
FoodEffect.ARRAY_TYPE.write(buffer, value.possibleEffects);
|
||||
}
|
||||
};
|
||||
public static final Type<FoodProperties> TYPE1_21 = new Type<FoodProperties>(FoodProperties.class) {
|
||||
@Override
|
||||
public FoodProperties read(final ByteBuf buffer) throws Exception {
|
||||
final int nutrition = Type.VAR_INT.readPrimitive(buffer);
|
||||
final float saturationModifier = buffer.readFloat();
|
||||
final boolean canAlwaysEat = buffer.readBoolean();
|
||||
final float eatSeconds = buffer.readFloat();
|
||||
final Item usingConvertsTo = Types1_21.OPTIONAL_ITEM.read(buffer);
|
||||
final FoodEffect[] possibleEffects = FoodEffect.ARRAY_TYPE.read(buffer);
|
||||
return new FoodProperties(nutrition, saturationModifier, canAlwaysEat, eatSeconds, usingConvertsTo, possibleEffects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final ByteBuf buffer, final FoodProperties value) throws Exception {
|
||||
Type.VAR_INT.writePrimitive(buffer, value.nutrition);
|
||||
buffer.writeFloat(value.saturationModifier);
|
||||
buffer.writeBoolean(value.canAlwaysEat);
|
||||
buffer.writeFloat(value.eatSeconds);
|
||||
Types1_21.OPTIONAL_ITEM.write(buffer, value.usingConvertsTo);
|
||||
FoodEffect.ARRAY_TYPE.write(buffer, value.possibleEffects);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
|
||||
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_5 = register(766, "1.20.5-1.20.6", new SubVersionRange("1.20", 5, 6));
|
||||
public static final ProtocolVersion v1_21 = register(767, 193, "1.21");
|
||||
public static final ProtocolVersion v1_21 = register(767, 194, "1.21");
|
||||
public static final ProtocolVersion unknown = new ProtocolVersion(VersionType.SPECIAL, -1, -1, "UNKNOWN", null);
|
||||
|
||||
public static ProtocolVersion register(int version, String name) {
|
||||
|
@ -28,6 +28,7 @@ import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.item.StructuredItem;
|
||||
import com.viaversion.viaversion.api.type.OptionalType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
@ -114,4 +115,11 @@ public class ItemType1_20_5 extends Type<Item> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final class OptionalItemType extends OptionalType<Item> {
|
||||
|
||||
public OptionalItemType() {
|
||||
super(ItemType1_20_5.this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,8 @@ public final class Types1_21 {
|
||||
|
||||
public static final StructuredDataType STRUCTURED_DATA = new StructuredDataType();
|
||||
public static final Type<StructuredData<?>[]> STRUCTURED_DATA_ARRAY = new ArrayType<>(STRUCTURED_DATA);
|
||||
public static final Type<Item> ITEM = new ItemType1_20_5(STRUCTURED_DATA);
|
||||
public static final ItemType1_20_5 ITEM = new ItemType1_20_5(STRUCTURED_DATA);
|
||||
public static final Type<Item> OPTIONAL_ITEM = ITEM.new OptionalItemType(); // Optional as in boolean prefixed, not via the amount
|
||||
public static final Type<Item[]> ITEM_ARRAY = new ArrayType<>(ITEM);
|
||||
public static final Type<Item> ITEM_COST = new ItemCostType1_20_5(STRUCTURED_DATA_ARRAY);
|
||||
public static final Type<Item> OPTIONAL_ITEM_COST = new ItemCostType1_20_5.OptionalItemCostType(ITEM_COST);
|
||||
|
@ -23,6 +23,7 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
|
||||
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider;
|
||||
import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
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_21;
|
||||
@ -67,13 +68,21 @@ public final class Protocol1_21To1_20_5 extends AbstractProtocol<ClientboundPack
|
||||
|
||||
new StatisticsRewriter<>(this).register(ClientboundPackets1_20_5.STATISTICS);
|
||||
new AttributeRewriter<>(this).register1_20_5(ClientboundPackets1_20_5.ENTITY_PROPERTIES);
|
||||
|
||||
registerClientbound(ClientboundPackets1_20_5.PROJECTILE_POWER, wrapper -> {
|
||||
wrapper.passthrough(Type.VAR_INT); // Id
|
||||
final double xPower = wrapper.read(Type.DOUBLE);
|
||||
final double yPower = wrapper.read(Type.DOUBLE);
|
||||
final double zPower = wrapper.read(Type.DOUBLE);
|
||||
final double accelerationPower = Math.sqrt(xPower * xPower + yPower * yPower + zPower * zPower);
|
||||
wrapper.write(Type.DOUBLE, accelerationPower);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMappingDataLoaded() {
|
||||
super.onMappingDataLoaded();
|
||||
|
||||
// Added preemptively TODO Check if there are actual changes before release
|
||||
Types1_21.PARTICLE.filler(this)
|
||||
.reader("block", ParticleType.Readers.BLOCK)
|
||||
.reader("block_marker", ParticleType.Readers.BLOCK)
|
||||
@ -81,7 +90,7 @@ public final class Protocol1_21To1_20_5 extends AbstractProtocol<ClientboundPack
|
||||
.reader("dust_pillar", ParticleType.Readers.BLOCK)
|
||||
.reader("falling_dust", ParticleType.Readers.BLOCK)
|
||||
.reader("dust_color_transition", ParticleType.Readers.DUST_TRANSITION)
|
||||
.reader("item", ParticleType.Readers.item(Types1_20_5.ITEM))
|
||||
.reader("item", ParticleType.Readers.item(Types1_21.ITEM))
|
||||
.reader("vibration", ParticleType.Readers.VIBRATION1_20_3)
|
||||
.reader("sculk_charge", ParticleType.Readers.SCULK_CHARGE)
|
||||
.reader("shriek", ParticleType.Readers.SHRIEK)
|
||||
@ -89,7 +98,7 @@ public final class Protocol1_21To1_20_5 extends AbstractProtocol<ClientboundPack
|
||||
Types1_21.STRUCTURED_DATA.filler(this)
|
||||
.add(StructuredDataKey.CUSTOM_DATA).add(StructuredDataKey.MAX_STACK_SIZE).add(StructuredDataKey.MAX_DAMAGE)
|
||||
.add(StructuredDataKey.DAMAGE).add(StructuredDataKey.UNBREAKABLE).add(StructuredDataKey.RARITY)
|
||||
.add(StructuredDataKey.HIDE_TOOLTIP).add(StructuredDataKey.FOOD).add(StructuredDataKey.FIRE_RESISTANT)
|
||||
.add(StructuredDataKey.HIDE_TOOLTIP).add(StructuredDataKey.FOOD1_21).add(StructuredDataKey.FIRE_RESISTANT)
|
||||
.add(StructuredDataKey.CUSTOM_NAME).add(StructuredDataKey.LORE).add(StructuredDataKey.ENCHANTMENTS)
|
||||
.add(StructuredDataKey.CAN_PLACE_ON).add(StructuredDataKey.CAN_BREAK).add(StructuredDataKey.ATTRIBUTE_MODIFIERS)
|
||||
.add(StructuredDataKey.CUSTOM_MODEL_DATA).add(StructuredDataKey.HIDE_ADDITIONAL_TOOLTIP).add(StructuredDataKey.REPAIR_COST)
|
||||
|
@ -18,6 +18,7 @@
|
||||
package com.viaversion.viaversion.protocols.protocol1_21to1_20_5.rewriter;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
|
||||
@ -54,7 +55,7 @@ public final class BlockItemPacketRewriter1_21 extends StructuredItemRewriter<Cl
|
||||
registerAdvancements1_20_3(ClientboundPackets1_20_5.ADVANCEMENTS);
|
||||
registerEntityEquipmentArray(ClientboundPackets1_20_5.ENTITY_EQUIPMENT);
|
||||
registerClickWindow1_17_1(ServerboundPackets1_20_5.CLICK_WINDOW);
|
||||
registerTradeList1_20_5(ClientboundPackets1_20_5.TRADE_LIST, Types1_20_5.ITEM_COST, Types1_20_5.ITEM_COST, Types1_21.OPTIONAL_ITEM_COST, Types1_21.OPTIONAL_ITEM_COST);
|
||||
registerTradeList1_20_5(ClientboundPackets1_20_5.TRADE_LIST, Types1_20_5.ITEM_COST, Types1_21.ITEM_COST, Types1_20_5.OPTIONAL_ITEM_COST, Types1_21.OPTIONAL_ITEM_COST);
|
||||
registerCreativeInvAction(ServerboundPackets1_20_5.CREATIVE_INVENTORY_ACTION);
|
||||
registerWindowPropertyEnchantmentHandler(ClientboundPackets1_20_5.WINDOW_PROPERTY);
|
||||
registerSpawnParticle1_20_5(ClientboundPackets1_20_5.SPAWN_PARTICLE, Types1_20_5.PARTICLE, Types1_21.PARTICLE);
|
||||
@ -62,4 +63,26 @@ public final class BlockItemPacketRewriter1_21 extends StructuredItemRewriter<Cl
|
||||
|
||||
new RecipeRewriter1_20_3<>(protocol).register1_20_5(ClientboundPackets1_20_5.DECLARE_RECIPES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Item handleItemToClient(final UserConnection connection, @Nullable final Item item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
super.handleItemToClient(connection, item);
|
||||
item.structuredData().replaceKey(StructuredDataKey.FOOD1_20_5, StructuredDataKey.FOOD1_21);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Item handleItemToServer(final UserConnection connection, @Nullable final Item item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
super.handleItemToServer(connection, item);
|
||||
item.structuredData().replaceKey(StructuredDataKey.FOOD1_21, StructuredDataKey.FOOD1_20_5);
|
||||
return item;
|
||||
}
|
||||
}
|
@ -261,7 +261,7 @@ public final class Protocol1_20_3To1_20_5 extends AbstractProtocol<ClientboundPa
|
||||
Types1_20_5.STRUCTURED_DATA.filler(this)
|
||||
.add(StructuredDataKey.CUSTOM_DATA).add(StructuredDataKey.MAX_STACK_SIZE).add(StructuredDataKey.MAX_DAMAGE)
|
||||
.add(StructuredDataKey.DAMAGE).add(StructuredDataKey.UNBREAKABLE).add(StructuredDataKey.RARITY)
|
||||
.add(StructuredDataKey.HIDE_TOOLTIP).add(StructuredDataKey.FOOD).add(StructuredDataKey.FIRE_RESISTANT)
|
||||
.add(StructuredDataKey.HIDE_TOOLTIP).add(StructuredDataKey.FOOD1_20_5).add(StructuredDataKey.FIRE_RESISTANT)
|
||||
.add(StructuredDataKey.CUSTOM_NAME).add(StructuredDataKey.LORE).add(StructuredDataKey.ENCHANTMENTS)
|
||||
.add(StructuredDataKey.CAN_PLACE_ON).add(StructuredDataKey.CAN_BREAK).add(StructuredDataKey.ATTRIBUTE_MODIFIERS)
|
||||
.add(StructuredDataKey.CUSTOM_MODEL_DATA).add(StructuredDataKey.HIDE_ADDITIONAL_TOOLTIP).add(StructuredDataKey.REPAIR_COST)
|
||||
|
@ -712,7 +712,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
effect.getFloat("probability")
|
||||
));
|
||||
}
|
||||
data.set(StructuredDataKey.FOOD, new FoodProperties(nutrition, saturation, canAlwaysEat, eatSeconds, possibleEffects.toArray(new FoodEffect[0])));
|
||||
data.set(StructuredDataKey.FOOD1_20_5, new FoodProperties(nutrition, saturation, canAlwaysEat, eatSeconds, null, possibleEffects.toArray(new FoodEffect[0])));
|
||||
}
|
||||
|
||||
private void restoreToolFromBackup(final CompoundTag tool, final StructuredDataContainer data) {
|
||||
|
@ -134,7 +134,7 @@ public class ComponentRewriter1_20_5<C extends ClientboundPacketType> extends Co
|
||||
register(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE, this::convertEnchantmentGlintOverride);
|
||||
register(StructuredDataKey.CREATIVE_SLOT_LOCK, null);
|
||||
register(StructuredDataKey.INTANGIBLE_PROJECTILE, this::convertIntangibleProjectile);
|
||||
register(StructuredDataKey.FOOD, this::convertFood);
|
||||
register(StructuredDataKey.FOOD1_20_5, this::convertFood);
|
||||
register(StructuredDataKey.FIRE_RESISTANT, this::convertFireResistant);
|
||||
register(StructuredDataKey.TOOL, this::convertTool);
|
||||
register(StructuredDataKey.STORED_ENCHANTMENTS, this::convertStoredEnchantments);
|
||||
|
@ -596,7 +596,7 @@ public final class StructuredDataConverter {
|
||||
getBackupTag(tag).putInt("rarity", data);
|
||||
}
|
||||
});
|
||||
register(StructuredDataKey.FOOD, (data, tag) -> {
|
||||
register(StructuredDataKey.FOOD1_20_5, (data, tag) -> {
|
||||
if (backupInconvertibleData) {
|
||||
final CompoundTag backupTag = new CompoundTag();
|
||||
backupTag.putInt("nutrition", data.nutrition());
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,5 +1,5 @@
|
||||
# Project properties - we put these here so they can be modified without causing a recompile of the build scripts
|
||||
projectVersion=5.0.0-24w18a-SNAPSHOT
|
||||
projectVersion=5.0.0-24w19a-SNAPSHOT
|
||||
|
||||
# Smile emoji
|
||||
mcVersions=1.20.6,1.20.5,1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10, 1.9.4, 1.9.3, 1.9.2, 1.9.1, 1.9, 1.8.9
|
||||
|
Loading…
Reference in New Issue
Block a user