use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.
the class EventHandler method onBlockBreak.
/**
* Event when a block is broken.
* Event gets cancelled when there no permission to break a hut.
*
* @param event {@link net.minecraftforge.event.world.BlockEvent.BreakEvent}
*/
@SubscribeEvent
public void onBlockBreak(@NotNull final BlockEvent.BreakEvent event) {
final World world = event.getWorld();
if (!world.isRemote && event.getState().getBlock() instanceof AbstractBlockHut) {
@Nullable final AbstractBuilding building = ColonyManager.getBuilding(world, event.getPos());
if (building == null) {
return;
}
if (!building.getColony().getPermissions().hasPermission(event.getPlayer(), Action.BREAK_HUTS)) {
event.setCanceled(true);
return;
}
building.destroy();
}
}
use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.
the class AbstractEntityAIGuard method checkIfExecute.
/**
* Checks if the worker is in a state where he can execute well.
*
* @return true if so.
*/
private boolean checkIfExecute() {
final AbstractBuilding building = getOwnBuilding();
if (!(building instanceof BuildingGuardTower)) {
return true;
}
if (!((BuildingGuardTower) building).shallRetrieveOnLowHealth()) {
return false;
}
if (worker.getHealth() > 2) {
return false;
}
worker.isWorkerAtSiteWithMove(building.getLocation(), PATH_CLOSE);
return true;
}
use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.
the class AbstractEntityAIGuard method patrol.
/**
* Lets the guard patrol inside the colony area searching for mobs.
*
* @return the next state to go.
*/
protected AIState patrol() {
worker.setAIMoveSpeed(1);
final AbstractBuilding building = getOwnBuilding();
if (building instanceof BuildingGuardTower) {
if (currentPathTarget == null || BlockPosUtil.getDistance2D(building.getColony().getCenter(), currentPathTarget) > Configurations.workingRangeTownHall + Configurations.townHallPadding || currentPathTarget.getY() < 2) {
return getNextPatrollingTarget((BuildingGuardTower) building);
}
if (worker.isWorkerAtSiteWithMove(currentPathTarget, PATH_CLOSE) || ((BuildingGuardTower) building).getTask().equals(BuildingGuardTower.Task.FOLLOW)) {
return getNextPatrollingTarget((BuildingGuardTower) building);
}
}
return AIState.GUARD_SEARCH_TARGET;
}
use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.
the class EntityAIStructureBuilder method executeSpecificCompleteActions.
@Override
public void executeSpecificCompleteActions() {
if (job.getStructure() == null && job.hasWorkOrder()) {
//fix for bad structures
job.complete();
}
if (job.getStructure() == null) {
return;
}
final String structureName = job.getStructure().getName();
worker.sendLocalizedChat(COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_BUILDCOMPLETE, structureName);
final WorkOrderBuildDecoration wo = job.getWorkOrder();
if (wo == null) {
Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Finished, but missing work order(%d)", worker.getColony().getID(), worker.getCitizenData().getId(), job.getWorkOrderId()));
} else {
final WorkOrderBuild woh = (wo instanceof WorkOrderBuild) ? (WorkOrderBuild) wo : null;
if (woh == null && structureName.contains(WAYPOINT_STRING)) {
worker.getColony().addWayPoint(wo.getBuildingLocation(), world.getBlockState(wo.getBuildingLocation()));
} else if (woh != null) {
final AbstractBuilding building = job.getColony().getBuilding(wo.getBuildingLocation());
if (building == null) {
Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Finished, but missing building(%s)", worker.getColony().getID(), worker.getCitizenData().getId(), woh.getBuildingLocation()));
} else {
building.setBuildingLevel(woh.getUpgradeLevel());
}
}
job.complete();
}
final BuildingBuilder workerBuilding = (BuildingBuilder) getOwnBuilding();
workerBuilding.resetNeededResources();
resetTask();
}
Aggregations