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 "Minecraft.h"
3#include "..\Minecraft.World\net.minecraft.world.level.h"
4#include "..\Minecraft.World\net.minecraft.world.level.dimension.h"
5#include "MultiplayerLocalPlayer.h"
6#include "..\Minecraft.World\JavaMath.h"
7#include "Texture.h"
8#include "CompassTexture.h"
9
10CompassTexture *CompassTexture::instance = NULL;
11
12CompassTexture::CompassTexture() : StitchedTexture(L"compass",L"compass")
13{
14 instance = this;
15
16 m_dataTexture = NULL;
17 m_iPad = XUSER_INDEX_ANY;
18
19 rot = rota = 0.0;
20}
21
22CompassTexture::CompassTexture(int iPad, CompassTexture *dataTexture) : StitchedTexture(L"compass",L"compass")
23{
24 m_dataTexture = dataTexture;
25 m_iPad = iPad;
26
27 rot = rota = 0.0;
28}
29
30void CompassTexture::cycleFrames()
31{
32 Minecraft *mc = Minecraft::GetInstance();
33
34 if (m_iPad >= 0 && m_iPad < XUSER_MAX_COUNT && mc->level != NULL && mc->localplayers[m_iPad] != NULL)
35 {
36 updateFromPosition(mc->localplayers[m_iPad]->level, mc->localplayers[m_iPad]->x, mc->localplayers[m_iPad]->z, mc->localplayers[m_iPad]->yRot, false, false);
37 }
38 else
39 {
40 frame = 1;
41 updateFromPosition(NULL, 0, 0, 0, false, true);
42 }
43}
44
45void CompassTexture::updateFromPosition(Level *level, double x, double z, double yRot, bool noNeedle, bool instant)
46{
47 double rott = 0;
48 if (level != NULL && !noNeedle)
49 {
50 Pos *spawnPos = level->getSharedSpawnPos();
51 double xa = spawnPos->x - x;
52 double za = spawnPos->z - z;
53 delete spawnPos;
54 yRot = (int)yRot % 360;
55 rott = -((yRot - 90) * PI / 180 - atan2(za, xa));
56 if (!level->dimension->isNaturalDimension())
57 {
58 rott = Math::random() * PI * 2;
59 }
60 }
61
62 if (instant)
63 {
64 rot = rott;
65 }
66 else
67 {
68 double rotd = rott - rot;
69 while (rotd < -PI)
70 rotd += PI * 2;
71 while (rotd >= PI)
72 rotd -= PI * 2;
73 if (rotd < -1) rotd = -1;
74 if (rotd > 1) rotd = 1;
75 rota += rotd * 0.1;
76 rota *= 0.8;
77 rot += rota;
78 }
79
80 // 4J Stu - We share data with another texture
81 if(m_dataTexture != NULL)
82 {
83 int newFrame = (int) (((rot / (PI * 2)) + 1.0) * m_dataTexture->frames->size()) % m_dataTexture->frames->size();
84 while (newFrame < 0)
85 {
86 newFrame = (newFrame + m_dataTexture->frames->size()) % m_dataTexture->frames->size();
87 }
88 if (newFrame != frame)
89 {
90 frame = newFrame;
91 m_dataTexture->source->blit(this->x, this->y, m_dataTexture->frames->at(this->frame), rotated);
92 }
93 }
94 else
95 {
96 int newFrame = (int) (((rot / (PI * 2)) + 1.0) * frames->size()) % frames->size();
97 while (newFrame < 0)
98 {
99 newFrame = (newFrame + frames->size()) % frames->size();
100 }
101 if (newFrame != frame)
102 {
103 frame = newFrame;
104 source->blit(this->x, this->y, frames->at(this->frame), rotated);
105 }
106 }
107}
108
109int CompassTexture::getSourceWidth() const
110{
111 return source->getWidth();
112}
113
114int CompassTexture::getSourceHeight() const
115{
116 return source->getHeight();
117}
118
119int CompassTexture::getFrames()
120{
121 if(m_dataTexture == NULL)
122 {
123 return StitchedTexture::getFrames();
124 }
125 else
126 {
127 return m_dataTexture->getFrames();
128 }
129}
130
131void CompassTexture::freeFrameTextures()
132{
133 if(m_dataTexture == NULL)
134 {
135 StitchedTexture::freeFrameTextures();
136 }
137}
138
139bool CompassTexture::hasOwnData()
140{
141 return m_dataTexture == NULL;
142}