Search in sources :

Example 6 with TileEntityRack

use of com.minecolonies.coremod.tileentities.TileEntityRack in project minecolonies by Minecolonies.

the class GuiHandler method getServerGuiElement.

@Override
public Object getServerGuiElement(final int id, final EntityPlayer player, final World world, final int x, final int y, final int z) {
    if (id == ID.DEFAULT.ordinal()) {
        final BlockPos pos = new BlockPos(x, y, z);
        final TileEntity tileEntity = world.getTileEntity(pos);
        if (tileEntity instanceof ScarecrowTileEntity) {
            return new ContainerField((ScarecrowTileEntity) tileEntity, player.inventory, world, pos);
        } else if (tileEntity instanceof TileEntityRack) {
            return new ContainerRack((TileEntityRack) tileEntity, ((TileEntityRack) tileEntity).getOtherChest(), player.inventory);
        } else {
            @Nullable final AbstractBuilding building = ColonyManager.getBuilding(world, new BlockPos(x, y, z));
            if (building != null) {
                return new CraftingGUIBuilding(player.inventory, world);
            }
            return null;
        }
    } else if (id == ID.BUILDING_INVENTORY.ordinal()) {
        final TileEntity entity = world.getTileEntity(new BlockPos(x, y, z));
        if (entity instanceof TileEntityColonyBuilding) {
            final TileEntityColonyBuilding tileEntityColonyBuilding = (TileEntityColonyBuilding) entity;
            final Colony colony = ColonyManager.getClosestColony(world, tileEntityColonyBuilding.getPos());
            return new ContainerMinecoloniesBuildingInventory(player.inventory, tileEntityColonyBuilding, colony.getID(), tileEntityColonyBuilding.getPos());
        }
    } else if (id == ID.CITIZEN_INVENTORY.ordinal()) {
        final Colony colony = ColonyManager.getColony(x);
        final CitizenData citizen = colony.getCitizenManager().getCitizen(y);
        final AbstractBuilding building = citizen.getWorkBuilding();
        return new ContainerMinecoloniesCitizenInventory(player.inventory, citizen.getInventory(), colony.getID(), building == null ? null : building.getID(), citizen.getId());
    }
    return null;
}
Also used : TileEntityColonyBuilding(com.minecolonies.coremod.tileentities.TileEntityColonyBuilding) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) TileEntityRack(com.minecolonies.coremod.tileentities.TileEntityRack) BlockPos(net.minecraft.util.math.BlockPos) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 7 with TileEntityRack

use of com.minecolonies.coremod.tileentities.TileEntityRack in project minecolonies by Minecolonies.

the class GuiHandler method getClientGuiElement.

@Override
public Object getClientGuiElement(final int id, final EntityPlayer player, final World world, final int x, final int y, final int z) {
    if (id == ID.DEFAULT.ordinal()) {
        final BlockPos pos = new BlockPos(x, y, z);
        final TileEntity tileEntity = world.getTileEntity(pos);
        if (tileEntity instanceof ScarecrowTileEntity) {
            return new GuiField(player.inventory, (ScarecrowTileEntity) tileEntity, world, pos);
        } else if (tileEntity instanceof TileEntityRack) {
            return new GuiRack(player.inventory, (TileEntityRack) tileEntity, ((TileEntityRack) tileEntity).getOtherChest(), world, pos);
        } else {
            @Nullable final AbstractBuildingView building = ColonyManager.getBuildingView(new BlockPos(x, y, z));
            if (building instanceof AbstractBuildingWorker.View) {
                return new WindowGuiCrafting(player.inventory, world, (AbstractBuildingWorker.View) building);
            }
        }
    } else if (id == ID.BUILDING_INVENTORY.ordinal()) {
        final TileEntity entity = world.getTileEntity(new BlockPos(x, y, z));
        if (entity instanceof TileEntityColonyBuilding) {
            final TileEntityColonyBuilding tileEntityColonyBuilding = (TileEntityColonyBuilding) entity;
            return new GuiChest(player.inventory, tileEntityColonyBuilding);
        }
    } else if (id == ID.CITIZEN_INVENTORY.ordinal()) {
        final ColonyView view = ColonyManager.getColonyView(x);
        final CitizenDataView citizenDataView = view.getCitizen(y);
        return new GuiChest(player.inventory, citizenDataView.getInventory());
    }
    return null;
}
Also used : TileEntityColonyBuilding(com.minecolonies.coremod.tileentities.TileEntityColonyBuilding) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) TileEntity(net.minecraft.tileentity.TileEntity) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) TileEntityRack(com.minecolonies.coremod.tileentities.TileEntityRack) AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) WindowGuiCrafting(com.minecolonies.coremod.client.gui.WindowGuiCrafting) BlockPos(net.minecraft.util.math.BlockPos) GuiChest(net.minecraft.client.gui.inventory.GuiChest)

Example 8 with TileEntityRack

use of com.minecolonies.coremod.tileentities.TileEntityRack 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

TileEntityRack (com.minecolonies.coremod.tileentities.TileEntityRack)8 TileEntity (net.minecraft.tileentity.TileEntity)7 TileEntityColonyBuilding (com.minecolonies.coremod.tileentities.TileEntityColonyBuilding)3 BlockPos (net.minecraft.util.math.BlockPos)3 AbstractBuildingView (com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView)2 ScarecrowTileEntity (com.minecolonies.coremod.tileentities.ScarecrowTileEntity)2 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