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

55 lines
1.7 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;
import com.minelittlepony.unicopia.magic.IDispenceable;
import com.minelittlepony.unicopia.magic.IMagicEffect;
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 {
@Override
2020-01-27 11:05:22 +01:00
public CastResult onDispenseSpell(BlockPointer source, ItemStack stack, IDispenceable 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-01-27 11:05:22 +01:00
public CastResult onCastSpell(ItemUsageContext context, IMagicEffect effect) {
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;
}
}