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

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

View file

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

View file

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

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