TheBrokenRail
4bc4821543
All checks were successful
SorceryCraft/pipeline/head This commit looks good
Update Mappings Add Lightning Spell
54 lines
1.6 KiB
Java
54 lines
1.6 KiB
Java
package com.thebrokenrail.sorcerycraft.spell;
|
|
|
|
import com.thebrokenrail.sorcerycraft.spell.api.Spell;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.LightningEntity;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.item.Items;
|
|
import net.minecraft.server.network.ServerPlayerEntity;
|
|
import net.minecraft.server.world.ServerWorld;
|
|
import net.minecraft.util.Identifier;
|
|
import net.minecraft.util.hit.BlockHitResult;
|
|
import net.minecraft.util.math.Vec3d;
|
|
import net.minecraft.world.World;
|
|
|
|
public class LightningSpell extends Spell {
|
|
public LightningSpell(Identifier id, int level) {
|
|
super(id, level);
|
|
}
|
|
|
|
@Override
|
|
public void execute(World world, Entity source, Entity attacker, Entity target) {
|
|
strike(world, target.getPos(), attacker);
|
|
}
|
|
|
|
@Override
|
|
public void execute(World world, Entity source, Entity attacker, BlockHitResult hitResult) {
|
|
strike(world, hitResult.getPos(), attacker);
|
|
}
|
|
|
|
private void strike(World world, Vec3d pos, Entity attacker) {
|
|
ServerWorld serverWorld = (ServerWorld) world;
|
|
LightningEntity lightningEntity = new LightningEntity(world, pos.getX(), pos.getY(), pos.getZ(), false);
|
|
if (attacker instanceof ServerPlayerEntity) {
|
|
lightningEntity.setChanneller((ServerPlayerEntity) attacker);
|
|
}
|
|
serverWorld.addLightning(lightningEntity);
|
|
}
|
|
|
|
@Override
|
|
public int getXPCost() {
|
|
return 18;
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getItemCost() {
|
|
return new ItemStack(Items.END_ROD);
|
|
}
|
|
|
|
@Override
|
|
public int getMaxLevel() {
|
|
return 1;
|
|
}
|
|
}
|