Java Code Examples for net.minecraft.entity.Entity#getEntityBoundingBox()

The following examples show how to use net.minecraft.entity.Entity#getEntityBoundingBox() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RotationUtils.java    From LiquidBounce with GNU General Public License v3.0 8 votes vote down vote up
/**
 * Face target with bow
 *
 * @param target your enemy
 * @param silent client side rotations
 * @param predict predict new enemy position
 * @param predictSize predict size of predict
 */
public static void faceBow(final Entity target, final boolean silent, final boolean predict, final float predictSize) {
    final EntityPlayerSP player = mc.thePlayer;

    final double posX = target.posX + (predict ? (target.posX - target.prevPosX) * predictSize : 0) - (player.posX + (predict ? (player.posX - player.prevPosX) : 0));
    final double posY = target.getEntityBoundingBox().minY + (predict ? (target.getEntityBoundingBox().minY - target.prevPosY) * predictSize : 0) + target.getEyeHeight() - 0.15 - (player.getEntityBoundingBox().minY + (predict ? (player.posY - player.prevPosY) : 0)) - player.getEyeHeight();
    final double posZ = target.posZ + (predict ? (target.posZ - target.prevPosZ) * predictSize : 0) - (player.posZ + (predict ? (player.posZ - player.prevPosZ) : 0));
    final double posSqrt = Math.sqrt(posX * posX + posZ * posZ);

    float velocity = LiquidBounce.moduleManager.getModule(FastBow.class).getState() ? 1F : player.getItemInUseDuration() / 20F;
    velocity = (velocity * velocity + velocity * 2) / 3;

    if(velocity > 1) velocity = 1;

    final Rotation rotation = new Rotation(
            (float) (Math.atan2(posZ, posX) * 180 / Math.PI) - 90,
            (float) -Math.toDegrees(Math.atan((velocity * velocity - Math.sqrt(velocity * velocity * velocity * velocity - 0.006F * (0.006F * (posSqrt * posSqrt) + 2 * posY * (velocity * velocity)))) / (0.006F * posSqrt)))
    );

    if(silent)
        setTargetRotation(rotation);
    else
        limitAngleChange(new Rotation(player.rotationYaw, player.rotationPitch), rotation,10 +
                new Random().nextInt(6)).toPlayer(mc.thePlayer);
}
 
Example 2
Source File: PullDownModule.java    From seppuku with GNU General Public License v3.0 6 votes vote down vote up
private boolean hullCollidesWithBlock(final Entity entity,
        final Vec3d nextPosition) {
    final AxisAlignedBB boundingBox = entity.getEntityBoundingBox();
    final Vec3d[] boundingBoxCorners = {
            new Vec3d(boundingBox.minX, boundingBox.minY, boundingBox.minZ),
            new Vec3d(boundingBox.minX, boundingBox.minY, boundingBox.maxZ),
            new Vec3d(boundingBox.maxX, boundingBox.minY, boundingBox.minZ),
            new Vec3d(boundingBox.maxX, boundingBox.minY, boundingBox.maxZ)
    };

    final Vec3d entityPosition = entity.getPositionVector();
    for (final Vec3d entityBoxCorner : boundingBoxCorners) {
        final Vec3d nextBoxCorner = entityBoxCorner.subtract(entityPosition).add(nextPosition);
        final RayTraceResult rayTraceResult = entity.world.rayTraceBlocks(entityBoxCorner,
                nextBoxCorner, true, false, true);
        if (rayTraceResult == null)
            continue;

        if (rayTraceResult.typeOfHit == RayTraceResult.Type.BLOCK)
            return true;
    }

    return false;
}
 
Example 3
Source File: PotionPhase.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Nullable
public BlockPos getBottomBlock(@Nonnull Entity entity) {
	boolean isSpectator = (entity instanceof EntityPlayer && ((EntityPlayer) entity).isSpectator());
	if (isSpectator) return null;
	AxisAlignedBB bb = entity.getEntityBoundingBox();
	int mX = MathHelper.floor(bb.minX);
	int mY = MathHelper.floor(bb.minY);
	int mZ = MathHelper.floor(bb.minZ);
	for (int y2 = mY; y2 < bb.maxY; y2++) {
		for (int x2 = mX; x2 < bb.maxX; x2++) {
			for (int z2 = mZ; z2 < bb.maxZ; z2++) {
				BlockPos tmp = new BlockPos(x2, y2, z2);
				if (!entity.world.isAirBlock(tmp)) return tmp;
			}
		}
	}

	return null;
}
 
Example 4
Source File: SwitchHeldItemAndRotationPacket.java    From Cyberware with MIT License 6 votes vote down vote up
public static void faceEntity(Entity player, Entity entityIn)
{
	double d0 = entityIn.posX - player.posX;
	double d2 = entityIn.posZ - player.posZ;
	double d1;

	if (entityIn instanceof EntityLivingBase)
	{
		EntityLivingBase entitylivingbase = (EntityLivingBase)entityIn;
		d1 = entitylivingbase.posY + (double)entitylivingbase.getEyeHeight() - (player.posY + (double)player.getEyeHeight());
	}
	else
	{
		d1 = (entityIn.getEntityBoundingBox().minY + entityIn.getEntityBoundingBox().maxY) / 2.0D - (player.posY + (double)player.getEyeHeight());
	}

	double d3 = (double)MathHelper.sqrt_double(d0 * d0 + d2 * d2);
	float f = (float)(MathHelper.atan2(d2, d0) * (180D / Math.PI)) - 90.0F;
	float f1 = (float)(-(MathHelper.atan2(d1, d3) * (180D / Math.PI)));
	player.rotationPitch = f1;
	player.rotationYaw = f;
}
 
Example 5
Source File: RenderUtils.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
public static void drawEntityBox(final Entity entity, final Color color, final boolean outline) {
    final RenderManager renderManager = mc.getRenderManager();
    final Timer timer = mc.timer;

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    enableGlCap(GL_BLEND);
    disableGlCap(GL_TEXTURE_2D, GL_DEPTH_TEST);
    glDepthMask(false);

    final double x = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * timer.renderPartialTicks
            - renderManager.renderPosX;
    final double y = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * timer.renderPartialTicks
            - renderManager.renderPosY;
    final double z = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * timer.renderPartialTicks
            - renderManager.renderPosZ;

    final AxisAlignedBB entityBox = entity.getEntityBoundingBox();
    final AxisAlignedBB axisAlignedBB = new AxisAlignedBB(
            entityBox.minX - entity.posX + x - 0.05D,
            entityBox.minY - entity.posY + y,
            entityBox.minZ - entity.posZ + z - 0.05D,
            entityBox.maxX - entity.posX + x + 0.05D,
            entityBox.maxY - entity.posY + y + 0.15D,
            entityBox.maxZ - entity.posZ + z + 0.05D
    );

    if (outline) {
        glLineWidth(1F);
        enableGlCap(GL_LINE_SMOOTH);
        glColor(color.getRed(), color.getGreen(), color.getBlue(), 95);
        drawSelectionBoundingBox(axisAlignedBB);
    }

    glColor(color.getRed(), color.getGreen(), color.getBlue(), outline ? 26 : 35);
    drawFilledBox(axisAlignedBB);
    GlStateManager.resetColor();
    glDepthMask(true);
    resetCaps();
}
 
Example 6
Source File: ParticleHandlerUtil.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void addBlockRunningEffects(World worldObj, Entity entity, TextureAtlasSprite atlasSprite, int spriteColor) {
    Random rand = new Random();
    double posX = entity.posX + (rand.nextFloat() - 0.5) * entity.width;
    double posY = entity.getEntityBoundingBox().minY + 0.1;
    double posZ = entity.posZ + (rand.nextFloat() - 0.5) * entity.width;
    ParticleManager manager = Minecraft.getMinecraft().effectRenderer;

    float red = (spriteColor >> 16 & 255) / 255.0F;
    float green = (spriteColor >> 8 & 255) / 255.0F;
    float blue = (spriteColor & 255) / 255.0F;

    DigIconParticle digIconParticle = new DigIconParticle(worldObj, posX, posY, posZ, -entity.motionX * 4.0, 1.5, -entity.motionZ * 4.0, atlasSprite);
    digIconParticle.setRBGColorF(red, green, blue);
    manager.addEffect(digIconParticle);
}
 
Example 7
Source File: EntityUtils.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static BlockPos getPositionOfBlockEntityIsCollidingWith(World world, Entity entity, Block block)
{
    AxisAlignedBB bb = entity.getEntityBoundingBox();
    int minX = MathHelper.floor(bb.minX);
    int minY = MathHelper.floor(bb.minY);
    int minZ = MathHelper.floor(bb.minZ);
    int maxX = MathHelper.floor(bb.maxX);
    int maxY = MathHelper.floor(bb.maxY);
    int maxZ = MathHelper.floor(bb.maxZ);

    for (int y2 = minY; y2 <= maxY; y2++)
    {
        for (int x2 = minX; x2 <= maxX; x2++)
        {
            for (int z2 = minZ; z2 <= maxZ; z2++)
            {
                BlockPos pos = new BlockPos(x2, y2, z2);

                if (world.getBlockState(pos).getBlock() == block)
                {
                    return pos;
                }
            }
        }
    }

    return null;
}
 
Example 8
Source File: EntityUtils.java    From ForgeHax with MIT License 4 votes vote down vote up
/**
 * Find the center of the entities hit box
 */
public static Vec3d getOBBCenter(Entity entity) {
  AxisAlignedBB obb = entity.getEntityBoundingBox();
  return new Vec3d(
      (obb.maxX + obb.minX) / 2.D, (obb.maxY + obb.minY) / 2.D, (obb.maxZ + obb.minZ) / 2.D);
}
 
Example 9
Source File: RayTrace.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Credits to Masa on discord for providing the base of the code. I heavily modified it.
 * This raytracer will precisely trace entities and blocks (including misses) without snapping to any grid.
 *
 * @return The RaytraceResult.
 */
@Nonnull
public RayTraceResult trace() {
	Vec3d lookVec = origin.add(slope.normalize().scale(range));

	RayTraceResult entityResult = null;
	RayTraceResult blockResult = null;// world.rayTraceBlocks(origin, lookVec, false, ignoreBlocksWithoutBoundingBoxes, returnLastUncollidableBlock);


	if (!skipEntities) {
		Entity targetEntity = null;
		RayTraceResult entityTrace = null;
		AxisAlignedBB bb = new AxisAlignedBB(origin.x, origin.y, origin.z, lookVec.x, lookVec.y, lookVec.z);
		List<Entity> list = world.getEntitiesWithinAABB(Entity.class, bb.grow(range, range, range), input -> {
			if (predicateEntity == null) return true;
			else return predicateEntity.test(input);
		});
		double closest = 0.0D;

		for (Entity entity : list) {
			if (entity == null) continue;

			bb = entity.getEntityBoundingBox();
			RayTraceResult traceTmp = bb.calculateIntercept(lookVec, origin);

			if (traceTmp != null) {
				double tmp = origin.distanceTo(traceTmp.hitVec);

				if (tmp < closest || closest == 0.0D) {
					targetEntity = entity;
					entityTrace = traceTmp;
					closest = tmp;
				}
			}
		}

		if (targetEntity != null) entityResult = new RayTraceResult(targetEntity, entityTrace.hitVec);
	}

	if (!skipBlocks) blockResult = traceBlock(origin, lookVec);

	if (blockResult == null)
		blockResult = new RayTraceResult(
				RayTraceResult.Type.BLOCK,
				lookVec,
				EnumFacing.getFacingFromVector((float) lookVec.x, (float) lookVec.y, (float) lookVec.z),
				new BlockPos(lookVec));

	return (entityResult != null && origin.distanceTo(entityResult.hitVec) < origin.distanceTo(blockResult.hitVec)) ? entityResult : blockResult;
}
 
Example 10
Source File: EntityCart.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a boundingBox used to collide the entity with other entities and blocks. This enables the entity to be
 * pushable on contact, like boats or minecarts.
 */
@Override
public AxisAlignedBB getCollisionBox(Entity entityIn)
{
	return entityIn.getEntityBoundingBox();
}
 
Example 11
Source File: RenderUtils.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void renderEntityDebugBoundingBox(Entity entityIn, float partialTicks, boolean renderLook, boolean renderEyeHeight)
{
    Entity renderViewEntity = Minecraft.getMinecraft().getRenderViewEntity();
    double x = entityIn.lastTickPosX + (entityIn.posX - entityIn.lastTickPosX) * (double)partialTicks;
    double y = entityIn.lastTickPosY + (entityIn.posY - entityIn.lastTickPosY) * (double)partialTicks;
    double z = entityIn.lastTickPosZ + (entityIn.posZ - entityIn.lastTickPosZ) * (double)partialTicks;
    x -= renderViewEntity.lastTickPosX + (renderViewEntity.posX - renderViewEntity.lastTickPosX) * (double)partialTicks;
    y -= renderViewEntity.lastTickPosY + (renderViewEntity.posY - renderViewEntity.lastTickPosY) * (double)partialTicks;
    z -= renderViewEntity.lastTickPosZ + (renderViewEntity.posZ - renderViewEntity.lastTickPosZ) * (double)partialTicks;

    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    GlStateManager.depthMask(false);
    GlStateManager.disableTexture2D();
    GlStateManager.disableLighting();
    GlStateManager.disableCull();
    GlStateManager.disableBlend();
    GlStateManager.glLineWidth(1.0F);

    double entityRadius = entityIn.width / 2.0D;
    AxisAlignedBB bb = entityIn.getEntityBoundingBox();

    RenderGlobal.drawBoundingBox(bb.minX - entityIn.posX + x,
                                 bb.minY - entityIn.posY + y,
                                 bb.minZ - entityIn.posZ + z,
                                 bb.maxX - entityIn.posX + x,
                                 bb.maxY - entityIn.posY + y,
                                 bb.maxZ - entityIn.posZ + z,
                                 1.0F, 1.0F, 1.0F, 1.0F);

    if (renderEyeHeight && entityIn instanceof EntityLivingBase)
    {
        RenderGlobal.drawBoundingBox(x - entityRadius,
                                     y + entityIn.getEyeHeight() - 0.01D,
                                     z - entityRadius,
                                     x + entityRadius,
                                     y + entityIn.getEyeHeight() + 0.01D,
                                     z + entityRadius, 1.0F, 0.0F, 0.0F, 1.0F);
    }

    if (renderLook)
    {
        Tessellator tessellator = Tessellator.getInstance();
        BufferBuilder vertexbuffer = tessellator.getBuffer();
        Vec3d look = entityIn.getLook(partialTicks);
        vertexbuffer.begin(3, DefaultVertexFormats.POSITION_COLOR);
        vertexbuffer.pos(x, y + entityIn.getEyeHeight(), z).color(0, 0, 255, 255).endVertex();
        vertexbuffer.pos(x + look.x * 2.0D, y + entityIn.getEyeHeight() + look.y * 2.0D, z + look.z * 2.0D).color(0, 0, 255, 255).endVertex();
        tessellator.draw();
    }

    GlStateManager.enableTexture2D();
    GlStateManager.enableLighting();
    GlStateManager.enableCull();
    GlStateManager.disableBlend();
    GlStateManager.depthMask(true);
}
 
Example 12
Source File: TeleportEntity.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static boolean teleportEntityRandomly(Entity entity, double maxDist)
{
    World world = entity.getEntityWorld();

    if (canTeleportEntity(entity) == false || world.isRemote)
    {
        return false;
    }

    double deltaYaw = 0.0d;
    double deltaPitch = 0.0d;
    double x = 0.0d;
    double y = 0.0d;
    double z = 0.0d;
    maxDist = maxDist - (world.rand.nextFloat() * maxDist / 2.0d);

    // Try to find a free spot (non-colliding with blocks)
    for (int i = 0; i < 20; i++)
    {
        deltaYaw = world.rand.nextFloat() * 2d * Math.PI;
        //deltaPitch = ((90.0d - (Math.random() * 180.0d)) / 180.0d) * Math.PI; // free range on the y-direction
        deltaPitch = world.rand.nextFloat() * 0.5d * Math.PI; // only from the same level upwards
        x = entity.posX;
        y = entity.posY;
        z = entity.posZ;
        x += Math.cos(deltaPitch) * Math.cos(deltaYaw) * maxDist;
        z += Math.cos(deltaPitch) * Math.sin(deltaYaw) * maxDist;
        y += Math.sin(deltaPitch) * maxDist;

        if (entity.getEntityBoundingBox() != null && world.getCollisionBoxes(entity, entity.getEntityBoundingBox()).isEmpty())
        {
            // Sound and particles on the original location
            addTeleportSoundsAndParticles(world, entity.posX, entity.posY, entity.posZ);

            entity.setLocationAndAngles(x, y, z, entity.rotationYaw, entity.rotationPitch);

            // Sound and particles on the new, destination location.
            addTeleportSoundsAndParticles(world, x, y, z);
            return true;
        }
    }

    return false;
}