Added some weird things to test entities

This commit is contained in:
Shoghi Cervantes Pueyo 2012-12-07 20:48:27 +01:00
parent 48a331cff1
commit 4d24f829aa
5 changed files with 99 additions and 9 deletions

1
README
View File

@ -40,4 +40,5 @@ Current features of the server:
- Whitelist and IP Ban files - Whitelist and IP Ban files
- Survival & Creative - Survival & Creative
- Awesome features in server list! - Awesome features in server list!
- Entities and player spawn as Dropped items
- Multiple worlds and importing! - Multiple worlds and importing!

View File

@ -241,6 +241,19 @@ class CustomPacketHandler{
$this->raw .= Utils::writeByte($this->data["roll"]); $this->raw .= Utils::writeByte($this->data["roll"]);
} }
break; break;
case MC_MOVE_ENTITY:
if($this->c === false){
$this->data["eid"] = Utils::readInt($this->get(4));
$this->data["x"] = Utils::readFloat($this->get(4));
$this->data["y"] = Utils::readFloat($this->get(4));
$this->data["z"] = Utils::readFloat($this->get(4));
}else{
$this->raw .= Utils::writeInt($this->data["eid"]);
$this->raw .= Utils::writeFloat($this->data["x"]);
$this->raw .= Utils::writeFloat($this->data["y"]);
$this->raw .= Utils::writeFloat($this->data["z"]);
}
break;
case MC_MOVE_PLAYER: case MC_MOVE_PLAYER:
if($this->c === false){ if($this->c === false){
$this->data["eid"] = Utils::readInt($this->get(4)); $this->data["eid"] = Utils::readInt($this->get(4));

View File

@ -88,6 +88,24 @@ class Session{
public function eventHandler($data, $event){ public function eventHandler($data, $event){
switch($event){ switch($event){
case "onEntityMove":
if($data === $this->eid){
break;
}
$entity = $this->server->entities[$this->eid];
$this->send(0x84, array(
$this->counter[0],
0x00,
array(
"id" => MC_MOVE_ENTITY,
"eid" => $data,
"x" => $entity->position["x"],
"y" => $entity->position["y"],
"z" => $entity->position["z"],
),
));
++$this->counter[0];
break;
case "onHealthChange": case "onHealthChange":
if($data["eid"] === $this->eid){ if($data["eid"] === $this->eid){
$this->send(0x84, array( $this->send(0x84, array(
@ -98,6 +116,7 @@ class Session{
"health" => $data["health"], "health" => $data["health"],
), ),
)); ));
++$this->counter[0];
$this->data["health"] = $data["health"]; $this->data["health"] = $data["health"];
if(is_object($this->entity)){ if(is_object($this->entity)){
$this->entity->setHealth($data["health"]); $this->entity->setHealth($data["health"]);
@ -108,7 +127,7 @@ class Session{
if($data["eid"] === $this->eid){ if($data["eid"] === $this->eid){
break; break;
} }
$this->send(0x84, array( /*$this->send(0x84, array(
$this->counter[0], $this->counter[0],
0x00, 0x00,
array( array(
@ -125,6 +144,23 @@ class Session{
"meta" => $data["meta"], "meta" => $data["meta"],
), ),
)); ));
++$this->counter[0];
*/
$this->send(0x84, array(
$this->counter[0],
0x00,
array(
"id" => MC_ADD_ITEM_ENTITY,
"eid" => $data["eid"],
"x" => $data["x"],
"y" => $data["y"],
"z" => $data["z"],
"block" => 10,
"meta" => 0,
"stack" => 1,
),
));
++$this->counter[0];
break; break;
case "onEntityRemove": case "onEntityRemove":
if($data === $this->eid){ if($data === $this->eid){
@ -138,6 +174,7 @@ class Session{
"eid" => $data, "eid" => $data,
), ),
)); ));
++$this->counter[0];
} }
break; break;
case "onTimeChange": case "onTimeChange":
@ -239,6 +276,7 @@ class Session{
$this->evid[] = array("onChat", $this->server->event("onChat", array($this, "eventHandler"))); $this->evid[] = array("onChat", $this->server->event("onChat", array($this, "eventHandler")));
$this->evid[] = array("onPlayerAdd", $this->server->event("onPlayerAdd", array($this, "eventHandler"))); $this->evid[] = array("onPlayerAdd", $this->server->event("onPlayerAdd", array($this, "eventHandler")));
$this->evid[] = array("onEntityDespawn", $this->server->event("onEntityDespawn", array($this, "eventHandler"))); $this->evid[] = array("onEntityDespawn", $this->server->event("onEntityDespawn", array($this, "eventHandler")));
$this->evid[] = array("onEntityMove", $this->server->event("onEntityMove", array($this, "eventHandler")));
$this->evid[] = array("onHealthChange", $this->server->event("onHealthChange", array($this, "eventHandler"))); $this->evid[] = array("onHealthChange", $this->server->event("onHealthChange", array($this, "eventHandler")));
$this->send(0x84, array( $this->send(0x84, array(
$this->counter[0], $this->counter[0],
@ -274,7 +312,7 @@ class Session{
$this->entity = new Entity($this->eid, ENTITY_PLAYER, 0, $this->server); $this->entity = new Entity($this->eid, ENTITY_PLAYER, 0, $this->server);
$this->entity->setName($this->username); $this->entity->setName($this->username);
$this->server->entities[$this->eid] = &$this->entity; $this->server->entities[$this->eid] = &$this->entity;
/*$this->server->trigger("onPlayerAdd", array( $this->server->trigger("onPlayerAdd", array(
"clientID" => $this->clientID, "clientID" => $this->clientID,
"username" => $this->username, "username" => $this->username,
"eid" => $this->eid, "eid" => $this->eid,
@ -285,16 +323,50 @@ class Session{
"pitch" => $this->data["spawn"]["pitch"], "pitch" => $this->data["spawn"]["pitch"],
"block" => 0, "block" => 0,
"meta" => 0, "meta" => 0,
));*/ ));
foreach($this->server->entities as $entity){
if($entity->eid !== $this->eid){
$this->send(0x84, array(
$this->counter[0],
0x00,
array(
"id" => MC_ADD_ITEM_ENTITY,
"eid" => $entity->eid,
"x" => $entity->position["x"],
"y" => $entity->position["y"],
"z" => $entity->position["z"],
"block" => $entity->type,
"meta" => 0,
"stack" => 1,
),
));
++$this->counter[0];
}
}
$this->eventHandler($this->server->motd, "onChat"); $this->eventHandler($this->server->motd, "onChat");
$this->server->trigger("onChat", $this->username." joined the game"); $this->server->trigger("onChat", $this->username." joined the game");
break; break;
case MC_MOVE_PLAYER: case MC_MOVE_PLAYER:
$this->entity->setPosition($data["x"], $data["y"], $data["z"], $data["yaw"], $data["pitch"]); $this->entity->setPosition($data["x"], $data["y"], $data["z"], $data["yaw"], $data["pitch"]);
$this->server->trigger("onPlayerMove", $this->eid); $this->server->trigger("onEntityMove", $this->eid);
$this->send(0x84, array(
$this->counter[0],
0x00,
array(
"id" => MC_ADD_ITEM_ENTITY,
"eid" => $this->server->eidCnt++,
"x" => $data["x"],
"y" => $data["y"],
"z" => $data["z"],
"block" => 7,
"meta" => 0,
"stack" => 1,
),
));
++$this->counter[0];
break; break;
case MC_PLAYER_EQUIPMENT: case MC_PLAYER_EQUIPMENT:
console("[DEBUG] EID ".$this->eid." has now ".$data["block"]." with metadata ".$data["meta"]." in their hands!", true, true, 2); console("[DEBUG] EID ".$this->eid." has now ".$data["block"].":".$data["meta"]." in their hands!", true, true, 2);
break; break;
case MC_REQUEST_CHUNK: case MC_REQUEST_CHUNK:
console("[DEBUG] Chunk X ".$data["x"]." Z ".$data["z"]." requested", true, true, 2); console("[DEBUG] Chunk X ".$data["x"]." Z ".$data["z"]." requested", true, true, 2);
@ -307,9 +379,9 @@ class Session{
array( array(
"id" => MC_ADD_ITEM_ENTITY, "id" => MC_ADD_ITEM_ENTITY,
"eid" => $this->server->eidCnt++, "eid" => $this->server->eidCnt++,
"x" => $data["x"], "x" => $data["x"] + mt_rand(0, 100)/100,
"y" => $data["y"], "y" => $data["y"],
"z" => $data["z"], "z" => $data["z"] + mt_rand(0, 100)/100,
"block" => 1, "block" => 1,
"meta" => 0, "meta" => 0,
"stack" => 1, "stack" => 1,

View File

@ -49,6 +49,8 @@ define("MC_ADD_PLAYER", 0x89);
define("MC_REMOVE_ENTITY", 0x8d); define("MC_REMOVE_ENTITY", 0x8d);
define("MC_ADD_ITEM_ENTITY", 0x8e); define("MC_ADD_ITEM_ENTITY", 0x8e);
define("MC_MOVE_ENTITY", 0x90);
define("MC_MOVE_ENTITY_POSROT", 0x93); define("MC_MOVE_ENTITY_POSROT", 0x93);
define("MC_MOVE_PLAYER", 0x94); define("MC_MOVE_PLAYER", 0x94);
define("MC_PLACE_BLOCK", 0x95); define("MC_PLACE_BLOCK", 0x95);

View File

@ -49,6 +49,8 @@ $dataName = array(
MC_REMOVE_ENTITY => "RemoveEntity", MC_REMOVE_ENTITY => "RemoveEntity",
MC_ADD_ITEM_ENTITY => "AddItemEntity", MC_ADD_ITEM_ENTITY => "AddItemEntity",
MC_MOVE_ENTITY => "MoveEntity",
MC_MOVE_ENTITY_POSROT => "MoveEntity_PosRot", MC_MOVE_ENTITY_POSROT => "MoveEntity_PosRot",
MC_MOVE_PLAYER => "MovePlayer", MC_MOVE_PLAYER => "MovePlayer",
MC_PLACE_BLOCK => "PlaceBlock", MC_PLACE_BLOCK => "PlaceBlock",