Search in sources :

Example 1 with ArmorMaterial

use of net.minecraft.world.item.ArmorMaterial in project MoreBoots by North-West-Wind.

the class BootRecyclerBlockEntity method calculateFuelValue.

private int calculateFuelValue(ItemStack stack) {
    ArmorMaterial material = ((ArmorItem) stack.getItem()).getMaterial();
    int armor = material.getDefenseForSlot(EquipmentSlot.FEET);
    float toughness = material.getToughness();
    int enchantability = material.getEnchantmentValue();
    int enchantments = EnchantmentHelper.getEnchantments(stack).size();
    int durability = material.getDurabilityForSlot(EquipmentSlot.FEET);
    return (int) ((Math.pow(durability, 2) / 2.0 + Math.pow(armor + toughness, 4) + Math.pow(enchantability + enchantments, 4)));
}
Also used : ArmorItem(net.minecraft.world.item.ArmorItem) ArmorMaterial(net.minecraft.world.item.ArmorMaterial)

Example 2 with ArmorMaterial

use of net.minecraft.world.item.ArmorMaterial in project BladesEdge by shadowygaming.

the class MagmaArmor method evaluateArmorEffects.

private void evaluateArmorEffects(Player player) {
    for (Map.Entry<ArmorMaterial, MobEffectInstance> entry : MATERIAL_TO_EFFECT_MAP.entrySet()) {
        ArmorMaterial mapArmorMaterial = entry.getKey();
        MobEffectInstance mapStatusEffect = entry.getValue();
        if (hasCorrectArmorOn(mapArmorMaterial, player)) {
            addStatusEffectForMaterial(player, mapArmorMaterial, mapStatusEffect);
        }
    }
}
Also used : MobEffectInstance(net.minecraft.world.effect.MobEffectInstance) ArmorMaterial(net.minecraft.world.item.ArmorMaterial) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 3 with ArmorMaterial

use of net.minecraft.world.item.ArmorMaterial in project Forge-Tutorial-1.18.1 by Tutorials-By-Kaupenjoe.

the class ModArmorItem method evaluateArmorEffects.

private void evaluateArmorEffects(Player player) {
    for (Map.Entry<ArmorMaterial, MobEffectInstance> entry : MATERIAL_TO_EFFECT_MAP.entrySet()) {
        ArmorMaterial mapArmorMaterial = entry.getKey();
        MobEffectInstance mapStatusEffect = entry.getValue();
        if (hasCorrectArmorOn(mapArmorMaterial, player)) {
            addStatusEffectForMaterial(player, mapArmorMaterial, mapStatusEffect);
        }
    }
}
Also used : MobEffectInstance(net.minecraft.world.effect.MobEffectInstance) ArmorMaterial(net.minecraft.world.item.ArmorMaterial) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 4 with ArmorMaterial

use of net.minecraft.world.item.ArmorMaterial in project EdenRing by paulevsGitch.

the class BrainTreeBlock method hitLighting.

private void hitLighting(ServerLevel world, Random random, BlockPos pos) {
    List<LivingEntity> entities = world.getNearbyEntities(LivingEntity.class, TargetingConditions.forNonCombat(), null, new AABB(pos).inflate(16, 16, 16));
    if (!entities.isEmpty()) {
        LivingEntity entity = entities.get(random.nextInt(entities.size()));
        if (entity instanceof Player && ((Player) entity).isCreative()) {
            return;
        }
        MutableBlockPos mpos = pos.mutable();
        float dx = (float) (entity.getX() - pos.getX() - 0.5);
        float dy = (float) (entity.getY() - pos.getY() - 0.5);
        float dz = (float) (entity.getZ() - pos.getZ() - 0.5);
        float ax = Mth.abs(dx);
        float ay = Mth.abs(dy);
        float az = Mth.abs(dz);
        float max = MHelper.max(ax, ay, az);
        int count = Mth.ceil(max);
        dx /= count;
        dy /= count;
        dz /= count;
        boolean hit = true;
        for (int i = 2; i < count; i++) {
            mpos.set(pos.getX() + dx * i, pos.getY() + dy * i, pos.getZ() + dz * i);
            BlockState blockState = world.getBlockState(mpos);
            if (blockState.getMaterial().blocksMotion() && !(blockState.getBlock() instanceof BrainTreeBlock)) {
                hit = false;
                break;
            }
        }
        if (hit) {
            LightningRayEntity lightningRay = EdenEntities.LIGHTNING_RAY.create(world);
            lightningRay.teleportTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
            lightningRay.setEnd(entity.position());
            world.addFreshEntity(lightningRay);
            world.playLocalSound(entity.getX(), entity.getY(), entity.getZ(), SoundEvents.LIGHTNING_BOLT_IMPACT, SoundSource.WEATHER, MHelper.randRange(1.0F, 5.0F, random), MHelper.randRange(0.5F, 1.5F, random), false);
            if (entity.isInvulnerable()) {
                return;
            }
            float resistance = 0;
            Iterator<ItemStack> iterator = entity.getArmorSlots().iterator();
            while (iterator.hasNext()) {
                ItemStack stack = iterator.next();
                if (stack.getItem() instanceof ArmorItem) {
                    ArmorItem item = (ArmorItem) stack.getItem();
                    ArmorMaterial material = item.getMaterial();
                    for (ArmorMaterial m : PROTECTIVE) {
                        if (material == m) {
                            resistance += 0.25F;
                            break;
                        }
                    }
                }
            }
            if (resistance < 1) {
                entity.hurt(DamageSource.LIGHTNING_BOLT, (1 - resistance) * 3F);
            }
        }
    }
}
Also used : Player(net.minecraft.world.entity.player.Player) LivingEntity(net.minecraft.world.entity.LivingEntity) ArmorItem(net.minecraft.world.item.ArmorItem) BlockState(net.minecraft.world.level.block.state.BlockState) LightningRayEntity(paulevs.edenring.entities.LightningRayEntity) ArmorMaterial(net.minecraft.world.item.ArmorMaterial) ItemStack(net.minecraft.world.item.ItemStack) MutableBlockPos(net.minecraft.core.BlockPos.MutableBlockPos) AABB(net.minecraft.world.phys.AABB)

Aggregations

ArmorMaterial (net.minecraft.world.item.ArmorMaterial)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 Map (java.util.Map)2 MobEffectInstance (net.minecraft.world.effect.MobEffectInstance)2 ArmorItem (net.minecraft.world.item.ArmorItem)2 MutableBlockPos (net.minecraft.core.BlockPos.MutableBlockPos)1 LivingEntity (net.minecraft.world.entity.LivingEntity)1 Player (net.minecraft.world.entity.player.Player)1 ItemStack (net.minecraft.world.item.ItemStack)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 AABB (net.minecraft.world.phys.AABB)1 LightningRayEntity (paulevs.edenring.entities.LightningRayEntity)1