From 057fb8898abe6344fb298af8333c2ddbed60e60c Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Thu, 9 May 2024 01:40:55 +0300 Subject: [PATCH] fixed trpadoors, walls and beds hitboxes + projectile aabb fix for tallgrass --- .../block/attachable/TrapdoorBlock.php | 39 +++++++++++++ src/material/block/misc/BedBlock.php | 6 +- src/material/block/nonfull/StoneWallBlock.php | 57 +++++++++++++++++++ src/material/block/plant/TallGrassBlock.php | 4 ++ 4 files changed, 105 insertions(+), 1 deletion(-) diff --git a/src/material/block/attachable/TrapdoorBlock.php b/src/material/block/attachable/TrapdoorBlock.php index aa78eec1..7d638722 100644 --- a/src/material/block/attachable/TrapdoorBlock.php +++ b/src/material/block/attachable/TrapdoorBlock.php @@ -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( diff --git a/src/material/block/misc/BedBlock.php b/src/material/block/misc/BedBlock.php index 00cb61d4..0f1efde7 100644 --- a/src/material/block/misc/BedBlock.php +++ b/src/material/block/misc/BedBlock.php @@ -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; diff --git a/src/material/block/nonfull/StoneWallBlock.php b/src/material/block/nonfull/StoneWallBlock.php index 24d7c62b..b9ac1194 100644 --- a/src/material/block/nonfull/StoneWallBlock.php +++ b/src/material/block/nonfull/StoneWallBlock.php @@ -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); + } } \ No newline at end of file diff --git a/src/material/block/plant/TallGrassBlock.php b/src/material/block/plant/TallGrassBlock.php index 6c959713..ff72cc56 100644 --- a/src/material/block/plant/TallGrassBlock.php +++ b/src/material/block/plant/TallGrassBlock.php @@ -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);