2019-03-05 13:29:16 +01:00
|
|
|
package com.minelittlepony.unicopia.spell;
|
|
|
|
|
2019-03-11 19:50:06 +01:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2019-03-05 13:29:16 +01:00
|
|
|
import com.minelittlepony.unicopia.entity.EntityProjectile;
|
|
|
|
import com.minelittlepony.unicopia.init.UItems;
|
|
|
|
import com.minelittlepony.unicopia.tossable.ITossable;
|
|
|
|
|
|
|
|
import net.minecraft.entity.Entity;
|
2019-03-11 19:50:06 +01:00
|
|
|
import net.minecraft.init.SoundEvents;
|
2019-03-05 14:15:34 +01:00
|
|
|
import net.minecraft.item.Item;
|
2019-03-05 13:29:16 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.SoundCategory;
|
2019-03-11 19:50:06 +01:00
|
|
|
import net.minecraft.util.SoundEvent;
|
2019-03-05 13:29:16 +01:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
public interface ITossedEffect extends IMagicEffect, ITossable<ICaster<?>> {
|
|
|
|
|
2019-03-11 19:50:06 +01:00
|
|
|
default SoundEvent getThrowSound(ICaster<?> caster) {
|
|
|
|
return SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT;
|
|
|
|
}
|
|
|
|
|
2019-03-05 17:42:36 +01:00
|
|
|
default ItemStack getCastAppearance(ICaster<?> caster) {
|
|
|
|
Item item = this.getAffinity() == SpellAffinity.BAD ? UItems.curse : UItems.spell;
|
|
|
|
|
|
|
|
return SpellRegistry.instance().enchantStack(new ItemStack(item), getName());
|
|
|
|
}
|
|
|
|
|
2019-03-11 19:50:06 +01:00
|
|
|
@Nullable
|
|
|
|
default EntityProjectile toss(ICaster<?> caster) {
|
2019-03-05 13:29:16 +01:00
|
|
|
World world = caster.getWorld();
|
|
|
|
|
|
|
|
Entity entity = caster.getOwner();
|
|
|
|
|
2019-03-11 19:50:06 +01:00
|
|
|
world.playSound(null, entity.posX, entity.posY, entity.posZ, getThrowSound(caster), SoundCategory.NEUTRAL, 0.7F, 0.4F / (world.rand.nextFloat() * 0.4F + 0.8F));
|
2019-03-05 13:29:16 +01:00
|
|
|
|
|
|
|
if (!world.isRemote) {
|
|
|
|
EntityProjectile projectile = new EntityProjectile(world, caster.getOwner());
|
|
|
|
|
2019-03-05 17:42:36 +01:00
|
|
|
projectile.setItem(getCastAppearance(caster));
|
2019-03-05 13:29:16 +01:00
|
|
|
projectile.setThrowDamage(getThrowDamage(caster));
|
|
|
|
projectile.setOwner(caster.getOwner());
|
|
|
|
projectile.setEffect(this);
|
2019-03-05 15:09:17 +01:00
|
|
|
projectile.setHydrophobic();
|
2019-03-05 13:29:16 +01:00
|
|
|
projectile.shoot(entity, entity.rotationPitch, entity.rotationYaw, 0, 1.5F, 1);
|
|
|
|
|
|
|
|
world.spawnEntity(projectile);
|
2019-03-11 19:50:06 +01:00
|
|
|
|
|
|
|
return projectile;
|
2019-03-05 13:29:16 +01:00
|
|
|
}
|
2019-03-11 19:50:06 +01:00
|
|
|
|
|
|
|
return null;
|
2019-03-05 13:29:16 +01:00
|
|
|
}
|
|
|
|
}
|