Skip to content

Commit

Permalink
Add UserConnection param to item rewriter methods
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Apr 21, 2024
1 parent a3fa487 commit cf0e9c9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public void register() {
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);

for (int i = 0; i < size; ++i) {
BlockItemPackets3D_Shareware.this.handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2));
BlockItemPackets3D_Shareware.this.handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2));
BlockItemPackets3D_Shareware.this.handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2));
BlockItemPackets3D_Shareware.this.handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2));
if (wrapper.passthrough(Type.BOOLEAN)) {
BlockItemPackets3D_Shareware.this.handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2));
BlockItemPackets3D_Shareware.this.handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2));
}

wrapper.passthrough(Type.BOOLEAN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package net.raphimc.viaaprilfools.protocols.protocol1_14to3D_Shareware.packets;

import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
Expand Down Expand Up @@ -51,7 +52,7 @@ public void register() {
map(Type.SHORT); // 10 - Velocity Y
map(Type.SHORT); // 11 - Velocity Z
map(Types1_14.METADATA_LIST); // 12 - Metadata
handler(packetWrapper -> handleMetadata(packetWrapper.get(Types1_14.METADATA_LIST, 0)));
handler(packetWrapper -> handleMetadata(packetWrapper.user(), packetWrapper.get(Types1_14.METADATA_LIST, 0)));
}
});
this.protocol.registerClientbound(ClientboundPackets3D_Shareware.SPAWN_PLAYER, new PacketHandlers() {
Expand All @@ -65,23 +66,23 @@ public void register() {
map(Type.BYTE); // 5 - Yaw
map(Type.BYTE); // 6 - Pitch
map(Types1_14.METADATA_LIST); // 7 - Metadata
handler(packetWrapper -> handleMetadata(packetWrapper.get(Types1_14.METADATA_LIST, 0)));
handler(packetWrapper -> handleMetadata(packetWrapper.user(), packetWrapper.get(Types1_14.METADATA_LIST, 0)));
}
});
this.protocol.registerClientbound(ClientboundPackets3D_Shareware.ENTITY_METADATA, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT); // 0 - Entity ID
map(Types1_14.METADATA_LIST);
handler(packetWrapper -> handleMetadata(packetWrapper.get(Types1_14.METADATA_LIST, 0)));
handler(packetWrapper -> handleMetadata(packetWrapper.user(), packetWrapper.get(Types1_14.METADATA_LIST, 0)));
}
});
}

public void handleMetadata(final List<Metadata> metadataList) {
public void handleMetadata(final UserConnection user, final List<Metadata> metadataList) {
for (Metadata metadata : metadataList) {
if (metadata.metaType() == Types1_14.META_TYPES.itemType) {
metadata.setValue(this.protocol.getItemRewriter().handleItemToClient(metadata.value()));
metadata.setValue(this.protocol.getItemRewriter().handleItemToClient(user, metadata.value()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ public void register() {
handler(wrapper -> {
int slot = wrapper.read(Type.VAR_INT);
wrapper.write(Type.BYTE, (byte) slot);
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2));
handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2));
});
}
});

protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, new PacketHandlers() {
@Override
public void register() {
handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2)));
handler(wrapper -> handleItemToServer(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)));
}
});
}
Expand Down

0 comments on commit cf0e9c9

Please sign in to comment.