use of net.minecraft.util.math.Vec3d in project minecolonies by Minecolonies.
the class PathNavigate method pathFollow.
@Override
protected void pathFollow() {
final int curNode = currentPath.getCurrentPathIndex();
final int curNodeNext = curNode + 1;
if (curNodeNext < currentPath.getCurrentPathLength()) {
final PathPointExtended pEx = (PathPointExtended) currentPath.getPathPointFromIndex(curNode);
final PathPointExtended pExNext = (PathPointExtended) currentPath.getPathPointFromIndex(curNodeNext);
// the entity reaches the bottom, otherwise they will try to head out early
if (pEx.isOnLadder() && pEx.getLadderFacing() == EnumFacing.DOWN && !pExNext.isOnLadder()) {
final Vec3d vec3 = getEntityPosition();
if ((vec3.yCoord - (double) pEx.yCoord) < 0.001) {
this.currentPath.setCurrentPathIndex(curNodeNext);
}
this.checkForStuck(vec3);
return;
}
}
super.pathFollow();
}
use of net.minecraft.util.math.Vec3d in project minecolonies by Minecolonies.
the class PathNavigate method onUpdateNavigation.
@Override
public void onUpdateNavigation() {
if (future != null) {
if (!future.isDone()) {
return;
}
try {
if (future.get() == null) {
future = null;
return;
}
setPath(future.get(), walkSpeed);
pathResult.setPathLength(getPath().getCurrentPathLength());
pathResult.setStatus(PathResult.Status.IN_PROGRESS_FOLLOWING);
final PathPoint p = getPath().getFinalPathPoint();
if (p != null && destination == null) {
destination = new BlockPos(p.xCoord, p.yCoord, p.zCoord);
// AbstractPathJob with no destination, did reach it's destination
pathResult.setPathReachesDestination(true);
}
} catch (@NotNull InterruptedException | ExecutionException e) {
Log.getLogger().catching(e);
}
future = null;
}
int oldIndex = this.noPath() ? 0 : this.getPath().getCurrentPathIndex();
super.onUpdateNavigation();
// Ladder Workaround
if (!this.noPath()) {
@NotNull final PathPointExtended pEx = (PathPointExtended) this.getPath().getPathPointFromIndex(this.getPath().getCurrentPathIndex());
if (pEx.isOnLadder()) {
final Vec3d vec3 = this.getPath().getPosition(this.entity);
if (vec3.squareDistanceTo(entity.posX, vec3.yCoord, entity.posZ) < 0.1) {
//This way he is less nervous and gets up the ladder
double newSpeed = 0.05;
switch(pEx.getLadderFacing()) {
// Any of these values is climbing, so adjust our direction of travel towards the ladder
case NORTH:
vec3.addVector(0, 0, 1);
break;
case SOUTH:
vec3.addVector(0, 0, -1);
break;
case WEST:
vec3.addVector(1, 0, 0);
break;
case EAST:
vec3.addVector(-1, 0, 0);
break;
// Any other value is going down, so lets not move at all
default:
newSpeed = 0;
break;
}
this.entity.getMoveHelper().setMoveTo(vec3.xCoord, vec3.yCoord, vec3.zCoord, newSpeed);
}
} else if (entity.isInWater()) {
// Prevent shortcuts when swimming
final int curIndex = this.getPath().getCurrentPathIndex();
if (curIndex > 0 && (curIndex + 1) < this.getPath().getCurrentPathLength() && this.getPath().getPathPointFromIndex(curIndex - 1).yCoord != pEx.yCoord) {
// Work around the initial 'spin back' when dropping into water
oldIndex = curIndex + 1;
}
this.getPath().setCurrentPathIndex(oldIndex);
Vec3d vec3d = this.getPath().getPosition(this.entity);
if (vec3d.squareDistanceTo(new Vec3d(entity.posX, vec3d.yCoord, entity.posZ)) < 0.1 && Math.abs(entity.posY - vec3d.yCoord) < 0.5) {
this.getPath().setCurrentPathIndex(this.getPath().getCurrentPathIndex() + 1);
if (this.noPath()) {
return;
}
vec3d = this.getPath().getPosition(this.entity);
}
this.entity.getMoveHelper().setMoveTo(vec3d.xCoord, vec3d.yCoord, vec3d.zCoord, walkSpeed);
} else {
if (BlockUtils.isPathBlock(world.getBlockState(entity.getPosition().down()).getBlock())) {
speed = ON_PATH_SPEED_MULTIPLIER * walkSpeed;
} else {
speed = walkSpeed;
}
}
}
if (pathResult != null && noPath()) {
pathResult.setStatus(PathResult.Status.COMPLETE);
pathResult = null;
}
}
use of net.minecraft.util.math.Vec3d in project minecolonies by Minecolonies.
the class EntityAICitizenWander method shouldExecute.
/**
* {@inheritDoc}
* Returns whether the EntityAIBase should begin execution.
* True when age less than 100, when a random (120) is chosen correctly, and when a citizen is nearby.
*/
@Override
public boolean shouldExecute() {
if (isToOld() || checkForRandom() || citizen.getDesiredActivity() == EntityCitizen.DesiredActivity.SLEEP) {
return false;
}
Vec3d vec3d = RandomPositionGenerator.getLandPos(citizen, 10, 7);
if (vec3d == null) {
return false;
}
vec3d = new Vec3d(vec3d.xCoord, getValidHeight(vec3d), vec3d.zCoord);
this.xPosition = vec3d.xCoord;
this.yPosition = vec3d.yCoord;
this.zPosition = vec3d.zCoord;
return true;
}
use of net.minecraft.util.math.Vec3d in project ConvenientAdditions by Necr0.
the class ItemClimbingClaws method onLivingUpdate.
@SubscribeEvent
public void onLivingUpdate(LivingEvent.LivingUpdateEvent event) {
if (event.getEntityLiving() instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) event.getEntityLiving();
for (SlotNotation slot : InventoryIterator.getIterable(player, EnumInventory.BAUBLES)) {
ItemStack stack = slot.getItem();
if (!stack.isEmpty() && stack.getItem() instanceof ItemClimbingClaws) {
ItemClimbingClaws item = (ItemClimbingClaws) stack.getItem();
if (item.wallClimbSpeed > 0) {
Vec3d ppos = new Vec3d(player.posX, player.posY, player.posZ);
Vec3d plook = player.getLookVec();
plook = plook.subtract(0, plook.yCoord, 0).normalize();
RayTraceResult r = player.world.rayTraceBlocks(ppos, ppos.add(plook.scale(.425)), false, true, false);
if (r != null && r.typeOfHit == RayTraceResult.Type.BLOCK) {
IBlockState state = player.world.getBlockState(r.getBlockPos());
if (state.isSideSolid(player.world, r.getBlockPos(), r.sideHit)) {
if (player.isSneaking()) {
if (player.moveForward > 0F) {
player.motionY = Math.max(item.wallClimbSpeed, player.motionY);
} else {
player.motionY = Math.max(0d, player.motionY);
}
player.fallDistance = 0;
} else {
player.motionY = Math.max(player.motionY, Math.min(player.motionY + .1d, -.15d));
if (player.motionY > -.666)
player.fallDistance = 0;
}
}
}
break;
}
}
}
for (SlotNotation slot : InventoryIterator.getIterable(player, EnumInventory.BAUBLES)) {
ItemStack stack = slot.getItem();
if (!stack.isEmpty() && stack.getItem() instanceof ItemClimbingClaws) {
ItemClimbingClaws item = (ItemClimbingClaws) stack.getItem();
if (item.stepHeightBoost > 0) {
if (player.isSneaking())
player.stepHeight = .6f;
else
player.stepHeight = .6f + item.stepHeightBoost;
break;
}
}
}
}
}
use of net.minecraft.util.math.Vec3d in project minecolonies by Minecolonies.
the class BuildingWareHouse method readFromNBT.
@Override
public void readFromNBT(@NotNull final NBTTagCompound compound) {
super.readFromNBT(compound);
registeredDeliverymen.clear();
final NBTTagList deliverymanTagList = compound.getTagList(TAG_DELIVERYMAN, Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < deliverymanTagList.tagCount(); i++) {
final BlockPos pos = NBTUtil.getPosFromTag(deliverymanTagList.getCompoundTagAt(i));
if (getColony() != null && getColony().getBuilding(pos) instanceof AbstractBuildingWorker && !registeredDeliverymen.contains(new Vec3d(pos))) {
registeredDeliverymen.add(new Vec3d(pos));
}
}
}
Aggregations