Merge pull request #19 from GameHerobrine/test

baby entities can spawn from eggs, minecarts
This commit is contained in:
kotyara 2022-05-29 15:43:51 +00:00 • committed by GitHub
commit dbac8582ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 146 additions and 6 deletions

View file

@ -1833,6 +1833,29 @@ class Player{
$data["entity"] = $this->entity;
if($packet->action === InteractPacket::ACTION_HOLD){
switch($target->class){
case ENTITY_OBJECT:
switch($target->type){
case OBJECT_MINECART:
if($target->linkedEntity != null){
break;
}
$players = $this->server->api->player->getAll($this->level);
$pk = new SetEntityLinkPacket;
$pk->rider = $target->eid;
$pk->riding = $this->entity->eid;
$pk->type = 2;
$this->server->api->player->broadcastPacket([$this], $pk);
$target->linkedEntity = $this->entity;
$this->entity->isInMinecart = true;
$pk = new SetEntityLinkPacket();
$pk->rider = $target->eid;
$pk->riding = 0;
$pk->type = 2;
$this->dataPacket($pk);
$needsBreak = true;
}
case ENTITY_MOB:
$slot = $this->getSlot($this->slot);
switch($target->type){
@ -1856,6 +1879,27 @@ class Player{
}
}
}
if($packet->action === InteractPacket::ACTION_VEHICLE_EXIT){
switch($target->class){
case ENTITY_OBJECT:
switch($target->type){
case OBJECT_MINECART:
$players = $this->server->api->player->getAll($this->level);
$pk = new SetEntityLinkPacket();
$pk->rider = targetEntity.getId();
$pk->riding = this.id;
$pk->type = 3;
$this->server->api->player->broadcastPacket([$this], $pk);
$this->entity->isInMinecart = false;
$target->linkedEntity = null;
$pk = new SetEntityLinkPacket();
$pk->rider = $target->eid;
$pk->riding = 0;
$pk->type = 3;
$this->dataPacket($pk);
}
}
}
if($needsBreak){
break;
}

View file

@ -22,6 +22,22 @@
class MinecartItem extends Item{
public function __construct($meta = 0, $count = 1){
parent::__construct(MINECART, 0, $count, "Minecart");
$this->isActivable = true;
}
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($target->getID() !== 66 and $target->getID() !== 27){
return;
}
$server = ServerAPI::request();
$data = [
"x" => $target->getX(),
"y" => $target->getY() + 0.8,
"z" => $target->getZ(),
];
$e = $server->api->entity->add($level, ENTITY_OBJECT, OBJECT_MINECART, $data);
$server->api->entity->spawnToAll($e);
if(($player->gamemode & 0x01) === 0x00){
$player->removeItem($this->getID(), $this->getMetadata(), 1, false);
}
}
}

View file

@ -27,11 +27,13 @@ class SpawnEggItem extends Item{
}
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$ageable = false;
switch($this->meta){
case MOB_CHICKEN:
case MOB_SHEEP:
case MOB_COW:
case MOB_PIG:
$ageable = true;
case MOB_ZOMBIE:
case MOB_CREEPER:
case MOB_SKELETON:
@ -41,6 +43,7 @@ class SpawnEggItem extends Item{
"x" => $block->x + 0.5,
"y" => $block->y,
"z" => $block->z + 0.5,
"isBaby" => $ageable ? mt_rand(0,20) === 0 ? 1 : 0 : 0,
);
$e = ServerAPI::request()->api->entity->add($block->level, ENTITY_MOB, $this->meta, $data);
ServerAPI::request()->api->entity->spawnToAll($e);

View file

@ -78,7 +78,7 @@ abstract class ProtocolInfo{
const HURT_ARMOR_PACKET = 0xa6;
const SET_ENTITY_DATA_PACKET = 0xa7;
const SET_ENTITY_MOTION_PACKET = 0xa8;
//const SET_ENTITY_LINK_PACKET = 0xa9;
const SET_ENTITY_LINK_PACKET = 0xa9;
const SET_HEALTH_PACKET = 0xaa;
const SET_SPAWN_POSITION_PACKET = 0xab;
const ANIMATE_PACKET = 0xac;

View file

@ -22,7 +22,7 @@
class InteractPacket extends RakNetDataPacket{
const ACTION_HOLD = 1; //HOLD CLICK ON ENTITY
const ACTION_ATTACK = 2; //SIMPLE CLICK(ATTACK)
const ACTION_VEHICLE_EXIT = 3; //EXIT FROM ENTITY(MINECART)
public $action;
public $eid;
public $target;

View file

@ -0,0 +1,29 @@
<?php
/*
Lets hope it will work
*/
class SetEntityLinkPacket extends RakNetDataPacket{
const TYPE_REMOVE = 0;
const TYPE_RIDE = 1;
const TYPE_PASSENGER = 2;
public $rider;
public $riding;
public $type;
public function decode() {
}
public function encode() {
$this->reset();
$this->putLong($this->rider);
$this->putLong($this->riding);
$this->putByte($this->type);
}
public function pid(){
return ProtocolInfo::SET_ENTITY_LINK_PACKET;
}
}

View file

@ -346,6 +346,8 @@ class RakNetParser{
case ProtocolInfo::ENTITY_DATA_PACKET:
$data = new EntityDataPacket;
break;
case ProtocolInfo::SET_ENTITY_LINK_PACKET:
$data = new SetEntityLinkPacket;
default:
$data = new UnknownPacket();
$data->packetID = $pid;

View file

@ -50,7 +50,9 @@ class Entity extends Position{
private $server;
private $isStatic;
public $level;
public $isInMinecart = false;
public $lastUpdate;
public $linkedEntity = null;
public $check = true;
public $size = 1;
public $inAction = false;
@ -144,6 +146,8 @@ class Entity extends Position{
}elseif($this->type === (OBJECT_ARROW or OBJECT_SNOWBALL)){
$this->server->schedule(1210, array($this, "update")); //Despawn
$this->update();
}elseif($this->type == OBJECT_MINECART){
$this->update();
}
break;
}
@ -195,6 +199,10 @@ class Entity extends Position{
return array(
array(PAINTING, 0, 1),
);
case OBJECT_MINECART:
return array(
array(MINECART, 0, 1),
);
}
}elseif($this->class === ENTITY_MOB){
switch($this->type){
@ -526,7 +534,7 @@ class Entity extends Position{
$this->fallY = $y;
$this->fallStart = microtime(true);
}elseif($this->class === ENTITY_PLAYER and ($this->fallStart + 5) < microtime(true)){
if($this->server->api->getProperty("allow-flight") !== true and $this->server->handle("player.flying", $this->player) !== true){
if($this->server->api->getProperty("allow-flight") !== true and $this->server->handle("player.flying", $this->player) !== true and $this->isInMinecart === false){
$this->player->close("flying");
return;
}
@ -625,7 +633,23 @@ class Entity extends Position{
return null;
}
}
/*METADATA VALUES(EXPEREMENTAL)
******************
Types: Get input type of <value>
0 -> Byte
1 -> Short
2 -> Integer
3 -> Float
4 -> Length of <value>, Short
5 -> array(Short, Byte, Short)
6 -> arry(Integer, Integer, Integer)
******************
0 => array("type" => 0, "value" => $flags) --> Unknown
1 => array("type" => 1, "value" => $this->air) --> Entity Air
14 => array("type" => 0, "value" => 1) --> isBaby, value: 0 => false, 1 => true
16 => array("type" => 0, "value" => 0) --> Unknown
17 => array("type" => 6, "value" => array(0, 0, 0)) --> Unknown
*/
public function getMetadata(){
$flags = 0;
$flags |= $this->fire > 0 ? 1:0;
@ -634,10 +658,14 @@ class Entity extends Position{
$d = array(
0 => array("type" => 0, "value" => $flags),
1 => array("type" => 1, "value" => $this->air),
//14 => array("type" => 0, "value" => 1), wip
14 => array("type" => 0, "value" => 0),
16 => array("type" => 0, "value" => 0),
17 => array("type" => 6, "value" => array(0, 0, 0)),
);
if(!isset($this->data["isBaby"])){
$this->data["isBaby"] = 0;
}
$d[14]["value"] = $this->data["isBaby"];
if($this->class === ENTITY_MOB and $this->type === MOB_SHEEP){
if(!isset($this->data["Sheared"])){
$this->data["Sheared"] = 0;
@ -782,6 +810,24 @@ class Entity extends Position{
$pk->speedY = $this->speedY;
$pk->speedZ = $this->speedZ;
$player->dataPacket($pk);
}elseif($this->type === OBJECT_MINECART){
$pk = new AddEntityPacket;
$pk->eid = $this->eid;
$pk->type = $this->type;
$pk->x = $this->x;
$pk->y = $this->y;
$pk->z = $this->z;
$pk->yaw = $this->yaw;
$pk->pitch = $this->pitch;
$player->dataPacket($pk);
$pk = new SetEntityMotionPacket;
$pk->eid = $this->eid;
$pk->speedX = $this->speedX;
$pk->speedY = $this->speedY;
$pk->speedZ = $this->speedZ;
$player->dataPacket($pk);
}
break;
case ENTITY_FALLING: