fixed trpadoors, walls and beds hitboxes + projectile aabb fix for tallgrass

This commit is contained in:
GameHerobrine 2024-05-09 01:40:55 +03:00
parent 518f6a99a7
commit 057fb8898a
4 changed files with 105 additions and 1 deletions

View file

@ -17,6 +17,45 @@ class TrapdoorBlock extends TransparentBlock{
return $id === SLAB || $id === GLOWSTONE || $id === SLAB || $id === WOOD_SLAB || (!$target->isTransparent || $target instanceof StairBlock);
}
public static function isOpen($meta){
return ($meta >> 2) & 1;
}
public static function getAABB(Level $level, $x, $y, $z){
static::updateShape($level, $x, $y, $z);
return StaticBlock::getAABB($level, $x, $y, $z);
}
public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){
return [static::getAABB($level, $x, $y, $z)];
}
public static function updateShape(Level $level, $x, $y, $z){
[$id, $meta] = $level->level->getBlock($x, $y, $z);
StaticBlock::setBlockBounds($id, 0.0, 0.0, 0.0, 1.0, 0.1875, 1.0);
if(static::isOpen($meta)){
$facing = $meta & 3;
switch($facing){
case 0:
StaticBlock::setBlockBounds($id, 0.0, 0.0, 0.8125, 1.0, 1.0, 1.0);
break;
case 1:
StaticBlock::setBlockBounds($id, 0.0, 0.0, 0.0, 1.0, 1.0, 0.1875);
break;
case 2:
StaticBlock::setBlockBounds($id, 0.8125, 0.0, 0.0, 1.0, 1.0, 1.0);
break;
case 3:
StaticBlock::setBlockBounds($id, 0.0, 0.0, 0.0, 0.1875, 1.0, 1.0);
break;
default:
ConsoleAPI::error("wat");
}
}
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if(($this->canAttachTo($target)) and $face !== 0 and $face !== 1){
$faces = array(

View file

@ -20,7 +20,11 @@ class BedBlock extends TransparentBlock{
$this->isFullBlock = false;
$this->hardness = 1;
}
//TODO collision box
public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){
return [static::getAABB($level, $x, $y, $z)];
}
public static function findStandUpPosition(Level $level, $x, $y, $z){
$blockMeta = $level->level->getBlockDamage($x, $y, $z);
$direction = $blockMeta & 0x3;

View file

@ -14,4 +14,61 @@ class StoneWallBlock extends TransparentBlock{
}
return [];
}
public static function connectsTo(Level $level, $x, $y, $z){
$id = $level->level->getBlockID($x, $y, $z);
if($id == STONE_WALL || $id == FENCE_GATE) return true;
if($id == 0) return false;
if(StaticBlock::getIsSolid($id) && !StaticBlock::getIsTransparent($id)){ //XXX in vanilla it uses Material->isSolidBlocking() and Tile->isCubeShaped()
return true; //XXX in vanilla it returns v7->material != Material::vegetable;
}
return false;
}
public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){
return [static::getAABB($level, $x, $y, $z)];
}
public static function getAABB(Level $level, $x, $y, $z){
static::updateShape($level, $x, $y, $z);
StaticBlock::$maxYs[$level->level->getBlockID($x, $y, $z)] = 1.5;
return parent::getAABB($level, $x, $y, $z);
}
public static function updateShape(Level $level, $x, $y, $z){
$zNeg = self::connectsTo($level, $x, $y, $z - 1);
$zPos = self::connectsTo($level, $x, $y, $z + 1);
$xNeg = self::connectsTo($level, $x - 1, $y, $z);
$xPos = self::connectsTo($level, $x + 1, $y, $z);
$minX = 0.25;
$maxY = 1.0;
$maxX = 0.75;
$minZ = $zNeg ? 0 : 0.25;
$maxZ = $zPos ? 1.0 : 0.75;
if($xNeg) $minX = 0;
if($xPos) $maxX = 1.0;
if($zNeg){
if($zPos && !$xNeg){
if(!$xPos){
$maxY = 0.8125;
$maxX = 0.6875;
$minX = 0.3125;
}
}
}else if(!$zPos && $zNeg){
if($xPos){
$maxY = 0.8125;
$maxZ = 0.6875;
$minZ = 0.3125;
}
}
$id = $level->level->getBlockID($x, $y, $z);
StaticBlock::setBlockBounds($id, $minX, 0, $minZ, $maxX, $maxY, $maxZ);
}
}

View file

@ -24,6 +24,10 @@ class TallGrassBlock extends FlowableBlock{
return false;
}
public static function getAABB(Level $level, $x, $y, $z){
return null;
}
public function getDrops(Item $item, Player $player){
$drops = array();
if($item->isShears()) $drops[] = array($this->id, $this->meta & 0x03, 1);