2020-12-25 01:43:24 +00:00
|
|
|
/*
|
2022-01-01 19:03:05 +00:00
|
|
|
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
2020-12-25 01:43:24 +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
|
|
|
|
*/
|
|
|
|
|
2021-11-20 23:29:46 +00:00
|
|
|
package org.geysermc.geyser.translator.inventory;
|
2020-12-25 01:43:24 +00:00
|
|
|
|
2021-11-14 05:07:24 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.inventory.ContainerType;
|
2022-10-30 00:23:21 +00:00
|
|
|
import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerSlotType;
|
2022-12-21 00:47:45 +00:00
|
|
|
import org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.ItemStackRequestSlotData;
|
2022-06-08 12:09:14 +00:00
|
|
|
import org.geysermc.geyser.inventory.*;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.inventory.updater.UIInventoryUpdater;
|
2022-12-29 20:10:40 +00:00
|
|
|
import org.geysermc.geyser.item.Items;
|
2022-06-08 12:09:14 +00:00
|
|
|
import org.geysermc.geyser.session.GeyserSession;
|
2020-12-25 01:43:24 +00:00
|
|
|
|
|
|
|
public class CartographyInventoryTranslator extends AbstractBlockInventoryTranslator {
|
|
|
|
public CartographyInventoryTranslator() {
|
2022-10-30 00:23:21 +00:00
|
|
|
super(3, "minecraft:cartography_table", org.cloudburstmc.protocol.bedrock.data.inventory.ContainerType.CARTOGRAPHY, UIInventoryUpdater.INSTANCE);
|
2020-12-25 01:43:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-01-11 21:56:11 +00:00
|
|
|
protected boolean shouldRejectItemPlace(GeyserSession session, Inventory inventory, ContainerSlotType bedrockSourceContainer,
|
2021-03-08 19:17:31 +00:00
|
|
|
int javaSourceSlot, ContainerSlotType bedrockDestinationContainer, int javaDestinationSlot) {
|
2020-12-26 21:41:50 +00:00
|
|
|
if (javaDestinationSlot == 0) {
|
2021-03-10 19:43:54 +00:00
|
|
|
// Bedrock Edition can use paper or an empty map in slot 0
|
2020-12-26 21:41:50 +00:00
|
|
|
GeyserItemStack itemStack = javaSourceSlot == -1 ? session.getPlayerInventory().getCursor() : inventory.getItem(javaSourceSlot);
|
2022-12-29 20:10:40 +00:00
|
|
|
return itemStack.asItem() == Items.PAPER || itemStack.asItem() == Items.MAP;
|
2020-12-27 03:55:14 +00:00
|
|
|
} else if (javaDestinationSlot == 1) {
|
2021-03-10 19:43:54 +00:00
|
|
|
// Bedrock Edition can use a compass to create locator maps, or use a filled map, in the ADDITIONAL slot
|
2020-12-25 01:43:24 +00:00
|
|
|
GeyserItemStack itemStack = javaSourceSlot == -1 ? session.getPlayerInventory().getCursor() : inventory.getItem(javaSourceSlot);
|
2022-12-29 20:10:40 +00:00
|
|
|
return itemStack.asItem() == Items.COMPASS || itemStack.asItem() == Items.FILLED_MAP;
|
2020-12-25 01:43:24 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-12-21 00:47:45 +00:00
|
|
|
public int bedrockSlotToJava(ItemStackRequestSlotData slotInfoData) {
|
2021-09-10 18:10:56 +00:00
|
|
|
return switch (slotInfoData.getContainer()) {
|
|
|
|
case CARTOGRAPHY_INPUT -> 0;
|
|
|
|
case CARTOGRAPHY_ADDITIONAL -> 1;
|
2022-12-23 17:06:41 +00:00
|
|
|
case CARTOGRAPHY_RESULT, CREATED_OUTPUT -> 2;
|
2021-09-10 18:10:56 +00:00
|
|
|
default -> super.bedrockSlotToJava(slotInfoData);
|
|
|
|
};
|
2020-12-25 01:43:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BedrockContainerSlot javaSlotToBedrockContainer(int slot) {
|
2021-09-10 18:10:56 +00:00
|
|
|
return switch (slot) {
|
|
|
|
case 0 -> new BedrockContainerSlot(ContainerSlotType.CARTOGRAPHY_INPUT, 12);
|
|
|
|
case 1 -> new BedrockContainerSlot(ContainerSlotType.CARTOGRAPHY_ADDITIONAL, 13);
|
|
|
|
case 2 -> new BedrockContainerSlot(ContainerSlotType.CARTOGRAPHY_RESULT, 50);
|
|
|
|
default -> super.javaSlotToBedrockContainer(slot);
|
|
|
|
};
|
2020-12-25 01:43:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int javaSlotToBedrock(int slot) {
|
2021-09-10 18:10:56 +00:00
|
|
|
return switch (slot) {
|
|
|
|
case 0 -> 12;
|
|
|
|
case 1 -> 13;
|
|
|
|
case 2 -> 50;
|
|
|
|
default -> super.javaSlotToBedrock(slot);
|
|
|
|
};
|
2020-12-25 01:43:24 +00:00
|
|
|
}
|
2020-12-27 03:55:14 +00:00
|
|
|
|
|
|
|
@Override
|
2021-11-14 05:07:24 +00:00
|
|
|
public Inventory createInventory(String name, int windowId, ContainerType containerType, PlayerInventory playerInventory) {
|
|
|
|
return new CartographyContainer(name, windowId, this.size, containerType, playerInventory);
|
2020-12-27 03:55:14 +00:00
|
|
|
}
|
2020-12-25 01:43:24 +00:00
|
|
|
}
|