本文整理汇总了Java中net.minecraft.util.math.MathHelper.absMax方法的典型用法代码示例。如果您正苦于以下问题:Java MathHelper.absMax方法的具体用法?Java MathHelper.absMax怎么用?Java MathHelper.absMax使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.util.math.MathHelper
的用法示例。
在下文中一共展示了MathHelper.absMax方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: canSee
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
* checking if two Vec3d can see each other (there are not any block between)
*
* the started pos can be likely to:
* for block: new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5)
* for entity: entity.getPositionVector().addVector(0, entity.getEyeHeight(), 0);
*
* @return if can see each other
*/
public static boolean canSee(World world, Vec3d traceStart, Vec3d traceEnd) {
Vec3d vecDelta = new Vec3d(
traceEnd.x - traceStart.x,
traceEnd.y - traceStart.y,
traceEnd.z - traceStart.z
);
// Normalize vector to the largest delta axis
double vecDeltaLength = MathHelper.absMax(vecDelta.x, MathHelper.absMax(vecDelta.y, vecDelta.z));
vecDelta = vecDelta.scale(1 / vecDeltaLength);
// Limit how many non solid block a turret can see through
for (int i = 0; i < 10; i++) {
// Offset start position toward the target to prevent self collision
traceStart = traceStart.add(vecDelta);
RayTraceResult traced = world.rayTraceBlocks(traceStart.add(Vec3d.ZERO), traceEnd.add(Vec3d.ZERO));
if (traced != null && traced.typeOfHit == RayTraceResult.Type.BLOCK) {
IBlockState hitBlock = world.getBlockState(traced.getBlockPos());
// If non solid block is in the way then proceed to continue
// tracing
if (hitBlock != null && !hitBlock.getMaterial().isSolid() && MathHelper.absMax(
MathHelper.absMax(traceStart.x - traceEnd.x, traceStart.y - traceEnd.y),
traceStart.z - traceEnd.z) > 1) {
// Start at new position and continue
traceStart = traced.hitVec;
continue;
}
}
return traced != null;
}
// If all above failed, the target cannot be seen
return false;
}
示例2: applyEntityCollision
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
/**
* Applies a velocity to the entities, to push them away from eachother.
*/
public void applyEntityCollision(Entity entityIn)
{
if (!this.isRidingSameEntity(entityIn))
{
if (!entityIn.noClip && !this.noClip)
{
double d0 = entityIn.posX - this.posX;
double d1 = entityIn.posZ - this.posZ;
double d2 = MathHelper.absMax(d0, d1);
if (d2 >= 0.009999999776482582D)
{
d2 = (double)MathHelper.sqrt(d2);
d0 = d0 / d2;
d1 = d1 / d2;
double d3 = 1.0D / d2;
if (d3 > 1.0D)
{
d3 = 1.0D;
}
d0 = d0 * d3;
d1 = d1 * d3;
d0 = d0 * 0.05000000074505806D;
d1 = d1 * 0.05000000074505806D;
d0 = d0 * (double)(1.0F - this.entityCollisionReduction);
d1 = d1 * (double)(1.0F - this.entityCollisionReduction);
if (!this.isBeingRidden())
{
if(!Hacks.findMod(AntiVelocity.class).isEnabled())
this.addVelocity(-d0, 0.0D, -d1);
}
if (!entityIn.isBeingRidden())
{
if(!Hacks.findMod(AntiVelocity.class).isEnabled())
entityIn.addVelocity(d0, 0.0D, d1);
}
}
}
}
}
示例3: absMax
import net.minecraft.util.math.MathHelper; //导入方法依赖的package包/类
public static double absMax(double p_absMax_0_, double p_absMax_2_)
{
return MathHelper.absMax(p_absMax_0_, p_absMax_2_);
}