Unicopia/src/main/java/com/minelittlepony/unicopia/item/CursedMagicGemItem.java

59 lines
1.8 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia.item;
2020-01-17 14:27:26 +01:00
import com.minelittlepony.unicopia.magic.Affinity;
import com.minelittlepony.unicopia.magic.CastResult;
2020-04-15 18:12:00 +02:00
import com.minelittlepony.unicopia.magic.DispenceableMagicEffect;
import com.minelittlepony.unicopia.magic.MagicEffect;
import com.minelittlepony.unicopia.util.MagicalDamageSource;
2020-01-17 14:27:26 +01:00
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.util.math.BlockPointer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.explosion.Explosion.DestructionType;
public class CursedMagicGemItem extends MagicGemItem {
public CursedMagicGemItem(Settings settings) {
super(settings);
}
2020-01-17 14:27:26 +01:00
@Override
2020-04-15 18:12:00 +02:00
public CastResult onDispenseSpell(BlockPointer source, ItemStack stack, DispenceableMagicEffect effect) {
2020-01-17 14:27:26 +01:00
BlockPos pos = source.getBlockPos();
World world = source.getWorld();
2020-01-27 11:05:22 +01:00
CastResult result = super.onDispenseSpell(source, stack, effect);
2020-01-17 14:27:26 +01:00
2020-01-27 11:05:22 +01:00
if (result != CastResult.NONE) {
2020-01-17 14:27:26 +01:00
if (world.random.nextInt(200) == 0) {
float strength = world.random.nextFloat() * 100;
world.createExplosion(null, pos.getX(), pos.getY(), pos.getZ(), strength, DestructionType.DESTROY);
2020-01-27 11:05:22 +01:00
return CastResult.NONE;
2020-01-17 14:27:26 +01:00
}
}
return result;
}
@Override
2020-04-15 18:12:00 +02:00
public CastResult onCastSpell(ItemUsageContext context, MagicEffect effect) {
2020-01-27 11:05:22 +01:00
CastResult result = super.onCastSpell(context, effect);
2020-01-17 14:27:26 +01:00
2020-01-27 11:05:22 +01:00
if (result != CastResult.NONE) {
2020-01-17 14:27:26 +01:00
context.getPlayer().damage(MagicalDamageSource.causePlayerDamage("corruption", context.getPlayer()), 1);
}
return result;
}
@Override
public Affinity getAffinity() {
return Affinity.BAD;
}
}