Search in sources :

Example 1 with BuildingWareHouse

use of com.minecolonies.coremod.colony.buildings.BuildingWareHouse in project minecolonies by Minecolonies.

the class TileEntityWareHouse method update.

@Override
public void update() {
    super.update();
    if (ticksPassed != WAIT_TICKS) {
        ticksPassed++;
        return;
    }
    ticksPassed = 0;
    final AbstractBuilding wareHouseBuilding = getBuilding();
    if (getColony() != null && wareHouseBuilding instanceof BuildingWareHouse && !((BuildingWareHouse) wareHouseBuilding).getRegisteredDeliverymen().isEmpty()) {
        final Map<BlockPos, AbstractBuilding> buildingMap = getColony().getBuildings();
        if (buildingMap.size() < this.index) {
            this.index = 1;
        }
        int i = 1;
        for (@NotNull final Map.Entry<BlockPos, AbstractBuilding> buildingEntry : buildingMap.entrySet()) {
            if (i == index) {
                if (!taskSet.contains(buildingEntry.getValue()) && buildingEntry.getValue().needsAnything()) {
                    checkInWareHouse(buildingEntry.getValue(), true);
                }
                this.index++;
            }
            i++;
        }
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) NotNull(org.jetbrains.annotations.NotNull) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) BuildingWareHouse(com.minecolonies.coremod.colony.buildings.BuildingWareHouse)

Example 2 with BuildingWareHouse

use of com.minecolonies.coremod.colony.buildings.BuildingWareHouse in project minecolonies by Minecolonies.

the class UpgradeWarehouseMessage method messageOnServerThread.

@Override
public void messageOnServerThread(final UpgradeWarehouseMessage message, final EntityPlayerMP player) {
    final Colony colony = ColonyManager.getColony(message.colonyId);
    if (colony == null) {
        Log.getLogger().warn("UpgradeWarehouseMessage colony is null");
        return;
    }
    if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
        return;
    }
    final AbstractBuilding building = colony.getBuildingManager().getBuilding(message.buildingId);
    if (!(building instanceof BuildingWareHouse)) {
        Log.getLogger().warn("UpgradeWarehouseMessage building is not a Warehouse");
        return;
    }
    ((BuildingWareHouse) building).upgradeContainers(player.world);
    final boolean isCreative = player.capabilities.isCreativeMode;
    if (!isCreative) {
        final int slot = InventoryUtils.findFirstSlotInItemHandlerWith(new InvWrapper(player.inventory), itemStack -> itemStack.isItemEqual(new ItemStack(Blocks.EMERALD_BLOCK)));
        player.inventory.decrStackSize(slot, 1);
    }
}
Also used : InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) Colony(com.minecolonies.coremod.colony.Colony) ItemStack(net.minecraft.item.ItemStack) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) BuildingWareHouse(com.minecolonies.coremod.colony.buildings.BuildingWareHouse)

Aggregations

AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)2 BuildingWareHouse (com.minecolonies.coremod.colony.buildings.BuildingWareHouse)2 Colony (com.minecolonies.coremod.colony.Colony)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ItemStack (net.minecraft.item.ItemStack)1 BlockPos (net.minecraft.util.math.BlockPos)1 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)1 NotNull (org.jetbrains.annotations.NotNull)1