Quick inventory fixes. WIP

Temporary. The inventory system will be rewritten very soon.
This commit is contained in:
AJ Ferguson 2020-06-26 18:51:09 -08:00
parent 17a1e82eca
commit ba9129129c
6 changed files with 31 additions and 41 deletions

View file

@ -54,5 +54,8 @@ public class BedrockContainerCloseTranslator extends PacketTranslator<ContainerC
session.getDownstream().getSession().send(closeWindowPacket);
InventoryUtils.closeInventory(session, windowId);
}
//Client wants close confirmation
session.sendUpstreamPacket(packet);
}
}

View file

@ -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.EntityDataMap;
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.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
@ -46,7 +48,13 @@ public class BedrockInteractTranslator extends PacketTranslator<InteractPacket>
@Override
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)
return;
@ -126,6 +134,14 @@ public class BedrockInteractTranslator extends PacketTranslator<InteractPacket>
}
}
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;
}
}
}

View file

@ -39,42 +39,9 @@ import org.geysermc.connector.utils.InventoryUtils;
import java.util.List;
public class CraftingInventoryTranslator extends BaseInventoryTranslator {
private final InventoryUpdater updater;
public class CraftingInventoryTranslator extends BlockInventoryTranslator {
public CraftingInventoryTranslator() {
super(10);
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);
super(10, "minecraft:crafting_table", ContainerType.WORKBENCH, new CursorInventoryUpdater());
}
@Override
@ -83,8 +50,6 @@ public class CraftingInventoryTranslator extends BaseInventoryTranslator {
int slotnum = action.getSlot();
if (slotnum >= 32 && 42 >= slotnum) {
return slotnum - 31;
} else if (slotnum == 50) {
return 0;
}
}
return super.bedrockSlotToJava(action);

View file

@ -159,10 +159,10 @@ public class PlayerInventoryTranslator extends InventoryTranslator {
case ContainerId.UI:
if (slotnum >= 28 && 31 >= slotnum) {
return slotnum - 27;
} else if (slotnum == 50) {
return 0;
}
break;
case ContainerId.CRAFTING_RESULT:
return 0;
}
return slotnum;
}

View file

@ -55,7 +55,7 @@ public class InventoryActionDataTranslator {
InventoryActionData containerAction = null;
boolean refresh = false;
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;
} else if (action.getSource().getType() == InventorySource.Type.WORLD_INTERACTION) {
worldAction = action;

View file

@ -97,6 +97,11 @@ public class InventoryUtils {
}
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
if (System.currentTimeMillis() - session.getLastWindowCloseTime() > 500) {
ContainerClosePacket closePacket = new ContainerClosePacket();
@ -104,6 +109,7 @@ public class InventoryUtils {
session.sendUpstreamPacket(closePacket);
session.setLastWindowCloseTime(System.currentTimeMillis());
}
*/
}
public static void updateCursor(GeyserSession session) {