no movement places more than one thing...
This commit is contained in:
parent
53d477d99a
commit
557f2e48c3
@ -30,7 +30,6 @@ import net.minecraft.block.BlockLadder;
|
|||||||
import net.minecraft.block.BlockVine;
|
import net.minecraft.block.BlockVine;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -53,23 +52,23 @@ public abstract class Movement implements Helper, MovementHelper {
|
|||||||
protected final BlockPos[] positionsToBreak;
|
protected final BlockPos[] positionsToBreak;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The positions where we need to place a block before this movement can ensue
|
* The position where we need to place a block before this movement can ensue
|
||||||
*/
|
*/
|
||||||
protected final BlockPos[] positionsToPlace;
|
protected final BlockPos positionToPlace;
|
||||||
|
|
||||||
private boolean didBreakLastTick;
|
private boolean didBreakLastTick;
|
||||||
|
|
||||||
private Double cost;
|
private Double cost;
|
||||||
|
|
||||||
protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak, BlockPos[] toPlace) {
|
protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak, BlockPos toPlace) {
|
||||||
this.src = src;
|
this.src = src;
|
||||||
this.dest = dest;
|
this.dest = dest;
|
||||||
this.positionsToBreak = toBreak;
|
this.positionsToBreak = toBreak;
|
||||||
this.positionsToPlace = toPlace;
|
this.positionToPlace = toPlace;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak, BlockPos[] toPlace, Vec3d rotationTarget) {
|
protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak) {
|
||||||
this(src, dest, toBreak, toPlace);
|
this(src, dest, toBreak, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getCost(CalculationContext context) {
|
public double getCost(CalculationContext context) {
|
||||||
@ -310,10 +309,8 @@ public abstract class Movement implements Helper, MovementHelper {
|
|||||||
return toPlaceCached;
|
return toPlaceCached;
|
||||||
}
|
}
|
||||||
List<BlockPos> result = new ArrayList<>();
|
List<BlockPos> result = new ArrayList<>();
|
||||||
for (BlockPos positionToBreak : positionsToPlace) {
|
if (positionToPlace != null && !MovementHelper.canWalkOn(positionToPlace)) {
|
||||||
if (!MovementHelper.canWalkOn(positionToBreak)) {
|
result.add(positionToPlace);
|
||||||
result.add(positionToBreak);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
toPlaceCached = result;
|
toPlaceCached = result;
|
||||||
return result;
|
return result;
|
||||||
|
@ -43,9 +43,9 @@ public class MovementAscend extends Movement {
|
|||||||
private int ticksWithoutPlacement = 0;
|
private int ticksWithoutPlacement = 0;
|
||||||
|
|
||||||
public MovementAscend(BlockPos src, BlockPos dest) {
|
public MovementAscend(BlockPos src, BlockPos dest) {
|
||||||
super(src, dest, new BlockPos[]{dest, src.up(2), dest.up()}, new BlockPos[]{dest.down()});
|
super(src, dest, new BlockPos[]{dest, src.up(2), dest.up()}, dest.down());
|
||||||
|
|
||||||
BlockPos placementLocation = positionsToPlace[0]; // dest.down()
|
BlockPos placementLocation = positionToPlace; // dest.down()
|
||||||
int i = 0;
|
int i = 0;
|
||||||
if (!placementLocation.north().equals(src))
|
if (!placementLocation.north().equals(src))
|
||||||
against[i++] = placementLocation.north();
|
against[i++] = placementLocation.north();
|
||||||
@ -72,12 +72,12 @@ public class MovementAscend extends Movement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calculateCost(CalculationContext context) {
|
protected double calculateCost(CalculationContext context) {
|
||||||
IBlockState toPlace = BlockStateInterface.get(positionsToPlace[0]);
|
IBlockState toPlace = BlockStateInterface.get(positionToPlace);
|
||||||
if (!MovementHelper.canWalkOn(positionsToPlace[0], toPlace)) {
|
if (!MovementHelper.canWalkOn(positionToPlace, toPlace)) {
|
||||||
if (!context.hasThrowaway()) {
|
if (!context.hasThrowaway()) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
if (!BlockStateInterface.isAir(toPlace) && !BlockStateInterface.isWater(toPlace.getBlock()) && !MovementHelper.isReplacable(positionsToPlace[0], toPlace)) {
|
if (!BlockStateInterface.isAir(toPlace) && !BlockStateInterface.isWater(toPlace.getBlock()) && !MovementHelper.isReplacable(positionToPlace, toPlace)) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
for (BlockPos against1 : against) {
|
for (BlockPos against1 : against) {
|
||||||
@ -135,7 +135,7 @@ public class MovementAscend extends Movement {
|
|||||||
return state.setStatus(MovementStatus.SUCCESS);
|
return state.setStatus(MovementStatus.SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!MovementHelper.canWalkOn(positionsToPlace[0])) {
|
if (!MovementHelper.canWalkOn(positionToPlace)) {
|
||||||
for (BlockPos anAgainst : against) {
|
for (BlockPos anAgainst : against) {
|
||||||
if (BlockStateInterface.get(anAgainst).isBlockNormalCube()) {
|
if (BlockStateInterface.get(anAgainst).isBlockNormalCube()) {
|
||||||
if (!MovementHelper.throwaway(true)) {//get ready to place a throwaway block
|
if (!MovementHelper.throwaway(true)) {//get ready to place a throwaway block
|
||||||
@ -148,7 +148,7 @@ public class MovementAscend extends Movement {
|
|||||||
EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit;
|
EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit;
|
||||||
|
|
||||||
LookBehaviorUtils.getSelectedBlock().ifPresent(selectedBlock -> {
|
LookBehaviorUtils.getSelectedBlock().ifPresent(selectedBlock -> {
|
||||||
if (Objects.equals(selectedBlock, anAgainst) && selectedBlock.offset(side).equals(positionsToPlace[0])) {
|
if (Objects.equals(selectedBlock, anAgainst) && selectedBlock.offset(side).equals(positionToPlace)) {
|
||||||
ticksWithoutPlacement++;
|
ticksWithoutPlacement++;
|
||||||
state.setInput(InputOverrideHandler.Input.SNEAK, true);
|
state.setInput(InputOverrideHandler.Input.SNEAK, true);
|
||||||
if (player().isSneaking()) {
|
if (player().isSneaking()) {
|
||||||
|
@ -33,7 +33,7 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
public class MovementDescend extends Movement {
|
public class MovementDescend extends Movement {
|
||||||
|
|
||||||
public MovementDescend(BlockPos start, BlockPos end) {
|
public MovementDescend(BlockPos start, BlockPos end) {
|
||||||
super(start, end, new BlockPos[]{end.up(2), end.up(), end}, new BlockPos[]{end.down()});
|
super(start, end, new BlockPos[]{end.up(2), end.up(), end}, end.down());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -44,7 +44,7 @@ public class MovementDescend extends Movement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calculateCost(CalculationContext context) {
|
protected double calculateCost(CalculationContext context) {
|
||||||
if (!MovementHelper.canWalkOn(positionsToPlace[0])) {
|
if (!MovementHelper.canWalkOn(positionToPlace)) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
Block tmp1 = BlockStateInterface.get(dest).getBlock();
|
Block tmp1 = BlockStateInterface.get(dest).getBlock();
|
||||||
|
@ -46,7 +46,7 @@ public class MovementDiagonal extends Movement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MovementDiagonal(BlockPos start, BlockPos end, BlockPos dir1, BlockPos dir2) {
|
public MovementDiagonal(BlockPos start, BlockPos end, BlockPos dir1, BlockPos dir2) {
|
||||||
super(start, end, new BlockPos[]{dir1, dir1.up(), dir2, dir2.up(), end, end.up()}, new BlockPos[]{end.down()});
|
super(start, end, new BlockPos[]{dir1, dir1.up(), dir2, dir2.up(), end, end.up()});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -77,8 +77,9 @@ public class MovementDiagonal extends Movement {
|
|||||||
if (!MovementHelper.canWalkThrough(positionsToBreak[4]) || !MovementHelper.canWalkThrough(positionsToBreak[5])) {
|
if (!MovementHelper.canWalkThrough(positionsToBreak[4]) || !MovementHelper.canWalkThrough(positionsToBreak[5])) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
IBlockState destWalkOn = BlockStateInterface.get(positionsToPlace[0]);
|
BlockPos destDown = dest.down();
|
||||||
if (!MovementHelper.canWalkOn(positionsToPlace[0], destWalkOn)) {
|
IBlockState destWalkOn = BlockStateInterface.get(destDown);
|
||||||
|
if (!MovementHelper.canWalkOn(destDown, destWalkOn)) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
double multiplier = WALK_ONE_BLOCK_COST;
|
double multiplier = WALK_ONE_BLOCK_COST;
|
||||||
|
@ -33,7 +33,7 @@ public class MovementDownward extends Movement {
|
|||||||
private int numTicks = 0;
|
private int numTicks = 0;
|
||||||
|
|
||||||
public MovementDownward(BlockPos start, BlockPos end) {
|
public MovementDownward(BlockPos start, BlockPos end) {
|
||||||
super(start, end, new BlockPos[]{end}, new BlockPos[0]);
|
super(start, end, new BlockPos[]{end});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -38,12 +38,12 @@ public class MovementFall extends Movement {
|
|||||||
private static final ItemStack STACK_BUCKET_EMPTY = new ItemStack(Items.BUCKET);
|
private static final ItemStack STACK_BUCKET_EMPTY = new ItemStack(Items.BUCKET);
|
||||||
|
|
||||||
public MovementFall(BlockPos src, BlockPos dest) {
|
public MovementFall(BlockPos src, BlockPos dest) {
|
||||||
super(src, dest, MovementFall.buildPositionsToBreak(src, dest), new BlockPos[]{dest.down()});
|
super(src, dest, MovementFall.buildPositionsToBreak(src, dest));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calculateCost(CalculationContext context) {
|
protected double calculateCost(CalculationContext context) {
|
||||||
if (!MovementHelper.canWalkOn(positionsToPlace[0])) {
|
if (!MovementHelper.canWalkOn(dest.down())) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
double placeBucketCost = 0.0;
|
double placeBucketCost = 0.0;
|
||||||
|
@ -34,7 +34,7 @@ public class MovementPillar extends Movement {
|
|||||||
private int numTicks = 0;
|
private int numTicks = 0;
|
||||||
|
|
||||||
public MovementPillar(BlockPos start, BlockPos end) {
|
public MovementPillar(BlockPos start, BlockPos end) {
|
||||||
super(start, end, new BlockPos[]{start.up(2)}, new BlockPos[]{start});
|
super(start, end, new BlockPos[]{start.up(2)}, start);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -130,7 +130,7 @@ public class MovementPillar extends Movement {
|
|||||||
boolean vine = fromDown.getBlock() instanceof BlockVine;
|
boolean vine = fromDown.getBlock() instanceof BlockVine;
|
||||||
if (!ladder) {
|
if (!ladder) {
|
||||||
state.setTarget(new MovementState.MovementTarget(Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F),
|
state.setTarget(new MovementState.MovementTarget(Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F),
|
||||||
Utils.getBlockPosCenter(positionsToPlace[0]),
|
Utils.getBlockPosCenter(positionToPlace),
|
||||||
new Rotation(mc.player.rotationYaw, mc.player.rotationPitch)), true));
|
new Rotation(mc.player.rotationYaw, mc.player.rotationPitch)), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ public class MovementTraverse extends Movement {
|
|||||||
private boolean wasTheBridgeBlockAlwaysThere = true;
|
private boolean wasTheBridgeBlockAlwaysThere = true;
|
||||||
|
|
||||||
public MovementTraverse(BlockPos from, BlockPos to) {
|
public MovementTraverse(BlockPos from, BlockPos to) {
|
||||||
super(from, to, new BlockPos[]{to.up(), to}, new BlockPos[]{to.down()});
|
super(from, to, new BlockPos[]{to.up(), to}, to.down());
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (!to.north().equals(from))
|
if (!to.north().equals(from))
|
||||||
@ -73,8 +73,8 @@ public class MovementTraverse extends Movement {
|
|||||||
protected double calculateCost(CalculationContext context) {
|
protected double calculateCost(CalculationContext context) {
|
||||||
IBlockState pb0 = BlockStateInterface.get(positionsToBreak[0]);
|
IBlockState pb0 = BlockStateInterface.get(positionsToBreak[0]);
|
||||||
IBlockState pb1 = BlockStateInterface.get(positionsToBreak[1]);
|
IBlockState pb1 = BlockStateInterface.get(positionsToBreak[1]);
|
||||||
IBlockState destOn = BlockStateInterface.get(positionsToPlace[0]);
|
IBlockState destOn = BlockStateInterface.get(positionToPlace);
|
||||||
if (MovementHelper.canWalkOn(positionsToPlace[0], destOn)) {//this is a walk, not a bridge
|
if (MovementHelper.canWalkOn(positionToPlace, destOn)) {//this is a walk, not a bridge
|
||||||
double WC = WALK_ONE_BLOCK_COST;
|
double WC = WALK_ONE_BLOCK_COST;
|
||||||
if (BlockStateInterface.isWater(pb0.getBlock()) || BlockStateInterface.isWater(pb1.getBlock())) {
|
if (BlockStateInterface.isWater(pb0.getBlock()) || BlockStateInterface.isWater(pb1.getBlock())) {
|
||||||
WC = WALK_ONE_IN_WATER_COST;
|
WC = WALK_ONE_IN_WATER_COST;
|
||||||
@ -105,7 +105,7 @@ public class MovementTraverse extends Movement {
|
|||||||
if (srcDown instanceof BlockLadder || srcDown instanceof BlockVine) {
|
if (srcDown instanceof BlockLadder || srcDown instanceof BlockVine) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
}
|
}
|
||||||
if (destOn.getBlock().equals(Blocks.AIR) || MovementHelper.isReplacable(positionsToPlace[0], destOn)) {
|
if (destOn.getBlock().equals(Blocks.AIR) || MovementHelper.isReplacable(positionToPlace, destOn)) {
|
||||||
boolean throughWater = BlockStateInterface.isWater(pb0.getBlock()) || BlockStateInterface.isWater(pb1.getBlock());
|
boolean throughWater = BlockStateInterface.isWater(pb0.getBlock()) || BlockStateInterface.isWater(pb1.getBlock());
|
||||||
if (BlockStateInterface.isWater(destOn.getBlock()) && throughWater) {
|
if (BlockStateInterface.isWater(destOn.getBlock()) && throughWater) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
@ -179,7 +179,7 @@ public class MovementTraverse extends Movement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isTheBridgeBlockThere = MovementHelper.canWalkOn(positionsToPlace[0]) || ladder;
|
boolean isTheBridgeBlockThere = MovementHelper.canWalkOn(positionToPlace) || ladder;
|
||||||
BlockPos whereAmI = playerFeet();
|
BlockPos whereAmI = playerFeet();
|
||||||
if (whereAmI.getY() != dest.getY() && !ladder) {
|
if (whereAmI.getY() != dest.getY() && !ladder) {
|
||||||
displayChatMessageRaw("Wrong Y coordinate");
|
displayChatMessageRaw("Wrong Y coordinate");
|
||||||
@ -220,7 +220,7 @@ public class MovementTraverse extends Movement {
|
|||||||
|
|
||||||
EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit;
|
EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit;
|
||||||
if (Objects.equals(LookBehaviorUtils.getSelectedBlock().orElse(null), against1) && Minecraft.getMinecraft().player.isSneaking()) {
|
if (Objects.equals(LookBehaviorUtils.getSelectedBlock().orElse(null), against1) && Minecraft.getMinecraft().player.isSneaking()) {
|
||||||
if (LookBehaviorUtils.getSelectedBlock().get().offset(side).equals(positionsToPlace[0])) {
|
if (LookBehaviorUtils.getSelectedBlock().get().offset(side).equals(positionToPlace)) {
|
||||||
return state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
|
return state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
|
||||||
} else {
|
} else {
|
||||||
// Out.gui("Wrong. " + side + " " + LookBehaviorUtils.getSelectedBlock().get().offset(side) + " " + positionsToPlace[0], Out.Mode.Debug);
|
// Out.gui("Wrong. " + side + " " + LookBehaviorUtils.getSelectedBlock().get().offset(side) + " " + positionsToPlace[0], Out.Mode.Debug);
|
||||||
|
Loading…
Reference in New Issue
Block a user