Search in sources :

Example 1 with CombinedItemHandler

use of com.minecolonies.coremod.inventory.api.CombinedItemHandler in project minecolonies by Minecolonies.

the class AbstractBuilding method getCapability.

@Nullable
@Override
public <T> T getCapability(@Nonnull final Capability<T> capability, @Nullable final EnumFacing facing) {
    if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && facing == null) {
        final Set<ICapabilityProvider> providers = new HashSet<>();
        // Add myself
        providers.add(getTileEntity());
        // Add additional containers
        providers.addAll(getAdditionalCountainers().stream().map(getTileEntity().getWorld()::getTileEntity).filter(entity -> (entity instanceof TileEntityChest) || (entity instanceof TileEntityRack)).collect(Collectors.toSet()));
        providers.removeIf(Objects::isNull);
        // Map all providers to IItemHandlers.
        final Set<IItemHandlerModifiable> modifiables = providers.stream().flatMap(provider -> InventoryUtils.getItemHandlersFromProvider(provider).stream()).filter(handler -> handler instanceof IItemHandlerModifiable).map(handler -> (IItemHandlerModifiable) handler).collect(Collectors.toSet());
        return (T) new CombinedItemHandler(getSchematicName(), modifiables.toArray(new IItemHandlerModifiable[modifiables.size()]));
    }
    return null;
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) BuildingRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.BuildingRequestResolver) Constants(net.minecraftforge.common.util.Constants) ImmutableCollection(com.google.common.collect.ImmutableCollection) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) StandardFactoryController(com.minecolonies.api.colony.requestsystem.StandardFactoryController) NBTTagList(net.minecraft.nbt.NBTTagList) Block(net.minecraft.block.Block) CombinedItemHandler(com.minecolonies.coremod.inventory.api.CombinedItemHandler) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BuildingBuilderView(com.minecolonies.coremod.colony.buildings.views.BuildingBuilderView) InventoryHelper(net.minecraft.inventory.InventoryHelper) Predicate(java.util.function.Predicate) RequestState(com.minecolonies.api.colony.requestsystem.request.RequestState) TileEntityColonyBuilding(com.minecolonies.coremod.tileentities.TileEntityColonyBuilding) Collectors(java.util.stream.Collectors) Capability(net.minecraftforge.common.capabilities.Capability) InvocationTargetException(java.lang.reflect.InvocationTargetException) AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) Nullable(org.jetbrains.annotations.Nullable) IRequestResolver(com.minecolonies.api.colony.requestsystem.resolver.IRequestResolver) BuildingUtils(com.minecolonies.coremod.util.BuildingUtils) EntityPlayer(net.minecraft.entity.player.EntityPlayer) com.minecolonies.coremod.blocks(com.minecolonies.coremod.blocks) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) IRequestResolverProvider(com.minecolonies.api.colony.requestsystem.resolver.IRequestResolverProvider) ItemStorage(com.minecolonies.api.crafting.ItemStorage) TickEvent(net.minecraftforge.fml.common.gameevent.TickEvent) NotNull(org.jetbrains.annotations.NotNull) NBTUtil(net.minecraft.nbt.NBTUtil) java.util(java.util) ColonyUtils(com.minecolonies.coremod.util.ColonyUtils) ICapabilityProvider(net.minecraftforge.common.capabilities.ICapabilityProvider) Suppression(com.minecolonies.api.util.constant.Suppression) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) EntityAIWorkDeliveryman(com.minecolonies.coremod.entity.ai.citizen.deliveryman.EntityAIWorkDeliveryman) TypeToken(com.google.common.reflect.TypeToken) Constructor(java.lang.reflect.Constructor) IRequestManager(com.minecolonies.api.colony.requestsystem.manager.IRequestManager) TileEntityChest(net.minecraft.tileentity.TileEntityChest) ITextComponent(net.minecraft.util.text.ITextComponent) ItemStack(net.minecraft.item.ItemStack) ImmutableList(com.google.common.collect.ImmutableList) ByteBuf(io.netty.buffer.ByteBuf) StructureWrapper(com.minecolonies.coremod.util.StructureWrapper) BuildingBasedRequester(com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester) ConstructionTapeHelper(com.minecolonies.coremod.entity.ai.citizen.builder.ConstructionTapeHelper) com.minecolonies.api.util(com.minecolonies.api.util) Nonnull(javax.annotation.Nonnull) WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) IRequester(com.minecolonies.api.colony.requestsystem.requester.IRequester) BlockContainer(net.minecraft.block.BlockContainer) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) World(net.minecraft.world.World) EnumFacing(net.minecraft.util.EnumFacing) Tuple(net.minecraft.util.Tuple) BlockPos(net.minecraft.util.math.BlockPos) IRequestable(com.minecolonies.api.colony.requestsystem.requestable.IRequestable) TileEntityRack(com.minecolonies.coremod.tileentities.TileEntityRack) TextComponentString(net.minecraft.util.text.TextComponentString) IBlockState(net.minecraft.block.state.IBlockState) TypeConstants(com.minecolonies.api.util.constant.TypeConstants) com.minecolonies.coremod.colony(com.minecolonies.coremod.colony) IInventory(net.minecraft.inventory.IInventory) NbtTagConstants(com.minecolonies.api.util.constant.NbtTagConstants) ByteBufUtils(net.minecraftforge.fml.common.network.ByteBufUtils) TileEntity(net.minecraft.tileentity.TileEntity) IRequestSystemBuildingDataStore(com.minecolonies.api.colony.requestsystem.data.IRequestSystemBuildingDataStore) TileEntityChest(net.minecraft.tileentity.TileEntityChest) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) TileEntityRack(com.minecolonies.coremod.tileentities.TileEntityRack) CombinedItemHandler(com.minecolonies.coremod.inventory.api.CombinedItemHandler) ICapabilityProvider(net.minecraftforge.common.capabilities.ICapabilityProvider) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ImmutableCollection (com.google.common.collect.ImmutableCollection)1 ImmutableList (com.google.common.collect.ImmutableList)1 TypeToken (com.google.common.reflect.TypeToken)1 StandardFactoryController (com.minecolonies.api.colony.requestsystem.StandardFactoryController)1 IRequestSystemBuildingDataStore (com.minecolonies.api.colony.requestsystem.data.IRequestSystemBuildingDataStore)1 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)1 IRequestManager (com.minecolonies.api.colony.requestsystem.manager.IRequestManager)1 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)1 RequestState (com.minecolonies.api.colony.requestsystem.request.RequestState)1 IDeliverable (com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)1 IRequestable (com.minecolonies.api.colony.requestsystem.requestable.IRequestable)1 IRequester (com.minecolonies.api.colony.requestsystem.requester.IRequester)1 IRequestResolver (com.minecolonies.api.colony.requestsystem.resolver.IRequestResolver)1 IRequestResolverProvider (com.minecolonies.api.colony.requestsystem.resolver.IRequestResolverProvider)1 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)1 ItemStorage (com.minecolonies.api.crafting.ItemStorage)1 com.minecolonies.api.util (com.minecolonies.api.util)1 NbtTagConstants (com.minecolonies.api.util.constant.NbtTagConstants)1 Suppression (com.minecolonies.api.util.constant.Suppression)1 TypeConstants (com.minecolonies.api.util.constant.TypeConstants)1