use of com.teamwizardry.wizardry.api.util.RayTrace in project Wizardry by TeamWizardry.
the class ModuleShapeBeam method run.
@Override
public boolean run(@Nonnull SpellData spell, @Nonnull SpellRing spellRing) throws NullPointerException {
World world = spell.world;
Vec3d look = spell.getData(LOOK);
Vec3d position = spell.getOrigin();
Entity caster = spell.getCaster();
if (look == null || position == null)
return false;
double range = spellRing.getAttributeValue(AttributeRegistry.RANGE, spell);
double potency = 30 - spellRing.getAttributeValue(AttributeRegistry.POTENCY, spell);
spellRing.multiplyMultiplierForAll((float) (potency / 25.0 * range / 75.0));
RayTraceResult trace = new RayTrace(world, look, position, range).setSkipEntity(caster).setReturnLastUncollidableBlock(true).setIgnoreBlocksWithoutBoundingBoxes(true).trace();
spell.processTrace(trace, look.scale(range));
sendRenderPacket(spell, spellRing);
if (spell.world.getTotalWorldTime() % potency == 0) {
if (spellRing.getChildRing() != null) {
spellRing.getChildRing().runSpellRing(spell);
}
}
return true;
}
use of com.teamwizardry.wizardry.api.util.RayTrace in project Wizardry by TeamWizardry.
the class ModuleEffectLightning method run.
@Override
public boolean run(@Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
World world = spell.world;
Vec3d target = spell.getTarget();
Entity caster = spell.getCaster();
float yaw = spell.getData(YAW, 0F);
float pitch = spell.getData(PITCH, 0F);
if (target == null)
return false;
Vec3d origin = target;
if (caster != null) {
float offX = 0.5f * (float) Math.sin(Math.toRadians(-90.0f - yaw));
float offZ = 0.5f * (float) Math.cos(Math.toRadians(-90.0f - yaw));
origin = new Vec3d(offX, caster.getEyeHeight(), offZ).add(target);
}
double range = spellRing.getAttributeValue(AttributeRegistry.RANGE, spell);
double strength = spellRing.getAttributeValue(AttributeRegistry.POTENCY, spell) / 2.0;
if (!spellRing.taxCaster(spell))
return false;
RayTraceResult traceResult = new RayTrace(world, PosUtils.vecFromRotations(pitch, yaw), target, range).setSkipBlocks(true).setSkipEntities(true).trace();
long seed = RandUtil.nextLong(100, 100000);
spell.addData(SEED, seed);
LightningGenerator generator = new LightningGenerator(origin, traceResult.hitVec, new RandUtilSeed(seed));
ArrayList<Vec3d> points = generator.generate();
spell.world.playSound(null, new BlockPos(traceResult.hitVec), ModSounds.LIGHTNING, SoundCategory.NEUTRAL, 0.5f, RandUtil.nextFloat(1, 1.5f));
for (Vec3d point : points) {
List<Entity> entityList = world.getEntitiesWithinAABBExcludingEntity(caster, new AxisAlignedBB(new BlockPos(point)).contract(0.2, 0.2, 0.2));
if (!entityList.isEmpty()) {
for (Entity entity : entityList) {
LightningTracker.INSTANCE.addEntity(origin, entity, caster, (int) strength);
}
}
}
return true;
}
use of com.teamwizardry.wizardry.api.util.RayTrace in project Wizardry by TeamWizardry.
the class TileManaInteracter method suckManaFrom.
public boolean suckManaFrom(TileManaInteracter interacterFrom, SuckRule suckRule) {
if (getWizardryCap() == null || interacterFrom.getWizardryCap() == null)
return false;
if (!isAllowOutsideSucking() && interacterFrom.isAllowOutsideSucking())
return false;
if (!suckRule.condition.test(this, interacterFrom))
return false;
CapManager thisManager = new CapManager(getWizardryCap());
CapManager theirManager = new CapManager(interacterFrom.getWizardryCap());
if (thisManager.isManaFull())
return false;
if (theirManager.isManaEmpty())
return false;
if (suckRule.equalize && Math.abs(thisManager.getMana() - theirManager.getMana()) <= suckRule.idealAmount)
return false;
Vec3d thisPos = new Vec3d(getPos()).addVector(0.5, 0.5, 0.5);
Vec3d theirPos = new Vec3d(interacterFrom.getPos()).addVector(0.5, 0.5, 0.5);
// DEBUG
// ParticleBuilder helix = new ParticleBuilder(200);
// helix.setRender(new ResourceLocation(Wizardry.MODID, Constants.MISC.SPARKLE_BLURRED));
// helix.setAlphaFunction(new InterpFadeInOut(0.1f, 0.1f));
// ParticleSpawner.spawn(helix, world, new StaticInterp<>(thisPos), 1, 0, (someFloat, particleBuilder) -> {
// particleBuilder.setColor(ColorUtils.changeColorAlpha(new Color(0xFF0000), RandUtil.nextInt(50, 200)));
// particleBuilder.setScale(RandUtil.nextFloat(0.3f, 0.8f));
// particleBuilder.disableRandom();
// particleBuilder.setPositionFunction(new InterpLine(Vec3d.ZERO, theirPos.subtract(thisPos)));
// particleBuilder.setLifetime(RandUtil.nextInt(50, 60));
// });
double ratio = theirManager.getMana() / thisManager.getMana();
if (suckRule.equalize && Double.isFinite(ratio) && ratio <= 1.2)
return false;
if (getCachedDistanceSq(interacterFrom) > ConfigValues.networkLinkDistance * ConfigValues.networkLinkDistance)
return false;
if (!suckRule.ignoreTrace) {
Vec3d thisSub = theirPos.subtract(thisPos.add(getOffset()));
Vec3d thisNorm = thisSub.normalize();
RayTraceResult trace = new RayTrace(world, thisNorm, thisPos.add(getOffset() == Vec3d.ZERO ? thisNorm : getOffset()), ConfigValues.networkLinkDistance * ConfigValues.networkLinkDistance).setSkipEntities(true).setIgnoreBlocksWithoutBoundingBoxes(true).trace();
if (!trace.getBlockPos().equals(interacterFrom.getPos()))
return false;
}
double amount = interacterFrom.drainMana(suckRule.idealAmount);
if (amount <= 0)
return false;
thisManager.addMana(amount);
ClientRunnable.run(new ClientRunnable() {
@Override
@SideOnly(Side.CLIENT)
public void runIfClient() {
ParticleBuilder helix = new ParticleBuilder(200);
helix.setRender(new ResourceLocation(Wizardry.MODID, Constants.MISC.SPARKLE_BLURRED));
helix.setAlphaFunction(new InterpFadeInOut(0.1f, 0.1f));
ParticleSpawner.spawn(helix, world, new StaticInterp<>(new Vec3d(interacterFrom.getPos()).addVector(0.5, 1, 0.5)), 1, 0, (someFloat, particleBuilder) -> {
particleBuilder.setColor(ColorUtils.changeColorAlpha(new Color(0x0097FF), RandUtil.nextInt(50, 200)));
particleBuilder.setScale(RandUtil.nextFloat(0.3f, 0.8f));
particleBuilder.setPositionFunction(new InterpBezier3D(Vec3d.ZERO, new Vec3d(getPos().subtract(interacterFrom.getPos())), new Vec3d(0, 5, 0), new Vec3d(0, -5, 0)));
particleBuilder.setLifetime(RandUtil.nextInt(50, 60));
});
}
});
return true;
}
use of com.teamwizardry.wizardry.api.util.RayTrace in project Wizardry by TeamWizardry.
the class EntitySpellProjectile method onUpdate.
@Override
public void onUpdate() {
super.onUpdate();
if (world.isRemote)
return;
if (spellRing == null || spellData == null) {
setDead();
world.removeEntity(this);
return;
}
Vec3d origin = spellData.getOrigin();
rotationPitch = spellData.getData(PITCH, 0F);
rotationYaw = spellData.getData(YAW, 0F);
Vec3d look = spellData.getData(LOOK);
if (look == null) {
setDead();
world.removeEntity(this);
return;
}
if (origin == null || dist < getDistance(origin.x, origin.y, origin.z)) {
spellData.processBlock(getPosition(), EnumFacing.getFacingFromVector((float) look.x, (float) look.y, (float) look.z), getPositionVector());
goBoom(spellData);
return;
}
if (isDead)
return;
if (!collided) {
// MOVE //
motionX += ((look.x * speed) - motionX);
motionY += ((look.y * speed) - motionY);
motionZ += ((look.z * speed) - motionZ);
// GRAVITY
// if (getDistanceSq(origin.x, origin.y, origin.z) > 4)
// motionY -= gravity;
move(MoverType.SELF, motionX, motionY, motionZ);
} else {
RayTraceResult result = new RayTrace(world, look, getPositionVector(), 5).setSkipEntity(this).trace();
spellData.processTrace(result, getPositionVector());
goBoom(spellData);
return;
}
List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(this, getEntityBoundingBox());
if (!entities.isEmpty()) {
Entity caster = spellData.getCaster();
// Don't collide with other spell projectiles
for (Entity entity : entities) {
if (entity == caster)
return;
if (entity instanceof EntitySpellProjectile)
return;
}
RayTraceResult result = new RayTrace(world, look, getPositionVector(), 1).setSkipEntity(this).trace();
spellData.processTrace(result, getPositionVector());
goBoom(spellData);
}
}
use of com.teamwizardry.wizardry.api.util.RayTrace in project Wizardry by TeamWizardry.
the class ModuleEffectZoom method run.
@Override
public boolean run(@Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
World world = spell.world;
Entity entityHit = spell.getVictim();
Vec3d look = spell.getData(LOOK);
Vec3d origin = spell.getData(ORIGIN);
if (entityHit == null)
return true;
else {
if (!spellRing.taxCaster(spell))
return false;
if (look == null)
return true;
if (origin == null)
return true;
double range = spellRing.getAttributeValue(AttributeRegistry.RANGE, spell);
RayTraceResult trace = new RayTrace(world, look, origin, range).setSkipEntity(entityHit).setIgnoreBlocksWithoutBoundingBoxes(true).setReturnLastUncollidableBlock(false).trace();
spell.addData(ORIGINAL_LOC, entityHit.getPositionVector());
entityHit.setPositionAndUpdate(trace.hitVec.x, trace.hitVec.y, trace.hitVec.z);
entityHit.motionX = 0;
entityHit.motionY = 0;
entityHit.motionZ = 0;
entityHit.velocityChanged = true;
}
if (entityHit instanceof EntityLivingBase) {
((EntityLivingBase) entityHit).addPotionEffect(new PotionEffect(ModPotions.NULLIFY_GRAVITY, 5, 1, true, false));
((EntityLivingBase) entityHit).addPotionEffect(new PotionEffect(ModPotions.NULL_MOVEMENT, 5, 1, true, false));
}
return true;
}
Aggregations