use of com.teamwizardry.wizardry.api.spell.module.ModuleInstanceEffect in project Wizardry by TeamWizardry.
the class ModuleEffectSubstitution method run.
@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 targetBlock = spell.getTargetPos();
EnumFacing facing = spell.getFaceHit();
if (caster == null)
return false;
if (targetEntity instanceof EntityLivingBase) {
if (!spellRing.taxCaster(world, spell, true))
return false;
Vec3d posTarget = new Vec3d(targetEntity.posX, targetEntity.posY, targetEntity.posZ), posCaster = new Vec3d(caster.posX, caster.posY, caster.posZ);
float yawTarget = targetEntity.rotationYaw, pitchTarget = targetEntity.rotationPitch, yawCaster = caster.rotationYaw, pitchCaster = caster.rotationPitch;
targetEntity.rotationYaw = yawCaster;
targetEntity.rotationPitch = pitchCaster;
targetEntity.setPositionAndUpdate(posCaster.x, posCaster.y, posCaster.z);
caster.rotationYaw = yawTarget;
caster.rotationPitch = pitchTarget;
caster.setPositionAndUpdate(posTarget.x, posTarget.y, posTarget.z);
world.playSound(null, caster.getPosition(), ModSounds.TELEPORT, SoundCategory.NEUTRAL, 1, RandUtil.nextFloat());
world.playSound(null, targetEntity.getPosition(), ModSounds.TELEPORT, SoundCategory.NEUTRAL, 1, RandUtil.nextFloat());
return true;
} else if (targetBlock != null && caster instanceof EntityPlayer) {
if (facing == null)
return false;
ItemStack hand = ((EntityPlayer) caster).getHeldItemMainhand();
if (hand.isEmpty())
return false;
world.playSound(null, targetBlock, ModSounds.TELEPORT, SoundCategory.NEUTRAL, 1, RandUtil.nextFloat());
if (NBTHelper.hasNBTEntry(hand, "selected")) {
NBTTagCompound compound = NBTHelper.getCompound(hand, "selected");
if (compound == null)
return false;
IBlockState state = NBTUtil.readBlockState(compound);
IBlockState touchedBlock = world.getBlockState(targetBlock);
boolean misMatch = false;
for (IProperty property : touchedBlock.getPropertyKeys()) {
if (state.getPropertyKeys().contains(property)) {
if (state.getValue(property).equals(touchedBlock.getValue(property))) {
} else {
misMatch = true;
}
}
}
if (touchedBlock.getBlock() == state.getBlock() && !misMatch)
return false;
double area = spellRing.getAttributeValue(world, AttributeRegistry.AREA, spell);
ItemStack stackBlock = null;
for (ItemStack stack : ((EntityPlayer) caster).inventory.mainInventory) {
if (stack.isEmpty())
continue;
if (!(stack.getItem() instanceof ItemBlock))
continue;
Block block = ((ItemBlock) stack.getItem()).getBlock();
if (block != state.getBlock())
continue;
stackBlock = stack;
break;
}
if (stackBlock == null)
return false;
Set<BlockPos> blocks = BlockUtils.blocksInSquare(targetBlock, facing, Math.min(stackBlock.getCount(), (int) area), (int) ((Math.sqrt(area) + 1) / 2), pos -> {
if (world.isAirBlock(pos))
return true;
if (!world.isAirBlock(pos.offset(facing)))
return true;
IBlockState block = world.getBlockState(pos);
return block.getBlock() != touchedBlock.getBlock();
});
if (blocks.isEmpty())
return true;
for (BlockPos pos : blocks) {
if (stackBlock.isEmpty())
return true;
if (!spellRing.taxCaster(world, spell, 1 / area, false))
return false;
if (world.isAirBlock(pos))
continue;
if (world.getBlockState(pos).getBlock() == state.getBlock())
continue;
stackBlock.shrink(1);
IBlockState oldState = world.getBlockState(pos);
BlockUtils.placeBlock(world, pos, state, (EntityPlayerMP) caster);
((EntityPlayer) caster).inventory.addItemStackToInventory(new ItemStack(oldState.getBlock().getItemDropped(oldState, world.rand, 0)));
}
}
return true;
}
return false;
}
use of com.teamwizardry.wizardry.api.spell.module.ModuleInstanceEffect in project Wizardry by TeamWizardry.
the class ModuleEffectSubstitution method renderSpell.
@Override
@SideOnly(Side.CLIENT)
public void renderSpell(World world, ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
Entity caster = spell.getCaster(world);
BlockPos targetBlock = spell.getTargetPos();
Entity targetEntity = spell.getVictim(world);
if (targetEntity != null && caster != null) {
ParticleBuilder glitter = new ParticleBuilder(RandUtil.nextInt(20, 30));
glitter.setRender(new ResourceLocation(Wizardry.MODID, NBTConstants.MISC.SPARKLE_BLURRED));
glitter.setColorFunction(new InterpColorHSV(instance.getPrimaryColor(), instance.getSecondaryColor()));
ParticleSpawner.spawn(glitter, world, new StaticInterp<>(new Vec3d(targetEntity.posX, targetEntity.posY, targetEntity.posZ)), 50, RandUtil.nextInt(20, 30), (aFloat, particleBuilder) -> {
glitter.setScale((float) RandUtil.nextDouble(0.3, 1));
glitter.setAlphaFunction(new InterpFloatInOut(0.3f, (float) RandUtil.nextDouble(0.6, 1)));
glitter.setLifetime(RandUtil.nextInt(10, 20));
glitter.setScaleFunction(new InterpScale(1, 0));
glitter.setPositionFunction(new InterpHelix(new Vec3d(0, 0, 0), new Vec3d(0, 2, 0), 0.5f, 0f, 1, RandUtil.nextFloat()));
});
glitter.setColorFunction(new InterpColorHSV(instance.getSecondaryColor(), instance.getPrimaryColor()));
ParticleSpawner.spawn(glitter, world, new StaticInterp<>(new Vec3d(caster.posX, caster.posY, caster.posZ)), 50, RandUtil.nextInt(20, 30), (aFloat, particleBuilder) -> {
glitter.setScale((float) RandUtil.nextDouble(0.3, 1));
glitter.setAlphaFunction(new InterpFloatInOut(0.3f, (float) RandUtil.nextDouble(0.6, 1)));
glitter.setLifetime(RandUtil.nextInt(10, 20));
glitter.setScaleFunction(new InterpScale(1, 0));
glitter.setPositionFunction(new InterpHelix(new Vec3d(0, 0, 0), new Vec3d(0, 4, 0), 1f, 0f, 1, RandUtil.nextFloat()));
});
} else if (targetBlock != null) {
ParticleBuilder glitter = new ParticleBuilder(RandUtil.nextInt(20, 30));
glitter.setRender(new ResourceLocation(Wizardry.MODID, NBTConstants.MISC.SPARKLE_BLURRED));
glitter.setColorFunction(new InterpColorHSV(instance.getPrimaryColor(), instance.getSecondaryColor()));
ParticleSpawner.spawn(glitter, world, new StaticInterp<>(new Vec3d(targetBlock).add(0.5, 0.5, 0.5)), 20, 0, (aFloat, particleBuilder) -> {
glitter.setScale((float) RandUtil.nextDouble(0.3, 1));
glitter.setAlphaFunction(new InterpFloatInOut(0.3f, (float) RandUtil.nextDouble(0.6, 1)));
glitter.setLifetime(RandUtil.nextInt(10, 20));
glitter.setScaleFunction(new InterpScale(1, 0));
glitter.setMotion(new Vec3d(RandUtil.nextDouble(-0.1, 0.1), RandUtil.nextDouble(-0.1, 0.1), RandUtil.nextDouble(-0.1, 0.1)));
});
}
}
use of com.teamwizardry.wizardry.api.spell.module.ModuleInstanceEffect in project Wizardry by TeamWizardry.
the class ModuleEffectSonic method run.
@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;
}
use of com.teamwizardry.wizardry.api.spell.module.ModuleInstanceEffect in project Wizardry by TeamWizardry.
the class ModuleEffectZoom method run.
@Override
public boolean run(@NotNull World world, ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
Entity entityHit = spell.getVictim(world);
Vec3d look = spell.getData(LOOK);
Vec3d origin = spell.getData(ORIGIN);
if (entityHit == null)
return true;
else {
if (!spellRing.taxCaster(world, spell, true))
return false;
if (look == null)
return true;
if (origin == null)
return true;
double range = spellRing.getAttributeValue(world, AttributeRegistry.RANGE, spell);
RayTraceResult trace = new RayTrace(world, look, origin, range).setEntityFilter(input -> input != 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, 2, 1, true, false));
((EntityLivingBase) entityHit).addPotionEffect(new PotionEffect(ModPotions.NULL_MOVEMENT, 2, 1, true, false));
}
return true;
}
Aggregations