use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by ldtteam.
the class Tree method checkIfInColonyAndNotInBuilding.
/**
* Calculates with a colony if the position is inside the colony and if it is inside a building.
*
* @param pos the position.
* @param colony the colony.
* @param world the world to use
* @return return false if not inside the colony or if inside a building.
*/
public static boolean checkIfInColonyAndNotInBuilding(final BlockPos pos, final IColony colony, final IWorldReader world) {
final IChunk chunk = world.getChunk(pos);
if (!(chunk instanceof Chunk)) {
return false;
}
final IColonyTagCapability cap = ((Chunk) chunk).getCapability(CLOSE_COLONY_CAP, null).resolve().orElse(null);
if (cap != null && cap.getOwningColony() != colony.getID()) {
return false;
}
// Dynamic tree's are never part of buildings
if (Compatibility.isDynamicBlock(world.getBlockState(pos).getBlock())) {
return true;
}
for (final IBuilding building : colony.getBuildingManager().getBuildings().values()) {
if (building.isInBuilding(pos)) {
return false;
}
}
return true;
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by ldtteam.
the class Tree method addAndSearch.
/**
* Adds a log and searches for further logs(Breadth first search).
*
* @param world The world the log is in.
* @param log the log to add.
*/
private void addAndSearch(@NotNull final World world, @NotNull final BlockPos log, final IColony colony) {
if (woodBlocks.size() >= MineColonies.getConfig().getServer().maxTreeSize.get()) {
return;
}
if (woodBlocks.contains(log)) {
return;
}
// Check if the new log fits the Tree's base log type
if (!world.getBlockState(log).getBlock().equals(world.getBlockState(location).getBlock())) {
return;
}
if (log.getY() < location.getY()) {
location = log;
}
if (log.getY() > topLog.getY()) {
topLog = log;
}
for (final IBuilding building : colony.getBuildingManager().getBuildings().values()) {
if (building.isInBuilding(log)) {
return;
}
}
woodBlocks.add(log);
// Only add the base to a dynamic tree
if (Compatibility.isDynamicBlock(BlockPosUtil.getBlock(world, log))) {
return;
}
for (int y = -1; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
final BlockPos temp = log.offset(x, y, z);
final Block block = BlockPosUtil.getBlock(world, temp);
if ((block.is(BlockTags.LOGS) || Compatibility.isSlimeBlock(block))) {
addAndSearch(world, temp, colony);
}
}
}
}
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by ldtteam.
the class EntityAIWorkDeliveryman method pickup.
/**
* Pickup items from a hut that has requested a pickup.
*
* @return the next state to go to.
*/
private IAIState pickup() {
final IRequest<? extends IDeliverymanRequestable> currentTask = job.getCurrentTask();
if (!(currentTask instanceof PickupRequest)) {
// The current task has changed since the Decision-state. Restart.
return START_WORKING;
}
if (cannotHoldMoreItems()) {
this.alreadyKept = new ArrayList<>();
this.currentSlot = 0;
return DUMPING;
}
worker.getCitizenData().setVisibleStatus(DELIVERING);
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.gathering"));
final BlockPos pickupTarget = currentTask.getRequester().getLocation().getInDimensionLocation();
if (pickupTarget != BlockPos.ZERO && !worker.isWorkerAtSiteWithMove(pickupTarget, MIN_DISTANCE_TO_WAREHOUSE)) {
setDelay(WALK_DELAY);
return PICKUP;
}
final IBuilding pickupBuilding = getOwnBuilding().getColony().getBuildingManager().getBuilding(pickupTarget);
if (pickupBuilding == null) {
job.finishRequest(false);
return START_WORKING;
}
if (pickupFromBuilding(pickupBuilding)) {
this.alreadyKept = new ArrayList<>();
this.currentSlot = 0;
job.finishRequest(true);
if (currentTask.getRequest().getPriority() >= PRIORITY_FORCING_DUMP) {
return DUMPING;
} else {
return START_WORKING;
}
} else if (InventoryUtils.openSlotCount(worker.getInventoryCitizen()) <= 0) {
this.alreadyKept = new ArrayList<>();
this.currentSlot = 0;
return DUMPING;
}
currentSlot++;
return PICKUP;
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by ldtteam.
the class EntityAIWorkDeliveryman method deliver.
/**
* Deliver the items to the hut. TODO: Current precondition: The dman's inventory may only consist of the requested itemstack.
*
* @return the next state.
*/
private IAIState deliver() {
final IRequest<? extends IDeliverymanRequestable> currentTask = job.getCurrentTask();
if (!(currentTask instanceof DeliveryRequest)) {
// Since prepareDelivery() was called earlier, go dumping first and then restart.
return DUMPING;
}
worker.getCitizenData().setVisibleStatus(DELIVERING);
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.delivering"));
final ILocation targetBuildingLocation = ((Delivery) currentTask.getRequest()).getTarget();
if (!targetBuildingLocation.isReachableFromLocation(worker.getLocation())) {
Log.getLogger().info(worker.getCitizenColonyHandler().getColony().getName() + ": " + worker.getName() + ": Can't inter dimension yet: ");
return START_WORKING;
}
if (!worker.isWorkerAtSiteWithMove(targetBuildingLocation.getInDimensionLocation(), MIN_DISTANCE_TO_WAREHOUSE)) {
setDelay(WALK_DELAY);
return DELIVERY;
}
final TileEntity tileEntity = world.getBlockEntity(targetBuildingLocation.getInDimensionLocation());
if (!(tileEntity instanceof TileEntityColonyBuilding)) {
// TODO: Non-Colony deliveries are unsupported yet. Fix that at some point in time.
job.finishRequest(true);
return START_WORKING;
}
final IBuilding targetBuilding = ((AbstractTileEntityColonyBuilding) tileEntity).getBuilding();
boolean success = true;
boolean extracted = false;
final IItemHandler workerInventory = worker.getInventoryCitizen();
for (int i = 0; i < workerInventory.getSlots(); i++) {
if (workerInventory.getStackInSlot(i).isEmpty()) {
continue;
}
final ItemStack stack = workerInventory.extractItem(i, Integer.MAX_VALUE, false);
if (ItemStackUtils.isEmpty(stack)) {
continue;
}
extracted = true;
final ItemStack insertionResultStack;
// TODO: Please only push items into the target that were actually requested.
if (targetBuilding instanceof AbstractBuilding) {
insertionResultStack = InventoryUtils.forceItemStackToItemHandler(targetBuilding.getCapability(ITEM_HANDLER_CAPABILITY, null).orElseGet(null), stack, ((IBuilding) targetBuilding)::isItemStackInRequest);
} else {
// Buildings that are not inherently part of the request system, but just receive a delivery, cannot have their items replaced.
// Therefore, the keep-predicate always returns true.
insertionResultStack = InventoryUtils.forceItemStackToItemHandler(targetBuilding.getCapability(ITEM_HANDLER_CAPABILITY, null).orElseGet(null), stack, itemStack -> true);
}
if (!ItemStackUtils.isEmpty(insertionResultStack)) {
if (ItemStack.matches(insertionResultStack, stack) && worker.getCitizenData() != null) {
// The replaced stack is the same as the one we tried to put into the inventory.
// Meaning, replacing failed.
success = false;
if (targetBuilding.hasModule(WorkerBuildingModule.class)) {
worker.getCitizenData().triggerInteraction(new PosBasedInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_NAMEDCHESTFULL, targetBuilding.getFirstModuleOccurance(WorkerBuildingModule.class).getFirstCitizen().getName()), ChatPriority.IMPORTANT, new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_CHESTFULL), targetBuilding.getID()));
} else {
worker.getCitizenData().triggerInteraction(new PosBasedInteraction(new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_CHESTFULL, new StringTextComponent(" :" + targetBuilding.getSchematicName())), ChatPriority.IMPORTANT, new TranslationTextComponent(COM_MINECOLONIES_COREMOD_JOB_DELIVERYMAN_CHESTFULL), targetBuildingLocation.getInDimensionLocation()));
}
}
// Insert the result back into the inventory so we do not lose it.
workerInventory.insertItem(i, insertionResultStack, false);
}
}
if (!extracted) {
// This can only happen if the dman's inventory was completely empty.
// Let the retry-system handle this case.
worker.decreaseSaturationForContinuousAction();
worker.getCitizenItemHandler().setHeldItem(Hand.MAIN_HAND, SLOT_HAND);
job.finishRequest(false);
// No need to go dumping in this case.
return START_WORKING;
}
worker.getCitizenExperienceHandler().addExperience(1.5D);
worker.decreaseSaturationForContinuousAction();
worker.getCitizenItemHandler().setHeldItem(Hand.MAIN_HAND, SLOT_HAND);
job.finishRequest(true);
return success ? START_WORKING : DUMPING;
}
use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by ldtteam.
the class AbstractEntityAIStructure method loadStructure.
/**
* Loads the structure given the name, rotation and position.
*
* @param name the name to retrieve it.
* @param rotateTimes number of times to rotateWithMirror it.
* @param position the position to set it.
* @param isMirrored is the structure mirroed?
* @param removal if removal step.
*/
public void loadStructure(@NotNull final String name, final int rotateTimes, final BlockPos position, final boolean isMirrored, final boolean removal) {
final BuildingStructureHandler<J, B> structure;
IBuilding colonyBuilding = worker.getCitizenColonyHandler().getColony().getBuildingManager().getBuilding(position);
final TileEntity entity = world.getBlockEntity(position);
if (removal) {
structure = new BuildingStructureHandler<>(world, position, name, new PlacementSettings(isMirrored ? Mirror.FRONT_BACK : Mirror.NONE, BlockPosUtil.getRotationFromRotations(rotateTimes)), this, new BuildingStructureHandler.Stage[] { REMOVE_WATER, REMOVE });
getOwnBuilding().setTotalStages(2);
} else if ((colonyBuilding != null && (colonyBuilding.getBuildingLevel() > 0 || colonyBuilding.hasParent())) || (entity instanceof TileEntityDecorationController && ((TileEntityDecorationController) entity).getTier() > 0)) {
structure = new BuildingStructureHandler<>(world, position, name, new PlacementSettings(isMirrored ? Mirror.FRONT_BACK : Mirror.NONE, BlockPosUtil.getRotationFromRotations(rotateTimes)), this, new BuildingStructureHandler.Stage[] { BUILD_SOLID, CLEAR_WATER, CLEAR_NON_SOLIDS, DECORATE, SPAWN });
getOwnBuilding().setTotalStages(5);
} else {
structure = new BuildingStructureHandler<>(world, position, name, new PlacementSettings(isMirrored ? Mirror.FRONT_BACK : Mirror.NONE, BlockPosUtil.getRotationFromRotations(rotateTimes)), this, new BuildingStructureHandler.Stage[] { CLEAR, BUILD_SOLID, CLEAR_WATER, CLEAR_NON_SOLIDS, DECORATE, SPAWN });
getOwnBuilding().setTotalStages(6);
}
if (!structure.hasBluePrint()) {
handleSpecificCancelActions();
Log.getLogger().warn("Couldn't find structure with name: " + name + " aborting loading procedure");
return;
}
job.setBlueprint(structure.getBluePrint());
job.getBlueprint().rotateWithMirror(BlockPosUtil.getRotationFromRotations(rotateTimes), isMirrored ? Mirror.FRONT_BACK : Mirror.NONE, world);
setStructurePlacer(structure);
if (getProgressPos() != null) {
structure.setStage(getProgressPos().getB());
}
}
Aggregations