the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "net.minecraft.world.entity.h"
3#include "net.minecraft.world.entity.ai.attributes.h"
4#include "net.minecraft.world.entity.ai.control.h"
5#include "net.minecraft.world.entity.monster.h"
6#include "net.minecraft.world.phys.h"
7#include "MoveControl.h"
8
9const float MoveControl::MIN_SPEED = 0.0005f;
10const float MoveControl::MIN_SPEED_SQR = MIN_SPEED * MIN_SPEED;
11
12MoveControl::MoveControl(Mob *mob)
13{
14 this->mob = mob;
15 wantedX = mob->x;
16 wantedY = mob->y;
17 wantedZ = mob->z;
18
19 speedModifier = 0.0;
20
21 _hasWanted = false;
22}
23
24bool MoveControl::hasWanted()
25{
26 return _hasWanted;
27}
28
29double MoveControl::getSpeedModifier()
30{
31 return speedModifier;
32}
33
34void MoveControl::setWantedPosition(double x, double y, double z, double speedModifier)
35{
36 wantedX = x;
37 wantedY = y;
38 wantedZ = z;
39 this->speedModifier = speedModifier;
40 _hasWanted = true;
41}
42
43void MoveControl::tick()
44{
45 mob->setYya(0);
46 if (!_hasWanted) return;
47 _hasWanted = false;
48
49 int yFloor = floor(mob->bb->y0 + .5f);
50
51 double xd = wantedX - mob->x;
52 double zd = wantedZ - mob->z;
53 double yd = wantedY - yFloor;
54 double dd = xd * xd + yd * yd + zd * zd;
55 if (dd < MIN_SPEED_SQR) return;
56
57 float yRotD = (float) (atan2(zd, xd) * 180 / PI) - 90;
58
59 mob->yRot = rotlerp(mob->yRot, yRotD, MAX_TURN);
60 mob->setSpeed((float) (speedModifier * mob->getAttribute(SharedMonsterAttributes::MOVEMENT_SPEED)->getValue()));
61
62 if (yd > 0 && xd * xd + zd * zd < 1) mob->getJumpControl()->jump();
63}
64
65float MoveControl::rotlerp(float a, float b, float max)
66{
67 float diff = Mth::wrapDegrees(b - a);
68 if (diff > max)
69 {
70 diff = max;
71 }
72 if (diff < -max)
73 {
74 diff = -max;
75 }
76 return a + diff;
77}