-
Notifications
You must be signed in to change notification settings - Fork 2
/
CCTV Mod V2.4.js
executable file
·362 lines (334 loc) · 10.7 KB
/
CCTV Mod V2.4.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
//CCTV Mod V2.4 (Compatible with 0.14)
//by wilco375
//Don't re-upload this code, nor share or redistribute this mod using the Github link without permission. Instead, use this link: http://adf.ly/tvNt3
var cameraId = 250
var monitorId = 510
var ctx = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();
var textsize = 15
var currentX, currentY, currentZ, camera, cameraX, cameraY, cameraZ, air, removed, prevCameraX, prevCameraY, prevCameraZ
var cameras = []
var camerasX = []
var camerasY = []
var camerasZ = []
var dirs = [[0, -1, 0],[0, 1, 0],[0, 0, -1],[0, 0, 1],[-1, 0, 0],[1, 0, 0]];
//Define Camera & Monitor
Block.defineBlock(cameraId,"カメラ",["piston_inner",0],18,false,0)
Block.setDestroyTime(cameraId, 1)
Item.addCraftRecipe(cameraId,1,0,[1,3,0,20,1,0,331,2,0,1,3,0])
if(ModPE.getMinecraftVersion().split(".")[1]<13)
Item.setCategory(cameraId,8,0);
else{
Item.setCategory(cameraId,ItemCategory.TOOL,0);
Player.addItemCreativeInv(cameraId,1,0);
}
ModPE.setItem(monitorId,"item_frame",0,"モニター")
Item.addCraftRecipe(monitorId,1,0,[1,4,0,20,1,0,1,2,0,331,1,0,1,1,0])
if(ModPE.getMinecraftVersion().split(".")[1]<13)
Item.setCategory(monitorId,8,0);
else{
Item.setCategory(monitorId,ItemCategory.TOOL,0);
Player.addItemCreativeInv(monitorId,1,0);
}
//Get all cameras when starting world
function selectLevelHook(){
if(ModPE.readData("cameras"+Level.getWorldDir()) != null && ModPE.readData("cameras"+Level.getWorldDir()) != ""){
cameras = ModPE.readData("cameras"+Level.getWorldDir()).split(",")
camerasX = ModPE.readData("camerasX"+Level.getWorldDir()).split(",")
camerasY = ModPE.readData("camerasY"+Level.getWorldDir()).split(",")
camerasZ = ModPE.readData("camerasZ"+Level.getWorldDir()).split(",")
print("Loaded "+cameras.length+" cameras")
}
}
function newLevel(){
var out = new java.io.ByteArrayOutputStream();
var response = android.net.http.AndroidHttpClient.newInstance("Online()").execute(new org.apache.http.client.methods.HttpGet("https://raw.github.com/wilco375/Minecraft-PE-Mod-Scripts/master/CCTV%202.4%20Update%20Checker.txt")).getEntity().writeTo(out);
out.close();
clientMessage(String(out.toString()));
}
//Remove camera from list if destroyed
function destroyBlock(x,y,z,side){
blockId = getTile(x,y,z)
if(blockId == cameraId){
for(i = 0;i < cameras.length;i++){
if(camerasX[i] == x && camerasY[i] == y && camerasZ[i] == z){
cameras.splice(i,1)
camerasX.splice(i,1)
camerasY.splice(i,1)
camerasZ.splice(i,1)
}
}
}
}
//Save cameras if leaving level
function leaveGame(){
if(camera == 1){
camera = 0
if(air == 1){
setTile(cameraX,cameraY-2,cameraZ,0)
air = 0
}
Entity.setPosition(getPlayerEnt(), currentX,currentY,currentZ)
}
if(cameras != null && cameras != [] && cameras != ""){
ModPE.saveData("cameras"+Level.getWorldDir(),cameras.toString())
ModPE.saveData("camerasX"+Level.getWorldDir(),camerasX.toString())
ModPE.saveData("camerasY"+Level.getWorldDir(),camerasY.toString())
ModPE.saveData("camerasZ"+Level.getWorldDir(),camerasZ.toString())
print("Saved " + cameras.length + " cameras")
cameras = null
camerasX = null
camerasY = null
camerasZ = null
}
}
//Ask to name camera and save it if placed down and prevent the player from placing blocks if in camera and show GUI if using monitorId
function useItem(x,y,z,itemId,blockId,side){
if(itemId == monitorId){
showCameraMenu();
}
else if(camera == 1){
preventDefault();
}
else if(itemId == cameraId){
preventDefault();
setTile(x+dirs[side][0],y+dirs[side][1],z+dirs[side][2],cameraId);
if(Level.getGameMode() == 0){
if(Player.getCarriedItemCount()>1) Player.addItemInventory(itemId,-1,0);
else Player.clearInventorySlot(Player.getSelectedSlotId);
}
showNameGUI(x+dirs[side][0],y+dirs[side][1],z+dirs[side][2]);
}
}
function showNameGUI(camX,camY,camZ){
ctx.runOnUiThread(new java.lang.Runnable(){
run: function(){
try{
var menu = new android.widget.LinearLayout(ctx);
var scroll = new android.widget.ScrollView(ctx);
menu.setOrientation(android.widget.LinearLayout.VERTICAL);
scroll.addView(menu);
var dialog = new android.app.Dialog(ctx);
dialog.setContentView(scroll);
dialog.setTitle("Enter a name");
var editText = new android.widget.EditText(ctx);
menu.addView(editText);
var button = new android.widget.Button(ctx);
button.setOnClickListener(new android.view.View.OnClickListener(){
onClick: function(){
try{
var name = editText.getText().toString();
if(name != ""){
dialog.dismiss();
clientMessage("You named the camera " + name);
if(cameras == null){
cameras = []
camerasX = []
camerasY = []
camerasZ = []
}
cameras.push(name)
camerasX.push(camX)
camerasY.push(camY)
camerasZ.push(camZ)
}
}
catch(e){
clientMessage(e);
}
}
})
button.setText("Ok");
button.setTextSize(textsize);
menu.addView(button);
dialog.setCancelable(false);
dialog.show();
}
catch (e){
print ("Error: "+e)
}
}
});
}
//All the commands:
function procCmd(command){
cmd = command.split(" ")
if(cmd[0] == "cctv"){
//List all the cameras
if(cmd[1] == "cameras"){
clientMessage(cameras)
}
//Show a camera
else if(cmd[1] == "show"){
var goToCam = null;
for(i = 0;i < cameras.length;i++){
if(cameras[i] == cmd[2]){
showCameraFromList(i);
break;
}
}
if(goToCam == null){
clientMessage("This camera doesn't exist. Type »/cctv cameras« to get a list of all the cameras")
}
}
//Leave the current camera
else if(cmd[1] == "leave"){
if(camera == 1){
camera = 0
if(air == 1){
setTile(cameraX,cameraY-2,cameraZ,0)
air = 0
}
Entity.setPosition(getPlayerEnt(), currentX,currentY,currentZ)
}
else{clientMessage("You're not looking through a camera")}
}
//Remove a camera from the list
else if(cmd[1] == "remove"){
for(i = 0;i < cameras.length;i++){
if(cameras[i] == cmd[2]){
cameras.splice(i,1)
camerasX.splice(i,1)
camerasY.splice(i,1)
camerasZ.splice(i,1)
removed = 1
clientMessage("カメラの削除に成功しました")
}
}
if(removed != 1) clientMessage("No cameras with this name found")
removed = 0
}
//List all the commands
else if(cmd[1] == "list"){
clientMessage("»/cctv cameras«, すべてのカメラの名前")
clientMessage("»/cctv show <camera name>«, そのカメラの映像を見ます")
clientMessage("»/cctv leave«, カメラを見るのをやめて元の位置に戻ります")
clientMessage("»/cctv remove <camera name>«, このコマンドでカメラをリストから消すことができます")
}
}
}
//TP the player back into the camera if he tries to leave
function modTick(){
if(camera == 1){
if(Player.getX() != cameraX+0.5 || Player.getY() > cameraY+1.5 || Player.getY() < cameraY+0.5 || Player.getZ() != cameraZ+0.5){
Entity.setPosition(getPlayerEnt(), cameraX+0.5,cameraY+1,cameraZ+0.5)
}
}
}
//Prevent the player from breaking blocks if he's in a camera
function destroyBlock(){
if(camera == 1){
preventDefault()
}
}
//Show GUI
function showCameraMenu(){
ctx.runOnUiThread(new java.lang.Runnable(){
run: function(){
try{
var menu = new android.widget.LinearLayout(ctx);
var scroll = new android.widget.ScrollView(ctx);
menu.setOrientation(android.widget.LinearLayout.VERTICAL);
scroll.addView(menu);
var dialog = new android.app.Dialog(ctx);
dialog.setContentView(scroll);
dialog.setTitle("Cameras");
//Add buttons
if(camera == 1){
var leave = new android.widget.Button(ctx);
leave.setOnClickListener(new android.view.View.OnClickListener(){
onClick: function(){
try{
dialog.dismiss();
camera = 0
if(air == 1){
setTile(cameraX,cameraY-2,cameraZ,0)
air = 0
}
Entity.setPosition(getPlayerEnt(),currentX,currentY,currentZ)
}
catch(e){
clientMessage(e)
}
}
});
leave.setText("Leave this camera");
leave.setTextSize(textsize);
menu.addView(leave);
}
var buttonArray = [];
//Add buttons
for(i=0;i<cameras.length;i++){
buttonArray.push(new android.widget.Button(ctx));
}
for(i=0;i<cameras.length;i++){
buttonArray[i].setOnClickListener(new android.view.View.OnClickListener(){
onClick: function(){
try{
dialog.dismiss();
if(camera == 1) showCameraFromList(menu.indexOfChild(arguments[0]) - 1);
else showCameraFromList(menu.indexOfChild(arguments[0]));
}
catch(e){
clientMessage(e);
}
}
})
//clientMessage("i "+i+" cameras[i] "+cameras[i])
buttonArray[i].setText(cameras[i]);
buttonArray[i].setTextSize(textsize);
menu.addView(buttonArray[i]);
}
dialog.show();
}
catch (e){
print ("Error: "+e);
}
}
});
}
//Show the camera that's selected from the list
function showCameraFromList(goToCam){
if(camera != 1){
currentX = Player.getX()
currentY = Player.getY()
currentZ = Player.getZ()
cameraX = parseInt(camerasX[parseInt(goToCam)])
cameraY = parseInt(camerasY[parseInt(goToCam)])
cameraZ = parseInt(camerasZ[parseInt(goToCam)])
if(getTile(cameraX,cameraY,cameraZ) == cameraId){
if(getTile(cameraX,cameraY-2,cameraZ) == 0){
air = 1
setTile(cameraX,cameraY-2,cameraZ,20)
}
Entity.setPosition(getPlayerEnt(), cameraX,cameraY,cameraZ)
clientMessage("»/cctv leave« と打つかモニターにあるこの欄を押すとカメラから離れることができます")
camera = 1
}
else{
clientMessage("この位置にあるカメラは、もはやカメラではありません!")
//clientMessage("The block at " + cameraX + " " + cameraY + " " + cameraZ + " is " + getTile(cameraX,cameraY,cameraZ) + ", goToCam = " + goToCam + ", camerasX[goToCam] is " + camerasX[goToCam])
}
}
else{
prevCameraX = cameraX
prevCameraY = cameraY
prevCameraZ = cameraZ
//clientMessage("goToCam "+goToCam);
cameraX = parseInt(camerasX[parseInt(goToCam)])
cameraY = parseInt(camerasY[parseInt(goToCam)])
cameraZ = parseInt(camerasZ[parseInt(goToCam)])
//clientMessage("cameraxyz: "+cameraX+","+cameraY+","+cameraZ);
if(getTile(cameraX,cameraY,cameraZ) == cameraId){
if(air == 1){
setTile(prevCameraX,prevCameraY-2,prevCameraZ,0)
air = 0
}
if(getTile(cameraX,cameraY-2,cameraZ) == 0){
air = 1
setTile(cameraX,cameraY-2,cameraZ,20)
}
Entity.setPosition(getPlayerEnt(), cameraX,cameraY,cameraZ)
}
else clientMessage("この位置にあるカメラは、もはやカメラではありません!")
}
}