|
56 | 56 | import net.minecraft.world.phys.HitResult;
|
57 | 57 | import net.minecraft.world.phys.Vec3;
|
58 | 58 |
|
59 |
| -import java.util.ArrayList; |
60 |
| -import java.util.Arrays; |
61 |
| -import java.util.List; |
62 |
| -import java.util.Optional; |
| 59 | +import java.util.*; |
63 | 60 | import java.util.function.Predicate;
|
64 | 61 |
|
65 | 62 | public final class FarmProcess extends BaritoneProcessHelper implements IFarmProcess {
|
@@ -102,6 +99,31 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
|
102 | 99 | Blocks.CACTUS.asItem()
|
103 | 100 | );
|
104 | 101 |
|
| 102 | + private static final Map<Block, Item> CROP_TO_PLANTABLE = new HashMap<>(); |
| 103 | + static { |
| 104 | + CROP_TO_PLANTABLE.put(Blocks.BEETROOTS, Items.BEETROOT_SEEDS); |
| 105 | + CROP_TO_PLANTABLE.put(Blocks.WHEAT, Items.WHEAT_SEEDS); |
| 106 | + CROP_TO_PLANTABLE.put(Blocks.CARROTS, Items.CARROT); |
| 107 | + CROP_TO_PLANTABLE.put(Blocks.POTATOES, Items.POTATO); |
| 108 | + CROP_TO_PLANTABLE.put(Blocks.MELON, Items.MELON_SEEDS); |
| 109 | + CROP_TO_PLANTABLE.put(Blocks.PUMPKIN, Items.PUMPKIN_SEEDS); |
| 110 | + } |
| 111 | + |
| 112 | + private static final Map<Block, List<Item>> CROP_TO_DROPPED = new HashMap<>(); |
| 113 | + static { |
| 114 | + CROP_TO_DROPPED.put(Blocks.BEETROOTS, Arrays.asList(Items.BEETROOT, Items.BEETROOT_SEEDS)); |
| 115 | + CROP_TO_DROPPED.put(Blocks.WHEAT, Arrays.asList(Items.WHEAT, Items.WHEAT_SEEDS)); |
| 116 | + CROP_TO_DROPPED.put(Blocks.CARROTS, List.of(Items.CARROT)); |
| 117 | + CROP_TO_DROPPED.put(Blocks.POTATOES, List.of(Items.POTATO)); |
| 118 | + CROP_TO_DROPPED.put(Blocks.MELON, Arrays.asList(Items.MELON_SEEDS, Items.MELON_SLICE)); |
| 119 | + CROP_TO_DROPPED.put(Blocks.PUMPKIN, Arrays.asList(Items.PUMPKIN, Items.PUMPKIN_SEEDS)); |
| 120 | + CROP_TO_DROPPED.put(Blocks.NETHER_WART, List.of(Items.NETHER_WART)); |
| 121 | + CROP_TO_DROPPED.put(Blocks.COCOA, List.of(Items.COCOA_BEANS)); |
| 122 | + CROP_TO_DROPPED.put(Blocks.SUGAR_CANE, List.of(Items.SUGAR_CANE)); |
| 123 | + CROP_TO_DROPPED.put(Blocks.BAMBOO, List.of(Items.BAMBOO)); |
| 124 | + CROP_TO_DROPPED.put(Blocks.CACTUS, List.of(Items.CACTUS)); |
| 125 | + } |
| 126 | + |
105 | 127 | public FarmProcess(Baritone baritone) {
|
106 | 128 | super(baritone);
|
107 | 129 | }
|
@@ -202,26 +224,82 @@ public boolean readyToHarvest(Level world, BlockPos pos, BlockState state) {
|
202 | 224 | private boolean readyForHarvest(Level world, BlockPos pos, BlockState state) {
|
203 | 225 | for (Harvest harvest : Harvest.values()) {
|
204 | 226 | if (harvest.block == state.getBlock()) {
|
205 |
| - return harvest.readyToHarvest(world, pos, state); |
| 227 | + if (!Baritone.settings().farmEnableWhitelist.value) { |
| 228 | + return harvest.readyToHarvest(world, pos, state); |
| 229 | + } else { |
| 230 | + for (Block whitelist : Baritone.settings().farmWhitelist.value) { |
| 231 | + if ((harvest.block.equals(whitelist)) && (harvest.block == state.getBlock())) { |
| 232 | + return harvest.readyToHarvest(world, pos, state); |
| 233 | + } |
| 234 | + } |
| 235 | + } |
206 | 236 | }
|
207 | 237 | }
|
208 | 238 | return false;
|
209 | 239 | }
|
210 | 240 |
|
211 | 241 | private boolean isPlantable(ItemStack stack) {
|
212 |
| - return FARMLAND_PLANTABLE.contains(stack.getItem()); |
| 242 | + if (!Baritone.settings().farmEnableWhitelist.value) { |
| 243 | + return FARMLAND_PLANTABLE.contains(stack.getItem()); |
| 244 | + } |
| 245 | + if (!FARMLAND_PLANTABLE.contains(stack.getItem())) { |
| 246 | + return false; |
| 247 | + } else { |
| 248 | + List<Item> whitelistedFarmlandPlantable = new ArrayList<>(); |
| 249 | + for (Block whitelist : Baritone.settings().farmWhitelist.value) { |
| 250 | + if (!(CROP_TO_PLANTABLE.get(whitelist) == null) && (CROP_TO_PLANTABLE.get(whitelist)).equals(stack.getItem())) { |
| 251 | + whitelistedFarmlandPlantable.add(CROP_TO_PLANTABLE.get(whitelist)); |
| 252 | + } |
| 253 | + } |
| 254 | + return whitelistedFarmlandPlantable.contains(stack.getItem()); |
| 255 | + } |
213 | 256 | }
|
214 | 257 |
|
215 | 258 | private boolean isBoneMeal(ItemStack stack) {
|
216 | 259 | return !stack.isEmpty() && stack.getItem().equals(Items.BONE_MEAL);
|
217 | 260 | }
|
218 | 261 |
|
219 | 262 | private boolean isNetherWart(ItemStack stack) {
|
220 |
| - return !stack.isEmpty() && stack.getItem().equals(Items.NETHER_WART); |
| 263 | + if (!Baritone.settings().farmEnableWhitelist.value) { |
| 264 | + return !stack.isEmpty() && stack.getItem().equals(Items.NETHER_WART); |
| 265 | + } else { |
| 266 | + return !stack.isEmpty() && stack.getItem().equals(Items.NETHER_WART) && Baritone.settings().farmWhitelist.value.contains(Blocks.NETHER_WART); |
| 267 | + } |
221 | 268 | }
|
222 | 269 |
|
223 | 270 | private boolean isCocoa(ItemStack stack) {
|
224 |
| - return !stack.isEmpty() && stack.getItem().equals(Items.COCOA_BEANS); |
| 271 | + if (!Baritone.settings().farmEnableWhitelist.value) { |
| 272 | + return !stack.isEmpty() && stack.getItem().equals(Items.COCOA_BEANS); |
| 273 | + } else { |
| 274 | + return !stack.isEmpty() && stack.getItem().equals(Items.COCOA_BEANS) && Baritone.settings().farmWhitelist.value.contains(Blocks.COCOA); |
| 275 | + } |
| 276 | + } |
| 277 | + |
| 278 | + private List<Goal> whereAreTheDrops() { |
| 279 | + List<Goal> pickup = new ArrayList<>(); |
| 280 | + for (Entity entity : ctx.entities()) { |
| 281 | + //check if the pickupGoals is out of range. |
| 282 | + if (range != 0 && entity.blockPosition().distSqr(center) > range * range) { |
| 283 | + continue; |
| 284 | + } |
| 285 | + if (entity instanceof ItemEntity && entity.onGround()) { |
| 286 | + ItemEntity ei = (ItemEntity) entity; |
| 287 | + if (PICKUP_DROPPED.contains(ei.getItem().getItem())) { |
| 288 | + if (!Baritone.settings().farmEnableWhitelist.value) { |
| 289 | + // +0.1 because of farmland's 0.9375 and soulsand's 0.875 dummy height lol |
| 290 | + pickup.add(new GoalBlock(new BetterBlockPos(entity.position().x, entity.position().y + 0.125, entity.position().z))); |
| 291 | + } else { |
| 292 | + for (Block whitelist : Baritone.settings().farmWhitelist.value) { |
| 293 | + if (!(CROP_TO_DROPPED.get(whitelist) == null) && (CROP_TO_DROPPED.get(whitelist)).contains(ei.getItem().getItem())) { |
| 294 | + // +0.1 because of farmland's 0.9375 and soulsand's 0.875 dummy height lol |
| 295 | + pickup.add(new GoalBlock(new BetterBlockPos(entity.position().x, entity.position().y + 0.125, entity.position().z))); |
| 296 | + } |
| 297 | + } |
| 298 | + } |
| 299 | + } |
| 300 | + } |
| 301 | + } |
| 302 | + return pickup; |
225 | 303 | }
|
226 | 304 |
|
227 | 305 | @Override
|
@@ -297,23 +375,11 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
|
297 | 375 | // Farm Continuously: Block input while paused
|
298 | 376 | if (!isPaused()) {
|
299 | 377 | // Check if item gather is prioritized
|
300 |
| - if (Baritone.settings().farmPrioritizeGather.value) { |
301 |
| - List<Goal> pickupGoals = new ArrayList<>(); |
302 |
| - for (Entity entity : ctx.entities()) { |
303 |
| - //check if the pickupGoals is out of range. |
304 |
| - if (range != 0 && entity.blockPosition().distSqr(center) > range * range) { |
305 |
| - continue; |
306 |
| - } |
307 |
| - if (entity instanceof ItemEntity && entity.onGround()) { |
308 |
| - ItemEntity ei = (ItemEntity) entity; |
309 |
| - if (PICKUP_DROPPED.contains(ei.getItem().getItem())) { |
310 |
| - // +0.1 because of farmland's 0.9375 and soulsand's 0.875 dummy height lol |
311 |
| - pickupGoals.add(new GoalBlock(new BetterBlockPos(entity.position().x, entity.position().y + 0.125, entity.position().z))); |
312 |
| - } |
313 |
| - } |
314 |
| - } |
| 378 | + if (Baritone.settings().farmPrioritizePickup.value) { |
| 379 | + List<Goal> pickupGoals = whereAreTheDrops(); |
315 | 380 | if (!(pickupGoals.isEmpty())) {
|
316 |
| - return new PathingCommand(new GoalComposite(pickupGoals.toArray(new Goal[0])), PathingCommandType.SET_GOAL_AND_PATH); |
| 381 | + GoalComposite pickupGoalComposite = new GoalComposite(pickupGoals.toArray(new Goal[0])); |
| 382 | + return new PathingCommand(pickupGoalComposite, PathingCommandType.SET_GOAL_AND_PATH); |
317 | 383 | }
|
318 | 384 | }
|
319 | 385 | baritone.getInputOverrideHandler().clearAllKeys();
|
@@ -428,18 +494,10 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
|
428 | 494 | goalz.add(new GoalBlock(pos));
|
429 | 495 | }
|
430 | 496 | }
|
431 |
| - for (Entity entity : ctx.entities()) { |
432 |
| - //check if the pickupGoals is out of range. |
433 |
| - if (range != 0 && entity.blockPosition().distSqr(center) > range * range) { |
434 |
| - continue; |
435 |
| - } |
436 |
| - if (entity instanceof ItemEntity && entity.onGround()) { |
437 |
| - ItemEntity ei = (ItemEntity) entity; |
438 |
| - if (PICKUP_DROPPED.contains(ei.getItem().getItem())) { |
439 |
| - // +0.1 because of farmland's 0.9375 and soulsand's 0.875 dummy height lol |
440 |
| - goalz.add(new GoalBlock(new BetterBlockPos(entity.position().x, entity.position().y + 0.125, entity.position().z))); |
441 |
| - } |
442 |
| - } |
| 497 | + List<Goal> pickupGoals = whereAreTheDrops(); |
| 498 | + if (!(pickupGoals.isEmpty())) { |
| 499 | + GoalComposite pickupGoalComposite = new GoalComposite(pickupGoals.toArray(new Goal[0])); |
| 500 | + goalz.add(pickupGoalComposite); |
443 | 501 | }
|
444 | 502 | if (goalz.isEmpty() && !isPaused()) {
|
445 | 503 | if (!Baritone.settings().farmContinuously.value) {
|
|
0 commit comments