Skip to content

Commit 091d240

Browse files
committed
Go over older protocols
Mostly only stylistic changes to keep the protocols aligned with their delegations in the main projects Signed-off-by: Florian Reuth <git@florianreuth.de>
1 parent 532a1a9 commit 091d240

File tree

10 files changed

+113
-199
lines changed

10 files changed

+113
-199
lines changed

common/src/main/java/com/viaversion/viaaprilfools/protocol/s20w14infinitetov1_16/Protocol20w14infiniteTo1_16.java

Lines changed: 39 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.viaversion.viaversion.api.connection.UserConnection;
3333
import com.viaversion.viaversion.api.minecraft.RegistryType;
3434
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16;
35-
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
3635
import com.viaversion.viaversion.api.type.Types;
3736
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
3837
import com.viaversion.viaversion.protocols.v1_15_2to1_16.Protocol1_15_2To1_16;
@@ -45,7 +44,7 @@
4544
import com.viaversion.viaversion.rewriter.TagRewriter;
4645
import java.util.UUID;
4746

48-
public class Protocol20w14infiniteTo1_16 extends BackwardsProtocol<ClientboundPackets20w14infinite, ClientboundPackets1_16, ServerboundPackets20w14infinite, ServerboundPackets1_16> {
47+
public final class Protocol20w14infiniteTo1_16 extends BackwardsProtocol<ClientboundPackets20w14infinite, ClientboundPackets1_16, ServerboundPackets20w14infinite, ServerboundPackets1_16> {
4948

5049
public static final BackwardsMappingData MAPPINGS = new VAFBackwardsMappingData("20w14infinite", "1.16", Protocol1_15_2To1_16.class);
5150
private static final UUID ZERO_UUID = new UUID(0, 0);
@@ -66,105 +65,55 @@ protected void registerPackets() {
6665
particleRewriter.registerLevelParticles1_13(ClientboundPackets20w14infinite.LEVEL_PARTICLES, Types.DOUBLE);
6766

6867
tagRewriter.register(ClientboundPackets20w14infinite.UPDATE_TAGS, RegistryType.ENTITY);
69-
new StatisticsRewriter<>(this).register(ClientboundPackets20w14infinite.AWARD_STATS);
68+
7069
final SoundRewriter<ClientboundPackets20w14infinite> soundRewriter = new SoundRewriter<>(this);
7170
soundRewriter.registerSound(ClientboundPackets20w14infinite.SOUND);
7271
soundRewriter.registerSound(ClientboundPackets20w14infinite.SOUND_ENTITY);
7372
soundRewriter.registerNamedSound(ClientboundPackets20w14infinite.CUSTOM_SOUND);
7473
soundRewriter.registerStopSound(ClientboundPackets20w14infinite.STOP_SOUND);
74+
75+
new StatisticsRewriter<>(this).register(ClientboundPackets20w14infinite.AWARD_STATS);
7576
new RecipeRewriter<>(this).register(ClientboundPackets20w14infinite.UPDATE_RECIPES);
7677

77-
this.registerClientbound(ClientboundPackets20w14infinite.CHAT, new PacketHandlers() {
78-
@Override
79-
public void register() {
80-
map(Types.COMPONENT);
81-
map(Types.BYTE);
82-
handler(wrapper -> {
83-
wrapper.write(Types.UUID, ZERO_UUID); // Sender uuid - always send as 'system'
84-
});
85-
}
78+
registerClientbound(ClientboundPackets20w14infinite.CHAT, wrapper -> {
79+
wrapper.passthrough(Types.COMPONENT);
80+
wrapper.passthrough(Types.BYTE);
81+
wrapper.write(Types.UUID, ZERO_UUID); // Sender uuid - always send as 'system'
8682
});
8783

88-
this.cancelServerbound(ServerboundPackets1_16.JIGSAW_GENERATE);
89-
this.registerServerbound(ServerboundPackets1_16.INTERACT, new PacketHandlers() {
90-
@Override
91-
public void register() {
92-
handler(wrapper -> {
93-
wrapper.passthrough(Types.VAR_INT); // Entity Id
94-
int action = wrapper.passthrough(Types.VAR_INT);
95-
if (action == 0 || action == 2) {
96-
if (action == 2) {
97-
// Location
98-
wrapper.passthrough(Types.FLOAT);
99-
wrapper.passthrough(Types.FLOAT);
100-
wrapper.passthrough(Types.FLOAT);
101-
}
102-
103-
wrapper.passthrough(Types.VAR_INT); // Hand
104-
}
105-
106-
// New boolean: Whether the client is sneaking/pressing shift
107-
wrapper.read(Types.BOOLEAN);
108-
});
84+
cancelServerbound(ServerboundPackets1_16.JIGSAW_GENERATE);
85+
registerServerbound(ServerboundPackets1_16.INTERACT, wrapper -> {
86+
wrapper.passthrough(Types.VAR_INT); // Entity id
87+
final int action = wrapper.passthrough(Types.VAR_INT);
88+
if (action == 0 || action == 2) {
89+
if (action == 2) {
90+
// Location
91+
wrapper.passthrough(Types.FLOAT);
92+
wrapper.passthrough(Types.FLOAT);
93+
wrapper.passthrough(Types.FLOAT);
94+
}
95+
96+
wrapper.passthrough(Types.VAR_INT); // Hand
10997
}
98+
99+
wrapper.read(Types.BOOLEAN); // Whether the client is sneaking/pressing shift
110100
});
111-
this.registerServerbound(ServerboundPackets1_16.PLAYER_ABILITIES, new PacketHandlers() {
112-
@Override
113-
public void register() {
114-
map(Types.BYTE); // Flags
115-
handler(wrapper -> {
116-
final PlayerAbilitiesProvider playerAbilities = Via.getManager().getProviders().get(PlayerAbilitiesProvider.class);
117-
wrapper.write(Types.FLOAT, playerAbilities.getFlyingSpeed(wrapper.user()));
118-
wrapper.write(Types.FLOAT, playerAbilities.getWalkingSpeed(wrapper.user()));
119-
});
120-
}
101+
registerServerbound(ServerboundPackets1_16.PLAYER_ABILITIES, wrapper -> {
102+
wrapper.passthrough(Types.BYTE); // Flags
103+
104+
final PlayerAbilitiesProvider playerAbilities = Via.getManager().getProviders().get(PlayerAbilitiesProvider.class);
105+
wrapper.write(Types.FLOAT, playerAbilities.getFlyingSpeed(wrapper.user()));
106+
wrapper.write(Types.FLOAT, playerAbilities.getWalkingSpeed(wrapper.user()));
121107
});
122108
}
123109

124110
@Override
125111
protected void onMappingDataLoaded() {
126-
int[] wallPostOverrideTag = new int[47];
127-
int arrayIndex = 0;
128-
wallPostOverrideTag[arrayIndex++] = 140;
129-
wallPostOverrideTag[arrayIndex++] = 179;
130-
wallPostOverrideTag[arrayIndex++] = 264;
131-
for (int i = 153; i <= 158; i++) {
132-
wallPostOverrideTag[arrayIndex++] = i;
133-
}
134-
for (int i = 163; i <= 168; i++) {
135-
wallPostOverrideTag[arrayIndex++] = i;
136-
}
137-
for (int i = 408; i <= 439; i++) {
138-
wallPostOverrideTag[arrayIndex++] = i;
139-
}
140-
141-
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:wall_post_override", wallPostOverrideTag);
142-
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:beacon_base_blocks", 133, 134, 148, 265);
143-
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:climbable", 160, 241, 658);
144-
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:fire", 142);
145-
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:campfires", 679);
146-
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:fence_gates", 242, 467, 468, 469, 470, 471);
147-
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:unstable_bottom_center", 242, 467, 468, 469, 470, 471);
148-
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:wooden_trapdoors", 193, 194, 195, 196, 197, 198);
149-
tagRewriter.addTag(RegistryType.ITEM, "minecraft:wooden_trapdoors", 215, 216, 217, 218, 219, 220);
150-
tagRewriter.addTag(RegistryType.ITEM, "minecraft:beacon_payment_items", 529, 530, 531, 760);
151-
tagRewriter.addTag(RegistryType.ENTITY, "minecraft:impact_projectiles", 2, 72, 71, 37, 69, 79, 83, 15, 93);
152-
153-
// The client crashes if we don't send all tags it may use
154-
tagRewriter.addEmptyTag(RegistryType.BLOCK, "minecraft:guarded_by_piglins");
155-
tagRewriter.addEmptyTag(RegistryType.BLOCK, "minecraft:soul_speed_blocks");
156-
tagRewriter.addEmptyTag(RegistryType.BLOCK, "minecraft:soul_fire_base_blocks");
157-
tagRewriter.addEmptyTag(RegistryType.BLOCK, "minecraft:non_flammable_wood");
158-
tagRewriter.addEmptyTag(RegistryType.ITEM, "minecraft:non_flammable_wood");
159-
160-
// The rest of not accessed tags added in older versions; #1830
161-
tagRewriter.addEmptyTags(RegistryType.BLOCK, "minecraft:bamboo_plantable_on", "minecraft:beds", "minecraft:bee_growables",
162-
"minecraft:beehives", "minecraft:coral_plants", "minecraft:crops", "minecraft:dragon_immune", "minecraft:flowers",
163-
"minecraft:portals", "minecraft:shulker_boxes", "minecraft:small_flowers", "minecraft:tall_flowers", "minecraft:trapdoors",
164-
"minecraft:underwater_bonemeals", "minecraft:wither_immune", "minecraft:wooden_fences", "minecraft:wooden_trapdoors");
165-
tagRewriter.addEmptyTags(RegistryType.ENTITY, "minecraft:arrows", "minecraft:beehive_inhabitors", "minecraft:raiders", "minecraft:skeletons");
166-
tagRewriter.addEmptyTags(RegistryType.ITEM, "minecraft:beds", "minecraft:coals", "minecraft:fences", "minecraft:flowers",
167-
"minecraft:lectern_books", "minecraft:music_discs", "minecraft:small_flowers", "minecraft:tall_flowers", "minecraft:trapdoors", "minecraft:walls", "minecraft:wooden_fences");
112+
tagRewriter.addEmptyTags(RegistryType.ITEM, "minecraft:crimson_stems", "minecraft:non_flammable_wood", "minecraft:piglin_loved",
113+
"minecraft:piglin_repellents", "minecraft:soul_fire_base_blocks", "minecraft:warped_stems");
114+
tagRewriter.addEmptyTags(RegistryType.BLOCK, "minecraft:crimson_stems", "minecraft:guarded_by_piglins", "minecraft:hoglin_repellents",
115+
"minecraft:non_flammable_wood", "minecraft:nylium", "minecraft:piglin_repellents", "minecraft:soul_fire_base_blocks", "minecraft:soul_speed_blocks",
116+
"minecraft:strider_warm_blocks", "minecraft:warped_stems");
168117
super.onMappingDataLoaded();
169118
}
170119

@@ -173,6 +122,11 @@ public void init(UserConnection userConnection) {
173122
userConnection.addEntityTracker(this.getClass(), new EntityTrackerBase(userConnection, EntityTypes1_16.PLAYER));
174123
}
175124

125+
@Override
126+
public BackwardsMappingData getMappingData() {
127+
return MAPPINGS;
128+
}
129+
176130
@Override
177131
public BlockItemPacketRewriter20w14infinite getItemRewriter() {
178132
return this.itemRewriter;
@@ -188,9 +142,4 @@ public EntityPacketRewriter20w14infinite getEntityRewriter() {
188142
return this.entityRewriter;
189143
}
190144

191-
@Override
192-
public BackwardsMappingData getMappingData() {
193-
return MAPPINGS;
194-
}
195-
196145
}

common/src/main/java/com/viaversion/viaaprilfools/protocol/s20w14infinitetov1_16/data/BiomeData20w14infinite.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import com.viaversion.viaversion.libs.fastutil.ints.IntArrayList;
2424
import com.viaversion.viaversion.libs.fastutil.ints.IntList;
2525

26-
public class BiomeData20w14infinite {
26+
public final class BiomeData20w14infinite {
2727

2828
private static final IntList VALID_BIOMES = new IntArrayList();
2929

common/src/main/java/com/viaversion/viaaprilfools/protocol/s20w14infinitetov1_16/rewriter/BlockItemPacketRewriter20w14infinite.java

Lines changed: 48 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -40,91 +40,77 @@
4040
import com.viaversion.viaversion.util.CompactArrayUtil;
4141
import java.util.Map;
4242

43-
public class BlockItemPacketRewriter20w14infinite extends ItemRewriter<ClientboundPackets20w14infinite, ServerboundPackets1_16, Protocol20w14infiniteTo1_16> {
43+
public final class BlockItemPacketRewriter20w14infinite extends ItemRewriter<ClientboundPackets20w14infinite, ServerboundPackets1_16, Protocol20w14infiniteTo1_16> {
4444

4545
public BlockItemPacketRewriter20w14infinite(Protocol20w14infiniteTo1_16 protocol) {
4646
super(protocol, Types.ITEM1_13_2, Types.ITEM1_13_2_SHORT_ARRAY);
4747
}
4848

4949
@Override
5050
protected void registerPackets() {
51-
this.registerCooldown(ClientboundPackets20w14infinite.COOLDOWN);
52-
this.registerSetContent(ClientboundPackets20w14infinite.CONTAINER_SET_CONTENT);
53-
this.registerSetSlot(ClientboundPackets20w14infinite.CONTAINER_SET_SLOT);
54-
this.registerMerchantOffers1_14_4(ClientboundPackets20w14infinite.MERCHANT_OFFERS);
55-
this.registerAdvancements(ClientboundPackets20w14infinite.UPDATE_ADVANCEMENTS);
56-
this.registerContainerClick(ServerboundPackets1_16.CONTAINER_CLICK);
57-
this.registerSetCreativeModeSlot(ServerboundPackets1_16.SET_CREATIVE_MODE_SLOT);
58-
final BlockRewriter<ClientboundPackets20w14infinite> blockRewriter = BlockRewriter.for1_14(this.protocol);
51+
registerCooldown(ClientboundPackets20w14infinite.COOLDOWN);
52+
registerSetContent(ClientboundPackets20w14infinite.CONTAINER_SET_CONTENT);
53+
registerSetSlot(ClientboundPackets20w14infinite.CONTAINER_SET_SLOT);
54+
registerMerchantOffers1_14_4(ClientboundPackets20w14infinite.MERCHANT_OFFERS);
55+
registerAdvancements(ClientboundPackets20w14infinite.UPDATE_ADVANCEMENTS);
56+
registerContainerClick(ServerboundPackets1_16.CONTAINER_CLICK);
57+
registerSetCreativeModeSlot(ServerboundPackets1_16.SET_CREATIVE_MODE_SLOT);
58+
59+
final BlockRewriter<ClientboundPackets20w14infinite> blockRewriter = BlockRewriter.for1_14(protocol);
5960
blockRewriter.registerBlockEvent(ClientboundPackets20w14infinite.BLOCK_EVENT);
6061
blockRewriter.registerBlockUpdate(ClientboundPackets20w14infinite.BLOCK_UPDATE);
6162
blockRewriter.registerChunkBlocksUpdate(ClientboundPackets20w14infinite.CHUNK_BLOCKS_UPDATE);
6263
blockRewriter.registerBlockBreakAck(ClientboundPackets20w14infinite.BLOCK_BREAK_ACK);
6364
blockRewriter.registerLevelEvent1_13(ClientboundPackets20w14infinite.LEVEL_EVENT);
6465

65-
protocol.registerClientbound(ClientboundPackets20w14infinite.LIGHT_UPDATE, new PacketHandlers() {
66-
@Override
67-
public void register() {
68-
map(Types.VAR_INT); // x
69-
map(Types.VAR_INT); // y
70-
handler(wrapper -> wrapper.write(Types.BOOLEAN, true)); // Take neighbour's light into account as well
71-
}
66+
protocol.registerClientbound(ClientboundPackets20w14infinite.LIGHT_UPDATE, wrapper -> {
67+
wrapper.passthrough(Types.VAR_INT); // x
68+
wrapper.passthrough(Types.VAR_INT); // y
69+
wrapper.write(Types.BOOLEAN, true); // Take neighbor's light into account as well
7270
});
73-
protocol.registerClientbound(ClientboundPackets20w14infinite.LEVEL_CHUNK, new PacketHandlers() {
74-
@Override
75-
public void register() {
76-
handler(wrapper -> {
77-
Chunk chunk = wrapper.read(ChunkType1_15.TYPE);
78-
wrapper.write(ChunkType1_16.TYPE, chunk);
71+
protocol.registerClientbound(ClientboundPackets20w14infinite.LEVEL_CHUNK, wrapper -> {
72+
final Chunk chunk = wrapper.read(ChunkType1_15.TYPE);
73+
wrapper.write(ChunkType1_16.TYPE, chunk);
74+
chunk.setIgnoreOldLightData(chunk.isFullChunk());
7975

80-
chunk.setIgnoreOldLightData(chunk.isFullChunk());
76+
for (int s = 0; s < chunk.getSections().length; s++) {
77+
final ChunkSection section = chunk.getSections()[s];
78+
if (section == null) {
79+
continue;
80+
}
8181

82-
for (int s = 0; s < chunk.getSections().length; s++) {
83-
ChunkSection section = chunk.getSections()[s];
84-
if (section == null) continue;
85-
final DataPalette blockPalette = section.palette(PaletteType.BLOCKS);
86-
for (int i = 0; i < blockPalette.size(); i++) {
87-
int old = blockPalette.idByIndex(i);
88-
blockPalette.setIdByIndex(i, protocol.getMappingData().getNewBlockStateId(old));
89-
}
90-
}
91-
92-
if (chunk.getBiomeData() != null) {
93-
for (int i = 0; i < chunk.getBiomeData().length; i++) {
94-
if (!BiomeData20w14infinite.isValid(chunk.getBiomeData()[i])) {
95-
chunk.getBiomeData()[i] = 1; // plains
96-
}
97-
}
98-
}
82+
final DataPalette blockPalette = section.palette(PaletteType.BLOCKS);
83+
for (int i = 0; i < blockPalette.size(); i++) {
84+
int old = blockPalette.idByIndex(i);
85+
blockPalette.setIdByIndex(i, protocol.getMappingData().getNewBlockStateId(old));
86+
}
87+
}
9988

100-
CompoundTag heightMaps = chunk.getHeightMap();
101-
for (Map.Entry<String, Tag> heightMapTag : heightMaps) {
102-
LongArrayTag heightMap = (LongArrayTag) heightMapTag.getValue();
103-
int[] heightMapData = new int[256];
104-
CompactArrayUtil.iterateCompactArray(9, heightMapData.length, heightMap.getValue(), (i, v) -> heightMapData[i] = v);
105-
heightMap.setValue(CompactArrayUtil.createCompactArrayWithPadding(9, heightMapData.length, i -> heightMapData[i]));
89+
if (chunk.getBiomeData() != null) {
90+
for (int i = 0; i < chunk.getBiomeData().length; i++) {
91+
if (!BiomeData20w14infinite.isValid(chunk.getBiomeData()[i])) {
92+
chunk.getBiomeData()[i] = 1; // plains
10693
}
107-
});
94+
}
10895
}
109-
});
110-
protocol.registerClientbound(ClientboundPackets20w14infinite.SET_EQUIPMENT, new PacketHandlers() {
111-
@Override
112-
public void register() {
113-
map(Types.VAR_INT); // 0 - Entity ID
11496

115-
handler(wrapper -> {
116-
int slot = wrapper.read(Types.VAR_INT);
117-
wrapper.write(Types.BYTE, (byte) slot);
118-
handleItemToClient(wrapper.user(), wrapper.passthrough(Types.ITEM1_13_2));
119-
});
97+
final CompoundTag heightMaps = chunk.getHeightMap();
98+
for (Map.Entry<String, Tag> heightMapTag : heightMaps) {
99+
LongArrayTag heightMap = (LongArrayTag) heightMapTag.getValue();
100+
int[] heightMapData = new int[256];
101+
CompactArrayUtil.iterateCompactArray(9, heightMapData.length, heightMap.getValue(), (i, v) -> heightMapData[i] = v);
102+
heightMap.setValue(CompactArrayUtil.createCompactArrayWithPadding(9, heightMapData.length, i -> heightMapData[i]));
120103
}
121104
});
105+
protocol.registerClientbound(ClientboundPackets20w14infinite.SET_EQUIPMENT, wrapper -> {
106+
wrapper.passthrough(Types.VAR_INT); // Entity id
107+
final int slot = wrapper.read(Types.VAR_INT);
108+
wrapper.write(Types.BYTE, (byte) slot);
109+
passthroughClientboundItem(wrapper);
110+
});
122111

123-
protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, new PacketHandlers() {
124-
@Override
125-
public void register() {
126-
handler(wrapper -> handleItemToServer(wrapper.user(), wrapper.passthrough(Types.ITEM1_13_2)));
127-
}
112+
protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, wrapper -> {
113+
handleItemToServer(wrapper.user(), wrapper.passthrough(Types.ITEM1_13_2));
128114
});
129115
}
130116

common/src/main/java/com/viaversion/viaaprilfools/protocol/s20w14infinitetov1_16/rewriter/EntityPacketRewriter20w14infinite.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
import com.viaversion.viaversion.util.Key;
3737
import java.util.UUID;
3838

39-
public class EntityPacketRewriter20w14infinite extends EntityRewriter<ClientboundPackets20w14infinite, Protocol20w14infiniteTo1_16> {
39+
public final class EntityPacketRewriter20w14infinite extends EntityRewriter<ClientboundPackets20w14infinite, Protocol20w14infiniteTo1_16> {
4040

4141
private final PacketHandler DIMENSION_HANDLER = wrapper -> {
42-
int dimension = wrapper.read(Types.INT);
42+
final int dimension = wrapper.read(Types.INT);
4343
String dimensionType;
4444
String dimensionName = switch (dimension) {
4545
case -1 -> dimensionType = "minecraft:the_nether";
@@ -70,7 +70,7 @@ protected void registerPackets() {
7070

7171
protocol.registerClientbound(ClientboundPackets20w14infinite.ADD_GLOBAL_ENTITY, ClientboundPackets1_16.ADD_ENTITY, wrapper -> {
7272
final int entityId = wrapper.passthrough(Types.VAR_INT); // entity id
73-
wrapper.user().getEntityTracker(Protocol20w14infiniteTo1_16.class).addEntity(entityId, EntityTypes1_16.LIGHTNING_BOLT);
73+
tracker(wrapper.user()).addEntity(entityId, EntityTypes1_16.LIGHTNING_BOLT);
7474

7575
wrapper.write(Types.UUID, UUID.randomUUID()); // uuid
7676
wrapper.write(Types.VAR_INT, EntityTypes1_16.LIGHTNING_BOLT.getId()); // entity type

0 commit comments

Comments
 (0)