2019-10-20 21:25:41 +00:00
|
|
|
/*
|
2021-01-01 15:10:36 +00:00
|
|
|
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
2019-10-20 21:25:41 +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-10-20 21:25:41 +00:00
|
|
|
|
2020-06-23 00:11:09 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.data.inventory.ContainerType;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.inventory.Inventory;
|
2021-11-21 18:36:42 +00:00
|
|
|
import org.geysermc.geyser.session.GeyserSessionImpl;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.inventory.holder.BlockInventoryHolder;
|
|
|
|
import org.geysermc.geyser.inventory.holder.InventoryHolder;
|
|
|
|
import org.geysermc.geyser.inventory.updater.InventoryUpdater;
|
2020-06-02 16:48:26 +00:00
|
|
|
|
2020-12-17 04:52:45 +00:00
|
|
|
/**
|
|
|
|
* Provided as a base for any inventory that requires a block for opening it
|
|
|
|
*/
|
|
|
|
public abstract class AbstractBlockInventoryTranslator extends BaseInventoryTranslator {
|
2020-06-02 16:48:26 +00:00
|
|
|
private final InventoryHolder holder;
|
2020-12-17 04:52:45 +00:00
|
|
|
private final InventoryUpdater updater;
|
2019-10-20 21:25:41 +00:00
|
|
|
|
2020-12-17 04:52:45 +00:00
|
|
|
/**
|
|
|
|
* @param size the amount of slots that the inventory adds alongside the base inventory slots
|
|
|
|
* @param javaBlockIdentifier a Java block identifier that is used as a temporary block
|
|
|
|
* @param containerType the container type of this inventory
|
|
|
|
* @param updater updater
|
2021-02-12 19:39:41 +00:00
|
|
|
* @param additionalValidBlocks any other block identifiers that can safely use this inventory without a fake block
|
2020-12-17 04:52:45 +00:00
|
|
|
*/
|
2021-02-12 19:39:41 +00:00
|
|
|
public AbstractBlockInventoryTranslator(int size, String javaBlockIdentifier, ContainerType containerType, InventoryUpdater updater,
|
|
|
|
String... additionalValidBlocks) {
|
2020-12-17 04:52:45 +00:00
|
|
|
super(size);
|
2021-02-12 19:39:41 +00:00
|
|
|
this.holder = new BlockInventoryHolder(javaBlockIdentifier, containerType, additionalValidBlocks);
|
2020-12-17 04:52:45 +00:00
|
|
|
this.updater = updater;
|
2020-06-02 16:48:26 +00:00
|
|
|
}
|
|
|
|
|
2021-02-26 02:51:50 +00:00
|
|
|
/**
|
|
|
|
* @param size the amount of slots that the inventory adds alongside the base inventory slots
|
|
|
|
* @param holder the custom block holder
|
|
|
|
* @param updater updater
|
|
|
|
*/
|
|
|
|
public AbstractBlockInventoryTranslator(int size, InventoryHolder holder, InventoryUpdater updater) {
|
|
|
|
super(size);
|
|
|
|
this.holder = holder;
|
|
|
|
this.updater = updater;
|
|
|
|
}
|
|
|
|
|
2020-06-02 16:48:26 +00:00
|
|
|
@Override
|
2021-11-21 18:36:42 +00:00
|
|
|
public void prepareInventory(GeyserSessionImpl session, Inventory inventory) {
|
2020-06-02 16:48:26 +00:00
|
|
|
holder.prepareInventory(this, session, inventory);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-11-21 18:36:42 +00:00
|
|
|
public void openInventory(GeyserSessionImpl session, Inventory inventory) {
|
2020-06-02 16:48:26 +00:00
|
|
|
holder.openInventory(this, session, inventory);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-11-21 18:36:42 +00:00
|
|
|
public void closeInventory(GeyserSessionImpl session, Inventory inventory) {
|
2020-06-02 16:48:26 +00:00
|
|
|
holder.closeInventory(this, session, inventory);
|
2019-10-20 21:25:41 +00:00
|
|
|
}
|
2020-12-17 04:52:45 +00:00
|
|
|
|
|
|
|
@Override
|
2021-11-21 18:36:42 +00:00
|
|
|
public void updateInventory(GeyserSessionImpl session, Inventory inventory) {
|
2020-12-17 04:52:45 +00:00
|
|
|
updater.updateInventory(this, session, inventory);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-11-21 18:36:42 +00:00
|
|
|
public void updateSlot(GeyserSessionImpl session, Inventory inventory, int slot) {
|
2020-12-17 04:52:45 +00:00
|
|
|
updater.updateSlot(this, session, inventory, slot);
|
|
|
|
}
|
2019-10-20 21:25:41 +00:00
|
|
|
}
|