Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-16 04:50:08 +01:00
Add item cost and particle types to item rewriter
Dieser Commit ist enthalten in:
Ursprung
bda4ea9fd0
Commit
fcd91bb855
@ -18,7 +18,7 @@
|
|||||||
package com.viaversion.viaversion.protocols.template;
|
package com.viaversion.viaversion.protocols.template;
|
||||||
|
|
||||||
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_5;
|
import com.viaversion.viaversion.api.type.types.version.Types1_21;
|
||||||
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.rewriter.RecipeRewriter1_20_3;
|
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.rewriter.RecipeRewriter1_20_3;
|
||||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5;
|
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5;
|
||||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5;
|
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5;
|
||||||
@ -30,10 +30,16 @@ import com.viaversion.viaversion.rewriter.StructuredItemRewriter;
|
|||||||
// To replace if needed:
|
// To replace if needed:
|
||||||
// ChunkType1_20_2
|
// ChunkType1_20_2
|
||||||
// RecipeRewriter1_20_3
|
// RecipeRewriter1_20_3
|
||||||
|
// Types1_21, Types1_OLD
|
||||||
final class BlockItemPacketRewriter1_99 extends StructuredItemRewriter<ClientboundPacket1_21, ServerboundPacket1_20_5, Protocol1_99To_98> {
|
final class BlockItemPacketRewriter1_99 extends StructuredItemRewriter<ClientboundPacket1_21, ServerboundPacket1_20_5, Protocol1_99To_98> {
|
||||||
|
|
||||||
public BlockItemPacketRewriter1_99(final Protocol1_99To_98 protocol) {
|
public BlockItemPacketRewriter1_99(final Protocol1_99To_98 protocol) {
|
||||||
super(protocol, /*TypesOLD.ITEM, TypesOLD.ITEM_ARRAY, */Types1_20_5.ITEM, Types1_20_5.ITEM_ARRAY);
|
super(protocol, Types1_21.ITEM, Types1_21.ITEM_ARRAY);
|
||||||
|
/*super(protocol,
|
||||||
|
Types1_OLD.ITEM, Types1_OLD.ITEM_ARRAY, Types1_21.ITEM, Types1_21.ITEM_ARRAY,
|
||||||
|
Types1_OLD.ITEM_COST, Types1_OLD.OPTIONAL_ITEM_COST, Types1_21.ITEM_COST, Types1_21.OPTIONAL_ITEM_COST,
|
||||||
|
Types1_OLD.PARTICLE, Types1_21.PARTICLE
|
||||||
|
);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -58,10 +64,10 @@ final class BlockItemPacketRewriter1_99 extends StructuredItemRewriter<Clientbou
|
|||||||
registerAdvancements1_20_3(ClientboundPackets1_21.UPDATE_ADVANCEMENTS);
|
registerAdvancements1_20_3(ClientboundPackets1_21.UPDATE_ADVANCEMENTS);
|
||||||
registerSetEquipment(ClientboundPackets1_21.SET_EQUIPMENT);
|
registerSetEquipment(ClientboundPackets1_21.SET_EQUIPMENT);
|
||||||
registerContainerClick1_17_1(ServerboundPackets1_20_5.CONTAINER_CLICK);
|
registerContainerClick1_17_1(ServerboundPackets1_20_5.CONTAINER_CLICK);
|
||||||
registerMerchantOffers1_20_5(ClientboundPackets1_21.MERCHANT_OFFERS, Types1_20_5.ITEM_COST, Types1_20_5.ITEM_COST, Types1_20_5.OPTIONAL_ITEM_COST, Types1_20_5.OPTIONAL_ITEM_COST);
|
registerMerchantOffers1_20_5(ClientboundPackets1_21.MERCHANT_OFFERS);
|
||||||
registerSetCreativeModeSlot(ServerboundPackets1_20_5.SET_CREATIVE_MODE_SLOT);
|
registerSetCreativeModeSlot(ServerboundPackets1_20_5.SET_CREATIVE_MODE_SLOT);
|
||||||
registerLevelParticles1_20_5(ClientboundPackets1_21.LEVEL_PARTICLES, Types1_20_5.PARTICLE, Types1_20_5.PARTICLE);
|
registerLevelParticles1_20_5(ClientboundPackets1_21.LEVEL_PARTICLES);
|
||||||
registerExplosion(ClientboundPackets1_21.EXPLODE, Types1_20_5.PARTICLE, Types1_20_5.PARTICLE); // Rewrites the included sound and particles
|
registerExplosion(ClientboundPackets1_21.EXPLODE); // Rewrites the included sound and particles
|
||||||
|
|
||||||
new RecipeRewriter1_20_3<>(protocol).register1_20_5(ClientboundPackets1_21.UPDATE_RECIPES);
|
new RecipeRewriter1_20_3<>(protocol).register1_20_5(ClientboundPackets1_21.UPDATE_RECIPES);
|
||||||
// OR do this if serialization of recipes changed and override the relevant method
|
// OR do this if serialization of recipes changed and override the relevant method
|
||||||
|
@ -90,7 +90,7 @@ final class Protocol1_99To_98 extends AbstractProtocol<ClientboundPacket1_21, Cl
|
|||||||
// EntityTypes1_20_5.initialize(this);
|
// EntityTypes1_20_5.initialize(this);
|
||||||
|
|
||||||
// Uncomment if a new particle was added = ids shifted; requires a new Types_ class copied from the last
|
// Uncomment if a new particle was added = ids shifted; requires a new Types_ class copied from the last
|
||||||
/*Types1_20_5.PARTICLE.filler(this)
|
/*Types1_21.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)
|
||||||
|
@ -48,7 +48,11 @@ public final class BlockItemPacketRewriter1_21 extends StructuredItemRewriter<Cl
|
|||||||
private static final List<String> DISCS = List.of("11", "13", "5", "blocks", "cat", "chirp", "far", "mall", "mellohi", "otherside", "pigstep", "relic", "stal", "strad", "wait", "ward");
|
private static final List<String> DISCS = List.of("11", "13", "5", "blocks", "cat", "chirp", "far", "mall", "mellohi", "otherside", "pigstep", "relic", "stal", "strad", "wait", "ward");
|
||||||
|
|
||||||
public BlockItemPacketRewriter1_21(final Protocol1_20_5To1_21 protocol) {
|
public BlockItemPacketRewriter1_21(final Protocol1_20_5To1_21 protocol) {
|
||||||
super(protocol, Types1_20_5.ITEM, Types1_20_5.ITEM_ARRAY, Types1_21.ITEM, Types1_21.ITEM_ARRAY);
|
super(protocol,
|
||||||
|
Types1_20_5.ITEM, Types1_20_5.ITEM_ARRAY, Types1_21.ITEM, Types1_21.ITEM_ARRAY,
|
||||||
|
Types1_20_5.ITEM_COST, Types1_20_5.OPTIONAL_ITEM_COST, Types1_21.ITEM_COST, Types1_21.OPTIONAL_ITEM_COST,
|
||||||
|
Types1_20_5.PARTICLE, Types1_21.PARTICLE
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -66,10 +70,10 @@ public final class BlockItemPacketRewriter1_21 extends StructuredItemRewriter<Cl
|
|||||||
registerAdvancements1_20_3(ClientboundPackets1_20_5.UPDATE_ADVANCEMENTS);
|
registerAdvancements1_20_3(ClientboundPackets1_20_5.UPDATE_ADVANCEMENTS);
|
||||||
registerSetEquipment(ClientboundPackets1_20_5.SET_EQUIPMENT);
|
registerSetEquipment(ClientboundPackets1_20_5.SET_EQUIPMENT);
|
||||||
registerContainerClick1_17_1(ServerboundPackets1_20_5.CONTAINER_CLICK);
|
registerContainerClick1_17_1(ServerboundPackets1_20_5.CONTAINER_CLICK);
|
||||||
registerMerchantOffers1_20_5(ClientboundPackets1_20_5.MERCHANT_OFFERS, Types1_20_5.ITEM_COST, Types1_21.ITEM_COST, Types1_20_5.OPTIONAL_ITEM_COST, Types1_21.OPTIONAL_ITEM_COST);
|
registerMerchantOffers1_20_5(ClientboundPackets1_20_5.MERCHANT_OFFERS);
|
||||||
registerSetCreativeModeSlot(ServerboundPackets1_20_5.SET_CREATIVE_MODE_SLOT);
|
registerSetCreativeModeSlot(ServerboundPackets1_20_5.SET_CREATIVE_MODE_SLOT);
|
||||||
registerLevelParticles1_20_5(ClientboundPackets1_20_5.LEVEL_PARTICLES, Types1_20_5.PARTICLE, Types1_21.PARTICLE);
|
registerLevelParticles1_20_5(ClientboundPackets1_20_5.LEVEL_PARTICLES);
|
||||||
registerExplosion(ClientboundPackets1_20_5.EXPLODE, Types1_20_5.PARTICLE, Types1_21.PARTICLE); // Rewrites the included sound and particles
|
registerExplosion(ClientboundPackets1_20_5.EXPLODE); // Rewrites the included sound and particles
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_20_5.HORSE_SCREEN_OPEN, wrapper -> {
|
protocol.registerClientbound(ClientboundPackets1_20_5.HORSE_SCREEN_OPEN, wrapper -> {
|
||||||
wrapper.passthrough(Types.UNSIGNED_BYTE); // Container id
|
wrapper.passthrough(Types.UNSIGNED_BYTE); // Container id
|
||||||
|
@ -42,13 +42,34 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
private final Type<Item> mappedItemType;
|
private final Type<Item> mappedItemType;
|
||||||
private final Type<Item[]> itemArrayType;
|
private final Type<Item[]> itemArrayType;
|
||||||
private final Type<Item[]> mappedItemArrayType;
|
private final Type<Item[]> mappedItemArrayType;
|
||||||
|
private final Type<Item> itemCostType;
|
||||||
|
private final Type<Item> mappedItemCostType;
|
||||||
|
private final Type<Item> optionalItemCostType;
|
||||||
|
private final Type<Item> mappedOptionalItemCostType;
|
||||||
|
private final Type<Particle> particleType;
|
||||||
|
private final Type<Particle> mappedParticleType;
|
||||||
|
|
||||||
public ItemRewriter(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType, Type<Item> mappedItemType, Type<Item[]> mappedItemArrayType) {
|
public ItemRewriter(
|
||||||
|
T protocol,
|
||||||
|
Type<Item> itemType, Type<Item[]> itemArrayType, Type<Item> mappedItemType, Type<Item[]> mappedItemArrayType,
|
||||||
|
Type<Item> itemCostType, Type<Item> optionalItemCostType, Type<Item> mappedItemCostType, Type<Item> mappedOptionalItemCostType,
|
||||||
|
Type<Particle> particleType, Type<Particle> mappedParticleType
|
||||||
|
) {
|
||||||
super(protocol);
|
super(protocol);
|
||||||
this.itemType = itemType;
|
this.itemType = itemType;
|
||||||
this.itemArrayType = itemArrayType;
|
this.itemArrayType = itemArrayType;
|
||||||
this.mappedItemType = mappedItemType;
|
this.mappedItemType = mappedItemType;
|
||||||
this.mappedItemArrayType = mappedItemArrayType;
|
this.mappedItemArrayType = mappedItemArrayType;
|
||||||
|
this.itemCostType = itemCostType;
|
||||||
|
this.mappedItemCostType = mappedItemCostType;
|
||||||
|
this.optionalItemCostType = optionalItemCostType;
|
||||||
|
this.mappedOptionalItemCostType = mappedOptionalItemCostType;
|
||||||
|
this.particleType = particleType;
|
||||||
|
this.mappedParticleType = mappedParticleType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemRewriter(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType, Type<Item> mappedItemType, Type<Item[]> mappedItemArrayType) {
|
||||||
|
this(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType, null, null, null, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemRewriter(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType) {
|
public ItemRewriter(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType) {
|
||||||
@ -322,25 +343,21 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Hopefully the item cost weirdness is temporary
|
// Hopefully the item cost weirdness is temporary
|
||||||
public void registerMerchantOffers1_20_5(
|
public void registerMerchantOffers1_20_5(final C packetType) {
|
||||||
final C packetType,
|
|
||||||
final Type<Item> costType, final Type<Item> mappedCostType,
|
|
||||||
final Type<Item> optionalCostType, final Type<Item> mappedOptionalCostType
|
|
||||||
) {
|
|
||||||
protocol.registerClientbound(packetType, wrapper -> {
|
protocol.registerClientbound(packetType, wrapper -> {
|
||||||
wrapper.passthrough(Types.VAR_INT); // Container id
|
wrapper.passthrough(Types.VAR_INT); // Container id
|
||||||
int size = wrapper.passthrough(Types.VAR_INT);
|
int size = wrapper.passthrough(Types.VAR_INT);
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
final Item input = wrapper.read(costType);
|
final Item input = wrapper.read(itemCostType);
|
||||||
wrapper.write(mappedCostType, handleItemToClient(wrapper.user(), input));
|
wrapper.write(mappedItemCostType, handleItemToClient(wrapper.user(), input));
|
||||||
|
|
||||||
handleClientboundItem(wrapper); // Result
|
handleClientboundItem(wrapper); // Result
|
||||||
|
|
||||||
Item secondInput = wrapper.read(optionalCostType);
|
Item secondInput = wrapper.read(optionalItemCostType);
|
||||||
if (secondInput != null) {
|
if (secondInput != null) {
|
||||||
handleItemToClient(wrapper.user(), secondInput);
|
handleItemToClient(wrapper.user(), secondInput);
|
||||||
}
|
}
|
||||||
wrapper.write(mappedOptionalCostType, secondInput);
|
wrapper.write(mappedOptionalItemCostType, secondInput);
|
||||||
|
|
||||||
wrapper.passthrough(Types.BOOLEAN); // Out of stock
|
wrapper.passthrough(Types.BOOLEAN); // Out of stock
|
||||||
wrapper.passthrough(Types.INT); // Number of trade uses
|
wrapper.passthrough(Types.INT); // Number of trade uses
|
||||||
@ -491,7 +508,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerLevelParticles1_20_5(C packetType, Type<Particle> unmappedParticleType, Type<Particle> mappedParticleType) {
|
public void registerLevelParticles1_20_5(C packetType) {
|
||||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
protocol.registerClientbound(packetType, new PacketHandlers() {
|
||||||
@Override
|
@Override
|
||||||
public void register() {
|
public void register() {
|
||||||
@ -505,7 +522,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
map(Types.FLOAT); // Particle Data
|
map(Types.FLOAT); // Particle Data
|
||||||
map(Types.INT); // Particle Count
|
map(Types.INT); // Particle Count
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
final Particle particle = wrapper.read(unmappedParticleType);
|
final Particle particle = wrapper.read(particleType);
|
||||||
rewriteParticle(wrapper.user(), particle);
|
rewriteParticle(wrapper.user(), particle);
|
||||||
wrapper.write(mappedParticleType, particle);
|
wrapper.write(mappedParticleType, particle);
|
||||||
});
|
});
|
||||||
@ -513,7 +530,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerExplosion(C packetType, Type<Particle> unmappedParticleType, Type<Particle> mappedParticleType) {
|
public void registerExplosion(C packetType) {
|
||||||
final SoundRewriter<C> soundRewriter = new SoundRewriter<>(protocol);
|
final SoundRewriter<C> soundRewriter = new SoundRewriter<>(protocol);
|
||||||
protocol.registerClientbound(packetType, wrapper -> {
|
protocol.registerClientbound(packetType, wrapper -> {
|
||||||
wrapper.passthrough(Types.DOUBLE); // X
|
wrapper.passthrough(Types.DOUBLE); // X
|
||||||
@ -531,8 +548,8 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
|||||||
wrapper.passthrough(Types.FLOAT); // Knockback Z
|
wrapper.passthrough(Types.FLOAT); // Knockback Z
|
||||||
wrapper.passthrough(Types.VAR_INT); // Block interaction type
|
wrapper.passthrough(Types.VAR_INT); // Block interaction type
|
||||||
|
|
||||||
final Particle smallExplosionParticle = wrapper.read(unmappedParticleType);
|
final Particle smallExplosionParticle = wrapper.read(particleType);
|
||||||
final Particle largeExplosionParticle = wrapper.read(unmappedParticleType);
|
final Particle largeExplosionParticle = wrapper.read(particleType);
|
||||||
wrapper.write(mappedParticleType, smallExplosionParticle);
|
wrapper.write(mappedParticleType, smallExplosionParticle);
|
||||||
wrapper.write(mappedParticleType, largeExplosionParticle);
|
wrapper.write(mappedParticleType, largeExplosionParticle);
|
||||||
rewriteParticle(wrapper.user(), smallExplosionParticle);
|
rewriteParticle(wrapper.user(), smallExplosionParticle);
|
||||||
|
@ -22,6 +22,7 @@ import com.viaversion.nbt.tag.Tag;
|
|||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
import com.viaversion.viaversion.api.data.FullMappings;
|
import com.viaversion.viaversion.api.data.FullMappings;
|
||||||
import com.viaversion.viaversion.api.data.MappingData;
|
import com.viaversion.viaversion.api.data.MappingData;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.Particle;
|
||||||
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
|
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
|
||||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
|
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
|
||||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
|
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
|
||||||
@ -38,6 +39,15 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
public class StructuredItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType,
|
public class StructuredItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType,
|
||||||
T extends Protocol<C, ?, ?, S>> extends ItemRewriter<C, S, T> {
|
T extends Protocol<C, ?, ?, S>> extends ItemRewriter<C, S, T> {
|
||||||
|
|
||||||
|
public StructuredItemRewriter(
|
||||||
|
T protocol,
|
||||||
|
Type<Item> itemType, Type<Item[]> itemArrayType, Type<Item> mappedItemType, Type<Item[]> mappedItemArrayType,
|
||||||
|
Type<Item> itemCostType, Type<Item> optionalItemCostType, Type<Item> mappedItemCostType, Type<Item> mappedOptionalItemCostType,
|
||||||
|
Type<Particle> particleType, Type<Particle> mappedParticleType
|
||||||
|
) {
|
||||||
|
super(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType, itemCostType, optionalItemCostType, mappedItemCostType, mappedOptionalItemCostType, particleType, mappedParticleType);
|
||||||
|
}
|
||||||
|
|
||||||
public StructuredItemRewriter(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType, Type<Item> mappedItemType, Type<Item[]> mappedItemArrayType) {
|
public StructuredItemRewriter(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType, Type<Item> mappedItemType, Type<Item[]> mappedItemArrayType) {
|
||||||
super(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType);
|
super(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType);
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren