/** Gets the facing based on the way the entity is looking * @param entity the entity * @return the facing*/ public static EnumFacing getFacingFromEntity(EntityLivingBase entity) { int direction = MathHelper.floor_double(entity.rotationYaw * 4.0F / 360.0F + 0.5D) & 3; EnumFacing dir = EnumFacing.NORTH; if (direction == 0) return EnumFacing.NORTH; if (direction == 1) return EnumFacing.EAST; if (direction == 2) return EnumFacing.SOUTH; if (direction == 3) return EnumFacing.WEST; return dir; }
public static EnumFacing getDirectionFromYaw(EntityLivingBase entity) { int l = MathHelper.floor_double((entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; switch (l) { case 0: return EnumFacing.SOUTH; case 1: return EnumFacing.WEST; case 2: return EnumFacing.NORTH; case 3: return EnumFacing.EAST; default: return EnumFacing.NORTH; } } }
/** * Returns PathPoint for given coordinates */ @Override public PathPoint getPathPointToCoords(double x, double y, double target) { return openPoint( MathHelper.floor_double(x - (entity.width / 2.0)), MathHelper.floor_double(y + 0.5), MathHelper.floor_double(target - (entity.width / 2.0)) ); }
static public EnumFacing getPlaceFace( final EntityLivingBase placer ) { return EnumFacing.getHorizontal( MathHelper.floor_double( placer.rotationYaw * 4.0F / 360.0F + 0.5D ) & 3 ).getOpposite(); }
private boolean findLandingBlock() { // get current entity position landingPos = dragon.getPosition(); // add some variance int followRange = MathHelper.floor_double(getFollowRange()); int ox = followRange - random.nextInt(followRange) * 2; int oz = followRange - random.nextInt(followRange) * 2; landingPos = landingPos.add(ox, 0, oz); // get ground block landingPos = world.getHeight(landingPos); // make sure the block below is solid return world.getBlockState(landingPos.down()).getMaterial().isSolid(); }
/** Returns if the entity is covered in enough water * @param entity the entity * @return if it's considered as in water */ public static boolean isInWater(Entity entity) { double eyes = entity.posY + (double)entity.getEyeHeight() - 0.65; int i = MathHelper.floor_double(entity.posX); int j = MathHelper.floor_float(MathHelper.floor_double(eyes)); int k = MathHelper.floor_double(entity.posZ); BlockPos pos = new BlockPos(i, j, k); IBlockState state = entity.worldObj.getBlockState(pos); Block block = state.getBlock(); if (state.getMaterial() == Material.WATER) { double filled = 1.0f; //If it's not a liquid assume it's a solid block if (block instanceof IFluidBlock) { filled = ((IFluidBlock)block).getFilledPercentage(entity.worldObj, pos); } else if (block instanceof BlockLiquid) { filled = BlockLiquid.getLiquidHeightPercent(block.getMetaFromState(state)); } if (filled < 0) { filled *= -1; return eyes > pos.getY() + 1 + (1 - filled); } else { return eyes < pos.getY() + 1 + filled; } } else return false; }
public static boolean tryWash(EntityItem entityItem) { if (entityItem == null || entityItem.worldObj.isRemote || entityItem.getEntityItem() == null) return false; if (!isReadyToCook(entityItem.getEntityItem())) { BlockPos fluidBlockPos = new BlockPos(MathHelper.floor_double(entityItem.posX), MathHelper.floor_double(entityItem.posY), MathHelper.floor_double(entityItem.posZ)); FluidStack consumedFluid = FluidHelper.consumeExactFluid(entityItem.worldObj, fluidBlockPos, FluidRegistry.WATER, Fluid.BUCKET_VOLUME); if (consumedFluid != null) { EntityItem entityItemToWash = entityItem; ItemStack doughToWash = entityItemToWash.getEntityItem(); if (entityItemToWash.getEntityItem().stackSize > 1) { doughToWash = entityItem.getEntityItem().splitStack(1); entityItemToWash = new EntityItem(entityItemToWash.worldObj, entityItemToWash.posX, entityItemToWash.posY, entityItemToWash.posZ, doughToWash); entityItemToWash.setPickupDelay(10); entityItemToWash.worldObj.spawnEntityInWorld(entityItemToWash); } ItemStack washedItemStack = wash(doughToWash, 1); entityItemToWash.setEntityItemStack(washedItemStack); return true; } } return false; }
public static boolean tryFillWithRawEnderFromWorld(EntityItem entityItem) { if (entityItem == null || entityItem.worldObj.isRemote || entityItem.getEntityItem() == null) return false; if (!isFull(entityItem.getEntityItem())) { BlockPos fluidBlockPos = new BlockPos(MathHelper.floor_double(entityItem.posX), MathHelper.floor_double(entityItem.posY), MathHelper.floor_double(entityItem.posZ)); FluidStack consumedFluid = FluidHelper.consumeExactFluid(entityItem.worldObj, fluidBlockPos, Ender.fluidRawEnder, FluidHelper.FINITE_FLUID_MB_PER_META); if (consumedFluid != null) { EntityItem entityItemToFill = entityItem; ItemStack bubbleToFill = entityItemToFill.getEntityItem(); if (entityItemToFill.getEntityItem().stackSize > 1) { bubbleToFill = entityItem.getEntityItem().splitStack(1); entityItemToFill = new EntityItem(entityItemToFill.worldObj, entityItemToFill.posX, entityItemToFill.posY, entityItemToFill.posZ, bubbleToFill); entityItemToFill.setPickupDelay(10); entityItemToFill.worldObj.spawnEntityInWorld(entityItemToFill); } ItemStack filledItemStack = fill(bubbleToFill, 1); entityItemToFill.setEntityItemStack(filledItemStack); return true; } } return false; }
motionY -= 0.20000000298023224D; playSound(SoundEvents.ENTITY_BOBBER_SPLASH, 0.25F, 1.0F + (rand.nextFloat() - rand.nextFloat()) * 0.4F); float f6 = (float) MathHelper.floor_double(getEntityBoundingBox().minY); worldserver.spawnParticle(EnumParticleTypes.WATER_BUBBLE, posX, (double) (f6 + 1.0F), posZ, (int) (1.0F + width * 20.0F), (double) width, 0.0D, (double) width, 0.20000000298023224D); worldserver.spawnParticle(EnumParticleTypes.WATER_WAKE, posX, (double) (f6 + 1.0F), posZ, (int) (1.0F + width * 20.0F), (double) width, 0.0D, (double) width, 0.20000000298023224D); float f10 = MathHelper.cos(f5); double d13 = posX + (double) (f8 * (float) ticksCatchableDelay * 0.1F); double d15 = (double) ((float) MathHelper.floor_double(getEntityBoundingBox().minY) + 1.0F); double d16 = posZ + (double) (f10 * (float) ticksCatchableDelay * 0.1F); Block block1 = worldserver.getBlockState(new BlockPos((int) d13, (int) d15 - 1, (int) d16)).getBlock(); float f9 = MathHelper.randomFloatClamp(rand, 25.0F, 60.0F); double d12 = posX + (double) (MathHelper.sin(f7) * f9 * 0.1F); double d14 = (double) ((float) MathHelper.floor_double(getEntityBoundingBox().minY) + 1.0F); double d2 = posZ + (double) (MathHelper.cos(f7) * f9 * 0.1F); Block block = worldserver.getBlockState(new BlockPos((int) d12, (int) d14 - 1, (int) d2)).getBlock();
int i = MathHelper.floor_double((double) (playerIn.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; EnumFacing enumfacing = EnumFacing.getHorizontal(i); BlockPos blockpos = pos.offset(enumfacing);