Skip to content

Commit

Permalink
Add some transformations for slot changes
Browse files Browse the repository at this point in the history
  • Loading branch information
booky10 committed Aug 30, 2024
1 parent bdccde4 commit 1260aa1
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
package com.github.retrooper.packetevents.util;

import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.player.Equipment;
import com.github.retrooper.packetevents.protocol.world.chunk.LightData;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerChunkData;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerDestroyEntities;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityEquipment;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSetCursorItem;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSetPlayerInventory;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSetSlot;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUpdateLight;

import java.util.Collections;
Expand Down Expand Up @@ -73,6 +75,18 @@ public static PacketWrapper<?>[] transform(PacketWrapper<?> wrapper) {

return output;
}
} else if (wrapper instanceof WrapperPlayServerSetSlot) {
// some plugins will probably fail to update this correctly, so just transform it when sending
WrapperPlayServerSetSlot setSlot = (WrapperPlayServerSetSlot) wrapper;
if (setSlot.getSlot() == -1) { // transform to cursor item
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_21_2)) {
wrapper = new WrapperPlayServerSetCursorItem(setSlot.getItem());
}
} else if (setSlot.getWindowId() == -2) { // transform to player inventory set
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_21_2)) {
wrapper = new WrapperPlayServerSetPlayerInventory(setSlot.getSlot(), setSlot.getItem());
}
}
}
return new PacketWrapper<?>[]{wrapper};
}
Expand Down

0 comments on commit 1260aa1

Please sign in to comment.