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

The following examples show how to use net.minecraft.entity.Entity#getDistance() . 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: NoDesyncModule.java    From seppuku with GNU General Public License v3.0 6 votes vote down vote up
@Listener
public void receivePacket(EventReceivePacket event) {
    if (event.getStage() == EventStageable.EventStage.PRE) {
        if (event.getPacket() instanceof SPacketSoundEffect) {
            final SPacketSoundEffect packet = (SPacketSoundEffect) event.getPacket();
            if (packet.getCategory() == SoundCategory.BLOCKS && packet.getSound() == SoundEvents.ENTITY_GENERIC_EXPLODE) {
                for (Entity e : Minecraft.getMinecraft().world.loadedEntityList) {
                    if (e != null && e instanceof EntityEnderCrystal) {
                        if (e.getDistance(packet.getX(), packet.getY(), packet.getZ()) <= 6.0f) {
                            e.setDead();
                        }
                    }
                }
            }
        }
    }
}
 
Example 2
Source File: PosUtils.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void boom(World world, Vec3d pos, @Nullable Entity excluded, double scale, boolean reverseDirection) {
	List<Entity> entityList = world.getEntitiesWithinAABBExcludingEntity(excluded, new AxisAlignedBB(new BlockPos(pos)).grow(32, 32, 32));
	for (Entity entity1 : entityList) {
		double x = entity1.getDistance(pos.x, pos.y, pos.z) / 32.0;
		double magY;

		if (reverseDirection) magY = x;
		else magY = -x + 1;

		Vec3d dir = entity1.getPositionVector().subtract(pos).normalize().scale(reverseDirection ? -1 : 1).scale(magY).scale(scale);

		entity1.motionX += (dir.x);
		entity1.motionY += (dir.y);
		entity1.motionZ += (dir.z);
		entity1.fallDistance = 0;
		entity1.velocityChanged = true;

		if (entity1 instanceof EntityPlayerMP)
			((EntityPlayerMP) entity1).connection.sendPacket(new SPacketEntityVelocity(entity1));
	}
}
 
Example 3
Source File: WEntity.java    From ForgeWurst with GNU General Public License v3.0 4 votes vote down vote up
public static float getDistance(Entity e1, Entity e2)
{
	return e1.getDistance(e2);
}
 
Example 4
Source File: PearlInfusionRecipe.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void complete(World world, BlockPos pos, ItemStack input, ItemStackHandler inventoryHandler) {
	ArrayList<ItemStack> stacks = new ArrayList<>();

	for (int i = 0; i < inventoryHandler.getSlots(); i++) {
		if (!inventoryHandler.getStackInSlot(i).isEmpty()) {
			stacks.add(inventoryHandler.getStackInSlot(i));
			inventoryHandler.setStackInSlot(i, ItemStack.EMPTY);
		}
	}

	// Process spellData multipliers based on nacre quality
	double pearlMultiplier = 1;
	if (input.getItem() instanceof INacreProduct) {
		float purity = ((INacreProduct) input.getItem()).getQuality(input);
		if (purity >= 1f) pearlMultiplier = ConfigValues.perfectPearlMultiplier * purity;
		else if (purity <= ConfigValues.damagedPearlMultiplier)
			pearlMultiplier = ConfigValues.damagedPearlMultiplier;
		else {
			double base = purity - 1;
			pearlMultiplier = 1 - (base * base * base * base);
		}
	}

	SpellBuilder builder = new SpellBuilder(stacks, pearlMultiplier);

	NBTTagList list = new NBTTagList();
	for (SpellRing spellRing : builder.getSpell()) {
		list.appendTag(spellRing.serializeNBT());
	}

	SpellUtils.infuseSpell(input, list);

	//markDirty();

	PacketHandler.NETWORK.sendToAllAround(new PacketExplode(new Vec3d(pos).add(0.5, 0.5, 0.5), Color.CYAN, Color.BLUE, 2, 2, 500, 300, 20, true),
			new NetworkRegistry.TargetPoint(world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 256));

	world.playSound(null, pos, ModSounds.BASS_BOOM, SoundCategory.BLOCKS, 1f, (float) RandUtil.nextDouble(1, 1.5));

	List<Entity> entityList = world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(pos).grow(32, 32, 32));
	for (Entity entity1 : entityList) {
		double dist = entity1.getDistance(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
		final double upperMag = 3;
		final double scale = 0.8;
		double mag = upperMag * (scale * dist / (-scale * dist - 1) + 1);
		Vec3d dir = entity1.getPositionVector().subtract(new Vec3d(pos).add(0.5, 0.5, 0.5)).normalize().scale(mag);

		entity1.motionX = (dir.x);
		entity1.motionY = (dir.y);
		entity1.motionZ = (dir.z);
		entity1.fallDistance = 0;
		entity1.velocityChanged = true;

		if (entity1 instanceof EntityPlayerMP)
			((EntityPlayerMP) entity1).connection.sendPacket(new SPacketEntityVelocity(entity1));
	}
}
 
Example 5
Source File: FairyJarRecipe.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void complete(World world, BlockPos pos, ItemStack input, ItemStackHandler inventoryHandler) {
	TileEntity tileEntity = world.getTileEntity(pos.offset(EnumFacing.UP));
	if (!(tileEntity instanceof TileJar)) return;
	TileJar jar = (TileJar) tileEntity;

	ArrayList<ItemStack> stacks = new ArrayList<>();

	for (int i = 0; i < inventoryHandler.getSlots(); i++) {
		if (!inventoryHandler.getStackInSlot(i).isEmpty()) {
			stacks.add(inventoryHandler.getStackInSlot(i));
			inventoryHandler.setStackInSlot(i, ItemStack.EMPTY);
		}
	}

	SpellBuilder builder = new SpellBuilder(stacks);
	List<SpellRing> spell = builder.getSpell();
	if (spell.isEmpty()) return;

	NBTTagList list = new NBTTagList();
	for (SpellRing spellRing : builder.getSpell()) {
		list.appendTag(spellRing.serializeNBT());
	}

	jar.fairy.infusedSpell.clear();
	jar.fairy.infusedSpell.addAll(builder.getSpell());

	PacketHandler.NETWORK.sendToAllAround(new PacketExplode(new Vec3d(pos).add(0.5, 0.5, 0.5), Color.CYAN, Color.BLUE, 2, 2, 500, 300, 20, true),
			new NetworkRegistry.TargetPoint(world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ(), 256));

	world.playSound(null, pos, ModSounds.BASS_BOOM, SoundCategory.BLOCKS, 1f, (float) RandUtil.nextDouble(1, 1.5));

	List<Entity> entityList = world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(pos).grow(32, 32, 32));
	for (Entity entity1 : entityList) {
		double dist = entity1.getDistance(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
		final double upperMag = 3;
		final double scale = 0.8;
		double mag = upperMag * (scale * dist / (-scale * dist - 1) + 1);
		Vec3d dir = entity1.getPositionVector().subtract(new Vec3d(pos).add(0.5, 0.5, 0.5)).normalize().scale(mag);

		entity1.motionX = (dir.x);
		entity1.motionY = (dir.y);
		entity1.motionZ = (dir.z);
		entity1.fallDistance = 0;
		entity1.velocityChanged = true;

		if (entity1 instanceof EntityPlayerMP)
			((EntityPlayerMP) entity1).connection.sendPacket(new SPacketEntityVelocity(entity1));
	}
}
 
Example 6
Source File: RenderBlockTarget.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public double getDistanceToEntity(Entity entity){
    return entity.getDistance(blockX + 0.5D, blockY + 0.5D, blockZ + 0.5D);
}