2019-11-30 00:49:29 +00:00
|
|
|
/*
|
2020-01-31 01:05:57 +00:00
|
|
|
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
|
2019-11-30 00:49:29 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
|
|
|
*/
|
|
|
|
|
2019-11-10 02:20:47 +00:00
|
|
|
package org.geysermc.connector.network.translators.inventory;
|
|
|
|
|
2020-01-31 01:05:57 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
2020-06-23 00:11:09 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.data.inventory.ContainerId;
|
|
|
|
import com.nukkitx.protocol.bedrock.data.inventory.ContainerType;
|
|
|
|
import com.nukkitx.protocol.bedrock.data.inventory.InventoryActionData;
|
|
|
|
import com.nukkitx.protocol.bedrock.data.inventory.InventorySource;
|
2019-11-10 02:20:47 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket;
|
2020-07-30 20:11:35 +00:00
|
|
|
import org.geysermc.connector.GeyserConnector;
|
2019-11-10 02:20:47 +00:00
|
|
|
import org.geysermc.connector.inventory.Inventory;
|
|
|
|
import org.geysermc.connector.network.session.GeyserSession;
|
2020-01-31 01:05:57 +00:00
|
|
|
import org.geysermc.connector.network.translators.inventory.updater.CursorInventoryUpdater;
|
|
|
|
import org.geysermc.connector.network.translators.inventory.updater.InventoryUpdater;
|
|
|
|
import org.geysermc.connector.utils.InventoryUtils;
|
2019-11-10 02:20:47 +00:00
|
|
|
|
2020-01-31 01:05:57 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
2020-06-27 02:51:09 +00:00
|
|
|
public class CraftingInventoryTranslator extends BlockInventoryTranslator {
|
2020-01-31 01:05:57 +00:00
|
|
|
public CraftingInventoryTranslator() {
|
2020-06-27 02:51:09 +00:00
|
|
|
super(10, "minecraft:crafting_table", ContainerType.WORKBENCH, new CursorInventoryUpdater());
|
2019-11-10 02:20:47 +00:00
|
|
|
}
|
2019-11-28 03:55:58 +00:00
|
|
|
|
|
|
|
@Override
|
2020-02-26 07:31:55 +00:00
|
|
|
public int bedrockSlotToJava(InventoryActionData action) {
|
2020-07-30 20:11:35 +00:00
|
|
|
if (action.getSlot() == 50) {
|
|
|
|
GeyserConnector.getInstance().getLogger().warning("Slot 50 found, please report: " + action);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-06-23 00:11:09 +00:00
|
|
|
if (action.getSource().getContainerId() == ContainerId.UI) {
|
2019-12-01 09:26:11 +00:00
|
|
|
int slotnum = action.getSlot();
|
2019-11-28 03:55:58 +00:00
|
|
|
if (slotnum >= 32 && 42 >= slotnum) {
|
|
|
|
return slotnum - 31;
|
|
|
|
}
|
|
|
|
}
|
2019-12-01 09:26:11 +00:00
|
|
|
return super.bedrockSlotToJava(action);
|
|
|
|
}
|
|
|
|
|
2020-01-31 01:05:57 +00:00
|
|
|
@Override
|
|
|
|
public int javaSlotToBedrock(int slot) {
|
2020-06-02 16:48:26 +00:00
|
|
|
if (slot < size) {
|
|
|
|
return slot == 0 ? 50 : slot + 31;
|
|
|
|
}
|
|
|
|
return super.javaSlotToBedrock(slot);
|
2020-01-31 01:05:57 +00:00
|
|
|
}
|
|
|
|
|
2019-12-01 09:26:11 +00:00
|
|
|
@Override
|
|
|
|
public SlotType getSlotType(int javaSlot) {
|
|
|
|
if (javaSlot == 0)
|
|
|
|
return SlotType.OUTPUT;
|
|
|
|
return SlotType.NORMAL;
|
2019-11-28 03:55:58 +00:00
|
|
|
}
|
2020-01-31 01:05:57 +00:00
|
|
|
|
|
|
|
@Override
|
2020-02-26 07:31:55 +00:00
|
|
|
public void translateActions(GeyserSession session, Inventory inventory, List<InventoryActionData> actions) {
|
2020-01-31 01:05:57 +00:00
|
|
|
if (session.getGameMode() == GameMode.CREATIVE) {
|
2020-02-26 07:31:55 +00:00
|
|
|
for (InventoryActionData action : actions) {
|
2020-01-31 01:05:57 +00:00
|
|
|
if (action.getSource().getType() == InventorySource.Type.CREATIVE) {
|
|
|
|
updateInventory(session, inventory);
|
|
|
|
InventoryUtils.updateCursor(session);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
super.translateActions(session, inventory, actions);
|
|
|
|
}
|
2019-11-10 02:20:47 +00:00
|
|
|
}
|