use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingLumberjack in project minecolonies by Minecolonies.
the class EntityAIWorkLumberjack method findTree.
/**
* Search for a tree.
*
* @return LUMBERJACK_GATHERING if job was canceled.
*/
private IAIState findTree() {
final BuildingLumberjack building = getOwnBuilding();
worker.getCitizenData().setVisibleStatus(SEARCH);
if (pathResult != null && pathResult.isComputing()) {
return getState();
}
if (pathResult == null) {
if (building.shouldRestrict()) {
final BlockPos startPos = building.getStartRestriction();
final BlockPos endPos = building.getEndRestriction();
pathResult = worker.getNavigation().moveToTree(startPos, endPos, 1.0D, building.getModuleMatching(ItemListModule.class, m -> m.getId().equals(SAPLINGS_LIST)).getList(), building.getSetting(BuildingLumberjack.DYNAMIC_TREES_SIZE).getValue(), worker.getCitizenColonyHandler().getColony());
} else {
pathResult = worker.getNavigation().moveToTree(SEARCH_RANGE + searchIncrement, 1.0D, building.getModuleMatching(ItemListModule.class, m -> m.getId().equals(SAPLINGS_LIST)).getList(), building.getSetting(BuildingLumberjack.DYNAMIC_TREES_SIZE).getValue(), worker.getCitizenColonyHandler().getColony());
}
return getState();
}
if (pathResult.isDone()) {
return setNewTree(building);
}
// None of the above yielded a result, report no trees found.
return LUMBERJACK_NO_TREES_FOUND;
}
use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingLumberjack in project minecolonies by Minecolonies.
the class EntityAIWorkLumberjack method chopTree.
/**
* Work on the tree. First find your way to the tree trunk. Then chop away and wait for saplings to drop then place a sapling if shouldReplant is true
*
* @return LUMBERJACK_GATHERING if tree is done
*/
private IAIState chopTree() {
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.chopping"));
if (job.getTree().hasLogs() || (job.getTree().hasLeaves() && job.getTree().isNetherTree()) || checkedInHut) {
if (!walkToTree(job.getTree().getStumpLocations().get(0))) {
if (checkIfStuck()) {
tryUnstuck();
}
return getState();
}
}
if (!job.getTree().hasLogs() && (!job.getTree().isNetherTree() || !(job.getTree().hasLeaves()))) {
if (hasNotDelayed(WAIT_BEFORE_SAPLING)) {
return getState();
}
final BuildingLumberjack building = getOwnBuilding();
if (building.shouldReplant()) {
plantSapling();
} else {
job.setTree(null);
checkedInHut = false;
}
worker.getCitizenExperienceHandler().addExperience(XP_PER_TREE);
incrementActionsDoneAndDecSaturation();
workFrom = null;
setDelay(TICKS_SECOND * GATHERING_DELAY);
return LUMBERJACK_GATHERING;
}
if (isOnSapling()) {
@Nullable final BlockPos spawnPoint = Utils.scanForBlockNearPoint(world, workFrom, 1, 1, 1, 3, Blocks.AIR, Blocks.CAVE_AIR, Blocks.SNOW, Blocks.TALL_GRASS);
WorkerUtil.setSpawnPoint(spawnPoint, worker);
}
if (job.getTree().hasLogs()) {
// take first log from queue
final BlockPos log = job.getTree().peekNextLog();
if (job.getTree().isDynamicTree()) {
// Dynamic Trees handles drops/tool dmg upon tree break, so those are set to false here
if (!mineBlock(log, workFrom, false, false, Compatibility.getDynamicTreeBreakAction(world, log, worker.getItemInHand(Hand.MAIN_HAND), worker.blockPosition()))) {
return getState();
}
// Successfully mined Dynamic tree, count as 6 actions done(1+5)
for (int i = 0; i < 6; i++) {
this.incrementActionsDone();
}
// Wait 5 sec for falling trees(dyn tree feature)/drops
setDelay(100);
} else {
if (!mineBlock(log, workFrom)) {
return getState();
}
}
job.getTree().pollNextLog();
worker.decreaseSaturationForContinuousAction();
} else if (job.getTree().hasLeaves() && job.getTree().isNetherTree()) {
final BlockPos leaf = job.getTree().peekNextLeaf();
if (!mineBlock(leaf, workFrom)) {
return getState();
}
job.getTree().pollNextLeaf();
}
return getState();
}
use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingLumberjack in project minecolonies by ldtteam.
the class EntityAIWorkLumberjack method chopTree.
/**
* Work on the tree. First find your way to the tree trunk. Then chop away and wait for saplings to drop then place a sapling if shouldReplant is true
*
* @return LUMBERJACK_GATHERING if tree is done
*/
private IAIState chopTree() {
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.chopping"));
if (job.getTree().hasLogs() || (job.getTree().hasLeaves() && job.getTree().isNetherTree()) || checkedInHut) {
if (!walkToTree(job.getTree().getStumpLocations().get(0))) {
if (checkIfStuck()) {
tryUnstuck();
}
return getState();
}
}
if (!job.getTree().hasLogs() && (!job.getTree().isNetherTree() || !(job.getTree().hasLeaves()))) {
if (hasNotDelayed(WAIT_BEFORE_SAPLING)) {
return getState();
}
final BuildingLumberjack building = getOwnBuilding();
if (building.shouldReplant()) {
plantSapling();
} else {
job.setTree(null);
checkedInHut = false;
}
worker.getCitizenExperienceHandler().addExperience(XP_PER_TREE);
incrementActionsDoneAndDecSaturation();
workFrom = null;
setDelay(TICKS_SECOND * GATHERING_DELAY);
return LUMBERJACK_GATHERING;
}
if (isOnSapling()) {
@Nullable final BlockPos spawnPoint = Utils.scanForBlockNearPoint(world, workFrom, 1, 1, 1, 3, Blocks.AIR, Blocks.CAVE_AIR, Blocks.SNOW, Blocks.TALL_GRASS);
WorkerUtil.setSpawnPoint(spawnPoint, worker);
}
if (job.getTree().hasLogs()) {
// take first log from queue
final BlockPos log = job.getTree().peekNextLog();
if (job.getTree().isDynamicTree()) {
// Dynamic Trees handles drops/tool dmg upon tree break, so those are set to false here
if (!mineBlock(log, workFrom, false, false, Compatibility.getDynamicTreeBreakAction(world, log, worker.getItemInHand(Hand.MAIN_HAND), worker.blockPosition()))) {
return getState();
}
// Successfully mined Dynamic tree, count as 6 actions done(1+5)
for (int i = 0; i < 6; i++) {
this.incrementActionsDone();
}
// Wait 5 sec for falling trees(dyn tree feature)/drops
setDelay(100);
} else {
if (!mineBlock(log, workFrom)) {
return getState();
}
}
job.getTree().pollNextLog();
worker.decreaseSaturationForContinuousAction();
} else if (job.getTree().hasLeaves() && job.getTree().isNetherTree()) {
final BlockPos leaf = job.getTree().peekNextLeaf();
if (!mineBlock(leaf, workFrom)) {
return getState();
}
job.getTree().pollNextLeaf();
}
return getState();
}
use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingLumberjack in project minecolonies by ldtteam.
the class EntityAIWorkLumberjack method findTree.
/**
* Search for a tree.
*
* @return LUMBERJACK_GATHERING if job was canceled.
*/
private IAIState findTree() {
final BuildingLumberjack building = getOwnBuilding();
worker.getCitizenData().setVisibleStatus(SEARCH);
if (pathResult != null && pathResult.isComputing()) {
return getState();
}
if (pathResult == null) {
if (building.shouldRestrict()) {
final BlockPos startPos = building.getStartRestriction();
final BlockPos endPos = building.getEndRestriction();
pathResult = worker.getNavigation().moveToTree(startPos, endPos, 1.0D, building.getModuleMatching(ItemListModule.class, m -> m.getId().equals(SAPLINGS_LIST)).getList(), building.getSetting(BuildingLumberjack.DYNAMIC_TREES_SIZE).getValue(), worker.getCitizenColonyHandler().getColony());
} else {
pathResult = worker.getNavigation().moveToTree(SEARCH_RANGE + searchIncrement, 1.0D, building.getModuleMatching(ItemListModule.class, m -> m.getId().equals(SAPLINGS_LIST)).getList(), building.getSetting(BuildingLumberjack.DYNAMIC_TREES_SIZE).getValue(), worker.getCitizenColonyHandler().getColony());
}
return getState();
}
if (pathResult.isDone()) {
return setNewTree(building);
}
// None of the above yielded a result, report no trees found.
return LUMBERJACK_NO_TREES_FOUND;
}
use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingLumberjack in project minecolonies by Minecolonies.
the class ItemScepterLumberjack method storeRestrictedArea.
private void storeRestrictedArea(final PlayerEntity player, final CompoundNBT compound, final World worldIn) {
final BlockPos startRestriction = BlockPosUtil.read(compound, NBT_START_POS);
final BlockPos endRestriction = BlockPosUtil.read(compound, NBT_END_POS);
// Check restricted area isn't too large
final int minX = Math.min(startRestriction.getX(), endRestriction.getX());
final int minZ = Math.min(startRestriction.getZ(), endRestriction.getZ());
final int maxX = Math.max(startRestriction.getX(), endRestriction.getX());
final int maxZ = Math.max(startRestriction.getZ(), endRestriction.getZ());
final int distX = maxX - minX;
final int distZ = maxZ - minZ;
final int area = distX * distZ;
final int maxArea = (int) Math.floor(2 * Math.pow(EntityAIWorkLumberjack.SEARCH_RANGE, 2));
if (area > maxArea) {
LanguageHandler.sendPlayerMessage(player, "item.minecolonies.scepterlumberjack.restrictiontoobig", area, maxArea);
return;
}
LanguageHandler.sendPlayerMessage(player, "item.minecolonies.scepterlumberjack.restrictionset", minX, maxX, minZ, maxZ, area, maxArea);
final IColony colony = IColonyManager.getInstance().getColonyByWorld(compound.getInt(TAG_ID), worldIn);
final BlockPos hutPos = BlockPosUtil.read(compound, TAG_POS);
final BuildingLumberjack hut = colony.getBuildingManager().getBuilding(hutPos, BuildingLumberjack.class);
if (hut == null) {
return;
}
hut.setRestrictedArea(startRestriction, endRestriction);
}
Aggregations