arrow collision tweaks

This commit is contained in:
GameHerobrine 2024-05-04 05:51:31 +03:00
parent f8ec00dad9
commit 8b07056323
17 changed files with 137 additions and 51 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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();

View file

@ -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;

View file

@ -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 [

View file

@ -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){

View file

@ -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){

View file

@ -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){

View file

@ -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){

View file

@ -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){

View file

@ -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){

View file

@ -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

View file

@ -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){

View file

@ -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){