2019-11-30 00:49:29 +00:00
|
|
|
/*
|
2022-01-01 19:03:05 +00:00
|
|
|
* Copyright (c) 2019-2022 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
|
|
|
|
*/
|
|
|
|
|
2021-11-20 23:29:46 +00:00
|
|
|
package org.geysermc.geyser.translator.inventory;
|
2019-11-10 02:20:47 +00:00
|
|
|
|
2021-11-14 05:07:24 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.inventory.ContainerType;
|
2020-10-16 23:25:05 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.data.inventory.ContainerSlotType;
|
|
|
|
import com.nukkitx.protocol.bedrock.data.inventory.StackRequestSlotInfoData;
|
2022-06-08 12:09:14 +00:00
|
|
|
import org.geysermc.geyser.inventory.*;
|
2021-11-22 19:52:26 +00:00
|
|
|
import org.geysermc.geyser.session.GeyserSession;
|
2019-11-10 02:20:47 +00:00
|
|
|
|
2020-10-16 23:25:05 +00:00
|
|
|
public abstract class BaseInventoryTranslator extends InventoryTranslator {
|
2020-12-17 04:52:45 +00:00
|
|
|
public BaseInventoryTranslator(int size) {
|
2020-01-31 01:05:57 +00:00
|
|
|
super(size);
|
2019-11-10 02:20:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-11-22 19:52:26 +00:00
|
|
|
public void updateProperty(GeyserSession session, Inventory inventory, int key, int value) {
|
2020-01-31 01:05:57 +00:00
|
|
|
//
|
2019-11-10 02:20:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-10-16 23:25:05 +00:00
|
|
|
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
|
|
|
|
int slotnum = slotInfoData.getSlot();
|
|
|
|
switch (slotInfoData.getContainer()) {
|
|
|
|
case HOTBAR_AND_INVENTORY:
|
|
|
|
case HOTBAR:
|
|
|
|
case INVENTORY:
|
|
|
|
//hotbar
|
|
|
|
if (slotnum >= 9) {
|
|
|
|
return slotnum + this.size - 9;
|
|
|
|
} else {
|
|
|
|
return slotnum + this.size + 27;
|
|
|
|
}
|
2020-01-31 01:05:57 +00:00
|
|
|
}
|
|
|
|
return slotnum;
|
2019-11-10 02:20:47 +00:00
|
|
|
}
|
2019-11-28 03:55:58 +00:00
|
|
|
|
|
|
|
@Override
|
2020-01-31 01:05:57 +00:00
|
|
|
public int javaSlotToBedrock(int slot) {
|
|
|
|
if (slot >= this.size) {
|
|
|
|
final int tmp = slot - this.size;
|
|
|
|
if (tmp < 27) {
|
|
|
|
return tmp + 9;
|
|
|
|
} else {
|
|
|
|
return tmp - 27;
|
2019-11-28 03:55:58 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-31 01:05:57 +00:00
|
|
|
return slot;
|
2019-12-01 09:26:11 +00:00
|
|
|
}
|
|
|
|
|
2020-10-16 23:25:05 +00:00
|
|
|
@Override
|
|
|
|
public BedrockContainerSlot javaSlotToBedrockContainer(int slot) {
|
|
|
|
if (slot >= this.size) {
|
|
|
|
final int tmp = slot - this.size;
|
|
|
|
if (tmp < 27) {
|
|
|
|
return new BedrockContainerSlot(ContainerSlotType.INVENTORY, tmp + 9);
|
|
|
|
} else {
|
|
|
|
return new BedrockContainerSlot(ContainerSlotType.HOTBAR, tmp - 27);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new IllegalArgumentException("Unknown bedrock slot");
|
|
|
|
}
|
|
|
|
|
2019-12-01 09:26:11 +00:00
|
|
|
@Override
|
|
|
|
public SlotType getSlotType(int javaSlot) {
|
|
|
|
return SlotType.NORMAL;
|
2019-11-28 03:55:58 +00:00
|
|
|
}
|
2020-01-31 01:05:57 +00:00
|
|
|
|
|
|
|
@Override
|
2021-11-14 05:07:24 +00:00
|
|
|
public Inventory createInventory(String name, int windowId, ContainerType containerType, PlayerInventory playerInventory) {
|
|
|
|
return new Container(name, windowId, this.size, containerType, playerInventory);
|
2020-01-31 01:05:57 +00:00
|
|
|
}
|
2019-11-10 02:20:47 +00:00
|
|
|
}
|