2019-11-05 23:17:22 +00:00
|
|
|
/*
|
2020-01-31 01:05:57 +00:00
|
|
|
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
|
2019-11-05 23:17:22 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.geysermc.connector.network.translators.inventory;
|
|
|
|
|
2020-06-23 00:11:09 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.data.inventory.ContainerType;
|
|
|
|
import com.nukkitx.protocol.bedrock.data.inventory.InventoryActionData;
|
2019-11-05 23:17:22 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.packet.ContainerSetDataPacket;
|
|
|
|
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.ContainerInventoryUpdater;
|
2019-11-05 23:17:22 +00:00
|
|
|
|
2020-01-31 01:05:57 +00:00
|
|
|
public class BrewingInventoryTranslator extends BlockInventoryTranslator {
|
|
|
|
public BrewingInventoryTranslator() {
|
|
|
|
super(5, "minecraft:brewing_stand[has_bottle_0=false,has_bottle_1=false,has_bottle_2=false]", ContainerType.BREWING_STAND, new ContainerInventoryUpdater());
|
2019-11-05 23:17:22 +00:00
|
|
|
}
|
|
|
|
|
2019-12-07 23:56:00 +00:00
|
|
|
@Override
|
|
|
|
public void openInventory(GeyserSession session, Inventory inventory) {
|
|
|
|
super.openInventory(session, inventory);
|
|
|
|
ContainerSetDataPacket dataPacket = new ContainerSetDataPacket();
|
|
|
|
dataPacket.setWindowId((byte) inventory.getId());
|
|
|
|
dataPacket.setProperty(ContainerSetDataPacket.BREWING_STAND_FUEL_TOTAL);
|
|
|
|
dataPacket.setValue(20);
|
2020-05-05 15:51:43 +00:00
|
|
|
session.sendUpstreamPacket(dataPacket);
|
2019-12-07 23:56:00 +00:00
|
|
|
}
|
|
|
|
|
2019-11-05 23:17:22 +00:00
|
|
|
@Override
|
|
|
|
public void updateProperty(GeyserSession session, Inventory inventory, int key, int value) {
|
|
|
|
ContainerSetDataPacket dataPacket = new ContainerSetDataPacket();
|
|
|
|
dataPacket.setWindowId((byte) inventory.getId());
|
|
|
|
switch (key) {
|
|
|
|
case 0:
|
2019-12-07 23:56:00 +00:00
|
|
|
dataPacket.setProperty(ContainerSetDataPacket.BREWING_STAND_BREW_TIME);
|
2019-11-05 23:17:22 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2019-12-07 23:56:00 +00:00
|
|
|
dataPacket.setProperty(ContainerSetDataPacket.BREWING_STAND_FUEL_AMOUNT);
|
2019-11-05 23:17:22 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2019-12-07 23:56:00 +00:00
|
|
|
dataPacket.setValue(value);
|
2020-05-05 15:51:43 +00:00
|
|
|
session.sendUpstreamPacket(dataPacket);
|
2019-11-05 23:17:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-02-26 07:31:55 +00:00
|
|
|
public int bedrockSlotToJava(InventoryActionData action) {
|
2020-01-31 01:05:57 +00:00
|
|
|
final int slot = super.bedrockSlotToJava(action);
|
|
|
|
switch (slot) {
|
2019-12-01 09:26:11 +00:00
|
|
|
case 0:
|
|
|
|
return 3;
|
|
|
|
case 1:
|
|
|
|
return 0;
|
|
|
|
case 2:
|
|
|
|
return 1;
|
|
|
|
case 3:
|
|
|
|
return 2;
|
|
|
|
default:
|
2020-01-31 01:05:57 +00:00
|
|
|
return slot;
|
2019-11-05 23:17:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-01-31 01:05:57 +00:00
|
|
|
public int javaSlotToBedrock(int slot) {
|
|
|
|
switch (slot) {
|
2019-11-05 23:17:22 +00:00
|
|
|
case 0:
|
|
|
|
return 1;
|
|
|
|
case 1:
|
|
|
|
return 2;
|
|
|
|
case 2:
|
|
|
|
return 3;
|
|
|
|
case 3:
|
|
|
|
return 0;
|
|
|
|
}
|
2020-01-31 01:05:57 +00:00
|
|
|
return super.javaSlotToBedrock(slot);
|
2019-11-05 23:17:22 +00:00
|
|
|
}
|
|
|
|
}
|