use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by ldtteam.
the class AbstractEntityAIBasic method dumpOneMoreSlot.
/**
* Dumps one inventory slot into the building chest.
*
* @return true if is has to dump more.
*/
@SuppressWarnings("PMD.PrematureDeclaration")
private boolean dumpOneMoreSlot() {
if (walkToBlock(getBuildingToDump().getPosition())) {
return true;
}
@Nullable final IBuilding buildingWorker = getOwnBuilding();
ItemStack stackToDump = worker.getInventoryCitizen().getStackInSlot(slotAt);
final int totalSize = worker.getInventoryCitizen().getSlots();
while (stackToDump.isEmpty()) {
if (slotAt >= totalSize) {
return false;
}
slotAt++;
stackToDump = worker.getInventoryCitizen().getStackInSlot(slotAt);
}
boolean dumpAnyway = false;
if (slotAt + MIN_OPEN_SLOTS * 2 >= totalSize) {
final long openSlots = InventoryUtils.openSlotCount(worker.getInventoryCitizen());
if (openSlots < MIN_OPEN_SLOTS * 2) {
if (stackToDump.getCount() < CHANCE_TO_DUMP_50) {
dumpAnyway = worker.getRandom().nextBoolean();
} else {
dumpAnyway = worker.getRandom().nextInt(stackToDump.getCount()) < CHANCE_TO_DUMP;
}
}
}
if (buildingWorker != null && !ItemStackUtils.isEmpty(stackToDump)) {
final int amount = dumpAnyway ? stackToDump.getCount() : buildingWorker.buildingRequiresCertainAmountOfItem(stackToDump, alreadyKept, true);
if (amount > 0) {
final ItemStack activeStack = getInventory().extractItem(slotAt, amount, false);
InventoryUtils.transferItemStackIntoNextBestSlotInItemHandler(activeStack, getBuildingToDump().getCapability(ITEM_HANDLER_CAPABILITY, null).orElseGet(null));
hasDumpedItems = true;
}
}
slotAt++;
return slotAt < totalSize;
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by ldtteam.
the class BuildingBarracks method registerBlockPosition.
@Override
public void registerBlockPosition(@NotNull final BlockState block, @NotNull final BlockPos pos, @NotNull final World world) {
super.registerBlockPosition(block, pos, world);
if (block.getBlock() == ModBlocks.blockHutBarracksTower) {
final IBuilding building = getColony().getBuildingManager().getBuilding(pos);
if (building instanceof BuildingBarracksTower) {
building.setStyle(this.getStyle());
((BuildingBarracksTower) building).addBarracks(getPosition());
if (!towers.contains(pos)) {
towers.add(pos);
}
}
}
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by ldtteam.
the class BuildingBarracksTower method onUpgradeComplete.
@Override
public void onUpgradeComplete(final int newLevel) {
super.onUpgradeComplete(newLevel);
final IBuilding barrack = colony.getBuildingManager().getBuilding(barracks);
if (barrack == null) {
return;
}
ChunkDataHelper.claimColonyChunks(colony, true, barracks, barrack.getClaimRadius(newLevel));
if (newLevel == barrack.getMaxBuildingLevel()) {
boolean allUpgraded = true;
for (BlockPos tower : ((BuildingBarracks) barrack).getTowers()) {
Log.getLogger().info("Upgraded: " + allUpgraded);
if (colony.getBuildingManager().getBuilding(tower).getBuildingLevel() != barrack.getMaxBuildingLevel())
allUpgraded = false;
}
if (allUpgraded)
AdvancementUtils.TriggerAdvancementPlayersForColony(colony, AdvancementTriggers.ALL_TOWERS::trigger);
}
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by ldtteam.
the class AbstractEntityAIStructureWithWorkOrder method executeSpecificCompleteActions.
@Override
public void executeSpecificCompleteActions() {
if (job.getBlueprint() == null && job.hasWorkOrder()) {
// fix for bad structures
job.complete();
}
if (job.getBlueprint() == null) {
return;
}
final String structureName = job.getBlueprint().getName();
final WorkOrderBuildDecoration wo = job.getWorkOrder();
if (wo instanceof WorkOrderBuildBuilding) {
sendCompletionMessage(wo);
WorkOrderBuild wob = (WorkOrderBuild) wo;
String buildingName = wo.getStructureName();
buildingName = buildingName.substring(buildingName.indexOf('/') + 1, buildingName.lastIndexOf('/')) + " " + buildingName.substring(buildingName.lastIndexOf('/') + 1, buildingName.lastIndexOf(String.valueOf(wob.getUpgradeLevel())));
job.getColony().getEventDescriptionManager().addEventDescription(wob.getUpgradeLevel() > 1 ? new BuildingUpgradedEvent(wo.getSchematicLocation(), buildingName, wob.getUpgradeLevel()) : new BuildingBuiltEvent(wo.getSchematicLocation(), buildingName, wob.getUpgradeLevel()));
} else if (wo instanceof WorkOrderBuildRemoval) {
worker.getCitizenChatHandler().sendLocalizedChat(COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_DECONSTRUCTION_COMPLETE, structureName);
WorkOrderBuild wob = (WorkOrderBuild) wo;
String buildingName = wo.getStructureName();
buildingName = buildingName.substring(buildingName.indexOf('/') + 1, buildingName.lastIndexOf('/')) + " " + buildingName.substring(buildingName.lastIndexOf('/') + 1, buildingName.indexOf(String.valueOf(wob.getUpgradeLevel())));
job.getColony().getEventDescriptionManager().addEventDescription(new BuildingDeconstructedEvent(wo.getSchematicLocation(), buildingName, wob.getUpgradeLevel()));
} else {
sendCompletionMessage(wo);
}
if (wo == null) {
Log.getLogger().error(String.format("Worker (%d:%d) ERROR - Finished, but missing work order(%d)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), job.getWorkOrderId()));
} else {
job.complete();
if (wo instanceof WorkOrderBuildBuilding) {
final IBuilding building = job.getColony().getBuildingManager().getBuilding(wo.getSchematicLocation());
if (building == null) {
Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Finished, but missing building(%s)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), wo.getSchematicLocation()));
} else {
// Normally levels are done through the schematic data, but incase it is missing we do it manually here.
final TileEntity te = worker.level.getBlockEntity(building.getID());
if (te instanceof AbstractTileEntityColonyBuilding && ((IBlueprintDataProvider) te).getSchematicName().isEmpty()) {
building.onUpgradeComplete(((WorkOrderBuildBuilding) wo).getUpgradeLevel());
building.setBuildingLevel(((WorkOrderBuildBuilding) wo).getUpgradeLevel());
}
}
} else if (wo instanceof WorkOrderBuildRemoval) {
final IBuilding building = job.getColony().getBuildingManager().getBuilding(wo.getSchematicLocation());
if (building == null) {
Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Finished, but missing building(%s)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), wo.getSchematicLocation()));
} else {
building.setDeconstructed();
}
}
}
getOwnBuilding().resetNeededResources();
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by ldtteam.
the class AbstractEntityAIStructureWithWorkOrder method loadRequirements.
/**
* Takes the existing workorder, loads the structure and tests the worker order if it is valid.
*/
@Override
public IAIState loadRequirements() {
if (!job.hasBlueprint() || structurePlacer == null) {
loadStructure();
final WorkOrderBuildDecoration wo = job.getWorkOrder();
if (wo == null) {
Log.getLogger().error(String.format("Worker (%d:%d) ERROR - Starting and missing work order(%d)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), job.getWorkOrderId()), new Exception());
job.setWorkOrder(null);
return IDLE;
}
if (wo instanceof WorkOrderBuildBuilding) {
final IBuilding building = job.getColony().getBuildingManager().getBuilding(wo.getSchematicLocation());
if (building == null) {
Log.getLogger().error(String.format("Worker (%d:%d) ERROR - Starting and missing building(%s)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), wo.getSchematicLocation()), new Exception());
return IDLE;
}
worker.getCitizenChatHandler().sendLocalizedChat(COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_BUILDSTART, job.getWorkOrder().getDisplayName());
// Don't go through the CLEAR stage for repairs and upgrades
if (building.getBuildingLevel() > 0) {
wo.setCleared(true);
}
} else if (!(wo instanceof WorkOrderBuildMiner)) {
worker.getCitizenChatHandler().sendLocalizedChat(COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_BUILDSTART, wo.getDisplayName());
}
return getState();
}
if (job.getWorkOrder().isRequested()) {
return afterStructureLoading();
}
// We need to deal with materials
requestMaterialsState();
return getState();
}
Aggregations