Search in sources :

Example 16 with Carrier

use of org.spongepowered.api.item.inventory.Carrier in project LanternServer by LanternPowered.

the class ClientContainerRegistryModule method registerDefaults.

@Override
public void registerDefaults() {
    register("minecraft", "chest", inventory -> {
        final int rows = inventory.getInventoryProperty(InventoryCapacity.class).map(capacity -> (int) Math.ceil(capacity.getValue().doubleValue() / 9.0)).orElse(1);
        return new ChestClientContainer(rows);
    });
    register("minecraft", "furnace", inventory -> new FurnaceClientContainer());
    register("minecraft", "dispenser", inventory -> new DispenserClientContainer());
    register("minecraft", "crafting_table", inventory -> new CraftingTableClientContainer());
    register("minecraft", "brewing_stand", inventory -> new BrewingStandClientContainer());
    register("minecraft", "hopper", inventory -> new HopperClientContainer());
    register("minecraft", "beacon", inventory -> new BeaconClientContainer());
    register("minecraft", "enchanting_table", inventory -> new EnchantmentTableClientContainer());
    register("minecraft", "anvil", inventory -> new AnvilClientContainer());
    register("minecraft", "villager", inventory -> new TradingClientContainer());
    register("minecraft", "horse", inventory -> {
        int capacity = inventory.capacity();
        capacity -= 2;
        capacity = (int) Math.ceil((float) capacity / 3);
        int entityId = -1;
        if (inventory instanceof CarriedInventory) {
            final Carrier carrier = ((CarriedInventory<Carrier>) inventory).getCarrier().orElse(null);
            if (carrier instanceof Entity) {
                final LanternEntity entity = (LanternEntity) carrier;
                entityId = entity.getWorld().getEntityProtocolManager().getProtocolId(entity);
            }
        }
        if (entityId == -1) {
            throw new IllegalStateException("Invalid carrier entity to create a container.");
        }
        // TODO: Dummy entity support?
        return new EntityEquipmentClientContainer(capacity, entityId);
    });
    register("minecraft", "shulker_box", inventory -> new ShulkerBoxClientContainer());
}
Also used : ChestClientContainer(org.lanternpowered.server.inventory.client.ChestClientContainer) TradingClientContainer(org.lanternpowered.server.inventory.client.TradingClientContainer) EnchantmentTableClientContainer(org.lanternpowered.server.inventory.client.EnchantmentTableClientContainer) LanternEntity(org.lanternpowered.server.entity.LanternEntity) ClientContainerType(org.lanternpowered.server.inventory.client.ClientContainerType) GuiId(org.spongepowered.api.item.inventory.property.GuiId) CraftingTableClientContainer(org.lanternpowered.server.inventory.client.CraftingTableClientContainer) Carrier(org.spongepowered.api.item.inventory.Carrier) Entity(org.spongepowered.api.entity.Entity) Function(java.util.function.Function) DispenserClientContainer(org.lanternpowered.server.inventory.client.DispenserClientContainer) InventoryCapacity(org.spongepowered.api.item.inventory.property.InventoryCapacity) AnvilClientContainer(org.lanternpowered.server.inventory.client.AnvilClientContainer) FurnaceClientContainer(org.lanternpowered.server.inventory.client.FurnaceClientContainer) EntityEquipmentClientContainer(org.lanternpowered.server.inventory.client.EntityEquipmentClientContainer) PluginCatalogRegistryModule(org.lanternpowered.server.game.registry.PluginCatalogRegistryModule) BrewingStandClientContainer(org.lanternpowered.server.inventory.client.BrewingStandClientContainer) GuiIds(org.spongepowered.api.item.inventory.property.GuiIds) CarriedInventory(org.spongepowered.api.item.inventory.type.CarriedInventory) ClientContainer(org.lanternpowered.server.inventory.client.ClientContainer) HopperClientContainer(org.lanternpowered.server.inventory.client.HopperClientContainer) ShulkerBoxClientContainer(org.lanternpowered.server.inventory.client.ShulkerBoxClientContainer) AbstractInventory(org.lanternpowered.server.inventory.AbstractInventory) BeaconClientContainer(org.lanternpowered.server.inventory.client.BeaconClientContainer) LanternEntity(org.lanternpowered.server.entity.LanternEntity) Entity(org.spongepowered.api.entity.Entity) DispenserClientContainer(org.lanternpowered.server.inventory.client.DispenserClientContainer) CarriedInventory(org.spongepowered.api.item.inventory.type.CarriedInventory) TradingClientContainer(org.lanternpowered.server.inventory.client.TradingClientContainer) FurnaceClientContainer(org.lanternpowered.server.inventory.client.FurnaceClientContainer) BrewingStandClientContainer(org.lanternpowered.server.inventory.client.BrewingStandClientContainer) ShulkerBoxClientContainer(org.lanternpowered.server.inventory.client.ShulkerBoxClientContainer) ChestClientContainer(org.lanternpowered.server.inventory.client.ChestClientContainer) CraftingTableClientContainer(org.lanternpowered.server.inventory.client.CraftingTableClientContainer) EntityEquipmentClientContainer(org.lanternpowered.server.inventory.client.EntityEquipmentClientContainer) AnvilClientContainer(org.lanternpowered.server.inventory.client.AnvilClientContainer) EnchantmentTableClientContainer(org.lanternpowered.server.inventory.client.EnchantmentTableClientContainer) BeaconClientContainer(org.lanternpowered.server.inventory.client.BeaconClientContainer) HopperClientContainer(org.lanternpowered.server.inventory.client.HopperClientContainer) Carrier(org.spongepowered.api.item.inventory.Carrier) LanternEntity(org.lanternpowered.server.entity.LanternEntity)

Example 17 with Carrier

use of org.spongepowered.api.item.inventory.Carrier in project LanternServer by LanternPowered.

the class EntityProtocol method spawnWithEquipment.

protected void spawnWithEquipment(EntityProtocolUpdateContext context) {
    if (hasEquipment() && this.entity instanceof Carrier) {
        final Inventory inventory = ((Carrier) this.entity).getInventory();
        for (int i = 0; i < Holder.EQUIPMENT_TYPES.length; i++) {
            final ItemStack itemStack = inventory.query(Holder.EQUIPMENT_QUERIES[i]).first().peek().orElse(null);
            final int slotIndex = i;
            if (itemStack != null) {
                context.sendToAllExceptSelf(() -> new MessagePlayOutEntityEquipment(getRootEntityId(), slotIndex, itemStack));
            }
        }
    }
}
Also used : Carrier(org.spongepowered.api.item.inventory.Carrier) MessagePlayOutEntityEquipment(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutEntityEquipment) ItemStack(org.spongepowered.api.item.inventory.ItemStack) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) Inventory(org.spongepowered.api.item.inventory.Inventory)

Aggregations

Carrier (org.spongepowered.api.item.inventory.Carrier)17 Inventory (org.spongepowered.api.item.inventory.Inventory)10 World (org.spongepowered.api.world.World)8 ItemStack (org.spongepowered.api.item.inventory.ItemStack)7 Listener (org.spongepowered.api.event.Listener)5 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)4 Map (java.util.Map)3 DuctData (org.cubeengine.module.itemduct.data.DuctData)3 LanternItemStack (org.lanternpowered.server.inventory.LanternItemStack)3 Chest (org.spongepowered.api.block.tileentity.carrier.Chest)3 Direction (org.spongepowered.api.util.Direction)3 Vector3d (com.flowpowered.math.vector.Vector3d)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 CauseStack (org.lanternpowered.server.event.CauseStack)2 BlockType (org.spongepowered.api.block.BlockType)2 Entity (org.spongepowered.api.entity.Entity)2 Player (org.spongepowered.api.entity.living.player.Player)2 Container (org.spongepowered.api.item.inventory.Container)2