Skip to content
This repository was archived by the owner on Jul 11, 2018. It is now read-only.

Commit 3bba524

Browse files
committed
Mobsters-0.5.0
1 parent fc5e96d commit 3bba524

File tree

6 files changed

+160
-31
lines changed

6 files changed

+160
-31
lines changed

Mobsters/plugin.yml

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
name: Mobsters
2-
version: 0.4.0
2+
version: 0.5.0
33
api: [1.12.0]
44
load: STARTUP
55
main: aliuly\mobsters\Main
66

77
author: aliuly
88
description: A simple Entity implementation
9+
10+
commands:
11+
mobster:
12+
description: "Spawn a mob"
13+
usage: "/mobster [spawn] <name> <x,y,z[,yaw,pitch][:world]>"
14+
aliases: [mob]
15+
permission: mobsters.cmd
16+
17+
permissions:
18+
mobsters.cmd:
19+
default: op
20+
description: "Allow mobster commands"
21+
mobsters.cmd.spawn:
22+
default: op
23+
description: "Allow to spawn mobs by command line"

Mobsters/src/aliuly/mobsters/Main.php

+91-22
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,50 @@
2323
use aliuly\mobsters\idiots\Zombie;
2424
use aliuly\mobsters\idiots\Villager;
2525

26+
use pocketmine\command\CommandExecutor;
27+
use pocketmine\command\ConsoleCommandSender;
28+
use pocketmine\command\CommandSender;
29+
use pocketmine\command\Command;
30+
use pocketmine\Player;
31+
2632
use pocketmine\event\player\PlayerInteractEvent;
2733
use pocketmine\math\Vector3;
34+
use pocketmine\level\Location;
35+
use pocketmine\nbt\tag\Byte;
36+
use pocketmine\nbt\tag\Tag;
37+
use pocketmine\nbt\tag\Compound;
38+
use pocketmine\nbt\tag\Double;
39+
use pocketmine\nbt\tag\Enum;
40+
use pocketmine\nbt\tag\Float;
41+
use pocketmine\nbt\tag\String;
42+
use pocketmine\nbt\tag\Int;
43+
2844

29-
class Main extends PluginBase implements Listener{
45+
class Main extends PluginBase implements Listener,CommandExecutor{
3046
public $spawner = [];
47+
protected $classtab;
3148

3249
public function onEnable(){
50+
$this->spawner = [];
51+
$this->classtab = [];
52+
$ns = "aliuly\\mobsters\\idiots\\";
3353
foreach([
34-
Chicken::NETWORK_ID, Pig::NETWORK_ID, Sheep::NETWORK_ID,
35-
Cow::NETWORK_ID, Mooshroom::NETWORK_ID, Wolf::NETWORK_ID,
36-
Enderman::NETWORK_ID, Spider::NETWORK_ID, Skeleton::NETWORK_ID,
37-
PigZombie::NETWORK_ID, Creeper::NETWORK_ID, Slime::NETWORK_ID,
38-
Silverfish::NETWORK_ID
54+
"Chicken", "Pig", "Sheep", "Cow","Mooshroom", "Wolf",
55+
"Enderman", "Spider", "Skeleton", "PigZombie", "Creeper",
56+
"Silverfish", "-Zombie", "-Villager",
3957
] as $type){
40-
Item::addCreativeItem(Item::get(Item::SPAWN_EGG, $type));
58+
$class = $ns.$type;
59+
if ($type{0} == "-") {
60+
$type = substr($type,1);
61+
$class = $ns.$type;
62+
} else {
63+
$id = $class::NETWORK_ID;
64+
Item::addCreativeItem(Item::get(Item::SPAWN_EGG,$id));
65+
}
66+
Entity::registerEntity($class);
67+
$this->classtab[$class::NETWORK_ID] = $class;
68+
$this->classtab[strtolower($type)] = $class;
4169
}
42-
Entity::registerEntity(Chicken::class);
43-
Entity::registerEntity(Pig::class);
44-
Entity::registerEntity(Sheep::class);
45-
Entity::registerEntity(Cow::class);
46-
Entity::registerEntity(Mooshroom::class);
47-
Entity::registerEntity(Wolf::class);
48-
Entity::registerEntity(Enderman::class);
49-
Entity::registerEntity(Spider::class);
50-
Entity::registerEntity(Skeleton::class);
51-
Entity::registerEntity(PigZombie::class);
52-
Entity::registerEntity(Creeper::class);
53-
//Entity::registerEntity(Slime::class);
54-
Entity::registerEntity(Silverfish::class);
55-
Entity::registerEntity(Villager::class);
56-
Entity::registerEntity(Zombie::class);
5770
$this->getServer()->getPluginManager()->registerEvents($this, $this);
5871
}
5972
public function onPlayerInteract(PlayerInteractEvent $e) {
@@ -77,4 +90,60 @@ public function getSpawner($x,$y,$z) {
7790
}
7891
return ["",0];
7992
}
93+
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) {
94+
if ($cmd->getName() != "mobster") return false;
95+
if (isset($args[0]) && strtolower($args[0]) == "spawn") array_shift($args);
96+
if (!$sender->hasPermission("mobsters.cmd.spawn")) {
97+
$sender->sendMessage("You are not allowed to do that!");
98+
return true;
99+
}
100+
if (count($args) != 2) return false;
101+
$mob = strtolower(array_shift($args));
102+
if (!isset($this->classtab[$mob])) {
103+
$sender->sendMessage("Unknown mob class: $mob");
104+
return true;
105+
}
106+
$class = $this->classtab[$mob];
107+
$location = explode(":",array_shift($args),2);
108+
if (count($location)<2) {
109+
if ($sender instanceof Player)
110+
$level = $sender->getLevel();
111+
else {
112+
$level = $this->getServer()->getDefaultLevel();
113+
}
114+
} else {
115+
$level = $this->getServer()->getLevelByName($location[1]);
116+
if ($level === null) {
117+
$sender->sendMessage("Unknown level: ".$location[1]);
118+
return true;
119+
}
120+
}
121+
$location = array_map("floatval",explode(",",$location[0],5));
122+
if (count($location)<3) {
123+
$sender->sendMessage("Invalid location specified");
124+
return false;
125+
}
126+
$location = new Location(...$location);
127+
$location->setLevel($level);
128+
$nbt = new Compound("",[
129+
new Enum("Pos",[
130+
new Double("",$location->x),
131+
new Double("",$location->y),
132+
new Double("",$location->z),
133+
]),
134+
new Enum("Motion", [
135+
new Double("",0),
136+
new Double("",0),
137+
new Double("",0),
138+
]),
139+
new Enum("Rotation",[
140+
new Float("",$location->yaw),
141+
new Float("",$location->pitch),
142+
])
143+
]);
144+
$entity = new $class($location->getLevel()->getChunk($location->x >> 4, $location->z >> 4), $nbt);
145+
$entity->spawnToAll();
146+
$sender->sendMessage("Spawned $mob");
147+
return true;
148+
}
80149
}

Mobsters/src/aliuly/mobsters/idiots/Chicken.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use pocketmine\network\Network;
88
use pocketmine\Player;
99
use pocketmine\entity\Animal;
10+
use pocketmine\entity\Entity;
1011

1112
use pocketmine\network\protocol\MovePlayerPacket;
1213
use pocketmine\math\AxisAlignedBB;
@@ -24,6 +25,7 @@ class Chicken extends Animal{
2425
public $width = 0.5;
2526
public $length = 0.8125;
2627
public $height = 0.875;
28+
public $knockback = 0;
2729

2830
public static $range = 16;
2931
public static $speed = 0.05;
@@ -64,7 +66,7 @@ public function getDrops(){
6466
return $drops;
6567
}
6668

67-
public function updateMovement(){
69+
public function zupdateMovement(){
6870
if($this->x !== $this->lastX or $this->y !== $this->lastY or $this->z !== $this->lastZ or $this->yaw !== $this->lastYaw or $this->pitch !== $this->lastPitch){
6971
$this->lastX = $this->x;
7072
$this->lastY = $this->y;
@@ -136,6 +138,12 @@ private function findTarget(){
136138
}
137139

138140
public function onUpdate($currentTick){
141+
if ($this->knockback) {
142+
if (time() < $this->knockback) {
143+
return parent::onUpdate($currentTick);
144+
}
145+
$this->knockback = 0;
146+
}
139147
$hasUpdate = false;
140148
$this->timings->startTiming();
141149

@@ -206,5 +214,9 @@ public function onUpdate($currentTick){
206214
$hasUpdate = parent::onUpdate($currentTick) || $hasUpdate;
207215
return $hasUpdate;
208216
}
217+
public function knockBack(Entity $attacker, $damage, $x, $z, $base = 0.4){
218+
parent::knockBack($attacker,$damage,$x,$z,$base);
219+
$this->knockback = time() + 1;// Stunned for 1 second...
220+
}
209221

210222
}

Mobsters/src/aliuly/mobsters/idiots/Pig.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use pocketmine\Player;
99
use pocketmine\entity\Rideable;
1010
use pocketmine\entity\Animal;
11+
use pocketmine\entity\Entity;
12+
1113

1214
use pocketmine\network\protocol\MovePlayerPacket;
1315
use pocketmine\math\AxisAlignedBB;
@@ -21,6 +23,7 @@ class Pig extends Animal implements Rideable{
2123
public $length = 1.3;
2224
public $height = 0.875;
2325
public $stepHeight = 0.2;
26+
public $knockback = 0;
2427

2528
public function getName(){
2629
return "Porky";
@@ -51,7 +54,7 @@ public function getDrops(){
5154
return [Item::get($this->fireTicks > 0 ? Item::COOKED_PORKCHOP : Item::RAW_PORKCHOP, 0, mt_rand(1, 3))];
5255
}
5356

54-
public function updateMovement(){
57+
public function noupdateMovement(){
5558
if($this->x !== $this->lastX or $this->y !== $this->lastY or $this->z !== $this->lastZ or $this->yaw !== $this->lastYaw or $this->pitch !== $this->lastPitch){
5659
$this->lastX = $this->x;
5760
$this->lastY = $this->y;
@@ -122,6 +125,12 @@ private function findTarget(){
122125
}
123126

124127
public function onUpdate($currentTick){
128+
if ($this->knockback) {
129+
if (time() < $this->knockback) {
130+
return parent::onUpdate($currentTick);
131+
}
132+
$this->knockback = 0;
133+
}
125134
$hasUpdate = false;
126135
$this->timings->startTiming();
127136

@@ -198,5 +207,9 @@ public function onUpdate($currentTick){
198207
$hasUpdate = parent::onUpdate($currentTick) || $hasUpdate;
199208
return $hasUpdate;
200209
}
210+
public function knockBack(Entity $attacker, $damage, $x, $z, $base = 0.4){
211+
parent::knockBack($attacker,$damage,$x,$z,$base);
212+
$this->knockback = time() + 1;// Stunned for 1 second...
213+
}
201214

202215
}

Mobsters/src/aliuly/mobsters/idiots/Wolf.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
use pocketmine\Player;
1111
use pocketmine\entity\Animal;
12+
use pocketmine\entity\Entity;
13+
1214
use pocketmine\entity\Tameable;
1315
use pocketmine\nbt\tag\String;
1416
use pocketmine\math\AxisAlignedBB;
@@ -25,6 +27,7 @@ class Wolf extends Animal implements Tameable{
2527
public $length = 1.4375;
2628
public $height = 1.25;
2729
public $owner = null;
30+
public $knockback = 0;
2831

2932
public function getName(){
3033
return "LameWolf";
@@ -91,7 +94,7 @@ public function getBoundingBox(){
9194
);
9295
return $this->boundingBox;
9396
}
94-
public function updateMovement(){
97+
public function noupdateMovement(){
9598
if($this->x !== $this->lastX or $this->y !== $this->lastY or $this->z !== $this->lastZ or $this->yaw !== $this->lastYaw or $this->pitch !== $this->lastPitch){
9699
$event = new \pocketmine\event\entity\EntityMoveEvent($this,new \pocketmine\math\Vector3($this->x - $this->lastX,$this->y - $this->lastY,$this->z - $this->lastZ));
97100
$this->server->getPluginManager()->callEvent($event);
@@ -130,6 +133,12 @@ public function updateMovement(){
130133
}
131134

132135
public function onUpdate($currentTick){
136+
if ($this->knockback) {
137+
if (time() < $this->knockback) {
138+
return parent::onUpdate($currentTick);
139+
}
140+
$this->knockback = 0;
141+
}
133142
$hasUpdate = false;
134143
$this->timings->startTiming();
135144

@@ -210,5 +219,9 @@ public function onUpdate($currentTick){
210219
$hasUpdate = parent::onUpdate($currentTick) || $hasUpdate;
211220
return $hasUpdate;
212221
}
222+
public function knockBack(Entity $attacker, $damage, $x, $z, $base = 0.4){
223+
parent::knockBack($attacker,$damage,$x,$z,$base);
224+
$this->knockback = time() + 1;// Stunned for 1 second...
225+
}
213226

214227
}

Mobsters/src/aliuly/mobsters/idiots/Zombie.php

+12-5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class Zombie extends Monster{
4848
public $length = 0.6;
4949
public $height = 1.8;
5050
public $stepHeight = 0.5;
51+
public $knockback = 0;
5152

5253
public function getName(){
5354
return "ZombieIdiot";
@@ -110,8 +111,7 @@ public function getDrops(){
110111

111112
return $drops;
112113
}
113-
114-
public function updateMovement(){
114+
public function zupdateMovement(){
115115
if($this->x !== $this->lastX or $this->y !== $this->lastY or $this->z !== $this->lastZ or $this->yaw !== $this->lastYaw or $this->pitch !== $this->lastPitch){
116116

117117
$this->lastX = $this->x;
@@ -181,6 +181,12 @@ private function findTarget(){
181181
}
182182

183183
public function onUpdate($currentTick){
184+
if ($this->knockback) {
185+
if (time() < $this->knockback) {
186+
return parent::onUpdate($currentTick);
187+
}
188+
$this->knockback = 0;
189+
}
184190
$hasUpdate = false;
185191
$this->timings->startTiming();
186192

@@ -257,9 +263,10 @@ public function onUpdate($currentTick){
257263
$hasUpdate = parent::onUpdate($currentTick) || $hasUpdate;
258264
return $hasUpdate;
259265
}
260-
public function knockBack(Entity $attacker, $damage, $x, $z, $base = 0.4){
261-
//echo __METHOD__.",".__LINE__."\n"; //##DEBUG
262-
parent::knockBack($attacker,$damage,$x,$z,2.5);
266+
public function knockBack(Entity $attacker, $damage, $x, $z, $base = 2){
267+
echo __METHOD__.",".__LINE__."\n"; //##DEBUG
268+
parent::knockBack($attacker,$damage,$x,$z,$base);
269+
$this->knockback = time() + 1;// Stunned for 1 second...
263270
}
264271

265272
}

0 commit comments

Comments
 (0)