1.21.2-pre1

This commit is contained in:
Nassim Jahnke 2024-10-07 21:40:08 +02:00
parent 3e3dad9e33
commit 7c7239a70d
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
10 changed files with 72 additions and 30 deletions

View File

@ -32,27 +32,29 @@ import it.unimi.dsi.fastutil.ints.Int2IntFunction;
import org.checkerframework.checker.nullness.qual.Nullable;
public record Equippable(int equipmentSlot, Holder<SoundEvent> soundEvent, @Nullable String model,
@Nullable HolderSet allowedEntities, boolean dispensable, boolean swappable,
boolean damageOnHurt) {
@Nullable String cameraOverlay, @Nullable HolderSet allowedEntities, boolean dispensable,
boolean swappable, boolean damageOnHurt) {
public static final Type<Equippable> TYPE = new Type<>(Equippable.class) {
@Override
public Equippable read(final ByteBuf buffer) {
final int equipmentSlot = Types.VAR_INT.readPrimitive(buffer);
final Holder<SoundEvent> soundEvent = Types.SOUND_EVENT.read(buffer);
final String model = Types.STRING.read(buffer);
final String model = Types.OPTIONAL_STRING.read(buffer);
final String cameraOverlay = Types.OPTIONAL_STRING.read(buffer);
final HolderSet allowedEntities = Types.HOLDER_SET.read(buffer);
final boolean dispensable = buffer.readBoolean();
final boolean swappable = buffer.readBoolean();
final boolean damageOnHurt = buffer.readBoolean();
return new Equippable(equipmentSlot, soundEvent, model, allowedEntities, dispensable, swappable, damageOnHurt);
return new Equippable(equipmentSlot, soundEvent, model, cameraOverlay, allowedEntities, dispensable, swappable, damageOnHurt);
}
@Override
public void write(final ByteBuf buffer, final Equippable value) {
Types.VAR_INT.writePrimitive(buffer, value.equipmentSlot());
Types.SOUND_EVENT.write(buffer, value.soundEvent());
Types.STRING.write(buffer, value.model());
Types.OPTIONAL_STRING.write(buffer, value.model());
Types.OPTIONAL_STRING.write(buffer, value.cameraOverlay());
Types.HOLDER_SET.write(buffer, value.allowedEntities());
buffer.writeBoolean(value.dispensable());
buffer.writeBoolean(value.swappable());
@ -62,6 +64,6 @@ public record Equippable(int equipmentSlot, Holder<SoundEvent> soundEvent, @Null
public Equippable rewrite(final Int2IntFunction soundIdRewriter) {
final Holder<SoundEvent> soundEvent = this.soundEvent.updateId(soundIdRewriter);
return soundEvent == this.soundEvent ? this : new Equippable(equipmentSlot, soundEvent, model, allowedEntities, dispensable, swappable, damageOnHurt);
return soundEvent == this.soundEvent ? this : new Equippable(equipmentSlot, soundEvent, model, cameraOverlay, allowedEntities, dispensable, swappable, damageOnHurt);
}
}

View File

@ -86,7 +86,7 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
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, "1.21-1.21.1", new SubVersionRange("1.21", 0, 1));
public static final ProtocolVersion v1_21_2 = register(768, 212, "1.21.2");
public static final ProtocolVersion v1_21_2 = register(768, 213, "1.21.2");
public static final ProtocolVersion unknown = new ProtocolVersion(VersionType.SPECIAL, -1, -1, "UNKNOWN", null);
public static ProtocolVersion register(int version, String name) {

View File

@ -36,11 +36,19 @@ public class IntType extends Type<Integer> implements TypeConverter<Integer> {
return buffer.readInt();
}
public int readPrimitive(ByteBuf buffer) {
return buffer.readInt();
}
@Override
public void write(ByteBuf buffer, Integer object) {
buffer.writeInt(object);
}
public void writePrimitive(ByteBuf buffer, int object) {
buffer.writeInt(object);
}
@Override
public Integer from(Object o) {
if (o instanceof Number number) {

View File

@ -77,6 +77,10 @@ public class ParticleType extends DynamicType<Particle> {
particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Blue 0-1
particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Scale 0.01-4
};
public static final DataReader<Particle> DUST1_21_2 = (buf, particle) -> {
particle.add(Types.INT, Types.INT.readPrimitive(buf)); // RGB
particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Scale 0.01-4
};
public static final DataReader<Particle> DUST_TRANSITION = (buf, particle) -> {
particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Red 0-1
particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Green 0-1
@ -86,6 +90,11 @@ public class ParticleType extends DynamicType<Particle> {
particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Green
particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Blue
};
public static final DataReader<Particle> DUST_TRANSITION1_21_2 = (buf, particle) -> {
particle.add(Types.INT, Types.INT.readPrimitive(buf)); // From RGB
particle.add(Types.INT, Types.INT.readPrimitive(buf)); // To RGB
particle.add(Types.FLOAT, Types.FLOAT.readPrimitive(buf)); // Scale 0.01-4
};
public static final DataReader<Particle> VIBRATION = (buf, particle) -> {
particle.add(Types.BLOCK_POSITION1_14, Types.BLOCK_POSITION1_14.read(buf)); // From block pos
@ -136,12 +145,14 @@ public class ParticleType extends DynamicType<Particle> {
public static final DataReader<Particle> SHRIEK = (buf, particle) -> {
particle.add(Types.VAR_INT, Types.VAR_INT.readPrimitive(buf)); // Delay
};
public static final DataReader<Particle> COLOR = (buf, particle) -> particle.add(Types.INT, buf.readInt());
public static final DataReader<Particle> COLOR = (buf, particle) -> {
particle.add(Types.INT, Types.INT.readPrimitive(buf));
};
public static final DataReader<Particle> TRAIL = (buf, particle) -> {
particle.add(Types.VAR_INT, Types.VAR_INT.readPrimitive(buf)); // Target X
particle.add(Types.VAR_INT, Types.VAR_INT.readPrimitive(buf)); // Target Y
particle.add(Types.VAR_INT, Types.VAR_INT.readPrimitive(buf)); // Target Z
particle.add(Types.INT, buf.readInt()); // Color
particle.add(Types.INT, Types.INT.readPrimitive(buf)); // Color
};
public static DataReader<Particle> item(Type<Item> item) {

View File

@ -108,16 +108,16 @@ final class Protocol1_99To_98 extends AbstractProtocol<ClientboundPacket1_21, Cl
/*Types1_21_2.PARTICLE.filler(this)
.reader("block", ParticleType.Readers.BLOCK)
.reader("block_marker", ParticleType.Readers.BLOCK)
.reader("dust", ParticleType.Readers.DUST)
.reader("dust", ParticleType.Readers.DUST1_21_2)
.reader("dust_pillar", ParticleType.Readers.BLOCK)
.reader("falling_dust", ParticleType.Readers.BLOCK)
.reader("dust_color_transition", ParticleType.Readers.DUST_TRANSITION)
.reader("dust_color_transition", ParticleType.Readers.DUST_TRANSITION1_21_2)
.reader("vibration", ParticleType.Readers.VIBRATION1_20_3)
.reader("sculk_charge", ParticleType.Readers.SCULK_CHARGE)
.reader("shriek", ParticleType.Readers.SHRIEK)
.reader("entity_effect", ParticleType.Readers.COLOR)
.reader("trail", ParticleType.Readers.TRAIL)
.reader("item", ParticleType.Readers.item(...));*/
.reader("item", ParticleType.Readers.item(itemRewriter.mappedItemType()));*/
super.onMappingDataLoaded(); // Calls load methods on rewriters. Last in case the rewriters access the above filled data
}

View File

@ -141,10 +141,10 @@ public final class Protocol1_21To1_21_2 extends AbstractProtocol<ClientboundPack
Types1_21_2.PARTICLE.filler(this)
.reader("block", ParticleType.Readers.BLOCK)
.reader("block_marker", ParticleType.Readers.BLOCK)
.reader("dust", ParticleType.Readers.DUST)
.reader("dust", ParticleType.Readers.DUST1_21_2)
.reader("dust_pillar", ParticleType.Readers.BLOCK)
.reader("falling_dust", ParticleType.Readers.BLOCK)
.reader("dust_color_transition", ParticleType.Readers.DUST_TRANSITION)
.reader("dust_color_transition", ParticleType.Readers.DUST_TRANSITION1_21_2)
.reader("vibration", ParticleType.Readers.VIBRATION1_20_3)
.reader("sculk_charge", ParticleType.Readers.SCULK_CHARGE)
.reader("shriek", ParticleType.Readers.SHRIEK)

View File

@ -314,6 +314,8 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter<
// Update final size
wrapper.set(Types.VAR_INT, 0, size);
wrapper.write(Types.BOOLEAN, state == RECIPE_INIT); // Replace
});
}

View File

@ -129,12 +129,11 @@ final class RecipeRewriter1_21_2 extends RecipeRewriter1_20_3<ClientboundPacket1
final int category = wrapper.read(Types.VAR_INT);
final Item[] ingredient = readIngredient(wrapper);
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
final float experience = wrapper.read(Types.FLOAT);
final int cookingTime = wrapper.read(Types.VAR_INT);
final FurnaceRecipe recipe = new FurnaceRecipe(recipesByKey.size(), currentRecipeIdentifier, group, category, ingredient, result);
final FurnaceRecipe recipe = new FurnaceRecipe(recipesByKey.size(), currentRecipeIdentifier, group, category, ingredient, result, cookingTime, experience);
addRecipe(recipe);
wrapper.read(Types.FLOAT); // EXP
wrapper.read(Types.VAR_INT); // Cooking time
}
private int readRecipeGroup(final PacketWrapper wrapper) {
@ -196,7 +195,7 @@ final class RecipeRewriter1_21_2 extends RecipeRewriter1_20_3<ClientboundPacket1
int SLOT_DISPLAY_EMPTY = 0;
int SLOT_DISPLAY_ANY_FUEL = 1;
int SLOT_DISPLAY_ITEM = 3;
int SLOT_DISPLAY_COMPOSITE = 6;
int SLOT_DISPLAY_COMPOSITE = 7;
int index();
@ -259,7 +258,7 @@ final class RecipeRewriter1_21_2 extends RecipeRewriter1_20_3<ClientboundPacket1
}
record FurnaceRecipe(int index, String identifier, int group, int category, Item[] ingredient,
Item result) implements Recipe {
Item result, int duration, float experience) implements Recipe {
@Override
public int recipeDisplayId() {
return 2;
@ -271,6 +270,8 @@ final class RecipeRewriter1_21_2 extends RecipeRewriter1_20_3<ClientboundPacket1
wrapper.write(Types.VAR_INT, SLOT_DISPLAY_ANY_FUEL); // Fuel
writeItemDisplay(wrapper, result);
writeCraftingStationDisplay(wrapper);
wrapper.write(Types.VAR_INT, duration);
wrapper.write(Types.FLOAT, experience);
}
}
@ -281,6 +282,7 @@ final class RecipeRewriter1_21_2 extends RecipeRewriter1_20_3<ClientboundPacket1
}
public void writeRecipeDisplay(final PacketWrapper wrapper) {
writeIngredientDisplay(wrapper, ingredient);
writeItemDisplay(wrapper, result);
writeCraftingStationDisplay(wrapper);
}
@ -308,7 +310,7 @@ final class RecipeRewriter1_21_2 extends RecipeRewriter1_20_3<ClientboundPacket1
private static void writeItemDisplay(final PacketWrapper wrapper, final Item item) {
wrapper.write(Types.VAR_INT, Recipe.SLOT_DISPLAY_ITEM);
wrapper.write(Types1_21_2.ITEM, item);
wrapper.write(Types1_21_2.ITEM, item.copy());
}
private static void writeCraftingStationDisplay(final PacketWrapper wrapper) {

View File

@ -97,22 +97,19 @@ public class RecipeDisplayRewriter<C extends ClientboundPacketType> {
}
protected void handleStoneCutter(final PacketWrapper wrapper) {
handleSlotDisplay(wrapper); // Input
handleSlotDisplay(wrapper); // Result
handleSlotDisplay(wrapper); // Crafting station
}
protected void handleSmithing(final PacketWrapper wrapper) {
handleSlotDisplay(wrapper); // Template
handleSlotDisplay(wrapper); // Base
handleSlotDisplay(wrapper); // Addition
handleSlotDisplay(wrapper); // Result
handleSlotDisplay(wrapper); // Crafting station
}
protected void handleSlotDisplayList(final PacketWrapper wrapper) {
final int size = wrapper.passthrough(Types.VAR_INT);
for (int i = 0; i < size; i++) {
handleSlotDisplay(wrapper);
}
}
protected void handleRecipeDisplay(final PacketWrapper wrapper) {
final int type = wrapper.passthrough(Types.VAR_INT);
switch (type) {
@ -125,16 +122,36 @@ public class RecipeDisplayRewriter<C extends ClientboundPacketType> {
}
protected void handleSlotDisplay(final PacketWrapper wrapper) {
// empty, any_fuel, smithing_trim are empty
// empty and any_fuel are empty
final int type = wrapper.passthrough(Types.VAR_INT);
switch (type) {
case 2 -> handleItemId(wrapper); // Item type
case 3 -> handleItem(wrapper); // Item
case 4 -> wrapper.passthrough(Types.STRING); // Tag key
case 6 -> handleSlotDisplayList(wrapper); // Composite
case 5 -> handleSmithingTrimSlotDisplay(wrapper); // Smithing trim
case 6 -> handleWithRemainderSlotDisplay(wrapper); // With remainder
case 7 -> handleSlotDisplayList(wrapper); // Composite
}
}
protected void handleSlotDisplayList(final PacketWrapper wrapper) {
final int size = wrapper.passthrough(Types.VAR_INT);
for (int i = 0; i < size; i++) {
handleSlotDisplay(wrapper);
}
}
protected void handleSmithingTrimSlotDisplay(final PacketWrapper wrapper) {
handleSlotDisplay(wrapper); // Base
handleSlotDisplay(wrapper); // Material
handleSlotDisplay(wrapper); // Pattern
}
protected void handleWithRemainderSlotDisplay(final PacketWrapper wrapper) {
handleSlotDisplay(wrapper); // Input
handleSlotDisplay(wrapper); // Remainder
}
protected void handleIngredient(final PacketWrapper wrapper) {
final HolderSet items = wrapper.passthrough(Types.HOLDER_SET);
if (items.hasTagKey()) {