Search in sources :

Example 1 with BuildingHome

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

the class EntityCitizen method isAtHome.

public boolean isAtHome() {
    @Nullable final AbstractBuilding homeBuilding = getHomeBuilding();
    if (homeBuilding instanceof BuildingHome) {
        final Tuple<Tuple<Integer, Integer>, Tuple<Integer, Integer>> corners = homeBuilding.getCorners();
        return new AxisAlignedBB(corners.getFirst().getFirst(), posY - 1, corners.getSecond().getFirst(), corners.getFirst().getSecond(), posY + 1, corners.getSecond().getSecond()).intersectsWithXZ(new Vec3d(this.getPosition()));
    }
    @Nullable final BlockPos homePosition = getHomePosition();
    return homePosition != null && homePosition.distanceSq((int) Math.floor(posX), (int) posY, (int) Math.floor(posZ)) <= RANGE_TO_BE_HOME;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) BuildingHome(com.minecolonies.coremod.colony.buildings.BuildingHome) BlockPos(net.minecraft.util.math.BlockPos) Nullable(org.jetbrains.annotations.Nullable) Vec3d(net.minecraft.util.math.Vec3d) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 2 with BuildingHome

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

the class TileEntityWareHouse method checkInWareHouse.

/**
     * Check if the required items by the building are in the wareHouse.
     * @param buildingEntry the building requesting.
     * @param addToList if is in warehouse should add to the list?
     * @return true if has something in warehouse to deliver.
     */
public boolean checkInWareHouse(@NotNull final AbstractBuilding buildingEntry, final boolean addToList) {
    if (buildingEntry.areItemsNeeded()) {
        for (final ItemStack stack : buildingEntry.getCopyOfNeededItems()) {
            if (stack == null || (deliveryManHasBuildingAsTask(buildingEntry) && addToList)) {
                continue;
            }
            if (isInHut(stack)) {
                if (addToList) {
                    buildingEntry.setOnGoingDelivery(true);
                    taskQueue.add(buildingEntry);
                    taskSet.add(buildingEntry);
                }
                return true;
            }
        }
        if (taskSet.contains(buildingEntry)) {
            taskQueue.remove(buildingEntry);
            taskSet.remove(buildingEntry);
            buildingEntry.setOnGoingDelivery(false);
        }
    }
    final String tool = buildingEntry.getRequiredTool();
    if (!tool.isEmpty()) {
        if (isToolInHut(tool, buildingEntry)) {
            if (addToList) {
                buildingEntry.setOnGoingDelivery(true);
                taskQueue.add(buildingEntry);
                taskSet.add(buildingEntry);
            }
            return true;
        }
        if (taskSet.contains(buildingEntry)) {
            taskQueue.remove(buildingEntry);
            taskSet.remove(buildingEntry);
            buildingEntry.setOnGoingDelivery(false);
        }
    }
    return buildingEntry instanceof BuildingHome && checkInWareHouse((BuildingHome) buildingEntry, addToList);
}
Also used : BuildingHome(com.minecolonies.coremod.colony.buildings.BuildingHome) ItemStack(net.minecraft.item.ItemStack)

Example 3 with BuildingHome

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

the class EntityAIGoHome method handleSaturation.

/**
     * Handle the saturation of the citizen.
     *
     * @param pos the position.
     */
private void handleSaturation(@NotNull final BlockPos pos) {
    if (citizen.isWorkerAtSiteWithMove(pos, 2) && citizen.getColony() != null && citizen.getCitizenData() != null && citizen.getCitizenData().getSaturation() < EntityCitizen.HIGH_SATURATION) {
        final double currentSaturation = citizen.getCitizenData().getSaturation();
        boolean tookFood = false;
        final AbstractBuilding home = citizen.getColony().getBuilding(pos);
        if (home instanceof BuildingHome && currentSaturation < EntityCitizen.FULL_SATURATION) {
            final int slot = InventoryUtils.findFirstSlotInProviderNotEmptyWith(home.getTileEntity(), itemStack -> itemStack.getItem() instanceof ItemFood);
            if (slot != -1) {
                final ItemStack stack = home.getTileEntity().getStackInSlot(slot);
                if (!InventoryUtils.isItemStackEmpty(stack)) {
                    final int slotToSet = InventoryUtils.getFirstOpenSlotFromItemHandler(new InvWrapper(citizen.getInventoryCitizen()));
                    if (slotToSet == -1) {
                        InventoryUtils.forceItemStackToItemHandler(new InvWrapper(citizen.getInventoryCitizen()), new ItemStack(stack.getItem(), 1), stack1 -> citizen.getWorkBuilding() == null || !citizen.getWorkBuilding().neededForWorker(stack1));
                    } else {
                        citizen.getInventoryCitizen().setInventorySlotContents(slotToSet, new ItemStack(stack.getItem(), 1));
                    }
                    tookFood = true;
                    stack.setCount(stack.getCount() - 1);
                }
                ((BuildingHome) home).setFoodNeeded(false);
            }
        }
        if (!tookFood) {
            requestFoodIfRequired(currentSaturation, home);
        }
    }
}
Also used : ItemFood(net.minecraft.item.ItemFood) BuildingHome(com.minecolonies.coremod.colony.buildings.BuildingHome) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) ItemStack(net.minecraft.item.ItemStack) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 4 with BuildingHome

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

the class AssignUnassignMessage method messageOnServerThread.

@Override
public void messageOnServerThread(final AssignUnassignMessage message, final EntityPlayerMP player) {
    final Colony colony = ColonyManager.getColony(message.colonyId);
    if (colony != null) {
        // Verify player has permission to change this huts settings
        if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
            return;
        }
        final AbstractBuilding building = colony.getBuildingManager().getBuilding(message.buildingId);
        if (!(building instanceof BuildingHome)) {
            return;
        }
        final CitizenData citizen = colony.getCitizenManager().getCitizen(message.citizenID);
        if (message.assign && !((BuildingHome) building).isFull() && citizen.getHomeBuilding() == null) {
            ((BuildingHome) building).addResident(citizen);
        } else if (((BuildingHome) building).hasResident(citizen)) {
            building.removeCitizen(citizen);
        }
    }
}
Also used : BuildingHome(com.minecolonies.coremod.colony.buildings.BuildingHome) Colony(com.minecolonies.coremod.colony.Colony) CitizenData(com.minecolonies.coremod.colony.CitizenData) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 5 with BuildingHome

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

the class EntityAISleep method shouldContinueExecuting.

/**
 * Continue executing if he should sleep.
 * Call the wake up method as soon as this isn't the case anymore.
 * Might search a bed while he is trying to sleep.
 *
 * @return true while he should sleep.
 */
@Override
public boolean shouldContinueExecuting() {
    if (citizen.getDesiredActivity() == EntityCitizen.DesiredActivity.SLEEP) {
        wokeUp = false;
        final Colony colony = citizen.getColony();
        if (colony == null || colony.getBuildingManager().getBuilding(citizen.getHomePosition()) == null) {
            return true;
        }
        if (usedBed == null) {
            final AbstractBuilding hut = colony.getBuildingManager().getBuilding(citizen.getHomePosition());
            if (hut instanceof BuildingHome) {
                for (final BlockPos pos : ((BuildingHome) hut).getBedList()) {
                    final World world = citizen.world;
                    IBlockState state = world.getBlockState(pos);
                    state = state.getBlock().getActualState(state, world, pos);
                    if (state.getBlock() instanceof BlockBed && !state.getValue(BlockBed.OCCUPIED) && state.getValue(BlockBed.PART).equals(BlockBed.EnumPartType.HEAD)) {
                        usedBed = pos;
                        citizen.world.setBlockState(pos, state.withProperty(BlockBed.OCCUPIED, true), 0x03);
                        final BlockPos feetPos = pos.offset(state.getValue(BlockBed.FACING).getOpposite());
                        final IBlockState feetState = citizen.world.getBlockState(feetPos);
                        citizen.world.setBlockState(feetPos, feetState.withProperty(BlockBed.OCCUPIED, true), 0x03);
                        return true;
                    }
                }
            }
            usedBed = citizen.getHomePosition();
        } else {
            if (citizen.isWorkerAtSiteWithMove(usedBed, 1)) {
                citizen.trySleep(usedBed);
                return true;
            }
        }
        return true;
    }
    citizen.onWakeUp();
    if (usedBed != null) {
        final IBlockState state = citizen.world.getBlockState(usedBed);
        if (state.getBlock() instanceof BlockBed) {
            final IBlockState headState = citizen.world.getBlockState(usedBed);
            citizen.world.setBlockState(usedBed, headState.withProperty(BlockBed.OCCUPIED, false), 0x03);
            final BlockPos feetPos = usedBed.offset(headState.getValue(BlockBed.FACING).getOpposite());
            final IBlockState feetState = citizen.world.getBlockState(feetPos);
            citizen.world.setBlockState(feetPos, feetState.withProperty(BlockBed.OCCUPIED, true), 0x03);
        }
        usedBed = null;
    }
    wokeUp = true;
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BuildingHome(com.minecolonies.coremod.colony.buildings.BuildingHome) Colony(com.minecolonies.coremod.colony.Colony) BlockBed(net.minecraft.block.BlockBed) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Aggregations

BuildingHome (com.minecolonies.coremod.colony.buildings.BuildingHome)5 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)4 Colony (com.minecolonies.coremod.colony.Colony)2 ItemStack (net.minecraft.item.ItemStack)2 BlockPos (net.minecraft.util.math.BlockPos)2 CitizenData (com.minecolonies.coremod.colony.CitizenData)1 BlockBed (net.minecraft.block.BlockBed)1 IBlockState (net.minecraft.block.state.IBlockState)1 ItemFood (net.minecraft.item.ItemFood)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 Vec3d (net.minecraft.util.math.Vec3d)1 World (net.minecraft.world.World)1 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)1 Nullable (org.jetbrains.annotations.Nullable)1