/// <inheritdoc /> public override void RandomUpdate(World world, Vector3i position, uint data) { var age = (int)(data & 0b00_0111); if (age < 7) { world.SetBlock(this.AsInstance((uint)(age + 1)), position); } else { if (!(world.GetBlock(position.Above())?.Block.IsReplaceable ?? false)) { return; } var height = 0; for (var offset = 0; offset < maxHeight; offset++) { if (world.GetBlock(position.Below(offset))?.Block == this) { height++; } else { break; } } if (height < maxHeight) { Place(world, position.Above()); } } }
/// <summary> /// Check if a given position has an opaque block above it. /// </summary> public static bool HasOpaqueTop(this World world, Vector3i position) { Block top = world.GetBlock(position.Above())?.Block ?? Block.Air; return(top.IsSolidAndFull && top.IsOpaque || top is IHeightVariable); }
/// <inheritdoc /> public bool Burn(World world, Vector3i position, Block fire) { world.SetBlock(GrassBurned.AsInstance(), position); fire.Place(world, position.Above()); return(false); }
/// <inheritdoc /> protected override void DoDestroy(World world, Vector3i position, uint data, PhysicsEntity?entity) { bool isBase = (data & 0b1) == 0; world.SetDefaultBlock(position); world.SetDefaultBlock(isBase ? position.Above() : position.Below()); }
/// <inheritdoc /> protected override void DoPlace(World world, Vector3i position, PhysicsEntity?entity) { bool isLowered = world.IsLowered(position); uint data = (isLowered ? 1u : 0u) << 1; world.SetBlock(this.AsInstance(data), position); world.SetBlock(this.AsInstance(data | 1), position.Above()); }
/// <inheritdoc /> public override void BlockUpdate(World world, Vector3i position, uint data, BlockSide side) { var orientation = (Orientation)(data & 0b00_0011); (Block block, uint dataAbove) = world.GetBlock(position.Above()) ?? BlockInstance.Default; // If another block of this type is above, no solid block is required to hold. if (block == this && orientation == (Orientation)(dataAbove & 0b00_0011)) { return; } if (side == BlockSide.Top) { side = orientation.Opposite().ToBlockSide(); } CheckBack(world, position, side, orientation, schedule: true); }
/// <summary> /// Check if a given position has a solid top above it. /// </summary> public static bool HasSolidTop(this World world, Vector3i position) { return(world.IsSolid(position.Above())); }
/// <inheritdoc /> public override bool CanPlace(World world, Vector3i position, PhysicsEntity?entity) { return(world.GetBlock(position.Above())?.Block.IsReplaceable == true && (world.GetBlock(position.Below())?.Block ?? Air) is IPlantable); }