2020-01-16 12:35:46 +01:00
|
|
|
package com.minelittlepony.unicopia.magic;
|
2019-03-05 13:29:16 +01:00
|
|
|
|
2019-03-11 19:50:06 +01:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
import com.minelittlepony.unicopia.UItems;
|
2020-01-17 14:27:26 +01:00
|
|
|
import com.minelittlepony.unicopia.entity.AdvancedProjectileEntity;
|
2020-01-16 12:35:46 +01:00
|
|
|
import com.minelittlepony.unicopia.magic.spells.SpellRegistry;
|
|
|
|
import com.minelittlepony.unicopia.projectile.IAdvancedProjectile;
|
|
|
|
import com.minelittlepony.unicopia.projectile.ITossable;
|
2019-03-05 13:29:16 +01:00
|
|
|
|
|
|
|
import net.minecraft.entity.Entity;
|
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;
|
2020-01-16 12:35:46 +01:00
|
|
|
import net.minecraft.sound.SoundCategory;
|
|
|
|
import net.minecraft.sound.SoundEvent;
|
|
|
|
import net.minecraft.sound.SoundEvents;
|
2019-03-05 13:29:16 +01:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2019-03-12 21:10:48 +01:00
|
|
|
/**
|
|
|
|
* Magic effects that can be thrown.
|
|
|
|
*/
|
2019-03-05 13:29:16 +01:00
|
|
|
public interface ITossedEffect extends IMagicEffect, ITossable<ICaster<?>> {
|
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
@Override
|
2019-03-11 19:50:06 +01:00
|
|
|
default SoundEvent getThrowSound(ICaster<?> caster) {
|
|
|
|
return SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT;
|
|
|
|
}
|
|
|
|
|
2019-03-12 21:10:48 +01:00
|
|
|
/**
|
|
|
|
* Gets the appearance to be used when projecting this spell.
|
|
|
|
*/
|
2019-03-05 17:42:36 +01:00
|
|
|
default ItemStack getCastAppearance(ICaster<?> caster) {
|
2020-01-16 12:35:46 +01:00
|
|
|
Item item = getAffinity() == Affinity.BAD ? UItems.curse : UItems.spell;
|
2019-03-05 17:42:36 +01:00
|
|
|
|
|
|
|
return SpellRegistry.instance().enchantStack(new ItemStack(item), getName());
|
|
|
|
}
|
|
|
|
|
2019-03-12 21:10:48 +01:00
|
|
|
/**
|
|
|
|
* Projects this spell.
|
|
|
|
*
|
|
|
|
* Returns the resulting projectile entity for customization (or null if on the client).
|
|
|
|
*/
|
2019-03-11 19:50:06 +01:00
|
|
|
@Nullable
|
2020-01-16 12:35:46 +01:00
|
|
|
default IAdvancedProjectile toss(ICaster<?> caster) {
|
2019-03-05 13:29:16 +01:00
|
|
|
World world = caster.getWorld();
|
|
|
|
|
|
|
|
Entity entity = caster.getOwner();
|
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
world.playSound(null, entity.x, entity.y, entity.z, getThrowSound(caster), SoundCategory.NEUTRAL, 0.7F, 0.4F / (world.random.nextFloat() * 0.4F + 0.8F));
|
2019-03-05 13:29:16 +01:00
|
|
|
|
2019-03-12 21:10:48 +01:00
|
|
|
if (caster.isLocal()) {
|
2020-01-16 12:35:46 +01:00
|
|
|
IAdvancedProjectile projectile = new AdvancedProjectileEntity(null, world, caster.getOwner());
|
2019-03-05 13:29:16 +01:00
|
|
|
|
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();
|
2020-01-16 12:35:46 +01:00
|
|
|
projectile.launch(entity, entity.pitch, entity.yaw, 0, 1.5F, 1);
|
2019-03-05 13:29:16 +01:00
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
projectile.spawn(world);
|
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
|
|
|
}
|
|
|
|
}
|