Search in sources :

Example 1 with ItemChisel

use of hellfirepvp.astralsorcery.common.item.ItemChisel in project AstralSorcery by HellFirePvP.

the class EntityCrystal method hitByEntity.

@Override
public boolean hitByEntity(Entity entity) {
    if (!this.getEntityWorld().isRemote() && entity instanceof ServerPlayerEntity) {
        ItemStack held = ((ServerPlayerEntity) entity).getHeldItem(Hand.MAIN_HAND);
        if (!held.isEmpty() && held.getItem() instanceof ItemChisel) {
            ItemStack thisStack = this.getItem();
            if (!thisStack.isEmpty() && thisStack.getItem() instanceof ItemCrystalBase) {
                CrystalAttributes thisAttributes = ((ItemCrystalBase) thisStack.getItem()).getAttributes(thisStack);
                if (thisAttributes != null) {
                    // TODO chipping sound ?
                    boolean doDamage = false;
                    if (rand.nextFloat() < 0.35F) {
                        int fortuneLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, held);
                        doDamage = this.splitCrystal(thisAttributes, fortuneLevel);
                    }
                    if (doDamage || rand.nextFloat() < 0.35F) {
                        held.damageItem(1, (PlayerEntity) entity, (player) -> player.sendBreakAnimation(Hand.MAIN_HAND));
                    }
                }
            }
        }
    }
    return true;
}
Also used : CrystalAttributes(hellfirepvp.astralsorcery.common.crystal.CrystalAttributes) ItemChisel(hellfirepvp.astralsorcery.common.item.ItemChisel) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ItemCrystalBase(hellfirepvp.astralsorcery.common.item.crystal.ItemCrystalBase) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ItemChisel

use of hellfirepvp.astralsorcery.common.item.ItemChisel in project AstralSorcery by HellFirePvP.

the class EntityStarmetal method hitByEntity.

@Override
public boolean hitByEntity(Entity entity) {
    if (!this.getEntityWorld().isRemote() && entity instanceof ServerPlayerEntity) {
        ItemStack held = ((ServerPlayerEntity) entity).getHeldItem(Hand.MAIN_HAND);
        if (!held.isEmpty() && held.getItem() instanceof ItemChisel) {
            ItemStack thisStack = this.getItem();
            if (!thisStack.isEmpty() && thisStack.getItem() instanceof ItemStarmetalIngot) {
                boolean doDamage = false;
                if (rand.nextFloat() < 0.4F) {
                    int fortuneLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, held);
                    doDamage = this.createStardust(fortuneLevel);
                }
                if (doDamage || rand.nextFloat() < 0.35F) {
                    held.damageItem(1, (PlayerEntity) entity, (player) -> player.sendBreakAnimation(Hand.MAIN_HAND));
                }
            }
        }
    }
    return true;
}
Also used : ItemStarmetalIngot(hellfirepvp.astralsorcery.common.item.ItemStarmetalIngot) ItemChisel(hellfirepvp.astralsorcery.common.item.ItemChisel) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemChisel (hellfirepvp.astralsorcery.common.item.ItemChisel)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 ItemStack (net.minecraft.item.ItemStack)2 CrystalAttributes (hellfirepvp.astralsorcery.common.crystal.CrystalAttributes)1 ItemStarmetalIngot (hellfirepvp.astralsorcery.common.item.ItemStarmetalIngot)1 ItemCrystalBase (hellfirepvp.astralsorcery.common.item.crystal.ItemCrystalBase)1