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;
}
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;
}
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());
}
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;
}
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();
}
Aggregations