-
Notifications
You must be signed in to change notification settings - Fork 6
/
controllable_mobs_1.1
155 lines (145 loc) · 3.85 KB
/
controllable_mobs_1.1
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
//Controllable Mobs by BeATz-UnKNoWN
var controlUI = null;
var controlsReady = false;
var forward = false;
var backward = false;
var up = false;
var down = false;
var verticalDIRchecked = false;
var verticalMovement = false;
var ANIMAL_SPEED = 0.5;
function newLevel(){
controlsReady = false;
forward = false;
backward = false;
up = false;
down = false;
verticalDIRchecked = false;
verticalMovement = false;
mobControls();
}
function mobControls(){
var ctx = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();
ctx.runOnUiThread(new java.lang.Runnable({ run: function(){
try{
var controlLayout = new android.widget.LinearLayout(ctx);
controlLayout.setOrientation(1);
var forwardBtn = new android.widget.Button(ctx);
forwardBtn.setText("↑");
forwardBtn.setOnTouchListener(new android.view.View.OnTouchListener({
onTouch: function(v, event){
if(!verticalMovement){
switch(event.getAction()){
case 0:
forward = true;
break;
case 1:
forward = false;
break;
}
}else{
switch(event.getAction()){
case 0:
up = true;
break;
case 1:
up = false;
break;
}
}
return true;
}
}));
controlLayout.addView(forwardBtn);
var middleBtn = new android.widget.ToggleButton(ctx);
middleBtn.setChecked(verticalDIRchecked);
middleBtn.setText("∞");
middleBtn.setOnClickListener(new android.view.View.OnClickListener({
onClick: function(viewarg){
if(!verticalMovement){
verticalMovement = true;
verticalDIRchecked = true;
}else{
verticalMovement = false;
verticalDIRchecked = false;
}
middleBtn.setChecked(verticalDIRchecked);
middleBtn.setText("∞");
}
}));
controlLayout.addView(middleBtn);
var backwardBtn = new android.widget.Button(ctx);
backwardBtn.setText("↓");
backwardBtn.setOnTouchListener(new android.view.View.OnTouchListener({
onTouch: function(v, event){
if(!verticalMovement){
switch(event.getAction()){
case 0:
backward = true;
break;
case 1:
backward = false;
break;
}
}else{
switch(event.getAction()){
case 0:
down = true;
break;
case 1:
down = false;
break;
}
}
return true;
}
}));
controlLayout.addView(backwardBtn);
controlUI = new android.widget.PopupWindow(controlLayout, android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT, android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);
controlUI.showAtLocation(ctx.getWindow().getDecorView(), android.view.Gravity.LEFT | android.view.Gravity.TOP, 0, 40);
}catch(err){
print("The mob controls could not be displayed, because: " + err + ".");
}
}}));
}
function leaveGame(){
var ctx = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();
ctx.runOnUiThread(new java.lang.Runnable({ run: function(){
if(controlUI != null){
controlUI.dismiss();
}
}}));
}
function attackHook(attacker, victim){
rideAnimal(attacker, victim);
controlledMob = victim;
controlsReady = true;
}
function modTick(){
if(controlsReady==true){
//500ISE's script
var playerYaw = getYaw();
var playerPitch = getPitch();
var velX = -1 * Math.sin(playerYaw / 180 * Math.PI) * ANIMAL_SPEED;
var velZ = Math.cos(playerYaw / 180 * Math.PI) * ANIMAL_SPEED;
if(forward==true){
setVelX(controlledMob, velX);
setVelZ(controlledMob, velZ);
}
if(backward==true){
setVelX(controlledMob, -velX);
setVelZ(controlledMob, -velZ);
}
if(up==true){
setVelY(controlledMob, 0.5);
}
if(down==true){
setVelY(controlledMob, -0.5);
}
}
if(controlsReady==true && forward==false && backward==false && up==false && down==false){
setVelX(controlledMob, 0);
setVelZ(controlledMob, 0);
setVelY(controlledMob, 0);
}
}