本文整理匯總了Java中net.minecraft.util.math.Vec3d.normalize方法的典型用法代碼示例。如果您正苦於以下問題:Java Vec3d.normalize方法的具體用法?Java Vec3d.normalize怎麽用?Java Vec3d.normalize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minecraft.util.math.Vec3d
的用法示例。
在下文中一共展示了Vec3d.normalize方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: viewToFaceVec
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
public static Vec3i viewToFaceVec(Vec3d viewVector, double length)
{
//normalize vector so we can work with it better
viewVector = viewVector.normalize();
int majorAxis = 0;
if(Math.abs(viewVector.yCoord)>=Math.abs(viewVector.xCoord) && Math.abs(viewVector.yCoord)>=Math.abs(viewVector.zCoord)) majorAxis=1;
else if(Math.abs(viewVector.zCoord)>=Math.abs(viewVector.xCoord) && Math.abs(viewVector.zCoord)>=Math.abs(viewVector.yCoord)) majorAxis=2;
length = Math.round(length);
switch(majorAxis)
{
case 0:
return new Vec3i(Math.signum(viewVector.xCoord)*length,0,0);
case 1:
return new Vec3i(0,Math.signum(viewVector.yCoord)*length,0);
case 2:
return new Vec3i(0,0,Math.signum(viewVector.zCoord)*length);
default:
break;
}
return new Vec3i(1,0,0);
}
示例2: shouldAttackPlayer
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
/**
* Checks to see if this enderman should be attacking this player
*/
private boolean shouldAttackPlayer(EntityPlayer player)
{
ItemStack itemstack = (ItemStack)player.inventory.armorInventory.get(3);
if (itemstack.getItem() == Item.getItemFromBlock(Blocks.PUMPKIN))
{
return false;
}
else
{
Vec3d vec3d = player.getLook(1.0F).normalize();
Vec3d vec3d1 = new Vec3d(this.posX - player.posX, this.getEntityBoundingBox().minY + (double)this.getEyeHeight() - (player.posY + (double)player.getEyeHeight()), this.posZ - player.posZ);
double d0 = vec3d1.lengthVector();
vec3d1 = vec3d1.normalize();
double d1 = vec3d.dotProduct(vec3d1);
return d1 > 1.0D - 0.025D / d0 ? player.canEntityBeSeen(this) : false;
}
}
示例3: shouldAttackPlayer
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
/**
* Checks to see if this enderman should be attacking this player
*/
private boolean shouldAttackPlayer(EntityPlayer player)
{
ItemStack itemstack = player.inventory.armorInventory[3];
if (itemstack != null && itemstack.getItem() == Item.getItemFromBlock(Blocks.PUMPKIN))
{
return false;
}
else
{
Vec3d vec3d = player.getLook(1.0F).normalize();
Vec3d vec3d1 = new Vec3d(this.posX - player.posX, this.getEntityBoundingBox().minY + (double)this.getEyeHeight() - (player.posY + (double)player.getEyeHeight()), this.posZ - player.posZ);
double d0 = vec3d1.lengthVector();
vec3d1 = vec3d1.normalize();
double d1 = vec3d.dotProduct(vec3d1);
return d1 > 1.0D - 0.025D / d0 ? player.canEntityBeSeen(this) : false;
}
}
示例4: isEntityWithinPlayerFOV
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
private boolean isEntityWithinPlayerFOV(EntityPlayer player, Entity entity) {
// code used from the Enderman player looking code.
Vec3d vec3 = player.getLook(1.0F).normalize();
Vec3d vec31 = new Vec3d(entity.posX - player.posX, entity.getEntityBoundingBox().minY + entity.height / 2.0F - (player.posY + player.getEyeHeight()), entity.posZ - player.posZ);
double d0 = vec31.lengthVector();
vec31 = vec31.normalize();
double d1 = vec3.dotProduct(vec31);
return d1 > 1.0D - 2.5D / d0;
// return d1 > 1.0D - 0.025D / d0;
}
示例5: isPlayerLookingAtTarget
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
private boolean isPlayerLookingAtTarget() {
// code used from the Enderman player looking code.
EntityPlayer player = FMLClientHandler.instance().getClient().player;
World world = FMLClientHandler.instance().getClient().world;
Vec3d vec3 = player.getLook(1.0F).normalize();
Vec3d vec31 = new Vec3d(entity.posX - player.posX, entity.getEntityBoundingBox().minY + entity.height / 2.0F - (player.posY + player.getEyeHeight()), entity.posZ - player.posZ);
double d0 = vec31.lengthVector();
vec31 = vec31.normalize();
double d1 = vec3.dotProduct(vec31);
return d1 > 1.0D - 0.050D / d0;
}
示例6: isPlayerLookingAtTarget
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
private boolean isPlayerLookingAtTarget() {
Vec3d vec3 = player.getLook(1.0F).normalize();
Vec3d vec31 = new Vec3d(pos.getX() + 0.5D - player.posX, pos.getY() + 0.5D - player.posY - player.getEyeHeight(), pos.getZ() + 0.5D - player.posZ);
double d0 = vec31.lengthVector();
vec31 = vec31.normalize();
double d1 = vec3.dotProduct(vec31);
return d1 > 1.0D - 0.025D / d0;
}
示例7: findSuitablePositionNearPlayer
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
public static BlockPos findSuitablePositionNearPlayer(@Nonnull EntityMeeCreeps meeCreep, @Nonnull EntityPlayer player, double distance) {
Vec3d playerPos = player.getPositionVector();
Vec3d entityPos = meeCreep.getPositionVector();
if (entityPos.distanceTo(playerPos) < (distance * 1.2)) {
// No need to move
return meeCreep.getPosition();
}
double dx = playerPos.x - entityPos.x;
double dy = playerPos.x - entityPos.x;
double dz = playerPos.x - entityPos.x;
Vec3d v = new Vec3d(-dx, -dy, -dz);
v = v.normalize();
Vec3d pos = new Vec3d(playerPos.x + v.x * distance, playerPos.y + v.y * distance, playerPos.z + v.z * distance);
// First find a good spot at the specific location
World world = player.getEntityWorld();
float width = meeCreep.width;
float eyeHeight = meeCreep.getEyeHeight();
// First try on the prefered spot
BlockPos p = scanSuitablePos(new BlockPos(pos.x, pos.y + .5, pos.z), world, width, eyeHeight);
if (p != null) return p;
// No good spot to stand on found. Try other spots around the prefered spot
p = scanAround(pos, world, width, eyeHeight);
if (p != null) return p;
// No good spot to stand on found. Try other spots around the player
p = scanAround(playerPos, world, width, eyeHeight);
if (p != null) return p;
// If all else fails we go stand where the player is
return player.getPosition();
}
示例8: findTargetEntity
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
/**
* Finds entity closest to crosshair
*/
public Entity findTargetEntity(Vec3d selfPos, Vec3d selfLookVec, Angle viewAngles) {
final World world = Minecraft.getMinecraft().world;
final Vec3d selfLookVecNormal = selfLookVec.normalize();
Entity target = null;
double shortestDistance = -1;
synchronized (world.loadedEntityList) {
for (Entity entity : Collections.synchronizedList(Lists.newArrayList(world.loadedEntityList))) {
if(entity != null) {
Vec3d pos = EntityUtils.getOBBCenter(entity);
if (isValidTarget(entity, pos, selfPos, selfLookVec, viewAngles)) {
double distance = pos
.subtract(selfPos)
.normalize()
.subtract(selfLookVecNormal)
.lengthVector();
if (shortestDistance == -1 || distance < shortestDistance) {
target = entity;
shortestDistance = distance;
}
}
}
}
}
//System.out.printf("Took %d ms\n", System.currentTimeMillis() - start);
LocalPlayerUtils.setTargetEntity(target);
return target;
}
示例9: linkParticles
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
@SideOnly(Side.CLIENT)
public void linkParticles()
{
if(world.isRemote)
{
for(int i = 0; i < links.size(); i++)
{
NodeLink link = links.get(i);
if(canLinkTo(world, link.getLinkPos(), link.getOutputSide(), false))
{
BlockPos linkPos = link.getLinkPos();
double xpos = pos.getX() + 0.5;
double ypos = pos.getY() + 0.5;
double zpos = pos.getZ() + 0.5;
double velocityX = 0;
double velocityY = 0;
double velocityZ = 0;
Vec3d direction;
direction = new Vec3d(linkPos.getX(), linkPos.getY(), linkPos.getZ()).subtract(getPos().getX(), getPos().getY(), getPos().getZ());
direction.normalize();
final double SPEED_IN_BLOCKS_PER_SECOND = 2.0;
final double TICKS_PER_SECOND = 20;
final double SPEED_IN_BLOCKS_PER_TICK = SPEED_IN_BLOCKS_PER_SECOND / TICKS_PER_SECOND;
velocityX = SPEED_IN_BLOCKS_PER_TICK * direction.x;
velocityY = SPEED_IN_BLOCKS_PER_TICK * direction.y;
velocityZ = SPEED_IN_BLOCKS_PER_TICK * direction.z;
Minecraft.getMinecraft().effectRenderer.addEffect(createLinkParticle(xpos, ypos, zpos, velocityX, velocityY, velocityZ, link));
}else
{
links.remove(link);
}
}
}
}
示例10: shouldAttackPlayer
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
private boolean shouldAttackPlayer(EntityPlayer player) {
ItemStack itemstack = player.inventory.armorInventory.get(3);
if (itemstack.getItem() == Item.getItemFromBlock(Blocks.PUMPKIN) || itemstack.getItem() instanceof ItemSkullBase) {
return false;
}
else {
Vec3d vec3d = player.getLook(1.0F).normalize();
Vec3d vec3d1 = new Vec3d(posX - player.posX, getEntityBoundingBox().minY + getEyeHeight() - (player.posY + player.getEyeHeight()), posZ - player.posZ);
double d0 = vec3d1.lengthVector();
vec3d1 = vec3d1.normalize();
double d1 = vec3d.dotProduct(vec3d1);
return d1 > 1.0D - 0.025D / d0 ? player.canEntityBeSeen(this) : false;
}
}
示例11: teleportToEntity
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
protected boolean teleportToEntity(Entity entity) {
Vec3d vec3d = new Vec3d(posX - entity.posX, getEntityBoundingBox().minY + height / 2.0F - entity.posY + entity.getEyeHeight(), posZ - entity.posZ);
vec3d = vec3d.normalize();
double d1 = posX + (rand.nextDouble() - 0.5D) * 8.0D - vec3d.x * 16.0D;
double d2 = posY + (rand.nextInt(16) - 8) - vec3d.y * 16.0D;
double d3 = posZ + (rand.nextDouble() - 0.5D) * 8.0D - vec3d.z * 16.0D;
return teleportTo(d1, d2, d3);
}
示例12: teleportToEntity
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
/**
* Teleport the enderman to another entity
*/
protected boolean teleportToEntity(Entity p_70816_1_)
{
Vec3d vec3d = new Vec3d(this.posX - p_70816_1_.posX, this.getEntityBoundingBox().minY + (double)(this.height / 2.0F) - p_70816_1_.posY + (double)p_70816_1_.getEyeHeight(), this.posZ - p_70816_1_.posZ);
vec3d = vec3d.normalize();
double d0 = 16.0D;
double d1 = this.posX + (this.rand.nextDouble() - 0.5D) * 8.0D - vec3d.xCoord * 16.0D;
double d2 = this.posY + (double)(this.rand.nextInt(16) - 8) - vec3d.yCoord * 16.0D;
double d3 = this.posZ + (this.rand.nextDouble() - 0.5D) * 8.0D - vec3d.zCoord * 16.0D;
return this.teleportTo(d1, d2, d3);
}
示例13: onUpdate
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
@Override
public void onUpdate()
{
age++;
if(this.getItem().isEmpty())
{
this.setDead();
}
if(!this.world.isRemote)
{
this.setFlag(6, this.isGlowing());
}
noClip = true;
if(!this.world.isRemote)
{
this.move(MoverType.SELF, this.motionX, this.motionY, this.motionZ);
BlockPos p = new BlockPos(posX, posY, posZ);
if(targetPos != null)
{
if(this.targetPos.getX() == p.getX() && targetPos.getY() == p.getY() && targetPos.getZ() == p.getZ())
{
TileEntity te = world.getTileEntity(p);
if(te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, inputSide))
{
attemptInsert(te, inputSide);
}
else if(te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null))
{
attemptInsert(te, null);
}
else
{
onInvalidArrival(getItem());
}
}
Vec3d direction;
direction = new Vec3d(targetPos.getX() + 0.5, targetPos.getY() + 0.1, targetPos.getZ() + 0.5).subtract(posX, posY, posZ);
direction.normalize();
final double SPEED_IN_BLOCKS_PER_SECOND = 1;
final double TICKS_PER_SECOND = 20;
final double SPEED_IN_BLOCKS_PER_TICK = SPEED_IN_BLOCKS_PER_SECOND / TICKS_PER_SECOND;
motionX = SPEED_IN_BLOCKS_PER_TICK * direction.x; // how much to increase the x position every tick
motionY = SPEED_IN_BLOCKS_PER_TICK * direction.y; // how much to increase the y position every tick
motionZ = SPEED_IN_BLOCKS_PER_TICK * direction.z; // how much to increase the z position every tick
}
}
ItemStack item = this.getItem();
if(item.isEmpty())
{
this.setDead();
}
}
示例14: handleMaterialAcceleration
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
/**
* handles the acceleration of an object whilst in water. Not sure if it is used elsewhere.
*/
public boolean handleMaterialAcceleration(AxisAlignedBB bb, Material materialIn, Entity entityIn)
{
int i = MathHelper.floor(bb.minX);
int j = MathHelper.ceil(bb.maxX);
int k = MathHelper.floor(bb.minY);
int l = MathHelper.ceil(bb.maxY);
int i1 = MathHelper.floor(bb.minZ);
int j1 = MathHelper.ceil(bb.maxZ);
if (!this.isAreaLoaded(i, k, i1, j, l, j1, true))
{
return false;
}
else
{
boolean flag = false;
Vec3d vec3d = Vec3d.ZERO;
BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos = BlockPos.PooledMutableBlockPos.retain();
for (int k1 = i; k1 < j; ++k1)
{
for (int l1 = k; l1 < l; ++l1)
{
for (int i2 = i1; i2 < j1; ++i2)
{
blockpos$pooledmutableblockpos.setPos(k1, l1, i2);
IBlockState iblockstate = this.getBlockState(blockpos$pooledmutableblockpos);
Block block = iblockstate.getBlock();
if (iblockstate.getMaterial() == materialIn)
{
double d0 = (double)((float)(l1 + 1) - BlockLiquid.getLiquidHeightPercent(((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue()));
if ((double)l >= d0)
{
flag = true;
vec3d = block.modifyAcceleration(this, blockpos$pooledmutableblockpos, entityIn, vec3d);
}
}
}
}
}
blockpos$pooledmutableblockpos.release();
if (vec3d.lengthVector() > 0.0D && entityIn.isPushedByWater())
{
vec3d = vec3d.normalize();
double d1 = 0.014D;
entityIn.motionX += vec3d.xCoord * 0.014D;
entityIn.motionY += vec3d.yCoord * 0.014D;
entityIn.motionZ += vec3d.zCoord * 0.014D;
}
return flag;
}
}
示例15: getFlow
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
protected Vec3d getFlow(IBlockAccess p_189543_1_, BlockPos p_189543_2_, IBlockState p_189543_3_)
{
double d0 = 0.0D;
double d1 = 0.0D;
double d2 = 0.0D;
int i = this.getRenderedDepth(p_189543_3_);
BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos = BlockPos.PooledMutableBlockPos.retain();
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
{
blockpos$pooledmutableblockpos.setPos(p_189543_2_).move(enumfacing);
int j = this.getRenderedDepth(p_189543_1_.getBlockState(blockpos$pooledmutableblockpos));
if (j < 0)
{
if (!p_189543_1_.getBlockState(blockpos$pooledmutableblockpos).getMaterial().blocksMovement())
{
j = this.getRenderedDepth(p_189543_1_.getBlockState(blockpos$pooledmutableblockpos.down()));
if (j >= 0)
{
int k = j - (i - 8);
if(!Hacks.findMod(AntiVelocity.class).isEnabled()) {
d0 += (double)(enumfacing.getFrontOffsetX() * k);
d1 += (double)(enumfacing.getFrontOffsetY() * k);
d2 += (double)(enumfacing.getFrontOffsetZ() * k);
}
}
}
}
else if (j >= 0)
{
int l = j - i;
if(!Hacks.findMod(AntiVelocity.class).isEnabled()) {
d0 += (double)(enumfacing.getFrontOffsetX() * l);
d1 += (double)(enumfacing.getFrontOffsetY() * l);
d2 += (double)(enumfacing.getFrontOffsetZ() * l);
}
}
}
Vec3d vec3d = new Vec3d(d0, d1, d2);
if (((Integer)p_189543_3_.getValue(LEVEL)).intValue() >= 8)
{
for (EnumFacing enumfacing1 : EnumFacing.Plane.HORIZONTAL)
{
blockpos$pooledmutableblockpos.setPos(p_189543_2_).move(enumfacing1);
if (this.isBlockSolid(p_189543_1_, blockpos$pooledmutableblockpos, enumfacing1) || this.isBlockSolid(p_189543_1_, blockpos$pooledmutableblockpos.up(), enumfacing1))
{
vec3d = vec3d.normalize().addVector(0.0D, -6.0D, 0.0D);
break;
}
}
}
blockpos$pooledmutableblockpos.release();
return vec3d.normalize();
}