aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/PigZombie.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Minecraft.World/PigZombie.cpp')
-rw-r--r--Minecraft.World/PigZombie.cpp159
1 files changed, 72 insertions, 87 deletions
diff --git a/Minecraft.World/PigZombie.cpp b/Minecraft.World/PigZombie.cpp
index cc060484..7a736c9a 100644
--- a/Minecraft.World/PigZombie.cpp
+++ b/Minecraft.World/PigZombie.cpp
@@ -3,7 +3,9 @@
#include "net.minecraft.world.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.phys.h"
+#include "net.minecraft.world.entity.ai.attributes.h"
#include "net.minecraft.world.entity.player.h"
+#include "net.minecraft.world.entity.monster.h"
#include "net.minecraft.world.item.h"
#include "net.minecraft.world.item.enchantment.h"
#include "net.minecraft.world.entity.item.h"
@@ -12,38 +14,31 @@
#include "..\Minecraft.Client\Textures.h"
#include "SoundTypes.h"
-
-
-shared_ptr<ItemInstance> PigZombie::sword;
-
-void PigZombie::staticCtor()
-{
- PigZombie::sword = shared_ptr<ItemInstance>( new ItemInstance(Item::sword_gold, 1) );
-}
+AttributeModifier *PigZombie::SPEED_MODIFIER_ATTACKING = (new AttributeModifier(eModifierId_MOB_PIG_ATTACKSPEED, 0.45, AttributeModifier::OPERATION_ADDITION))->setSerialize(false);
void PigZombie::_init()
{
+ registerAttributes();
+
angerTime = 0;
playAngrySoundIn = 0;
+ lastAttackTarget = nullptr;
}
PigZombie::PigZombie(Level *level) : Zombie( level )
{
- // 4J Stu - This function call had to be moved here from the Entity ctor to ensure that
- // the derived version of the function is called
-
- // 4J Stu - Zombie has already called this, and we don't override it so the Zombie one is the most derived version anyway
- //this->defineSynchedData();
+ _init();
- // 4J Stu - This function call had to be moved here from the Entity ctor to ensure that the derived version of the function is called
- health = getMaxHealth();
+ fireImmune = true;
+}
- _init();
+void PigZombie::registerAttributes()
+{
+ Zombie::registerAttributes();
- this->textureIdx = TN_MOB_PIGZOMBIE; // 4J was L"/mob/pigzombie.png";
- runSpeed = 0.5f;
- attackDamage = 5;
- this->fireImmune = true;
+ getAttribute(SPAWN_REINFORCEMENTS_CHANCE)->setBaseValue(0);
+ getAttribute(SharedMonsterAttributes::MOVEMENT_SPEED)->setBaseValue(0.5f);
+ getAttribute(SharedMonsterAttributes::ATTACK_DAMAGE)->setBaseValue(5);
}
bool PigZombie::useNewAi()
@@ -51,39 +46,45 @@ bool PigZombie::useNewAi()
return false;
}
-int PigZombie::getTexture()
-{
- return textureIdx;
-}
-
void PigZombie::tick()
{
- runSpeed = attackTarget != NULL ? 0.95f : 0.5f;
- if (playAngrySoundIn > 0)
+ if (lastAttackTarget != attackTarget && !level->isClientSide)
+ {
+ AttributeInstance *speed = getAttribute(SharedMonsterAttributes::MOVEMENT_SPEED);
+ speed->removeModifier(SPEED_MODIFIER_ATTACKING);
+
+ if (attackTarget != NULL)
+ {
+ speed->addModifier(new AttributeModifier(*SPEED_MODIFIER_ATTACKING));
+ }
+ }
+ lastAttackTarget = attackTarget;
+
+ if (playAngrySoundIn > 0)
{
- if (--playAngrySoundIn == 0)
+ if (--playAngrySoundIn == 0)
{
- level->playSound(shared_from_this(), eSoundType_MOB_ZOMBIEPIG_ZPIGANGRY, getSoundVolume() * 2, ((random->nextFloat() - random->nextFloat()) * 0.2f + 1.0f) * 1.8f);
- }
- }
- Zombie::tick();
+ playSound(eSoundType_MOB_ZOMBIEPIG_ZPIGANGRY, getSoundVolume() * 2, ((random->nextFloat() - random->nextFloat()) * 0.2f + 1.0f) * 1.8f);
+ }
+ }
+ Zombie::tick();
}
bool PigZombie::canSpawn()
{
- return level->difficulty > Difficulty::PEACEFUL && level->isUnobstructed(bb) && level->getCubes(shared_from_this(), bb)->empty() && !level->containsAnyLiquid(bb);
+ return level->difficulty > Difficulty::PEACEFUL && level->isUnobstructed(bb) && level->getCubes(shared_from_this(), bb)->empty() && !level->containsAnyLiquid(bb);
}
void PigZombie::addAdditonalSaveData(CompoundTag *tag)
{
- Zombie::addAdditonalSaveData(tag);
- tag->putShort(L"Anger", (short) angerTime);
+ Zombie::addAdditonalSaveData(tag);
+ tag->putShort(L"Anger", (short) angerTime);
}
void PigZombie::readAdditionalSaveData(CompoundTag *tag)
{
- Zombie::readAdditionalSaveData(tag);
- angerTime = tag->getShort(L"Anger");
+ Zombie::readAdditionalSaveData(tag);
+ angerTime = tag->getShort(L"Anger");
}
shared_ptr<Entity> PigZombie::findAttackTarget()
@@ -97,51 +98,51 @@ shared_ptr<Entity> PigZombie::findAttackTarget()
#endif
#endif
- if (angerTime == 0) return nullptr;
- return Zombie::findAttackTarget();
+ if (angerTime == 0) return nullptr;
+ return Zombie::findAttackTarget();
}
-bool PigZombie::hurt(DamageSource *source, int dmg)
+bool PigZombie::hurt(DamageSource *source, float dmg)
{
shared_ptr<Entity> sourceEntity = source->getEntity();
- if (dynamic_pointer_cast<Player>(sourceEntity) != NULL)
+ if ( sourceEntity != NULL && sourceEntity->instanceof(eTYPE_PLAYER) )
{
- vector<shared_ptr<Entity> > *nearby = level->getEntities( shared_from_this(), bb->grow(32, 32, 32));
+ vector<shared_ptr<Entity> > *nearby = level->getEntities( shared_from_this(), bb->grow(32, 32, 32));
AUTO_VAR(itEnd, nearby->end());
for (AUTO_VAR(it, nearby->begin()); it != itEnd; it++)
{
- shared_ptr<Entity> e = *it; //nearby->at(i);
- if (dynamic_pointer_cast<PigZombie>(e) != NULL)
+ shared_ptr<Entity> e = *it; //nearby->at(i);
+ if ( e->instanceof(eTYPE_PIGZOMBIE) )
{
- shared_ptr<PigZombie> pigZombie = dynamic_pointer_cast<PigZombie>(e);
- pigZombie->alert(sourceEntity);
- }
- }
- alert(sourceEntity);
- }
- return Zombie::hurt(source, dmg);
+ shared_ptr<PigZombie> pigZombie = dynamic_pointer_cast<PigZombie>(e);
+ pigZombie->alert(sourceEntity);
+ }
+ }
+ alert(sourceEntity);
+ }
+ return Zombie::hurt(source, dmg);
}
void PigZombie::alert(shared_ptr<Entity> target)
{
- this->attackTarget = target;
- angerTime = 20 * 20 + random->nextInt(20 * 20);
- playAngrySoundIn = random->nextInt(20 * 2);
+ attackTarget = target;
+ angerTime = 20 * 20 + random->nextInt(20 * 20);
+ playAngrySoundIn = random->nextInt(20 * 2);
}
int PigZombie::getAmbientSound()
{
- return eSoundType_MOB_ZOMBIEPIG_AMBIENT;
+ return eSoundType_MOB_ZOMBIEPIG_AMBIENT;
}
int PigZombie::getHurtSound()
{
- return eSoundType_MOB_ZOMBIEPIG_HURT;
+ return eSoundType_MOB_ZOMBIEPIG_HURT;
}
int PigZombie::getDeathSound()
{
- return eSoundType_MOB_ZOMBIEPIG_DEATH;
+ return eSoundType_MOB_ZOMBIEPIG_DEATH;
}
void PigZombie::dropDeathLoot(bool wasKilledByPlayer, int playerBonusLevel)
@@ -158,45 +159,29 @@ void PigZombie::dropDeathLoot(bool wasKilledByPlayer, int playerBonusLevel)
}
}
+bool PigZombie::mobInteract(shared_ptr<Player> player)
+{
+ return false;
+}
+
void PigZombie::dropRareDeathLoot(int rareLootLevel)
{
- if (rareLootLevel > 0)
- {
- shared_ptr<ItemInstance> sword = shared_ptr<ItemInstance>( new ItemInstance(Item::sword_gold) );
- EnchantmentHelper::enchantItem(random, sword, 5);
- spawnAtLocation(sword, 0);
- }
- else
- {
- int select = random->nextInt(3);
- if (select == 0)
- {
- spawnAtLocation(Item::goldIngot_Id, 1);
- }
- else if (select == 1)
- {
- spawnAtLocation(Item::sword_gold_Id, 1);
- }
- else if (select == 2)
- {
- spawnAtLocation(Item::helmet_gold_Id, 1);
- }
- }
+ spawnAtLocation(Item::goldIngot_Id, 1);
}
int PigZombie::getDeathLoot()
{
- return Item::rotten_flesh_Id;
+ return Item::rotten_flesh_Id;
}
-void PigZombie::finalizeMobSpawn()
+void PigZombie::populateDefaultEquipmentSlots()
{
- Zombie::finalizeMobSpawn();
- setVillager(false);
+ setEquippedSlot(SLOT_WEAPON, shared_ptr<ItemInstance>( new ItemInstance(Item::sword_gold)) );
}
-shared_ptr<ItemInstance> PigZombie::getCarriedItem()
+MobGroupData *PigZombie::finalizeMobSpawn(MobGroupData *groupData, int extraData /*= 0*/) // 4J Added extraData param
{
- // TODO 4J - could be of const shared_ptr<ItemInstance> type.
- return (shared_ptr<ItemInstance> ) sword;
-}
+ Zombie::finalizeMobSpawn(groupData);
+ setVillager(false);
+ return groupData;
+} \ No newline at end of file