Fix container id conversion and itemrewriter explosion method

This commit is contained in:
Nassim Jahnke 2024-08-16 12:16:08 +02:00
parent e46b38e58a
commit 1d18f2e45e
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
5 changed files with 19 additions and 16 deletions

View File

@ -96,10 +96,10 @@ final class Protocol1_99To_98 extends AbstractProtocol<ClientboundPacket1_21, Cl
.reader("dust", ParticleType.Readers.DUST)
.reader("falling_dust", ParticleType.Readers.BLOCK)
.reader("dust_color_transition", ParticleType.Readers.DUST_TRANSITION)
.reader("item", ParticleType.Readers.ITEM1_20_2)
.reader("vibration", ParticleType.Readers.VIBRATION1_20_3)
.reader("sculk_charge", ParticleType.Readers.SCULK_CHARGE)
.reader("shriek", ParticleType.Readers.SHRIEK);*/
.reader("shriek", ParticleType.Readers.SHRIEK)
.reader("item", ParticleType.Readers.item(...));*/
super.onMappingDataLoaded(); // Calls load methods on rewriters. Last in case the rewriters access the above filled data
}

View File

@ -91,7 +91,7 @@ public final class Protocol1_21To1_21_2 extends AbstractProtocol<ClientboundPack
wrapper.passthrough(Types.VAR_INT); // Main hand
wrapper.passthrough(Types.BOOLEAN); // Text filtering enabled
wrapper.passthrough(Types.BOOLEAN); // Allow listing
wrapper.read(Types.VAR_INT);
wrapper.read(Types.VAR_INT); // Particle status
}
@Override
@ -102,10 +102,10 @@ public final class Protocol1_21To1_21_2 extends AbstractProtocol<ClientboundPack
.reader("dust", ParticleType.Readers.DUST)
.reader("falling_dust", ParticleType.Readers.BLOCK)
.reader("dust_color_transition", ParticleType.Readers.DUST_TRANSITION)
.reader("item", ParticleType.Readers.item(Types1_21_2.ITEM))
.reader("vibration", ParticleType.Readers.VIBRATION1_20_3)
.reader("sculk_charge", ParticleType.Readers.SCULK_CHARGE)
.reader("shriek", ParticleType.Readers.SHRIEK);
.reader("shriek", ParticleType.Readers.SHRIEK)
.reader("item", ParticleType.Readers.item(Types1_21_2.ITEM));
Types1_21_2.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)
@ -116,18 +116,19 @@ public final class Protocol1_21To1_21_2 extends AbstractProtocol<ClientboundPack
.add(StructuredDataKey.CREATIVE_SLOT_LOCK).add(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE).add(StructuredDataKey.INTANGIBLE_PROJECTILE)
.add(StructuredDataKey.STORED_ENCHANTMENTS).add(StructuredDataKey.DYED_COLOR).add(StructuredDataKey.MAP_COLOR)
.add(StructuredDataKey.MAP_ID).add(StructuredDataKey.MAP_DECORATIONS).add(StructuredDataKey.MAP_POST_PROCESSING)
.add(StructuredDataKey.CHARGED_PROJECTILES1_21_2).add(StructuredDataKey.BUNDLE_CONTENTS1_21_2).add(StructuredDataKey.POTION_CONTENTS)
.add(StructuredDataKey.POTION_CONTENTS)
.add(StructuredDataKey.SUSPICIOUS_STEW_EFFECTS).add(StructuredDataKey.WRITABLE_BOOK_CONTENT).add(StructuredDataKey.WRITTEN_BOOK_CONTENT)
.add(StructuredDataKey.TRIM).add(StructuredDataKey.DEBUG_STICK_STATE).add(StructuredDataKey.ENTITY_DATA)
.add(StructuredDataKey.BUCKET_ENTITY_DATA).add(StructuredDataKey.BLOCK_ENTITY_DATA).add(StructuredDataKey.INSTRUMENT1_21_2)
.add(StructuredDataKey.RECIPES).add(StructuredDataKey.LODESTONE_TRACKER).add(StructuredDataKey.FIREWORK_EXPLOSION)
.add(StructuredDataKey.FIREWORKS).add(StructuredDataKey.PROFILE).add(StructuredDataKey.NOTE_BLOCK_SOUND)
.add(StructuredDataKey.BANNER_PATTERNS).add(StructuredDataKey.BASE_COLOR).add(StructuredDataKey.POT_DECORATIONS)
.add(StructuredDataKey.CONTAINER1_21_2).add(StructuredDataKey.BLOCK_STATE).add(StructuredDataKey.BEES)
.add(StructuredDataKey.BLOCK_STATE).add(StructuredDataKey.BEES)
.add(StructuredDataKey.LOCK).add(StructuredDataKey.CONTAINER_LOOT).add(StructuredDataKey.TOOL)
.add(StructuredDataKey.ITEM_NAME).add(StructuredDataKey.OMINOUS_BOTTLE_AMPLIFIER)
.add(StructuredDataKey.FOOD1_21).add(StructuredDataKey.JUKEBOX_PLAYABLE).add(StructuredDataKey.ATTRIBUTE_MODIFIERS1_21)
.add(StructuredDataKey.REPAIRABLE).add(StructuredDataKey.ENCHANTABLE);
.add(StructuredDataKey.REPAIRABLE).add(StructuredDataKey.ENCHANTABLE)
.add(StructuredDataKey.CHARGED_PROJECTILES1_21_2).add(StructuredDataKey.BUNDLE_CONTENTS1_21_2).add(StructuredDataKey.CONTAINER1_21_2);
super.onMappingDataLoaded();
}

View File

@ -226,8 +226,12 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter<
}
private void updateContainerId(final PacketWrapper wrapper) {
final int containerId = wrapper.read(Types.UNSIGNED_BYTE).intValue();
wrapper.write(Types.VAR_INT, containerId);
// Container id handling was always a bit whack with most reading them as unsigned bytes, some as bytes, some already as var ints.
// In VV they're generally read as unsigned bytesto not have to look the type up every time, but we need to make sure they're
// properly converted to ints when used
final short containerId = wrapper.read(Types.UNSIGNED_BYTE);
final int intId = (byte) containerId;
wrapper.write(Types.VAR_INT, intId);
}
private void updateContainerIdServerbound(final PacketWrapper wrapper) {

View File

@ -567,12 +567,9 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
wrapper.passthrough(Types.DOUBLE); // Knockback Y
wrapper.passthrough(Types.DOUBLE); // Knockback Z
final Particle smallExplosionParticle = wrapper.read(particleType);
final Particle largeExplosionParticle = wrapper.read(particleType);
wrapper.write(mappedParticleType, smallExplosionParticle);
wrapper.write(mappedParticleType, largeExplosionParticle);
rewriteParticle(wrapper.user(), smallExplosionParticle);
rewriteParticle(wrapper.user(), largeExplosionParticle);
final Particle explosionParticle = wrapper.read(particleType);
wrapper.write(mappedParticleType, explosionParticle);
rewriteParticle(wrapper.user(), explosionParticle);
soundRewriter.soundHolderHandler().handle(wrapper);
});

View File

@ -118,6 +118,7 @@ public class StructuredItemRewriter<C extends ClientboundPacketType, S extends S
final Int2IntFunction itemIdRewriter = clientbound ? mappingData::getNewItemId : mappingData::getOldItemId;
container.replace(StructuredDataKey.TRIM, value -> value.rewrite(itemIdRewriter));
container.replace(StructuredDataKey.POT_DECORATIONS, value -> value.rewrite(itemIdRewriter));
container.replace(StructuredDataKey.REPAIRABLE, value -> value.rewrite(itemIdRewriter));
}
if (mappingData.getBlockMappings() != null) {
final Int2IntFunction blockIdRewriter = clientbound ? mappingData::getNewBlockId : mappingData::getOldBlockId;