net.minecraft.network.play.server.SPacketEntityVelocity Java Examples

The following examples show how to use net.minecraft.network.play.server.SPacketEntityVelocity. 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: 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 #2
Source File: AntiKnockbackMod.java    From ForgeHax with MIT License 5 votes vote down vote up
private Vec3d getPacketMotion(Packet<?> packet) {
  if (packet instanceof SPacketExplosion) {
    return new Vec3d(
        FastReflection.Fields.SPacketExplosion_motionX.get(packet),
        FastReflection.Fields.SPacketExplosion_motionY.get(packet),
        FastReflection.Fields.SPacketExplosion_motionZ.get(packet));
  } else if (packet instanceof SPacketEntityVelocity) {
    return new Vec3d(
        FastReflection.Fields.SPacketEntityVelocity_motionX.get(packet),
        FastReflection.Fields.SPacketEntityVelocity_motionY.get(packet),
        FastReflection.Fields.SPacketEntityVelocity_motionZ.get(packet));
  } else {
    throw new IllegalArgumentException();
  }
}
 
Example #3
Source File: AntiKnockbackMod.java    From ForgeHax with MIT License 5 votes vote down vote up
private void setPacketMotion(Packet<?> packet, Vec3d in) {
  if (packet instanceof SPacketExplosion) {
    FastReflection.Fields.SPacketExplosion_motionX.set(packet, (float) in.x);
    FastReflection.Fields.SPacketExplosion_motionY.set(packet, (float) in.y);
    FastReflection.Fields.SPacketExplosion_motionZ.set(packet, (float) in.z);
  } else if (packet instanceof SPacketEntityVelocity) {
    FastReflection.Fields.SPacketEntityVelocity_motionX.set(packet, (int) Math.round(in.x));
    FastReflection.Fields.SPacketEntityVelocity_motionY.set(packet, (int) Math.round(in.y));
    FastReflection.Fields.SPacketEntityVelocity_motionZ.set(packet, (int) Math.round(in.z));
  } else {
    throw new IllegalArgumentException();
  }
}
 
Example #4
Source File: ModuleEffectAntiGravityWell.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) {
	Vec3d position = spell.getTarget(world);

	if (position == null) return false;

	double area = spellRing.getAttributeValue(world, AttributeRegistry.AREA, spell);

	for (Entity entity : world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(new BlockPos(position)).grow(area, area, area))) {
		if (entity == null) continue;
		double dist = entity.getPositionVector().distanceTo(position);
		if (dist < 2) continue;
		if (dist > area) continue;
		if (!spellRing.taxCaster(world, spell, false)) return false;

		final double upperMag = spellRing.getAttributeValue(world, AttributeRegistry.POTENCY, spell) / 50.0;
		final double scale = 1.5;
		double mag = upperMag * (scale * dist / (-scale * dist - 1) + 1);

		Vec3d dir = position.subtract(entity.getPositionVector()).normalize().scale(-mag);

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

		spell.addData(ENTITY_HIT, entity.getEntityId());
		if (entity instanceof EntityPlayerMP)
			((EntityPlayerMP) entity).connection.sendPacket(new SPacketEntityVelocity(entity));
	}

	return true;
}
 
Example #5
Source File: ModuleEffectGravityWell.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) {
	Vec3d position = spell.getTarget(world);

	if (position == null) return false;

	double area = spellRing.getAttributeValue(world, AttributeRegistry.AREA, spell);

	for (Entity entity : world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(new BlockPos(position)).grow(area, area, area))) {
		if (entity == null) continue;
		double dist = entity.getPositionVector().distanceTo(position);
		if (dist < 2) continue;
		if (dist > area) continue;
		if (!spellRing.taxCaster(world, spell, false)) return false;

		final double upperMag = spellRing.getAttributeValue(world, AttributeRegistry.POTENCY, spell) / 50.0;
		final double scale = 1.5;
		double mag = upperMag * (scale * dist / (-scale * dist - 1) + 1);

		Vec3d dir = position.subtract(entity.getPositionVector()).normalize().scale(mag);

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

		spell.addData(ENTITY_HIT, entity.getEntityId());
		if (entity instanceof EntityPlayerMP)
			((EntityPlayerMP) entity).connection.sendPacket(new SPacketEntityVelocity(entity));
	}

	return true;
}
 
Example #6
Source File: ModuleEffectLeap.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) {
	Vec3d lookVec = spell.getData(LOOK);
	Entity target = spell.getVictim(world);

	if (!(target instanceof EntityLivingBase)) return true;

	ItemStack stack = ((EntityLivingBase) target).getHeldItemMainhand();
	if (stack.isEmpty()) return true;
	if (lookVec == null) return true;

	if (!target.hasNoGravity()) {
		double potency = spellRing.getAttributeValue(world, AttributeRegistry.POTENCY, spell);
		if (!spellRing.taxCaster(world, spell, true)) return false;

		if (!NBTHelper.hasNBTEntry(stack, "jump_count")
				|| !NBTHelper.hasNBTEntry(stack, "max_jumps")
				|| !NBTHelper.hasNBTEntry(stack, "jump_timer")) {
			NBTHelper.setInt(stack, "jump_count", (int) potency);
			NBTHelper.setInt(stack, "max_jumps", (int) potency);
			NBTHelper.setInt(stack, "jump_timer", 200);
		}

		target.motionX += lookVec.x;
		target.motionY += 0.65;
		target.motionZ += lookVec.z;

		target.velocityChanged = true;
		target.fallDistance /= (1 + MathHelper.ceil(spellRing.getAttributeValue(world, AttributeRegistry.POTENCY, spell) / 8));

		if (target instanceof EntityPlayerMP)
			((EntityPlayerMP) target).connection.sendPacket(new SPacketEntityVelocity(target));
		world.playSound(null, target.getPosition(), ModSounds.FLY, SoundCategory.NEUTRAL, 1, 1);
	}
	return true;
}
 
Example #7
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 #8
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));
	}
}