the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 72 lines 1.8 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.entity.ai.control.h" 3#include "net.minecraft.world.entity.ai.navigation.h" 4#include "net.minecraft.world.entity.h" 5#include "net.minecraft.world.level.h" 6#include "net.minecraft.world.level.tile.h" 7#include "EatTileGoal.h" 8 9EatTileGoal::EatTileGoal(Mob *mob) 10{ 11 eatAnimationTick = 0; 12 13 this->mob = mob; 14 level = mob->level; 15 setRequiredControlFlags(Control::MoveControlFlag | Control::LookControlFlag | Control::JumpControlFlag); 16} 17 18bool EatTileGoal::canUse() 19{ 20 if (mob->getRandom()->nextInt(mob->isBaby() ? 50 : 1000) != 0) return false; 21 22 int xx = Mth::floor(mob->x); 23 int yy = Mth::floor(mob->y); 24 int zz = Mth::floor(mob->z); 25 if (level->getTile(xx, yy, zz) == Tile::tallgrass_Id && level->getData(xx, yy, zz) == TallGrass::TALL_GRASS) return true; 26 if (level->getTile(xx, yy - 1, zz) == Tile::grass_Id) return true; 27 return false; 28} 29 30void EatTileGoal::start() 31{ 32 eatAnimationTick = EAT_ANIMATION_TICKS; 33 level->broadcastEntityEvent(mob->shared_from_this(), EntityEvent::EAT_GRASS); 34 mob->getNavigation()->stop(); 35} 36 37void EatTileGoal::stop() 38{ 39 eatAnimationTick = 0; 40} 41 42bool EatTileGoal::canContinueToUse() 43{ 44 return eatAnimationTick > 0; 45} 46 47int EatTileGoal::getEatAnimationTick() 48{ 49 return eatAnimationTick; 50} 51 52void EatTileGoal::tick() 53{ 54 eatAnimationTick = max(0, eatAnimationTick - 1); 55 if (eatAnimationTick != 4) return; 56 57 int xx = Mth::floor(mob->x); 58 int yy = Mth::floor(mob->y); 59 int zz = Mth::floor(mob->z); 60 61 if (level->getTile(xx, yy, zz) == Tile::tallgrass_Id) 62 { 63 level->destroyTile(xx, yy, zz, false); 64 mob->ate(); 65 } 66 else if (level->getTile(xx, yy - 1, zz) == Tile::grass_Id) 67 { 68 level->levelEvent(LevelEvent::PARTICLES_DESTROY_BLOCK, xx, yy - 1, zz, Tile::grass_Id); 69 level->setTileAndData(xx, yy - 1, zz, Tile::dirt_Id, 0, Tile::UPDATE_CLIENTS); 70 mob->ate(); 71 } 72}