forked from GeyserMC/Geyser
Quick inventory fixes. WIP
Temporary. The inventory system will be rewritten very soon.
This commit is contained in:
parent
17a1e82eca
commit
ba9129129c
6 changed files with 31 additions and 41 deletions
|
@ -54,5 +54,8 @@ public class BedrockContainerCloseTranslator extends PacketTranslator<ContainerC
|
||||||
session.getDownstream().getSession().send(closeWindowPacket);
|
session.getDownstream().getSession().send(closeWindowPacket);
|
||||||
InventoryUtils.closeInventory(session, windowId);
|
InventoryUtils.closeInventory(session, windowId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Client wants close confirmation
|
||||||
|
session.sendUpstreamPacket(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,8 @@ package org.geysermc.connector.network.translators.bedrock;
|
||||||
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
|
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
|
||||||
import com.nukkitx.protocol.bedrock.data.entity.EntityDataMap;
|
import com.nukkitx.protocol.bedrock.data.entity.EntityDataMap;
|
||||||
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
|
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.inventory.ContainerType;
|
||||||
|
import com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket;
|
||||||
import org.geysermc.connector.entity.Entity;
|
import org.geysermc.connector.entity.Entity;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
|
@ -46,7 +48,13 @@ public class BedrockInteractTranslator extends PacketTranslator<InteractPacket>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translate(InteractPacket packet, GeyserSession session) {
|
public void translate(InteractPacket packet, GeyserSession session) {
|
||||||
Entity entity = session.getEntityCache().getEntityByGeyserId(packet.getRuntimeEntityId());
|
Entity entity;
|
||||||
|
if (packet.getRuntimeEntityId() == session.getPlayerEntity().getGeyserId()) {
|
||||||
|
//Player is not in entity cache
|
||||||
|
entity = session.getPlayerEntity();
|
||||||
|
} else {
|
||||||
|
entity = session.getEntityCache().getEntityByGeyserId(packet.getRuntimeEntityId());
|
||||||
|
}
|
||||||
if (entity == null)
|
if (entity == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -126,6 +134,14 @@ public class BedrockInteractTranslator extends PacketTranslator<InteractPacket>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case OPEN_INVENTORY:
|
||||||
|
ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket();
|
||||||
|
containerOpenPacket.setId((byte) 0);
|
||||||
|
containerOpenPacket.setType(ContainerType.INVENTORY);
|
||||||
|
containerOpenPacket.setUniqueEntityId(-1);
|
||||||
|
containerOpenPacket.setBlockPosition(entity.getPosition().toInt());
|
||||||
|
session.sendUpstreamPacket(containerOpenPacket);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,42 +39,9 @@ import org.geysermc.connector.utils.InventoryUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CraftingInventoryTranslator extends BaseInventoryTranslator {
|
public class CraftingInventoryTranslator extends BlockInventoryTranslator {
|
||||||
private final InventoryUpdater updater;
|
|
||||||
|
|
||||||
public CraftingInventoryTranslator() {
|
public CraftingInventoryTranslator() {
|
||||||
super(10);
|
super(10, "minecraft:crafting_table", ContainerType.WORKBENCH, new CursorInventoryUpdater());
|
||||||
this.updater = new CursorInventoryUpdater();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void prepareInventory(GeyserSession session, Inventory inventory) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void openInventory(GeyserSession session, Inventory inventory) {
|
|
||||||
ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket();
|
|
||||||
containerOpenPacket.setId((byte) inventory.getId());
|
|
||||||
containerOpenPacket.setType(ContainerType.WORKBENCH);
|
|
||||||
containerOpenPacket.setBlockPosition(inventory.getHolderPosition());
|
|
||||||
containerOpenPacket.setUniqueEntityId(inventory.getHolderId());
|
|
||||||
session.sendUpstreamPacket(containerOpenPacket);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void closeInventory(GeyserSession session, Inventory inventory) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateInventory(GeyserSession session, Inventory inventory) {
|
|
||||||
updater.updateInventory(this, session, inventory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateSlot(GeyserSession session, Inventory inventory, int slot) {
|
|
||||||
updater.updateSlot(this, session, inventory, slot);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -83,8 +50,6 @@ public class CraftingInventoryTranslator extends BaseInventoryTranslator {
|
||||||
int slotnum = action.getSlot();
|
int slotnum = action.getSlot();
|
||||||
if (slotnum >= 32 && 42 >= slotnum) {
|
if (slotnum >= 32 && 42 >= slotnum) {
|
||||||
return slotnum - 31;
|
return slotnum - 31;
|
||||||
} else if (slotnum == 50) {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.bedrockSlotToJava(action);
|
return super.bedrockSlotToJava(action);
|
||||||
|
|
|
@ -159,10 +159,10 @@ public class PlayerInventoryTranslator extends InventoryTranslator {
|
||||||
case ContainerId.UI:
|
case ContainerId.UI:
|
||||||
if (slotnum >= 28 && 31 >= slotnum) {
|
if (slotnum >= 28 && 31 >= slotnum) {
|
||||||
return slotnum - 27;
|
return slotnum - 27;
|
||||||
} else if (slotnum == 50) {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case ContainerId.CRAFTING_RESULT:
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return slotnum;
|
return slotnum;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class InventoryActionDataTranslator {
|
||||||
InventoryActionData containerAction = null;
|
InventoryActionData containerAction = null;
|
||||||
boolean refresh = false;
|
boolean refresh = false;
|
||||||
for (InventoryActionData action : actions) {
|
for (InventoryActionData action : actions) {
|
||||||
if (action.getSource().getContainerId() == ContainerId.CRAFTING_USE_INGREDIENT || action.getSource().getContainerId() == ContainerId.CRAFTING_RESULT) {
|
if (action.getSource().getContainerId() == ContainerId.CRAFTING_USE_INGREDIENT) {
|
||||||
return;
|
return;
|
||||||
} else if (action.getSource().getType() == InventorySource.Type.WORLD_INTERACTION) {
|
} else if (action.getSource().getType() == InventorySource.Type.WORLD_INTERACTION) {
|
||||||
worldAction = action;
|
worldAction = action;
|
||||||
|
|
|
@ -97,6 +97,11 @@ public class InventoryUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void closeWindow(GeyserSession session, int windowId) {
|
public static void closeWindow(GeyserSession session, int windowId) {
|
||||||
|
//TODO: Investigate client crash when force closing window and opening a new one
|
||||||
|
//Instead, the window will eventually close by removing the fake blocks
|
||||||
|
session.setLastWindowCloseTime(System.currentTimeMillis());
|
||||||
|
|
||||||
|
/*
|
||||||
//Spamming close window packets can bug the client
|
//Spamming close window packets can bug the client
|
||||||
if (System.currentTimeMillis() - session.getLastWindowCloseTime() > 500) {
|
if (System.currentTimeMillis() - session.getLastWindowCloseTime() > 500) {
|
||||||
ContainerClosePacket closePacket = new ContainerClosePacket();
|
ContainerClosePacket closePacket = new ContainerClosePacket();
|
||||||
|
@ -104,6 +109,7 @@ public class InventoryUtils {
|
||||||
session.sendUpstreamPacket(closePacket);
|
session.sendUpstreamPacket(closePacket);
|
||||||
session.setLastWindowCloseTime(System.currentTimeMillis());
|
session.setLastWindowCloseTime(System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateCursor(GeyserSession session) {
|
public static void updateCursor(GeyserSession session) {
|
||||||
|
|
Loading…
Reference in a new issue