2018-08-08 03:16:53 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Baritone.
|
|
|
|
*
|
|
|
|
* Baritone is free software: you can redistribute it and/or modify
|
2018-09-17 22:11:40 +00:00
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
2018-08-08 03:16:53 +00:00
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2018-08-08 04:15:22 +00:00
|
|
|
* Baritone is distributed in the hope that it will be useful,
|
2018-08-08 03:16:53 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2018-09-17 22:11:40 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2018-08-08 03:16:53 +00:00
|
|
|
*
|
2018-09-17 22:11:40 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2018-08-08 03:16:53 +00:00
|
|
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-08-22 20:15:56 +00:00
|
|
|
package baritone.pathing.movement;
|
2018-08-07 21:36:32 +00:00
|
|
|
|
2018-08-22 20:15:56 +00:00
|
|
|
import baritone.Baritone;
|
2018-11-13 17:50:29 +00:00
|
|
|
import baritone.api.IBaritone;
|
2018-10-01 21:26:55 +00:00
|
|
|
import baritone.api.pathing.movement.ActionCosts;
|
2018-11-12 02:23:18 +00:00
|
|
|
import baritone.cache.WorldData;
|
2018-11-11 20:35:04 +00:00
|
|
|
import baritone.utils.BlockStateInterface;
|
2018-08-22 20:15:56 +00:00
|
|
|
import baritone.utils.ToolSet;
|
2018-10-12 21:34:33 +00:00
|
|
|
import baritone.utils.pathing.BetterWorldBorder;
|
2018-11-11 20:35:04 +00:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
2018-11-10 01:21:02 +00:00
|
|
|
import net.minecraft.client.entity.EntityPlayerSP;
|
2018-10-01 21:26:55 +00:00
|
|
|
import net.minecraft.enchantment.EnchantmentHelper;
|
2018-08-11 03:24:26 +00:00
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
2018-08-08 22:41:58 +00:00
|
|
|
import net.minecraft.init.Items;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2018-11-11 20:35:04 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2018-11-10 01:21:02 +00:00
|
|
|
import net.minecraft.world.World;
|
2018-08-07 21:36:32 +00:00
|
|
|
|
2018-12-26 05:07:17 +00:00
|
|
|
import static baritone.api.pathing.movement.ActionCosts.COST_INF;
|
|
|
|
|
2018-08-07 21:36:32 +00:00
|
|
|
/**
|
|
|
|
* @author Brady
|
2018-11-14 03:53:27 +00:00
|
|
|
* @since 8/7/2018
|
2018-08-07 21:36:32 +00:00
|
|
|
*/
|
2018-11-10 01:21:02 +00:00
|
|
|
public class CalculationContext {
|
2018-08-07 21:36:32 +00:00
|
|
|
|
2018-08-11 03:24:26 +00:00
|
|
|
private static final ItemStack STACK_BUCKET_WATER = new ItemStack(Items.WATER_BUCKET);
|
|
|
|
|
2018-12-26 05:07:17 +00:00
|
|
|
public final boolean safeForThreadedUse;
|
2018-12-21 05:22:18 +00:00
|
|
|
public final IBaritone baritone;
|
|
|
|
public final EntityPlayerSP player;
|
|
|
|
public final World world;
|
|
|
|
public final WorldData worldData;
|
|
|
|
public final BlockStateInterface bsi;
|
|
|
|
public final ToolSet toolSet;
|
|
|
|
public final boolean hasWaterBucket;
|
|
|
|
public final boolean hasThrowaway;
|
|
|
|
public final boolean canSprint;
|
2018-12-26 05:07:17 +00:00
|
|
|
protected final double placeBlockCost; // protected because you should call the function instead
|
2018-12-21 05:22:18 +00:00
|
|
|
public final boolean allowBreak;
|
|
|
|
public final boolean allowParkour;
|
|
|
|
public final boolean allowParkourPlace;
|
|
|
|
public final boolean allowJumpAt256;
|
|
|
|
public final boolean assumeWalkOnWater;
|
|
|
|
public final boolean allowDiagonalDescend;
|
|
|
|
public final int maxFallHeightNoWater;
|
|
|
|
public final int maxFallHeightBucket;
|
|
|
|
public final double waterWalkSpeed;
|
|
|
|
public final double breakBlockAdditionalCost;
|
2019-01-09 22:36:44 +00:00
|
|
|
public double jumpPenalty;
|
2018-12-21 05:22:18 +00:00
|
|
|
public final double walkOnWaterOnePenalty;
|
|
|
|
public final BetterWorldBorder worldBorder;
|
2018-08-07 21:36:32 +00:00
|
|
|
|
2018-11-13 17:50:29 +00:00
|
|
|
public CalculationContext(IBaritone baritone) {
|
2018-11-26 06:30:37 +00:00
|
|
|
this(baritone, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public CalculationContext(IBaritone baritone, boolean forUseOnAnotherThread) {
|
2018-12-26 05:07:17 +00:00
|
|
|
this.safeForThreadedUse = forUseOnAnotherThread;
|
2018-11-13 17:50:29 +00:00
|
|
|
this.baritone = baritone;
|
|
|
|
this.player = baritone.getPlayerContext().player();
|
|
|
|
this.world = baritone.getPlayerContext().world();
|
|
|
|
this.worldData = (WorldData) baritone.getWorldProvider().getCurrentWorld();
|
2018-12-26 05:07:17 +00:00
|
|
|
this.bsi = new BlockStateInterface(world, worldData, forUseOnAnotherThread);
|
2018-11-10 01:21:02 +00:00
|
|
|
this.toolSet = new ToolSet(player);
|
2018-11-13 17:50:29 +00:00
|
|
|
this.hasThrowaway = Baritone.settings().allowPlace.get() && MovementHelper.throwaway(baritone.getPlayerContext(), false);
|
2018-11-10 01:21:02 +00:00
|
|
|
this.hasWaterBucket = Baritone.settings().allowWaterBucketFall.get() && InventoryPlayer.isHotbar(player.inventory.getSlotFor(STACK_BUCKET_WATER)) && !world.provider.isNether();
|
|
|
|
this.canSprint = Baritone.settings().allowSprint.get() && player.getFoodStats().getFoodLevel() > 6;
|
2018-08-17 20:17:16 +00:00
|
|
|
this.placeBlockCost = Baritone.settings().blockPlacementPenalty.get();
|
|
|
|
this.allowBreak = Baritone.settings().allowBreak.get();
|
2018-12-04 22:38:08 +00:00
|
|
|
this.allowParkour = Baritone.settings().allowParkour.get();
|
|
|
|
this.allowParkourPlace = Baritone.settings().allowParkourPlace.get();
|
2018-12-13 02:14:56 +00:00
|
|
|
this.allowJumpAt256 = Baritone.settings().allowJumpAt256.get();
|
2018-12-04 23:00:45 +00:00
|
|
|
this.assumeWalkOnWater = Baritone.settings().assumeWalkOnWater.get();
|
2018-12-21 05:06:56 +00:00
|
|
|
this.allowDiagonalDescend = Baritone.settings().allowDiagonalDescend.get();
|
2018-08-22 00:16:00 +00:00
|
|
|
this.maxFallHeightNoWater = Baritone.settings().maxFallHeightNoWater.get();
|
|
|
|
this.maxFallHeightBucket = Baritone.settings().maxFallHeightBucket.get();
|
2018-11-10 01:21:02 +00:00
|
|
|
int depth = EnchantmentHelper.getDepthStriderModifier(player);
|
2018-10-01 21:26:55 +00:00
|
|
|
if (depth > 3) {
|
|
|
|
depth = 3;
|
|
|
|
}
|
|
|
|
float mult = depth / 3.0F;
|
|
|
|
this.waterWalkSpeed = ActionCosts.WALK_ONE_IN_WATER_COST * (1 - mult) + ActionCosts.WALK_ONE_BLOCK_COST * mult;
|
2018-10-03 15:20:24 +00:00
|
|
|
this.breakBlockAdditionalCost = Baritone.settings().blockBreakAdditionalPenalty.get();
|
2018-12-19 22:37:11 +00:00
|
|
|
this.jumpPenalty = Baritone.settings().jumpPenalty.get();
|
2018-12-20 06:01:47 +00:00
|
|
|
this.walkOnWaterOnePenalty = Baritone.settings().walkOnWaterOnePenalty.get();
|
2018-08-17 20:17:16 +00:00
|
|
|
// why cache these things here, why not let the movements just get directly from settings?
|
|
|
|
// because if some movements are calculated one way and others are calculated another way,
|
|
|
|
// then you get a wildly inconsistent path that isn't optimal for either scenario.
|
2018-11-10 01:21:02 +00:00
|
|
|
this.worldBorder = new BetterWorldBorder(world.getWorldBorder());
|
2018-10-12 21:34:33 +00:00
|
|
|
}
|
|
|
|
|
2018-11-13 17:50:29 +00:00
|
|
|
public final IBaritone getBaritone() {
|
2018-11-13 22:33:45 +00:00
|
|
|
return baritone;
|
2018-11-13 17:50:29 +00:00
|
|
|
}
|
|
|
|
|
2018-11-11 20:35:04 +00:00
|
|
|
public IBlockState get(int x, int y, int z) {
|
2018-11-12 01:36:54 +00:00
|
|
|
return bsi.get0(x, y, z); // laughs maniacally
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isLoaded(int x, int z) {
|
|
|
|
return bsi.isLoaded(x, z);
|
|
|
|
}
|
|
|
|
|
2018-11-11 20:35:04 +00:00
|
|
|
public IBlockState get(BlockPos pos) {
|
|
|
|
return get(pos.getX(), pos.getY(), pos.getZ());
|
|
|
|
}
|
|
|
|
|
|
|
|
public Block getBlock(int x, int y, int z) {
|
|
|
|
return get(x, y, z).getBlock();
|
|
|
|
}
|
|
|
|
|
2018-12-26 05:07:17 +00:00
|
|
|
public double costOfPlacingAt(int x, int y, int z) {
|
2018-12-21 05:22:18 +00:00
|
|
|
if (!hasThrowaway) { // only true if allowPlace is true, see constructor
|
2018-12-26 05:07:17 +00:00
|
|
|
return COST_INF;
|
2018-10-12 21:34:33 +00:00
|
|
|
}
|
|
|
|
if (isPossiblyProtected(x, y, z)) {
|
2018-12-26 05:07:17 +00:00
|
|
|
return COST_INF;
|
2018-10-12 21:34:33 +00:00
|
|
|
}
|
2018-12-26 05:07:17 +00:00
|
|
|
if (!worldBorder.canPlaceAt(x, z)) {
|
|
|
|
// TODO perhaps MovementHelper.canPlaceAgainst could also use this?
|
|
|
|
return COST_INF;
|
|
|
|
}
|
|
|
|
return placeBlockCost;
|
2018-10-12 21:34:33 +00:00
|
|
|
}
|
|
|
|
|
2019-01-09 04:45:02 +00:00
|
|
|
public double breakCostMultiplierAt(int x, int y, int z) {
|
2018-12-21 05:22:18 +00:00
|
|
|
if (!allowBreak) {
|
2019-01-09 04:45:02 +00:00
|
|
|
return COST_INF;
|
|
|
|
}
|
|
|
|
if (isPossiblyProtected(x, y, z)) {
|
|
|
|
return COST_INF;
|
2018-10-12 21:34:33 +00:00
|
|
|
}
|
2019-01-09 04:45:02 +00:00
|
|
|
return 1;
|
2018-10-12 21:34:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-26 05:07:17 +00:00
|
|
|
public double placeBucketCost() {
|
|
|
|
return placeBlockCost; // shrug
|
|
|
|
}
|
|
|
|
|
2018-10-12 21:34:33 +00:00
|
|
|
public boolean isPossiblyProtected(int x, int y, int z) {
|
|
|
|
// TODO more protection logic here; see #220
|
|
|
|
return false;
|
2018-08-07 21:36:32 +00:00
|
|
|
}
|
|
|
|
}
|