Unicopia/src/main/java/com/minelittlepony/unicopia/magic/ITossedEffect.java

69 lines
2.2 KiB
Java
Raw Normal View History

2020-01-16 12:35:46 +01:00
package com.minelittlepony.unicopia.magic;
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;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
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;
import net.minecraft.world.World;
2019-03-12 21:10:48 +01:00
/**
* Magic effects that can be thrown.
*/
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.
*/
default ItemStack getCastAppearance(ICaster<?> caster) {
2020-01-16 12:35:46 +01:00
Item item = getAffinity() == Affinity.BAD ? UItems.curse : UItems.spell;
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) {
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-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());
projectile.setItem(getCastAppearance(caster));
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);
2020-01-16 12:35:46 +01:00
projectile.spawn(world);
2019-03-11 19:50:06 +01:00
return projectile;
}
2019-03-11 19:50:06 +01:00
return null;
}
}