no movement places more than one thing...

This commit is contained in:
Leijurv 2018-08-28 13:41:44 -07:00
parent 53d477d99a
commit 557f2e48c3
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
8 changed files with 32 additions and 34 deletions

View File

@ -30,7 +30,6 @@ import net.minecraft.block.BlockLadder;
import net.minecraft.block.BlockVine;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import java.util.ArrayList;
import java.util.Arrays;
@ -53,23 +52,23 @@ public abstract class Movement implements Helper, MovementHelper {
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 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.dest = dest;
this.positionsToBreak = toBreak;
this.positionsToPlace = toPlace;
this.positionToPlace = toPlace;
}
protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak, BlockPos[] toPlace, Vec3d rotationTarget) {
this(src, dest, toBreak, toPlace);
protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak) {
this(src, dest, toBreak, null);
}
public double getCost(CalculationContext context) {
@ -310,10 +309,8 @@ public abstract class Movement implements Helper, MovementHelper {
return toPlaceCached;
}
List<BlockPos> result = new ArrayList<>();
for (BlockPos positionToBreak : positionsToPlace) {
if (!MovementHelper.canWalkOn(positionToBreak)) {
result.add(positionToBreak);
}
if (positionToPlace != null && !MovementHelper.canWalkOn(positionToPlace)) {
result.add(positionToPlace);
}
toPlaceCached = result;
return result;

View File

@ -43,9 +43,9 @@ public class MovementAscend extends Movement {
private int ticksWithoutPlacement = 0;
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;
if (!placementLocation.north().equals(src))
against[i++] = placementLocation.north();
@ -72,12 +72,12 @@ public class MovementAscend extends Movement {
@Override
protected double calculateCost(CalculationContext context) {
IBlockState toPlace = BlockStateInterface.get(positionsToPlace[0]);
if (!MovementHelper.canWalkOn(positionsToPlace[0], toPlace)) {
IBlockState toPlace = BlockStateInterface.get(positionToPlace);
if (!MovementHelper.canWalkOn(positionToPlace, toPlace)) {
if (!context.hasThrowaway()) {
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;
}
for (BlockPos against1 : against) {
@ -135,7 +135,7 @@ public class MovementAscend extends Movement {
return state.setStatus(MovementStatus.SUCCESS);
}
if (!MovementHelper.canWalkOn(positionsToPlace[0])) {
if (!MovementHelper.canWalkOn(positionToPlace)) {
for (BlockPos anAgainst : against) {
if (BlockStateInterface.get(anAgainst).isBlockNormalCube()) {
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;
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++;
state.setInput(InputOverrideHandler.Input.SNEAK, true);
if (player().isSneaking()) {

View File

@ -33,7 +33,7 @@ import net.minecraft.util.math.BlockPos;
public class MovementDescend extends Movement {
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
@ -44,7 +44,7 @@ public class MovementDescend extends Movement {
@Override
protected double calculateCost(CalculationContext context) {
if (!MovementHelper.canWalkOn(positionsToPlace[0])) {
if (!MovementHelper.canWalkOn(positionToPlace)) {
return COST_INF;
}
Block tmp1 = BlockStateInterface.get(dest).getBlock();

View File

@ -46,7 +46,7 @@ public class MovementDiagonal extends Movement {
}
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
@ -77,8 +77,9 @@ public class MovementDiagonal extends Movement {
if (!MovementHelper.canWalkThrough(positionsToBreak[4]) || !MovementHelper.canWalkThrough(positionsToBreak[5])) {
return COST_INF;
}
IBlockState destWalkOn = BlockStateInterface.get(positionsToPlace[0]);
if (!MovementHelper.canWalkOn(positionsToPlace[0], destWalkOn)) {
BlockPos destDown = dest.down();
IBlockState destWalkOn = BlockStateInterface.get(destDown);
if (!MovementHelper.canWalkOn(destDown, destWalkOn)) {
return COST_INF;
}
double multiplier = WALK_ONE_BLOCK_COST;

View File

@ -33,7 +33,7 @@ public class MovementDownward extends Movement {
private int numTicks = 0;
public MovementDownward(BlockPos start, BlockPos end) {
super(start, end, new BlockPos[]{end}, new BlockPos[0]);
super(start, end, new BlockPos[]{end});
}
@Override

View File

@ -38,12 +38,12 @@ public class MovementFall extends Movement {
private static final ItemStack STACK_BUCKET_EMPTY = new ItemStack(Items.BUCKET);
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
protected double calculateCost(CalculationContext context) {
if (!MovementHelper.canWalkOn(positionsToPlace[0])) {
if (!MovementHelper.canWalkOn(dest.down())) {
return COST_INF;
}
double placeBucketCost = 0.0;

View File

@ -34,7 +34,7 @@ public class MovementPillar extends Movement {
private int numTicks = 0;
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
@ -130,7 +130,7 @@ public class MovementPillar extends Movement {
boolean vine = fromDown.getBlock() instanceof BlockVine;
if (!ladder) {
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));
}

View File

@ -45,7 +45,7 @@ public class MovementTraverse extends Movement {
private boolean wasTheBridgeBlockAlwaysThere = true;
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;
if (!to.north().equals(from))
@ -73,8 +73,8 @@ public class MovementTraverse extends Movement {
protected double calculateCost(CalculationContext context) {
IBlockState pb0 = BlockStateInterface.get(positionsToBreak[0]);
IBlockState pb1 = BlockStateInterface.get(positionsToBreak[1]);
IBlockState destOn = BlockStateInterface.get(positionsToPlace[0]);
if (MovementHelper.canWalkOn(positionsToPlace[0], destOn)) {//this is a walk, not a bridge
IBlockState destOn = BlockStateInterface.get(positionToPlace);
if (MovementHelper.canWalkOn(positionToPlace, destOn)) {//this is a walk, not a bridge
double WC = WALK_ONE_BLOCK_COST;
if (BlockStateInterface.isWater(pb0.getBlock()) || BlockStateInterface.isWater(pb1.getBlock())) {
WC = WALK_ONE_IN_WATER_COST;
@ -105,7 +105,7 @@ public class MovementTraverse extends Movement {
if (srcDown instanceof BlockLadder || srcDown instanceof BlockVine) {
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());
if (BlockStateInterface.isWater(destOn.getBlock()) && throughWater) {
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();
if (whereAmI.getY() != dest.getY() && !ladder) {
displayChatMessageRaw("Wrong Y coordinate");
@ -220,7 +220,7 @@ public class MovementTraverse extends Movement {
EnumFacing side = Minecraft.getMinecraft().objectMouseOver.sideHit;
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);
} else {
// Out.gui("Wrong. " + side + " " + LookBehaviorUtils.getSelectedBlock().get().offset(side) + " " + positionsToPlace[0], Out.Mode.Debug);