the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 227 lines 5.6 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.level.h" 3#include "net.minecraft.world.level.tile.h" 4#include "net.minecraft.world.phys.h" 5#include "net.minecraft.world.damagesource.h" 6#include "net.minecraft.world.entity.ai.attributes.h" 7#include "net.minecraft.world.entity.monster.h" 8#include "net.minecraft.h" 9#include "..\Minecraft.Client\Textures.h" 10#include "Silverfish.h" 11#include "SoundTypes.h" 12 13 14 15Silverfish::Silverfish(Level *level) : Monster( level ) 16{ 17 // 4J Stu - This function call had to be moved here from the Entity ctor to ensure that 18 // the derived version of the function is called 19 this->defineSynchedData(); 20 registerAttributes(); 21 setHealth(getMaxHealth()); 22 23 setSize(0.3f, 0.7f); 24} 25 26void Silverfish::registerAttributes() 27{ 28 Monster::registerAttributes(); 29 30 getAttribute(SharedMonsterAttributes::MAX_HEALTH)->setBaseValue(8); 31 getAttribute(SharedMonsterAttributes::MOVEMENT_SPEED)->setBaseValue(0.6f); 32 getAttribute(SharedMonsterAttributes::ATTACK_DAMAGE)->setBaseValue(1); 33} 34 35bool Silverfish::makeStepSound() 36{ 37 return false; 38} 39 40shared_ptr<Entity> Silverfish::findAttackTarget() 41{ 42#ifndef _FINAL_BUILD 43 if(app.GetMobsDontAttackEnabled()) 44 { 45 return shared_ptr<Player>(); 46 } 47#endif 48 49 double maxDist = 8; 50 return level->getNearestAttackablePlayer(shared_from_this(), maxDist); 51} 52 53int Silverfish::getAmbientSound() 54{ 55 // 4J - brought sound change forward from 1.2.3 56 return eSoundType_MOB_SILVERFISH_AMBIENT; 57} 58 59int Silverfish::getHurtSound() 60{ 61 // 4J - brought sound change forward from 1.2.3 62 return eSoundType_MOB_SILVERFISH_HURT; 63} 64 65int Silverfish::getDeathSound() 66{ 67 // 4J - brought sound change forward from 1.2.3 68 return eSoundType_MOB_SILVERFISH_DEATH; 69} 70 71 72bool Silverfish::hurt(DamageSource *source, float dmg) 73{ 74 if (isInvulnerable()) return false; 75 if (lookForFriends <= 0 && (dynamic_cast<EntityDamageSource *>(source) != NULL || source == DamageSource::magic)) 76 { 77 // look for friends 78 lookForFriends = 20; 79 } 80 return Monster::hurt(source, dmg); 81} 82 83void Silverfish::checkHurtTarget(shared_ptr<Entity> target, float d) 84{ 85 86 // super.checkHurtTarget(target, d); 87 if (attackTime <= 0 && d < 1.2f && target->bb->y1 > bb->y0 && target->bb->y0 < bb->y1) 88 { 89 attackTime = 20; 90 doHurtTarget(target); 91 } 92 93} 94 95void Silverfish::playStepSound(int xt, int yt, int zt, int t) 96{ 97 playSound(eSoundType_MOB_SILVERFISH_STEP, 0.15f, 1); 98} 99 100int Silverfish::getDeathLoot() 101{ 102 return 0; 103} 104 105void Silverfish::tick() 106{ 107 // rotate the whole body to the same angle as the head 108 yBodyRot = yRot; 109 110 Monster::tick(); 111} 112 113void Silverfish::serverAiStep() 114{ 115 Monster::serverAiStep(); 116 117 if (level->isClientSide) 118 { 119 return; 120 } 121 122 if (lookForFriends > 0) 123 { 124 lookForFriends--; 125 if (lookForFriends == 0) 126 { 127 // see if there are any friendly monster eggs nearby 128 int baseX = Mth::floor(x); 129 int baseY = Mth::floor(y); 130 int baseZ = Mth::floor(z); 131 bool doBreak = false; 132 133 for (int yOff = 0; !doBreak && yOff <= 5 && yOff >= -5; yOff = (yOff <= 0) ? 1 - yOff : 0 - yOff) 134 { 135 for (int xOff = 0; !doBreak && xOff <= 10 && xOff >= -10; xOff = (xOff <= 0) ? 1 - xOff : 0 - xOff) 136 { 137 for (int zOff = 0; !doBreak && zOff <= 10 && zOff >= -10; zOff = (zOff <= 0) ? 1 - zOff : 0 - zOff) 138 { 139 int tile = level->getTile(baseX + xOff, baseY + yOff, baseZ + zOff); 140 if (tile == Tile::monsterStoneEgg_Id) 141 { 142 if (!level->getGameRules()->getBoolean(GameRules::RULE_MOBGRIEFING)) 143 { 144 int data = level->getData(baseX + xOff, baseY + yOff, baseZ + zOff); 145 146 Tile *restoreTile = Tile::stone; 147 if (data == StoneMonsterTile::HOST_COBBLE) 148 { 149 restoreTile = Tile::cobblestone; 150 } 151 if (data == StoneMonsterTile::HOST_STONEBRICK) 152 { 153 restoreTile = Tile::stoneBrick; 154 } 155 156 level->setTileAndData(baseX + xOff, baseY + yOff, baseZ + zOff, restoreTile->id, 0, Tile::UPDATE_ALL); 157 } 158 else 159 { 160 level->destroyTile(baseX + xOff, baseY + yOff, baseZ + zOff, false); 161 } 162 Tile::monsterStoneEgg->destroy(level, baseX + xOff, baseY + yOff, baseZ + zOff, 0); 163 164 if (random->nextBoolean()) 165 { 166 doBreak = true; 167 break; 168 } 169 } 170 } 171 } 172 } 173 } 174 } 175 176 if (attackTarget == NULL && !isPathFinding()) 177 { 178 // if the silverfish isn't doing anything special, it will merge 179 // with any rock tile it is nearby 180 int tileX = Mth::floor(x), tileY = Mth::floor(y + .5f), tileZ = Mth::floor(z); 181 int facing = random->nextInt(6); 182 183 int tile = level->getTile(tileX + Facing::STEP_X[facing], tileY + Facing::STEP_Y[facing], tileZ + Facing::STEP_Z[facing]); 184 if (StoneMonsterTile::isCompatibleHostBlock(tile)) 185 { 186 level->setTileAndData(tileX + Facing::STEP_X[facing], tileY + Facing::STEP_Y[facing], tileZ + Facing::STEP_Z[facing], Tile::monsterStoneEgg_Id, StoneMonsterTile::getDataForHostBlock(tile), Tile::UPDATE_ALL); 187 spawnAnim(); 188 remove(); 189 } 190 else 191 { 192 findRandomStrollLocation(); 193 } 194 195 } 196 else if (attackTarget != NULL && !isPathFinding()) 197 { 198 attackTarget = nullptr; 199 } 200} 201 202float Silverfish::getWalkTargetValue(int x, int y, int z) 203{ 204 // silverfish LOVES stone =) 205 if (level->getTile(x, y - 1, z) == Tile::stone_Id) return 10; 206 return Monster::getWalkTargetValue(x, y, z); 207} 208 209bool Silverfish::isDarkEnoughToSpawn() 210{ 211 return true; 212} 213 214bool Silverfish::canSpawn() 215{ 216 if (Monster::canSpawn()) 217 { 218 shared_ptr<Player> nearestPlayer = level->getNearestPlayer(shared_from_this(), 5.0); 219 return nearestPlayer == NULL; 220 } 221 return false; 222} 223 224MobType Silverfish::getMobType() 225{ 226 return ARTHROPOD; 227}