From 8b07056323cf00db99d2c977a37c8be5b9e9df28 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Sat, 4 May 2024 05:51:31 +0300 Subject: [PATCH] arrow collision tweaks --- src/Player.php | 4 +- src/material/Block.php | 6 +- src/material/StaticBlock.php | 3 + src/material/block/LiquidBlock.php | 4 +- .../block/attachable/SignPostBlock.php | 4 +- src/material/block/attachable/TorchBlock.php | 6 ++ src/material/block/misc/FireBlock.php | 4 +- src/material/block/nonfull/CobwebBlock.php | 5 + src/material/block/nonfull/RailBaseBlock.php | 5 + src/material/block/nonfull/SlabBlock.php | 91 +++++++++++-------- src/material/block/nonfull/SnowLayerBlock.php | 4 +- src/material/block/nonfull/WoodSlabBlock.php | 28 +++++- src/material/block/plant/CyanFlowerBlock.php | 6 +- src/material/block/plant/DandelionBlock.php | 4 +- src/material/block/plant/DeadBushBlock.php | 6 +- src/material/block/plant/SaplingBlock.php | 4 +- src/material/block/plant/SugarcaneBlock.php | 4 +- 17 files changed, 137 insertions(+), 51 deletions(-) diff --git a/src/Player.php b/src/Player.php index 2af4c5c1..45ccf0e2 100755 --- a/src/Player.php +++ b/src/Player.php @@ -707,7 +707,7 @@ class Player{ $pk->rider = $data["rider"]; } $pk->riding = $data["riding"]; - $pk->type = 0; //TODO; + $pk->type = 0; $this->dataPacket($pk); break; case "tile.update": @@ -1920,7 +1920,7 @@ class Player{ case 5: //Shot arrow if($this->entity->inAction){ $arrowSlot = $this->hasItem(ARROW); - if($this->getSlot($this->slot)->getID() === BOW && (($this->gamemode & 0x01) == 0x1 || $arrowSlot !== false)){ //TODO check arrow count + if($this->getSlot($this->slot)->getID() === BOW && (($this->gamemode & 0x01) == 0x1 || $arrowSlot !== false)){ if($this->startAction !== false){ $initalPower = $this->entity->inActionCounter; $power = $initalPower / 20; diff --git a/src/material/Block.php b/src/material/Block.php index 32b32b8a..ed847ec0 100755 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -171,8 +171,12 @@ abstract class Block extends Position{ return $v == null ? false : $v->x >= StaticBlock::$minXs[$id] && $v->x <= StaticBlock::$maxXs[$id] && $v->y >= StaticBlock::$minYs[$id] && $v->y <= StaticBlock::$maxYs[$id]; } + public static function updateShape(Level $level, $x, $y, $z){ + + } + public static function clip(Level $level, $x, $y, $z, Vector3 $start, Vector3 $end){ - //self::updateShape($level, $x, $y, $z); TODO update shape + static::updateShape($level, $x, $y, $z); $id = $level->level->getBlockID($x, $y, $z); $start = $start->subtract($x, $y, $z); diff --git a/src/material/StaticBlock.php b/src/material/StaticBlock.php index 76842175..89c8767b 100644 --- a/src/material/StaticBlock.php +++ b/src/material/StaticBlock.php @@ -70,6 +70,9 @@ class StaticBlock self::setBlockBounds(RAIL, 0, 0, 0, 1, 0.125, 1); self::setBlockBounds(POWERED_RAIL, 0, 0, 0, 1, 0.125, 1); + self::setBlockBounds(DANDELION, 0.3, 0.0, 0.3, 0.7, 0.6, 0.7); //extends Bush + self::setBlockBounds(ROSE, 0.3, 0.0, 0.3, 0.7, 0.6, 0.7); //extends Bush + self::setBlockBounds(SUGARCANE_BLOCK, 0.5 - 0.375, 0, 0.5 - 0.375, 0.5 + 0.375, 1, 0.5 + 0.375); self::setBlockBounds(SNOW_LAYER, 0, 0, 0, 1, 0.125, 1); //Stairs: based on different factors diff --git a/src/material/block/LiquidBlock.php b/src/material/block/LiquidBlock.php index 215e225d..2cfa7f72 100644 --- a/src/material/block/LiquidBlock.php +++ b/src/material/block/LiquidBlock.php @@ -15,7 +15,9 @@ class LiquidBlock extends TransparentBlock{ $this->isFullBlock = true; $this->hardness = 500; } - + public static function getAABB(Level $level, $x, $y, $z){ + return null; + } public static function getPercentAir($meta){ if($meta >= 8) $meta = 0; $f = ($meta + 1) / 9; diff --git a/src/material/block/attachable/SignPostBlock.php b/src/material/block/attachable/SignPostBlock.php index 09838670..e94fae08 100644 --- a/src/material/block/attachable/SignPostBlock.php +++ b/src/material/block/attachable/SignPostBlock.php @@ -8,7 +8,9 @@ class SignPostBlock extends TransparentBlock{ 4 => 4, 5 => 5, ]; - + public static function getAABB(Level $level, $x, $y, $z){ + return null; + } public function __construct($meta = 0){ parent::__construct(SIGN_POST, $meta, "Sign Post"); $this->isSolid = false; diff --git a/src/material/block/attachable/TorchBlock.php b/src/material/block/attachable/TorchBlock.php index 7bae649b..70e4ff76 100644 --- a/src/material/block/attachable/TorchBlock.php +++ b/src/material/block/attachable/TorchBlock.php @@ -5,9 +5,15 @@ class TorchBlock extends FlowableBlock implements LightingBlock{ parent::__construct(TORCH, $meta, "Torch"); $this->hardness = 0; } + public function getMaxLightValue(){ return 15; } + + public static function getAABB(Level $level, $x, $y, $z){ + return null; + } + public function onUpdate($type){ if($type === BLOCK_UPDATE_NORMAL){ $side = $this->getMetadata(); diff --git a/src/material/block/misc/FireBlock.php b/src/material/block/misc/FireBlock.php index 319fdd68..c4908adf 100644 --- a/src/material/block/misc/FireBlock.php +++ b/src/material/block/misc/FireBlock.php @@ -12,7 +12,9 @@ class FireBlock extends FlowableBlock implements LightingBlock{ $this->isFullBlock = true; $this->hardness = 0; } - + public static function getAABB(Level $level, $x, $y, $z){ + return null; + } public static function setFlammabilityAndCatchingChance($blockID, $flammability, $v){ self::$flammability[$blockID] = $flammability; self::$fireCatchingChance[$blockID] = $v; diff --git a/src/material/block/nonfull/CobwebBlock.php b/src/material/block/nonfull/CobwebBlock.php index 0982b960..76e79d93 100644 --- a/src/material/block/nonfull/CobwebBlock.php +++ b/src/material/block/nonfull/CobwebBlock.php @@ -7,6 +7,11 @@ class CobwebBlock extends FlowableBlock{ $this->isFullBlock = false; $this->hardness = 25; } + + public static function getAABB(Level $level, $x, $y, $z){ + return null; + } + public function getDrops(Item $item, Player $player){ if ($item->isSword()){ return [ diff --git a/src/material/block/nonfull/RailBaseBlock.php b/src/material/block/nonfull/RailBaseBlock.php index 3c813139..d5fb7c0b 100644 --- a/src/material/block/nonfull/RailBaseBlock.php +++ b/src/material/block/nonfull/RailBaseBlock.php @@ -7,6 +7,11 @@ abstract class RailBaseBlock extends FlowableBlock //TODO move some methods here $id = $l->level->getBlockID($x, $y, $z); return $id === POWERED_RAIL || $id === RAIL; } + + public static function getAABB(Level $level, $x, $y, $z){ + return null; + } + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $down = $this->getSide(0); if($down->getID() !== AIR and $down instanceof SolidBlock){ diff --git a/src/material/block/nonfull/SlabBlock.php b/src/material/block/nonfull/SlabBlock.php index 82ec32d8..c59caf60 100644 --- a/src/material/block/nonfull/SlabBlock.php +++ b/src/material/block/nonfull/SlabBlock.php @@ -23,52 +23,71 @@ class SlabBlock extends TransparentBlock{ } $this->hardness = 30; } + public static function updateShape(Level $level, $x, $y, $z){ + + [$id, $meta] = $level->level->getBlock($x, $y, $z); + + if($meta & 0x08 == 0x08){ + StaticBlock::setBlockBounds($id, 0, 0, 0, 1, 1, 1); + }else{ + $bottom = (($meta ^ 8) >> 3) & 1; + if($bottom) StaticBlock::setBlockBounds($id, 0, 0, 0, 1, 0.5, 1); + else StaticBlock::setBlockBounds($id, 0, 0.5, 0, 1, 1, 1); + } + } public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ - if(($level->level->getBlockDamage($x, $y, $z) & 0x08) == 0x08) return [new AxisAlignedBB($x, $y, $z, $x + 1, $y + 1, $z + 1)]; - return [new AxisAlignedBB($x, $y, $z, $x + 1, $y + 0.5, $z + 1)]; + self::updateShape($level, $x, $y, $z); + $id = $level->level->getBlockID($x, $y, $z); + + return [ + new AxisAlignedBB( + $x + StaticBlock::$minXs[$id], $y + StaticBlock::$minYs[$id], $z + StaticBlock::$minZs[$id], + $x + StaticBlock::$maxXs[$id], $y + StaticBlock::$maxYs[$id], $z + StaticBlock::$maxZs[$id] + ) + ]; } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - $this->meta &= 0x07; - if($face === 0){ - if($target->getID() === SLAB and ($target->getMetadata() & 0x08) === 0x08 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){ - $this->level->setBlock($target, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true); - return true; - }elseif($block->getID() === SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ + $this->meta &= 0x07; + if($face === 0){ + if($target->getID() === SLAB and ($target->getMetadata() & 0x08) === 0x08 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){ + $this->level->setBlock($target, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true); + return true; + }elseif($block->getID() === SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ + $this->level->setBlock($block, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true); + return true; + }else{ + $this->meta |= 0x08; + } + }elseif($face === 1){ + if($target->getID() === SLAB and ($target->getMetadata() & 0x08) === 0 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){ + $this->level->setBlock($target, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true); + return true; + }elseif($block->getID() === SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ + $this->level->setBlock($block, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true); + return true; + } + }elseif(!$player->entity->inBlock($block)){ + if($block->getID() === SLAB){ + if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ $this->level->setBlock($block, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true); return true; - }else{ + } + return false; + }else{ + if($fy > 0.5){ $this->meta |= 0x08; } - }elseif($face === 1){ - if($target->getID() === SLAB and ($target->getMetadata() & 0x08) === 0 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){ - $this->level->setBlock($target, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true); - return true; - }elseif($block->getID() === SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ - $this->level->setBlock($block, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true); - return true; - } - }elseif(!$player->entity->inBlock($block)){ - if($block->getID() === SLAB){ - if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){ - $this->level->setBlock($block, BlockAPI::get(DOUBLE_SLAB, $this->meta), true, false, true); - return true; - } - return false; - }else{ - if($fy > 0.5){ - $this->meta |= 0x08; - } - } - }else{ - return false; } - if($block->getID() === SLAB and ($target->getMetadata() & 0x07) !== ($this->meta & 0x07)){ - return false; - } - $this->level->setBlock($block, $this, true, false, true); - return true; + }else{ + return false; + } + if($block->getID() === SLAB and ($target->getMetadata() & 0x07) !== ($this->meta & 0x07)){ + return false; + } + $this->level->setBlock($block, $this, true, false, true); + return true; } public function getBreakTime(Item $item, Player $player){ diff --git a/src/material/block/nonfull/SnowLayerBlock.php b/src/material/block/nonfull/SnowLayerBlock.php index 607a9f1c..24ac9082 100644 --- a/src/material/block/nonfull/SnowLayerBlock.php +++ b/src/material/block/nonfull/SnowLayerBlock.php @@ -8,7 +8,9 @@ class SnowLayerBlock extends FlowableBlock{ $this->isFullBlock = false; $this->hardness = 0.5; } - + public static function getAABB(Level $level, $x, $y, $z){ + return null; + } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $down = $this->getSide(0); if($down instanceof SolidBlock){ diff --git a/src/material/block/nonfull/WoodSlabBlock.php b/src/material/block/nonfull/WoodSlabBlock.php index 626a0e7f..7072f9f9 100644 --- a/src/material/block/nonfull/WoodSlabBlock.php +++ b/src/material/block/nonfull/WoodSlabBlock.php @@ -17,10 +17,32 @@ class WoodSlabBlock extends TransparentBlock{ } $this->hardness = 15; } - public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ - if(($level->level->getBlockDamage($x, $y, $z) & 0x08) == 0x08) return [new AxisAlignedBB($x, $y, $z, $x + 1, $y + 1, $z + 1)]; - return [new AxisAlignedBB($x, $y, $z, $x + 1, $y + 0.5, $z + 1)]; + + public static function updateShape(Level $level, $x, $y, $z){ + + [$id, $meta] = $level->level->getBlock($x, $y, $z); + + if($meta & 0x08 == 0x08){ + StaticBlock::setBlockBounds($id, 0, 0, 0, 1, 1, 1); + }else{ + $bottom = (($meta ^ 8) >> 3) & 1; + if($bottom) StaticBlock::setBlockBounds($id, 0, 0, 0, 1, 0.5, 1); + else StaticBlock::setBlockBounds($id, 0, 0.5, 0, 1, 1, 1); + } } + + public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){ + self::updateShape($level, $x, $y, $z); + $id = $level->level->getBlockID($x, $y, $z); + + return [ + new AxisAlignedBB( + $x + StaticBlock::$minXs[$id], $y + StaticBlock::$minYs[$id], $z + StaticBlock::$minZs[$id], + $x + StaticBlock::$maxXs[$id], $y + StaticBlock::$maxYs[$id], $z + StaticBlock::$maxZs[$id] + ) + ]; + } + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $this->meta &= 0x07; if($face === 0){ diff --git a/src/material/block/plant/CyanFlowerBlock.php b/src/material/block/plant/CyanFlowerBlock.php index f97fa614..67225b8b 100644 --- a/src/material/block/plant/CyanFlowerBlock.php +++ b/src/material/block/plant/CyanFlowerBlock.php @@ -6,7 +6,11 @@ class CyanFlowerBlock extends FlowableBlock{ $this->isActivable = true; $this->hardness = 0; } - + + public static function getAABB(Level $level, $x, $y, $z){ + return null; + } + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $down = $this->getSide(0); if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){ diff --git a/src/material/block/plant/DandelionBlock.php b/src/material/block/plant/DandelionBlock.php index 7364aa13..def18792 100644 --- a/src/material/block/plant/DandelionBlock.php +++ b/src/material/block/plant/DandelionBlock.php @@ -6,7 +6,9 @@ class DandelionBlock extends FlowableBlock{ $this->isActivable = true; $this->hardness = 0; } - + public static function getAABB(Level $level, $x, $y, $z){ + return null; + } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $down = $this->getSide(0); if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){ diff --git a/src/material/block/plant/DeadBushBlock.php b/src/material/block/plant/DeadBushBlock.php index 4cb464ec..a528b6f8 100644 --- a/src/material/block/plant/DeadBushBlock.php +++ b/src/material/block/plant/DeadBushBlock.php @@ -6,7 +6,11 @@ class DeadBushBlock extends FlowableBlock{ //$this->isReplaceable = true; $this->hardness = 0; } - + + public static function getAABB(Level $level, $x, $y, $z){ + return null; + } + public function onUpdate($type){ if($type === BLOCK_UPDATE_NORMAL){ if($this->getSide(0)->isTransparent === true){ //Replace with common break method diff --git a/src/material/block/plant/SaplingBlock.php b/src/material/block/plant/SaplingBlock.php index 4d8e308e..0f7dffa4 100644 --- a/src/material/block/plant/SaplingBlock.php +++ b/src/material/block/plant/SaplingBlock.php @@ -19,7 +19,9 @@ class SaplingBlock extends FlowableBlock{ $this->name = $names[$this->meta & 0x03]; $this->hardness = 0; } - + public static function getAABB(Level $level, $x, $y, $z){ + return null; + } public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $down = $this->getSide(0); if($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === FARMLAND){ diff --git a/src/material/block/plant/SugarcaneBlock.php b/src/material/block/plant/SugarcaneBlock.php index 07771276..1f179a0b 100644 --- a/src/material/block/plant/SugarcaneBlock.php +++ b/src/material/block/plant/SugarcaneBlock.php @@ -12,7 +12,9 @@ class SugarcaneBlock extends FlowableBlock{ [SUGARCANE, 0, 1], ]; } - + public static function getAABB(Level $level, $x, $y, $z){ + return null; + } public function onActivate(Item $item, Player $player){ if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal if($this->level->level->getBlockID($this->x, $this->y - 1, $this->z) != SUGARCANE_BLOCK){