the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 187 lines 4.6 kB view raw
1#include "stdafx.h" 2#include "com.mojang.nbt.h" 3#include "net.minecraft.world.h" 4#include "net.minecraft.world.level.h" 5#include "net.minecraft.world.phys.h" 6#include "net.minecraft.world.entity.ai.attributes.h" 7#include "net.minecraft.world.entity.player.h" 8#include "net.minecraft.world.entity.monster.h" 9#include "net.minecraft.world.item.h" 10#include "net.minecraft.world.item.enchantment.h" 11#include "net.minecraft.world.entity.item.h" 12#include "net.minecraft.world.damagesource.h" 13#include "PigZombie.h" 14#include "..\Minecraft.Client\Textures.h" 15#include "SoundTypes.h" 16 17AttributeModifier *PigZombie::SPEED_MODIFIER_ATTACKING = (new AttributeModifier(eModifierId_MOB_PIG_ATTACKSPEED, 0.45, AttributeModifier::OPERATION_ADDITION))->setSerialize(false); 18 19void PigZombie::_init() 20{ 21 registerAttributes(); 22 23 angerTime = 0; 24 playAngrySoundIn = 0; 25 lastAttackTarget = nullptr; 26} 27 28PigZombie::PigZombie(Level *level) : Zombie( level ) 29{ 30 _init(); 31 32 fireImmune = true; 33} 34 35void PigZombie::registerAttributes() 36{ 37 Zombie::registerAttributes(); 38 39 getAttribute(SPAWN_REINFORCEMENTS_CHANCE)->setBaseValue(0); 40 getAttribute(SharedMonsterAttributes::MOVEMENT_SPEED)->setBaseValue(0.5f); 41 getAttribute(SharedMonsterAttributes::ATTACK_DAMAGE)->setBaseValue(5); 42} 43 44bool PigZombie::useNewAi() 45{ 46 return false; 47} 48 49void PigZombie::tick() 50{ 51 if (lastAttackTarget != attackTarget && !level->isClientSide) 52 { 53 AttributeInstance *speed = getAttribute(SharedMonsterAttributes::MOVEMENT_SPEED); 54 speed->removeModifier(SPEED_MODIFIER_ATTACKING); 55 56 if (attackTarget != NULL) 57 { 58 speed->addModifier(new AttributeModifier(*SPEED_MODIFIER_ATTACKING)); 59 } 60 } 61 lastAttackTarget = attackTarget; 62 63 if (playAngrySoundIn > 0) 64 { 65 if (--playAngrySoundIn == 0) 66 { 67 playSound(eSoundType_MOB_ZOMBIEPIG_ZPIGANGRY, getSoundVolume() * 2, ((random->nextFloat() - random->nextFloat()) * 0.2f + 1.0f) * 1.8f); 68 } 69 } 70 Zombie::tick(); 71} 72 73bool PigZombie::canSpawn() 74{ 75 return level->difficulty > Difficulty::PEACEFUL && level->isUnobstructed(bb) && level->getCubes(shared_from_this(), bb)->empty() && !level->containsAnyLiquid(bb); 76} 77 78void PigZombie::addAdditonalSaveData(CompoundTag *tag) 79{ 80 Zombie::addAdditonalSaveData(tag); 81 tag->putShort(L"Anger", (short) angerTime); 82} 83 84void PigZombie::readAdditionalSaveData(CompoundTag *tag) 85{ 86 Zombie::readAdditionalSaveData(tag); 87 angerTime = tag->getShort(L"Anger"); 88} 89 90shared_ptr<Entity> PigZombie::findAttackTarget() 91{ 92#ifndef _FINAL_BUILD 93#ifdef _DEBUG_MENUS_ENABLED 94 if(app.GetMobsDontAttackEnabled()) 95 { 96 return shared_ptr<Player>(); 97 } 98#endif 99#endif 100 101 if (angerTime == 0) return nullptr; 102 return Zombie::findAttackTarget(); 103} 104 105bool PigZombie::hurt(DamageSource *source, float dmg) 106{ 107 shared_ptr<Entity> sourceEntity = source->getEntity(); 108 if ( sourceEntity != NULL && sourceEntity->instanceof(eTYPE_PLAYER) ) 109 { 110 vector<shared_ptr<Entity> > *nearby = level->getEntities( shared_from_this(), bb->grow(32, 32, 32)); 111 AUTO_VAR(itEnd, nearby->end()); 112 for (AUTO_VAR(it, nearby->begin()); it != itEnd; it++) 113 { 114 shared_ptr<Entity> e = *it; //nearby->at(i); 115 if ( e->instanceof(eTYPE_PIGZOMBIE) ) 116 { 117 shared_ptr<PigZombie> pigZombie = dynamic_pointer_cast<PigZombie>(e); 118 pigZombie->alert(sourceEntity); 119 } 120 } 121 alert(sourceEntity); 122 } 123 return Zombie::hurt(source, dmg); 124} 125 126void PigZombie::alert(shared_ptr<Entity> target) 127{ 128 attackTarget = target; 129 angerTime = 20 * 20 + random->nextInt(20 * 20); 130 playAngrySoundIn = random->nextInt(20 * 2); 131} 132 133int PigZombie::getAmbientSound() 134{ 135 return eSoundType_MOB_ZOMBIEPIG_AMBIENT; 136} 137 138int PigZombie::getHurtSound() 139{ 140 return eSoundType_MOB_ZOMBIEPIG_HURT; 141} 142 143int PigZombie::getDeathSound() 144{ 145 return eSoundType_MOB_ZOMBIEPIG_DEATH; 146} 147 148void PigZombie::dropDeathLoot(bool wasKilledByPlayer, int playerBonusLevel) 149{ 150 int count = random->nextInt(2 + playerBonusLevel); 151 for (int i = 0; i < count; i++) 152 { 153 spawnAtLocation(Item::rotten_flesh_Id, 1); 154 } 155 count = random->nextInt(2 + playerBonusLevel); 156 for (int i = 0; i < count; i++) 157 { 158 spawnAtLocation(Item::goldNugget_Id, 1); 159 } 160} 161 162bool PigZombie::mobInteract(shared_ptr<Player> player) 163{ 164 return false; 165} 166 167void PigZombie::dropRareDeathLoot(int rareLootLevel) 168{ 169 spawnAtLocation(Item::goldIngot_Id, 1); 170} 171 172int PigZombie::getDeathLoot() 173{ 174 return Item::rotten_flesh_Id; 175} 176 177void PigZombie::populateDefaultEquipmentSlots() 178{ 179 setEquippedSlot(SLOT_WEAPON, shared_ptr<ItemInstance>( new ItemInstance(Item::sword_gold)) ); 180} 181 182MobGroupData *PigZombie::finalizeMobSpawn(MobGroupData *groupData, int extraData /*= 0*/) // 4J Added extraData param 183{ 184 Zombie::finalizeMobSpawn(groupData); 185 setVillager(false); 186 return groupData; 187}