use of am2.api.events.SpellCastingEvent in project ArsMagica2 by Mithion.
the class SpellHelper method preSpellCast.
private SpellCastingEvent.Pre preSpellCast(ItemStack stack, EntityLivingBase caster, boolean isChanneled) {
SpellRequirements reqs = SpellUtils.instance.getSpellRequirements(stack, caster);
float manaCost = reqs.manaCost;
float burnout = reqs.burnout;
ArrayList<ItemStack> reagents = reqs.reagents;
ManaCostEvent mce = new ManaCostEvent(stack, caster, manaCost, burnout);
MinecraftForge.EVENT_BUS.post(mce);
manaCost = mce.manaCost;
burnout = mce.burnout;
SpellCastingEvent.Pre event = new SpellCastingEvent().new Pre(stack, (ItemSpellBase) stack.getItem(), caster, manaCost, burnout, isChanneled);
if (MinecraftForge.EVENT_BUS.post(event)) {
event.castResult = SpellCastResult.EFFECT_FAILED;
return event;
}
event.castResult = SpellCastResult.SUCCESS;
if (!SpellUtils.instance.casterHasAllReagents(caster, reagents))
event.castResult = SpellCastResult.REAGENTS_MISSING;
if (!SpellUtils.instance.casterHasMana(caster, manaCost))
event.castResult = SpellCastResult.NOT_ENOUGH_MANA;
return event;
}
use of am2.api.events.SpellCastingEvent in project ArsMagica2 by Mithion.
the class SpellHelper method applyStackStage.
public SpellCastResult applyStackStage(ItemStack stack, EntityLivingBase caster, EntityLivingBase target, double x, double y, double z, int side, World world, boolean consumeMBR, boolean giveXP, int ticksUsed) {
if (caster.isPotionActive(BuffList.silence.id))
return SpellCastResult.SILENCED;
ItemStack parsedStack = SpellUtils.instance.constructSpellStack(stack);
if (SpellUtils.instance.numStages(parsedStack) == 0) {
return SpellCastResult.SUCCESS;
}
ISpellShape shape = SpellUtils.instance.getShapeForStage(parsedStack, 0);
ItemSpellBase item = (ItemSpellBase) parsedStack.getItem();
if (SkillTreeManager.instance.isSkillDisabled(shape))
return SpellCastResult.EFFECT_FAILED;
if (!(caster instanceof EntityPlayer)) {
consumeMBR = false;
}
SpellCastingEvent.Pre checkEvent = null;
if (consumeMBR) {
checkEvent = preSpellCast(parsedStack, caster, false);
if (checkEvent.castResult != SpellCastResult.SUCCESS) {
if (checkEvent.castResult == SpellCastResult.NOT_ENOUGH_MANA && caster.worldObj.isRemote && caster instanceof EntityPlayer) {
AMCore.proxy.flashManaBar();
}
SpellCastingEvent.Post event = new SpellCastingEvent().new Post(parsedStack, (ItemSpellBase) parsedStack.getItem(), caster, checkEvent.manaCost, checkEvent.burnout, false, checkEvent.castResult);
MinecraftForge.EVENT_BUS.post(event);
return checkEvent.castResult;
}
}
SpellCastResult result = SpellCastResult.MALFORMED_SPELL_STACK;
if (shape != null) {
result = shape.beginStackStage(item, parsedStack, caster, target, world, x, y, z, side, giveXP, ticksUsed);
if (!world.isRemote) {
AMDataWriter writer = new AMDataWriter();
writer.add(parsedStack);
writer.add(caster.getEntityId());
if (target != null) {
writer.add(true);
writer.add(target.getEntityId());
} else {
writer.add(false);
}
writer.add(x).add(y).add(z);
writer.add(side);
writer.add(ticksUsed);
AMNetHandler.INSTANCE.sendPacketToAllClientsNear(world.provider.dimensionId, x, y, z, 32, AMPacketIDs.SPELL_CAST, writer.generate());
}
}
float manaCost = 0;
float burnout = 0;
if (consumeMBR) {
manaCost = checkEvent.manaCost;
burnout = checkEvent.burnout;
if (result == SpellCastResult.SUCCESS_REDUCE_MANA) {
result = SpellCastResult.SUCCESS;
manaCost *= 0.2f;
burnout *= 0.2f;
}
}
if (result == SpellCastResult.SUCCESS) {
if (consumeMBR) {
ExtendedProperties.For(caster).deductMana(manaCost);
ExtendedProperties.For(caster).addBurnout(burnout);
}
if (world.isRemote) {
String sfx = shape.getSoundForAffinity(SpellUtils.instance.mainAffinityFor(parsedStack), parsedStack, null);
if (sfx != null) {
if (!shape.isChanneled()) {
world.playSound(caster.posX, caster.posY, caster.posZ, sfx, 0.4f, world.rand.nextFloat() * 0.1F + 0.9F, false);
} else {
// SoundHelper.instance.loopSound(world, (float)x, (float)y, (float)z, sfx, 0.6f);
}
}
}
}
SpellCastingEvent.Post event = new SpellCastingEvent().new Post(parsedStack, (ItemSpellBase) parsedStack.getItem(), caster, manaCost, burnout, false, result);
MinecraftForge.EVENT_BUS.post(event);
return result;
}
Aggregations