the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 73 lines 1.8 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.entity.h" 3#include "net.minecraft.world.entity.ai.navigation.h" 4#include "net.minecraft.world.level.h" 5#include "net.minecraft.world.level.pathfinder.h" 6#include "net.minecraft.world.level.tile.h" 7#include "DoorInteractGoal.h" 8 9DoorInteractGoal::DoorInteractGoal(Mob *mob) 10{ 11 doorX = doorY = doorZ = 0; 12 doorTile = NULL; 13 passed = false; 14 doorOpenDirX = doorOpenDirZ = 0.0f; 15 16 this->mob = mob; 17} 18 19bool DoorInteractGoal::canUse() 20{ 21 if (!mob->horizontalCollision) return false; 22 PathNavigation *pathNav = mob->getNavigation(); 23 Path *path = pathNav->getPath(); 24 if (path == NULL || path->isDone() || !pathNav->canOpenDoors()) return false; 25 26 for (int i = 0; i < min(path->getIndex() + 2, path->getSize()); ++i) 27 { 28 Node *n = path->get(i); 29 doorX = n->x; 30 doorY = n->y + 1; 31 doorZ = n->z; 32 if (mob->distanceToSqr(doorX, mob->y, doorZ) > 1.5 * 1.5) continue; 33 doorTile = getDoorTile(doorX, doorY, doorZ); 34 if (doorTile == NULL) continue; 35 return true; 36 } 37 38 doorX = Mth::floor(mob->x); 39 doorY = Mth::floor(mob->y + 1); 40 doorZ = Mth::floor(mob->z); 41 doorTile = getDoorTile(doorX, doorY, doorZ); 42 return doorTile != NULL; 43} 44 45bool DoorInteractGoal::canContinueToUse() 46{ 47 return !passed; 48} 49 50void DoorInteractGoal::start() 51{ 52 passed = false; 53 doorOpenDirX = (float) (doorX + 0.5f - mob->x); 54 doorOpenDirZ = (float) (doorZ + 0.5f - mob->z); 55} 56 57void DoorInteractGoal::tick() 58{ 59 float newDoorDirX = (float) (doorX + 0.5f - mob->x); 60 float newDoorDirZ = (float) (doorZ + 0.5f - mob->z); 61 float dot = doorOpenDirX * newDoorDirX + doorOpenDirZ * newDoorDirZ; 62 if (dot < 0) 63 { 64 passed = true; 65 } 66} 67 68DoorTile *DoorInteractGoal::getDoorTile(int x, int y, int z) 69{ 70 int tileId = mob->level->getTile(x, y, z); 71 if (tileId != Tile::door_wood_Id) return NULL; 72 return (DoorTile *) Tile::tiles[tileId]; 73}