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

The following examples show how to use net.minecraft.entity.Entity#getPositionVector() . 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: NPCUtils.java    From SkyblockAddons with MIT License 6 votes vote down vote up
/**
 * Checks if a given entity is near any NPC.
 *
 * @param entity the entity to check
 * @return {@code true} if the entity is near an NPC, {@code false} otherwise
 */
public static boolean isNearAnyNPC(Entity entity) {
    SkyblockAddons main = SkyblockAddons.getInstance();
    Location currentLocation = main.getUtils().getLocation();

    for (NPC npc:
         NPC_LIST) {
        if (npc.hasLocation(currentLocation)) {
            Vec3 NPCVector = new Vec3(npc.getX(), npc.getY(), npc.getZ());
            Vec3 entityVector = entity.getPositionVector();

            if (NPCVector.distanceTo(entityVector) <= HIDE_RADIUS) {
                return true;
            }
        }
    }
    return false;
}
 
Example 2
Source File: NPCUtils.java    From SkyblockAddons with MIT License 6 votes vote down vote up
/**
 * Checks if a given entity is near any NPC with the given {@link Tag}.
 *
 * @param entity the entity to check
 * @return {@code true} if the entity is near an NPC, {@code false} otherwise
 */
public static boolean isNearAnyNPCWithTag(Entity entity, Tag tag) {
    SkyblockAddons main = SkyblockAddons.getInstance();
    Location currentLocation = main.getUtils().getLocation();

    for (NPC npc:
            NPC_LIST) {
        if (npc.hasLocation(currentLocation)) {
            Vec3 NPCVector = new Vec3(npc.getX(), npc.getY(), npc.getZ());
            Vec3 entityVector = entity.getPositionVector();

            if (NPCVector.distanceTo(entityVector) <= HIDE_RADIUS) {
                if (npc.hasTag(tag))
                    return true;
            }
        }
    }
    return false;
}
 
Example 3
Source File: NPCUtils.java    From SkyblockAddons with MIT License 6 votes vote down vote up
/**
 * Checks if a given entity is near the NPC with the given name.
 *
 * @param entity the entity to check
 * @param NPCName the NPC's name in {@link NPC}
 * @return {@code true} if the entity is near the matching NPC,{@code false} if the entity is not near the matching NPC or no matching NPC is found
 */
public static boolean isNearNPC(Entity entity, String NPCName) {
    SkyblockAddons main = SkyblockAddons.getInstance();
    Location currentLocation = main.getUtils().getLocation();

    for (NPC npc:
         NPC_LIST) {
        if (npc.name().equals(NPCName) && npc.hasLocation(currentLocation)) {
            Vec3 NPCVector = new Vec3(npc.getX(), npc.getY(), npc.getZ());
            Vec3 entityVector = entity.getPositionVector();

            if (NPCVector.distanceTo(entityVector) <= HIDE_RADIUS) {
                return true;
            }
        }
    }
    return false;
}
 
Example 4
Source File: NPCUtils.java    From SkyblockAddons with MIT License 6 votes vote down vote up
/**
 * Checks if a given entity is near any NPC with the given {@link Tag}s.
 *
 * @param entity the entity to check
 * @return {@code true} if the entity is near an NPC with the given tags, {@code false} otherwise
 */
public static boolean isNearAnyNPCWithTags(Entity entity, Set<Tag> tags) {
    SkyblockAddons main = SkyblockAddons.getInstance();
    Location currentLocation = main.getUtils().getLocation();

    for (NPC npc:
            NPC_LIST) {
        if (npc.hasLocation(currentLocation)) {
            Vec3 NPCVector = new Vec3(npc.getX(), npc.getY(), npc.getZ());
            Vec3 entityVector = entity.getPositionVector();

            if (NPCVector.distanceTo(entityVector) <= HIDE_RADIUS) {
                if (npc.getTags().containsAll(tags))
                    return true;
            }
        }
    }
    return false;
}
 
Example 5
Source File: NPCUtils.java    From SkyblockAddons with MIT License 6 votes vote down vote up
/**
 * Checks if a given entity is near any player NPC.
 *
 * @param entity the entity to check
 * @return {@code true} if the entity is near any player NPC, {@code false} otherwise
 */
public static boolean isNearAnyPlayerNPC(Entity entity) {
    SkyblockAddons main = SkyblockAddons.getInstance();
    Location currentLocation = main.getUtils().getLocation();

    for (NPC npc:
            NPC_LIST) {
        if (npc.hasLocation(currentLocation)) {
            Vec3 NPCVector = new Vec3(npc.getX(), npc.getY(), npc.getZ());
            Vec3 entityVector = entity.getPositionVector();

            if (NPCVector.distanceTo(entityVector) <= HIDE_RADIUS) {
                if (npc.hasTag(Tag.PLAYER))
                    return true;
            }
        }
    }
    return false;
}
 
Example 6
Source File: NPCUtils.java    From SkyblockAddons with MIT License 6 votes vote down vote up
/**
 * Checks if a given entity is near any furniture NPC.
 *
 * @param entity the entity to check
 * @return {@code true} if the entity is near any furniture NPC, {@code false} otherwise
 */
public static boolean isNearAnyFurnitureNPC(Entity entity) {
    SkyblockAddons main = SkyblockAddons.getInstance();
    Location currentLocation = main.getUtils().getLocation();

    for (NPC npc:
            NPC_LIST) {
        if (npc.hasLocation(currentLocation)) {
            Vec3 NPCVector = new Vec3(npc.getX(), npc.getY(), npc.getZ());
            Vec3 entityVector = entity.getPositionVector();

            if (NPCVector.distanceTo(entityVector) <= HIDE_RADIUS) {
                if (npc.hasTag(Tag.FURNITURE))
                    return true;
            }
        }
    }
    return false;
}
 
Example 7
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 8
Source File: ModuleShapeSelf.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SideOnly(Side.CLIENT)
@Override
public SpellData renderVisualization(@Nonnull World world, ModuleInstanceShape instance, @Nonnull SpellData data, @Nonnull SpellRing ring, float partialTicks) {
	Vec3d target = data.getTarget(world);
	Entity caster = data.getCaster(world);

	if (caster == null) return data;
	if (target == null) {
		target = caster.getPositionVector();
		data.addData(SpellData.DefaultKeys.TARGET_HIT, target);
		data.addData(SpellData.DefaultKeys.TARGET_HIT, target);
	}
	double interpPosX = caster.lastTickPosX + (caster.posX - caster.lastTickPosX) * partialTicks;
	double interpPosY = caster.lastTickPosY + (caster.posY - caster.lastTickPosY) * partialTicks;
	double interpPosZ = caster.lastTickPosZ + (caster.posZ - caster.lastTickPosZ) * partialTicks;

	RenderUtils.drawCircle(new Vec3d(interpPosX, interpPosY + caster.height / 2.0, interpPosZ), 0.55, false, true);
	RenderUtils.drawCircle(new Vec3d(interpPosX, interpPosY + caster.height / 2.0, interpPosZ), 0.6, false, true);

	return data;
}
 
Example 9
Source File: EventsCommon.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onEntityJoinWorldEvent(EntityJoinWorldEvent event) {
    Entity entity = event.getEntity();

    World world = entity.world;
    BlockPos posAt = new BlockPos(entity);

    Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysicsObject(world, posAt);
    if (!event.getWorld().isRemote && physicsObject.isPresent()
        && !(entity instanceof EntityFallingBlock)) {
        if (entity instanceof EntityArmorStand
            || entity instanceof EntityPig || entity instanceof EntityBoat) {
            EntityMountable entityMountable = new EntityMountable(world,
                entity.getPositionVector(), CoordinateSpaceType.SUBSPACE_COORDINATES, posAt);
            world.spawnEntity(entityMountable);
            entity.startRiding(entityMountable);
        }
        physicsObject.get()
            .getShipTransformationManager()
            .getCurrentTickTransform().transform(entity,
            TransformType.SUBSPACE_TO_GLOBAL);
        // TODO: This should work but it doesn't because of sponge. Instead we have to rely on MixinChunk.preAddEntity() to fix this
        // event.setCanceled(true);
        // event.getWorld().spawnEntity(entity);
    }
}
 
Example 10
Source File: ModuleEffectSonic.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean run(@NotNull World world, ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
	Entity targetEntity = spell.getVictim(world);
	Entity caster = spell.getCaster(world);
	BlockPos pos = spell.getTargetPos();

	if (pos == null) return false;

	double potency = spellRing.getAttributeValue(world, AttributeRegistry.POTENCY, spell) / 2;
	double area = spellRing.getAttributeValue(world, AttributeRegistry.AREA, spell) / 2;

	if (!spellRing.taxCaster(world, spell, true)) return false;

	if (targetEntity instanceof EntityLivingBase) {
		world.playSound(null, pos, ModSounds.SOUND_BOMB, SoundCategory.NEUTRAL, 1, RandUtil.nextFloat(0.8f, 1.2f));
		damageEntity((EntityLivingBase) targetEntity, caster, (float) potency);

		if (((EntityLivingBase) targetEntity).getHealth() <= 0) {
			Vec3d targetPos = targetEntity.getPositionVector();
			double sqArea = area * area;
			AxisAlignedBB aabb = new AxisAlignedBB(targetEntity.getPosition()).grow(area);
			world.getEntitiesWithinAABB(EntityLivingBase.class, aabb).stream()
					.filter(entity -> entity.getPositionVector().squareDistanceTo(targetPos) < sqArea)
					.forEach(entity -> damageEntity(entity, caster, (float) potency));
		}
	}
	return true;
}
 
Example 11
Source File: VSWorldEventListener.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
public void onEntityAdded(Entity entity) {
    if (entity instanceof PhysicsWrapperEntity) {
        ValkyrienSkiesMod.VS_PHYSICS_MANAGER.onShipLoad((PhysicsWrapperEntity) entity);
    } else {
        // This is really only here because Sponge doesn't call the entity join event for some reason :/
        // So I basically just copied the event code here as well.
        World world = worldObj;
        BlockPos posAt = new BlockPos(entity);
        Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysicsObject(world, posAt);

        if (!worldObj.isRemote && physicsObject.isPresent()
            && !(entity instanceof EntityFallingBlock)) {
            if (entity instanceof EntityArmorStand
                || entity instanceof EntityPig || entity instanceof EntityBoat) {
                EntityMountable entityMountable = new EntityMountable(world,
                    entity.getPositionVector(), CoordinateSpaceType.SUBSPACE_COORDINATES,
                    posAt);
                world.spawnEntity(entityMountable);
                entity.startRiding(entityMountable);
            }
            world.getChunk(entity.getPosition().getX() >> 4, entity.getPosition().getZ() >> 4)
                .removeEntity(entity);
            physicsObject.get()
                .getShipTransformationManager()
                .getCurrentTickTransform().transform(entity,
                TransformType.SUBSPACE_TO_GLOBAL);
            world.getChunk(entity.getPosition().getX() >> 4, entity.getPosition().getZ() >> 4)
                .addEntity(entity);
        }
    }
}
 
Example 12
Source File: ModuleEffectZoom.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
public void renderSpell(World world, ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {

	Entity entity = spell.getVictim(world);
	if (entity == null) return;

	Vec3d origin = spell.getData(ORIGINAL_LOC);
	if (origin == null) return;

	Vec3d to = entity.getPositionVector();

	ParticleBuilder glitter = new ParticleBuilder(10);
	glitter.setRender(new ResourceLocation(Wizardry.MODID, NBTConstants.MISC.SPARKLE_BLURRED));
	glitter.setAlphaFunction(new InterpFloatInOut(0.0f, 0.3f));

	glitter.enableMotionCalculation();
	glitter.disableRandom();
	glitter.setCollision(true);
	glitter.setTick(particle -> {
		if (particle.getAge() >= particle.getLifetime() / RandUtil.nextDouble(2, 5)) {
			if (particle.getAcceleration().y == 0)
				particle.setAcceleration(new Vec3d(0, RandUtil.nextDouble(-0.05, -0.01), 0));
		} else if (particle.getAcceleration().x != 0 || particle.getAcceleration().y != 0 || particle.getAcceleration().z != 0) {
			particle.setAcceleration(Vec3d.ZERO);
		}
	});
	ParticleSpawner.spawn(glitter, world, new StaticInterp<>(origin.add(0, entity.height / 2.0, 0)), 10, 0, (aFloat, particleBuilder) -> {
		glitter.setPositionOffset(new Vec3d(
				RandUtil.nextDouble(-0.5, 0.5),
				RandUtil.nextDouble(-0.5, 0.5),
				RandUtil.nextDouble(-0.5, 0.5)
		));
		ParticleSpawner.spawn(glitter, world, new InterpLine(origin.add(particleBuilder.getPositionOffset()), to.add(particleBuilder.getPositionOffset()).add(0, entity.height / 2.0, 0)), (int) origin.distanceTo(to) * 5, 0, (aFloat2, particleBuilder2) -> {
			glitter.setAlpha(RandUtil.nextFloat(0.5f, 0.8f));
			glitter.setScale(RandUtil.nextFloat(0.3f, 0.6f));
			glitter.setLifetime(RandUtil.nextInt(30, 50));
			glitter.setColorFunction(new InterpColorHSV(instance.getPrimaryColor(), instance.getSecondaryColor()));
			glitter.setAlphaFunction(new InterpFloatInOut(0f, 1f));
		});
	});
}
 
Example 13
Source File: BounceManager.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
public boolean doesMatch(Entity entity) {
	Vec3d vec = entity.getPositionVector();
	if (vec.x > pos.getX() && vec.x < pos.getX() + 1 && vec.z > pos.getZ() && vec.z < pos.getZ() + 1)
		return this.dim == entity.world.provider.getDimension();
	return false;
}