use of net.minecraft.network.play.server.SPacketEntityVelocity in project Wizardry by TeamWizardry.
the class ModuleEffectGravityWell method run.
@Override
@SuppressWarnings("unused")
public boolean run(@Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
World world = spell.world;
Vec3d position = spell.getTarget();
Entity caster = spell.getCaster();
if (position == null)
return false;
double strength = spellRing.getAttributeValue(AttributeRegistry.AREA, spell);
for (Entity entity : world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(new BlockPos(position)).grow(strength, strength, strength))) {
if (entity == null)
continue;
double dist = entity.getPositionVector().distanceTo(position);
if (dist < 2)
continue;
if (dist > strength)
continue;
if (!spellRing.taxCaster(spell))
return false;
final double upperMag = spellRing.getAttributeValue(AttributeRegistry.POTENCY, spell) / 100.0;
final double scale = 3.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);
if (entity instanceof EntityPlayerMP)
((EntityPlayerMP) entity).connection.sendPacket(new SPacketEntityVelocity(entity));
}
return true;
}
use of net.minecraft.network.play.server.SPacketEntityVelocity in project Wizardry by TeamWizardry.
the class ModuleEffectLeap method run.
@Override
@SuppressWarnings("unused")
public boolean run(@Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
float yaw = spell.getData(YAW, 0F);
float pitch = spell.getData(PITCH, 0F);
Vec3d pos = spell.getTarget();
Entity target = spell.getVictim();
Entity caster = spell.getCaster();
if (target == null)
return false;
if (!(target instanceof EntityLivingBase))
return true;
Vec3d lookVec = PosUtils.vecFromRotations(pitch, yaw);
if (!target.hasNoGravity()) {
double strength = spellRing.getAttributeValue(AttributeRegistry.POTENCY, spell) / 10.0;
if (!spellRing.taxCaster(spell))
return false;
if (!target.getEntityData().hasKey("jump_count")) {
target.getEntityData().setInteger("jump_count", (int) strength);
target.getEntityData().setInteger("jump_timer", 200);
}
target.motionX += lookVec.x;
target.motionY += 0.65;
target.motionZ += lookVec.z;
target.velocityChanged = true;
target.fallDistance /= MathHelper.clamp(spellRing.getAttributeValue(AttributeRegistry.POTENCY, spell), 2, 10);
if (target instanceof EntityPlayerMP)
((EntityPlayerMP) target).connection.sendPacket(new SPacketEntityVelocity(target));
spell.world.playSound(null, target.getPosition(), ModSounds.FLY, SoundCategory.NEUTRAL, 1, 1);
}
return true;
}
use of net.minecraft.network.play.server.SPacketEntityVelocity in project Wizardry by TeamWizardry.
the class EntityFairy method onUpdate.
@Override
public void onUpdate() {
super.onUpdate();
if (world.isRemote)
return;
if (isAIDisabled())
return;
if (ambush) {
List<Entity> entities = world.getEntitiesInAABBexcluding(this, new AxisAlignedBB(getPosition()).grow(64, 64, 64), null);
for (Entity entity : entities) if (entity instanceof EntityPlayer) {
double dist = entity.getPositionVector().distanceTo(getPositionVector());
Vec3d sub = entity.getPositionVector().addVector(0, entity.height / 2, 0).subtract(getPositionVector()).normalize().scale(dist / 3.0);
motionX = sub.x;
motionY = sub.y;
motionZ = sub.z;
velocityChanged = true;
if ((int) dist <= 0 || RandUtil.nextInt((int) (dist * 20.0)) == 0)
ambush = false;
if (entity instanceof EntityPlayerMP)
((EntityPlayerMP) entity).connection.sendPacket(new SPacketEntityVelocity(this));
}
return;
}
if (!getNavigator().noPath())
return;
boolean nopeOut = false;
List<Entity> entities = world.getEntitiesInAABBexcluding(this, new AxisAlignedBB(getPosition()).grow(5, 5, 5), null);
for (Entity entity : entities) if (entity instanceof EntityLivingBase) {
if (entity.isSneaking())
continue;
nopeOut = true;
Vec3d sub = getPositionVector().subtract(entity.getPositionVector().addVector(0, entity.height / 2, 0)).normalize();
Random rand = new Random(hashCode());
double speed = rand.nextInt(9) + 1;
motionX += sub.x / speed;
motionY += sub.y / speed;
motionZ += sub.z / speed;
}
if (nopeOut) {
for (int i = -2; i < 2; i++) for (int k = -2; k < 2; k++) for (int j = -2; j < 2; j++) {
BlockPos pos = new BlockPos(getPositionVector()).add(i, j, k);
if (!world.isAirBlock(pos)) {
Vec3d center = new Vec3d(pos).addVector(0.5, 0.5, 0.5);
Vec3d sub = getPositionVector().addVector(0, height / 2, 0).subtract(center).normalize();
Random rand = new Random(hashCode());
double speed = rand.nextInt(9) + 1;
motionX += sub.x / speed;
motionY += sub.y / speed;
motionZ += sub.z / speed;
}
}
}
if (!nopeOut) {
int r = Math.abs(new Random(getPosition().toLong()).nextInt(20)) + 1;
if (RandUtil.nextInt(r) == 0) {
changingCourse = true;
changeCourseTick = RandUtil.nextInt(50);
tickPitch = (float) RandUtil.nextDouble(-10, 10);
tickYaw = (float) RandUtil.nextDouble(-10, 10);
}
if (changingCourse) {
if (changeCourseTick > 0) {
changeCourseTick--;
Vec3d dir = getVectorForRotation(rotationPitch += tickPitch, rotationYaw += tickYaw).normalize();
Random rand = new Random(hashCode());
double speed = rand.nextInt(9) + 1;
motionX = dir.x / speed;
motionY = dir.y / speed;
motionZ = dir.z / speed;
} else
changingCourse = false;
}
}
}
use of net.minecraft.network.play.server.SPacketEntityVelocity in project Wizardry by TeamWizardry.
the class ModuleEffectAntiGravityWell method run.
@Override
@SuppressWarnings("unused")
public boolean run(@Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
World world = spell.world;
Vec3d position = spell.getTarget();
Entity caster = spell.getCaster();
if (position == null)
return false;
double area = spellRing.getAttributeValue(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(spell))
return false;
final double upperMag = spellRing.getAttributeValue(AttributeRegistry.POTENCY, spell) / 100.0;
final double scale = 3.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);
if (entity instanceof EntityPlayerMP)
((EntityPlayerMP) entity).connection.sendPacket(new SPacketEntityVelocity(entity));
}
return true;
}
use of net.minecraft.network.play.server.SPacketEntityVelocity in project EnderIO by SleepyTrousers.
the class TeleportUtil method serverTeleport.
public static boolean serverTeleport(@Nonnull Entity entity, @Nonnull BlockPos pos, int targetDim, boolean conserveMotion, @Nonnull TravelSource source) {
TeleportEntityEvent evt = new TeleportEntityEvent(entity, source, pos, targetDim);
if (MinecraftForge.EVENT_BUS.post(evt)) {
return false;
}
EntityPlayerMP player = null;
if (entity instanceof EntityPlayerMP) {
player = (EntityPlayerMP) entity;
}
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
int from = entity.dimension;
if (from != targetDim) {
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
WorldServer fromDim = server.getWorld(from);
WorldServer toDim = server.getWorld(targetDim);
Teleporter teleporter = new TeleporterEIO(toDim);
// play sound at the dimension we are leaving for others to hear
SoundHelper.playSound(server.getWorld(entity.dimension), entity, source.sound, 1.0F, 1.0F);
if (player != null) {
server.getPlayerList().transferPlayerToDimension(player, targetDim, teleporter);
if (from == 1 && entity.isEntityAlive()) {
// get around vanilla End
// hacks
toDim.spawnEntity(entity);
toDim.updateEntityWithOptionalForce(entity, false);
}
} else {
NBTTagCompound tagCompound = new NBTTagCompound();
float rotationYaw = entity.rotationYaw;
float rotationPitch = entity.rotationPitch;
entity.writeToNBT(tagCompound);
Class<? extends Entity> entityClass = entity.getClass();
fromDim.removeEntity(entity);
try {
Entity newEntity = entityClass.getConstructor(World.class).newInstance(toDim);
newEntity.readFromNBT(tagCompound);
newEntity.setLocationAndAngles(x, y, z, rotationYaw, rotationPitch);
newEntity.forceSpawn = true;
toDim.spawnEntity(newEntity);
// necessary?
newEntity.forceSpawn = false;
} catch (Exception e) {
// Throwables.propagate(e);
Log.error("serverTeleport: Error creating a entity to be created in new dimension.");
return false;
}
}
}
// Force the chunk to load
if (!entity.world.isBlockLoaded(pos)) {
entity.world.getChunkFromBlockCoords(pos);
}
if (player != null) {
player.connection.setPlayerLocation(x + 0.5, y + 1.1, z + 0.5, player.rotationYaw, player.rotationPitch);
} else {
entity.setPositionAndUpdate(x + 0.5, y + 1.1, z + 0.5);
}
entity.fallDistance = 0;
SoundHelper.playSound(entity.world, entity, source.sound, 1.0F, 1.0F);
if (player != null) {
if (conserveMotion) {
Vector3d velocityVex = Util.getLookVecEio(player);
SPacketEntityVelocity p = new SPacketEntityVelocity(entity.getEntityId(), velocityVex.x, velocityVex.y, velocityVex.z);
player.connection.sendPacket(p);
}
}
return true;
}
Aggregations