farm -> dirt on player fall, how works better

This commit is contained in:
GameHerobrine 2023-07-10 00:41:20 +03:00
parent 1baafb8b26
commit 8e5d2bb1c7
8 changed files with 34 additions and 22 deletions

View file

@ -468,20 +468,6 @@ class Entity extends Position
$hasUpdate = true;
}
break;
/*default:
if($this->isPlayer()){
ConsoleAPI::debug("new {}");
ConsoleAPI::debug($this->boundingBox);
ConsoleAPI::debug(($this->boundingBox->maxY - $this->boundingBox->minY).", {$this->onGround}");
}
if (!$b->isTransparent && $b->boundingBox->intersectsWith($bup) and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER)) {
$this->harm(1, "suffocation"); // Suffocation
$hasUpdate = true;
} elseif ($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1)) {
$this->air = 200; // Breathing
}
break;*/
}
}
}
@ -731,6 +717,17 @@ class Entity extends Position
public function fall(){
if($this->isPlayer()){
$x = floor($this->x);
$y = floor($this->y - 0.2);
$z = floor($this->z);
$bid = $this->level->level->getBlockID($x, $y, $z);
if($bid > 0){
$clz = StaticBlock::getBlock($bid);
$clz::fallOn($this->level, $x, $y, $z, $this, floor($this->fallStart - $this->y));
}
$dmg = floor($this->fallStart - $this->y) - 3;
if($dmg > 0){
$this->harm($dmg, "fall");

View file

@ -156,7 +156,7 @@ abstract class Block extends Position{
public $slipperiness;
public static function onRandomTick(Level $level, $x, $y, $z){}
public static function fallOn(Level $level, $x, $y, $z, Entity $entity, $fallDistance){}
public function __construct($id, $meta = 0, $name = "Unknown"){
$this->id = (int) $id;
$this->meta = (int) $meta;

View file

@ -37,6 +37,10 @@ class StaticBlock
}
}
public static function getBlock($id){
return nullsafe(Block::$class[$id], Block::$class[0]);
}
public static function getBoundingBoxForBlockCoords($id, $x, $y, $z){
/**@var AxisAlignedBB $bb*/
$bb = nullsafe(self::$boundingBoxes[$id], false);

View file

@ -16,6 +16,14 @@ class FarmlandBlock extends TransparentBlock{
return $b->isTransparent && $b->id != 0;
}
public static function fallOn(Level $level, $x, $y, $z, Entity $entity, $fallDistance){
$rv = lcg_value();
console("rv: $rv, fd: ".($fallDistance - 0.5));
if($rv < ($fallDistance - 0.5)){
$level->fastSetBlockUpdate($x, $y, $z, DIRT, 0);
}
}
public static function onRandomTick(Level $level, $x, $y, $z){
$meta = $level->level->getBlockDamage($x, $y, $z);
$b = $level->level->getBlockID($x, $y + 1, $z);

View file

@ -15,7 +15,7 @@ class DirtBlock extends SolidBlock{
if($item->getMetadata() >= $item->getMaxDurability()) $player->setSlot($player->slot, new Item(AIR, 0, 0), false);
else $player->setSlot($player->slot, $item, true);
}
$this->level->setBlock($this, BlockAPI::get(FARMLAND, 0), true, false, true);
$this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, FARMLAND, 0, true);
return true;
}
return false;

View file

@ -27,7 +27,7 @@ class GrassBlock extends SolidBlock{
if($item->getMetadata() >= $item->getMaxDurability()) $player->setSlot($player->slot, new Item(AIR, 0, 0), false);
else $player->setSlot($player->slot, $item, true);
}
$this->level->setBlock($this, new FarmlandBlock());
$this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, FARMLAND, 0, true);
$this->seedsDrop();
return true;
}

View file

@ -586,11 +586,14 @@ class Utils{
}
public static function chance($i){//GameHerobrine's code
return self::randomFloat() <= $i / 100;
return lcg_value() <= $i / 100;
}
public static function randomFloat(){//GameHerobrine's code
return rand() / getrandmax();
/**
* @deprecated use lcg_value instead
*/
public static function randomFloat(){
return lcg_value();
}
public static function round($number){

View file

@ -311,7 +311,7 @@ class Level{
$pk->meta = $meta;
$this->server->api->player->broadcastPacket($this->players, $pk);
if($updateBlock){
$this->server->api->block->blockUpdateAround(new Vector3($x, $y, $z), BLOCK_UPDATE_NORMAL, 1);
$this->server->api->block->blockUpdateAround(new Position($x, $y, $z, $this), BLOCK_UPDATE_NORMAL, 1);
}
}