use of com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker in project minecolonies by Minecolonies.
the class EntityCitizen method getDesiredActivity.
@NotNull
public DesiredActivity getDesiredActivity() {
if (this.getColonyJob() instanceof JobGuard) {
return DesiredActivity.WORK;
}
if (!world.isDaytime()) {
if (isDay && citizenData != null) {
isDay = false;
final AbstractBuildingWorker buildingWorker = getWorkBuilding();
final double decreaseBy = buildingWorker == null || buildingWorker.getBuildingLevel() == 0 ? 0.1 : (SATURATION_DECREASE_FACTOR * Math.pow(2, buildingWorker.getBuildingLevel() - 1.0));
citizenData.decreaseSaturation(decreaseBy);
citizenData.markDirty();
}
return DesiredActivity.SLEEP;
}
isDay = true;
if (world.isRaining() && !shouldWorkWhileRaining()) {
return DesiredActivity.IDLE;
} else {
if (this.getNavigator() != null && (this.getNavigator().getPath() != null && this.getNavigator().getPath().getCurrentPathLength() == 0)) {
this.getNavigator().clearPathEntity();
}
return DesiredActivity.WORK;
}
}
use of com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker in project minecolonies by Minecolonies.
the class WalkToProxy method fillProxyList.
/**
* Calculates a list of proxies to a certain target for a worker.
*
* @param target the target.
* @param distanceToPath the complete distance.
* @return the first position to path to.
*/
@NotNull
private BlockPos fillProxyList(@NotNull final BlockPos target, final double distanceToPath) {
final BlockPos proxyPoint;
final AbstractBuildingWorker building = worker.getWorkBuilding();
if (worker.getColonyJob() != null && worker.getColonyJob() instanceof JobMiner && building instanceof BuildingMiner) {
proxyPoint = getMinerProxy(target, distanceToPath, (BuildingMiner) building);
} else {
proxyPoint = getProxy(target, worker.getPosition(), distanceToPath);
}
if (!proxyList.isEmpty()) {
proxyList.remove(0);
}
return proxyPoint;
}
use of com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker in project minecolonies by Minecolonies.
the class AbstractEntityAIGuard method goToBuilding.
/**
* Goes back to the building and tries to take armour from it when he hasn't in his inventory.
*
* @return the next state to go to.
*/
protected AIState goToBuilding() {
if (walkToBuilding()) {
return AIState.GUARD_RESTOCK;
}
final AbstractBuildingWorker workBuilding = getOwnBuilding();
if (workBuilding != null) {
final TileEntityColonyBuilding chest = workBuilding.getTileEntity();
for (int i = 0; i < workBuilding.getTileEntity().getSizeInventory(); i++) {
final ItemStack stack = chest.getStackInSlot(i);
if (InventoryUtils.isItemStackEmpty(stack)) {
continue;
}
if (stack.getItem() instanceof ItemArmor && worker.getItemStackFromSlot(((ItemArmor) stack.getItem()).armorType) == null) {
final int emptySlot = InventoryUtils.findFirstSlotInItemHandlerWith(new InvWrapper(worker.getInventoryCitizen()), InventoryUtils::isItemStackEmpty);
if (emptySlot != -1) {
new InvWrapper(worker.getInventoryCitizen()).insertItem(emptySlot, stack, false);
chest.setInventorySlotContents(i, ItemStack.EMPTY);
}
}
dumpAfterActions = DUMP_BASE * workBuilding.getBuildingLevel();
}
}
attacksExecuted = 0;
return AIState.GUARD_SEARCH_TARGET;
}
use of com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker in project minecolonies by Minecolonies.
the class RecallCitizenMessage method messageOnServerThread.
@Override
public void messageOnServerThread(final RecallCitizenMessage 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;
}
@Nullable final AbstractBuildingWorker building = colony.getBuilding(message.buildingId, AbstractBuildingWorker.class);
if (building != null) {
EntityCitizen citizen = building.getWorkerEntity();
if (citizen == null) {
final CitizenData citizenData = building.getWorker();
if (citizenData != null) {
Log.getLogger().warn(String.format("Citizen #%d:%d has gone AWOL, respawning them!", colony.getID(), citizenData.getId()));
colony.spawnCitizen(citizenData);
citizen = citizenData.getCitizenEntity();
} else {
Log.getLogger().warn("Citizen is AWOL and citizenData is null!");
return;
}
}
final BlockPos loc = building.getLocation();
if (!TeleportHelper.teleportCitizen(citizen, colony.getWorld(), loc)) {
LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.workerHuts.recallFail");
}
}
}
}
use of com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker in project minecolonies by Minecolonies.
the class AbstractEntityAIBasic method isInHut.
/**
* Check all chests in the worker hut for a required item.
*
* @param is the type of item requested (amount is ignored)
* @return true if a stack of that type was found
*/
public boolean isInHut(@Nullable final ItemStack is) {
@Nullable final AbstractBuildingWorker building = getOwnBuilding();
boolean hasItem;
if (building != null) {
hasItem = isInTileEntity(building.getTileEntity(), is);
if (hasItem) {
return true;
}
for (final BlockPos pos : building.getAdditionalCountainers()) {
final TileEntity entity = world.getTileEntity(pos);
if (entity instanceof TileEntityChest) {
hasItem = isInTileEntity((TileEntityChest) entity, is);
if (hasItem) {
return true;
}
}
}
}
return false;
}
Aggregations