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
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Brady
|
|
|
|
* @since 8/7/2018 4:30 PM
|
|
|
|
*/
|
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-11-13 17:50:29 +00:00
|
|
|
private final IBaritone baritone;
|
2018-11-10 01:21:02 +00:00
|
|
|
private final EntityPlayerSP player;
|
|
|
|
private final World world;
|
2018-11-12 02:23:18 +00:00
|
|
|
private final WorldData worldData;
|
2018-11-12 01:36:54 +00:00
|
|
|
private final BlockStateInterface bsi;
|
2018-08-07 21:36:32 +00:00
|
|
|
private final ToolSet toolSet;
|
2018-08-08 22:41:58 +00:00
|
|
|
private final boolean hasWaterBucket;
|
2018-08-11 22:03:14 +00:00
|
|
|
private final boolean hasThrowaway;
|
2018-08-17 17:52:58 +00:00
|
|
|
private final boolean canSprint;
|
2018-08-17 20:17:16 +00:00
|
|
|
private final double placeBlockCost;
|
|
|
|
private final boolean allowBreak;
|
2018-08-22 00:16:00 +00:00
|
|
|
private final int maxFallHeightNoWater;
|
|
|
|
private final int maxFallHeightBucket;
|
2018-10-01 21:26:55 +00:00
|
|
|
private final double waterWalkSpeed;
|
2018-10-03 15:20:24 +00:00
|
|
|
private final double breakBlockAdditionalCost;
|
2018-10-12 21:34:33 +00:00
|
|
|
private final BetterWorldBorder worldBorder;
|
2018-08-07 21:36:32 +00:00
|
|
|
|
2018-11-13 17:50:29 +00:00
|
|
|
public CalculationContext(IBaritone baritone) {
|
|
|
|
this.baritone = baritone;
|
|
|
|
this.player = baritone.getPlayerContext().player();
|
|
|
|
this.world = baritone.getPlayerContext().world();
|
|
|
|
this.worldData = (WorldData) baritone.getWorldProvider().getCurrentWorld();
|
2018-11-12 02:23:18 +00:00
|
|
|
this.bsi = new BlockStateInterface(world, worldData); // TODO TODO TODO
|
2018-11-12 01:36:54 +00:00
|
|
|
// new CalculationContext() needs to happen, can't add an argument (i'll beat you), can we get the world provider from currentlyTicking?
|
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-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-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-10-12 21:34:33 +00:00
|
|
|
public boolean canPlaceThrowawayAt(int x, int y, int z) {
|
|
|
|
if (!hasThrowaway()) { // only true if allowPlace is true, see constructor
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (isPossiblyProtected(x, y, z)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return worldBorder.canPlaceAt(x, z); // TODO perhaps MovementHelper.canPlaceAgainst could also use this?
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canBreakAt(int x, int y, int z) {
|
|
|
|
if (!allowBreak()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-27 23:18:03 +00:00
|
|
|
return !isPossiblyProtected(x, y, z);
|
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
|
|
|
}
|
|
|
|
|
2018-11-10 01:21:02 +00:00
|
|
|
public World world() {
|
|
|
|
return world;
|
|
|
|
}
|
|
|
|
|
|
|
|
public EntityPlayerSP player() {
|
|
|
|
return player;
|
|
|
|
}
|
|
|
|
|
2018-11-12 02:23:18 +00:00
|
|
|
public BlockStateInterface bsi() {
|
|
|
|
return bsi;
|
|
|
|
}
|
|
|
|
|
|
|
|
public WorldData worldData() {
|
|
|
|
return worldData;
|
|
|
|
}
|
2018-11-10 01:21:02 +00:00
|
|
|
|
2018-08-07 21:36:32 +00:00
|
|
|
public ToolSet getToolSet() {
|
2018-10-01 21:26:55 +00:00
|
|
|
return toolSet;
|
2018-08-07 21:36:32 +00:00
|
|
|
}
|
2018-08-08 22:41:58 +00:00
|
|
|
|
|
|
|
public boolean hasWaterBucket() {
|
|
|
|
return hasWaterBucket;
|
|
|
|
}
|
2018-08-11 22:03:14 +00:00
|
|
|
|
|
|
|
public boolean hasThrowaway() {
|
|
|
|
return hasThrowaway;
|
|
|
|
}
|
2018-08-17 17:52:58 +00:00
|
|
|
|
|
|
|
public boolean canSprint() {
|
|
|
|
return canSprint;
|
|
|
|
}
|
2018-08-17 20:17:16 +00:00
|
|
|
|
|
|
|
public double placeBlockCost() {
|
|
|
|
return placeBlockCost;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean allowBreak() {
|
|
|
|
return allowBreak;
|
|
|
|
}
|
2018-08-20 14:11:15 +00:00
|
|
|
|
2018-08-22 00:16:00 +00:00
|
|
|
public int maxFallHeightNoWater() {
|
|
|
|
return maxFallHeightNoWater;
|
2018-08-20 14:11:15 +00:00
|
|
|
}
|
2018-08-22 00:16:00 +00:00
|
|
|
|
|
|
|
public int maxFallHeightBucket() {
|
|
|
|
return maxFallHeightBucket;
|
|
|
|
}
|
|
|
|
|
2018-10-01 21:26:55 +00:00
|
|
|
public double waterWalkSpeed() {
|
|
|
|
return waterWalkSpeed;
|
|
|
|
}
|
|
|
|
|
2018-10-03 15:20:24 +00:00
|
|
|
public double breakBlockAdditionalCost() {
|
|
|
|
return breakBlockAdditionalCost;
|
|
|
|
}
|
2018-08-07 21:36:32 +00:00
|
|
|
}
|