arrows test

This commit is contained in:
GameHerobrine 2024-03-21 04:27:58 +03:00
parent 968f3b9dd2
commit 60be9fb2da
7 changed files with 259 additions and 106 deletions

View file

@ -155,19 +155,63 @@ abstract class Block extends Position{
public $z = 0;
public $slipperiness;
public static $minX = 0, $minY = 0, $minZ = 0, $maxX = 1, $maxY = 1, $maxZ = 1;
public static function setBlockBounds($minX, $minY, $minZ, $maxX, $maxY, $maxZ){ //TODO call for some specific blocks
static::$minX = $minX;
static::$minY = $minY;
static::$minZ = $minZ;
static::$maxX = $maxX;
static::$maxY = $maxY;
static::$maxZ = $maxZ;
}
public static function getAABB(Level $level, $x, $y, $z){
return new AxisAlignedBB(static::$minX + $x, static::$minY + $y, static::$minZ + $z, static::$maxX + $x, static::$maxY + $y, static::$maxZ + $z);
return StaticBlock::getAABB($level, $x, $y, $z);
}
public static function containsX($id, $v){
return $v == null ? false : $v->y >= StaticBlock::$minYs[$id] && $v->y <= StaticBlock::$maxYs[$id] && $v->z >= StaticBlock::$minZs[$id] && $v->z <= StaticBlock::$maxZs[$id];
}
public static function containsY($id, $v){
return $v == null ? false : $v->x >= StaticBlock::$minXs[$id] && $v->x <= StaticBlock::$maxXs[$id] && $v->z >= StaticBlock::$minZs[$id] && $v->z <= StaticBlock::$maxZs[$id];
}
public static function containsZ($id, $v){
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 clip(Level $level, $x, $y, $z, Vector3 $start, Vector3 $end){
//self::updateShape($level, $x, $y, $z); TODO update shape
$id = $level->level->getBlockID($x, $y, $z);
$start = $start->subtract($x, $y, $z);
$end = $end->subtract($x, $y, $z);
$v7 = $start->clipX($end, StaticBlock::$minXs[$id]);
$v8 = $start->clipX($end, StaticBlock::$maxXs[$id]);
$v9 = $start->clipY($end, StaticBlock::$minYs[$id]);
$v10 = $start->clipY($end, StaticBlock::$maxYs[$id]);
$v11 = $start->clipZ($end, StaticBlock::$minZs[$id]);
$v12 = $start->clipZ($end, StaticBlock::$maxZs[$id]);
if(!self::containsX($id, $v7)) $v7 = null;
if(!self::containsX($id, $v8)) $v8 = null;
if(!self::containsY($id, $v9)) $v9 = null;
if(!self::containsY($id, $v10)) $v10 = null;
if(!self::containsZ($id, $v11)) $v11 = null;
if(!self::containsZ($id, $v12)) $v12 = null;
$v13 = null;
if($v7 != null && ($v13 == null || $start->distanceSquared($v7) < $start->distanceSquared($v13))) $v13 = $v7;
if($v8 != null && ($v13 == null || $start->distanceSquared($v8) < $start->distanceSquared($v13))) $v13 = $v8;
if($v9 != null && ($v13 == null || $start->distanceSquared($v9) < $start->distanceSquared($v13))) $v13 = $v9;
if($v10 != null && ($v13 == null || $start->distanceSquared($v10) < $start->distanceSquared($v13))) $v13 = $v10;
if($v11 != null && ($v13 == null || $start->distanceSquared($v11) < $start->distanceSquared($v13))) $v13 = $v11;
if($v12 != null && ($v13 == null || $start->distanceSquared($v12) < $start->distanceSquared($v13))) $v13 = $v12;
if($v13 == null) return null;
$v14 = -1;
if($v13 == $v7) $v14 = 4;
if($v13 == $v8) $v14 = 5;
if($v13 == $v9) $v14 = 0;
if($v13 == $v10) $v14 = 1;
if($v13 == $v11) $v14 = 2;
if($v13 == $v12) $v14 = 3;
return MovingObjectPosition::fromBlock($x, $y, $z, $v14, $v13->add($x, $y, $z));
}
public static function addVelocityToEntity(Level $level, $x, $y, $z, Entity $entity, Vector3 $velocityVector){}
public static function onRandomTick(Level $level, $x, $y, $z){}

View file

@ -6,6 +6,7 @@ class StaticBlock
{
const DEFAULT_SLIPPERINESS = 0.6;
const DEFAULT_HARDNESS = 0;
private static $NULL_BOUNDS;
public static $isSolid = [];
public static $isTransparent = [];
@ -19,6 +20,8 @@ class StaticBlock
public static $hardness = [];
public static $slipperiness = [];
public static $boundingBoxes = [];
public static $minXs = [], $minYs = [], $minZs = [], $maxXs = [], $maxYs = [], $maxZs = [];
public static function init(){
self::$NULL_BOUNDS = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
foreach(Block::$class as $nonstaticname){
@ -39,32 +42,35 @@ class StaticBlock
FireBlock::setFlammabilityAndCatchingChance($b->getID(), 0, 0);
self::setBlockBounds($b->getID(), 0, 0, 0, 1, 1, 1);
}
Block::$class[BED_BLOCK]::setBlockBounds(0, 0, 0, 1, 0.5625, 1);
self::setBlockBounds(BED_BLOCK, 0, 0, 0, 1, 0.5625, 1);
//Cake: has bounds based on world state
//Chest: has bounds based on world state
Block::$class[WHEAT_BLOCK]::setBlockBounds(0, 0, 0, 1, 0.25, 1);
Block::$class[CARROT_BLOCK]::setBlockBounds(0, 0, 0, 1, 0.25, 1);
Block::$class[POTATO_BLOCK]::setBlockBounds(0, 0, 0, 1, 0.25, 1);
Block::$class[BEETROOT_BLOCK]::setBlockBounds(0, 0, 0, 1, 0.25, 1); //i assume it extends class Crops
Block::$class[WHEAT_BLOCK]::setBlockBounds(0, 0, 0, 1, 0.25, 1);
Block::$class[DEAD_BUSH]::setBlockBounds(0.1, 0, 0.1, 0.9, 0.8, 0.9);
Block::$class[DOOR_BLOCK]::setBlockBounds(0, 0, 0, 1, 1, 1); //has bounds based on rotation
Block::$class[FARMLAND]::setBlockBounds(0, 0, 0, 1, 0.9375, 1);
self::setBlockBounds(WHEAT_BLOCK, 0, 0, 0, 1, 0.25, 1);
self::setBlockBounds(CARROT_BLOCK, 0, 0, 0, 1, 0.25, 1);
self::setBlockBounds(POTATO_BLOCK,0, 0, 0, 1, 0.25, 1);
self::setBlockBounds(BEETROOT_BLOCK, 0, 0, 0, 1, 0.25, 1); //i assume it extends class Crops
self::setBlockBounds(WHEAT_BLOCK, 0, 0, 0, 1, 0.25, 1);
self::setBlockBounds(DEAD_BUSH, 0.1, 0, 0.1, 0.9, 0.8, 0.9);
self::setBlockBounds(DOOR_BLOCK, 0, 0, 0, 1, 1, 1); //has bounds based on rotation
self::setBlockBounds(FARMLAND, 0, 0, 0, 1, 0.9375, 1);
//Fence: bounds on state
//Fence Gate: bounds on state
Block::$class[TALL_GRASS]::setBlockBounds(0.1, 0, 0.1, 0.9, 0.8, 0.9);
Block::$class[MELON_STEM]::setBlockBounds(0.5 - 0.125, 0, 0.5 - 0.125, 0.5 + 0.125, 0.25, 0.5 + 0.125);
Block::$class[PUMPKIN_STEM]::setBlockBounds(0.5 - 0.125, 0, 0.5 - 0.125, 0.5 + 0.125, 0.25, 0.5 + 0.125);
Block::$class[SAPLING]::setBlockBounds(0.1, 0, 0.1, 0.9, 0.8, 0.9);
Block::$class[BROWN_MUSHROOM]::setBlockBounds(0.3, 0, 0.3, 0.8, 0.4, 0.8);
Block::$class[SLAB]::setBlockBounds(0, 0, 0, 1, 0.5, 1);
self::setBlockBounds(TALL_GRASS, 0.1, 0, 0.1, 0.9, 0.8, 0.9);
self::setBlockBounds(MELON_STEM, 0.5 - 0.125, 0, 0.5 - 0.125, 0.5 + 0.125, 0.25, 0.5 + 0.125);
self::setBlockBounds(PUMPKIN_STEM, 0.5 - 0.125, 0, 0.5 - 0.125, 0.5 + 0.125, 0.25, 0.5 + 0.125);
self::setBlockBounds(SAPLING, 0.1, 0, 0.1, 0.9, 0.8, 0.9);
self::setBlockBounds(BROWN_MUSHROOM, 0.3, 0, 0.3, 0.8, 0.4, 0.8);
self::setBlockBounds(SLAB, 0, 0, 0, 1, 0.5, 1);
//Ladder: based on rotation
//Glass Pane: based on state
RailBaseBlock::setBlockBounds(0, 0, 0, 1, 0.125, 1);
Block::$class[SUGARCANE_BLOCK]::setBlockBounds(0.5 - 0.375, 0, 0.5 - 0.375, 0.5 + 0.375, 1, 0.5 + 0.375);
Block::$class[SNOW_LAYER]::setBlockBounds(0, 0, 0, 1, 0.125, 1);
self::setBlockBounds(RAIL, 0, 0, 0, 1, 0.125, 1);
self::setBlockBounds(POWERED_RAIL, 0, 0, 0, 1, 0.125, 1);
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
//Stone wall: based on state
@ -92,6 +98,21 @@ class StaticBlock
FireBlock::setFlammabilityAndCatchingChance(SPONGE, 30, 60);
}
public static function setBlockBounds($blockID, $minX, $minY, $minZ, $maxX, $maxY, $maxZ){
self::$maxXs[$blockID] = $maxX;
self::$maxYs[$blockID] = $maxY;
self::$maxZs[$blockID] = $maxZ;
self::$minXs[$blockID] = $minX;
self::$minYs[$blockID] = $minY;
self::$minZs[$blockID] = $minZ;
}
public static function getAABB(Level $level, $x, $y, $z){
$id = $level->level->getBlockID($x, $y, $z);
return new AxisAlignedBB(self::$minXs[$id] + $x, self::$minYs[$id] + $y, self::$minZs[$id] + $z, self::$maxXs[$id] + $x, self::$maxYs[$id] + $y, self::$maxZs[$id] + $z); //TODO get bb from self::$boundingBoxes ?
}
public static function getBlock($id){
return Block::$class[$id] ?? Block::$class[0];
}