Search in sources :

Example 1 with CompoundContainer

use of net.minecraft.world.CompoundContainer in project SpongeCommon by SpongePowered.

the class InventoryUtil method getDoubleChestInventory.

public static Optional<Inventory> getDoubleChestInventory(final ChestBlockEntity chest) {
    final Optional<Chest> connectedChestOptional = ((Chest) chest).connectedChest();
    if (!connectedChestOptional.isPresent()) {
        return Optional.empty();
    }
    final ChestType chestType = chest.getBlockState().getValue(ChestBlock.TYPE);
    final ChestBlockEntity connectedChest = (ChestBlockEntity) connectedChestOptional.get();
    // Logic in the instanceof check of ChestBlock.getChestInventory but with exploded ternary operators.
    if (chestType == ChestType.RIGHT) {
        return Optional.of((Inventory) new CompoundContainer(chest, connectedChest));
    } else {
        return Optional.of((Inventory) new CompoundContainer(connectedChest, chest));
    }
}
Also used : Chest(org.spongepowered.api.block.entity.carrier.chest.Chest) ChestBlockEntity(net.minecraft.world.level.block.entity.ChestBlockEntity) CompoundContainer(net.minecraft.world.CompoundContainer) ChestType(net.minecraft.world.level.block.state.properties.ChestType)

Aggregations

CompoundContainer (net.minecraft.world.CompoundContainer)1 ChestBlockEntity (net.minecraft.world.level.block.entity.ChestBlockEntity)1 ChestType (net.minecraft.world.level.block.state.properties.ChestType)1 Chest (org.spongepowered.api.block.entity.carrier.chest.Chest)1