the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 94 lines 2.7 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.damagesource.h" 3#include "net.minecraft.world.item.enchantment.h" 4#include "net.minecraft.world.entity.h" 5#include "ProtectionEnchantment.h" 6 7const int ProtectionEnchantment::names[] = {IDS_ENCHANTMENT_PROTECT_ALL, IDS_ENCHANTMENT_PROTECT_FIRE, IDS_ENCHANTMENT_PROTECT_FALL, IDS_ENCHANTMENT_PROTECT_EXPLOSION, IDS_ENCHANTMENT_PROTECT_PROJECTILE}; 8const int ProtectionEnchantment::minCost[] = {1, 10, 5, 5, 3}; 9const int ProtectionEnchantment::levelCost[] = {11, 8, 6, 8, 6}; 10const int ProtectionEnchantment::levelCostSpan[] = {20, 12, 10, 12, 15}; 11 12ProtectionEnchantment::ProtectionEnchantment(int id, int frequency, int type) : Enchantment(id, frequency, EnchantmentCategory::armor), type(type) 13{ 14 if (type == FALL) 15 { 16 category = EnchantmentCategory::armor_feet; 17 } 18} 19 20int ProtectionEnchantment::getMinCost(int level) 21{ 22 return minCost[type] + (level - 1) * levelCost[type]; 23} 24 25int ProtectionEnchantment::getMaxCost(int level) 26{ 27 return getMinCost(level) + levelCostSpan[type]; 28} 29 30int ProtectionEnchantment::getMaxLevel() 31{ 32 return 4; 33} 34 35int ProtectionEnchantment::getDamageProtection(int level, DamageSource *source) 36{ 37 if (source->isBypassInvul()) return 0; 38 39 float protect = (6 + level * level) / 3.0f; 40 41 if (type == ALL) return Mth::floor(protect * 0.75f); 42 if (type == FIRE && source->isFire()) return Mth::floor(protect * 1.25f); 43 if (type == FALL && source == DamageSource::fall) return Mth::floor(protect * 2.5f); 44 if (type == EXPLOSION && source->isExplosion() ) return Mth::floor(protect * 1.5f); 45 if (type == PROJECTILE && source->isProjectile()) return Mth::floor(protect * 1.5f); 46 return 0; 47} 48 49int ProtectionEnchantment::getDescriptionId() 50{ 51 return names[type]; 52} 53 54bool ProtectionEnchantment::isCompatibleWith(Enchantment *other) const 55{ 56 ProtectionEnchantment *pe = dynamic_cast<ProtectionEnchantment *>( other ); 57 if (pe != NULL) 58 { 59 if (pe->type == type) 60 { 61 return false; 62 } 63 if (type == FALL || pe->type == FALL) 64 { 65 return true; 66 } 67 return false; 68 } 69 return Enchantment::isCompatibleWith(other); 70} 71 72int ProtectionEnchantment::getFireAfterDampener(shared_ptr<Entity> entity, int time) 73{ 74 int level = EnchantmentHelper::getEnchantmentLevel(Enchantment::fireProtection->id, entity->getEquipmentSlots()); 75 76 if (level > 0) 77 { 78 time -= Mth::floor(time * (level * 0.15f)); 79 } 80 81 return time; 82} 83 84double ProtectionEnchantment::getExplosionKnockbackAfterDampener(shared_ptr<Entity> entity, double power) 85{ 86 int level = EnchantmentHelper::getEnchantmentLevel(Enchantment::explosionProtection->id, entity->getEquipmentSlots()); 87 88 if (level > 0) 89 { 90 power -= Mth::floor(power * (level * 0.15f)); 91 } 92 93 return power; 94}