Search in sources :

Example 46 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by ldtteam.

the class EntityAISickTask method findEmptyBed.

/**
 * Find an empty bed to ly in.
 *
 * @return the next state to go to.
 */
private DiseaseState findEmptyBed() {
    // Finding bed
    if (usedBed == null && citizen.getCitizenData() != null) {
        this.usedBed = citizen.getCitizenData().getBedPos();
        if (citizen.getCitizenData().getBedPos().equals(BlockPos.ZERO)) {
            this.usedBed = null;
        }
    }
    final BlockPos hospitalPos = citizen.getCitizenColonyHandler().getColony().getBuildingManager().getBestBuilding(citizen, BuildingHospital.class);
    final IColony colony = citizen.getCitizenColonyHandler().getColony();
    final IBuilding hospital = colony.getBuildingManager().getBuilding(hospitalPos);
    if (hospital instanceof BuildingHospital) {
        if (usedBed != null && !((BuildingHospital) hospital).getBedList().contains(usedBed)) {
            usedBed = null;
        }
        if (usedBed == null) {
            for (final BlockPos pos : ((BuildingHospital) hospital).getBedList()) {
                final World world = citizen.level;
                BlockState state = world.getBlockState(pos);
                if (state.getBlock().is(BlockTags.BEDS) && !state.getValue(BedBlock.OCCUPIED) && state.getValue(BedBlock.PART).equals(BedPart.HEAD) && world.isEmptyBlock(pos.above())) {
                    usedBed = pos;
                    ((BuildingHospital) hospital).registerPatient(usedBed, citizen.getCivilianID());
                    return FIND_EMPTY_BED;
                }
            }
            if (usedBed == null) {
                return WAIT_FOR_CURE;
            }
        }
        if (citizen.isWorkerAtSiteWithMove(usedBed, 3)) {
            waitingTicks++;
            if (!citizen.getCitizenSleepHandler().trySleep(usedBed)) {
                ((BuildingHospital) hospital).registerPatient(usedBed, 0);
                citizen.getCitizenData().setBedPos(BlockPos.ZERO);
                usedBed = null;
            }
        }
    }
    if (waitingTicks > GOING_TO_BED_ATTEMPTS) {
        waitingTicks = 0;
        return WAIT_FOR_CURE;
    }
    return FIND_EMPTY_BED;
}
Also used : BlockState(net.minecraft.block.BlockState) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) BuildingHospital(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingHospital) IColony(com.minecolonies.api.colony.IColony) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World)

Example 47 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by ldtteam.

the class EntityAISleep method resetAI.

/**
 * Resets the AI state
 */
private void resetAI() {
    citizen.getCitizenData().setVisibleStatus(null);
    citizen.getCitizenSleepHandler().onWakeUp();
    // Clean bed state
    if (usedBed != null) {
        final BlockState state = citizen.level.getBlockState(usedBed);
        if (state.getBlock().is(BlockTags.BEDS)) {
            final IColony colony = citizen.getCitizenColonyHandler().getColony();
            if (colony != null && colony.getBuildingManager().getBuilding(citizen.getRestrictCenter()) != null) {
                final IBuilding hut = colony.getBuildingManager().getBuilding(citizen.getRestrictCenter());
                if (hut.hasModule(BedHandlingModule.class)) {
                    setBedOccupied(false);
                }
            }
        }
        usedBed = null;
    }
    bedTicks = 0;
}
Also used : BlockState(net.minecraft.block.BlockState) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) IColony(com.minecolonies.api.colony.IColony)

Example 48 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by ldtteam.

the class EntityAIVisitor method isEntityLoaded.

/**
 * Whether the entity is in a ticked chunk
 *
 * @return true if loaded
 */
private boolean isEntityLoaded() {
    if (citizen.getCitizenColonyHandler().getColony() == null || citizen.getCitizenData() == null || citizen.getCitizenData().getHomeBuilding() == null) {
        return false;
    }
    IBuilding building = citizen.getCitizenData().getHomeBuilding();
    if (building.hasModule(TavernBuildingModule.class)) {
        tavern = (DefaultBuildingInstance) building;
    }
    ((VisitorData) citizen.getCitizenData()).setSittingPosition(BlockPos.ZERO);
    return WorldUtil.isEntityBlockLoaded(citizen.level, citizen.blockPosition());
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) VisitorData(com.minecolonies.coremod.colony.VisitorData)

Example 49 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding in project AdvancedPeripherals by Seniorendi.

the class ColonyPeripheral method getBuildings.

@LuaFunction(mainThread = true)
public final Object getBuildings() throws LuaException {
    IColony colony = getColony();
    IBuildingManager manager = colony.getBuildingManager();
    List<Object> buildingData = new ArrayList<>();
    for (Map.Entry<BlockPos, IBuilding> building : manager.getBuildings().entrySet()) {
        buildingData.add(MineColonies.buildingToObject(manager, building.getValue(), building.getKey()));
    }
    return buildingData;
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) IColony(com.minecolonies.api.colony.IColony) BlockPos(net.minecraft.util.math.BlockPos) IBuildingManager(com.minecolonies.api.colony.managers.interfaces.IBuildingManager) LuaFunction(dan200.computercraft.api.lua.LuaFunction)

Example 50 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.

the class BuildingManager method removeBuilding.

@Override
public void removeBuilding(@NotNull final IBuilding building, final Set<ServerPlayerEntity> subscribers) {
    if (buildings.containsKey(building.getID())) {
        final ImmutableMap.Builder<BlockPos, IBuilding> builder = new ImmutableMap.Builder<>();
        for (final IBuilding tbuilding : buildings.values()) {
            if (tbuilding != building) {
                builder.put(tbuilding.getID(), tbuilding);
            }
        }
        buildings = builder.build();
        for (final ServerPlayerEntity player : subscribers) {
            Network.getNetwork().sendToPlayer(new ColonyViewRemoveBuildingMessage(colony, building.getID()), player);
        }
        Log.getLogger().info(String.format("Colony %d - removed AbstractBuilding %s of type %s", colony.getID(), building.getID(), building.getSchematicName()));
    }
    if (building instanceof BuildingTownHall) {
        townHall = null;
    } else if (building instanceof BuildingWareHouse) {
        wareHouses.remove(building);
    } else if (building instanceof BuildingMysticalSite) {
        mysticalSites.remove(building);
    }
    // Allow Citizens to fix up any data that wasn't fixed up by the AbstractBuilding's own onDestroyed
    for (@NotNull final ICitizenData citizen : colony.getCitizenManager().getCitizens()) {
        citizen.onRemoveBuilding(building);
        building.cancelAllRequestsOfCitizen(citizen);
    }
    colony.getRequestManager().onProviderRemovedFromColony(building);
    colony.getRequestManager().onRequesterRemovedFromColony(building.getRequester());
    colony.getCitizenManager().calculateMaxCitizens();
}
Also used : BuildingMysticalSite(com.minecolonies.coremod.colony.buildings.BuildingMysticalSite) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ColonyViewRemoveBuildingMessage(com.minecolonies.coremod.network.messages.client.colony.ColonyViewRemoveBuildingMessage) NotNull(org.jetbrains.annotations.NotNull) ImmutableMap(com.google.common.collect.ImmutableMap) BuildingTownHall(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingTownHall) BuildingWareHouse(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingWareHouse)

Aggregations

IBuilding (com.minecolonies.api.colony.buildings.IBuilding)187 BlockPos (net.minecraft.util.math.BlockPos)71 NotNull (org.jetbrains.annotations.NotNull)45 IColony (com.minecolonies.api.colony.IColony)37 Nullable (org.jetbrains.annotations.Nullable)26 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)24 ICitizenData (com.minecolonies.api.colony.ICitizenData)22 World (net.minecraft.world.World)20 ItemStack (net.minecraft.item.ItemStack)19 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)19 TileEntity (net.minecraft.tileentity.TileEntity)17 CompoundNBT (net.minecraft.nbt.CompoundNBT)15 ArrayList (java.util.ArrayList)14 AbstractBuildingGuards (com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards)10 ItemStorage (com.minecolonies.api.crafting.ItemStorage)9 ResourceLocation (net.minecraft.util.ResourceLocation)9 IItemHandler (net.minecraftforge.items.IItemHandler)9 InventoryUtils (com.minecolonies.api.util.InventoryUtils)8 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)8 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)8