Merge pull request #17 from GameHerobrine/test

milk is now obtainable, sheep can be sheared
This commit is contained in:
kotyara 2022-05-28 19:23:18 +00:00 • committed by GitHub
commit 583a416d35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 3 deletions

View file

@ -1819,6 +1819,7 @@ class Player{
if($this->spawned === false){
break;
}
$needsBreak = false;
$packet->eid = $this->eid;
$data = array();
$data["target"] = $packet->target;
@ -1830,9 +1831,34 @@ class Player{
if($target instanceof Entity and $this->entity instanceof Entity and $this->gamemode !== VIEW and $this->blocked === false and ($target instanceof Entity) and $this->entity->distance($target) <= 8){
$data["targetentity"] = $target;
$data["entity"] = $this->entity;
if($target->class === ENTITY_PLAYER and ($this->server->api->getProperty("pvp") == false or $this->server->difficulty <= 0 or ($target->player->gamemode & 0x01) === 0x01)){
break;
}elseif($this->server->handle("player.interact", $data) !== false){
if($packet->action === InteractPacket::ACTION_HOLD){
switch($target->class){
case ENTITY_MOB:
$slot = $this->getSlot($this->slot);
switch($target->type){
case MOB_COW:
if($slot->getID() === BUCKET && $slot->getMetadata() === 0){ //Empty Bucket
$this->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true); //remove a bucket
$this->addItem(BUCKET, 1, $slot->count, true); //add a milk bucket
$needsBreak = true;
}
break;
case MOB_SHEEP:
if($slot->getID() === SHEARS && $target->data["Sheared"] === 0){ //not sheared
ServerAPI::request()->api->entity->drop(new Position($target->x + 0.5, $target->y, $target->z + 0.5, $target->level), BlockAPI::getItem(WOOL, $target->data["Color"], mt_rand(1,3)));
$target->data["Sheared"] = 1; //i hope it means sheared right?
$target->updateMetadata();
$needsBreak = true;
}
}
}
}
if($needsBreak){
break;
}
if($target->class === ENTITY_PLAYER and ($this->server->api->getProperty("pvp") == false or $this->server->difficulty <= 0 or ($target->player->gamemode & 0x01) === 0x01)){
break;
}elseif($this->server->handle("player.interact", $data) !== false){
$slot = $this->getSlot($this->slot);
switch($slot->getID()){
case WOODEN_SWORD:

View file

@ -20,6 +20,9 @@
*/
class InteractPacket extends RakNetDataPacket{
const ACTION_HOLD = 1; //HOLD CLICK ON ENTITY
const ACTION_ATTACK = 2; //SIMPLE CLICK(ATTACK)
public $action;
public $eid;
public $target;