This repository has been archived by the owner on Jan 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 710
/
Copy pathAchievementsWithGUI_tombailey94.js
115 lines (105 loc) · 3.35 KB
/
AchievementsWithGUI_tombailey94.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//Achievements mod by tombailey94
// version 0.0.2
/* experimental; requires "wood.png" file in "games/com.mojang/" folder for displaying achievement (not uploaded as copyright Mojang) */
var imgview;
var ctx;
var simpleGUI;
var imgs = ["wood","bed","nether","diamonds"];
var GUICounter = 0; //counter that will be set to 200 later. It will then decrease until it is 0 and the GUI is hidden.
var achvs = [false,false,false,false];
var achvNames = ["Getting Wood","Bedtime Already?","Into The Nether","DIAMONDS!"];
function unlockAchv(intIndex){
achvs[intIndex] = true;
clientMessage(achvNames[intIndex] + " unlocked.");
GUICounter = 200;
ctx.runOnUiThread(new java.lang.Runnable({ run: function() {
try{
simpleGUI = new android.widget.PopupWindow();
var layout = new android.widget.RelativeLayout(ctx);
imgview = new android.widget.ImageView(ctx);
imgview.setImageBitmap(android.graphics.BitmapFactory.decodeFile(android.os.Environment.getExternalStorageDirectory() + "/games/com.mojang/" + imgs[intIndex] + ".png"));
layout.addView(imgview);
simpleGUI.setContentView(layout);
simpleGUI.setWidth(555);
simpleGUI.setHeight(109);
simpleGUI.showAtLocation(ctx.getWindow().getDecorView(), android.view.Gravity.TOP, 0, 0);
}catch(err){
print("Error: "+err);
}
} }));
}
function destroyBlock(x, y, z, side) {
blockId = getTile(x,y,z);
if(blockId == 17 && !achvs[0]) { //if player has mined wood for the first time
unlockAchv(0);
} else if(blockId == 56 && !achvs[3]) { //if player has mined diamond ore for the first time
unlockAchv(3);
}
}
function useItem(x,y,z,itemId,blockId,side) {
if(blockId == 247 && !achvs[2]) { //if player has touched a nether reactor core for the first time
unlockAchv(2);
} else if(blockId == 26 && !achvs[1]) { //if player has touched a bed for the first time
unlockAchv(1);
}
}
function newLevel() { //load world
ctx = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();
}
function leaveGame() { //exit world
if(ctx!=null) {
ctx.runOnUiThread(new java.lang.Runnable({ run: function() {
try{
if(simpleGUI != null) {
simpleGUI.dismiss();
simpleGUI = null;
}
}catch(err){
print("Error: "+err);
}
}}));
}
}
function procCmd(cmd) {
var commandElements = cmd.split(" ");
if(commandElements[0] == "achvs") { //if command was /achievements // suggestion: shorten it
if(commandElements.length==1) {
for(var i=0;i<achvs.length;i++){
if(achvs[i]) { //achievement unlocked
clientMessage(achvNames[i] + " unlocked.");
} else { //achievement locked
clientMessage(achvNames[i] + " locked.");
}
}
} else if(commandElements.length==2){
if(commandElements[1] == "reset") {
for(var i=0;i<achvs.length;i++){
achvs[i] == false;
}
clientMessage("Achievements reset.");
} else {
clientMessage("Your parameters were wrong. Achievements command only allows for 'reset' parameter.");
}
} else {
clientMessage("Your parameters were wrong. Achievements command only allows for 'reset' parameter.");
}
}
}
function modTick() {
if(ctx!=null) {
if(GUICounter>0) {
GUICounter -= 1; //decrement counter
} else {
ctx.runOnUiThread(new java.lang.Runnable({ run: function() {
try{
if(simpleGUI != null) {
simpleGUI.dismiss();
simpleGUI = null;
}
}catch(err){
print("Error: "+err);
}
}}));
}
}
}