TU19: merge Minecraft.World/Enchantments

This commit is contained in:
Tropical 2026-03-21 15:55:35 -05:00
parent 7d05b36f85
commit 405a87e078
9 changed files with 71 additions and 71 deletions

View file

@ -23,15 +23,16 @@ int DamageEnchantment::getMaxCost(int level) {
int DamageEnchantment::getMaxLevel() { return 5; } int DamageEnchantment::getMaxLevel() { return 5; }
int DamageEnchantment::getDamageBonus(int level, std::shared_ptr<Mob> target) { float DamageEnchantment::getDamageBonus(int level,
std::shared_ptr<LivingEntity> target) {
if (type == ALL) { if (type == ALL) {
return Mth::floor(level * 2.75f); return level * 1.25f;
} }
if (type == UNDEAD && target->getMobType() == UNDEAD) { if (type == UNDEAD && target->getMobType() == UNDEAD) {
return Mth::floor(level * 4.5f); return level * 2.5f;
} }
if (type == ARTHROPODS && target->getMobType() == ARTHROPOD) { if (type == ARTHROPODS && target->getMobType() == ARTHROPOD) {
return Mth::floor(level * 4.5f); return level * 2.5f;
} }
return 0; return 0;
} }

View file

@ -22,7 +22,8 @@ public:
virtual int getMinCost(int level); virtual int getMinCost(int level);
virtual int getMaxCost(int level); virtual int getMaxCost(int level);
virtual int getMaxLevel(); virtual int getMaxLevel();
virtual int getDamageBonus(int level, std::shared_ptr<Mob> target); virtual float getDamageBonus(int level,
std::shared_ptr<LivingEntity> target);
virtual int getDescriptionId(); virtual int getDescriptionId();
virtual bool isCompatibleWith(Enchantment* other) const; virtual bool isCompatibleWith(Enchantment* other) const;
virtual bool canEnchant(std::shared_ptr<ItemInstance> item); virtual bool canEnchant(std::shared_ptr<ItemInstance> item);

View file

@ -1,5 +1,6 @@
#include "../Platform/stdafx.h" #include "../Platform/stdafx.h"
#include "../Headers/net.minecraft.world.item.enchantment.h" #include "../Headers/net.minecraft.world.item.enchantment.h"
#include "../Headers/net.minecraft.world.item.h"
#include "Enchantment.h" #include "Enchantment.h"
// Enchantment *Enchantment::enchantments[256]; // Enchantment *Enchantment::enchantments[256];
@ -119,8 +120,9 @@ int Enchantment::getDamageProtection(int level, DamageSource* source) {
return 0; return 0;
} }
int Enchantment::getDamageBonus(int level, std::shared_ptr<Mob> target) { float Enchantment::getDamageBonus(int level,
return 0; std::shared_ptr<LivingEntity> target) {
return 0.0f;
} }
bool Enchantment::isCompatibleWith(Enchantment* other) const { bool Enchantment::isCompatibleWith(Enchantment* other) const {
@ -134,14 +136,12 @@ Enchantment* Enchantment::setDescriptionId(int id) {
int Enchantment::getDescriptionId() { return descriptionId; } int Enchantment::getDescriptionId() { return descriptionId; }
std::wstring Enchantment::getFullname(int level, std::wstring& unformatted) { HtmlString Enchantment::getFullname(int level) {
wchar_t formatted[256]; wchar_t formatted[256];
swprintf(formatted, 256, L"%ls %ls", app.GetString(getDescriptionId()), swprintf(formatted, 256, L"%ls %ls", app.GetString(getDescriptionId()),
getLevelString(level).c_str()); getLevelString(level).c_str());
unformatted = formatted;
swprintf(formatted, 256, L"<font color=\"#%08x\">%ls</font>", return HtmlString(formatted, eHTMLColor_f);
app.GetHTMLColour(eHTMLColor_f), unformatted.c_str());
return formatted;
} }
bool Enchantment::canEnchant(std::shared_ptr<ItemInstance> item) { bool Enchantment::canEnchant(std::shared_ptr<ItemInstance> item) {

View file

@ -74,12 +74,12 @@ public:
virtual int getMinCost(int level); virtual int getMinCost(int level);
virtual int getMaxCost(int level); virtual int getMaxCost(int level);
virtual int getDamageProtection(int level, DamageSource* source); virtual int getDamageProtection(int level, DamageSource* source);
virtual int getDamageBonus(int level, std::shared_ptr<Mob> target); virtual float getDamageBonus(int level,
std::shared_ptr<LivingEntity> target);
virtual bool isCompatibleWith(Enchantment* other) const; virtual bool isCompatibleWith(Enchantment* other) const;
virtual Enchantment* setDescriptionId(int id); virtual Enchantment* setDescriptionId(int id);
virtual int getDescriptionId(); virtual int getDescriptionId();
virtual std::wstring getFullname( virtual HtmlString getFullname(int level);
int level, std::wstring& unformatted); // 4J Stu added unformatted
virtual bool canEnchant(std::shared_ptr<ItemInstance> item); virtual bool canEnchant(std::shared_ptr<ItemInstance> item);
private: private:

View file

@ -87,6 +87,7 @@ void EnchantmentHelper::setEnchantments(
int EnchantmentHelper::getEnchantmentLevel(int enchantmentId, int EnchantmentHelper::getEnchantmentLevel(int enchantmentId,
ItemInstanceArray inventory) { ItemInstanceArray inventory) {
if (inventory.data == NULL) return 0;
int bestLevel = 0; int bestLevel = 0;
// for (ItemInstance piece : inventory) // for (ItemInstance piece : inventory)
for (unsigned int i = 0; i < inventory.length; ++i) { for (unsigned int i = 0; i < inventory.length; ++i) {
@ -142,12 +143,12 @@ EnchantmentHelper::GetDamageProtectionIteration
* @param source * @param source
* @return * @return
*/ */
int EnchantmentHelper::getDamageProtection(std::shared_ptr<Inventory> inventory, int EnchantmentHelper::getDamageProtection(ItemInstanceArray armor,
DamageSource* source) { DamageSource* source) {
getDamageProtectionIteration.sum = 0; getDamageProtectionIteration.sum = 0;
getDamageProtectionIteration.source = source; getDamageProtectionIteration.source = source;
runIterationOnInventory(getDamageProtectionIteration, inventory->armor); runIterationOnInventory(getDamageProtectionIteration, armor);
if (getDamageProtectionIteration.sum > 25) { if (getDamageProtectionIteration.sum > 25) {
getDamageProtectionIteration.sum = 25; getDamageProtectionIteration.sum = 25;
@ -172,75 +173,72 @@ EnchantmentHelper::GetDamageBonusIteration
* @param target * @param target
* @return * @return
*/ */
int EnchantmentHelper::getDamageBonus(std::shared_ptr<Inventory> inventory, float EnchantmentHelper::getDamageBonus(std::shared_ptr<LivingEntity> source,
std::shared_ptr<Mob> target) { std::shared_ptr<LivingEntity> target) {
getDamageBonusIteration.sum = 0; getDamageBonusIteration.sum = 0;
getDamageBonusIteration.target = target; getDamageBonusIteration.target = target;
runIterationOnItem(getDamageBonusIteration, inventory->getSelected()); runIterationOnItem(getDamageBonusIteration, source->getCarriedItem());
if (getDamageBonusIteration.sum > 0) { return getDamageBonusIteration.sum;
return 1 + random.nextInt(getDamageBonusIteration.sum);
}
return 0;
} }
int EnchantmentHelper::getKnockbackBonus(std::shared_ptr<Inventory> inventory, int EnchantmentHelper::getKnockbackBonus(std::shared_ptr<LivingEntity> source,
std::shared_ptr<Mob> target) { std::shared_ptr<LivingEntity> target) {
return getEnchantmentLevel(Enchantment::knockback->id, return getEnchantmentLevel(Enchantment::knockback->id,
inventory->getSelected()); source->getCarriedItem());
} }
int EnchantmentHelper::getFireAspect(std::shared_ptr<Mob> source) { int EnchantmentHelper::getFireAspect(std::shared_ptr<LivingEntity> source) {
return getEnchantmentLevel(Enchantment::fireAspect->id, return getEnchantmentLevel(Enchantment::fireAspect->id,
source->getCarriedItem()); source->getCarriedItem());
} }
int EnchantmentHelper::getOxygenBonus(std::shared_ptr<Inventory> inventory) { int EnchantmentHelper::getOxygenBonus(std::shared_ptr<LivingEntity> source) {
return getEnchantmentLevel(Enchantment::drownProtection->id, return getEnchantmentLevel(Enchantment::drownProtection->id,
inventory->armor); source->getEquipmentSlots());
} }
int EnchantmentHelper::getDiggingBonus(std::shared_ptr<Inventory> inventory) { int EnchantmentHelper::getDiggingBonus(std::shared_ptr<LivingEntity> source) {
return getEnchantmentLevel(Enchantment::diggingBonus->id, return getEnchantmentLevel(Enchantment::diggingBonus->id,
inventory->getSelected()); source->getCarriedItem());
} }
int EnchantmentHelper::getDigDurability(std::shared_ptr<Inventory> inventory) { int EnchantmentHelper::getDigDurability(std::shared_ptr<LivingEntity> source) {
return getEnchantmentLevel(Enchantment::digDurability->id, return getEnchantmentLevel(Enchantment::digDurability->id,
inventory->getSelected()); source->getCarriedItem());
} }
bool EnchantmentHelper::hasSilkTouch(std::shared_ptr<Inventory> inventory) { bool EnchantmentHelper::hasSilkTouch(std::shared_ptr<LivingEntity> source) {
return getEnchantmentLevel(Enchantment::untouching->id, return getEnchantmentLevel(Enchantment::untouching->id,
inventory->getSelected()) > 0; source->getCarriedItem()) > 0;
} }
int EnchantmentHelper::getDiggingLootBonus( int EnchantmentHelper::getDiggingLootBonus(
std::shared_ptr<Inventory> inventory) { std::shared_ptr<LivingEntity> source) {
return getEnchantmentLevel(Enchantment::resourceBonus->id, return getEnchantmentLevel(Enchantment::resourceBonus->id,
inventory->getSelected()); source->getCarriedItem());
} }
int EnchantmentHelper::getKillingLootBonus( int EnchantmentHelper::getKillingLootBonus(
std::shared_ptr<Inventory> inventory) { std::shared_ptr<LivingEntity> source) {
return getEnchantmentLevel(Enchantment::lootBonus->id, return getEnchantmentLevel(Enchantment::lootBonus->id,
inventory->getSelected()); source->getCarriedItem());
} }
bool EnchantmentHelper::hasWaterWorkerBonus( bool EnchantmentHelper::hasWaterWorkerBonus(
std::shared_ptr<Inventory> inventory) { std::shared_ptr<LivingEntity> source) {
return getEnchantmentLevel(Enchantment::waterWorker->id, inventory->armor) > return getEnchantmentLevel(Enchantment::waterWorker->id,
0; source->getEquipmentSlots()) > 0;
} }
int EnchantmentHelper::getArmorThorns(std::shared_ptr<Mob> source) { int EnchantmentHelper::getArmorThorns(std::shared_ptr<LivingEntity> source) {
return getEnchantmentLevel(Enchantment::thorns->id, return getEnchantmentLevel(Enchantment::thorns->id,
source->getEquipmentSlots()); source->getEquipmentSlots());
} }
std::shared_ptr<ItemInstance> EnchantmentHelper::getRandomItemWith( std::shared_ptr<ItemInstance> EnchantmentHelper::getRandomItemWith(
Enchantment* enchantment, std::shared_ptr<Mob> source) { Enchantment* enchantment, std::shared_ptr<LivingEntity> source) {
ItemInstanceArray items = source->getEquipmentSlots(); ItemInstanceArray items = source->getEquipmentSlots();
for (unsigned int i = 0; i < items.length; ++i) { for (unsigned int i = 0; i < items.length; ++i) {
std::shared_ptr<ItemInstance> item = items[i]; std::shared_ptr<ItemInstance> item = items[i];

View file

@ -50,14 +50,14 @@ private:
* @return * @return
*/ */
public: public:
static int getDamageProtection(std::shared_ptr<Inventory> inventory, static int getDamageProtection(ItemInstanceArray armor,
DamageSource* source); DamageSource* source);
private: private:
class GetDamageBonusIteration : public EnchantmentIterationMethod { class GetDamageBonusIteration : public EnchantmentIterationMethod {
public: public:
int sum; float sum;
std::shared_ptr<Mob> target; std::shared_ptr<LivingEntity> target;
virtual void doEnchantment(Enchantment* enchantment, int level); virtual void doEnchantment(Enchantment* enchantment, int level);
}; };
@ -71,21 +71,21 @@ private:
* @return * @return
*/ */
public: public:
static int getDamageBonus(std::shared_ptr<Inventory> inventory, static float getDamageBonus(std::shared_ptr<LivingEntity> source,
std::shared_ptr<Mob> target); std::shared_ptr<LivingEntity> target);
static int getKnockbackBonus(std::shared_ptr<Inventory> inventory, static int getKnockbackBonus(std::shared_ptr<LivingEntity> source,
std::shared_ptr<Mob> target); std::shared_ptr<LivingEntity> target);
static int getFireAspect(std::shared_ptr<Mob> source); static int getFireAspect(std::shared_ptr<LivingEntity> source);
static int getOxygenBonus(std::shared_ptr<Inventory> inventory); static int getOxygenBonus(std::shared_ptr<LivingEntity> source);
static int getDiggingBonus(std::shared_ptr<Inventory> inventory); static int getDiggingBonus(std::shared_ptr<LivingEntity> source);
static int getDigDurability(std::shared_ptr<Inventory> inventory); static int getDigDurability(std::shared_ptr<LivingEntity> source);
static bool hasSilkTouch(std::shared_ptr<Inventory> inventory); static bool hasSilkTouch(std::shared_ptr<LivingEntity> source);
static int getDiggingLootBonus(std::shared_ptr<Inventory> inventory); static int getDiggingLootBonus(std::shared_ptr<LivingEntity> source);
static int getKillingLootBonus(std::shared_ptr<Inventory> inventory); static int getKillingLootBonus(std::shared_ptr<LivingEntity> source);
static bool hasWaterWorkerBonus(std::shared_ptr<Inventory> inventory); static bool hasWaterWorkerBonus(std::shared_ptr<LivingEntity> source);
static int getArmorThorns(std::shared_ptr<Mob> source); static int getArmorThorns(std::shared_ptr<LivingEntity> source);
static std::shared_ptr<ItemInstance> getRandomItemWith( static std::shared_ptr<ItemInstance> getRandomItemWith(
Enchantment* enchantment, std::shared_ptr<Mob> source); Enchantment* enchantment, std::shared_ptr<LivingEntity> source);
/** /**
* *

View file

@ -39,7 +39,7 @@ int ProtectionEnchantment::getDamageProtection(int level,
if (type == FIRE && source->isFire()) return Mth::floor(protect * 1.25f); if (type == FIRE && source->isFire()) return Mth::floor(protect * 1.25f);
if (type == FALL && source == DamageSource::fall) if (type == FALL && source == DamageSource::fall)
return Mth::floor(protect * 2.5f); return Mth::floor(protect * 2.5f);
if (type == EXPLOSION && source == DamageSource::explosion) if (type == EXPLOSION && source->isExplosion())
return Mth::floor(protect * 1.5f); return Mth::floor(protect * 1.5f);
if (type == PROJECTILE && source->isProjectile()) if (type == PROJECTILE && source->isProjectile())
return Mth::floor(protect * 1.5f); return Mth::floor(protect * 1.5f);
@ -51,10 +51,10 @@ int ProtectionEnchantment::getDescriptionId() { return names[type]; }
bool ProtectionEnchantment::isCompatibleWith(Enchantment* other) const { bool ProtectionEnchantment::isCompatibleWith(Enchantment* other) const {
ProtectionEnchantment* pe = dynamic_cast<ProtectionEnchantment*>(other); ProtectionEnchantment* pe = dynamic_cast<ProtectionEnchantment*>(other);
if (pe != NULL) { if (pe != NULL) {
if (pe->type == this->type) { if (pe->type == type) {
return false; return false;
} }
if (this->type == FALL || pe->type == FALL) { if (type == FALL || pe->type == FALL) {
return true; return true;
} }
return false; return false;

View file

@ -39,9 +39,9 @@ int ThornsEnchantment::getDamage(int level, Random* random) {
} }
} }
void ThornsEnchantment::doThornsAfterAttack(std::shared_ptr<Entity> source, void ThornsEnchantment::doThornsAfterAttack(
std::shared_ptr<Mob> target, std::shared_ptr<Entity> source, std::shared_ptr<LivingEntity> target,
Random* random) { Random* random) {
int level = EnchantmentHelper::getArmorThorns(target); int level = EnchantmentHelper::getArmorThorns(target);
std::shared_ptr<ItemInstance> item = std::shared_ptr<ItemInstance> item =
EnchantmentHelper::getRandomItemWith(Enchantment::thorns, target); EnchantmentHelper::getRandomItemWith(Enchantment::thorns, target);
@ -51,11 +51,11 @@ void ThornsEnchantment::doThornsAfterAttack(std::shared_ptr<Entity> source,
source->playSound(eSoundType_DAMAGE_THORNS, .5f, 1.0f); source->playSound(eSoundType_DAMAGE_THORNS, .5f, 1.0f);
if (item != NULL) { if (item != NULL) {
item->hurt(3, target); item->hurtAndBreak(3, target);
} }
} else { } else {
if (item != NULL) { if (item != NULL) {
item->hurt(1, target); item->hurtAndBreak(1, target);
} }
} }
} }

View file

@ -16,6 +16,6 @@ public:
static bool shouldHit(int level, Random* random); static bool shouldHit(int level, Random* random);
static int getDamage(int level, Random* random); static int getDamage(int level, Random* random);
static void doThornsAfterAttack(std::shared_ptr<Entity> source, static void doThornsAfterAttack(std::shared_ptr<Entity> source,
std::shared_ptr<Mob> target, std::shared_ptr<LivingEntity> target,
Random* random); Random* random);
}; };