use of com.minecolonies.api.entity.MinecoloniesMinecart in project minecolonies by Minecolonies.
the class MinecoloniesAdvancedPathNavigate method canUpdatePath.
@Override
protected boolean canUpdatePath() {
// Auto dismount when trying to path.
if (ourEntity.vehicle != null) {
@NotNull final PathPointExtended pEx = (PathPointExtended) this.getPath().getNode(this.getPath().getNextNodeIndex());
if (pEx.isRailsExit()) {
final Entity entity = ourEntity.vehicle;
ourEntity.stopRiding();
entity.remove();
} else if (!pEx.isOnRails()) {
if (ourEntity.vehicle instanceof MinecoloniesMinecart) {
final Entity entity = ourEntity.vehicle;
ourEntity.stopRiding();
entity.remove();
} else {
ourEntity.stopRiding();
}
} else if ((Math.abs(pEx.x - mob.getX()) > 7 || Math.abs(pEx.z - mob.getZ()) > 7) && ourEntity.vehicle != null) {
final Entity entity = ourEntity.vehicle;
ourEntity.stopRiding();
entity.remove();
}
}
return true;
}
use of com.minecolonies.api.entity.MinecoloniesMinecart in project minecolonies by ldtteam.
the class MinecoloniesAdvancedPathNavigate method canUpdatePath.
@Override
protected boolean canUpdatePath() {
// Auto dismount when trying to path.
if (ourEntity.vehicle != null) {
@NotNull final PathPointExtended pEx = (PathPointExtended) this.getPath().getNode(this.getPath().getNextNodeIndex());
if (pEx.isRailsExit()) {
final Entity entity = ourEntity.vehicle;
ourEntity.stopRiding();
entity.remove();
} else if (!pEx.isOnRails()) {
if (ourEntity.vehicle instanceof MinecoloniesMinecart) {
final Entity entity = ourEntity.vehicle;
ourEntity.stopRiding();
entity.remove();
} else {
ourEntity.stopRiding();
}
} else if ((Math.abs(pEx.x - mob.getX()) > 7 || Math.abs(pEx.z - mob.getZ()) > 7) && ourEntity.vehicle != null) {
final Entity entity = ourEntity.vehicle;
ourEntity.stopRiding();
entity.remove();
}
}
return true;
}
use of com.minecolonies.api.entity.MinecoloniesMinecart in project minecolonies by ldtteam.
the class MinecoloniesAdvancedPathNavigate method handlePathOnRails.
/**
* Handle pathing on rails.
*
* @param pEx the current path point.
* @param pExNext the next path point.
* @return if go to next point.
*/
private boolean handlePathOnRails(final PathPointExtended pEx, final PathPointExtended pExNext) {
if (pEx.isRailsEntry()) {
final BlockPos blockPos = new BlockPos(pEx.x, pEx.y, pEx.z);
if (!spawnedPos.equals(blockPos)) {
final BlockState blockstate = level.getBlockState(blockPos);
RailShape railshape = blockstate.getBlock() instanceof AbstractRailBlock ? ((AbstractRailBlock) blockstate.getBlock()).getRailDirection(blockstate, level, blockPos, null) : RailShape.NORTH_SOUTH;
double yOffset = 0.0D;
if (railshape.isAscending()) {
yOffset = 0.5D;
}
if (mob.vehicle instanceof MinecoloniesMinecart) {
((MinecoloniesMinecart) mob.vehicle).setHurtDir(1);
} else {
MinecoloniesMinecart minecart = (MinecoloniesMinecart) ModEntities.MINECART.create(level);
final double x = pEx.x + 0.5D;
final double y = pEx.y + 0.625D + yOffset;
final double z = pEx.z + 0.5D;
minecart.setPos(x, y, z);
minecart.setDeltaMovement(Vector3d.ZERO);
minecart.xo = x;
minecart.yo = y;
minecart.zo = z;
level.addFreshEntity(minecart);
minecart.setHurtDir(1);
mob.startRiding(minecart, true);
}
spawnedPos = blockPos;
}
} else {
spawnedPos = BlockPos.ZERO;
}
if (mob.vehicle instanceof MinecoloniesMinecart && pExNext != null) {
final BlockPos blockPos = new BlockPos(pEx.x, pEx.y, pEx.z);
final BlockPos blockPosNext = new BlockPos(pExNext.x, pExNext.y, pExNext.z);
final Vector3d motion = mob.vehicle.getDeltaMovement();
double forward;
switch(BlockPosUtil.getXZFacing(blockPos, blockPosNext).getOpposite()) {
case EAST:
forward = Math.min(Math.max(motion.x() - 1 * 0.01D, -1), 0);
mob.vehicle.setDeltaMovement(motion.add(forward == -1 ? -1 : -0.01D, 0.0D, 0.0D));
break;
case WEST:
forward = Math.max(Math.min(motion.x() + 0.01D, 1), 0);
mob.vehicle.setDeltaMovement(motion.add(forward == 1 ? 1 : 0.01D, 0.0D, 0.0D));
break;
case NORTH:
forward = Math.max(Math.min(motion.z() + 0.01D, 1), 0);
mob.vehicle.setDeltaMovement(motion.add(0.0D, 0.0D, forward == 1 ? 1 : 0.01D));
break;
case SOUTH:
forward = Math.min(Math.max(motion.z() - 1 * 0.01D, -1), 0);
mob.vehicle.setDeltaMovement(motion.add(0.0D, 0.0D, forward == -1 ? -1 : -0.01D));
break;
case DOWN:
case UP:
// unreachable
break;
}
}
return false;
}
use of com.minecolonies.api.entity.MinecoloniesMinecart in project minecolonies by Minecolonies.
the class MinecoloniesAdvancedPathNavigate method handlePathOnRails.
/**
* Handle pathing on rails.
*
* @param pEx the current path point.
* @param pExNext the next path point.
* @return if go to next point.
*/
private boolean handlePathOnRails(final PathPointExtended pEx, final PathPointExtended pExNext) {
if (pEx.isRailsEntry()) {
final BlockPos blockPos = new BlockPos(pEx.x, pEx.y, pEx.z);
if (!spawnedPos.equals(blockPos)) {
final BlockState blockstate = level.getBlockState(blockPos);
RailShape railshape = blockstate.getBlock() instanceof AbstractRailBlock ? ((AbstractRailBlock) blockstate.getBlock()).getRailDirection(blockstate, level, blockPos, null) : RailShape.NORTH_SOUTH;
double yOffset = 0.0D;
if (railshape.isAscending()) {
yOffset = 0.5D;
}
if (mob.vehicle instanceof MinecoloniesMinecart) {
((MinecoloniesMinecart) mob.vehicle).setHurtDir(1);
} else {
MinecoloniesMinecart minecart = (MinecoloniesMinecart) ModEntities.MINECART.create(level);
final double x = pEx.x + 0.5D;
final double y = pEx.y + 0.625D + yOffset;
final double z = pEx.z + 0.5D;
minecart.setPos(x, y, z);
minecart.setDeltaMovement(Vector3d.ZERO);
minecart.xo = x;
minecart.yo = y;
minecart.zo = z;
level.addFreshEntity(minecart);
minecart.setHurtDir(1);
mob.startRiding(minecart, true);
}
spawnedPos = blockPos;
}
} else {
spawnedPos = BlockPos.ZERO;
}
if (mob.vehicle instanceof MinecoloniesMinecart && pExNext != null) {
final BlockPos blockPos = new BlockPos(pEx.x, pEx.y, pEx.z);
final BlockPos blockPosNext = new BlockPos(pExNext.x, pExNext.y, pExNext.z);
final Vector3d motion = mob.vehicle.getDeltaMovement();
double forward;
switch(BlockPosUtil.getXZFacing(blockPos, blockPosNext).getOpposite()) {
case EAST:
forward = Math.min(Math.max(motion.x() - 1 * 0.01D, -1), 0);
mob.vehicle.setDeltaMovement(motion.add(forward == -1 ? -1 : -0.01D, 0.0D, 0.0D));
break;
case WEST:
forward = Math.max(Math.min(motion.x() + 0.01D, 1), 0);
mob.vehicle.setDeltaMovement(motion.add(forward == 1 ? 1 : 0.01D, 0.0D, 0.0D));
break;
case NORTH:
forward = Math.max(Math.min(motion.z() + 0.01D, 1), 0);
mob.vehicle.setDeltaMovement(motion.add(0.0D, 0.0D, forward == 1 ? 1 : 0.01D));
break;
case SOUTH:
forward = Math.min(Math.max(motion.z() - 1 * 0.01D, -1), 0);
mob.vehicle.setDeltaMovement(motion.add(0.0D, 0.0D, forward == -1 ? -1 : -0.01D));
break;
case DOWN:
case UP:
// unreachable
break;
}
}
return false;
}
Aggregations