use of com.github.dirtpowered.dirtmv.network.versions.Release47To5.inventory.WindowTypeTracker in project DirtMultiversion by DirtPowered.
the class InventoryPackets method registerTranslators.
@Override
public void registerTranslators() {
// set slot
addTranslator(0x2F, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
short windowId = data.read(Type.UNSIGNED_BYTE, 0);
short slot = data.read(Type.SHORT, 1);
int windowType = 0;
if (storage.hasObject(WindowTypeTracker.class)) {
WindowTypeTracker windowTracker = storage.get(WindowTypeTracker.class);
windowType = windowTracker.getWindowType(windowId);
}
ItemStack originalItem = data.read(Type.V1_3R_ITEM, 2);
if (originalItem == null)
return new PacketData(0x2F, data.getObjects());
ItemStack itemStack = itemRemapper.replaceItem(originalItem);
if (windowType == 4) {
if (slot >= 1) {
slot++;
}
}
// quick-bar cache
if (storage.hasObject(QuickBarTracker.class)) {
QuickBarTracker quickBarTracker = storage.get(QuickBarTracker.class);
quickBarTracker.setItem(slot, itemStack);
}
return PacketUtil.createPacket(0x2F, new TypeHolder[] { data.read(0), set(Type.SHORT, slot), set(Type.V1_8R_ITEM, itemStack) });
}
});
// window items
addTranslator(0x30, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
short windowId = data.read(Type.UNSIGNED_BYTE, 0);
ItemStack[] itemArray = data.read(Type.V1_3R_ITEM_ARRAY, 1);
int windowType = 0;
if (storage.hasObject(WindowTypeTracker.class)) {
WindowTypeTracker windowTracker = storage.get(WindowTypeTracker.class);
windowType = windowTracker.getWindowType(windowId);
}
if (windowType == 4) {
ItemStack[] copy = itemArray;
itemArray = new ItemStack[copy.length + 1];
itemArray[0] = copy[0];
int slot = 0;
while (slot < copy.length - 1) {
itemArray[slot + 2] = copy[slot + 1];
slot++;
}
// lapis
itemArray[1] = new ItemStack(351, 3, 4, null);
}
for (int i = 0; i < itemArray.length; i++) {
ItemStack originalItem = itemArray[i];
ItemStack item = originalItem;
if (originalItem != null) {
item = itemRemapper.replaceItem(originalItem);
}
itemArray[i] = item;
// quick-bar cache
if (storage.hasObject(QuickBarTracker.class)) {
QuickBarTracker quickBarTracker = storage.get(QuickBarTracker.class);
quickBarTracker.setItem(i, item);
}
}
return PacketUtil.createPacket(0x30, new TypeHolder[] { data.read(0), set(Type.V1_8R_ITEM_ARRAY, itemArray) });
}
});
// open window
addTranslator(0x2D, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
short windowId = data.read(Type.UNSIGNED_BYTE, 0);
short type = data.read(Type.UNSIGNED_BYTE, 1);
String title = data.read(Type.V1_7_STRING, 2);
short slots = data.read(Type.UNSIGNED_BYTE, 3);
// non storage inventories have always 0 slots
slots = InventoryUtils.isNonStorageInventory(type) ? 0 : slots;
// cache window type (for enchanting tables)
if (storage.hasObject(WindowTypeTracker.class)) {
WindowTypeTracker windowTracker = storage.get(WindowTypeTracker.class);
windowTracker.setWindowTypeFor(windowId, type);
}
return PacketUtil.createPacket(0x2D, new TypeHolder[] { data.read(0), set(Type.V1_7_STRING, InventoryUtils.getNamedTypeFromId(type)), set(Type.V1_7_STRING, InventoryUtils.addTranslateComponent(type == 6 ? "entity.Villager.name" : title)), set(Type.UNSIGNED_BYTE, slots) });
}
});
// window click
addTranslator(0x0E, ProtocolState.PLAY, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
byte windowId = data.read(Type.BYTE, 0);
short slot = data.read(Type.SHORT, 1);
int windowType = 0;
if (storage.hasObject(WindowTypeTracker.class)) {
WindowTypeTracker windowTracker = storage.get(WindowTypeTracker.class);
windowType = windowTracker.getWindowType(windowId);
}
if (windowType == 4) {
if (slot > 1) {
slot--;
}
}
if (storage.hasObject(QuickBarTracker.class)) {
QuickBarTracker cache = storage.get(QuickBarTracker.class);
boolean shiftClick = data.read(Type.BYTE, 4) == 1;
updateLocalInventory(cache, slot, shiftClick);
}
return PacketUtil.createPacket(0x0E, new TypeHolder[] { data.read(0), set(Type.SHORT, slot), data.read(2), data.read(3), data.read(4), set(Type.V1_3R_ITEM, data.read(Type.V1_8R_ITEM, 5)) });
}
});
// creative item get
addTranslator(0x10, ProtocolState.PLAY, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ItemStack item = data.read(Type.V1_8R_ITEM, 1);
boolean notNull = item != null;
if (notNull && !creativeTab.exists(item.getItemId())) {
// replace all unknown items to stone
item.setItemId(1);
item.setData(0);
}
return PacketUtil.createPacket(0x10, new TypeHolder[] { data.read(0), set(Type.V1_3R_ITEM, item) });
}
});
// change held slot
addTranslator(0x09, ProtocolState.PLAY, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
if (storage.hasObject(QuickBarTracker.class)) {
QuickBarTracker quickBarTracker = storage.get(QuickBarTracker.class);
quickBarTracker.setCurrentHotBarSlot(data.read(Type.SHORT, 0));
}
return data;
}
});
// change held slot (server-side)
addTranslator(0x09, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ProtocolStorage storage = session.getStorage();
if (storage.hasObject(QuickBarTracker.class)) {
QuickBarTracker quickBarTracker = storage.get(QuickBarTracker.class);
quickBarTracker.setCurrentHotBarSlot(data.read(Type.BYTE, 0));
}
return data;
}
});
// window property
addTranslator(0x31, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
int property = data.read(Type.SHORT, 1);
switch(property) {
case 0:
property = 2;
PacketData windowProperty = PacketUtil.createPacket(0x31, new TypeHolder[] { data.read(0), set(Type.SHORT, (short) 3), set(Type.SHORT, (short) 200) });
session.sendPacket(windowProperty, PacketDirection.TO_CLIENT, getFrom());
break;
case 1:
property = 0;
break;
case 2:
property = 1;
break;
}
return PacketUtil.createPacket(0x31, new TypeHolder[] { data.read(0), set(Type.SHORT, (short) property), data.read(2) });
}
});
}
use of com.github.dirtpowered.dirtmv.network.versions.Release47To5.inventory.WindowTypeTracker in project DirtMultiversion by DirtPowered.
the class ProtocolRelease47To5 method onConnect.
@Override
public void onConnect(ServerSession session) {
ProtocolStorage storage = session.getStorage();
storage.set(OnGroundTracker.class, new OnGroundTracker());
storage.set(WindowTypeTracker.class, new WindowTypeTracker());
storage.set(QuickBarTracker.class, new QuickBarTracker());
// additional block storage (for nether portal rotation fix)
storage.set(PortalFrameCache.class, new PortalFrameCache());
if (session.getMain().getConfiguration().enableViaVersion()) {
// it's not needed for 1.8->1.7, but ViaVersion will need that to fix issues
// with eating, entering portals, effects (potions)
storage.set(PlayerMovementTracker.class, new PlayerMovementTracker());
}
// check if 1.6 entity tracker exists - if not, create one
if (!storage.hasObject(EntityTracker.class)) {
storage.set(V1_7EntityTracker.class, new V1_7EntityTracker());
}
// fixes block hardness inconsistencies
if (session.getMain().getConfiguration().getServerVersion() == MinecraftVersion.B1_7_3) {
storage.set(BlockMiningTimeFixer.class, new BlockMiningTimeFixer(session));
}
}
Aggregations